Пример #1
0
        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("Поля \"Имя\", \"Фамилия\", \"Отчество\", \"Количество гостей\", \"Количество детей\" обязательны к заполению");
            }
        }
Пример #2
0
 private void dataGridView3_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     SetButtonsActive2();
     try
     {
         bookingS       = ElementsSettings.SetDataFromLivingOrBookingDGVToTextBoxes(dataGridView3, e);
         idOfChosenRow3 = Convert.ToInt32(RequestsSQLT.SelectNthIdFromCustomerWherePassportDataDefinedToString(conn, Convert.ToInt32(bookingS[0]), Convert.ToInt32(bookingS[1])));
         textBox17.Text = bookingS[5];
         textBox16.Text = bookingS[6];
         if (bookingS[7] != "")
         {
             idOfChosenRowBooking = Convert.ToInt32(bookingS[8]);
         }
     } catch { }
 }
Пример #3
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     SetButtonsActive0();
     try
     {
         string[] s = ElementsSettings.SetDataFromCustomersDGVToTextBoxes(dataGridView1, e);
         idOfChosenRow1        = Convert.ToInt32(RequestsSQLT.SelectNthIdFromCustomerWherePassportDataDefinedToString(conn, Convert.ToInt32(s[0]), Convert.ToInt32(s[1])));
         textBox2.Text         = s[0];
         textBox3.Text         = s[1];
         textBox4.Text         = s[2];
         textBox5.Text         = s[3];
         textBox6.Text         = s[4];
         dateTimePicker1.Value = Convert.ToDateTime(s[5]);
         //textBox7.Text = s[6];
         textBox8.Text = s[6];
     } catch { }
 }
Пример #4
0
 private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     SetButtonsActive1();
     try
     {
         string[] s = ElementsSettings.SetDataFromLivingOrBookingDGVToTextBoxes(dataGridView2, e);
         idOfChosenRow2 = Convert.ToInt32(RequestsSQLT.SelectNthIdFromCustomerWherePassportDataDefinedToString(conn, Convert.ToInt32(s[0]), Convert.ToInt32(s[1])));
         textBox12.Text = s[5];
         textBox11.Text = s[6];
         if (s[7] != "")
         {
             idOfChosenRowAS = Convert.ToInt32(s[7]);
         }
         if (s[8] != "")
         {
             idOfChosenRowLiving = Convert.ToInt32(s[8]);
         }
     } catch { }
 }