//Удалить рейс
        private void ButtonClick_DelFlight(object sender, RoutedEventArgs e)
        {
            try
            {
                MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);

                int index = DataGridFlights.SelectedIndex;

                dynamic std  = DataGridFlights.SelectedItems;
                short   ind  = std[0].FlightID;
                string  ind2 = std[0].SideNumber;

                dboperator.ExecuteCommand("DELETE FROM Flight where FlightID = {0}", ind);
                DataGridFlights.Items.RemoveAt(index);

                Aircraft Aircr = dboperator.aircrafts.Where(airc => airc.SideNumber == ind2).FirstOrDefault();
                Aircr.IsFree = true;

                dboperator.SubmitChanges();
            }
            catch
            {
                ErrorTextBlock.Text       = "Выделите строку для удаления";
                ErrorTextBlock.Visibility = Visibility.Visible;
            }
        }
        void QueryFlightNumber()
        {
            DataGridFlights.Items.Clear();
            MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);

            var flights = from fl in dboperator.flights
                          join airc in dboperator.airlines on fl.AirlineID equals airc.AirlineID
                          join air in dboperator.aircrafts on fl.AircraftID equals air.AircraftID
                          where fl.FlightNumber.Contains(SortBox.Text) || air.SideNumber.Contains(SortBox.Text) || air.AircraftModel.Contains(SortBox.Text) || airc.AirlineName.Contains(SortBox.Text) || fl.DepatureCity.Contains(SortBox.Text) || fl.ArrivalCity.Contains(SortBox.Text)
                          select new
            {
                fl.ArrivalCity,
                fl.ArrivalTime,
                fl.DepartureTime,
                fl.DepatureCity,
                fl.FlightNumber,
                airc.AirlineName,
                fl.FlightID,
                air.AircraftModel,
                air.SideNumber
            };

            foreach (var item in flights)
            {
                DataGridFlights.Items.Add(item);
            }
        }
Пример #3
0
        public static ComboBox LoadComboBoxSideNumberandAirline(ref ComboBox Airl, ref ComboBox AirlINV, ref ComboBox Aircr, ref ComboBox AircrINV)
        {
            Airl.Items.Clear();
            AirlINV.Items.Clear();
            Aircr.Items.Clear();
            AircrINV.Items.Clear();

            MyDataContext db = new MyDataContext(connectionString);

            var aircrafts = from airc in db.aircrafts
                            select new { airc.AircraftID, airc.AircraftModel, airc.IsFree };

            var airlines = from airln in db.airlines
                           select new { airln.AirlineID, airln.AirlineName };


            foreach (var item in airlines)
            {
                Airl.Items.Add(item.AirlineName);
                AirlINV.Items.Add(item.AirlineID);
            }

            foreach (var item in aircrafts)
            {
                if (item.IsFree)
                {
                    Aircr.Items.Add(item.AircraftModel);
                    AircrINV.Items.Add(item.AircraftID);
                }
            }

            return(null);
        }
        public Page1()
        {
            InitializeComponent();

            MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);


            var flights = from fl in dboperator.flights
                          join airc in dboperator.airlines on fl.AirlineID equals airc.AirlineID
                          join air in dboperator.aircrafts on fl.AircraftID equals air.AircraftID
                          select new
            {
                fl.ArrivalCity,
                fl.ArrivalTime,
                fl.DepartureTime,
                fl.DepatureCity,
                fl.FlightNumber,
                airc.AirlineName,
                fl.FlightID,
                air.AircraftModel,
                air.SideNumber
            };

            foreach (var item in flights)
            {
                DataGridFlights.Items.Add(item);
            }



            _ComboBoxHours   = CurrentUser.LoadComboBoxHours(_ComboBoxHours);
            _ComboBoxMinutes = CurrentUser.LoadComboBoxMinutes(_ComboBoxMinutes);
            CurrentUser.LoadComboBoxSideNumberandAirline(ref _ComboBoxAirlineName, ref _ComboBoxAirlineNameINV, ref _ComboBoxSideNumber, ref _ComboBoxSideNumberINV);
        }
        private void ButtonClick_DeleteAircraft(object sender, RoutedEventArgs e)
        {
            try
            {
                ErrorTextBlock.Visibility = Visibility.Collapsed;

                MyDataContext dboperator  = new MyDataContext(CurrentUser.connectionString);
                int           index       = DataGridAircraft.SelectedIndex;
                IList         delaircraft = DataGridAircraft.SelectedItems;

                if (!(delaircraft[0] as Aircraft).IsFree)
                {
                    ErrorTextBlock.Text       = "Операция запрещена пока самолет находится в расписании";
                    ErrorTextBlock.Visibility = Visibility.Visible;
                }
                else
                {
                    dboperator.ExecuteCommand("DELETE FROM Aircraft where AircraftID = {0}", (delaircraft[0] as Aircraft).AircraftID);
                    DataGridAircraft.Items.RemoveAt(index);
                }
            }
            catch (Exception)
            {
                ErrorTextBlock.Text       = "Выделите строку для удаления";
                ErrorTextBlock.Visibility = Visibility.Visible;
            }
        }
        public void Sort(bool par, byte addpar)
        {
            DataGridAircraft.Items.Clear();
            MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);


            var aircrafts = from airc in dboperator.aircrafts
                            select airc;

            if (addpar == 1)
            {
                foreach (var item in aircrafts)
                {
                    DataGridAircraft.Items.Add(item);
                }
                return;
            }
            else
            {
                foreach (var item in aircrafts)
                {
                    if (item.IsFree == par)
                    {
                        DataGridAircraft.Items.Add(item);
                    }
                }
                return;
            }
        }
