コード例 #1
0
        public static bool Deleteitem(item iTem)
        {
            using (var _context = new DBQuanLyBangBarcodeEntities())
            {
                //xoa item
                var dbiTem = (from u in _context.items
                              where u.itemcode == iTem.itemcode
                              select u).SingleOrDefault();

/*
 *              foreach (var x in dbiTem.listNCC)
 *              {
 *                  foreach (var u in x.listitem)
 *                  {
 *                      if (u.itemcode == iTem.itemcode)
 *                      {
 *                          x.listitem.Remove(u);
 *                          break;
 *                      }
 *                  }
 *              }
 */
                //delete
                _context.items.Remove(dbiTem);
                _context.SaveChanges();
                return(true);
            }
        }
コード例 #2
0
 //truy xuat list item khong co ncc
 public static List <item> getListitem()
 {
     using (var _context = new DBQuanLyBangBarcodeEntities())
     {
         var iTem = (from u in _context.items.AsEnumerable()
                     select new
         {
             itemcode = u.itemcode,
             itemname = u.itemname,
             form = u.form,
             NSX = u.NSX,
             HSD = u.HSD,
             price = u.price,
             NCC = u.NCC,
             NNK = u.NNK,
         }).Select(x => new item
         {
             itemcode = x.itemcode,
             itemname = x.itemname,
             form     = x.form,
             NSX      = x.NSX,
             HSD      = x.HSD,
             price    = x.price,
             NCC      = x.NCC,
             NNK      = x.NNK,
         }).ToList();
         return(iTem);
     }
 }
