public ChiTietPhieuNhap(CHITIETPHIEUNHAP chitiet)
 {
     MaSoPhieuNhap = chitiet.masophieunhap;
     MaSoSach = chitiet.masosach;
     SoLuong = chitiet.soluong;
     DonGia = chitiet.dongia;
     TrangThai = chitiet.trangthai;
 }
		private void detach_CHITIETPHIEUNHAPs(CHITIETPHIEUNHAP entity)
		{
			this.SendPropertyChanging();
			entity.SACH = null;
		}
 partial void DeleteCHITIETPHIEUNHAP(CHITIETPHIEUNHAP instance);
 partial void UpdateCHITIETPHIEUNHAP(CHITIETPHIEUNHAP instance);
 partial void InsertCHITIETPHIEUNHAP(CHITIETPHIEUNHAP instance);
		private void attach_CHITIETPHIEUNHAPs(CHITIETPHIEUNHAP entity)
		{
			this.SendPropertyChanging();
			entity.PHIEUNHAP = this;
		}
 public ChiTietPhieuNhap(CHITIETPHIEUNHAP chitiet, SACH sach)
     : this(chitiet)
 {
     Sach = new Sach(sach);
 }
 public static bool add(List<ChiTietPhieuNhap> dmchitiet, int masophieunhap)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             foreach (ChiTietPhieuNhap chitiet in dmchitiet)
             {
                 CHITIETPHIEUNHAP ct = new CHITIETPHIEUNHAP()
                 {
                     masosach = chitiet.Sach.MaSoSach,
                     dongia = chitiet.DonGia,
                     soluong = chitiet.SoLuong,
                     masophieunhap = masophieunhap,
                     trangthai = 0
                 };
                 db.CHITIETPHIEUNHAPs.InsertOnSubmit(ct);
             }
             db.SubmitChanges();
             return true;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return false;
     }
 }
 public static bool add(ChiTietPhieuNhap chitiet,int masophieunhap)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CHITIETPHIEUNHAP ct;
             ct = (from c in db.CHITIETPHIEUNHAPs
                   where c.masophieunhap.Equals(masophieunhap)
                   && c.masosach.Equals(chitiet.MaSoSach)
                   select c).SingleOrDefault();
             if (ct != null) return false;
             ct = new CHITIETPHIEUNHAP()
                 {
                     masosach = chitiet.Sach.MaSoSach,
                     dongia = chitiet.DonGia,
                     soluong = chitiet.SoLuong,
                     masophieunhap = masophieunhap,
                     trangthai = chitiet.TrangThai == null ? 0 : 1
             };
             db.CHITIETPHIEUNHAPs.InsertOnSubmit(ct);
             db.SubmitChanges();
             return true;
         }
     }catch(Exception ex)
     {
         Console.WriteLine(ex.Message);
         return false;
     }
 }