Пример #7
0
        void CurrentOperators()
        {
            DataGridAll.Items.Clear();
            MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);

            var report = from fl in dboperator.flights
                         join airc in dboperator.airlines on fl.AirlineID equals airc.AirlineID
                         join aircrf in dboperator.aircrafts on fl.AircraftID equals aircrf.AircraftID
                         join op in dboperator.operators on fl.OperatorID equals op.OperatorID
                         where op.OperatorID == CurrentUser.CurrentID
                         select new
            {
                fl.ArrivalCity,
                fl.ArrivalTime,
                fl.DepartureTime,
                fl.DepatureCity,
                fl.FlightNumber,
                airc.AirlineName,
                aircrf.AircraftModel,
                aircrf.SideNumber,
                op.FirstName,
                op.SecondName
            };

            foreach (var item in report)
            {
                DataGridAll.Items.Add(item);
            }
        }
        //Авторизация в программе
        private void Button_Click_Login(object sender, RoutedEventArgs e)
        {
            MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);

            try
            {
                var entry = dboperator.ExecuteQuery <Operator>("SELECT * FROM Operator WHERE OperatorLogin COLLATE Latin1_General_CS_AS = {0} AND OperatorPassword COLLATE Latin1_General_CS_AS = {1}", LoginTextBox.Text, PasswordBox.Password).ToList();

                if (entry.Count() == 0)
                {
                    TextBlockMessage.Text   = "Неверный логин или пароль, повторите попытку";
                    WrongPassOrLogin.IsOpen = true;
                }
                else
                {
                    CurrentUser.CurrentID  = entry.Single().OperatorID;
                    CurrentUser.FirstName  = entry.Single().FirstName;
                    CurrentUser.SecondName = entry.Single().SecondName;

                    Window1 window1 = new Window1();
                    window1.Show();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                TextBlockMessage.Text   = "Не удалось подключится к базе данных";
                WrongPassOrLogin.IsOpen = true;
                return;
            }
        }
        private void ButtonClick_AddAircraft(object sender, RoutedEventArgs e)
        {
            if (_TextBlockBusinessClass.Text.Length < 1 || _TextBlockEconomyClass.Text.Length < 1 || _TextBlockFirstClass.Text.Length < 1 || _TextBlockModel.Text.Length < 1 || _TextBlockSideNumber.Text.Length < 1 || _TextBlockVipClass.Text.Length < 1)
            {
                TextBlockMessgeAddAircraft.Visibility = Visibility.Visible;
                TextBlockMessgeAddAircraft.Text       = "Заполнены не все поля";
            }
            else
            {
                try
                {
                    MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);

                    Aircraft aircraftnew = new Aircraft
                    {
                        AircraftModel = _TextBlockModel.Text,
                        SideNumber    = _TextBlockSideNumber.Text,
                        EconomyClass  = short.Parse(_TextBlockEconomyClass.Text),
                        BusinessClass = short.Parse(_TextBlockBusinessClass.Text),
                        FirstClass    = short.Parse(_TextBlockFirstClass.Text),
                        VIPClass      = short.Parse(_TextBlockVipClass.Text),
                        IsFree        = true
                    };

                    dboperator.aircrafts.InsertOnSubmit(aircraftnew);
                    dboperator.SubmitChanges();

                    TextBlockMessgeAddAircraft.Text       = "Самолет добавлен";
                    TextBlockMessgeAddAircraft.Visibility = Visibility.Visible;

                    ClearTextBoxes();

                    DataGridAircraft.Items.Add(aircraftnew);

                    if (All.IsChecked == true)
                    {
                        Sort(true, 1); return;
                    }
                    if (Free.IsChecked == true)
                    {
                        Sort(true, 0); return;
                    }
                    if (Off.IsChecked == true)
                    {
                        Sort(false, 0); return;
                    }
                }
                catch (Exception)
                {
                    TextBlockMessgeAddAircraft.Visibility = Visibility.Visible;
                    TextBlockMessgeAddAircraft.Text       = $"Номер {_TextBlockSideNumber.Text} занят";
                }
            }
        }
Пример #10
0
        public Page3()
        {
            InitializeComponent();

            MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);
            var           airlines   = dboperator.airlines;

            foreach (var item in airlines)
            {
                DataGridAirline.Items.Add(item);
            }
        }
Пример #11
0
        public static ComboBox GetOperators(ref ComboBox _Operators)
        {
            MyDataContext db         = new MyDataContext(connectionString);
            var           Qoperators = from op in db.operators
                                       select new { op.Login };

            foreach (var item in Qoperators)
            {
                _Operators.Items.Add($"{item.Login}");
            }
            _Operators.SelectedIndex = 0;
            return(null);
        }
Пример #12
0
        private void ButtonClick_DeleteAirline(object sender, RoutedEventArgs e)
        {
            try
            {
                ErrorTextBlock.Visibility = Visibility.Collapsed;

                MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);
                int           index      = DataGridAirline.SelectedIndex;
                IList         delairline = DataGridAirline.SelectedItems;

                dboperator.ExecuteCommand("DELETE FROM Airline where AirlineID = {0}", (delairline[0] as Airline).AirlineID);
                DataGridAirline.Items.RemoveAt(index);
            }
            catch (Exception)
            {
                ErrorTextBlock.Visibility = Visibility.Visible;
            }

            Message.IsOpen = false;
        }
Пример #13
0
        private void ButtonClick_AddAirline(object sender, RoutedEventArgs e)
        {
            if (_TextBlockAirlineName.Text.Length > 0 && _TextBlockCounty.Text.Length > 0)
            {
                try
                {
                    MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);

                    Airline airlinenew = new Airline
                    {
                        AirlineName = _TextBlockAirlineName.Text.Length == 0 ? null : _TextBlockAirlineName.Text,
                        Country     = _TextBlockCounty.Text.Length == 0 ? null : _TextBlockCounty.Text,
                    };

                    dboperator.airlines.InsertOnSubmit(airlinenew);
                    dboperator.SubmitChanges();

                    //TextBlockMessgeAddAirline = CurrentUser.ResetColor(TextBlockMessgeAddAirline);

                    ClearTextValues();

                    TextBlockMessgeAddAirline.Text       = "Авиакомпания добавлена";
                    TextBlockMessgeAddAirline.Visibility = Visibility.Visible;

                    DataGridAirline.Items.Add(airlinenew);
                }
                catch (System.Data.SqlClient.SqlException)
                {
                    // TextBlockMessgeAddAirline.Foreground = Brushes.Red;
                    TextBlockMessgeAddAirline.Visibility = Visibility.Visible;
                    TextBlockMessgeAddAirline.Text       = $"Имя {_TextBlockAirlineName.Text} занято";
                }
            }
            else
            {
                //TextBlockMessgeAddAirline.Foreground = Brushes.Red;
                TextBlockMessgeAddAirline.Visibility = Visibility.Visible;
                TextBlockMessgeAddAirline.Text       = "Заполнены не все поля";
            }
        }
        private void ContinueReg_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);

                if (_RepitPasswordBox.Password == _TextBoxPasswordReg.Password)
                {
                    Operator operatornew = new Operator {
                        FirstName = _TextBoxFirstName.Text, SecondName = _TextBoxSecondName.Text, Login = _TextBoxLoginReg.Text, Password = _TextBoxPasswordReg.Password, MiddleName = _TextBoxMiddleName.Text.Length == 0 ? null : _TextBoxMiddleName.Text
                    };
                    dboperator.GetTable <Operator>().InsertOnSubmit(operatornew);
                    dboperator.SubmitChanges();

                    RepitPassword.IsOpen    = false;
                    TextBlockMessage.Text   = "Регистрация прошла успешно";
                    WrongPassOrLogin.IsOpen = true;

                    _TextBoxFirstName.Clear();
                    _TextBoxSecondName.Clear();
                    _TextBoxMiddleName.Clear();
                    _TextBoxLoginReg.Clear();
                    _TextBoxPasswordReg.Clear();
                    FlipperAcc.IsFlipped = false;
                }
                else
                {
                    TextBlockChangedPass.Text = "Неверный пароль";
                }
            }
            catch (Exception)
            {
                RepitPassword.IsOpen    = false;
                TextBlockMessage.Text   = "Пользователь с таким логином уже зарегестрирован";
                WrongPassOrLogin.IsOpen = true;
            }
        }
        private void ButtonClick_OK(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_TextBoxArrivalCity.Text.Length > 0 && _TextBoxDepatureCity.Text.Length > 0 && _TextBoxFlightNumber.Text.Length > 0)
                {
                    MyDataContext dbFlight = new MyDataContext(CurrentUser.connectionString);

                    DateTime date1;
                    date1 = Convert.ToDateTime(DatePiker.Text);
                    date1 = date1.AddHours(TimePiker.SelectedTime.Value.Hour);
                    date1 = date1.AddMinutes(TimePiker.SelectedTime.Value.Minute);

                    if (date1 < DateTime.Now)
                    {
                        TextBlockMessgeAddFlight.Visibility = Visibility.Visible;
                        TextBlockMessgeAddFlight.Text       = "Неверная дата";
                        return;
                    }

                    DateTime date2 = date1;
                    date2 = date2.AddHours(double.Parse(_ComboBoxHours.Text));
                    date2 = date2.AddMinutes(double.Parse(_ComboBoxMinutes.Text));



                    Flight newflight = new Flight
                    {
                        ArrivalCity   = _TextBoxArrivalCity.Text,
                        DepatureCity  = _TextBoxDepatureCity.Text,
                        FlightNumber  = _TextBoxFlightNumber.Text,
                        OperatorID    = CurrentUser.CurrentID,
                        AircraftID    = short.Parse(_ComboBoxSideNumberINV.Items[_ComboBoxSideNumber.SelectedIndex].ToString()),
                        AirlineID     = short.Parse(_ComboBoxAirlineNameINV.Items[_ComboBoxAirlineName.SelectedIndex].ToString()),
                        DepartureTime = date1,
                        ArrivalTime   = date2,
                    };

                    dbFlight.flights.InsertOnSubmit(newflight);
                    dbFlight.SubmitChanges();

                    TextBlockMessgeAddFlight.Text       = "Рейс добавлен";
                    TextBlockMessgeAddFlight.Visibility = Visibility.Visible;

                    var flights = from fl in dbFlight.flights
                                  join airc in dbFlight.airlines on fl.AirlineID equals airc.AirlineID
                                  join air in dbFlight.aircrafts on fl.AircraftID equals air.AircraftID
                                  where fl.FlightNumber == _TextBoxFlightNumber.Text
                                  select new
                    {
                        fl.ArrivalCity,
                        fl.ArrivalTime,
                        fl.DepartureTime,
                        fl.DepatureCity,
                        fl.FlightNumber,
                        airc.AirlineName,
                        fl.FlightID,
                        air.AircraftModel,
                        air.SideNumber
                    };

                    foreach (var item in flights)
                    {
                        DataGridFlights.Items.Add(item);
                    }


                    Aircraft Aircr = dbFlight.aircrafts.Where(airc => airc.AircraftID == short.Parse(_ComboBoxSideNumberINV.Items[_ComboBoxSideNumber.SelectedIndex].ToString())).FirstOrDefault();
                    Aircr.IsFree = false;

                    dbFlight.SubmitChanges();
                    ClearValue();
                }
                else
                {
                    TextBlockMessgeAddFlight.Visibility = Visibility.Visible;
                    TextBlockMessgeAddFlight.Text       = "Заполнены не все поля";
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                TextBlockMessgeAddFlight.Visibility = Visibility.Visible;
                TextBlockMessgeAddFlight.Text       = $"Рейс с номером {_TextBoxFlightNumber.Text} уже существует";
            }
            catch (Exception)
            {
                TextBlockMessgeAddFlight.Visibility = Visibility.Visible;
                TextBlockMessgeAddFlight.Text       = "Заполнены не все поля";
            }
        }
