Exemplo n.º 1
0
        public override ValueObject Execute(TransactionContext trxContext, ValueObject arg)
        {
            UserRoleVo inVo = (UserRoleVo)arg;

            StringBuilder sqlQuery = new StringBuilder();

            sqlQuery.Append("Delete from m_mes_user_role");
            sqlQuery.Append(" Where	");
            sqlQuery.Append(" user_cd = :usercd ");
            sqlQuery.Append(" and ");
            sqlQuery.Append(" role_cd = :rolecd ;");

            //create command
            DbCommandAdaptor sqlCommandAdapter = base.GetDbCommandAdaptor(trxContext, sqlQuery.ToString());

            //create parameter
            DbParameterList sqlParameter = sqlCommandAdapter.CreateParameterList();

            sqlParameter.AddParameterString("usercd", inVo.UserCode);
            sqlParameter.AddParameterString("rolecd", inVo.RoleCode);

            UserRoleVo outVo = new UserRoleVo {
                AffectedCount = sqlCommandAdapter.ExecuteNonQuery(sqlParameter)
            };

            return(outVo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks user is admin
        /// </summary>
        /// <returns></returns>
        private bool IsAdminUser()
        {
            bool isAdmin = false;

            UserRoleVo userRoleOutVo = new UserRoleVo();

            UserRoleVo userRoleInVo = new UserRoleVo
            {
                UserCode = UserData.GetUserData().UserCode
            };

            try
            {
                userRoleOutVo = (UserRoleVo)base.InvokeCbm(new GetUserRoleMasterMntCbm(), userRoleInVo, false);
            }
            catch (Framework.ApplicationException exception)
            {
                popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                logger.Error(exception.GetMessageData());
            }

            List <UserRoleVo> userRoleList = userRoleOutVo.UserRoleListVo.Where(t => t.RoleCode == ADMIN).ToList();

            if (userRoleList.Count > 0)
            {
                isAdmin = true;
            }

            return(isAdmin);
        }
Exemplo n.º 3
0
        public override ValueObject Execute(TransactionContext trxContext, ValueObject arg)
        {
            UserRoleVo inVo = (UserRoleVo)arg;

            StringBuilder sqlQuery = new StringBuilder();

            sqlQuery.Append("Select mur.user_cd,mur.role_cd from m_mes_user_role mur");
            sqlQuery.Append(" inner join m_mes_user mu ");
            sqlQuery.Append(" on mur.user_cd = mu.user_cd ");
            sqlQuery.Append(" inner join m_mes_role mr ");
            sqlQuery.Append(" on mur.role_cd = mr.role_cd ");
            sqlQuery.Append(" where 1 = 1 ");

            if (inVo.RoleCode != null)
            {
                sqlQuery.Append(" and mur.role_cd = :rolecd ");
            }

            if (inVo.UserCode != null)
            {
                sqlQuery.Append(" and mur.user_cd = :usercd ");
            }
            sqlQuery.Append(" order by mu.user_cd");
            //create command
            DbCommandAdaptor sqlCommandAdapter = base.GetDbCommandAdaptor(trxContext, sqlQuery.ToString());

            //create parameter
            DbParameterList sqlParameter = sqlCommandAdapter.CreateParameterList();

            if (inVo.RoleCode != null)
            {
                sqlParameter.AddParameterString("rolecd", inVo.RoleCode);
            }

            if (inVo.UserCode != null)
            {
                sqlParameter.AddParameterString("usercd", inVo.UserCode);
            }

            //execute SQL
            IDataReader dataReader = sqlCommandAdapter.ExecuteReader(trxContext, sqlParameter);

            UserRoleVo outVo = new UserRoleVo();

            while (dataReader.Read())
            {
                UserRoleVo currOutVo = new UserRoleVo
                {
                    RoleCode = dataReader["role_cd"].ToString(),
                    UserCode = dataReader["user_cd"].ToString()
                };

                outVo.UserRoleListVo.Add(currOutVo);
            }

            dataReader.Close();

            return(outVo);
        }
Exemplo n.º 4
0
        private void BtnDelUser_Click(object sender, EventArgs e)
        {
            UserRoleVo vo = (UserRoleVo)this.gridView2.GetRow(this.gridView2.FocusedRowHandle);

            if (vo == null)
            {
                return;
            }
            if (DeleteDao.DeleteByID(vo.Id, typeof(UserRoleVo)) > 0)
            {
                XtraMessageBox.Show("删除成功!");
                FillUser();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Updates user role
        /// </summary>
        private void UpdateUserRole()
        {
            string userCode;
            string roleCode;

            TreeNodeCollection nodes = UserRoleDetails_tv.Nodes;

            UserRoleVo userRoleCheckVo = new UserRoleVo();

            try
            {
                userRoleCheckVo = (UserRoleVo)base.InvokeCbm(new GetUserRoleMasterMntCbm(), new UserRoleVo(), false);
            }
            catch (Framework.ApplicationException exception)
            {
                popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                Logger.Error(exception.GetMessageData());
                return;
            }

            foreach (TreeNode tn in nodes)
            {
                foreach (TreeNode child in tn.Nodes)
                {
                    userCode = tn.Tag.ToString();
                    roleCode = child.Tag.ToString();

                    var userRoleCount = userRoleCheckVo.UserRoleListVo.Count(t => t.UserCode == userCode && t.RoleCode == roleCode);

                    if (child.Checked)
                    {
                        if (userRoleCount == 0)
                        {
                            AddUserRole(userCode, roleCode);
                        }
                    }
                    else
                    {
                        if (userRoleCount == 1)
                        {
                            DeleteUserRole(userCode, roleCode);
                        }
                    }
                }
            }

            messageData = new MessageData("mmci00002", Properties.Resources.mmci00002, null);
            Logger.Info(messageData);
            popUpMessage.Information(messageData, Text);
        }
Exemplo n.º 6
0
        private void BtnUpdateUser_Click(object sender, EventArgs e)
        {
            UserRoleVo vo = (UserRoleVo)this.gridView2.GetRow(this.gridView2.FocusedRowHandle);

            if (vo == null)
            {
                return;
            }
            UserForm form = new UserForm(vo);

            if (form.ShowDialog() == DialogResult.OK)
            {
                FillUser();
            }
        }
        public override ValueObject Execute(TransactionContext trxContext, ValueObject arg)
        {
            UserRoleVo inVo = (UserRoleVo)arg;

            StringBuilder sqlQuery = new StringBuilder();

            sqlQuery.Append("Insert into m_mes_user_role");
            sqlQuery.Append(" ( ");
            sqlQuery.Append(" user_cd, ");
            sqlQuery.Append(" role_cd, ");
            sqlQuery.Append(" registration_user_cd, ");
            sqlQuery.Append(" registration_date_time, ");
            sqlQuery.Append(" factory_cd ");
            sqlQuery.Append(" ) ");
            sqlQuery.Append("VALUES	");
            sqlQuery.Append(" ( ");
            sqlQuery.Append(" :usercd ,");
            sqlQuery.Append(" :rolecd ,");
            sqlQuery.Append(" :registrationusercode ,");
            sqlQuery.Append(" now() ,");
            sqlQuery.Append(" :factorycode ");
            sqlQuery.Append(" ); ");

            //create command
            DbCommandAdaptor sqlCommandAdapter = base.GetDbCommandAdaptor(trxContext, sqlQuery.ToString());

            //create parameter
            DbParameterList sqlParameter = sqlCommandAdapter.CreateParameterList();

            sqlParameter.AddParameterString("rolecd", inVo.RoleCode);
            sqlParameter.AddParameterString("usercd", inVo.UserCode);
            sqlParameter.AddParameterString("registrationusercode", inVo.RegistrationUserCode);
            //sqlParameter.AddParameterDateTime("registrationdatetime", inVo.RegistrationDateTime);
            sqlParameter.AddParameterString("factorycode", inVo.FactoryCode);

            UserRoleVo outVo = new UserRoleVo {
                AffectedCount = sqlCommandAdapter.ExecuteNonQuery(sqlParameter)
            };

            return(outVo);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Deletes user role
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="roleCode"></param>
        private void DeleteUserRole(string userCode, string roleCode)
        {
            UserRoleVo userRoleInVo = new UserRoleVo
            {
                UserCode = userCode,
                RoleCode = roleCode
            };

            UserRoleVo userRoleOutVo = new UserRoleVo();

            try
            {
                userRoleOutVo = (UserRoleVo)base.InvokeCbm(new DeleteUserRoleMasterMntCbm(), userRoleInVo, false);
            }
            catch (Framework.ApplicationException exception)
            {
                popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                Logger.Error(exception.GetMessageData());
                return;
            }
        }
Exemplo n.º 9
0
 private void BtnAdd_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(this.textUserName.Text) || string.IsNullOrWhiteSpace(this.comMode.Text) || string.IsNullOrWhiteSpace(this.textPassword.Text))
     {
         XtraMessageBox.Show("请填写完整信息!");
     }
     else
     {
         //更新
         if (userVo != null)
         {
             userVo.Name   = this.textUserName.Text;
             userVo.Role   = this.comMode.Text;
             userVo.Psword = this.textPassword.Text;
             UpdateDao.UpdateByID(userVo);
             XtraMessageBox.Show("保存成功!");
             this.DialogResult = DialogResult.OK;
             return;
         }
         //新增
         UserRoleVo vo = new UserRoleVo()
         {
             Name      = this.textUserName.Text,
             Role      = this.comMode.Text,
             Psword    = this.textPassword.Text,
             CompanyId = SystemConst.companyId
         };
         if (SelectDao.IsUserExist(vo.Name))
         {
             XtraMessageBox.Show("该用户已经存在!");
             return;
         }
         if (InsertDao.InsertData(vo, typeof(UserRoleVo)) > 0)
         {
             XtraMessageBox.Show("保存成功!");
             this.DialogResult = DialogResult.OK;
             return;
         }
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Adds new user role
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="roleCode"></param>
        private void AddUserRole(string userCode, string roleCode)
        {
            UserRoleVo userRoleInVo = new UserRoleVo
            {
                UserCode = userCode,
                RoleCode = roleCode,
                //RegistrationDateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                RegistrationUserCode = UserData.GetUserData().UserCode,
                FactoryCode          = UserData.GetUserData().FactoryCode
            };

            UserRoleVo userRoleOutVo = new UserRoleVo();

            try
            {
                userRoleOutVo = (UserRoleVo)base.InvokeCbm(new AddUserRoleMasterMntCbm(), userRoleInVo, false);
            }
            catch (Framework.ApplicationException exception)
            {
                popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                Logger.Error(exception.GetMessageData());
                return;
            }
        }
Exemplo n.º 11
0
 public UserForm(UserRoleVo userVo = null)
 {
     InitializeComponent();
     InitEvents();
     this.userVo = userVo;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Binds tree view with role
        /// </summary>
        /// <param name="userList"></param>
        private void PopulateTreeView(List <UserVo> userList)
        {
            RoleVo roleOutVo = new RoleVo();

            AuthorityControlVo authorityOutVo = new AuthorityControlVo();

            try
            {
                roleOutVo = (RoleVo)base.InvokeCbm(new GetRoleMasterMntCbm(), roleInVo, false);

                AuthorityControlVo authorityInVo = new AuthorityControlVo();

                authorityOutVo = (AuthorityControlVo)base.InvokeCbm(new GetAuthorityControlMasterMntCbm(), authorityInVo, false);
            }
            catch (Framework.ApplicationException exception)
            {
                popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                Logger.Error(exception.GetMessageData());
                return;
            }

            UserRoleDetails_tv.Nodes.Clear();

            TreeNode[] headerNode = new TreeNode[userList.Count];

            int i = 0;

            foreach (UserVo user in userList)
            {
                TreeNode child = new TreeNode
                {
                    Text = user.UserCode + ": " + user.UserName,
                    Tag  = user.UserCode
                };

                headerNode[i] = child;

                int childNodes = roleOutVo.RoleListVo.Count;

                TreeNode[] rootNodes = new TreeNode[childNodes];

                int node = 0;

                //UserRoleVo userRoleInVo = new UserRoleVo();

                UserRoleVo userRoleOutVo = new UserRoleVo();

                try
                {
                    userRoleOutVo = (UserRoleVo)base.InvokeCbm(new GetUserRoleMasterMntCbm(), new UserRoleVo(), false);
                }
                catch (Framework.ApplicationException exception)
                {
                    popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                    Logger.Error(exception.GetMessageData());
                    return;
                }

                foreach (RoleVo role in roleOutVo.RoleListVo)
                {
                    TreeNode rootChild = new TreeNode
                    {
                        Text = role.RoleCode + ": " + role.RoleName,
                        Tag  = role.RoleCode
                    };

                    List <UserRoleVo> userRoleList = userRoleOutVo.UserRoleListVo.Where(t => t.UserCode == child.Tag.ToString()).ToList();

                    foreach (UserRoleVo userRole in userRoleList)
                    {
                        if (userRole.RoleCode == rootChild.Tag.ToString())
                        {
                            rootChild.Checked = true;
                        }
                    }

                    rootNodes[node] = rootChild;

                    headerNode[i].Nodes.Add(rootNodes[node]);

                    RoleAuthorityControlVo roleAuthorityOutVo = new RoleAuthorityControlVo();

                    try
                    {
                        roleAuthorityOutVo = (RoleAuthorityControlVo)base.InvokeCbm(new GetRoleAuthorityControlMasterMntCbm(), new RoleAuthorityControlVo(), false);
                    }
                    catch (Framework.ApplicationException exception)
                    {
                        popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                        Logger.Error(exception.GetMessageData());
                        return;
                    }

                    List <RoleAuthorityControlVo> roleAuthorityList = roleAuthorityOutVo.RoleAuthorityControlListVo.Where(t => t.RoleCode == rootChild.Tag.ToString()).ToList();

                    int authorityNodes = roleAuthorityList.Count;

                    TreeNode[] authorityRootNodes = new TreeNode[authorityNodes];

                    int subnode = 0;

                    foreach (RoleAuthorityControlVo roleAuth in roleAuthorityList)
                    {
                        AuthorityControlVo authVo = authorityOutVo.AuthorityControlListVo.Where(t => t.AuthorityControlCode == roleAuth.AuthorityControlCode).ToList().First();

                        TreeNode authorityChild = new TreeNode
                        {
                            Text = authVo.AuthorityControlCode + ": " + authVo.AuthorityControlName,
                            Tag  = authVo.AuthorityControlCode
                        };

                        authorityRootNodes[subnode] = authorityChild;

                        rootNodes[node].Nodes.Add(authorityRootNodes[subnode]);

                        subnode += 1;
                    }

                    node += 1;
                }

                UserRoleDetails_tv.Nodes.Add(headerNode[i]);

                i += 1;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Binds data for excel export
        /// </summary>
        /// <returns></returns>
        private DataTable BindDataForExcel()
        {
            AuthorityControlVo authorityOutVo = null;
            UserVo             userOutVo      = null;
            UserRoleVo         userRoleOutVo  = null;

            try
            {
                authorityOutVo = (AuthorityControlVo)DefaultCbmInvoker.Invoke(new GetAuthorityControlMasterMntCbm(), new AuthorityControlVo());
            }
            catch (Framework.ApplicationException exception)
            {
                popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                logger.Error(exception.GetMessageData());
            }

            try
            {
                userOutVo = (UserVo)DefaultCbmInvoker.Invoke(new GetUserMasterMntCbm(), new UserVo());
            }
            catch (Framework.ApplicationException exception)
            {
                popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                logger.Error(exception.GetMessageData());
            }

            try
            {
                userRoleOutVo = (UserRoleVo)DefaultCbmInvoker.Invoke(new GetUserAuthorityCbm(), new UserRoleVo());
            }
            catch (Framework.ApplicationException exception)
            {
                popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                logger.Error(exception.GetMessageData());
            }

            DataTable dt = new DataTable();
            DataRow   dr;

            dt.Columns.Add("AuthorityName");
            dt.Columns.Add("SubAuthorityName");
            dt.Columns.Add("FormName");

            if (userOutVo != null && userOutVo.UserListVo.Count > 0)
            {
                foreach (UserVo user in userOutVo.UserListVo)
                {
                    dt.Columns.Add(user.UserCode);
                }

                //dr = dt.NewRow();
                //dr["AuthorityName"] = "Authority Name";
                //dr["SubAuthorityName"] = "SubAuthority Name";
                //dr["FormName"] = "Form Name";

                //foreach (UserVo user in userOutVo.UserListVo)
                //{
                //    dr[user.UserCode] = user.UserName;
                //}

                //dt.Rows.Add(dr);
            }


            if (authorityOutVo != null && authorityOutVo.AuthorityControlListVo.Count > 0)
            {
                foreach (AuthorityControlVo authorityVo in authorityOutVo.AuthorityControlListVo)
                {
                    if (string.IsNullOrWhiteSpace(authorityVo.ParentControlCode))
                    {
                        dr = dt.NewRow();

                        dr["AuthorityName"] = authorityVo.AuthorityControlName;
                        dt.Rows.Add(dr);

                        List <AuthorityControlVo> controlList = authorityOutVo.AuthorityControlListVo.
                                                                Where(t => t.ParentControlCode == authorityVo.AuthorityControlCode).ToList();

                        if (controlList != null && controlList.Count > 0)
                        {
                            foreach (AuthorityControlVo controlVo in controlList)
                            {
                                dr = dt.NewRow();
                                dr["SubAuthorityName"] = controlVo.AuthorityControlName;
                                dt.Rows.Add(dr);

                                List <AuthorityControlVo> childControlList = authorityOutVo.AuthorityControlListVo.
                                                                             Where(t => t.ParentControlCode == controlVo.AuthorityControlCode).ToList();

                                if (childControlList != null && childControlList.Count > 0)
                                {
                                    foreach (AuthorityControlVo childControlVo in childControlList)
                                    {
                                        dr             = dt.NewRow();
                                        dr["FormName"] = childControlVo.AuthorityControlName;

                                        List <UserRoleVo> userRoleList = userRoleOutVo.UserRoleListVo.
                                                                         Where(t => t.AuthorityControlCode == childControlVo.AuthorityControlCode).ToList();

                                        foreach (UserRoleVo userRole in userRoleList)
                                        {
                                            dr[userRole.UserCode] = ((char)0x221A).ToString();
                                        }
                                        dt.Rows.Add(dr);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(dt);
        }