예제 #1
0
        private new void InitializeComponent()
        {
            panel.Controls.Add(panelChild);

            panel.Dock      = DockStyle.Right;
            panel.Padding   = new Padding(40, 0, 0, 20);
            panel.BackColor = colors.White1;

            // DAO

            FlightDAO airlineDAO = new FlightDAO(Enums.Server.MariaDB);

            BindingSource bindingSource = new BindingSource
            {
                DataSource = airlineDAO.GetAllFlights()
            };

            DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();

            dataGridViewCellStyle2.Alignment          = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            dataGridViewCellStyle2.BackColor          = colors.White1;
            dataGridViewCellStyle2.Font               = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            dataGridViewCellStyle2.ForeColor          = System.Drawing.Color.Black;
            dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.WhiteSmoke;
            dataGridViewCellStyle2.SelectionForeColor = System.Drawing.Color.Black;
            dataGridViewCellStyle2.WrapMode           = System.Windows.Forms.DataGridViewTriState.False;


            // main controls
            AddElement(new FlatLabelTitle("Flights", 0, 0));
            AddElement(new FlatButton("Create Flight plan"));
            panelChild.Controls[1].Click += new EventHandler(GoToCreate);
            panelChild.Controls[1].Width  = 200;

            AddElement(new DataGridView
            {
                Name       = "dgvFlights",
                DataSource = bindingSource,
                Width      = 975,
                ForeColor  = colors.Black1,

                DefaultCellStyle = dataGridViewCellStyle2,
                ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2,
                RowsDefaultCellStyle          = dataGridViewCellStyle2,
                RowHeadersDefaultCellStyle    = dataGridViewCellStyle2,
                AllowUserToAddRows            = false,
                AllowUserToDeleteRows         = false,
                AutoSizeColumnsMode           = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.ColumnHeader,
                AutoSize                    = true,
                BackgroundColor             = colors.White1,
                BorderStyle                 = System.Windows.Forms.BorderStyle.None,
                ColumnHeadersBorderStyle    = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single,
                ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize,
                GridColor                   = System.Drawing.SystemColors.Control,
                RowHeadersBorderStyle       = System.Windows.Forms.DataGridViewHeaderBorderStyle.None,
                MultiSelect                 = false,
                RowHeadersVisible           = false,
                ReadOnly                    = true,
            });
        }
예제 #2
0
 internal LoggedInAirlineFacade(LoginToken <AirlineCompany> token)
 {
     LoginToken  = token;
     _ticketDAO  = new TicketDAO();
     _flightDAO  = new FlightDAO();
     _airlineDAO = new AirlineDAO();
 }
예제 #3
0
 internal AnonymousUserFacade()
 {
     LoginToken  = null;
     _airlineDAO = new AirlineDAO();
     _flightDAO  = new FlightDAO();
     _countryDAO = new CountryDAO();
 }
예제 #4
0
 // ================ FLIGHT ==================
 // FLIGHT's VIEW
 public ActionResult Flight()
 {
     if (IsLoggedIn())
     {
         return(View(FlightDAO.GetFlightList()));
     }
     return(RedirectToAction("Index"));
 }
예제 #5
0
 // FLIGHT EDIT'S VIEW
 public ActionResult FlightEdit(string id)
 {
     if (IsLoggedIn())
     {
         var f = FlightDAO.GetFlight(id);
         if (f != null)
         {
             ViewBag.RouteData = RouteDAO.GetRouteList();
             return(View(f));
         }
     }
     return(RedirectToAction("Index"));
 }
예제 #6
0
 public ActionResult FlightEdit(Flight updateF)
 {
     ModelState.Remove("AvailSeatsF");
     ModelState.Remove("AvailSeatsE");
     ModelState.Remove("AvailSeatsB");
     ModelState.Remove("FlightTime");
     if (ModelState.IsValid)
     {
         var editResult = FlightDAO.UpdateFlight(updateF);
         if (editResult == "ok")
         {
             return(RedirectToAction("Flight"));
         }
         ModelState.AddModelError("", editResult);
     }
     ViewBag.RouteData = RouteDAO.GetRouteList();
     return(View(updateF));
 }
