Пример #1
0
        public static AirCompany RestoreDates(AirCompany company)
        {
            //JsonSerializer serializer = new JsonSerializer();
            //using (StreamReader In = new StreamReader(Constants.path))
            //using(JsonReader jsr = new JsonTextReader(In))
            StreamReader In;

            try
            {
                In = new StreamReader(Constants.path);
                for (string s = In.ReadLine(); s != null; s = In.ReadLine())
                {
                    flight f = JsonConvert.DeserializeObject <flight>(s);
                    if (f.typeOfPlane.Equals(Constants.typeOfPlaneIsCargo))
                    {
                        company.AddCargoFlight(Convert.ToInt32(f.flightNumber), Convert.ToDouble(f.curbWeight) - Constants.emptyWeightOfCargoPlane, f.names);
                    }
                    if (f.typeOfPlane.Equals(Constants.typeOfPlaneIsPassenger))
                    {
                        company.AddPassengerFlight(Convert.ToInt32(f.flightNumber), (int)((Convert.ToDouble(f.curbWeight) - Constants.emptyWeightOfPassengerPlane) / Constants.averagePassengerWeight), f.names);
                    }
                }
                In.Close();
            }
            catch
            {
                return(company);
            }
            return(company);
        }
Пример #2
0
        private void Bt_next_Click(object sender, RoutedEventArgs e)
        {
            if (modeType)
            {
                Bt_next.Content                = "Добавить";
                Bt_cancel.Content              = "Назад";
                Txt_type.Visibility            = Visibility.Collapsed;
                TypeList.Visibility            = Visibility.Collapsed;
                modeType                       = false;
                Txt_flight.Visibility          = Visibility.Visible;
                Tb_flight.Visibility           = Visibility.Visible;
                Tb_count_or_weight.Visibility  = Visibility.Visible;
                Txt_count_or_weight.Visibility = Visibility.Visible;
                Txt_aircrew.Visibility         = Visibility.Visible;
                Txt_pilot1.Visibility          = Visibility.Visible;
                Tb_pilot1.Visibility           = Visibility.Visible;
                Txt_pilot2.Visibility          = Visibility.Visible;
                Tb_pilot2.Visibility           = Visibility.Visible;
                if (typeCargo)
                {
                    Txt_count_or_weight.Text = Constants.str_curb_weight;
                }
                else
                {
                    Txt_count_or_weight.Text = Constants.str_count_of_borarding_seats;
                    Txt_stuard1.Visibility   = Visibility.Visible;
                    Tb_stuard1.Visibility    = Visibility.Visible;
                    Txt_stuard2.Visibility   = Visibility.Visible;
                    Tb_stuard2.Visibility    = Visibility.Visible;
                }
            }
            else
            {
                if (typeCargo)
                {
                    int    flightNumber = 0;
                    double curbWeight   = 0;
                    string members      = "";
                    try
                    {
                        flightNumber = Convert.ToInt32(Tb_flight.Text);
                        curbWeight   = Convert.ToDouble(Tb_count_or_weight.Text);

                        if (Tb_pilot1.Text.Equals("") || Tb_pilot1.Text.Equals(" ") || Tb_pilot2.Text.Equals("") || Tb_pilot2.Text.Equals(""))
                        {
                            ErrorCallback("Не все поля заполнены!!!");
                            return;
                        }
                        members += (Tb_pilot1.Text + " : Пилот №1\n");
                        members += (Tb_pilot2.Text + " : Пилот №2");
                    }
                    catch
                    {
                        ErrorCallback("ОШИБКА!!!");
                        return;
                    }
                    if (!company.AddCargoFlight(flightNumber, curbWeight, members))
                    {
                        ErrorCallback("Рейс с таким номером уже существует!!!");
                        return;
                    }
                }
                else
                {
                    int    flightNumber = 0;
                    int    countOfSeats = 0;
                    string members      = "";
                    try {
                        flightNumber = Convert.ToInt32(Tb_flight.Text);
                        countOfSeats = Convert.ToInt32(Tb_count_or_weight.Text);

                        if (Tb_pilot1.Text.Equals("") || Tb_pilot1.Text.Equals(" ") || Tb_pilot2.Text.Equals(" ") || Tb_pilot2.Text.Equals("") || Tb_stuard1.Text.Equals(" ") || Tb_stuard1.Text.Equals("") || Tb_stuard2.Text.Equals(" ") || Tb_stuard2.Text.Equals(""))
                        {
                            ErrorCallback("Не все поля заполнены!!!");
                            return;
                        }

                        members += (Tb_pilot1.Text + " : Пилот №1\n");
                        members += (Tb_pilot2.Text + " : Пилот №2\n");
                        members += (Tb_stuard1.Text + " : борт.проводник №1\n");
                        members += (Tb_stuard2.Text + " : борт.проводник №2");
                    }
                    catch {
                        ErrorCallback("ОШИБКА!!!");
                        return;
                    }
                    if (!company.AddPassengerFlight(flightNumber, countOfSeats, members))
                    {
                        ErrorCallback("Рейс с таким номером уже существует!!!");
                        return;
                    }
                }
                Close();
            }
        }