Пример #1
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (gvBophan.FocusedRowHandle < 0)
     {
         MessageBox.Show("Vui lòng chọn dòng để xóa!", "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Hand);
         return;
     }
     if (XtraMessageBox.Show("Bạn có muốn xóa hay không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         var id    = Convert.ToInt32(gvBophan.GetRowCellValue(gvBophan.FocusedRowHandle, gvBophan.Columns[2]));
         var delbp = db.BoPhan.FirstOrDefault(m => m.Id == id);
         if (gvBophan.FocusedRowHandle < gvBophan.RowCount - 1)
         {
             var idduoi = Convert.ToInt32(gvBophan.GetRowCellValue(gvBophan.FocusedRowHandle + 1, gvBophan.Columns[2]));
             var editbp = db.BoPhan.FirstOrDefault(m => m.Id == idduoi);
             editbp.STT = delbp.STT;
         }
         db.BoPhan.Remove(delbp);
         db.SaveChanges();
         BoPhanToChuc_Load(sender, e);
         PostData();
         MessageBox.Show("Xóa thành công!", "Success",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
 }
Пример #2
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < gvQuantri.RowCount; i++)
     {
         var id     = Convert.ToInt32(gvQuantri.GetRowCellValue(i, gvQuantri.Columns[0]));
         var editnv = db.NhanVien.FirstOrDefault(m => m.Id == id);
         editnv.HoTen     = gvQuantri.GetRowCellValue(i, gvQuantri.Columns[2]).ToString();
         editnv.MaNV      = gvQuantri.GetRowCellValue(i, gvQuantri.Columns[1]).ToString();
         editnv.NgaySinh  = Convert.ToDateTime(gvQuantri.GetRowCellValue(i, gvQuantri.Columns[3]));
         editnv.SoCMND    = Convert.ToInt32(gvQuantri.GetRowCellValue(i, gvQuantri.Columns[4]));
         editnv.DiaChi    = gvQuantri.GetRowCellValue(i, gvQuantri.Columns[5]).ToString();
         editnv.DienThoai = gvQuantri.GetRowCellValue(i, gvQuantri.Columns[6]).ToString();
         editnv.Account   = gvQuantri.GetRowCellValue(i, gvQuantri.Columns[7]).ToString();
         foreach (var item in lstNhanvien)
         {
             if (item.Id == id)
             {
                 editnv.Password = item.Password;
             }
         }
         db.SaveChanges();
         if (NameNhanVienEvent != null)
         {
             var idnv = db.NhanVien.FirstOrDefault(m => m.Id == iddn);
             NameNhanVienEvent(idnv.HoTen);
         }
     }
     MessageBox.Show("Lưu thành công!", "Success",
                     MessageBoxButtons.OK, MessageBoxIcon.Information);
     return;
 }
Пример #3
0
        public ActionResult Create([Bind(Include = "MaDV,TenDV,DonGiaVN")] DICHVU dICHVU)
        {
            if (ModelState.IsValid)
            {
                db.DICHVUS.Add(dICHVU);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(dICHVU));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "MaHD,MaKH,SoTien,NgayTT,HinhThucTT")] HOADON hOADON)
        {
            if (ModelState.IsValid)
            {
                db.HOADONS.Add(hOADON);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hOADON));
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "MaKH,HoTenKH,SoDT")] KhachHang khachHang)
        {
            if (ModelState.IsValid)
            {
                db.KhachHangs.Add(khachHang);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(khachHang));
        }
Пример #6
0
        public ActionResult Create([Bind(Include = "MaKH,NgayDen,NgayDi,ThanhToan")] THUEPHONG tHUEPHONG)
        {
            if (ModelState.IsValid)
            {
                db.THUEPHONGS.Add(tHUEPHONG);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tHUEPHONG));
        }
Пример #7
0
        public ActionResult Create([Bind(Include = "MaPhong,TenPhong,LoaiPhong,TrangThai,GiaPhong")] PHONG pHONG)
        {
            if (ModelState.IsValid)
            {
                db.PHONGS.Add(pHONG);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(pHONG));
        }
Пример #8
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            string sdt   = txtSDT.EditValue.ToString().Trim();
            string cmnd  = txtCMND.EditValue.ToString().Trim();
            string tk    = txtTK.EditValue.ToString().Trim();
            string mk    = txtMK.EditValue.ToString().Trim();
            string golai = txtGolai.EditValue.ToString().Trim();
            string hoten = txtHoten.EditValue.ToString().Trim();
            string manv  = txtMaNV.EditValue.ToString().Trim();

            if (string.IsNullOrEmpty(sdt) || string.IsNullOrEmpty(cmnd) || string.IsNullOrEmpty(tk) || string.IsNullOrEmpty(mk) || string.IsNullOrEmpty(golai) || string.IsNullOrEmpty(hoten) || string.IsNullOrEmpty(manv))
            {
                MessageBox.Show("Các dòng (*) không được để trống!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (mk != golai)
            {
                MessageBox.Show("Mật khẩu và lặp lại mật khẩu không khớp!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            byte[] temp    = ASCIIEncoding.ASCII.GetBytes(mk);
            byte[] hasData = new MD5CryptoServiceProvider().ComputeHash(temp);
            string hasPass = "";

            foreach (byte item in hasData)
            {
                hasPass += item;
            }
            NhanVien nv = new NhanVien();

            nv.MaNV   = manv;
            nv.SoCMND = Convert.ToInt32(cmnd);
            if (dateEditNS.EditValue.ToString() != "")
            {
                nv.NgaySinh = Convert.ToDateTime(dateEditNS.EditValue);
            }
            nv.DienThoai = txtSDT.EditValue.ToString();
            nv.MaNhom    = cbNhom.EditValue.ToString();
            nv.Account   = tk;
            nv.Password  = hasPass;
            nv.HoTen     = hoten;
            if (txtDiachi.EditValue.ToString() != "")
            {
                nv.DiaChi = txtDiachi.EditValue.ToString();
            }
            db.NhanVien.Add(nv);
            db.SaveChanges();
            PostData();
            MessageBox.Show("Thêm thành công!", "Success",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }
Пример #9
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     if (t == 1)
     {
         Room r = new Room();
         r.Sophong  = Convert.ToInt32(gvDataList.GetRowCellValue(gvDataList.FocusedRowHandle, gvDataList.Columns[5]));
         r.Songuoi  = Convert.ToInt32(gvDataList.GetRowCellValue(gvDataList.FocusedRowHandle, gvDataList.Columns[0]));
         r.Sogiuong = Convert.ToInt32(gvDataList.GetRowCellValue(gvDataList.FocusedRowHandle, gvDataList.Columns[1]));
         r.TienPVND = Convert.ToInt32(gvDataList.GetRowCellValue(gvDataList.FocusedRowHandle, gvDataList.Columns[3]));
         r.TienPUSD = Convert.ToInt32(gvDataList.GetRowCellValue(gvDataList.FocusedRowHandle, gvDataList.Columns[4]));
         r.Manhom   = manhom;
         r.Maloai   = Convert.ToInt32(gvDataList.GetRowCellValue(gvDataList.FocusedRowHandle, gvDataList.Columns[2]));
         r.Sophone  = gvDataList.GetRowCellValue(gvDataList.FocusedRowHandle, gvDataList.Columns[5]).ToString();
         r.Status   = 1;
         db.Rooms.Add(r);
         db.SaveChanges();
     }
     else
     {
         for (int i = 0; i < gvDataList.RowCount - 1; i++)
         {
             var id       = Convert.ToInt32(gvDataList.GetRowCellValue(i, gvDataList.Columns[6]));
             var editroom = db.Rooms.FirstOrDefault(m => m.Id == id);
             editroom.Sophong  = Convert.ToInt32(gvDataList.GetRowCellValue(i, gvDataList.Columns[5]));
             editroom.Maloai   = Convert.ToInt32(gvDataList.GetRowCellValue(i, gvDataList.Columns[2]));
             editroom.Songuoi  = Convert.ToInt32(gvDataList.GetRowCellValue(i, gvDataList.Columns[0]));
             editroom.Sogiuong = Convert.ToInt32(gvDataList.GetRowCellValue(i, gvDataList.Columns[1]));
             editroom.TienPVND = Convert.ToInt32(gvDataList.GetRowCellValue(i, gvDataList.Columns[3]));
             editroom.TienPUSD = Convert.ToInt32(gvDataList.GetRowCellValue(i, gvDataList.Columns[4]));
             db.SaveChanges();
         }
     }
     MessageBox.Show("Lưu thành công!", "Success",
                     MessageBoxButtons.OK, MessageBoxIcon.Information);
     btnThem.Enabled  = true;
     btnBoqua.Enabled = false;
 }
Пример #10
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            List <int> row = gvDichvu.GetSelectedRows().Where(m => m >= 0).ToList();

            foreach (var i in lstdv)
            {
                foreach (var item in row)
                {
                    if (i.Id == Convert.ToInt32(gvDichvu.GetRowCellValue(item, gvDichvu.Columns[5])))
                    {
                        if (Convert.ToInt32(gvDichvu.GetRowCellValue(item, gvDichvu.Columns[4])) <= 0)
                        {
                            MessageBox.Show("Vui lòng chọn số lượng của dịch vụ!");
                            return;
                        }
                        Thongtin tt  = new Thongtin();
                        PhongDV  pdv = new PhongDV();
                        pdv.MaDV     = gvDichvu.GetRowCellValue(item, gvDichvu.Columns[0]).ToString();
                        pdv.IdPhong  = idphong;
                        pdv.Soluong  = Convert.ToInt32(gvDichvu.GetRowCellValue(item, gvDichvu.Columns[4]));
                        pdv.Loaitien = loaitien;
                        if (pdv.Loaitien == "USD")
                        {
                            pdv.DonGia = Convert.ToInt32(gvDichvu.GetRowCellValue(item, gvDichvu.Columns[3])) * 22000;
                        }
                        else
                        {
                            pdv.DonGia = Convert.ToInt32(gvDichvu.GetRowCellValue(item, gvDichvu.Columns[3]));
                        }
                        if (Convert.ToString(gvDichvu.GetRowCellValue(item, gvDichvu.Columns[2])) != "")
                        {
                            pdv.Thanhtien = pdv.Soluong * pdv.DonGia;
                        }
                        else
                        {
                            pdv.Thanhtien = pdv.DonGia;
                        }
                        pdv.Tygia  = tygia;
                        pdv.Ngay   = DateTime.Now.Date;
                        pdv.Gio    = DateTime.Now.ToShortTimeString();
                        pdv.Ghichu = "";
                        var p_dv = db.PhongDVs.Where(m => m.MaDV == pdv.MaDV && m.IdPhong == pdv.IdPhong).Count();
                        if (p_dv != 0)
                        {
                            var editpdv = db.PhongDVs.Where(m => m.MaDV == pdv.MaDV && m.IdPhong == pdv.IdPhong).First();
                            editpdv.Soluong += pdv.Soluong;
                            db.SaveChanges();
                        }
                        else
                        {
                            db.PhongDVs.Add(pdv);
                            db.SaveChanges();
                        }
                        var sl = Convert.ToInt32(gvDichvu.GetRowCellValue(item, gvDichvu.Columns[4]));
                        var dv = db.DichVu.Where(m => m.Id == i.Id).First();
                        dv.SoLuong = i.SoLuong - sl;
                        db.SaveChanges();
                        MessageBox.Show("Thêm thành công!");
                        this.Close();
                    }
                    else
                    {
                        var editsl = db.DichVu.Where(m => m.Id == i.Id).First();
                        editsl.SoLuong = i.SoLuong;
                        db.SaveChanges();
                    }
                }
            }
        }
Пример #11
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     if (t == 0)
     {
         if (txtCmnd.Text == "")
         {
             MessageBox.Show("CMND không được để trống!");
             return;
         }
         var         list      = db.DK_Customers.ToList();
         DK_Customer khachhang = new DK_Customer();
         Khach       khach     = new Khach();
         //khachhang.Id = k;
         khachhang.Id       = Convert.ToInt32(gvDataCheckin.GetRowCellValue(gvDataCheckin.FocusedRowHandle, "Id"));
         khachhang.CMND     = txtCmnd.Text.ToString().Trim();
         khachhang.Hoten    = txtHoten.Text.ToString().Trim();
         khachhang.Quoctich = Convert.ToInt32(lookUpEditQuoctich.EditValue);
         if (cbGioitinh.Checked == true)
         {
             khachhang.Gioitinh = true;
         }
         else
         {
             khachhang.Gioitinh = false;
         }
         if (cbDaidien.Checked == true)
         {
             khachhang.Daidien = true;
         }
         else
         {
             khachhang.Daidien = false;
         }
         khachhang.DateCheckin  = Convert.ToDateTime(dateEditCheckin.EditValue);
         khachhang.GioCheckin   = txtGioCheckin.Text.ToString().Trim();
         khachhang.DateCheckout = Convert.ToDateTime(dateEditCheckout.EditValue);
         khachhang.GioCheckout  = txtGioCheckout.Text.ToString().Trim();
         khachhang.Ghichu       = memoEditGhichu.Text.ToString().Trim();
         khachhang.Sophong      = Convert.ToInt32(labPhong.Text);
         khach.DonVi            = "Khách hàng";
         khach.SoCMND           = khachhang.CMND;
         khach.HoTen            = khachhang.Hoten;
         khach.MaQT             = khachhang.Quoctich;
         khach.GioiTnh          = khachhang.Gioitinh;
         khach.MaBank           = "";
         khach.NgaySinh         = Convert.ToDateTime("01-01-1900");
         khach.Phone            = "";
         khach.SoATM            = 0;
         khach.GhiChu           = "";
         db.DK_Customers.Add(khachhang);
         if (otp == 1)
         {
             KhachHangBUS.Instance.NewKhachHang(khach);
             var idkh = db.Khach.OrderByDescending(m => m.Id).First();
             khachhang.IdKH = idkh.Id;
             DK_CustomerBUS.Instance.NewCustomer(khachhang);
             DK_CustomerBUS.Instance.Xem(gcDataCheckin, Convert.ToInt32(labPhong.Text));
             MessageBox.Show("Thêm thành công!");
             gcDataCheckin.Enabled = true;
             btnThemnguoi.Enabled  = true;
             sodophong             = new Sodophong();
             Thongtin_Load(sender, e);
             GetData data = new GetData(sodophong.PostData);
             data(list);
             otp = 0;
             btnDelete.Enabled = true;
         }
         else
         {
             khach.Id = idkh;
             DK_CustomerBUS.Instance.EditCustomer(khachhang);
             KhachHangBUS.Instance.EditKhachHang(khach);
             DK_CustomerBUS.Instance.Xem(gcDataCheckin, Convert.ToInt32(labPhong.Text));
             MessageBox.Show("Sửa thành công!");
             gcDataCheckin.Enabled = true;
             btnThemnguoi.Enabled  = true;
         }
     }
     else if (t == 1)
     {
         if (gvListDichvu.DataSource != null)
         {
             for (int i = 0; i < gvListDichvu.RowCount; i++)
             {
                 int id  = Convert.ToInt32(gvListDichvu.GetRowCellValue(i, gvListDichvu.Columns[0]));
                 var pdv = db.PhongDVs.FirstOrDefault(c => c.Id == id);
                 if (pdv.Soluong > Convert.ToInt32(gvListDichvu.GetRowCellValue(i, gvListDichvu.Columns[6])))
                 {
                     pdv.Soluong = pdv.Soluong - Convert.ToInt32(gvListDichvu.GetRowCellValue(i, gvListDichvu.Columns[6]));
                     if (pdv.Loaitien == "VNĐ")
                     {
                         pdv.Thanhtien = pdv.Soluong * pdv.DonGia;
                     }
                     else
                     {
                         pdv.Thanhtien = pdv.Soluong * pdv.DonGia * pdv.Tygia;
                     }
                     var dv = db.DichVu.FirstOrDefault(c => c.MaDV == pdv.MaDV);
                     dv.SoLuong += Convert.ToInt32(gvListDichvu.GetRowCellValue(i, gvListDichvu.Columns[6]));
                     db.SaveChanges();
                 }
                 else if (pdv.Soluong < Convert.ToInt32(gvListDichvu.GetRowCellValue(i, gvListDichvu.Columns[6])))
                 {
                     pdv.Soluong = pdv.Soluong + Convert.ToInt32(gvListDichvu.GetRowCellValue(i, gvListDichvu.Columns[6]));
                     if (pdv.Loaitien == "VNĐ")
                     {
                         pdv.Thanhtien = pdv.Soluong * pdv.DonGia;
                     }
                     else
                     {
                         pdv.Thanhtien = pdv.Soluong * pdv.DonGia * pdv.Tygia;
                     }
                     var dv = db.DichVu.FirstOrDefault(c => c.MaDV == pdv.MaDV);
                     dv.SoLuong -= Convert.ToInt32(gvListDichvu.GetRowCellValue(i, gvListDichvu.Columns[6]));
                     db.SaveChanges();
                 }
             }
         }
         if (gcBaothuc.DataSource != null)
         {
             for (int i = 0; i < gvBaothuc.RowCount - 1; i++)
             {
                 var id = Convert.ToInt32(gvBaothuc.GetRowCellValue(i, gvBaothuc.Columns[4]));
                 var bt = db.BaoThuc.Where(m => m.Id == id).Count();
                 if (bt != 0)
                 {
                     var editbt = db.BaoThuc.FirstOrDefault(m => m.Id == id);
                     editbt.Ngay    = Convert.ToDateTime(gvBaothuc.GetRowCellValue(i, gvBaothuc.Columns[0]));
                     editbt.Gio     = gvBaothuc.GetRowCellValue(i, gvBaothuc.Columns[1]).ToString();
                     editbt.NoiDung = gvBaothuc.GetRowCellValue(i, gvBaothuc.Columns[2]).ToString();
                     editbt.Lap     = gvBaothuc.GetRowCellValue(i, gvBaothuc.Columns[3]).ToString();
                     db.SaveChanges();
                 }
                 else
                 {
                     BaoThuc addbt = new BaoThuc();
                     addbt.IdPhong = Convert.ToInt32(labPhong.Text);
                     addbt.Ngay    = Convert.ToDateTime(gvBaothuc.GetRowCellValue(i, gvBaothuc.Columns[0]));
                     addbt.Gio     = Convert.ToString(gvBaothuc.GetRowCellValue(i, gvBaothuc.Columns[1]));
                     addbt.NoiDung = Convert.ToString(gvBaothuc.GetRowCellValue(i, gvBaothuc.Columns[2]));
                     addbt.Lap     = Convert.ToString(gvBaothuc.GetRowCellValue(i, gvBaothuc.Columns[3]));
                     db.BaoThuc.Add(addbt);
                     db.SaveChanges();
                 }
             }
         }
     }
     else if (t == 4)
     {
         if (gcSuachua.DataSource != null)
         {
             for (int i = 0; i < gvSuachua.RowCount - 1; i++)
             {
                 var id = Convert.ToInt32(gvSuachua.GetRowCellValue(i, gvSuachua.Columns[0]));
                 var sc = db.PhongS.Where(m => m.Id == id).Count();
                 if (sc != 0)
                 {
                     var editsc = db.PhongS.FirstOrDefault(m => m.Id == id);
                     editsc.MaStatus = ma;
                     editsc.Tungay   = tungay;
                     editsc.Denngay  = denngay;
                     db.SaveChanges();
                 }
                 else
                 {
                     PhongS addsc = new PhongS();
                     addsc.Sophong  = Convert.ToInt32(labPhong.Text);
                     addsc.MaStatus = ma;
                     addsc.Tungay   = tungay;
                     addsc.Denngay  = denngay;
                     db.PhongS.Add(addsc);
                     db.SaveChanges();
                 }
             }
         }
     }
 }
Пример #12
0
        private void btnChapnhan_Click(object sender, EventArgs e)
        {
            string mkc    = MahoaMD5(txtmkcu.EditValue.ToString().Trim());
            string mkm    = MahoaMD5(txtmkm.EditValue.ToString().Trim());
            string laplai = MahoaMD5(txtgolai.EditValue.ToString().Trim());

            if (string.IsNullOrEmpty(mkc))
            {
                MessageBox.Show("Mật khẩu cũ không được để trống!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtmkcu.Focus();
                return;
            }
            else if (string.IsNullOrEmpty(mkm))
            {
                MessageBox.Show("Mật khẩu mới không được để trống!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtmkm.Focus();
                return;
            }
            else if (string.IsNullOrEmpty(laplai))
            {
                MessageBox.Show("Gõ lại mật khẩu mới không được để trống!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtgolai.Focus();
                return;
            }
            var ktmkc = db.NhanVien.Where(m => m.Id == id && m.Password == mkc).Count();

            if (ktmkc > 0)
            {
                if (mkm == laplai)
                {
                    if (t == 0)
                    {
                        var dmk = db.NhanVien.FirstOrDefault(m => m.Id == id);
                        dmk.Password = mkm;
                        db.SaveChanges();
                        MessageBox.Show("Đổi mật khẩu thành công!", "Succes",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (t == 1)
                    {
                        if (PasswordEvent != null)
                        {
                            PasswordEvent(id, mkm);
                            this.Close();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Mật khẩu mới và gõ lại mật khẩu không khớp!", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtmkm.Focus();
                    return;
                }
            }
            else
            {
                MessageBox.Show("Mật khẩu cũ không đúng!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtmkcu.Focus();
                return;
            }
        }
Пример #13
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string phong = "";

            if (glueDoitac.Text == "")
            {
                MessageBox.Show("Vui lòng chọn khách hàng hoặc đối tác!");
                glueDoitac.Focus();
                return;
            }
            else
            {
                var idkhach = Convert.ToInt32(glueDoitac.EditValue);
                if (t == 1)
                {
                    if (txtSo.Text == "")
                    {
                        if (gcDangky.DataSource == null)
                        {
                            MessageBox.Show("Vui lòng chọn phòng để đăng ký");
                            return;
                        }
                        Dangky dk = new Dangky();
                        dk.NgayDK       = Convert.ToDateTime(dateNgay.EditValue.ToString());
                        dk.NgayCheckin  = Convert.ToDateTime(dateCheckin.EditValue.ToString());
                        dk.NgayCheckout = Convert.ToDateTime(dateCheckout.EditValue.ToString());
                        dk.SotienUT     = Convert.ToDouble(tbDattruoc.Text.ToString());
                        dk.Sokhach      = Convert.ToInt32(gvDangky.Columns[2].SummaryItem.SummaryValue);
                        dk.Sophong      = Convert.ToInt32(gvDangky.Columns[3].SummaryItem.SummaryValue);
                        dk.DaCheckin    = false;
                        dk.Ghichu       = tbNoidung.Text.ToString();
                        dk.HinhthucTT   = cbHinhthuc.EditValue.ToString();
                        dk.Loaitien     = cbxLoai.EditValue.ToString();
                        if (dk.HinhthucTT == "Tiền mặt")
                        {
                            dk.SoATM = "";
                        }
                        else
                        {
                            dk.SoATM = tbSoTK.EditValue.ToString();
                        }
                        dk.Tygia  = Convert.ToInt32(tbTygia.Text.ToString());
                        dk.MaBank = glueNganhang.EditValue.ToString();
                        dk.NgayUT = Convert.ToDateTime(dtDattruoc.EditValue.ToString());
                        db.Dangky.Add(dk);
                        db.SaveChanges();
                        var id = db.Dangky.Where(m => m.DaCheckin == false).OrderByDescending(m => m.Id).First();
                        for (int j = 0; j < gvDangky.RowCount; j++)
                        {
                            GridView dView = gvDangky.GetDetailView(j, 0) as GridView;
                            if (dView == null)
                            {
                                MessageBox.Show("Vui lòng nhập thông tin khách hàng đăng ký!");
                                return;
                            }
                            phong.Trim();
                            phong += gvDangky.GetRowCellValue(j, gvDangky.Columns[0]).ToString();
                            if (j < gvDangky.RowCount - 1)
                            {
                                phong += ",";
                            }
                            DK_Customer dk_khach = new DK_Customer();
                            Khach       khach    = new Khach();
                            DangKyPhong dk_phong = new DangKyPhong();
                            for (int i = 0; i < dView.RowCount; i++)
                            {
                                if (dView.GetRowCellValue(i, dView.Columns[0]) != null && dView.GetRowCellValue(i, dView.Columns[1]) != null)
                                {
                                    khach.HoTen    = dView.GetRowCellValue(i, dView.Columns[1]).ToString();
                                    khach.SoCMND   = dView.GetRowCellValue(i, dView.Columns[0]).ToString();
                                    khach.GioiTnh  = Convert.ToBoolean(dView.GetRowCellValue(i, dView.Columns[2]));
                                    khach.MaQT     = Convert.ToInt32(dView.GetRowCellValue(i, dView.Columns[3]));
                                    khach.NgaySinh = DateTime.Now;
                                    khach.DonVi    = "Khách hàng";
                                    if (edtDienThoai.Text == "Nhập số điện thoại")
                                    {
                                        khach.Phone = "";
                                    }
                                    else
                                    {
                                        khach.Phone = edtDienThoai.Text.ToString();
                                    }
                                    db.Khach.Add(khach);
                                    db.SaveChanges();
                                    var idkh = db.Khach.OrderByDescending(m => m.Id).First();
                                    dk_khach.IdDK         = id.Id;
                                    dk_khach.IdKH         = idkhach;
                                    dk_khach.Hoten        = dView.GetRowCellValue(i, dView.Columns[1]).ToString();
                                    dk_khach.CMND         = dView.GetRowCellValue(i, dView.Columns[0]).ToString();
                                    dk_khach.Gioitinh     = Convert.ToBoolean(dView.GetRowCellValue(i, dView.Columns[2]));
                                    dk_khach.Quoctich     = Convert.ToInt32(dView.GetRowCellValue(i, dView.Columns[3]));
                                    dk_khach.Sophong      = Convert.ToInt32(gvDangky.GetRowCellValue(j, gvDangky.Columns[0]));
                                    dk_khach.DateCheckin  = Convert.ToDateTime(dateCheckin.EditValue.ToString());
                                    dk_khach.DateCheckout = Convert.ToDateTime(dateCheckout.EditValue.ToString());
                                    dk_khach.GioCheckin   = DateTime.Now.ToShortTimeString();
                                    dk_khach.GioCheckout  = "12:00";
                                    db.DK_Customers.Add(dk_khach);
                                    db.SaveChanges();
                                    dk_phong.IDDK         = id.Id;
                                    dk_phong.SoPhong      = Convert.ToInt32(gvDangky.GetRowCellValue(j, gvDangky.Columns[0]));
                                    dk_phong.NgayCheckIn  = Convert.ToDateTime(dateCheckin.EditValue.ToString());
                                    dk_phong.NgayCheckOut = Convert.ToDateTime(dateCheckout.EditValue.ToString());
                                    dk_phong.LoaiTien     = id.Loaitien;
                                    dk_phong.TyGia        = id.Tygia;
                                    dk_phong.GhiChu       = id.Ghichu;
                                    dk_phong.DaCheckIn    = id.DaCheckin;
                                    dk_phong.DonGia       = Convert.ToInt32(gvDangky.GetRowCellValue(j, gvDangky.Columns[1]));
                                    db.DangKyPhong.Add(dk_phong);
                                }
                            }
                        }
                        txtSo.Text = id.ToString();
                        var update = db.Dangky.FirstOrDefault(m => m.Id == id.Id);
                        update.Phong = phong.ToString();
                        db.SaveChanges();
                        t = 0;
                    }
                    else
                    {
                        var id = Convert.ToInt32(txtSo.Text);
                        var dk = db.Dangky.FirstOrDefault(m => m.Id == id);
                        dk.NgayDK       = Convert.ToDateTime(dateNgay.EditValue.ToString());
                        dk.NgayCheckin  = Convert.ToDateTime(dateCheckin.EditValue.ToString());
                        dk.NgayCheckout = Convert.ToDateTime(dateCheckout.EditValue.ToString());
                        dk.SotienUT     = Convert.ToDouble(tbDattruoc.Text.ToString());
                        dk.Sokhach      = Convert.ToInt32(gvDangky.Columns[2].SummaryItem.SummaryValue);
                        dk.Sophong      = Convert.ToInt32(gvDangky.Columns[3].SummaryItem.SummaryValue);
                        dk.DaCheckin    = false;
                        dk.Ghichu       = tbNoidung.Text.ToString();
                        dk.HinhthucTT   = cbHinhthuc.EditValue.ToString();
                        dk.Loaitien     = cbxLoai.EditValue.ToString();
                        if (dk.HinhthucTT == "Tiền mặt")
                        {
                            dk.SoATM = "";
                        }
                        else
                        {
                            dk.SoATM = tbSoTK.EditValue.ToString();
                        }
                        dk.Tygia  = Convert.ToInt32(tbTygia.Text.ToString());
                        dk.MaBank = glueNganhang.EditValue.ToString();
                        dk.NgayUT = Convert.ToDateTime(dtDattruoc.EditValue.ToString());
                        phong     = dk.Phong.ToString();
                        db.SaveChanges();
                        var dkphong = db.DangKyPhong.Where(m => m.IDDK == id).Count();
                        if (gvDangky.RowCount > dkphong)
                        {
                            for (int j = dkphong; j < gvDangky.RowCount; j++)
                            {
                                GridView dView = gvDangky.GetDetailView(j, 0) as GridView;
                                phong.Trim();
                                phong += gvDangky.GetRowCellValue(j, gvDangky.Columns[0]).ToString();
                                if (j < gvDangky.RowCount - 1)
                                {
                                    phong += ",";
                                }
                                DK_Customer dk_khach = new DK_Customer();
                                Khach       khach    = new Khach();
                                DangKyPhong dk_phong = new DangKyPhong();
                                for (int i = 0; i < dView.RowCount; i++)
                                {
                                    if (dView.GetRowCellValue(i, dView.Columns[0]) != null && dView.GetRowCellValue(i, dView.Columns[1]) != null)
                                    {
                                        khach.HoTen    = dView.GetRowCellValue(i, dView.Columns[1]).ToString();
                                        khach.SoCMND   = dView.GetRowCellValue(i, dView.Columns[0]).ToString();
                                        khach.GioiTnh  = Convert.ToBoolean(dView.GetRowCellValue(i, dView.Columns[2]));
                                        khach.MaQT     = Convert.ToInt32(dView.GetRowCellValue(i, dView.Columns[3]));
                                        khach.NgaySinh = DateTime.Now;
                                        khach.DonVi    = "Khách hàng";
                                        if (edtDienThoai.Text == "Nhập số điện thoại")
                                        {
                                            khach.Phone = "";
                                        }
                                        else
                                        {
                                            khach.Phone = edtDienThoai.Text.ToString();
                                        }
                                        db.Khach.Add(khach);
                                        db.SaveChanges();
                                        dk_khach.IdDK         = id;
                                        dk_khach.IdKH         = idkhach;
                                        dk_khach.Hoten        = dView.GetRowCellValue(i, dView.Columns[1]).ToString();
                                        dk_khach.CMND         = dView.GetRowCellValue(i, dView.Columns[0]).ToString();
                                        dk_khach.Gioitinh     = Convert.ToBoolean(dView.GetRowCellValue(i, dView.Columns[2]));
                                        dk_khach.Quoctich     = Convert.ToInt32(dView.GetRowCellValue(i, dView.Columns[3]));
                                        dk_khach.Sophong      = Convert.ToInt32(gvDangky.GetRowCellValue(j, gvDangky.Columns[0]));
                                        dk_khach.DateCheckin  = Convert.ToDateTime(dateCheckin.EditValue.ToString());
                                        dk_khach.DateCheckout = Convert.ToDateTime(dateCheckout.EditValue.ToString());
                                        dk_khach.GioCheckin   = DateTime.Now.ToShortTimeString();
                                        dk_khach.GioCheckout  = "12:00";
                                        db.DK_Customers.Add(dk_khach);
                                        db.SaveChanges();
                                        dk_phong.IDDK         = id;
                                        dk_phong.SoPhong      = Convert.ToInt32(gvDangky.GetRowCellValue(j, gvDangky.Columns[0]));
                                        dk_phong.NgayCheckIn  = Convert.ToDateTime(dateCheckin.EditValue.ToString());
                                        dk_phong.NgayCheckOut = Convert.ToDateTime(dateCheckout.EditValue.ToString());
                                        dk_phong.LoaiTien     = cbxLoai.EditValue.ToString();
                                        dk_phong.TyGia        = Convert.ToInt32(tbTygia.Text.ToString());
                                        dk_phong.GhiChu       = tbNoidung.Text.ToString();
                                        dk_phong.DaCheckIn    = false;
                                        dk_phong.DonGia       = Convert.ToInt32(gvDangky.GetRowCellValue(j, gvDangky.Columns[1]));
                                        db.DangKyPhong.Add(dk_phong);
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int j = 0; j < gvDangky.RowCount; j++)
                            {
                                var         sophong  = Convert.ToInt32(gvDangky.GetRowCellValue(j, gvDangky.Columns[0]));
                                var         dkkhach  = db.DK_Customers.Where(m => m.IdDK == id && m.Sophong == sophong).Count();
                                GridView    dView    = gvDangky.GetDetailView(j, 0) as GridView;
                                DK_Customer dk_khach = new DK_Customer();
                                Khach       khach    = new Khach();
                                DangKyPhong dk_phong = new DangKyPhong();
                                int         dem      = 0;
                                for (int i = 0; i < dView.RowCount; i++)
                                {
                                    if (dView.GetRowCellValue(i, dView.Columns[0]) != null && dView.GetRowCellValue(i, dView.Columns[1]) != null)
                                    {
                                        dem++;
                                    }
                                }
                                if (dem > dkkhach)
                                {
                                    for (int i = dkkhach; i < dView.RowCount; i++)
                                    {
                                        if (dView.GetRowCellValue(i, dView.Columns[0]) != null && dView.GetRowCellValue(i, dView.Columns[1]) != null)
                                        {
                                            khach.HoTen    = dView.GetRowCellValue(i, dView.Columns[1]).ToString();
                                            khach.SoCMND   = dView.GetRowCellValue(i, dView.Columns[0]).ToString();
                                            khach.GioiTnh  = Convert.ToBoolean(dView.GetRowCellValue(i, dView.Columns[2]));
                                            khach.MaQT     = Convert.ToInt32(dView.GetRowCellValue(i, dView.Columns[3]));
                                            khach.NgaySinh = DateTime.Now;
                                            khach.DonVi    = "Khách hàng";
                                            if (edtDienThoai.Text == "Nhập số điện thoại")
                                            {
                                                khach.Phone = "";
                                            }
                                            else
                                            {
                                                khach.Phone = edtDienThoai.Text.ToString();
                                            }
                                            db.Khach.Add(khach);
                                            db.SaveChanges();
                                            var idkh = db.Khach.OrderByDescending(m => m.Id == idkhach).First();
                                            dk_khach.IdDK         = id;
                                            dk_khach.IdKH         = idkhach;
                                            dk_khach.Hoten        = dView.GetRowCellValue(i, dView.Columns[1]).ToString();
                                            dk_khach.CMND         = dView.GetRowCellValue(i, dView.Columns[0]).ToString();
                                            dk_khach.Gioitinh     = Convert.ToBoolean(dView.GetRowCellValue(i, dView.Columns[2]));
                                            dk_khach.Quoctich     = Convert.ToInt32(dView.GetRowCellValue(i, dView.Columns[3]));
                                            dk_khach.Sophong      = Convert.ToInt32(gvDangky.GetRowCellValue(i, gvDangky.Columns[0]));
                                            dk_khach.DateCheckin  = Convert.ToDateTime(dateCheckin.EditValue.ToString());
                                            dk_khach.DateCheckout = Convert.ToDateTime(dateCheckout.EditValue.ToString());
                                            dk_khach.GioCheckin   = DateTime.Now.ToShortTimeString();
                                            dk_khach.Sophong      = Convert.ToInt32(dView.GetRowCellValue(i, dView.Columns[4]));
                                            dk_khach.GioCheckout  = "12:00";
                                            db.DK_Customers.Add(dk_khach);
                                            db.SaveChanges();
                                        }
                                    }
                                }
                                else if (dem <= dkkhach)
                                {
                                    for (int i = 0; i < dkkhach; i++)
                                    {
                                        if (dView.GetRowCellValue(i, dView.Columns[0]) != null && dView.GetRowCellValue(i, dView.Columns[1]) != null)
                                        {
                                            var iddk      = Convert.ToInt32(dView.GetRowCellValue(i, dView.Columns[5]).ToString());
                                            var editkhach = db.Khach.FirstOrDefault(m => m.Id == idkhach);
                                            if (edtDienThoai.Text == "Nhập số điện thoại")
                                            {
                                                editkhach.Phone = "";
                                            }
                                            else
                                            {
                                                editkhach.Phone = edtDienThoai.Text.ToString();
                                            }
                                            db.SaveChanges();
                                            DK_Customer edit_dkkhach = (from dkcus in db.DK_Customers
                                                                        where dkcus.Id == iddk
                                                                        select dkcus).DefaultIfEmpty().Single();
                                            DK_Customer dkcustomer = new DK_Customer();
                                            dkcustomer.IdKH           = idkhach;
                                            dkcustomer.Hoten          = dView.GetRowCellValue(i, dView.Columns[1]).ToString();
                                            dkcustomer.CMND           = dView.GetRowCellValue(i, dView.Columns[0]).ToString();
                                            dkcustomer.Gioitinh       = Convert.ToBoolean(dView.GetRowCellValue(i, dView.Columns[2]));
                                            dkcustomer.Quoctich       = Convert.ToInt32(dView.GetRowCellValue(i, dView.Columns[3]).ToString());
                                            dkcustomer.Sophong        = Convert.ToInt32(gvDangky.GetRowCellValue(i, gvDangky.Columns[0]));
                                            dkcustomer.DateCheckin    = Convert.ToDateTime(dateCheckin.EditValue.ToString());
                                            dkcustomer.DateCheckout   = Convert.ToDateTime(dateCheckout.EditValue.ToString());
                                            dkcustomer.GioCheckin     = DateTime.Now.ToShortTimeString();
                                            dkcustomer.GioCheckout    = "12:00";
                                            edit_dkkhach.CMND         = dkcustomer.CMND;
                                            edit_dkkhach.Hoten        = dkcustomer.Hoten;
                                            edit_dkkhach.Gioitinh     = dkcustomer.Gioitinh;
                                            edit_dkkhach.Quoctich     = dkcustomer.Quoctich;
                                            edit_dkkhach.DateCheckin  = dkcustomer.DateCheckin;
                                            edit_dkkhach.DateCheckout = dkcustomer.DateCheckout;
                                            edit_dkkhach.IdKH         = dkcustomer.IdKH;
                                            db.SaveChanges();
                                        }
                                    }
                                }
                            }
                        }
                        var update = db.Dangky.FirstOrDefault(m => m.Id == id);
                        update.Phong = phong.ToString();
                        db.SaveChanges();
                        t = 0;
                    }
                }
                if (tam == 2)
                {
                    if (txtSo.Text != null)
                    {
                        var id = Convert.ToInt32(txtSo.Text);
                        if (gcDangky.DataSource == null)
                        {
                            var delid = db.Dangky.FirstOrDefault(m => m.Id == id);
                            db.Dangky.Remove(delid);
                            db.SaveChanges();
                            var deldk = db.DK_Customers.FirstOrDefault(m => m.IdDK == id);
                            db.DK_Customers.Remove(deldk);
                            var deldkp = db.DangKyPhong.Where(m => m.IDDK == id).ToList();
                            foreach (var item in deldkp)
                            {
                                db.DangKyPhong.Remove(item);
                            }
                            var listdkp = db.DangKyPhong.Where(m => m.IDDK == id).ToList();
                            foreach (var item in listdkp)
                            {
                                var room = db.Rooms.Where(m => m.Sophong == item.SoPhong).First();
                                room.Status = 1;
                            }
                            db.SaveChanges();
                        }
                        else
                        {
                            var dkp = db.DangKyPhong.Where(m => m.IDDK == id).OrderBy(m => m.SoPhong).ToList();
                            if (lstdkp.Count != 0)
                            {
                                foreach (var item in lstdkp)
                                {
                                    db.DangKyPhong.Remove(item);
                                    var deldkk = db.DK_Customers.Where(m => m.Sophong == item.SoPhong).First();
                                    db.DK_Customers.Remove(deldkk);
                                    var room = db.Rooms.Where(m => m.Sophong == item.SoPhong).First();
                                    room.Status = 1;
                                }
                                for (int i = 0; i < gvDangky.RowCount; i++)
                                {
                                    phong.Trim();
                                    phong += gvDangky.GetRowCellValue(i, gvDangky.Columns[0]).ToString();
                                    if (i < gvDangky.RowCount - 1)
                                    {
                                        phong += ",";
                                    }
                                }
                                var update = db.Dangky.FirstOrDefault(m => m.Id == id);
                                update.Phong = phong.ToString();
                                db.SaveChanges();
                            }
                            else
                            {
                                foreach (var item in lstdkk)
                                {
                                    db.DK_Customers.Remove(item);
                                }
                                db.SaveChanges();
                            }
                        }
                    }
                }
                MessageBox.Show("Lưu thành công!");
            }
        }