Esempio n. 1
0
 public bool UpdateRelation(string empCode, OPERATETYPE type)
 {
     try
     {
         List <deviceemployeerelation> devEmps = db.deviceemployeerelation.Where(m => m.EmpCode == empCode).ToList();
         foreach (var item in devEmps)
         {
             item.Operate = (sbyte)type;
             db.deviceemployeerelation.Attach(item);
             db.Entry(item).State = System.Data.Entity.EntityState.Modified;
         }
         int result = db.SaveChanges();
         return(result > 0);
     }
     catch (Exception ex)
     {
         LogHelper.Error("更新关系表失败", ex);
         return(false);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 从设备上移除对应员工
 /// </summary>
 /// <param name="empCode"></param>
 /// <returns></returns>
 public bool DeleteRelation(string empCode, OPERATETYPE type)
 {
     try
     {
         using (BemEntities db = new BemEntities())
         {
             var devList = db.deviceemployeerelation.Where(m => m.EmpCode == empCode);
             if (devList.Count() == 0)
             {
                 return(false);
             }
             var           groups   = devList.GroupBy(m => m.DevCode);
             List <string> devCodes = new List <string>();
             foreach (var dev in devList)
             {
                 devCodes.Add(dev.DevCode);
             }
             int count = 0;
             count = db.Database.ExecuteSqlCommand(string.Format("update DeviceEmployeeRelation set operate={0} where EmpCode='{1}';", (int)type, empCode));
             if (count > 0)
             {
                 foreach (string devCode in devCodes)
                 {
                     ClientTask task = new ClientTask();
                     task.ClientID = devCode;
                     task.TaskID   = Guid.NewGuid().ToString();
                     TaskManager.TaskEnqueue(task);
                 }
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         LogHelper.Error("删除绑定关系失败", ex);
         return(false);
     }
 }