예제 #1
0
        public HttpResponseMessage PostFlight([FromBody] FLIGHT flight)
        {
            try
            {
                using (TECAirlinesDBEntities entities = new TECAirlinesDBEntities())
                {
                    entities.INSERT_FLIGHT(flight.FLIGHT_ID, flight.PLANE_ID, flight.ORIGIN_AIRPORT,
                                           flight.DESTINATION_AIRPORT, flight.FSTATUS);
                    entities.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, flight);
                    message.Headers.Location = new Uri(Request.RequestUri + flight.FLIGHT_ID.ToString());
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
예제 #2
0
 public void updateFlight(FLIGHT flight)
 {
     db.Updateable(flight).ExecuteCommand();
 }
예제 #3
0
        public FLIGHT getFlight(string F_ID)
        {
            FLIGHT flight = db.Queryable <FLIGHT>().Where(it => it.F_ID == F_ID).Single();

            return(flight);
        }
        public ActionResult ReceiveMsg1()
        {
            //新建航班,多表插入
            string  id         = Request.Params["id"];
            string  pid        = Request.Params["pid"];
            string  t_airport  = Request.Params["t_airport"];
            string  t_terminal = Request.Params["t_terminal"];
            string  t_time     = Request.Params["t_time"];
            string  l_airport  = Request.Params["l_airport"];
            string  l_terminal = Request.Params["l_terminal"];
            string  l_time     = Request.Params["l_time"];
            Actions a          = new Actions();
            PLANE   b          = a.GetPLANE(pid);
            FLIGHT  obj2       = new FLIGHT();

            obj2.F_ID     = id;
            obj2.P_ID     = pid;
            obj2.CAPACITY = b.CAPACITY;
            obj2.RESERVE  = 0;
            obj2.CHECKED  = 0;
            obj2.VALUE    = 500;
            obj2.LUGGAGE  = 50;
            obj2.BOARD    = 0;
            FLIGHTIME obj1 = new FLIGHTIME();

            obj1.F_ID       = id;
            obj1.T_AIRPORT  = t_airport;
            obj1.T_TERMINAL = t_terminal;
            obj1.L_AIRPORT  = l_airport;
            obj1.L_TERMNAL  = l_terminal;

            obj1.EX_TAKEOFF_TIME = a.SystemTime.AddHours(10);
            obj1.EX_LAND_TIME    = a.SystemTime.AddHours(12);
            obj1.RE_TAKEOFF_TIME = null;
            obj1.RE_LAND_TIME    = null;

            string d_ID = id;       //降落飞机ID

            char[] str = d_ID.ToCharArray();
            string d_ID_re;   //返回航班ID
            int    temp = int.Parse(str[5].ToString());

            if (temp % 2 == 0)
            {
                d_ID_re = d_ID.Substring(0, d_ID.Length - 1) + (temp + 1).ToString();
            }
            else
            {
                d_ID_re = d_ID.Substring(0, d_ID.Length - 1) + (temp - 1).ToString();
            }



            FLIGHTIME obj3 = new FLIGHTIME();

            obj3.F_ID       = d_ID_re;
            obj3.T_AIRPORT  = l_airport;
            obj3.T_TERMINAL = l_terminal;
            obj3.L_AIRPORT  = t_airport;
            obj3.L_TERMNAL  = t_terminal;

            obj3.EX_TAKEOFF_TIME = a.SystemTime.AddHours(14);
            obj3.EX_LAND_TIME    = a.SystemTime.AddHours(16);
            obj3.RE_TAKEOFF_TIME = null;
            obj3.RE_LAND_TIME    = null;

            db.Insertable(obj1).ExecuteCommand();
            db.Insertable(obj2).ExecuteCommand();
            db.Insertable(obj3).ExecuteCommand();
            //DataBaseAccess.insertObj(obj1);
            //DataBaseAccess.insertObj(obj2);
            //DataBaseAccess.insertObj(obj3);
            return(View("Airlines"));
        }
예제 #5
0
        public void dropcheck()
        {
            Actions a = new Actions();

            try
            {
                a.BeginTran();

                List <FLIGHTIME> dropFlightList = a.searchDropFlights();
                foreach (var dropFlightime in dropFlightList)       //降落飞机
                {
                    string   d_ID             = dropFlightime.F_ID; //降落飞机ID
                    char[]   str              = d_ID.ToCharArray();
                    DateTime systime          = a.SystemTime;
                    TimeSpan rest             = TimeSpan.FromHours(5);
                    DateTime ex_takeoftime_re = systime + rest;                 //返回起飞时间
                    var      time_length      = dropFlightime.EX_LAND_TIME - dropFlightime.EX_TAKEOFF_TIME;
                    DateTime ex_landtime_re   = ex_takeoftime_re + time_length; //航班长度
                    string   d_ID_re;                                           //返回航班ID
                    int      temp = int.Parse(str[5].ToString());
                    if (temp % 2 == 0)
                    {
                        d_ID_re = d_ID.Substring(0, d_ID.Length - 1) + (temp + 1).ToString();
                    }
                    else
                    {
                        d_ID_re = d_ID.Substring(0, d_ID.Length - 1) + (temp - 1).ToString();
                    }
                    //现航班
                    try
                    {
                        a.BeginTran();
                        a.dealDropFlightime(dropFlightime);
                        FLIGHT dropFlight = a.getFlight(dropFlightime.F_ID);
                        dropFlight.CHECKED = 0;
                        dropFlight.BOARD   = 0;
                        dropFlight.RESERVE = 0;
                        a.updateFlight(dropFlight);
                        a.delSeat(dropFlight.F_ID);
                        a.delLuggage(dropFlight.F_ID);
                        textBox1.Text += (dropFlight.F_ID + "  已降落\r\n");

                        a.CommitTran();
                    }
                    catch
                    {
                        a.RollbackTran();
                        Console.WriteLine("dealDropFlight");
                    }

                    //返回航班
                    try
                    {
                        a.BeginTran();
                        a.dealDropFlight_return(ex_takeoftime_re, ex_landtime_re, d_ID_re);
                        textBox1.Text += (d_ID_re + "  返程航班已修改\r\n");
                        a.CommitTran();
                    }
                    catch
                    {
                        a.RollbackTran();
                        Console.WriteLine("dealDropFlight_return" + "  " +
                                          d_ID_re + " " + systime.ToString("yyyy-MM-dd-hh-mm") + " " + ex_takeoftime_re.GetDateTimeFormats('t')[0].ToString() + " " + ex_landtime_re.GetDateTimeFormats('t')[0].ToString());
                    }
                    //乘客下机  行李下机 飞机初始化修改航班
                    try
                    {
                        a.BeginTran();
                        a.dropFlightUpdate(dropFlightime.F_ID, d_ID_re);
                        a.CommitTran();
                    }
                    catch
                    {
                        a.RollbackTran();
                        Console.WriteLine("乘客下机  行李下机 飞机初始化修改航班");
                    }
                }
                List <FLIGHTIME> newFlightimes = a.searchnewFlightimes();
                foreach (FLIGHTIME newFlightime in newFlightimes)
                {
                    try
                    {
                        a.BeginTran();
                        a.departFstate(newFlightime.F_ID);
                        textBox1.Text += (newFlightime.F_ID + "  待起飞\r\n");
                        a.CommitTran();
                    }
                    catch
                    {
                        a.RollbackTran();
                        Console.WriteLine("departFstate" + "  " +
                                          newFlightime.F_ID + " " + newFlightime.EX_TAKEOFF_TIME.ToString("yyyy-MM-dd-hh-mm"));
                    }
                    //选出10名乘客购票

                    var CustomerList = a.selectFreeCustomers(10);
                    Console.WriteLine(CustomerList.Count);
                    foreach (var customer in CustomerList)
                    {
                        SEAT insertSeat = new SEAT();
                        insertSeat.F_ID        = newFlightime.F_ID;
                        insertSeat.C_ID        = customer.ID;
                        insertSeat.SEAT_NUMBER = null;
                        insertSeat.STATE       = "已购票";
                        try
                        {
                            a.BeginTran();
                            a.InsertSeat(insertSeat);
                            textBox1.Text += (customer.ID.ToString() + "  已购票\r\n");
                            a.CommitTran();
                        }
                        catch
                        {
                            a.RollbackTran();
                            Console.WriteLine("insertSeat");
                        }
                    }
                    FLIGHT newFlight = a.getFlight(newFlightime.F_ID);
                    newFlight.RESERVE = (short)CustomerList.Count;
                    a.updateFlight(newFlight);
                }
                a.CommitTran();
            }catch
            {
                a.RollbackTran();
            }
        }