コード例 #1
0
 public static bool edit(Sach sach)
 {
     using (EntitiesDataContext db = new EntitiesDataContext())
     {
         var s = (from b in db.SACHes
                  where b.masosach == sach.MaSoSach
                  select b).SingleOrDefault();
         if (s == null)
         {
             return(false);
         }
         s.tensach     = sach.TenSach;
         s.masolinhvuc = sach.LinhVucSach.MaSoLinhVuc;
         s.masonxb     = sach.NXB.MaSoNXB;
         s.tacgia      = sach.TenTacGia;
         s.soluong     = sach.Soluong;
         s.giaban      = sach.GiaBan;
         s.gianhap     = sach.GiaNhap;
         s.hinhanh     = sach.HinhAnh;
         s.mota        = sach.MoTa;
         s.trangthai   = sach.TrangThai;
         db.SubmitChanges();
         return(true);
     }
 }
コード例 #2
0
 public static bool delete(int masonxb)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             NXB nxb;
             nxb = (from n in db.NXBs
                    where n.masonxb.Equals(masonxb)
                    select n).SingleOrDefault();
             if (nxb == null)
             {
                 return(false);
             }
             db.NXBs.DeleteOnSubmit(nxb);
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #3
0
 public static int add(Sach sach)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             var s = new SACH();
             s.tensach     = sach.TenSach;
             s.masolinhvuc = sach.LinhVucSach.MaSoLinhVuc;
             s.masonxb     = sach.NXB.MaSoNXB;
             s.tacgia      = sach.TenTacGia;
             s.soluong     = sach.Soluong;
             s.giaban      = sach.GiaBan;
             s.gianhap     = sach.GiaNhap;
             s.hinhanh     = sach.HinhAnh;
             s.mota        = sach.MoTa;
             db.SACHes.InsertOnSubmit(s);
             db.SubmitChanges();
             return(s.masosach);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(0);
     }
 }
コード例 #4
0
 public static bool edit(NhaXuatBan nhaxuatban)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             NXB nxb;
             nxb = (from n in db.NXBs
                    where n.masonxb.Equals(nhaxuatban.MaSoNXB)
                    select n).SingleOrDefault();
             if (nxb == null)
             {
                 return(false);
             }
             nxb.ten         = nhaxuatban.TenNXB;
             nxb.diachi      = nhaxuatban.DiaChi;
             nxb.sodienthoai = nhaxuatban.SoDienThoai;
             nxb.sotaikhoan  = nhaxuatban.SoTaiKhoan;
             nxb.trangthai   = nhaxuatban.TrangThai;
             nxb.nganhang    = nhaxuatban.NganHang;
             db.SubmitChanges();
             return(true);
         }
     }catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #5
0
 public static bool delete(ChiTietHoaDonNXB chitiet)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CHITIETHOADONNXB ct;
             ct = (from c in db.CHITIETHOADONNXBs
                   where c.masohoadon.Equals(chitiet.MaSoHoaDon) &&
                   c.masosach.Equals(chitiet.MaSoSach)
                   select c).SingleOrDefault();
             if (ct == null)
             {
                 return(false);
             }
             db.CHITIETHOADONNXBs.DeleteOnSubmit(ct);
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #6
0
 public static bool delete(int masodaily)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             DAILY dl;
             dl = (from d in db.DAILies
                   where d.masodaily.Equals(masodaily)
                   select d).SingleOrDefault();
             if (dl == null)
             {
                 return(false);            //Nếu đại lý không tồn tại
             }
             db.DAILies.DeleteOnSubmit(dl);
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
 public static bool edit(PhieuNhap phieu)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             PHIEUNHAP px;
             px = (from p in db.PHIEUNHAPs
                   where p.masophieunhap.Equals(phieu.MaSoPhieuNhap)
                   select p).SingleOrDefault();
             if (px == null)
             {
                 return(false);
             }
             px.masonxb       = phieu.MaSoNXB;
             px.ngaylap       = phieu.NgayLap;
             px.nguoigiaosach = phieu.NguoiGiao;
             px.trangthai     = phieu.TrangThai;
             px.tongtien      = phieu.ChiTiet.Sum(ct => ct.SoLuong * ct.DonGia); // tính tổng tiền các chi tiết
             db.CHITIETPHIEUNHAPs.DeleteAllOnSubmit(px.CHITIETPHIEUNHAPs);
             db.SubmitChanges();
             foreach (ChiTietPhieuNhap ct in phieu.ChiTiet)
             {
                 ct.MaSoPhieuNhap = phieu.MaSoPhieuNhap;
                 ChiTiet.add(ct);
             }
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #9
0
 public static bool delete(int masophieunhap)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             PHIEUNHAP phieu;
             phieu = (from p in db.PHIEUNHAPs
                      where p.masophieunhap.Equals(masophieunhap)
                      select p).SingleOrDefault();
             if (phieu == null)
             {
                 return(false);
             }
             db.CHITIETPHIEUNHAPs.DeleteAllOnSubmit(phieu.CHITIETPHIEUNHAPs);
             db.PHIEUNHAPs.DeleteOnSubmit(phieu);
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #10
0
 public static bool delete(int masonguoidung)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             NGUOIDUNG nguoidung;
             nguoidung = (from s in db.NGUOIDUNGs
                          where s.masonguoidung.Equals(masonguoidung)
                          select s).SingleOrDefault();
             if (nguoidung == null)
             {
                 return(false);
             }
             db.NGUOIDUNGs.DeleteOnSubmit(nguoidung);
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #11
0
 public static bool delete(int masolinhvuc)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             //Kiểm tra lĩnh vực có tồn tại không
             LINHVUC lv;
             lv = (from b in db.LINHVUCs
                   where b.masolinhvuc.Equals(masolinhvuc)
                   select b).SingleOrDefault();
             if (lv == null)
             {
                 return(false);
             }
             db.LINHVUCs.DeleteOnSubmit(lv);
             db.SubmitChanges();
             return(true);
         }
     }catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #12
0
 private void CreateTimeSlots(EntitiesDataContext _EDC, ShippingPoint _sp, UpdateToolStripEvent _update)
 {
     _update(this, new ProgressChangedEventArgs(1, "CreateTimeSlots starting"));
     for (int _i = 0; _i < Properties.Settings.Default.NumberOfDays; _i++)
     {
         DateTime _dy = DateTime.Now.Date + TimeSpan.FromDays(_i);
         _update(this, new ProgressChangedEventArgs(1, _dy.ToShortDateString()));
         if (_dy.DayOfWeek == DayOfWeek.Sunday || _dy.DayOfWeek == DayOfWeek.Saturday)
         {
             continue;
         }
         List <TimeSlotTimeSlot> _ts = new List <TimeSlotTimeSlot>();
         short _strtTm = 8;
         for (int _indx = _strtTm; _indx <= _strtTm + Properties.Settings.Default.TimeSlotsPerDay; _indx++)
         {
             DateTime _bgn = _dy + TimeSpan.FromHours(_indx);
             DateTime _end = _bgn + TimeSpan.FromHours(1);
             _ts.Add(new TimeSlotTimeSlot()
             {
                 EntryTime = _bgn, EndTime = _end, ExitTime = _end, Occupied = Occupied.Free, TimeSlot2ShippingPointLookup = _sp, StartTime = _bgn
             });
             _update(this, new ProgressChangedEventArgs(1, _bgn.ToShortDateString()));
         }
         _EDC.TimeSlot.InsertAllOnSubmit(_ts);
         _EDC.SubmitChanges();
     }
 }
コード例 #13
0
 public static bool edit(CongNoDaiLy congno)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CONGNODAILY cn;
             cn = (from d in db.CONGNODAILies
                   where d.masodaily.Equals(congno.MaSoDaiLy) &&
                   d.masosach.Equals(congno.MaSoSach) &&
                   d.thang.Month.Equals(congno.Thang.Month) &&
                   d.thang.Year.Equals(congno.Thang.Year)
                   select d).SingleOrDefault();
             if (cn == null)
             {
                 return(false);            //Nếu đại lý không tồn tại
             }
             cn.soluong = congno.SoLuong;
             cn.dongia  = congno.DonGia;
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #14
0
 public static bool delete(int masohoadon)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             HOADONNXB hd;
             hd = (from p in db.HOADONNXBs
                   where p.masohoadon.Equals(masohoadon)
                   select p).SingleOrDefault();
             if (hd == null)
             {
                 return(false);
             }
             db.CHITIETHOADONNXBs.DeleteAllOnSubmit(hd.CHITIETHOADONNXBs);
             db.HOADONNXBs.DeleteOnSubmit(hd);
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #15
0
 public static bool add(ChiTietHoaDonNXB chitiet, int masohoadon)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CHITIETHOADONNXB ct;
             ct = (from c in db.CHITIETHOADONNXBs
                   where c.masohoadon.Equals(masohoadon) &&
                   c.masosach.Equals(chitiet.MaSoSach)
                   select c).SingleOrDefault();
             if (ct != null)
             {
                 return(false);
             }
             ct = new CHITIETHOADONNXB
             {
                 masohoadon = masohoadon,
                 masosach   = chitiet.MaSoSach,
                 soluong    = chitiet.SoLuong,
                 dongia     = chitiet.DonGia,
                 trangthai  = chitiet.TrangThai == null ? 0 : 1
             };
             db.CHITIETHOADONNXBs.InsertOnSubmit(ct);
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #16
0
        public static bool edit(HoaDonNXB hoadon)
        {
            try
            {
                using (EntitiesDataContext db = new EntitiesDataContext())
                {
                    HOADONNXB hd;
                    hd = (from p in db.HOADONNXBs
                          where p.masohoadon.Equals(hoadon.MaSoHoaDon)
                          select p).SingleOrDefault();
                    if (hd == null)
                    {
                        return(false);
                    }
                    hd.masonxb   = hoadon.MaSoNXB;
                    hd.ngaylap   = hoadon.NgayLap;
                    hd.trangthai = hoadon.TrangThai;
                    hd.tongtien  = hoadon.ChiTiet.Sum(ct => ct.SoLuong * ct.DonGia); // tính tổng tiền các chi tiết
                    db.CHITIETHOADONNXBs.DeleteAllOnSubmit(hd.CHITIETHOADONNXBs);
                    db.SubmitChanges();
                    foreach (ChiTietHoaDonNXB ct in hoadon.ChiTiet)
                    {
                        ChiTiet.add(ct, hoadon.MaSoHoaDon);
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
コード例 #17
0
 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);
     }
 }
コード例 #18
0
 public static bool edit(ChiTietHoaDonDaiLy chitiet)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CHITIETHOADONDAILY ct;
             ct = (from c in db.CHITIETHOADONDAILies
                   where c.masohoadon.Equals(chitiet.MaSoHoaDon) &&
                   c.masosach.Equals(chitiet.MaSoSach)
                   select c).SingleOrDefault();
             if (ct == null)
             {
                 return(false);
             }
             ct.soluong   = chitiet.SoLuong;
             ct.trangthai = chitiet.TrangThai;
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #19
0
 public static bool delete(TheKho thekho)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             THEKHO tk;
             tk = (from t in db.THEKHOs
                   where t.masosach.Equals(thekho.MaSoSach) &&
                   t.ngayghi.Equals(thekho.NgayGhi)
                   select t).SingleOrDefault();
             if (tk == null)
             {
                 return(false);
             }
             db.THEKHOs.DeleteOnSubmit(tk);
             db.SubmitChanges();
             return(true);
         }
     }catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #20
0
 public static bool edit(TheKho thekho)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             THEKHO tk;
             tk = (from s in db.THEKHOs
                   where s.masosach.Equals(thekho.MaSoSach) &&
                   s.ngayghi.Equals(thekho.NgayGhi)
                   select s).SingleOrDefault();
             if (tk == null)
             {
                 return(false);            //Nếu không tồn tại thẻ kho
             }
             tk.soluong = thekho.SoLuong;
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #21
0
 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);
     }
 }
コード例 #22
0
 public static bool edit(ChiTietPhieuXuat chitiet)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CHITIETPHIEUXUAT ct;
             ct = (from c in db.CHITIETPHIEUXUATs
                   where c.masophieuxuat.Equals(chitiet.MaSoPhieuXuat) &&
                   c.masosach.Equals(chitiet.MaSoSach)
                   select c).SingleOrDefault();
             if (ct == null)
             {
                 return(false);
             }
             ct.soluong   = chitiet.SoLuong;
             ct.trangthai = chitiet.TrangThai;
             db.SubmitChanges();
             return(true);
         }
     }catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #23
0
 public static bool delete(ChiTietPhieuNhap chitiet)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CHITIETPHIEUNHAP ct;
             ct = (from c in db.CHITIETPHIEUNHAPs
                   where c.masophieunhap.Equals(chitiet.MaSoPhieuNhap) &&
                   c.masosach.Equals(chitiet.MaSoSach)
                   select c).SingleOrDefault();
             if (ct == null)
             {
                 return(false);
             }
             db.CHITIETPHIEUNHAPs.DeleteOnSubmit(ct);
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #24
0
 public static int add(PhieuNhap phieunhap)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             var phieu = new PHIEUNHAP()
             {
                 masonxb       = phieunhap.NXB.MaSoNXB,
                 ngaylap       = phieunhap.NgayLap,
                 nguoigiaosach = phieunhap.NguoiGiao,
                 tongtien      = phieunhap.ChiTiet.Sum(ct => ct.SoLuong * ct.DonGia),
                 trangthai     = 0
             };
             db.PHIEUNHAPs.InsertOnSubmit(phieu);
             db.SubmitChanges();
             ChiTiet.add(phieunhap.ChiTiet, phieu.masophieunhap);
             return(phieu.masophieunhap);
         }
     }catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(0);
     }
 }
コード例 #25
0
 public static int add(PhieuXuat phieuxuat)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             var phieu = new PHIEUXUAT
             {
                 masodaily    = phieuxuat.MaSoDaiLy,
                 ngaylap      = phieuxuat.NgayLap,
                 nguoinhasach = phieuxuat.NguoiNhan,
                 tongtien     = phieuxuat.ChiTiet.Sum(ct => ct.SoLuong * ct.DonGia),
                 trangthai    = 0
             };
             db.PHIEUXUATs.InsertOnSubmit(phieu);
             db.SubmitChanges();
             foreach (ChiTietPhieuXuat ct in phieuxuat.ChiTiet)
             {
                 Chitiet.add(ct, phieu.masophieuxuat);
             }
             return(phieu.masophieuxuat);
         }
     }catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(0);
     }
 }
コード例 #26
0
 public static bool edit(DaiLy daily)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             DAILY dl;
             dl = (from d in db.DAILies
                   where d.masodaily.Equals(daily.MaSoDaiLy)
                   select d).SingleOrDefault();
             if (dl == null)
             {
                 return(false);            //Nếu đại lý không tồn tại
             }
             dl.ten         = daily.TenDaiLy;
             dl.diachi      = daily.DiaChi;
             dl.sodienthoai = daily.SoDienThoai;
             dl.sotaikhoan  = daily.SoTaiKhoan;
             dl.trangthai   = daily.TrangThai;
             dl.nganhang    = daily.NganHang;
             db.SubmitChanges();
             return(true);
         }
     }catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #27
0
 public static bool delete(CongNoNXB congno)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CONGNONXB cn;
             cn = (from d in db.CONGNONXBs
                   where d.masonxb.Equals(congno.MaSoNXB) &&
                   d.masosach.Equals(congno.MaSoSach) &&
                   d.thang.Month.Equals(congno.Thang.Month) &&
                   d.thang.Year.Equals(congno.Thang.Year)
                   select d).SingleOrDefault();
             if (cn == null)
             {
                 return(false);            //Nếu đại lý không tồn tại
             }
             db.CONGNONXBs.DeleteOnSubmit(cn);
             db.SubmitChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(false);
     }
 }
コード例 #28
0
 public static int add(DaiLy daily)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             DAILY dl;
             dl = (from d in db.DAILies
                   where d.masodaily.Equals(daily.MaSoDaiLy)
                   select d).SingleOrDefault();
             if (dl != null)
             {
                 return(0);            //Nếu đại lý đã tồn tại
             }
             dl = new DAILY()
             {
                 ten           = daily.TenDaiLy,
                 diachi        = daily.DiaChi,
                 sodienthoai   = daily.SoDienThoai,
                 sotaikhoan    = daily.SoTaiKhoan,
                 nganhang      = daily.NganHang,
                 masonguoidung = daily.MaSoNguoiDung
             };
             db.DAILies.InsertOnSubmit(dl);
             db.SubmitChanges();
             return(dl.masodaily);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(0);
     }
 }
コード例 #29
0
 public static int add(LinhVuc linhvuc)
 {
     using (EntitiesDataContext db = new EntitiesDataContext())
     {
         var lv = new LINHVUC();
         lv.ten = linhvuc.TenLinhVuc;
         db.LINHVUCs.InsertOnSubmit(lv);
         db.SubmitChanges();
         return(lv.masolinhvuc);
     }
 }
コード例 #30
0
 public static int add(CongNoNXB congno)
 {
     try
     {
         using (EntitiesDataContext db = new EntitiesDataContext())
         {
             CONGNONXB cn;
             cn = (from c in db.CONGNONXBs
                   where c.masonxb.Equals(congno.MaSoNXB) &&
                   c.masosach.Equals(congno.MaSoSach) &&
                   c.thang.Month.Equals(congno.Thang.Month) &&
                   c.thang.Year.Equals(congno.Thang.Year)
                   select c).SingleOrDefault();
             if (cn != null)
             {
                 cn.soluong += congno.SoLuong;
                 db.SubmitChanges();
                 return(1);
             }
             else
             {
                 cn          = new CONGNONXB();
                 cn.masonxb  = congno.MaSoNXB;
                 cn.masosach = congno.MaSoSach;
                 cn.soluong  = congno.SoLuong;
                 cn.dongia   = congno.DonGia;
                 cn.thang    = congno.Thang;
                 db.CONGNONXBs.InsertOnSubmit(cn);
                 db.SubmitChanges();
                 return(1);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(0);
     }
 }