Exemplo n.º 1
0
 public bool Copy(List <int> Ids, int userId)
 {
     try
     {
         using (db = new QMSSystemEntities())
         {
             var src = db.Q_UserCmdRegister.Where(x => !x.IsDeleted && Ids.Contains(x.Id)).ToList();
             if (src.Count > 0)
             {
                 Q_UserCmdRegister obj;
                 for (int i = 0; i < src.Count; i++)
                 {
                     obj               = new Q_UserCmdRegister();
                     obj.UserId        = userId;
                     obj.CmdParamId    = src[i].CmdParamId;
                     obj.ActionParamId = src[i].ActionParamId;
                     obj.Param         = src[i].Param;
                     obj.Index         = src[i].Index;
                     obj.Note          = src[i].Note;
                     db.Q_UserCmdRegister.Add(obj);
                 }
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception)
     { }
     return(false);
 }
Exemplo n.º 2
0
        //public List<ModelSelectItem> GetLookUp()
        //{
        //      using (db = new QMSSystemEntities()){
        //    return db.Q_UserCmdRegister.Where(x => !x.IsDeleted).Select(x => new ModelSelectItem() { Id = x.Id, Name = x.Code }).ToList();
        //}

        public int Insert(Q_UserCmdRegister obj)
        {
            using (db = new QMSSystemEntities())
            {
                if (!CheckExists(obj))
                {
                    db.Q_UserCmdRegister.Add(obj);
                    db.SaveChanges();
                }
                return(obj.Id);
            }
        }
Exemplo n.º 3
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (userId == 0)
         {
             MessageBox.Show("Vui lòng chọn nhân viên.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else if (cmdParamId == 0)
         {
             MessageBox.Show("Vui lòng chọn tham số lệnh.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else if (acParamId == 0)
         {
             MessageBox.Show("Vui lòng chọn tham số hành động.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else if (txtStt.Value == null)
         {
             MessageBox.Show("Vui lòng nhập số thứ tự thực hiện.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             var obj = new Q_UserCmdRegister()
             {
                 Id = Id, CmdParamId = cmdParamId, ActionParamId = acParamId, Index = (int)txtStt.Value, Param = txtparam.Text, Note = "", UserId = userId
             };
             int kq = 0;
             if (obj.Id == 0)
             {
                 kq = BLLRegisterUserCmd.Instance.Insert(obj);
             }
             else
             {
                 kq = BLLRegisterUserCmd.Instance.Update(obj);
             }
             if (kq == 0)
             {
                 MessageBox.Show("Tham số hành động này đã tồn tại. Vui lòng chọn tham số hành động khác", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 GetGridView();
                 btnCancel_Click(sender, e);
                 frmMain.lib_RegisterUserCmds = BLLRegisterUserCmd.Instance.Gets();
             }
         }
     }
     catch (Exception)
     { }
 }
Exemplo n.º 4
0
 public int Update(Q_UserCmdRegister model)
 {
     using (db = new QMSSystemEntities())
     {
         var obj = db.Q_UserCmdRegister.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
         if (obj != null)
         {
             if (!CheckExists(model))
             {
                 obj.ActionParamId = model.ActionParamId;
                 obj.Index         = model.Index;
                 obj.Param         = model.Param;
                 obj.Note          = model.Note;
                 db.SaveChanges();
                 return(obj.Id);
             }
             else
             {
                 return(0);
             }
         }
         return(0);
     }
 }
Exemplo n.º 5
0
        private bool CheckExists(Q_UserCmdRegister model)
        {
            var obj = db.Q_UserCmdRegister.FirstOrDefault(x => !x.IsDeleted && !x.Q_User.IsDeleted && !x.Q_CommandParameter.Q_Command.IsDeleted && !x.Q_CommandParameter.IsDeleted && !x.Q_ActionParameter.Q_Action.IsDeleted && !x.Q_ActionParameter.IsDeleted && x.UserId == model.UserId && x.CmdParamId == model.CmdParamId && x.ActionParamId == model.ActionParamId && x.Id != model.Id);

            return(obj != null ? true : false);
        }