コード例 #1
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("Неверно введены данные");
                }
            }
        }
コード例 #2
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;
        }
コード例 #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");
                    }
                }
            }
            //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;
        }