Пример #16
0
        private void Button_Click_CreateReport(object sender, RoutedEventArgs e)
        {
            DateTime res;

            if (DateTime.TryParse(_DataPiker_First.Text, out res) && DateTime.TryParse(_DataPiker_Second.Text, out res))
            {
                _CreateReportErrorMessage.Visibility = Visibility.Hidden;
                DataGridAll.Items.Clear();
                MyDataContext dboperator = new MyDataContext(CurrentUser.connectionString);

                if (_CheckBoxAllOperators.IsChecked == true)
                {
                    var report = from fl in dboperator.flights
                                 join airc in dboperator.airlines on fl.AirlineID equals airc.AirlineID
                                 join aircrf in dboperator.aircrafts on fl.AircraftID equals aircrf.AircraftID
                                 join op in dboperator.operators on fl.OperatorID equals op.OperatorID
                                 where fl.DepartureTime >= _DataPiker_First.SelectedDate && fl.DepartureTime <= _DataPiker_Second.SelectedDate
                                 select new
                    {
                        fl.ArrivalCity,
                        fl.ArrivalTime,
                        fl.DepartureTime,
                        fl.DepatureCity,
                        fl.FlightNumber,
                        airc.AirlineName,
                        aircrf.AircraftModel,
                        aircrf.SideNumber,
                        op.FirstName,
                        op.SecondName,
                        op.Login
                    };

                    foreach (var item in report)
                    {
                        DataGridAll.Items.Add(item);
                    }
                }
                else if (_CheckBoxAllOperators.IsChecked == false)
                {
                    var report = from fl in dboperator.flights
                                 join airc in dboperator.airlines on fl.AirlineID equals airc.AirlineID
                                 join aircrf in dboperator.aircrafts on fl.AircraftID equals aircrf.AircraftID
                                 join op in dboperator.operators on fl.OperatorID equals op.OperatorID
                                 where fl.DepartureTime >= _DataPiker_First.SelectedDate && fl.DepartureTime <= _DataPiker_Second.SelectedDate && op.Login == _ComboBoxNames.SelectedItem.ToString()
                                 select new
                    {
                        fl.ArrivalCity,
                        fl.ArrivalTime,
                        fl.DepartureTime,
                        fl.DepatureCity,
                        fl.FlightNumber,
                        airc.AirlineName,
                        aircrf.AircraftModel,
                        aircrf.SideNumber,
                        op.FirstName,
                        op.SecondName,
                        op.Login
                    };

                    foreach (var item in report)
                    {
                        DataGridAll.Items.Add(item);
                    }
                }
            }
            else
            {
                _CreateReportErrorMessage.Text       = "Заполните все поля";
                _CreateReportErrorMessage.Visibility = Visibility.Visible;
            }
        }