Exemplo n.º 1
0
 public bool Save(object dataBoundItem)
 {
     if (dataBoundItem is MuonTB ob)
     {
         var db = new dbQLTSEntities();
         if (ob.IDMuonTB <= 0)
         {
             ob.CreateBy   = COMMON.User.IDAccount;
             ob.CreateTime = DateTime.Now;
             ob.Status     = false;
             db.MuonTBs.Add(ob);
         }
         else
         {
             var obj = db.MuonTBs.ToList().FirstOrDefault(q => q.IDMuonTB == ob.IDMuonTB);
             if (obj is MuonTB)
             {
                 db.Entry(obj).CurrentValues.SetValues(ob);
             }
             else
             {
                 return(false);
             }
         }
         db.SaveChanges();
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
        public object Search(string sKey)
        {
            var acc = new dbQLTSEntities().Accounts.ToList().Where(q => q.FullName.Contains(sKey)).Select(q => q.IDAccount).ToList();

            return(new BindingList <MuonTB>(new dbQLTSEntities().MuonTBs.ToList()
                                            .Where(q => q.Account.FullName.Contains(sKey) ||
                                                   acc.Any(a => a == q.IDAccount || a == q.CreateBy) ||
                                                   q.Account.FullName.Contains(sKey) ||
                                                   q.Account.FullName.Contains(sKey) ||
                                                   q.CreateTime.ToString().Contains(sKey) ||
                                                   q.TimeEnd.ToString().Contains(sKey) ||
                                                   q.TimeStart.ToString().Contains(sKey) ||
                                                   q.IDMuonTB.ToString().Contains(sKey) ||
                                                   q.Note.Contains(sKey)
                                                   ).ToList()));
        }
Exemplo n.º 3
0
 public bool Delete(object dataBoundItem)
 {
     if (dataBoundItem is MuonTB muontb)
     {
         var db = new dbQLTSEntities();
         if (db.MuonTBs.ToList().FirstOrDefault(q => q.IDMuonTB == muontb.IDMuonTB) is MuonTB value)
         {
             var ct = value.CTMuonTBs.ToArray();
             foreach (var item in ct)
             {
                 db.CTMuonTBs.Remove(item);
             }
             db.MuonTBs.Remove(value);
             return(db.SaveChanges() > 0);
         }
         else
         {
             throw new Exception("Vui lòng reload");
         }
     }
     return(false);
 }