private void changeBookingDataButton_Click(object sender, EventArgs e) { var dResult = MessageBox.Show("Вы уверены, что хотите применить изменения в базе данных?", "", MessageBoxButtons.YesNo); if (dResult == DialogResult.Yes) { if (ElementsSettings.ValuesOfGuestsAndKidsAreCorrect(textBox12, textBox11) == true) //Проверяем все ограничения ввода для таблицы клиентов { SqlCommand command = new SqlCommand(); command = new SqlCommand($"UPDATE Booking SET value_of_guests = {Convert.ToInt32(textBox12.Text)}, value_of_kids = {Convert.ToInt32(textBox11.Text)} WHERE booking_id = {idOfChosenRowBooking}", conn); command.ExecuteNonQuery(); Refresh3(); } else { MessageBox.Show("Введены недопустимые значения"); } } }
public void CheckAndAddCustomerData_Click(object sender, EventArgs e) //Регистрация проживания { if (textBox13.Text != "" && textBox14.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "") { SqlCommand command1 = new SqlCommand(); SqlCommand command2 = new SqlCommand(); SqlCommand command3 = new SqlCommand(); int idOfNewAdditionalService = -1; 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) { command3 = new SqlCommand("INSERT INTO Additional_services (mini_bar, clothes_washing, telephone, intercity_telephone, food) VALUES (0, 0, 0, 0, 0)", Form1.conn); command3.ExecuteNonQuery(); command3 = new SqlCommand("select @@IDENTITY", Form1.conn); idOfNewAdditionalService = Convert.ToInt32(command3.ExecuteScalar()); command2 = new SqlCommand("INSERT INTO Living (number, settling, eviction, value_of_guests, value_of_kids, customer_id, as_id) VALUES (@number, @settling, @eviction, @value_of_guests, @value_of_kids, @customer_id, @as_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.Parameters.AddWithValue("@as_id", idOfNewAdditionalService); command2.ExecuteNonQuery(); //Тут можно потом поставить MessageBox, предупреждающий о том, что ткоей клинет уже есть в базе данных //Tyт потом дописать каскадное создание записи в Additional_services!!!! } } 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 Living (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("Поля \"Имя\", \"Фамилия\", \"Отчество\", \"Количество гостей\", \"Количество детей\" обязательны к заполению"); } }