public static bool InsertHangBan(HangBan hb) { try { using (SieuThiDBDataContext db = new SieuThiDBDataContext()) { db.HangBans.InsertOnSubmit(hb); db.SubmitChanges(); return(true); } } catch { return(false); } }
private void btnTaoPhieuNhap_Click(object sender, EventArgs e) { int ktra = 0; if (listHHN.Count > 0) { DAO.HoaDon hd = new DAO.HoaDon { MaNV = int.Parse(txtMaNV.Text), NgayNhap = DateTime.Parse(txtNgayDat.Text) }; if (HoaDonBus.InsertHoaDon(hd)) { foreach (var item in listHHN) { HangBan hb = new HangBan { SoHD = hd.SoHoaDon, DonGia = item.DG, MaHang = item.MaHang, SoLuong = item.SL }; if (!HoaDonBus.InsertHangBan(hb)) { ktra++; } } } else { ktra++; } if (ktra == 0) { MessageBox.Show("Tạo đơn hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { MessageBox.Show("Hãy thêm hàng hóa muốn nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }