public void CheckAndAddВookingData_Click(object sender, EventArgs e) //Регистрация бронирования { if (textBox13.Text != "" && textBox14.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "") { SqlCommand command1 = new SqlCommand(); SqlCommand command2 = new SqlCommand(); Form1.OpenConnectionCorrect(Form1.conn); int idOfCurrentCustomer = 0; if (ElementsSettings.RowOfPassportSeriesConsistEnoughNumbers(textBox1) == true && ElementsSettings.RowOfPassportNumberConsistEnoughNumbers(textBox2) == true && ElementsSettings.ValuesOfGuestsAndKidsAreCorrect(textBox13, textBox14) == true && ElementsSettings.SettlingDateIsLessThenEvictionDate(ancSettlingDateTimePicker, ancEvictionDateTimePicker) == true) //Проверяем все ограничения ввода { //SqlCommand command = new SqlCommand("INSERT INTO Customer (passport_series, passport_number, name, surname, patronymic, birthday, tel_number) values('"+textBox1.Text+"', '"+textBox2.Text+"', '"+textBox3.Text+"', '"+textBox4.Text+"', '"+textBox5.Text+"', '"+textBox6.Text+"', '"+textBox7.Text+"')", Form1.conn); if (RequestsSQLT.SelectNthIdFromCustomerWherePassportDataDefinedToString(Form1.conn, Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text)) != "null") //Если клиент уже был постояльцем, то реистрируем проживание по его ID { idOfCurrentCustomer = Convert.ToInt32(RequestsSQLT.SelectNthIdFromCustomerWherePassportDataDefinedToString(Form1.conn, Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text))); if (RequestsSQLT.ValueOfCustomerLivingsAndBookingsForToday(Form1.conn, idOfCurrentCustomer) < 5) { command2 = new SqlCommand("INSERT INTO Booking (number, settling, eviction, value_of_guests, value_of_kids, customer_id) VALUES (@number, @settling, @eviction, @value_of_guests, @value_of_kids, @customer_id)", Form1.conn); command2.Parameters.AddWithValue("@number", selectedNumberOfApartments); command2.Parameters.AddWithValue("@settling", ancSettlingDateTimePicker.Value); command2.Parameters.AddWithValue("@eviction", ancEvictionDateTimePicker.Value); command2.Parameters.AddWithValue("@value_of_guests", textBox13.Text); command2.Parameters.AddWithValue("@value_of_kids", textBox14.Text); command2.Parameters.AddWithValue("@customer_id", idOfCurrentCustomer); command2.ExecuteNonQuery(); //Тут можно потом поставить MessageBox, предупреждающий о том, что ткоей клинет уже есть в базе данных } } else //Если клиент ещё не был постояльцем в отеле, то добавляем его запись в таблицу клиентов и сразу регистрируем новое проживание { command1 = new SqlCommand("INSERT INTO Customer (passport_series, passport_number, name, surname, patronymic, birthday, tel_number) VALUES (@passport_series, @passport_number, @name, @surname, @patronymic, @birthday, @tel_number)", Form1.conn); command1.Parameters.AddWithValue("@passport_series", textBox1.Text); command1.Parameters.AddWithValue("@passport_number", textBox2.Text); command1.Parameters.AddWithValue("@name", textBox3.Text); command1.Parameters.AddWithValue("@surname", textBox4.Text); command1.Parameters.AddWithValue("@patronymic", textBox5.Text); command1.Parameters.AddWithValue("@birthday", ancBirthdayDateTimePicker.Value); command1.Parameters.AddWithValue("@tel_number", textBox7.Text); command1.ExecuteNonQuery(); string check = RequestsSQLT.SelectNthIdFromCustomerWherePassportDataDefinedToString(Form1.conn, Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text)); idOfCurrentCustomer = Convert.ToInt32(RequestsSQLT.SelectNthIdFromCustomerWherePassportDataDefinedToString(Form1.conn, Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text)));//Заного определяем ID только что добавленного клиента command2 = new SqlCommand("INSERT INTO Booking (number, settling, eviction, value_of_guests, value_of_kids, customer_id) VALUES (@number, @settling, @eviction, @value_of_guests, @value_of_kids, @customer_id)", Form1.conn); command2.Parameters.AddWithValue("@number", selectedNumberOfApartments); command2.Parameters.AddWithValue("@settling", ancSettlingDateTimePicker.Value); command2.Parameters.AddWithValue("@eviction", ancEvictionDateTimePicker); command2.Parameters.AddWithValue("@value_of_guests", textBox13.Text); command2.Parameters.AddWithValue("@value_of_kids", textBox14.Text); command2.Parameters.AddWithValue("@customer_id", idOfCurrentCustomer); command2.ExecuteNonQuery(); } } } else { MessageBox.Show("Поля \"Имя\", \"Фамилия\", \"Отчество\", \"Количество гостей\", \"Количество детей\" обязательны к заполению"); } }
private void changeCustomerDataButton_Click(object sender, EventArgs e) { var dResult = MessageBox.Show("Вы уверены, что хотите применить изменения в базе данных?", "", MessageBoxButtons.YesNo); if (dResult == DialogResult.Yes) { if (ElementsSettings.RowOfPassportSeriesConsistEnoughNumbers(textBox2) == true && ElementsSettings.RowOfPassportNumberConsistEnoughNumbers(textBox3) == true) //Проверяем все ограничения ввода для таблицы клиетов { SqlCommand command = new SqlCommand(); command = new SqlCommand($"UPDATE Customer SET passport_series = {Convert.ToInt32(textBox2.Text)}, passport_number = {Convert.ToInt32(textBox3.Text)}, name = '{textBox4.Text}', surname = '{textBox5.Text}', patronymic = '{textBox6.Text}', birthday = '{dateTimePicker1.Value}', tel_number = '{textBox8.Text}' WHERE customer_id = {idOfChosenRow1}", conn); command.ExecuteNonQuery(); Refresh1(); } else { MessageBox.Show("Серия или номер паспорта заданы некорректно"); } } }