コード例 #1
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            if (_selected == -1)
            {
                return;
            }
            using (var db = new AirlinesContext())
            {
                var passenger = db.Passengers.Find(_email);

                var flight = db.Flights.Find((int)FlightView.Rows[_selected].Cells["Id"].Value);
                var ticket = db.Tickets.Find(flight.Id, passenger.Email);

                if (ticket == null)
                {
                    ticket           = db.Tickets.Create();
                    ticket.Flight    = flight;
                    ticket.Passenger = passenger;
                    ticket.Count     = 1;
                    db.Tickets.Add(ticket);
                }
                else
                {
                    ticket.Count = ticket.Count + 1;
                }


                db.SaveChanges();
            }

            this.Close();
        }
コード例 #2
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            using (var db = new AirlinesContext())
            {
                Flight flight;
                var    date1 = DepartureBox.Value;
                var    date2 = ArrivalBox.Value;

                do
                {
                    flight           = db.Flights.Create();
                    flight.Route_id  = _route.Id;
                    flight.Departure = date1;
                    flight.Arrival   = date2;
                    db.Flights.Add(flight);

                    if (RepeatBox.SelectedIndex == 0)
                    {
                        date1 = date1.AddDays(1);
                        date2 = date2.AddDays(1);
                    }
                    else
                    {
                        date1 = date1.AddDays(7);
                        date2 = date2.AddDays(7);
                    }
                } while (CheckBox.Checked && DepartureBox.Value.AddMonths((int)MonthBox.Value) > date1);

                db.SaveChanges();
            }

            this.Close();
        }
コード例 #3
0
        private void SearchFlightsForm_Load(object sender, EventArgs e)
        {
            using (var db = new AirlinesContext())
            {
                _routes =
                    db.Routes.Select(
                        x =>
                        new RouteModel
                {
                    Id          = x.Id,
                    Origin      = x.OriginLocation.Airport,
                    Destination = x.DestinationLocation.Airport
                }).ToList();
            }

            RouteBox.DataSource = _routes.Select(x => x.Origin + " -> " + x.Destination).ToArray();

            if (_routes.Count > 0)
            {
                RouteBox_SelectedIndexChanged(this, new EventArgs());
            }

            DataGridViewCheckBoxColumn Select = new DataGridViewCheckBoxColumn();

            Select.HeaderText = "Select";
            Select.Name       = "Select";
            FlightView.Columns.Add(Select);
        }
コード例 #4
0
        private void LoadFlights()
        {
            using (var db = new AirlinesContext())
            {
                var routeId   = _routes[RouteBox.SelectedIndex].Id;
                var passenger = db.Passengers.Find(_email);

                _flights =
                    db.Flights.Where(x => x.Route.Id == routeId && x.Plane != null && (x.Tickets.Sum(y => y.Count) < x.Plane.Seat_count) || (x.Tickets.Count == 0))
                    .Select(x => new FlightModel
                {
                    Id = x.Id,
                    DestinationLocation = x.Route.DestinationLocation,
                    OriginLocation      = x.Route.OriginLocation,
                    Arrival             = x.Arrival,
                    Departure           = x.Departure,
                    PlaneModel          = x.Plane.Model
                })
                    .OrderBy(x => x.Departure)
                    .ToList();
            }

            foreach (var f in _flights)
            {
                f.FlightDuration = f.Arrival -
                                   TimeZoneInfo.ConvertTimeBySystemTimeZoneId(f.Departure, f.OriginLocation.Timezone,
                                                                              f.DestinationLocation.Timezone);
            }
        }
コード例 #5
0
        private void RegisterButton_Click(object sender, EventArgs e)
        {
            if (Validation())
            {
                using (var db = new AirlinesContext())
                {
                    var passenger = db.Passengers.Create();
                    if (db.Passengers.Find(EmailBox.Text.ToLower()) == null)
                    {
                        passenger.Name     = NameBox.Text;
                        passenger.Surname  = SurnameBox.Text;
                        passenger.Email    = EmailBox.Text.ToLower();
                        passenger.Password = PasswordBox.Text.Encrypt();

                        db.Passengers.Add(passenger);
                        db.SaveChanges();

                        this.Close();
                    }
                    else
                    {
                        Error.Visible = true;
                        Error.Text    = "Email already used";
                    }
                }
            }
        }
コード例 #6
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            using (var db = new AirlinesContext())
            {
                var flight = db.Flights.Find(_flight.Id);

                foreach (DataGridViewRow r in PilotsDataGrid.Rows)
                {
                    var d        = (DataRowView)r.DataBoundItem;
                    var employee = db.Employees.Find(d.Row[0]);

                    if (r.Cells[SelectColumnIndex].Value != null &&
                        (bool?)r.Cells[SelectColumnIndex].Value == true)
                    {
                        flight.Employees.Add(employee);
                    }
                    else
                    {
                        flight.Employees.Remove(employee);
                    }
                }

                db.SaveChanges();
            }


            this.Close();
        }
コード例 #7
0
        private void UpdateLocations()
        {
            _locations.Clear();

            using (var db = new AirlinesContext())
            {
                foreach (var l in db.Locations)
                {
                    _locations.Add(l.Airport);
                }
            }
        }
コード例 #8
0
        private void DeletePlane(int rowIndex)
        {
            var d = (DataRowView)PlaneDataGrid.Rows[rowIndex].DataBoundItem;

            using (var db = new AirlinesContext())
            {
                db.Planes.Remove(db.Planes.Find(d.Row[0]));
                db.SaveChanges();
            }

            PlaneForm_Load(this, new EventArgs());
        }
コード例 #9
0
        private void DeleteAttendant(int rowIndex)
        {
            var d = (DataRowView)AttendantsDataGrid.Rows[rowIndex].DataBoundItem;

            using (var db = new AirlinesContext())
            {
                db.Employees.Remove(db.Employees.Find(d.Row[0]));
                db.SaveChanges();
            }

            EmployeesForm_Load(this, new EventArgs());
        }
コード例 #10
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            using (var db = new AirlinesContext())
            {
                var route = db.Routes.Create();
                route.Origin      = OriginBox.Text;
                route.Destination = DestinationBox.Text;

                db.Routes.AddOrUpdate(route);
                db.SaveChanges();
            }

            this.Close();
        }
コード例 #11
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            if (Validation())
            {
                using (var db = new AirlinesContext())
                {
                    var location = db.Locations.Create();
                    location.Airport  = LocationBox.Text;
                    location.Timezone = _zones[TimezoneBox.SelectedIndex].Id;

                    db.Locations.Add(location);
                    db.SaveChanges();
                }

                this.Close();
            }
        }
コード例 #12
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            using (var db = new AirlinesContext())
            {
                var pilot = db.Employees.Create <Pilot>();
                pilot.Id           = _id ?? default(int);
                pilot.Name         = NameTextBox.Text;
                pilot.Surname      = SurnameTextBox.Text;
                pilot.Birth        = BirthDatePicker.Value;
                pilot.License      = LicenseTextBox.Text;
                pilot.License_date = LicenseDatePicker.Value;

                db.Employees.AddOrUpdate(pilot);
                db.SaveChanges();
            }

            this.Close();
        }
コード例 #13
0
        private void EditPlane(int rowIndex)
        {
            Plane plane;
            var   d = (DataRowView)PlaneDataGrid.Rows[rowIndex].DataBoundItem;

            using (var db = new AirlinesContext())
            {
                plane = db.Planes.Find(d.Row[0]);
            }

            var editPlaneForm = new AddEditPlaneForm(plane);

            this.Enabled = false;

            editPlaneForm.FormClosed += (a, b) => { PlaneForm_Load(a, b);
                                                    this.Enabled = true; };
            editPlaneForm.Show();
        }
コード例 #14
0
        private void EditPilot(int rowIndex)
        {
            Pilot pilot;
            var   d = (DataRowView)PilotsDataGrid.Rows[rowIndex].DataBoundItem;

            using (var db = new AirlinesContext())
            {
                pilot = (Pilot)db.Employees.Find(d.Row[0]);
            }

            var editPlaneForm = new AddEditPilotForm(pilot);

            this.Enabled = false;

            editPlaneForm.FormClosed += (a, b) => { EmployeesForm_Load(a, b);
                                                    this.Enabled = true; };
            editPlaneForm.Show();
        }
コード例 #15
0
        private void EditAttendant(int rowIndex)
        {
            Attendant attendant;
            var       d = (DataRowView)AttendantsDataGrid.Rows[rowIndex].DataBoundItem;

            using (var db = new AirlinesContext())
            {
                attendant = (Attendant)db.Employees.Find(d.Row[0]);
            }

            var editAttendantForm = new AddEditAttendantForm(attendant);

            this.Enabled = false;

            editAttendantForm.FormClosed += (a, b) => { EmployeesForm_Load(a, b);
                                                        this.Enabled = true; };
            editAttendantForm.Show();
        }
コード例 #16
0
        private void ConfirmAddPlane_Click(object sender, EventArgs e)
        {
            using (var db = new AirlinesContext())
            {
                var plane = db.Planes.Create();
                plane.Id         = PlaneId.Text;
                plane.Seat_count = (int)PlaneSeatCount.Value;
                plane.Model      = PlaneModel.Text;

                if (!PlaneId.Enabled || db.Planes.Find(plane.Id) == null)
                {
                    db.Planes.AddOrUpdate(plane);
                }

                db.SaveChanges();
            }

            this.Close();
        }
コード例 #17
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            using (var db = new AirlinesContext())
            {
                Passenger passenger = db.Passengers.Find(EmailTextBox.Text.ToLower());
                Admin     admin     = db.Admins.Find(EmailTextBox.Text.ToLower());

                if (passenger != null)
                {
                    if (passenger.Password == PasswordTextBox.Text.Encrypt())
                    {
                        var form = new PassengerForm(passenger.Email);
                        form.Closed += (a, b) => this.Close();
                        this.Visible = false;
                        form.Show();
                    }
                    else
                    {
                        WrongPassword();
                    }
                }
                else if (admin != null)
                {
                    if (admin.Password == PasswordTextBox.Text.Encrypt())
                    {
                        var form = new AdminForm();
                        form.Closed += (a, b) => this.Close();
                        this.Visible = false;
                        form.Show();
                    }
                    else
                    {
                        WrongPassword();
                    }
                }
                else
                {
                    WrongEmail();
                }
            }
        }
コード例 #18
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            if (Validation())
            {
                using (var db = new AirlinesContext())
                {
                    var attendant = db.Employees.Create <Attendant>();
                    attendant.Id      = _id ?? default(int);
                    attendant.Name    = NameTextBox.Text;
                    attendant.Surname = SurnameTextBox.Text;
                    attendant.Birth   = BirthDatePicker.Value;
                    attendant.Height  = (byte)HeightBox.Value;
                    attendant.Gender  = GenderBox.Text;

                    db.Employees.AddOrUpdate(attendant);
                    db.SaveChanges();
                }

                this.Close();
            }
        }
コード例 #19
0
        private void SelectAttendantsForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'databaseDataSet.AttendantInfo' table. You can move, or remove it, as needed.
            this.attendantInfoTableAdapter.Fill(this.databaseDataSet.AttendantInfo);

            using (var db = new AirlinesContext())
            {
                var flight      = db.Flights.Find(_flight.Id);
                var employeeIds = new HashSet <int>(flight.Employees.Select(x => x.Id));
                //tbh I just want to finish already
                foreach (DataGridViewRow r in AttendantsDataGrid.Rows)
                {
                    var d = (DataRowView)r.DataBoundItem;

                    if (employeeIds.Contains((int)d.Row[0]))
                    {
                        r.Cells[SelectColumnIndex].Value = true;
                    }
                }
            }
        }
コード例 #20
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            using (var db = new AirlinesContext())
            {
                var flight = db.Flights.Find(_flight.Id);

                if (_selected == -1)
                {
                    flight.Plane_id = null;
                }
                else
                {
                    flight.Plane_id = (string)PlaneDataGrid.Rows[_selected].Cells[0].Value;
                }

                db.SaveChanges();
            }


            this.Close();
        }
コード例 #21
0
        private void EditFlight(int rowIndex, int columnIndex)
        {
            Flight flight;
            var    d = (DataRowView)FlightDataGrid.Rows[rowIndex].DataBoundItem;
            Form   form;

            using (var db = new AirlinesContext())
            {
                flight = db.Flights.Find(d.Row[0]);
            }

            switch (columnIndex)
            {
            case PlaneColumnIndex:
                form = new SelectPlaneForm(flight);
                break;

            case PilotsColumnIndex:
                form = new SelectPilotsForm(flight);
                break;

            case AttendantsColumnIndex:
                form = new SelectAttendantsForm(flight);
                break;

            case PassengersColumnIndex:
                form = new ViewPassengersForm(flight);
                break;

            default:
                form = new ErrorForm();
                break;
            }

            this.Enabled = false;

            form.FormClosed += (a, b) => this.Enabled = true;

            form.Show();
        }
コード例 #22
0
        private void SelectPilotsForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'databaseDataSet.PilotInfo' table. You can move, or remove it, as needed.
            this.pilotInfoTableAdapter.Fill(this.databaseDataSet.PilotInfo);

            using (var db = new AirlinesContext())
            {
                var flight = db.Flights.Find(_flight.Id);

                //tbh I just want to finish already
                foreach (DataGridViewRow r in PilotsDataGrid.Rows)
                {
                    var d = (DataRowView)r.DataBoundItem;

                    foreach (var p in flight.Employees)
                    {
                        if ((int)d.Row[0] == p.Id)
                        {
                            r.Cells[SelectColumnIndex].Value = true;
                        }
                    }
                }
            }
        }
コード例 #23
0
        private void LoadFlights()
        {
            using (var db = new AirlinesContext())
            {
                var passenger = db.Passengers.Find(_email);

                _flights = passenger.Tickets.Select(x => new FlightModel
                {
                    DestinationLocation = x.Flight.Route.DestinationLocation,
                    OriginLocation      = x.Flight.Route.OriginLocation,
                    Arrival             = x.Flight.Arrival,
                    Departure           = x.Flight.Departure,
                    PlaneModel          = x.Flight.Plane.Model,
                    TicketCount         = x.Count
                }).ToList();
            }

            foreach (var f in _flights)
            {
                f.FlightDuration = f.Arrival -
                                   TimeZoneInfo.ConvertTimeBySystemTimeZoneId(f.Departure, f.OriginLocation.Timezone,
                                                                              f.DestinationLocation.Timezone);
            }
        }