コード例 #3
0
 public static bool UpdateNCC(NCC nCC)
 {
     try
     {
         using (var _context = new DBQuanLyBangBarcodeEntities())
         {
             /*
              *                  foreach (var iTem in nCC.listitem)
              *                  {
              *                      var iTemdb = (from u in _context.items
              *                                    where u.itemcode == iTem.itemcode
              *                                    select u).Single();
              *                      iTemdb.listNCC.Add(nCC);
              *                  }
              *                  nCC.listitem.Clear();
              */
             _context.NCCs.AddOrUpdate(nCC);
             _context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
コード例 #4
0
 public static List <NCC> getListNCCs()
 {
     using (var _context = new DBQuanLyBangBarcodeEntities())
     {
         var nCC = (from u in _context.NCCs.AsEnumerable()
                    select new
         {
             NCCcode = u.NCCcode,
             NCCname = u.NCCname,
             address = u.address,
             NLDCC = u.NLDCC,
             SDT = u.SDT,
             email = u.email,
             DangCungCap = u.DangCungCap,
             DaCungCap = u.DaCungCap
         })
                   .Select(x => new NCC
         {
             NCCcode     = x.NCCcode,
             NCCname     = x.NCCname,
             address     = x.address,
             NLDCC       = x.NLDCC,
             SDT         = x.SDT,
             email       = x.email,
             DangCungCap = x.DangCungCap,
             DaCungCap   = x.DaCungCap
         });
         return(nCC.ToList());
     }
 }
コード例 #5
0
        public static bool DeleteNCC(NCC nCC)
        {
            using (var _context = new DBQuanLyBangBarcodeEntities())
            {
                var dbnCC = (from u in _context.NCCs
                             where u.NCCcode == nCC.NCCcode
                             select u).SingleOrDefault();

                _context.NCCs.Remove(dbnCC);
                _context.SaveChanges();
                return(true);
            }
        }
コード例 #6
0
 public static bool Updateitem(item iTem)
 {
     try
     {
         using (var _context = new DBQuanLyBangBarcodeEntities())
         {
             _context.items.AddOrUpdate(iTem);
             _context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
コード例 #7
0
 public static item getitem(string itemcode)
 {
     using (var _context = new DBQuanLyBangBarcodeEntities())
     {
         var iTem = (from u in _context.items
                     where u.itemcode == itemcode
                     select u).ToList();
         if (iTem.Count == 1)
         {
             return(iTem[0]);
         }
         else
         {
             return(null);
         }
     }
 }
コード例 #8
0
 public static NCC getNCC(string nCCcode)
 {
     using (var _context = new DBQuanLyBangBarcodeEntities())
     {
         var nCC = (from u in _context.NCCs.Include("listitem")
                    where u.NCCcode == nCCcode
                    select u).ToList();
         if (nCC.Count == 1)
         {
             return(nCC[0]);
         }
         else
         {
             return(null);
         }
     }
 }
コード例 #9
0
        public static void initializeDB()
        {
            using (var _context = new DBQuanLyBangBarcodeEntities())
            {
                var iTem = new item {
                    itemcode = "ABC0123", itemname = "Mi tom", NSX = DateTime.Now, HSD = DateTime.Now, NNK = DateTime.Now
                };
                _context.items.Add(iTem);
                var nCC = new NCC {
                    NCCcode = "123", NCCname = "Mien trung", NLDCC = DateTime.Now
                };
                _context.NCCs.Add(nCC);

                _context.SaveChanges();
            }
            MessageBox.Show("finish");
        }
コード例 #10
0
 public static List <NCC> getListNCCs(string NCCnamesearch)
 {
     using (var _context = new DBQuanLyBangBarcodeEntities())
     {
         var nCC = (from u in _context.NCCs.AsEnumerable()
                    where u.NCCcode.Contains(NCCnamesearch)
                    select u)
                   .Select(x => new NCC
         {
             NCCcode     = x.NCCcode,
             NCCname     = x.NCCname,
             address     = x.address,
             NLDCC       = x.NLDCC,
             SDT         = x.SDT,
             email       = x.email,
             DangCungCap = x.DangCungCap,
             DaCungCap   = x.DaCungCap,
         }).ToList();
         return(nCC);
     }
 }
コード例 #11
0
 public static int getIDfromDB()
 {
     using (var _context = new DBQuanLyBangBarcodeEntities())
     {
         var id = (from t in _context.items
                   select t.ID).ToArray();
         //return id.Max() + 1;
         if (id.Length <= 0)
         {
             return(1);
         }
         int i;
         for (i = 0; i < id.Length - 1; i++)
         {
             if (id[i + 1] != id[i] + 1)
             {
                 return(i + 1);
             }
         }
         return(i + 1);
     }
 }
コード例 #12
0
        public static bool AddNCC(NCC nCC)
        {
/*
 *          using (var _context = new DBQuanLyBangBarcodeEntities())
 *          {
 *              if (nCC.listitem != null)
 *              {
 *                  foreach (var iTem in nCC.listitem)
 *                  {
 *                      var itemdb = (from i in _context.items
 *                                    where i.itemcode == iTem.itemcode
 *                                    select i).Single();
 *                      //                      itemdb.NCCs.Add(nCC);
 *                  }
 *              }
 *              if (nCC.listitem != null)
 *              {
 *                  nCC.listitem.Clear();
 *              }
 *              _context.NCCs.AddOrUpdate(nCC);
 *              _context.SaveChanges();
 *              return true;
 *          }
 */
            try
            {
                using (var _context = new DBQuanLyBangBarcodeEntities())
                {
                    _context.NCCs.Add(nCC);
                    _context.SaveChanges();
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
コード例 #13
0
 public static bool Additem(item iTem)
 {
     try
     {
         using (var _context = new DBQuanLyBangBarcodeEntities())
         {
             foreach (var nCC in iTem.listNCC)
             {
                 var nCCbd = (from u in _context.NCCs
                              where u.NCCcode == nCC.NCCcode
                              select u).Single();
                 nCCbd.listitem.Add(iTem);
             }
             iTem.listNCC.Clear();
             _context.items.AddOrUpdate(iTem);
             _context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }