Пример #1
0
        private void NextButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            isPageSwitched = true;
            _customers.Clear();

            if (_currentPage != _customersRowCount)
            {
                SqlDataReader reader = CarRentalDbWorker.ExecuteFormDataCommand("SelectFromCustomers", _currentPage + 1, _connection);
                _customers.Load(reader);
                reader.Close();

                PassBox.Text = _customers.Rows[0][1].ToString();
                _oldPass     = PassBox.Text;

                LNameBox.Text = _customers.Rows[0][2].ToString();
                FNameBox.Text = _customers.Rows[0][3].ToString();
                MNameBox.Text = _customers.Rows[0][4].ToString();

                Title = string.Format("Клиент № {0}", _customers.Rows[0][0].ToString());
                _currentPage++;
            }
            else
            {
                _oldPass = string.Empty;

                Title = "Новый клиент";

                PassBox.Text  = string.Empty;
                LNameBox.Text = string.Empty;
                FNameBox.Text = string.Empty;
                MNameBox.Text = string.Empty;
            }
        }
        private void PrevButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (_currentPage != 1)
            {
                isPageSwitched = true;

                _customers.Clear();
                _rents.Clear();

                SqlDataReader reader = CarRentalDbWorker.ExecuteFormDataCommand("SelectFromCustomers", _currentPage - 1, _connection);
                _customers.Load(reader);
                reader.Close();

                PassBox.Text = _customers.Rows[0][1].ToString();
                _oldPass     = PassBox.Text;
                ////
                SqlDataReader readerRent = CarRentalDbWorker.ExecuteFormRentDataCommand(_oldPass, _connection);
                _rents.Load(readerRent);
                readerRent.Close();

                DataGrid.ItemsSource = _rents.DefaultView;
                ////
                LNameBox.Text = _customers.Rows[0][2].ToString();
                FNameBox.Text = _customers.Rows[0][3].ToString();
                MNameBox.Text = _customers.Rows[0][4].ToString();

                Title = string.Format("Клиент № {0}", _customers.Rows[0][0].ToString());
                _currentPage--;
            }
        }
Пример #3
0
        public PrintRentForm(SqlConnection connection)
        {
            InitializeComponent();

            RentDataViewer.Reset();

            DataTable rentData     = CarRentalDbWorker.RentToPrintData(connection);
            string    currentUser  = rentData.Rows[0][rentData.Columns[3]].ToString();
            DataTable customerData = CarRentalDbWorker.RentCustomerToPrintData(connection, currentUser);
            string    currentCar   = rentData.Rows[0][rentData.Columns[4]].ToString();
            DataTable carsData     = CarRentalDbWorker.RentCarToPrintData(connection, currentCar);

            ReportDataSource RentDataSource     = new ReportDataSource("RentData", rentData);
            ReportDataSource CustomerDataSource = new ReportDataSource("CustomerData", customerData);
            ReportDataSource CarDataSource      = new ReportDataSource("CarData", carsData);

            RentDataViewer.LocalReport.DataSources.Add(RentDataSource);
            RentDataViewer.LocalReport.DataSources.Add(CustomerDataSource);
            RentDataViewer.LocalReport.DataSources.Add(CarDataSource);

            RentDataViewer.LocalReport.ReportEmbeddedResource = "CarRentDBApp.RentReport.rdlc";
            RentDataViewer.RefreshReport();

            ShowActivated = true;
            Show();
        }
Пример #4
0
        public MainWindow(SqlConnection connection)
        {
            InitializeComponent();

            _connection  = connection;
            _carRentalDb = new CarRentalDbWorker(_connection);

            SqlCommand cmd = new SqlCommand("DefinePermissionLevel", _connection);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            string accessSchemaName = cmd.ExecuteScalar().ToString();

            if (accessSchemaName.Equals("CarRentalDbAdmin"))
            {
                isAdmin = true;
            }

            if (!isAdmin)
            {
                TablesMenu.Children.Remove(CustomersNavItem);
                TablesMenu.Children.Remove(RentNavItem);
                RequestMenu.Children.Remove(RentDetailsRequest);
                RequestMenu.Children.Remove(RentsForTimeRequest);
            }
        }
Пример #5
0
        private void OkButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            short   year  = 0;
            decimal price = 0;
            decimal worth = 0;

            if (short.TryParse(YearBox.Text, out year) &&
                decimal.TryParse(PriceBox.Text, out price) &&
                decimal.TryParse(WorthBox.Text, out worth) == true &&
                YearBox.Text.Length == 4)
            {
                CarRentalDbWorker.AddNewCar(_connection,
                                            GovNumBox.Text,
                                            ModelBox.Text,
                                            ColorBox.Text,
                                            year,
                                            price,
                                            worth);
                DialogResult = true;
                Close();
            }
            else
            {
                MessageBox.Show("Неверно введены данные");
            }
        }