예제 #7
0
        /// <summary>
        /// Add flight to flight id collection in customer object
        /// </summary>
        /// <param name="_customerList"></param>
        public void AddFlight(List <Customer> _customerList)
        {
            String   _loopFlightId = "";
            String   _flightId, _customerId;
            Customer _customer = new Customer();

            do
            {
                Console.WriteLine("Enter the customer id: ");
                _customerId = Console.ReadLine();
                if (!Validator.IsCustomerIdExisted(_customerId))
                {
                    Console.WriteLine("Customer id is not existed! Please enter again. ");
                    continue;
                }
                break;
            } while (true);

            foreach (Customer c in _customerList)
            {
                if (c.Id.Equals(_customerId))
                {
                    _customer = c;
                    break;
                }
            }

            do
            {
                Console.WriteLine("Enter the flight id: ");
                _flightId = Console.ReadLine();
                if (!Validator.IsFlightIdExisted(_flightId))
                {
                    Console.WriteLine("This flight id is not existed ! Please enter again.");
                    continue;
                }
                FlightDAO.GetFlightById(_flightId).CustomerId.Add(_customerId);
                _customer.FlightId.Add(_flightId);
                Console.WriteLine("Add succeed !");
                Console.WriteLine("Do you want to continue entering flight id (Y/N): ");
                _loopFlightId = Console.ReadLine();
            } while (_loopFlightId[0] == 'Y' || _loopFlightId[0] == 'y');
        }
