Пример #1
0
 protected internal static ServiceForm Instance()
 {
     if (_instance == null)
     {
         _instance = new ServiceForm();
     }
     return(_instance);
 }
Пример #2
0
 private void panel2_Paint(object sender, PaintEventArgs e)
 {
     checkStatus(lblUser.Text);
     if (status == "NV")
     {
         btnRegistration.Visible = false;
         btnRoom.Visible         = false;
         ServiceForm sf = ServiceForm.Instance();
         sf.btnAdd.Visible = false;
     }
     else
     {
         btnRegistration.Visible = true;
         btnRoom.Visible         = true;
     }
 }
Пример #3
0
        private void btnServices_Click(object sender, EventArgs e)
        {
            int check = checkRoomState();

            if (check == 1) //đang sử dụng -> sử dụng dịch vụ
            {
                HomeForm    hf = HomeForm.Instance();
                ServiceForm sf = ServiceForm.Instance();
                if (!hf.panel3.Controls.Contains(sf))
                {
                    hf.panel3.Controls.Add(sf);
                    sf.Dock = DockStyle.Fill;
                    sf.BringToFront();
                    sf.Visible      = true;
                    sf.lblRoom.Text = lblRoom.Text;
                    sf.loadDV();
                    this.Hide();
                }
                else
                {
                    sf.BringToFront();
                    sf.Visible      = true;
                    sf.lblRoom.Text = lblRoom.Text;
                    sf.loadDV();
                    this.Hide();
                }
            }
            else if (check == 2) //phòng đặt trước không được sử dụng dịch vụ cho đến khi khách checkin
            {
                MessageBox.Show("Phòng đang đặt trước!!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                MessageBox.Show("Phòng trống!!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
Пример #4
0
        public void removeItemSQL(string id)
        {
            try
            {
                using (con = new SqlConnection(cs))
                {
                    con.Open();
                    using (tran = con.BeginTransaction(IsolationLevel.Serializable))
                    {
                        try
                        {
                            //LẤY CMND KHÁCH HÀNG
                            cmd = new SqlCommand("SELECT CMND FROM GIAO_DICH WHERE MaPhong=@maphong AND TrangThai=@trangthai AND LoaiDK=@loaidk", con, tran);
                            cmd.Parameters.AddWithValue("@maphong", ServiceForm.Instance().lblRoom.Text);
                            cmd.Parameters.AddWithValue("@trangthai", "Active");
                            cmd.Parameters.AddWithValue("@loaidk", 0);
                            rdr = cmd.ExecuteReader();
                            string cmnd = "";
                            if (rdr.Read())
                            {
                                cmnd = rdr["CMND"].ToString();
                            }
                            else
                            {
                                MessageBox.Show("Không tìm thấy CMND khách hàng");
                                return;
                            }
                            rdr.Close();
                            //LẤY ID HOÁ ĐƠN
                            cmd = new SqlCommand("SELECT idHD FROM HOA_DON WHERE CMND=@cmnd AND MaPhong=@maphong ORDER BY NgayLap DESC", con, tran);
                            cmd.Parameters.AddWithValue("@cmnd", cmnd);
                            cmd.Parameters.AddWithValue("@maphong", ServiceForm.Instance().lblRoom.Text);
                            rdr = cmd.ExecuteReader();
                            string idhd = "";
                            if (rdr.Read())
                            {
                                idhd = rdr["idHD"].ToString();
                            }
                            else
                            {
                                MessageBox.Show("Không tìm thấy hoá đơn!!!");
                                return;
                            }
                            rdr.Close();

                            cmd = new SqlCommand("DELETE FROM DS_DICH_VU WHERE idHD=@idhd AND idDV=@iddv", con, tran);
                            cmd.Parameters.AddWithValue("@idHD", idhd);
                            cmd.Parameters.AddWithValue("@idDV", id);
                            tran.Save("deleteDSDV");
                            cmd.ExecuteNonQuery();
                            tran.Commit();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Commit exeption type: " + ex.GetType());
                            MessageBox.Show("Message :" + ex.Message);
                            try
                            {
                                if (tran != null)
                                {
                                    tran.Rollback();
                                }
                            }
                            catch (Exception ex2)
                            {
                                MessageBox.Show("Rollback exeption type :" + ex2.GetType());
                                MessageBox.Show("Message :" + ex2.Message);
                            }
                        }
                        finally
                        {
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }
        }
Пример #5
0
        public void loadDSDV()
        {
            try
            {
                using (con = new SqlConnection(cs))
                {
                    con.Open();
                    //LẤY CMND KHÁCH HÀNG
                    cmd = new SqlCommand("SELECT CMND FROM GIAO_DICH WHERE MaPhong=@maphong AND TrangThai=@trangthai AND LoaiDK=@loaidk", con);
                    cmd.Parameters.AddWithValue("@maphong", ServiceForm.Instance().lblRoom.Text);
                    cmd.Parameters.AddWithValue("@trangthai", "Active");
                    cmd.Parameters.AddWithValue("@loaidk", "0");
                    rdr = cmd.ExecuteReader();
                    string cmnd = "";
                    if (rdr.Read())
                    {
                        cmnd = rdr["CMND"].ToString();
                    }
                    else
                    {
                        MessageBox.Show("Không tìm thấy CMND khách hàng");
                        return;
                    }
                    rdr.Close();

                    //LẤY ID HOÁ ĐƠN
                    cmd = new SqlCommand("SELECT idHD FROM HOA_DON WHERE CMND=@cmnd AND MaPhong=@maphong ORDER BY NgayLap DESC", con);
                    cmd.Parameters.AddWithValue("@cmnd", cmnd);
                    cmd.Parameters.AddWithValue("@maphong", ServiceForm.Instance().lblRoom.Text);
                    string idhd = "";
                    rdr = cmd.ExecuteReader();
                    if (rdr.Read())
                    {
                        idhd = rdr["idHD"].ToString();
                    }
                    else
                    {
                        MessageBox.Show("Không tìm thấy hoá đơn!!!");
                        return;
                    }
                    rdr.Close();

                    cmd = new SqlCommand("SELECT A.idDV,A.LoaiDV,A.TenDV,A.Gia,B.SoLuong FROM DICH_VU A, DS_DICH_VU B WHERE A.idDV=B.idDV AND B.idHD=@idhd", con);
                    cmd.Parameters.AddWithValue("@idhd", idhd);
                    dt  = new DataTable("DICH_VU");
                    adp = new SqlDataAdapter(cmd);
                    adp.Fill(dt);
                    adp.Dispose();
                    listViewSV.Items.Clear();
                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            ListViewItem lvi = new ListViewItem(row["idDV"].ToString());
                            lvi.SubItems.Add(row["TenDV"].ToString());
                            lvi.SubItems.Add(row["Gia"].ToString());
                            lvi.SubItems.Add(row["SoLuong"].ToString());
                            listViewSV.Items.Add(lvi);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }
            finally { con.Close(); }
        }
Пример #6
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                if (cbServiceType.Text == "" || txtPrice.Text == "" || txtServiceName.Text == "")
                {
                    MessageBox.Show("Xin hãy nhập các ô trống", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtServiceName.Focus();
                    return;
                }
                else if (Double.TryParse(txtPrice.Text.ToString(), out double x) == false)
                {
                    MessageBox.Show("Xin hãy nhập số!!!", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtPrice.Focus();
                    return;
                }
                if (checkServiceName(txtServiceName.Text.ToString())) //KT CÓ TÊN DV ===> ĐÃ CÓ
                {
                    DialogResult dialogResult = MessageBox.Show("Bạn có muốn cập nhật dịch vụ này ?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (dialogResult == DialogResult.Yes) //ĐỒNG Ý CẬP NHẬT
                    {
                        if (update_DV())
                        {
                            cbServiceType.Text  = "";
                            txtServiceName.Text = "";
                            txtPrice.Text       = "";

                            MessageBox.Show("Cập nhật thành công", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ServiceForm sf = ServiceForm._instance;
                            sf.loadDV();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else //KHÔNG ĐỒNG Ý
                    {
                        return;
                    }
                }
                else //CHƯA CÓ TÊN DV ĐÓ
                {
                    if (createService())
                    {
                        MessageBox.Show("Tạo thành công", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        cbServiceType.Text  = "";
                        txtServiceName.Text = "";
                        txtPrice.Text       = "";
                        con.Close();
                        //ServiceForm sf = ServiceForm._instance;
                        //sf.displayData();
                    }
                    else
                    {
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }