コード例 #1
0
 void luuHoaDon()
 {
     if (lblTenKH.Text == "Khách lẻ" && Convert.ToInt32(txtNolai.Text) > 0)
     {
         MessageBox.Show("Khách lẻ không cho nợ !");
     }
     else
     {
         using (DataBanHang data = new DataBanHang())
         {
             HoaDonBanHang hdbh = new HoaDonBanHang();
             var           a    = data.HoaDonBanHangs.Max(d => d.MaHDB);
             hdbh.MaHDB       = a + 1;
             hdbh.KhachHang   = Convert.ToInt32(lblMakh.Text);
             hdbh.NhanVienLap = 9;
             hdbh.NgayLap     = Convert.ToDateTime(DateTime.Now.ToString("dd/MM/yyyy"));
             hdbh.CK          = Convert.ToInt32(txtCk.Text);
             hdbh.NoCu        = Convert.ToInt32(txtNocu.Text);
             hdbh.TienTra     = Convert.ToInt32(txtKhachtra.Text);
             hdbh.GhiChu      = txtGhichu.Text;
             hdbh.TinhTrang   = true;
             data.HoaDonBanHangs.InsertOnSubmit(hdbh);
             foreach (CTHDBanHangDTO item in mangCTHD)
             {
                 CTHDBanHang cthdbh = new CTHDBanHang();
                 cthdbh.MaHDB     = hdbh.MaHDB;
                 cthdbh.SanPham   = item.SanPham;
                 cthdbh.SL        = item.Sl;
                 cthdbh.TinhTrang = true;
                 cthdbh.DonGia    = Convert.ToDouble(item.DonGia);
                 data.CTHDBanHangs.InsertOnSubmit(cthdbh);
                 data.SubmitChanges();
             }
             foreach (CTHDBanHangDTO item in mangCTHD)
             {
                 CTHDBanHang cthdbh = new CTHDBanHang();
                 HangHoa     hh     = data.HangHoas.Where(d => d.MaHH.Equals(item.SanPham)).FirstOrDefault();
                 hh.SoLuong = hh.SoLuong - item.Sl;
                 //sau khi thanh toán thành công thì phải xét lại sl trong bảng hóa đơn hoặc reset bảng hóa đơn
                 data.SubmitChanges();
             }
             KhachHang kh = data.KhachHangs.Where(d => d.MaKH.Equals(lblMakh.Text)).SingleOrDefault();
             kh.SoNo = Convert.ToInt32(txtNolai.Text);
             data.SubmitChanges();
             MessageBox.Show("Lưu Thành Công !");
             this.Close();
             resetHoaDon();
         }
     }
 }
コード例 #2
0
 partial void DeleteCTHDBanHang(CTHDBanHang instance);
コード例 #3
0
 partial void UpdateCTHDBanHang(CTHDBanHang instance);
コード例 #4
0
 partial void InsertCTHDBanHang(CTHDBanHang instance);