예제 #8
0
        private void Save(object sender, System.EventArgs e)
        {
            try
            {
                ComboBox myCombo  = (ComboBox)panelChild.Controls[2];
                ComboBox myCombo2 = (ComboBox)panelChild.Controls[12];
                ComboBox myCombo3 = (ComboBox)panelChild.Controls[13];

                ComboBox myCombo4 = (ComboBox)panelChild.Controls[16];
                ComboBox myCombo5 = (ComboBox)panelChild.Controls[18];
                ComboBox myCombo6 = (ComboBox)panelChild.Controls[20];

                DateTime departureDate  = DateTime.Parse(panelChild.Controls[6].Text);
                DateTime arrivalDate    = DateTime.Parse(panelChild.Controls[9].Text);
                TimeSpan twentyFourHour = new TimeSpan(24, 0, 0);
                TimeSpan departureHour  = TimeSpan.Parse(panelChild.Controls[7].Controls[0].Text);
                TimeSpan arrivalHour    = TimeSpan.Parse(panelChild.Controls[10].Controls[0].Text);
                TimeSpan flightHour     = (departureHour > arrivalHour) ? (twentyFourHour - departureHour) + arrivalHour : arrivalHour - departureHour;

                AirlineDAO  airlineDAO  = new AirlineDAO(Server.MariaDB);
                AirplaneDAO airplaneDAO = new AirplaneDAO(Server.MariaDB);
                PilotDAO    pilotDAO    = new PilotDAO(Server.MariaDB);

                Flight flight = new Flight
                {
                    Type          = myCombo.SelectedItem.ToString(),
                    Origin        = panelChild.Controls[3].Controls[0].Text,
                    Destiny       = panelChild.Controls[4].Controls[0].Text,
                    DepartureDate = departureDate.ToString(),
                    DepartureHour = departureHour.ToString(),
                    ArrivalDate   = arrivalDate.ToString(),
                    ArrivalHour   = arrivalHour.ToString(),
                    FlightTime    = flightHour.ToString(),
                    Pist          = int.Parse(myCombo2.SelectedItem.ToString()),
                    FlightStatus  = myCombo3.SelectedItem.ToString(),
                    AirlineID     = airlineDAO.GetID(myCombo4.SelectedItem.ToString()),
                    AirplaneID    = airplaneDAO.GetID(myCombo5.SelectedItem.ToString()),
                    PilotID       = pilotDAO.GetID(myCombo6.SelectedItem.ToString()),
                };

                FlightDAO dao = new FlightDAO(Enums.Server.MariaDB);
                dao.Save(flight);

                // Button is the last child
                panelChild.Controls[panelChild.Controls.Count - 1].Enabled = false;

                FlatPanel parentPanel = (FlatPanel)panel.Parent;
                Control   toolbar     = parentPanel.Controls[0];

                MenuSection menuController = new MenuSection(0);
                menuController.ShowPanel(ref parentPanel, Enums.ItemMenuType.Flight);

                PanelAdjustment();

                void PanelAdjustment()
                {
                    parentPanel.Controls[1].Dock   = DockStyle.None;
                    toolbar.Controls[0].Width      = parentPanel.Width;
                    parentPanel.Controls[1].Top    = toolbar.Top + toolbar.Height;
                    parentPanel.Controls[1].Width  = parentPanel.Width;
                    parentPanel.Controls[1].Height = parentPanel.Height - toolbar.Height;
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }
        }
예제 #9
0
 public FlightServiceImpl()
 {
     flightDao = DaoFactory.createFlightDao();
 }
예제 #10
0
        public ActionResult FlightAdd(List <Flight> newFlights)
        {
            //init validation variables
            bool          invalid = false, invalid2 = false;
            int           total = newFlights.Count;
            List <string> added = new List <string>();

            ModelState.Remove("AvailSeatsF");
            ModelState.Remove("AvailSeatsE");
            ModelState.Remove("AvailSeatsB");
            ModelState.Remove("FlightTime");
            if (ModelState.IsValid)
            {
                foreach (var item in newFlights)
                {
                    //get aircraft of route
                    var route    = RouteDAO.GetRoute(item.RNo);
                    var aircraft = RouteDAO.GetAircraft(route.RAircraft);

                    //assign default seatnumbers
                    if (aircraft.FirstClassSeats != null)
                    {
                        item.AvailSeatsF = aircraft.FirstClassSeats;
                    }
                    if (aircraft.BussinessSeats != null)
                    {
                        item.AvailSeatsB = aircraft.BussinessSeats;
                    }
                    item.AvailSeatsE = aircraft.EconomySeats;
                    var diff = item.ArrivalTime.Hour - item.DepartureTime.Hour;
                    item.FlightTime = int.Parse(diff.ToString());
                    if (!FlightDAO.AddFlight(item))
                    {
                        ModelState.AddModelError("", string.Format("Could not add flight {0}", item.FNo));
                        invalid = true;
                        total--;
                    }
                    else
                    {
                        added.Add(string.Format("{0}", item.FNo));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Please enter required fields");
                invalid2 = true;
            }
            if (!invalid && !invalid2)
            {
                return(RedirectToAction("Flight"));
            }

            if (added.Count > 0)
            {
                ModelState.AddModelError("", "Flights Added: ");
                foreach (var item in added)
                {
                    ModelState.AddModelError("", item);
                }
            }

            return(View());
        }
예제 #11
0
 // FLIGHT DELETE's PROCESS
 public ActionResult FlightDelete(string id) => IsLoggedIn() && FlightDAO.DeleteFlight(id) ? Content("OK") : Content("Error");
예제 #12
0
 public FlightBUS()
 {
     flightDAO = new FlightDAO();
 }
 internal AnonymousUserFacade()
 {
     _airlineDAO = new AirlineDAO();
     _flightDAO  = new FlightDAO();
     _countryDAO = new CountryDAO();
 }
예제 #14
0
 public void SaveFlight(FlightDAO flight)
 {
     FlightBLL.AddFlight(flight);
 }
예제 #15
0
        // Function that process Payment request
        // Will return "ok:[orderid]" if success
        // Will return any other error string when failed
        public static string ProcessPayment(Payment payment, bool isBlocked)
        {
            db = new AirlineDBEntities();
            // Checking Creditcard
            CreditCard card = db.CreditCard.FirstOrDefault(c => c.CCNo == payment.CCNo);

            if (!isBlocked)
            {
                if (card == null || card.CVV != payment.CVV)
                {
                    return("Error: Credit Card is not valid.");
                }
                if (card.Balance < payment.Total)
                {
                    return("Error: Not enough money in account.");
                }
            }

            string s = "";

            try
            {
                // Create Order
                DateTime now        = DateTime.Now;
                string   OrderIDStr = "" + now.Year + now.Month + now.Day + now.Hour + now.Minute + now.Second;
                Int64    OrderID    = Int64.Parse(OrderIDStr);
                double   Total      = 0;

                Order order = new Order();
                order.OrderID   = OrderID;
                order.OrderDate = now;
                if (isBlocked)
                {
                    order.Status = 0;
                }
                else
                {
                    order.Status = 1;
                }

                order.UserID = payment.UserID;
                order.Total  = Total;

                db.Order.Add(order);
                int ticketCount = 1;

                // Create Oneway / First Flight/ First Stop Ticket
                Flight FInfo1 = FlightDAO.GetFlight(payment.FNo1);
                payment.Passengers.ForEach(p =>
                {
                    Ticket ticket  = new Ticket();
                    Int64 TicketID = Int64.Parse(OrderID.ToString() + ticketCount);
                    double price   = 0;
                    if (p.Age >= 14)
                    {
                        price += FInfo1.BasePrice + FInfo1.Route.Aircraft.ServiceFee;
                    }
                    else
                    {
                        price += FInfo1.BasePrice * 70 / 100 + FInfo1.Route.Aircraft.ServiceFee;
                    }
                    double daysToDeparture = (FInfo1.DepartureTime - DateTime.Now).TotalDays;
                    if (daysToDeparture <= 14)
                    {
                        if (p.Age >= 14)
                        {
                            price += FInfo1.BasePrice * 0.02 * (14 - daysToDeparture);
                        }
                        else
                        {
                            price += FInfo1.BasePrice * 70 / 100 * 0.02 * (14 - daysToDeparture);
                        }
                    }

                    foreach (var item in p.Service)
                    {
                        price += ServiceDAO.GetService(item).ServiceFee;
                        db.TicketService.Add(new TicketService {
                            ServiceID = item, TicketID = TicketID
                        });
                    }
                    if (payment.Class == "F")
                    {
                        price += 20;
                    }
                    else if (payment.Class == "B")
                    {
                        price += 10;
                    }
                    ticket.TicketID   = TicketID;
                    ticket.OrderID    = OrderID;
                    ticket.FNo        = FInfo1.FNo;
                    ticket.PassportNo = p.PassportNo;
                    ticket.Class      = payment.Class;
                    ticket.Firstname  = p.Firstname;
                    ticket.Lastname   = p.Lastname;
                    ticket.Sex        = p.Sex;
                    ticket.Age        = p.Age;
                    ticket.IsReturn   = false;
                    ticket.Price      = price;
                    db.Ticket.Add(ticket);
                    Total += price;
                    ticketCount++;
                });

                // Create Second stop's ticket (if exists)
                Flight FInfo2 = FlightDAO.GetFlight(payment.FNo2);
                if (FInfo2 != null)
                {
                    payment.Passengers.ForEach(p =>
                    {
                        Ticket ticket  = new Ticket();
                        Int64 TicketID = Int64.Parse(OrderID.ToString() + ticketCount);
                        double price   = 0;
                        if (p.Age >= 14)
                        {
                            price += FInfo2.BasePrice + FInfo2.Route.Aircraft.ServiceFee;
                        }
                        else
                        {
                            price += FInfo2.BasePrice * 70 / 100 + FInfo2.Route.Aircraft.ServiceFee;
                        }
                        double daysToDeparture = (FInfo2.DepartureTime - DateTime.Now).TotalDays;
                        if (daysToDeparture <= 14)
                        {
                            if (p.Age >= 14)
                            {
                                price += FInfo2.BasePrice * 0.02 * (14 - daysToDeparture);
                            }
                            else
                            {
                                price += FInfo2.BasePrice * 70 / 100 * 0.02 * (14 - daysToDeparture);
                            }
                        }

                        foreach (var item in p.Service)
                        {
                            price += ServiceDAO.GetService(item).ServiceFee;
                            db.TicketService.Add(new TicketService {
                                ServiceID = item, TicketID = TicketID
                            });
                        }
                        if (payment.Class == "F")
                        {
                            price += 20;
                        }
                        else if (payment.Class == "B")
                        {
                            price += 10;
                        }
                        ticket.TicketID   = TicketID;
                        ticket.OrderID    = OrderID;
                        ticket.FNo        = FInfo2.FNo;
                        ticket.PassportNo = p.PassportNo;
                        ticket.Class      = payment.Class;
                        ticket.Firstname  = p.Firstname;
                        ticket.Lastname   = p.Lastname;
                        ticket.Sex        = p.Sex;
                        ticket.Age        = p.Age;
                        ticket.IsReturn   = false;
                        ticket.Price      = price;
                        db.Ticket.Add(ticket);
                        Total += price;
                        ticketCount++;
                    });
                }

                // Create Return Flight Ticket
                Flight ReFInfo = FlightDAO.GetFlight(payment.ReFNo);
                if (ReFInfo != null)
                {
                    payment.Passengers.ForEach(p =>
                    {
                        Ticket ticket  = new Ticket();
                        Int64 TicketID = Int64.Parse(OrderID.ToString() + ticketCount);
                        double price   = 0;
                        if (p.Age >= 14)
                        {
                            price += ReFInfo.BasePrice + ReFInfo.Route.Aircraft.ServiceFee;
                        }
                        else
                        {
                            price += ReFInfo.BasePrice * 70 / 100 + ReFInfo.Route.Aircraft.ServiceFee;
                        }

                        double daysToDeparture = (ReFInfo.DepartureTime - DateTime.Now).TotalDays;
                        if (daysToDeparture <= 14)
                        {
                            if (p.Age >= 14)
                            {
                                price += ReFInfo.BasePrice * 0.02 * (14 - daysToDeparture);
                            }
                            else
                            {
                                price += ReFInfo.BasePrice * 70 / 100 * 0.02 * (14 - daysToDeparture);
                            }
                        }

                        foreach (var item in p.Service)
                        {
                            price += ServiceDAO.GetService(item).ServiceFee;
                            db.TicketService.Add(new TicketService {
                                ServiceID = item, TicketID = TicketID
                            });
                        }
                        if (payment.Class == "F")
                        {
                            price += 20;
                        }
                        else if (payment.Class == "B")
                        {
                            price += 10;
                        }
                        ticket.TicketID   = TicketID;
                        ticket.OrderID    = OrderID;
                        ticket.FNo        = ReFInfo.FNo;
                        ticket.PassportNo = p.PassportNo;
                        ticket.Class      = payment.Class;
                        ticket.Firstname  = p.Firstname;
                        ticket.Lastname   = p.Lastname;
                        ticket.Sex        = p.Sex;
                        ticket.Age        = p.Age;
                        ticket.IsReturn   = true;
                        ticket.Price      = price;
                        db.Ticket.Add(ticket);
                        Total += price;
                        ticketCount++;
                    });
                }
                db.SaveChanges();

                db.Order.FirstOrDefault(o => o.OrderID == OrderID).Total = Total;

                // Seat Calculation
                var SFInfo1  = db.Flight.Where(f => f.FNo == payment.FNo1).FirstOrDefault();
                var SFInfo2  = db.Flight.Where(f => f.FNo == payment.FNo2).FirstOrDefault();
                var SReFInfo = db.Flight.Where(f => f.FNo == payment.ReFNo).FirstOrDefault();
                if (payment.Class == "F")
                {
                    SFInfo1.AvailSeatsF = SFInfo1.AvailSeatsF - payment.Passengers.Count();

                    if (SFInfo2 != null)
                    {
                        SFInfo2.AvailSeatsF = SFInfo2.AvailSeatsF - payment.Passengers.Count();
                    }
                    if (SReFInfo != null)
                    {
                        SReFInfo.AvailSeatsF = SReFInfo.AvailSeatsF - payment.Passengers.Count();
                    }
                }
                else if (payment.Class == "B")
                {
                    SFInfo1.AvailSeatsB = SFInfo1.AvailSeatsB - payment.Passengers.Count();
                    if (SFInfo2 != null)
                    {
                        SFInfo2.AvailSeatsB = SFInfo2.AvailSeatsB - payment.Passengers.Count();
                    }
                    if (SReFInfo != null)
                    {
                        SReFInfo.AvailSeatsB = SReFInfo.AvailSeatsB - payment.Passengers.Count();
                    }
                }
                else
                {
                    SFInfo1.AvailSeatsE = SFInfo1.AvailSeatsE - payment.Passengers.Count();
                    if (SFInfo2 != null)
                    {
                        SFInfo2.AvailSeatsE = SFInfo2.AvailSeatsE - payment.Passengers.Count();
                    }
                    if (SReFInfo != null)
                    {
                        SReFInfo.AvailSeatsE = SReFInfo.AvailSeatsE - payment.Passengers.Count();
                    }
                }
                db.SaveChanges();


                // Skymile
                if (order.Status == 1)
                {
                    int dis1  = 0;
                    int dis2  = 0;
                    int reDis = 0;
                    var objD1 = db.FlightDistance.Where(fd => fd.AirportID1 == FInfo1.Route.Departure && fd.AirportID2 == FInfo1.Route.Destination).FirstOrDefault();
                    if (objD1 == null)
                    {
                        objD1 = db.FlightDistance.Where(fd => fd.AirportID1 == FInfo1.Route.Destination && fd.AirportID2 == FInfo1.Route.Departure).FirstOrDefault();
                    }
                    dis1 = objD1.Distance * payment.Passengers.Count();

                    if (FInfo2 != null)
                    {
                        var objD2 = db.FlightDistance.Where(fd => fd.AirportID1 == FInfo2.Route.Departure && fd.AirportID2 == FInfo2.Route.Destination).FirstOrDefault();
                        if (objD2 == null)
                        {
                            objD2 = db.FlightDistance.Where(fd => fd.AirportID1 == FInfo2.Route.Destination && fd.AirportID2 == FInfo2.Route.Departure).FirstOrDefault();
                        }
                        dis2 = objD2.Distance * payment.Passengers.Count();
                    }

                    if (ReFInfo != null)
                    {
                        var objReD = db.FlightDistance.Where(fd => fd.AirportID1 == ReFInfo.Route.Departure && fd.AirportID2 == ReFInfo.Route.Destination).FirstOrDefault();
                        if (objReD == null)
                        {
                            objReD = db.FlightDistance.Where(fd => fd.AirportID1 == ReFInfo.Route.Destination && fd.AirportID2 == ReFInfo.Route.Departure).FirstOrDefault();
                        }
                        reDis = objReD.Distance * payment.Passengers.Count();
                    }

                    db.User.FirstOrDefault(u => u.UserID == order.UserID).Skymiles += dis1 + dis2 + reDis;
                }
                db.SaveChanges();

                // Charging creditcard
                if (!isBlocked)
                {
                    card.Balance = card.Balance - Total;
                }

                // Saving changes
                db.SaveChanges();
                return("ok:" + OrderID);
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }