示例#1
0
        public async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            bool isNumber = int.TryParse(formExperience.Text, out int n);

            if (isNumber)
            {
                Pilot f = new Pilot()
                {
                    Name       = formName.Text,
                    Surname    = formSurname.Text,
                    Experience = Int32.Parse(formExperience.Text)
                };
                if (PilotService.Validate(f))
                {
                    Form.Visibility = Visibility.Collapsed;
                    if (FormTitle.Text == "New Pilot")
                    {
                        if (!await PilotService.Add(f))
                        {
                            WrongInput.Visibility = Visibility.Visible;
                        }
                        WrongInput.Visibility = Visibility.Collapsed;
                        return;
                    }
                    if (FormTitle.Text == "Edit Pilot")
                    {
                        if (!await PilotService.Update(f))
                        {
                            WrongInput.Visibility = Visibility.Visible;
                        }
                        WrongInput.Visibility = Visibility.Collapsed;
                        return;
                    }
                }
            }
            WrongInput.Visibility = Visibility.Visible;
        }
示例#2
0
        public async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            bool isNumber2 = int.TryParse(formExperience.Text, out int experience);
            bool isNumber3 = int.TryParse(formNumberOfSeats.Text, out int numberOfSeats);
            bool isNumber4 = int.TryParse(formLoadCapacity.Text, out int loadCapacity);

            if (formReleaseDate.Date.HasValue && isNumber2 && isNumber3 && isNumber4 &&
                formArrivalTime.Date.HasValue && formTimeOfDeparture.Date.HasValue && formDateOfBirth.Date.HasValue &&
                formTimeOfDeparture2.Date.HasValue)
            {
                Stewardess s = new Stewardess()
                {
                    Name        = formStewardessName.Text,
                    Surname     = formStewardessSurname.Text,
                    CrewId      = 1,
                    DateOfBirth = formDateOfBirth.Date.Value.Date
                };

                Pilot pil = new Pilot()
                {
                    Name       = formPilotName.Text,
                    Surname    = formPilotSurname.Text,
                    Experience = experience
                };

                Plane p = new Plane()
                {
                    ReleaseDate = formReleaseDate.Date.Value.Date,
                    PlaneType   = new PlaneType()
                    {
                        Model         = formModel.Text,
                        NumberOfSeats = numberOfSeats,
                        LoadCapacity  = loadCapacity
                    }
                };
                Flight f = new Flight()
                {
                    Destination     = formDestination.Text,
                    DepartureFrom   = formDepartureFrom.Text,
                    ArrivalTime     = formArrivalTime.Date.Value.Date,
                    TimeOfDeparture = formTimeOfDeparture.Date.Value.Date
                };



                Departure d = new Departure()
                {
                    Crew = new Crew()
                    {
                        Pilot        = pil,
                        Stewardesses = new List <Stewardess>()
                        {
                            s
                        }
                    },
                    Flight          = f,
                    Plane           = p,
                    TimeOfDeparture = formTimeOfDeparture2.Date.Value.Date
                };

                if (DepartureService.Validate(d))
                {
                    Form.Visibility = Visibility.Collapsed;
                    if (FormTitle.Text == "New Departure")
                    {
                        if (!await DepartureService.Add(d))
                        {
                            WrongInput.Visibility = Visibility.Visible;
                        }
                        WrongInput.Visibility = Visibility.Collapsed;
                        return;
                    }
                    if (FormTitle.Text == "Edit Departure")
                    {
                        if (!await DepartureService.Update(d))
                        {
                            WrongInput.Visibility = Visibility.Visible;
                        }
                        WrongInput.Visibility = Visibility.Collapsed;
                        return;
                    }
                }
            }
            WrongInput.Visibility = Visibility.Visible;
        }