示例#1
0
        //populate drop down with seat rows
        private void PopulateSeatRows()
        {
            using (AirlineEntities context = new AirlineEntities())
            {
                var seatRows = context.Seats.OrderBy(s => s.SeatRow).ThenBy(s => s.SeatColumn).Select(s => s.SeatRow).Distinct().ToList();

                foreach (var row in seatRows)
                {
                    cboSeatRow.Items.Add(row);
                }
            }
        }
示例#2
0
        //Display the seats in the list box
        private void PopulateAirplane()
        {
            //clear previous listbox and list of Seats
            lstOutput.Items.Clear();
            seatList.Clear();

            //Select * seats from Seats table. Read results and create a Seat object with
            //ID, Row, Column and IsTaken property from the reader
            //Add the Seat object to the list
            //Loop through the list and display the content in the list box
            using (AirlineEntities context = new AirlineEntities())
            {
                var seats = context.Seats.OrderBy(s => s.SeatRow).ThenBy(s => s.SeatColumn).ToList();
                foreach (var seat in seats)
                {
                    var s = new Seat
                    {
                        SeatID     = seat.SeatID,
                        SeatRow    = seat.SeatRow,
                        SeatColumn = seat.SeatColumn,
                        IsTaken    = seat.IsTaken
                    };
                    seatList.Add(s);
                }

                var msg     = "";
                var counter = 0;
                for (int i = 0; i < seatList.Count; i++)
                {
                    counter++;
                    var  seat      = seatList[i];
                    bool available = seatList[i].IsSeatTaken(seat.SeatID);
                    if (available == true)
                    {
                        msg += "   " + seatList[i].SeatRow + seatList[i].SeatColumn + "   ";
                    }
                    else
                    {
                        msg += "   XX            ";
                    }
                    if (counter % 4 == 0)
                    {
                        lstOutput.Items.Add(msg);
                        msg = "";
                    }
                    else if (counter % 2 == 0)
                    {
                        msg += "  ";
                    }
                }
            }
        }
示例#3
0
 //check if the plane is full (used to place passenger on waiting list)
 public bool IsPlaneFull()
 {
     using (AirlineEntities context = new AirlineEntities())
     {
         var isFull = (from s in context.Seats
                       where s.IsTaken == false
                       select s).Count();
         if (isFull > 0)
         {
             return(false);
         }
     }
     return(true);
 }
示例#4
0
        private void frmReservations_Load(object sender, EventArgs e)
        {
            using (AirlineEntities context = new AirlineEntities())
            {
                context.Passengers.ToList();
                context.Seats.ToList();

                this.passengerBindingSource.DataSource = context.Passengers.Local.ToBindingList();
                this.seatBindingSource.DataSource      = context.Seats.Local.ToBindingList();

                PopulateAirplane();
                PopulateSeatRows();
            }
        }
示例#5
0
        //check if seat is already taken
        public bool IsSeatTaken(int SeatID)
        {
            using (AirlineEntities context = new AirlineEntities())
            {
                //var seat = context.Database.ExecuteSqlCommand("SELECT * FROM seats WHERE SeatRow = @SeatRow and SeatColumn = @SeatColumn" +
                //    "AND IsTaken = false");
                var seat = context.Seats.Find(SeatID);

                if (seat.IsTaken == true)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }