internal static void save(HoaDon hoaDon, NhanVien nhanVien = null) { using (var db = DBContext.GetContext ()) { var old = db.HoaDon.FirstOrDefault(b => b.MaHoaDon == hoaDon.MaHoaDon); if (old == null) { //hoaDon.ThoiGianTao = DateTime.Now; hoaDon.NhanVien = nhanVien; var nhanVienLap = db.NhanVien.Find(hoaDon.NhanVien.MaNhanVien); hoaDon.NhanVien = nhanVienLap; foreach (var c in hoaDon.ChiTietHoaDon) { c.SanPham = db.SanPham.Find(c.MaSanPham); c.HoaDon = hoaDon; } db.HoaDon.Add(hoaDon); } else { old.ChiTietHoaDon.Clear(); foreach (var c in hoaDon.ChiTietHoaDon) { old.ChiTietHoaDon.Add(new ChiTietHoaDon() { MaSanPham = c.SanPham.MaSanPham, SoLuong= c.SoLuong, Gia= c.Gia }); } } db.SaveChanges(); } }
public FrmBanHang(bool isNhap = false) { InitializeComponent(); lblTongTien.Visible = !isNhap; int phongID = Login1.GetPhongHienTai().MaPhongTap; allSanPham = SanPhamController.GetList(phongID); lbSanPham.DataSource = allSanPham; lbSanPham.DisplayMember = "ListBoxString"; hoaDon = new HoaDon(); this.isNhap = isNhap; lblTitle.Text = isNhap ? "Nhập hàng" : "Bán hàng"; if (isNhap) { btnReset.Text = "Hủy phiếu nhập hiện tại"; btnSave.Text = "Nhập hàng"; } txtMaVach.Focus(); }
internal static CODE_RESULT_RETURN Add(HoaDon hv) { using (var context = DBContext.GetContext()) { var ds = (from e in context.HoaDon where e.MaHoaDon == hv.MaHoaDon select e).SingleOrDefault(); if (ds != null) return CODE_RESULT_RETURN.MaTrung; else { context.HoaDon.Add(hv); context.SaveChanges(); return CODE_RESULT_RETURN.ThanhCong; } } }
internal static CODE_RESULT_RETURN Update(HoaDon hv) { using (var db = DBContext.GetContext()) { var hvc = db.HoaDon.FirstOrDefault(h => h.MaHoaDon == hv.MaHoaDon); if (hvc != null) { hvc.NgayLap = hv.NgayLap; hvc.DanhSachChiTiet.Clear(); foreach(ChiTietHoaDon c in hv.DanhSachChiTiet){ db.ChiTietHoaDon.Add(c); } db.SaveChanges(); return CODE_RESULT_RETURN.ThanhCong; } return CODE_RESULT_RETURN.ThatBai; } }
private void FrmBanHang_Load(object sender, EventArgs e) { hoaDon = new HoaDon(); // loadListSanPham(allSanPham); }
private void btnReset_Click(object sender, EventArgs e) { hoaDon = new HoaDon(); lvHangNhap.Items.Clear(); capNhatLabelTien(); }
internal static void taoHoaDon(HoaDon hoaDon, NhanVien banHienTai, string message) { save(hoaDon, banHienTai); MessageBox.Show(message); }
internal static void tangSoLuong(HoaDon hoaDon, SanPham h, int p) { var c = hoaDon.ChiTietHoaDon.FirstOrDefault(c1 => c1.MaSanPham == h.MaSanPham); c.SoLuong += p; }