Пример #6
0
        private void InitRentBtnsHandlers()
        {
            _rentContainer.EditingBlock.Children.Remove(_rentContainer.NewRent);
            _rentContainer.EditingBlock.Children.Remove(_rentContainer.AddButton);

            _rentContainer.EditB.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) =>
            {
                DataRowView row = null;

                try
                {
                    row = _rentContainer.DataGrid.SelectedItem as DataRowView;
                    EditRentDialog EditRent = new EditRentDialog(_connection, row);
                    if (EditRent.DialogResult == true)
                    {
                        AddTableTab(_carRentalDb.Rent.TableName);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Не выбрано ни одной строки");
                }
            };

            _rentContainer.DeleteB.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) =>
            {
                DataRowView row = null;
                try
                {
                    row = _rentContainer.DataGrid.SelectedItem as DataRowView;

                    string           message       = "Удалить из базы запись о прокате №: " + row[1].ToString() + "?";
                    string           caption       = "Удалить запись";
                    MessageBoxButton buttons       = MessageBoxButton.OKCancel;
                    MessageBoxImage  icon          = MessageBoxImage.Question;
                    MessageBoxResult defaultResult = MessageBoxResult.OK;
                    MessageBoxResult result        = MessageBox.Show(message, caption, buttons, icon, defaultResult);

                    if (result == MessageBoxResult.OK)
                    {
                        CarRentalDbWorker.DeleteRent(_connection, int.Parse(row[1].ToString()));
                        AddTableTab(_carRentalDb.Rent.TableName);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Не выбрано ни одной строки");
                }
            };
        }
Пример #7
0
        public CarsReportForm(SqlConnection connection)
        {
            InitializeComponent();

            DataTable carsData = CarRentalDbWorker.GetCarsReport(connection);


            ReportDataSource dataSource = new ReportDataSource("CarsReportData", carsData);

            CarsReportViewer.LocalReport.DataSources.Add(dataSource);
            CarsReportViewer.LocalReport.ReportEmbeddedResource = "CarRentDBApp.CarsReport.rdlc";
            CarsReportViewer.RefreshReport();

            Show();
        }
Пример #8
0
        private void OkButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            byte rentDays = 0;

            if (byte.TryParse(RentDaysBox.Text, out rentDays))
            {
                CarRentalDbWorker.EditRent(_connection, _orderId, rentDays);

                DialogResult = true;
                Close();
            }
            else
            {
                MessageBox.Show("Неверно введены данные");
            }
        }
Пример #9
0
        private void OkButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (PassBox.Text != string.Empty &&
                LNameBox.Text != string.Empty &&
                FNameBox.Text != string.Empty)
            {
                CarRentalDbWorker.EditCustomer(_connection, _oldPassData, PassBox.Text, LNameBox.Text, FNameBox.Text, MNameBox.Text);

                DialogResult = true;
                Close();
            }
            else
            {
                MessageBox.Show("Неверно введены данные");
            }
        }
Пример #10
0
        private void OkButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            byte rentDays       = 0;
            int  findUserResult = 0;

            if (PassBox.Text != string.Empty)
            {
                string       query       = string.Format("Select @Count = COUNT(SeriesAndPassNum) From Customers Where SeriesAndPassNum = '{0}'", PassBox.Text);
                SqlCommand   cmdFindUser = new SqlCommand(query, _connection);
                SqlParameter parameter   = new SqlParameter("@Count", SqlDbType.Int);
                parameter.Direction = ParameterDirection.Output;
                cmdFindUser.Parameters.Add(parameter);
                cmdFindUser.ExecuteNonQuery();

                findUserResult = (int)parameter.Value;
            }

            if (findUserResult == 1 && byte.TryParse(RentDaysBox.Text, out rentDays) && rentDays != 0)
            {
                CarRentalDbWorker.AddNewRent(_connection, rentDays, PassBox.Text, _govNum);

                new PrintRentForm(_connection);
                DialogResult = true;
                Close();
            }
            else
            {
                if (PassBox.Text != string.Empty &&
                    LNameBox.Text != string.Empty &&
                    FNameBox.Text != string.Empty &&
                    byte.TryParse(RentDaysBox.Text, out rentDays) &&
                    rentDays != 0)
                {
                    CarRentalDbWorker.AddNewCustomer(_connection, PassBox.Text, LNameBox.Text, FNameBox.Text, MNameBox.Text);
                    CarRentalDbWorker.AddNewRent(_connection, rentDays, PassBox.Text, _govNum);

                    new PrintRentForm(_connection);
                    DialogResult = true;
                    Close();
                }
                else
                {
                    MessageBox.Show("Неверно введены данные");
                }
            }
        }
