Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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;
        }