private void button1Ok_Click(object sender, EventArgs e)
        {
            try
            {
                FlightCollection File    = new FlightCollection("Flights.txt");
                Flight           Current = File.FindByNumber(Number);

                string depDay = dateTimePicker1DepartureDay.Value.Day.ToString() + "."
                                + dateTimePicker1DepartureDay.Value.Month.ToString() + "."
                                + dateTimePicker1DepartureDay.Value.Year.ToString();
                string arrDay = dateTimePicker2arrivalDay.Value.Day.ToString() + "."
                                + dateTimePicker2arrivalDay.Value.Month.ToString() + "."
                                + dateTimePicker2arrivalDay.Value.Year.ToString();
                string depTime = numericUpDown1DepHour.Value + ":" + numericUpDown2DepMinutes.Value;
                string arrTime = numericUpDown1ArrHours.Value + ":" + numericUpDown1ArrMinutes.Value;

                string StopStation = Program.RemoveSpaces(textBox3stopstat.Text);

                if (StopStation != "")
                {
                    Current.AddStopStation(StopStation);
                }

                Current.Departure = Convert.ToDateTime(depDay + " " + depTime);
                Current.Arrival   = Convert.ToDateTime(arrDay + " " + arrTime);
                File.ClearFile();
                File.WriteInFile();
                this.Close();
                Program.MainForm.OnLoadFuction();
            }
            catch (Exception myexp)
            {
                MessageBox.Show(myexp.Message, "Оповещение");
            }
        }
        private void button2Ok_Click(object sender, EventArgs e)
        {
            try
            {
                string Name       = textBox1Name.Text;
                string Surname    = textBox2Surname.Text;
                string Middlename = textBox3Middlename.Text;

                string  num   = FlightTable.CurrentRow.Cells[0].Value.ToString();
                decimal count = numericUpDown1Count.Value;

                Passenger        user = new Passenger(Name, Surname, Middlename);
                FlightCollection arr  = new FlightCollection("Flights.txt");

                Flight Current = arr.FindByNumber(Convert.ToInt32(num));
                Current.AddPassenger(user, count);

                MessageBox.Show("Пассажир добавлен!", "Оповещение");
                this.Close();
                Program.MainForm.OnLoadFuction();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Не выбрано ни одного рейса!", "Оповещение");
            }
            catch (Exception my)
            {
                MessageBox.Show(my.Message, "Оповещение");
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            string           num  = FlightTable1.CurrentRow.Cells[0].Value.ToString();
            FlightCollection file = new FlightCollection("Flights.txt");

            file.RemoveFlightAndFile(num);
            file.ClearFile();
            file.WriteInFile();
            OnLoadFuction();
        }
        public void OnLoadFuction()
        {
            foreach (DataGridViewColumn colum in FlightTable1.Columns)
            {
                colum.SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            try
            {
                FlightTable1.Rows.Clear();

                FlightCollection list = new FlightCollection("Flights.txt");
                list.SortingByDays();

                for (int i = list.Count - 1; i >= 0; i--)
                {
                    FlightTable1.Rows.Add(list[i].Number,
                                          list[i].FreePlaces,
                                          list[i].DepartureFrom,
                                          list[i].ArrivalIn,
                                          list[i].Departure.TimeOfDay.ToString("hh':'mm"),
                                          list[i].Departure.Date.ToString().Split(' ')[0],
                                          list[i].Arrival.TimeOfDay.ToString("hh':'mm"),
                                          list[i].Arrival.Date.ToString().Split(' ')[0],
                                          Program.GetStopStations(list[i].StopStation));
                }
                if (FlightTable1.Rows.Count == 0)
                {
                    button3DeleteFlight.Visible  = false;
                    button5InfomOfFlight.Visible = false;
                    button2EditFlight.Visible    = false;
                }
                else
                {
                    button3DeleteFlight.Visible  = true;
                    button5InfomOfFlight.Visible = true;
                    button2EditFlight.Visible    = true;
                }
            }
            catch
            {
                this.Show();
                MessageBox.Show("Ошибка в базе данных!", "Оповещение");
                this.Close();
            }
        }
        private void SearchFlight_Click(object sender, EventArgs e)
        {
            try
            {
                FlightTable.Rows.Clear();
                string dep     = Program.RemoveSpaces(textBox4DepartureFrom.Text);
                string arrival = Program.RemoveSpaces(textBox5arrivalIn.Text);

                DateTime         now  = DateTime.Now;
                FlightCollection list = new FlightCollection("Flights.txt", dep, arrival);

                list.SortingByDays();

                for (int i = list.Count - 1; i >= 0; i--)
                {
                    if (list[i].Departure > now)
                    {
                        FlightTable.Rows.Add(list[i].Number,
                                             list[i].FreePlaces,
                                             list[i].DepartureFrom,
                                             list[i].ArrivalIn,
                                             list[i].Departure.TimeOfDay.ToString("hh':'mm"),
                                             list[i].Departure.Date.ToString().Split(' ')[0],
                                             list[i].Arrival.TimeOfDay.ToString("hh':'mm"),
                                             list[i].Arrival.Date.ToString().Split(' ')[0],
                                             Program.GetStopStations(list[i].StopStation)
                                             );
                    }
                }
                if (FlightTable.RowCount == 0) // Проверка на существование рейсов в базе данных
                {
                    MessageBox.Show("Не найдено соответствующего рейса", "Оповещение");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void Info_Load(object sender, EventArgs e)
        {
            try
            {
                foreach (DataGridViewColumn colum in ListOfPassengers.Columns)
                {
                    colum.SortMode = DataGridViewColumnSortMode.NotSortable;
                }

                FlightCollection file    = new FlightCollection("Flights.txt");
                Flight           Current = file.FindByNumber(Number);
                List <string>    rez     = new List <string>();
                rez.Add("Номер: " + Current.Number);
                rez.Add("Откуда отправляется: " + Current.DepartureFrom);
                rez.Add("Куда направляется: " + Current.ArrivalIn);
                rez.Add("Дата отправления: " + Current.Departure.Date.ToString().Split(' ')[0]);
                rez.Add("Время отправления: " + Current.Departure.TimeOfDay.ToString("hh':'mm"));
                rez.Add("Дата прибытия: " + Current.Arrival.Date.ToString().Split(' ')[0]);
                rez.Add("Время прибытия: " + Current.Arrival.TimeOfDay.ToString("hh':'mm"));
                rez.Add("Количество посадочных мест: " + Current.CountPlaces);
                rez.Add("Свободные места: " + Current.FreePlaces);
                rez.Add("Пункты промежуточной посадки: " + Program.GetStopStations(Current.StopStation));

                listBox1info.DataSource = rez;

                for (int i = 0; i < Current.ListOfPassengers.Count; i++)
                {
                    ListOfPassengers.Rows.Add(Current.ListOfPassengers[i].Name,
                                              Current.ListOfPassengers[i].Surname,
                                              Current.ListOfPassengers[i].MiddleName);
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Ошибка: время отправления этого рейса стало меньше текущего.", "Оповещение");
                this.Close();
                Program.MainForm.OnLoadFuction();
            }
        }
 private void EditFlight_Load(object sender, EventArgs e)
 {
     try
     {
         FlightCollection File    = new FlightCollection("Flights.txt");
         Flight           Current = File.FindByNumber(Number);
         textBox1dep.Text                  = Current.DepartureFrom;
         textBox1arr.Text                  = Current.ArrivalIn;
         textBox1num.Text                  = Current.Number.ToString();
         numericUpDown1DepHour.Value       = Current.Departure.TimeOfDay.Hours;
         numericUpDown2DepMinutes.Value    = Current.Departure.TimeOfDay.Minutes;
         numericUpDown1ArrHours.Value      = Current.Arrival.TimeOfDay.Hours;
         numericUpDown1ArrMinutes.Value    = Current.Arrival.TimeOfDay.Minutes;
         dateTimePicker1DepartureDay.Value = Current.Departure;
         dateTimePicker2arrivalDay.Value   = Current.Arrival;
     }
     catch (NullReferenceException)
     {
         MessageBox.Show("Ошибка: время отправления этого рейса стало меньше текущего.", "Оповещение");
         this.Close();
         Program.MainForm.OnLoadFuction();
     }
 }
Beispiel #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string Number = Program.RemoveSpaces(textBox1Number.Text);
                string depDay = dateTimePicker1DepartureDay.Value.Day.ToString() + "."
                                + dateTimePicker1DepartureDay.Value.Month.ToString() + "."
                                + dateTimePicker1DepartureDay.Value.Year.ToString();
                string arrDay = dateTimePicker2ArrivalDay.Value.Day.ToString() + "."
                                + dateTimePicker2ArrivalDay.Value.Month.ToString() + "."
                                + dateTimePicker2ArrivalDay.Value.Year.ToString();
                string   depTime      = numericUpDown4DepHours.Value + ":" + numericUpDown5DepMinutes.Value;
                string   arrTime      = numericUpDown1ArrHours.Value + ":" + numericUpDown2ArrMinutes.Value;
                string[] StopStations = Program.RemoveSpaces(textBox1StopStations.Text).Split(',');

                string DepartureFrom = Program.RemoveSpaces(textBox1DepartureFrom.Text);
                string ArrivalIn     = Program.RemoveSpaces(textBox1ArrivalIn.Text);
                int    countPlaces   = Convert.ToInt32(numericUpDown6countPlaces.Value);

                if (Convert.ToDateTime(depDay + " " + depTime) <= DateTime.Now)
                {
                    MessageBox.Show("Время и дата отправления должны быть больше текущих.", "Оповещение");
                    return;
                }
                if (DepartureFrom == "" || ArrivalIn == "")
                {
                    MessageBox.Show("Укажите маршрут", "Оповещение");
                    return;
                }



                Flight           newFlight;
                FlightCollection file    = new FlightCollection("Flights.txt");
                Flight           Current = file.FindByNumber(Convert.ToInt32(Number));

                if (Current == null)
                {
                    newFlight = new Flight(Number, DepartureFrom, ArrivalIn, depTime, depDay, arrTime, arrDay, countPlaces, StopStations);
                    file.AddFlightAndWriteInFile(newFlight);
                }
                else
                {
                    MessageBox.Show("Рейс с таким номером уже существует.", "Оповещение");
                    return;
                }
                this.Close();
                Program.MainForm.OnLoadFuction();
            }
            catch (FormatException)
            {
                MessageBox.Show("Проверьте правильность введённых данных.", "Оповещение");
            }
            catch (ArithmeticException)
            {
                MessageBox.Show("Номер не может состоять более, чем из 9 цифр", "Оповещение");
            }
            catch (Exception my)
            {
                MessageBox.Show(my.Message, "Оповещение");
            }
        }