Ejemplo n.º 1
0
        private void Thongtin_FormClosing(object sender, FormClosingEventArgs e)
        {
            sodophong = new Sodophong();
            Thongtin_Load(sender, e);
            var     list = db.DK_Customers.ToList();
            GetData data = new GetData(sodophong.PostData);

            data(list);
        }
Ejemplo n.º 2
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();
                 }
             }
         }
     }
 }