Пример #11
0
        private void ToEnd_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            isPageSwitched = true;
            _customers.Clear();

            SqlDataReader reader = CarRentalDbWorker.ExecuteFormDataCommand("SelectFromCustomers", _customersRowCount, _connection);

            _customers.Load(reader);
            reader.Close();

            Title = string.Format("Клиент № {0}", _customers.Rows[0][0].ToString());

            PassBox.Text = _customers.Rows[0][1].ToString();
            _oldPass     = PassBox.Text;

            LNameBox.Text = _customers.Rows[0][2].ToString();
            FNameBox.Text = _customers.Rows[0][3].ToString();
            MNameBox.Text = _customers.Rows[0][4].ToString();
        }
Пример #12
0
        private void OkButtonForEdit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            decimal price = 0;
            decimal worth = 0;

            if (decimal.TryParse(PriceBox.Text, out price) &&
                decimal.TryParse(WorthBox.Text, out worth) == true)
            {
                CarRentalDbWorker.EditCar(_connection,
                                          _oldGovNum,
                                          GovNumBox.Text,
                                          ColorBox.Text,
                                          price,
                                          worth);
                DialogResult = true;
                Close();
            }
            else
            {
                MessageBox.Show("Неверно введены данные");
            }
        }
Пример #13
0
        public CustomerRentForm(SqlConnection connection)
        {
            InitializeComponent();
            CarsCatalogBlock.Visibility = Visibility.Collapsed;

            _connection  = connection;
            _customers   = new DataTable();
            _rents       = new DataTable();
            _carsCatalog = new DataTable();

            _customersRowCount   = CarRentalDbWorker.TotalFormDataRowCount(_connection, "Customers");
            _rentsRowCount       = CarRentalDbWorker.TotalFormDataRowCount(_connection, "Rent");
            _carsCatalogRowCount = CarRentalDbWorker.TotalFormDataRowCount(_connection, "Cars");

            SqlDataReader reader = CarRentalDbWorker.ExecuteFormDataCommand("SelectFromCustomers", _currentPage, _connection);

            _customers.Load(reader);
            reader.Close();

            Title = string.Format("Клиент № {0}", _customers.Rows[0][0].ToString());

            PassBox.Text = _customers.Rows[0][1].ToString();
            _oldPass     = PassBox.Text;
            ////
            SqlDataReader readerRent = CarRentalDbWorker.ExecuteFormRentDataCommand(_oldPass, _connection);

            _rents.Load(readerRent);
            readerRent.Close();

            DataGrid.ItemsSource = _rents.DefaultView;
            ////
            LNameBox.Text = _customers.Rows[0][2].ToString();
            FNameBox.Text = _customers.Rows[0][3].ToString();
            MNameBox.Text = _customers.Rows[0][4].ToString();

            Show();
        }
Пример #14
0
        private void NewRentB_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            CarsCatalogBlock.Visibility = Visibility.Visible;
            _carsCatalog.Clear();

            int pagesQuantity = 0;

            ExecutePage(_connection, "SelectFromCars", 1, _carsCatalog, CarsDataGrid);

            MouseButtonEventHandler handler = (object sender1, MouseButtonEventArgs e1) =>
            {
                TextBlock button = sender1 as TextBlock;

                int rowCount = CarRentalDbWorker.TotalFormDataRowCount(_connection, "Cars");

                if (!rowCount.Equals(_carsCatalogRowCount))
                {
                    ExecutePage(_connection, "SelectFromCars", 1, _carsCatalog, CarsDataGrid);
                    pagesQuantity = PagesCounter(_carsCatalogRowCount);
                    InitPageControls(this, pagesQuantity);
                }

                PageSwitcherLogic("SelectFromCars", this, _carsCatalog, button);
            };

            PageNum1.MouseLeftButtonDown += handler;
            PageNum2.MouseLeftButtonDown += handler;
            PageNum3.MouseLeftButtonDown += handler;
            PageNum4.MouseLeftButtonDown += handler;
            PageNum5.MouseLeftButtonDown += handler;
            PageNum6.MouseLeftButtonDown += handler;
            NextPage.MouseLeftButtonDown += handler;
            PrevPage.MouseLeftButtonDown += handler;

            pagesQuantity = PagesCounter(_carsCatalogRowCount);
            InitPageControls(this, pagesQuantity);
        }
