Esempio n. 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static USER_SHARE_ROLESMODEL GetRoleModel(int ROLEID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select ROLEID,ROLENAME,ROLEDESC,PROJECTID,COMPANYID,STATUS from USER_SHARE_ROLES ");
            strSql.Append(" where ROLEID=:ROLEID AND STATUS=:STATUS ");
            ParamList param = new ParamList();

            param["ROLEID"] = ROLEID;
            param["STATUS"] = ShareEnum.RoleStatus.Normal.ToString("d");
            USER_SHARE_ROLESMODEL model = null;
            DataTable             dt    = StaticConnectionProvider.ExecuteDataTable(strSql.ToString(), param);

            if (dt != null && dt.Rows.Count > 0)
            {
                model = ReaderBind(dt.Rows[0]);
            }

            return(model);
        }
Esempio n. 2
0
        /// <summary>
        /// 新增角色信息
        /// </summary>
        /// <param name="roleModel"></param>
        /// <returns></returns>
        public static bool AddARole(USER_SHARE_ROLESMODEL roleModel, string strFunIds, string strGroupIds, List <RoleAccountModel> lstRaModel, USER_SHARE_LOGMODEL log)
        {
            bool          blSuccess = false;
            StringBuilder strSql    = new StringBuilder();

            strSql.Append("insert into USER_SHARE_ROLES(");
            strSql.Append("ROLEID,ROLENAME,ROLEDESC,PROJECTID,COMPANYID,STATUS,CREATORID,CREATEDATE)");
            strSql.Append(" values (");
            strSql.Append(":ROLEID,:ROLENAME,:ROLEDESC,:PROJECTID,:COMPANYID,:STATUS,:CREATORID,:CREATEDATE)");
            ParamList param = new ParamList();

            param["ROLEID"]     = roleModel.ROLEID;
            param["ROLENAME"]   = roleModel.ROLENAME;
            param["ROLEDESC"]   = roleModel.ROLEDESC;
            param["PROJECTID"]  = roleModel.PROJECTID;
            param["COMPANYID"]  = roleModel.COMPANYID;
            param["STATUS"]     = roleModel.STATUS;
            param["CREATORID"]  = roleModel.CreatorId;
            param["CREATEDATE"] = roleModel.CreateDate;

            IConnectionProvider connection = ConnectionProviderBuilder.CreateConnectionProvider();

            try
            {
                using (connection)
                {
                    connection.BeginTranscation();
                    //增加角色信息
                    connection.ExecuteNonQuery(strSql.ToString(), param);
                    param.Clear();

                    string strSqlFun = string.Empty;

                    //角色功能
                    if (strFunIds.Trim().Length > 0)
                    {
                        string[] funId = strFunIds.Split(',');

                        foreach (string str in funId)
                        {
                            if (str.Trim().Length > 0)
                            {
                                strSqlFun = string.Format("INSERT INTO USER_SHARE_ROLEFUN(ROLEID,FUNID) VALUES({0},{1}) ", roleModel.ROLEID, str);
                                connection.ExecuteNonQuery(strSqlFun);
                            }
                        }
                    }

                    //角色下的账号更新
                    foreach (RoleAccountModel raModel in lstRaModel)
                    {
                        //新增时选中的账号,角色更新,未选中的不用做处理
                        if (raModel.IsChecked)
                        {
                            strSqlFun = string.Format("UPDATE USER_SHARE_ACCOUNT SET ROLEIDS=(ROLEIDS||(CASE WHEN ROLEIDS IS NULL THEN ',{0},' ELSE '{0},' END )) WHERE ACCOUNTID={1} ", roleModel.ROLEID, raModel.AccountId);
                            connection.ExecuteNonQuery(strSqlFun);
                        }
                    }

                    //拥有权限的车辆分组
                    if (strGroupIds.Trim().Length > 0)
                    {
                        string[] funId = strGroupIds.Split(',');

                        foreach (string str in funId)
                        {
                            if (str.Trim().Length > 0)
                            {
                                strSqlFun = string.Format("INSERT INTO USER_SHARE_ROLE_GROUP(ROLEID,SHAREGROUPID) VALUES({0},{1}) ", roleModel.ROLEID, str);
                                connection.ExecuteNonQuery(strSqlFun);
                            }
                        }
                    }

                    //操作日志
                    strSql = new StringBuilder();
                    strSql.Append("insert into USER_SHARE_LOG(");
                    strSql.Append("LOGID,OPERATETYPE,OPERATORID,PROJECTID,COMPANYID,OPERATECONTENT,OPERATEDATE)");
                    strSql.Append(" values (");
                    strSql.Append(":LOGID,:OPERATETYPE,:OPERATORID,:PROJECTID,:COMPANYID,:OPERATECONTENT,:OPERATEDATE)");

                    param["LOGID"]          = log.LOGID;
                    param["OPERATETYPE"]    = log.OPERATETYPE;
                    param["OPERATORID"]     = log.OPERATORID;
                    param["PROJECTID"]      = log.PROJECTID;
                    param["COMPANYID"]      = log.COMPANYID;
                    param["OPERATECONTENT"] = log.OPERATECONTENT;
                    param["OPERATEDATE"]    = log.OPERATEDATE;
                    connection.ExecuteNonQuery(strSql.ToString(), param);

                    connection.CommitTranscation();
                    blSuccess = true;
                }
            }
            catch (Exception ex)
            {
                connection.RollbackTranscation();
                LogHelper.WriteErr("新增角色信息时发生错误,角色名称:" + roleModel.ROLENAME, ex);
            }

            return(blSuccess);
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //项目下拉框
                DataTable dt = CompanyBusiness.GetCompanyProjects(CompanyCode.ToString());
                ControlHelper.BindListControl(ddlProject, dt, "PROJECTNAME", "PROJECTID");
                if (dt != null && dt.Rows.Count > 0 && ProjectId == 0)
                {
                    ExecStartScript("$('#trProject').show();");
                }
                else
                {
                    ControlHelper.SelectFlg(ddlProject, ProjectId.ToString());
                    ExecStartScript("$('#trProject').hide();");
                }

                //车辆分组
                if (GroupId.Length > 0)
                {
                    LoadCompanyGroup();
                    ExecStartScript("$('#trGroups').show();");
                }

                #region 账号绑定

                string strWhere = string.Format(" AND ISADMIN=0 AND COMPANYID={0} ", CompanyCode);

                DataTable dtAccounts = AccountBusiness.GetAccountList(strWhere);
                ControlHelper.BindListControl(cblAccounts, dtAccounts, "ARNAME", "ROLEACCOUNTS");

                #endregion

                hidRoleId.Value = RoleId.ToString();
                if (RoleId > 0)
                {
                    USER_SHARE_ROLESMODEL roleModel = RoleBusiness.GetRoleModel(RoleId);
                    if (roleModel != null)
                    {
                        txtRoleName.Text = roleModel.ROLENAME;
                        txtRoleDesc.Text = CommonMethod.FinalString(roleModel.ROLEDESC);
                        ControlHelper.SelectFlg(ddlProject, roleModel.PROJECTID.ToString());

                        #region 判断账号的选中

                        foreach (ListItem accountitem in cblAccounts.Items)
                        {
                            if (accountitem.Value.IndexOf("," + roleModel.ROLEID + ",") >= 0)
                            {
                                accountitem.Selected = true;
                            }
                        }

                        #endregion

                        #region 判断分组的选中

                        foreach (TreeNode tn in tvGroups.Nodes)
                        {
                            tn.Checked = CompanyGroupBusiness.IsRoleContainGroup(RoleId, tn.Value);
                        }

                        #endregion
                    }
                    else
                    {
                        Response.Write("不存在的角色信息!");
                        Response.End();
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <param name="roleModel"></param>
        /// <returns></returns>
        public static bool EditRole(USER_SHARE_ROLESMODEL roleModel, string strFunIds, string strGroupIds, List <RoleAccountModel> lstRaModel, USER_SHARE_LOGMODEL log)
        {
            bool blSuccess = false;

            StringBuilder strSql = new StringBuilder();

            strSql.Append("update USER_SHARE_ROLES set ");
            strSql.Append("ROLENAME=:ROLENAME,");
            strSql.Append("ROLEDESC=:ROLEDESC,");
            strSql.Append("PROJECTID=:PROJECTID,");
            strSql.Append("COMPANYID=:COMPANYID,");
            strSql.Append("STATUS=:STATUS");
            strSql.Append(" where ROLEID=:ROLEID ");

            ParamList param = new ParamList();

            param["ROLEID"]    = roleModel.ROLEID;
            param["ROLENAME"]  = roleModel.ROLENAME;
            param["ROLEDESC"]  = roleModel.ROLEDESC;
            param["PROJECTID"] = roleModel.PROJECTID;
            param["COMPANYID"] = roleModel.COMPANYID;
            param["STATUS"]    = roleModel.STATUS;

            IConnectionProvider connection = ConnectionProviderBuilder.CreateConnectionProvider();

            try
            {
                using (connection)
                {
                    connection.BeginTranscation();
                    //修改账号信息
                    connection.ExecuteNonQuery(strSql.ToString(), param);
                    param.Clear();

                    //角色功能

                    //删除旧的信息
                    string strSqlFun = "DELETE FROM USER_SHARE_ROLEFUN WHERE ROLEID=" + roleModel.ROLEID;
                    connection.ExecuteNonQuery(strSqlFun);

                    //新的信息插入
                    if (strFunIds.Trim().Length > 0)
                    {
                        string[] funId = strFunIds.Split(',');

                        foreach (string str in funId)
                        {
                            if (str.Trim().Length > 0)
                            {
                                strSqlFun = string.Format("INSERT INTO USER_SHARE_ROLEFUN(ROLEID,FUNID) VALUES({0},{1}) ", roleModel.ROLEID, str);
                                connection.ExecuteNonQuery(strSqlFun);
                            }
                        }
                    }

                    //角色下的账号更新
                    foreach (RoleAccountModel raModel in lstRaModel)
                    {
                        //修改时账号角色更新
                        if (raModel.IsChecked)
                        {
                            strSqlFun = string.Format(@"UPDATE USER_SHARE_ACCOUNT SET ROLEIDS=(CASE WHEN REPLACE(ROLEIDS,',{0},',',')=',' OR ROLEIDS  IS NULL 
                                                        THEN ',{0},' ELSE REPLACE(ROLEIDS,',{0},',',')||'{0},'  end) WHERE ACCOUNTID={1} ", roleModel.ROLEID, raModel.AccountId);
                        }
                        else
                        {
                            strSqlFun = string.Format(@"UPDATE USER_SHARE_ACCOUNT SET ROLEIDS=(CASE WHEN REPLACE(ROLEIDS,',{0},',',')=',' OR ROLEIDS  IS NULL 
                                                        THEN '' ELSE REPLACE(ROLEIDS,',{0},',',')  end) WHERE ACCOUNTID={1} ", roleModel.ROLEID, raModel.AccountId);
                        }

                        connection.ExecuteNonQuery(strSqlFun);
                    }


                    //车辆分组

                    //删除旧的信息
                    strSqlFun = "DELETE FROM USER_SHARE_ROLE_GROUP WHERE ROLEID=" + roleModel.ROLEID;
                    connection.ExecuteNonQuery(strSqlFun);

                    //新的信息插入
                    if (strGroupIds.Trim().Length > 0)
                    {
                        string[] funId = strGroupIds.Split(',');

                        foreach (string str in funId)
                        {
                            if (str.Trim().Length > 0)
                            {
                                strSqlFun = string.Format("INSERT INTO USER_SHARE_ROLE_GROUP(ROLEID,SHAREGROUPID) VALUES({0},{1}) ", roleModel.ROLEID, str);
                                connection.ExecuteNonQuery(strSqlFun);
                            }
                        }
                    }

                    //操作日志
                    strSql = new StringBuilder();
                    strSql.Append("insert into USER_SHARE_LOG(");
                    strSql.Append("LOGID,OPERATETYPE,OPERATORID,PROJECTID,COMPANYID,OPERATECONTENT,OPERATEDATE)");
                    strSql.Append(" values (");
                    strSql.Append(":LOGID,:OPERATETYPE,:OPERATORID,:PROJECTID,:COMPANYID,:OPERATECONTENT,:OPERATEDATE)");

                    param["LOGID"]          = log.LOGID;
                    param["OPERATETYPE"]    = log.OPERATETYPE;
                    param["OPERATORID"]     = log.OPERATORID;
                    param["PROJECTID"]      = log.PROJECTID;
                    param["COMPANYID"]      = log.COMPANYID;
                    param["OPERATECONTENT"] = log.OPERATECONTENT;
                    param["OPERATEDATE"]    = log.OPERATEDATE;
                    connection.ExecuteNonQuery(strSql.ToString(), param);

                    connection.CommitTranscation();
                    blSuccess = true;
                }
            }
            catch (Exception ex)
            {
                connection.RollbackTranscation();
                LogHelper.WriteErr("修改角色信息时发生错误,角色Id:" + roleModel.ROLEID, ex);
            }

            return(blSuccess);
        }
Esempio n. 5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            #region  务端验证

            if (txtRoleName.Text.Trim().Length == 0)
            {
                Alert("请输入角色名称!");
                Select(txtRoleName);
                return;
            }

            if (CommonMethod.FinalString(Request.Form["fun"]).Length == 0)
            {
                Alert("请选择角色拥有的权限!");
                return;
            }

            #endregion

            #region 角色信息保存

            USER_SHARE_ROLESMODEL roleModel = null;

            //日志信息
            USER_SHARE_LOGMODEL logModel = new USER_SHARE_LOGMODEL();
            logModel.LOGID       = CommonBusiness.GetSeqID("S_USER_SHARE_LOG");
            logModel.OPERATEDATE = DateTime.Now;
            logModel.OPERATORID  = AccountId;
            logModel.PROJECTID   = ProjectId;
            logModel.COMPANYID   = CompanyId;

            if (RoleId > 0)
            {
                roleModel               = RoleBusiness.GetRoleModel(RoleId);
                logModel.OPERATETYPE    = int.Parse(ShareEnum.LogType.EditRole.ToString("d"));
                logModel.OPERATECONTENT = string.Format("修改角色信息,修改后角色名称:{0}, 角色Id:{1} ", txtRoleName.Text.Trim(), RoleId);
            }
            else
            {
                roleModel               = new USER_SHARE_ROLESMODEL();
                roleModel.ROLEID        = CommonBusiness.GetSeqID("S_USER_SHARE_ROLES");
                roleModel.CreatorId     = AccountId;
                roleModel.CreateDate    = DateTime.Now;
                roleModel.COMPANYID     = CompanyId;
                roleModel.STATUS        = int.Parse(ShareEnum.RoleStatus.Normal.ToString("d"));
                logModel.OPERATETYPE    = int.Parse(ShareEnum.LogType.AddRole.ToString("d"));
                logModel.OPERATECONTENT = string.Format("新增角色信息,角色名称:{0},公司编码:{1} ", txtRoleName.Text.Trim(), CompanyCode);
            }

            roleModel.PROJECTID = ValidatorHelper.ToInt(ddlProject.SelectedValue, 0);
            roleModel.ROLENAME  = txtRoleName.Text.Trim();
            roleModel.ROLEDESC  = txtRoleDesc.Text.Trim();

            bool   blSuccess   = false;
            string strRoleFuns = Request.Form["fun"];

            #region  账号信息

            List <RoleAccountModel> raModel = new List <RoleAccountModel>();
            RoleAccountModel        model   = null;
            foreach (ListItem item in cblAccounts.Items)
            {
                model           = new RoleAccountModel();
                model.AccountId = ValidatorHelper.ToInt(item.Value.Split('$')[0], 0);
                model.IsChecked = item.Selected;
                raModel.Add(model);
            }

            #endregion

            #region 角色拥有车辆分组

            string strGroup = string.Empty;
            foreach (TreeNode tn in tvGroups.Nodes)
            {
                if (tn.Checked)
                {
                    strGroup += tn.Value + ",";
                }
            }

            strGroup = strGroup.TrimEnd(',');

            #endregion

            if (RoleId == 0)
            {
                blSuccess = RoleBusiness.AddARole(roleModel, strRoleFuns, strGroup, raModel, logModel);
            }
            else
            {
                blSuccess = RoleBusiness.EditRole(roleModel, strRoleFuns, strGroup, raModel, logModel);
            }

            Alert((RoleId > 0 ? "修改" : "新增") + "角色" + (blSuccess ? "成功" : "失败,请重试!"));

            ExecScript("parent.__doPostBack('ctl00$MainContent$btnSearch','');");


            #endregion
        }