Ejemplo n.º 1
0
        private void AddServiceButton_Click(object sender, EventArgs e)
        {
            this.Hide();
            EmloyeesCherfulness emloyeesCherfulness = new EmloyeesCherfulness(ID, StDate, FinDate, StatusTenant, Type_user);

            emloyeesCherfulness.ShowDialog();
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (Debs == null)
            {
                if (CardNumber.Text.Length == 19 && Convert.ToInt32(Month.Text) > 0 &&
                    Convert.ToInt32(Month.Text) <= 12 && Convert.ToInt32(Year.Text) > DateTime.Now.Year)
                {
                    connection = new SqlConnection(connectionString);
                    try
                    {
                        connection.Open();

                        dataAdapter = new SqlDataAdapter($"select ID_room from Hostel_number where Employment = 0", connection);
                        DataSet IDroom = new DataSet();
                        dataAdapter.Fill(IDroom);

                        dataAdapter = new SqlDataAdapter($"select First_name from [User] where ID_user = '******'", connection);
                        DataSet NameOrg = new DataSet();
                        dataAdapter.Fill(NameOrg);

                        dataAdapter = new SqlDataAdapter($"select Hotel_ID from Hostel_number where ID_room = '{IDroom.Tables[0].Rows[0][0]}'", connection);
                        DataSet Hotel = new DataSet();
                        dataAdapter.Fill(Hotel);

                        if (Type_user == "1")
                        {
                            cmd = new SqlCommand($"insert into Reservations (Class_hotel,All_quantity_people,Status_cancel,Time_Check_In,Time_Eviction) values ('{Hostel}',{Convert.ToInt32(CountPeople)},0,'{StDate}','{FinDate}')", connection);
                            cmd.ExecuteNonQuery();

                            dataAdapter = new SqlDataAdapter($"select IDENT_CURRENT ('Reservations')", connection);
                            DataSet BookingID = new DataSet();
                            dataAdapter.Fill(BookingID);

                            cmd = new SqlCommand($"insert into Tenant (Feedback_Tenant,Report,Debts_Tenant,Booking_ID,[Date_Eviction],DLC_cost,[User_ID]) values ('','',0,'{BookingID.Tables[0].Rows[0][0]}','{FinDate}',0,'{IdUser}')", connection);
                            cmd.ExecuteNonQuery();

                            cmd = new SqlCommand($"update Hostel_number set DLC_service_ID = 3, Popularity_numbers = Popularity_numbers + 1, Employment = 1, Booking_ID = '{BookingID.Tables[0].Rows[0][0]}' where ID_room = {IDroom.Tables[0].Rows[0][0]}", connection);
                            cmd.ExecuteNonQuery();

                            cmd = new SqlCommand($"update [User] set Status_tenant = 1 where [ID_user] = '{IdUser}'", connection);
                            cmd.ExecuteNonQuery();
                        }
                        if (Type_user == "2")
                        {
                            AmountPay -= (AmountPay / 100) * 40;
                            int roomscount = Convert.ToInt32(CountPeople) / 4;
                            cmd = new SqlCommand($"insert into Contracts (Discount,Time_CheckIn,Time_eviction, Quantity_peopole, Busy_rooms) values (40,'{StDate}','{FinDate}',{Convert.ToInt32(CountPeople)},{roomscount})", connection);
                            cmd.ExecuteNonQuery();

                            dataAdapter = new SqlDataAdapter($"select IDENT_CURRENT ('Contracts')", connection);
                            DataSet IDContract = new DataSet();
                            dataAdapter.Fill(IDContract);
                            int rooms = Convert.ToInt32(IDroom.Tables[0].Rows[0][0]);
                            while (roomscount > 0)
                            {
                                cmd = new SqlCommand($"update Hostel_number set DLC_service_ID = 3, Popularity_numbers = Popularity_numbers + 1, Employment = 1, Contract_ID = '{IDContract.Tables[0].Rows[0][0]}' where ID_room = {rooms}", connection);
                                cmd.ExecuteNonQuery();
                                rooms++;
                                roomscount--;
                            }

                            cmd = new SqlCommand($"update [User] set Status_tenant = 1 where [ID_user] = '{IdUser}'", connection);
                            cmd.ExecuteNonQuery();

                            cmd = new SqlCommand($"insert into Organiations (Name_organization,Contract_ID,Characteristics_group,[User_ID]) values ('{NameOrg.Tables[0].Rows[0][0].ToString()}','{IDContract.Tables[0].Rows[0][0]}','Группа организации { NameOrg.Tables[0].Rows[0][0].ToString() }','{IdUser}')", connection);
                            cmd.ExecuteNonQuery();
                        }


                        dataAdapter = new SqlDataAdapter($"select Type_user from [User] where [ID_user] = {IdUser}", connection);
                        DataSet type = new DataSet();
                        dataAdapter.Fill(type);

                        cmd = new SqlCommand($"update Hostel set Revenue = Revenue + {Convert.ToDouble(Amount)} where ID_Hostel = '{Hotel.Tables[0].Rows[0][0]}'", connection);
                        cmd.ExecuteNonQuery();

                        MessageBox.Show("Успешная оплата!");

                        if (type.Tables[0].Rows[0][0].ToString() == "1")
                        {
                            this.Hide();
                            Guest guest = new Guest(IdUser, "1", Type_user);
                            guest.ShowDialog();
                        }
                        if (type.Tables[0].Rows[0][0].ToString() == "2")
                        {
                            this.Hide();
                            EmloyeesCherfulness emloyeesCherfulness = new EmloyeesCherfulness(IdUser, StDate, FinDate, "1", Type_user);
                            emloyeesCherfulness.ShowDialog();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка");
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Неправильные данные!");
                }
            }
            else
            {
                connection = new SqlConnection(connectionString);

                try
                {
                    connection.Open();

                    dataAdapter = new SqlDataAdapter($"select [ID_room] from Hostel_number inner join Tenant on [User_ID] = '{IdUser}' where Hostel_number.Booking_ID = Tenant.Booking_ID", connection);
                    DataSet IDroom = new DataSet();
                    dataAdapter.Fill(IDroom);

                    dataAdapter = new SqlDataAdapter($"select Hotel_ID from Hostel_number where ID_room = '{IDroom.Tables[0].Rows[0][0].ToString()}'", connection);
                    DataSet Hotel = new DataSet();
                    dataAdapter.Fill(Hotel);

                    cmd = new SqlCommand($"update Tenant set Debts_Tenant = 0 where [User_ID] = '{IdUser}'", connection);
                    cmd.ExecuteNonQuery();

                    cmd = new SqlCommand($"update Hostel set Revenue += {ServAmount} where ID_Hostel = '{Hotel.Tables[0].Rows[0][0]}' ", connection);
                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Успешная оплата!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка");
                }
                finally
                {
                    connection.Close();
                    this.Close();
                    this.Hide();
                    MenuBuyer menuBuyer = new MenuBuyer(IdUser, "1", Type_user);
                    menuBuyer.ShowDialog();
                }
            }
        }