public static int add(HoaDonNXB hoadon)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             var hd = new HOADONNXB
             {
                 masonxb = hoadon.MaSoNXB,
                 ngaylap = hoadon.NgayLap,
                 tongtien = hoadon.ChiTiet.Sum(ct => ct.SoLuong * ct.DonGia),
                 trangthai = 0
             };
             db.HOADONNXBs.InsertOnSubmit(hd);
             db.SubmitChanges();
             foreach (ChiTietHoaDonNXB ct in hoadon.ChiTiet)
             {
                 ChiTiet.add(ct, hd.masohoadon);
             }
             return hd.masohoadon;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return 0;
     }
 }
 public HoaDonNXB(HOADONNXB hoadon)
 {
     MaSoHoaDon = hoadon.masohoadon;
     MaSoNXB = hoadon.masonxb;
     NgayLap = hoadon.ngaylap;
     TongTien = hoadon.tongtien;
     TrangThai = hoadon.trangthai;
 }
 partial void DeleteHOADONNXB(HOADONNXB instance);
 partial void UpdateHOADONNXB(HOADONNXB instance);
 partial void InsertHOADONNXB(HOADONNXB instance);
		private void detach_HOADONNXBs(HOADONNXB entity)
		{
			this.SendPropertyChanging();
			entity.NXB = null;
		}
		private void attach_HOADONNXBs(HOADONNXB entity)
		{
			this.SendPropertyChanging();
			entity.NXB = this;
		}
 public HoaDonNXB(HOADONNXB hoadon, NXB nxb)
     : this(hoadon)
 {
     NXB = new NhaXuatBan(nxb);
 }