Пример #15
0
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!isPageSwitched)
            {
                int findUserResult = 0;

                if (PassBox.Text != string.Empty &&
                    LNameBox.Text != string.Empty &&
                    FNameBox.Text != string.Empty)
                {
                    string       query       = string.Format("Select @Count = COUNT(SeriesAndPassNum) From Customers Where SeriesAndPassNum = '{0}'", _oldPass);
                    SqlCommand   cmdFindUser = new SqlCommand(query, _connection);
                    SqlParameter parameter   = new SqlParameter("@Count", SqlDbType.Int);
                    parameter.Direction = ParameterDirection.Output;
                    cmdFindUser.Parameters.Add(parameter);
                    cmdFindUser.ExecuteNonQuery();

                    findUserResult = (int)parameter.Value;

                    if (findUserResult == 1)
                    {
                        CarRentalDbWorker.EditCustomer(_connection, _oldPass, PassBox.Text, LNameBox.Text, FNameBox.Text, MNameBox.Text);
                        _oldPass = PassBox.Text;
                    }
                    else if (findUserResult == 0 &&
                             PassBox.Text != string.Empty &&
                             LNameBox.Text != string.Empty &&
                             FNameBox.Text != string.Empty)
                    {
                        CarRentalDbWorker.AddNewCustomer(_connection, PassBox.Text, LNameBox.Text, FNameBox.Text, MNameBox.Text);
                        _oldPass           = PassBox.Text;
                        _customersRowCount = CarRentalDbWorker.TotalFormDataRowCount(_connection, "Customers");
                    }
                }
            }
            isPageSwitched = false;
        }
Пример #16
0
        private void SubmitRent_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            byte rentDays = 0;

            try
            {
                _carCatalogRow = CarsDataGrid.SelectedItem as DataRowView;

                if (byte.TryParse(RentDaysBox.Text, out rentDays) &&
                    rentDays != 0 &&
                    PassBox.Text != string.Empty &&
                    LNameBox.Text != string.Empty &&
                    FNameBox.Text != string.Empty)
                {
                    CarRentalDbWorker.AddNewRent(_connection, rentDays, PassBox.Text, _carCatalogRow[1].ToString());
                    new PrintRentForm(_connection);

                    SqlDataReader readerRent = CarRentalDbWorker.ExecuteFormRentDataCommand(_oldPass, _connection);
                    _rents.Clear();
                    _rents.Load(readerRent);
                    readerRent.Close();

                    CarsCatalogBlock.Visibility = Visibility.Collapsed;

                    DataGrid.ItemsSource = _rents.DefaultView;
                }
                else
                {
                    MessageBox.Show("Неверно введены данные");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Выберите авто из каталога");
            }
        }
Пример #17
0
        public CustomersForm(SqlConnection connection)
        {
            InitializeComponent();

            _connection        = connection;
            _customers         = new DataTable();
            _customersRowCount = CarRentalDbWorker.TotalFormDataRowCount(_connection, "Customers");

            SqlDataReader reader = CarRentalDbWorker.ExecuteFormDataCommand("SelectFromCustomers", _currentPage, _connection);

            _customers.Load(reader);
            reader.Close();

            Title = string.Format("Клиент № {0}", _customers.Rows[0][0].ToString());

            PassBox.Text = _customers.Rows[0][1].ToString();
            _oldPass     = PassBox.Text;

            LNameBox.Text = _customers.Rows[0][2].ToString();
            FNameBox.Text = _customers.Rows[0][3].ToString();
            MNameBox.Text = _customers.Rows[0][4].ToString();

            Show();
        }
Пример #18
0
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!isPageSwitched)
            {
                int findUserResult = 0;

                if (PassBox.Text != string.Empty &&
                    LNameBox.Text != string.Empty &&
                    FNameBox.Text != string.Empty)
                {
                    string       query       = string.Format("Select @Count = COUNT(SeriesAndPassNum) From Customers Where SeriesAndPassNum = '{0}'", _oldPass);
                    SqlCommand   cmdFindUser = new SqlCommand(query, _connection);
                    SqlParameter parameter   = new SqlParameter("@Count", SqlDbType.Int);
                    parameter.Direction = ParameterDirection.Output;
                    cmdFindUser.Parameters.Add(parameter);
                    cmdFindUser.ExecuteNonQuery();

                    findUserResult = (int)parameter.Value;

                    if (findUserResult == 1)
                    {
                        CarRentalDbWorker.EditCustomer(_connection, _oldPass, PassBox.Text, LNameBox.Text, FNameBox.Text, MNameBox.Text);
                        _oldPass = PassBox.Text;
                    }
                    else if (findUserResult == 0 &&
                             PassBox.Text != string.Empty &&
                             LNameBox.Text != string.Empty &&
                             FNameBox.Text != string.Empty)
                    {
                        CarRentalDbWorker.AddNewCustomer(_connection, PassBox.Text, LNameBox.Text, FNameBox.Text, MNameBox.Text);
                        _oldPass           = PassBox.Text;
                        _customersRowCount = CarRentalDbWorker.TotalFormDataRowCount(_connection, "Customers");
                    }
                }
            }
            //else if(!isPageSwitched && _oldPass == string.Empty &&
            //        PassBox.Text == string.Empty &&
            //        LNameBox.Text == string.Empty &&
            //        FNameBox.Text == string.Empty)
            //{
            //    Title = "asdfs";
            //    int findUserResult = 0;
            //    if(PassBox.Text != string.Empty)
            //    {
            //        string query = string.Format("Select @Count = COUNT(SeriesAndPassNum) From Customers Where SeriesAndPassNum = '{0}'", _oldPass);
            //        SqlCommand cmdFindUser = new SqlCommand(query, _connection);
            //        SqlParameter parameter = new SqlParameter("@Count", SqlDbType.Int);
            //        parameter.Direction = ParameterDirection.Output;
            //        cmdFindUser.Parameters.Add(parameter);
            //        cmdFindUser.ExecuteNonQuery();

            //        findUserResult = (int)parameter.Value;

            //        if (findUserResult == 1)
            //        {
            //            query = string.Format("Select LName, FName, MName From Customers Where SeriesAndPassNum= '{0}'", PassBox.Text);
            //            cmdFindUser = new SqlCommand(query, _connection);
            //            SqlDataReader reader = cmdFindUser.ExecuteReader();

            //            while (reader.Read())
            //            {
            //                LNameBox.Text = reader[0].ToString();
            //                FNameBox.Text = reader[1].ToString();
            //                MNameBox.Text = reader[2].ToString();
            //            }
            //            reader.Close();
            //            CarRentalDbWorker.EditCustomer(_connection, _oldPass, PassBox.Text, LNameBox.Text, FNameBox.Text, MNameBox.Text);
            //            _oldPass = PassBox.Text;
            //        }
            //    }
            //}

            isPageSwitched = false;
        }
Пример #19
0
        private void InitCarsEditBtnsHandlers()
        {
            _carsContainer.AddB.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) =>
            {
                NewCarRecordDialog newCarDialog = new NewCarRecordDialog(_connection);
                if (newCarDialog.DialogResult == true)
                {
                    AddTableTab(_carRentalDb.Cars.TableName);
                }
            };
            _carsContainer.EditB.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) =>
            {
                DataRowView row = null;

                try
                {
                    row = _carsContainer.DataGrid.SelectedItem as DataRowView;
                    NewCarRecordDialog editCar = new NewCarRecordDialog(_connection, row);
                    if (editCar.DialogResult == true)
                    {
                        AddTableTab(_carRentalDb.Cars.TableName);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Не выбрано ни одной строки");
                }
            };

            _carsContainer.DeleteB.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) =>
            {
                DataRowView row = null;
                try
                {
                    row = _carsContainer.DataGrid.SelectedItem as DataRowView;

                    string           message       = "Удалить из базы автомобиль Гос.Номер: " + row[1].ToString() + "?";
                    string           caption       = "Удалить запись";
                    MessageBoxButton buttons       = MessageBoxButton.OKCancel;
                    MessageBoxImage  icon          = MessageBoxImage.Question;
                    MessageBoxResult defaultResult = MessageBoxResult.OK;
                    MessageBoxResult result        = MessageBox.Show(message, caption, buttons, icon, defaultResult);

                    if (result == MessageBoxResult.OK)
                    {
                        CarRentalDbWorker.DeleteCar(_connection, row[1].ToString());
                        AddTableTab(_carRentalDb.Cars.TableName);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Не выбрано ни одной строки");
                }
            };

            _carsContainer.NewRentB.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) =>
            {
                DataRowView row = null;

                try
                {
                    row = _carsContainer.DataGrid.SelectedItem as DataRowView;
                    FormalizeRent NewRent = new FormalizeRent(_connection, row);
                    if (NewRent.DialogResult == true)
                    {
                        AddTableTab(_carRentalDb.Cars.TableName);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Не выбрано ни одной строки");
                }
            };
        }