角色
Inheritance: Model.BaseModel
Esempio n. 1
0
 /// <summary>
 /// 检查是否重复
 /// </summary>
 /// <param name="Model.Role"></param>
 /// <returns></returns>
 public static bool CheckRepeat(Model.Role model)
 {
     try
     {
         string         sql  = "select * from Role where Name = @Name and Id <> @Id";
         SqlParameter[] para = new SqlParameter[]
         {
             new SqlParameter("@Name", model.Name.Trim()),
             new SqlParameter("@Id", model.Id)
         };
         DataTable temp = DBHelper.ExecuteGetDataTable(CommandType.Text, sql, para);
         if (temp.Rows.Count > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         ErrorLog e = new ErrorLog();
         e.TargetIds = model.Id.ToString();
         e.CodeTag   = "CheckRepeat";
         e.LogName   = "检查是否重复-ForRole";
         e.ErrorMsg  = ex.Message.ToString();
         ErrorLogService.AddErrorLog <Model.Role>(e, model);
         return(true);
     }
 }
Esempio n. 2
0
 public Role GetOneRole_Name_Role1()
 {
     Role r = new Role();
     r.Name = "role1";
     r.Id = new Guid("AD43BF4C-BF09-4203-BC09-3BDB7B8A7AC7");
     return r;
 }
Esempio n. 3
0
        public int AddRole(Model.Role role)
        {
            int id = -1;

            if (DalBase.Insert(role) > 0)
            {
                id = Convert.ToInt32(DalBase.GetMax <Model.Role>());
            }
            return(id);
        }
Esempio n. 4
0
        public ActionResult AddRole(int? id)
        {
            ViewData["All"] = powerSv.GetAllControList().ToList();
            ViewData["ParentContro"] = powerSv.GetParentContro();
            Role role = new Role();
            if (id != null)
            {
                role = powerSv.GetRole(id.Value);
            }

            return PartialView(role);
        }
        public bool ChangeStatus(string status, int Id)
        {
            if (Session[Util.ProjectConfig.ADMINUSER] == null)
            {
                return(false);
            }

            Model.Role role = RoleManager.GetRoleByPK(Id);
            role.Status = role.Status == "1" ? "0" : "1";

            return(RoleManager.UpdateRole(role));
        }
Esempio n. 6
0
        private bool tryPut(ref Model.Role model, out string errMsg)
        {
            errMsg = "";
            bool re = false;

            model.Modifier     = this.auth.UserId;
            model.ModifiedDate = DateTime.Now;
            if (RoleManager.ModifyRoleById(ref model, out errMsg))
            {
                re = true;
            }
            return(re);
        }
Esempio n. 7
0
 /// <summary>
 /// 添加角色
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool AddRole(ref Model.Role model, out string errMsg)
 {
     errMsg = "";
     try
     {
         model.Name        = model.Name.Trim();
         model.Description = model.Description.Trim();
         int[]          powers      = model.Powers.ToArray();
         string[]       arrayPowers = Array.ConvertAll(powers, delegate(int s) { return(s.ToString()); });
         SqlParameter[] para        = new SqlParameter[]
         {
             new SqlParameter("@Name", model.Name),
             new SqlParameter("@Powers", string.Join(",", arrayPowers)),
             new SqlParameter("@Description", model.Description),
             new SqlParameter("@Creater", model.Creater),
             new SqlParameter("@CreatedDate", model.CreatedDate),
             new SqlParameter("@Modifier", model.Modifier),
             new SqlParameter("@ModifiedDate", model.ModifiedDate),
             new SqlParameter("@return", SqlDbType.Int)
         };
         para[7].Direction = ParameterDirection.ReturnValue;
         int i = DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, "proc_RoleInsert", para);
         if (i > 0)
         {
             model.Id = int.Parse(para[7].Value.ToString());
             EventLog e = new EventLog();
             e.TargetIds = para[7].Value.ToString();
             e.CodeTag   = "AddRole";
             e.LogName   = "添加角色";
             EventLogService.AddEventLog <Model.Role>(e, model);
             return(true);
         }
         else
         {
             errMsg = "添加记录失败,受影响行数为0";
             return(false);
         }
     }
     catch (Exception ex)
     {
         errMsg = ex.Message;
         ErrorLog e = new ErrorLog();
         e.TargetIds = "0";
         e.CodeTag   = "AddRole";
         e.LogName   = "添加角色";
         e.ErrorMsg  = ex.Message.ToString();
         ErrorLogService.AddErrorLog <Model.Role>(e, model);
         return(false);
     }
 }
Esempio n. 8
0
 /// <summary>
 /// 根据id修改角色
 /// </summary>
 /// <param name="Model.Role"></param>
 /// <returns></returns>
 public static bool ModifyRoleById(ref Model.Role model, out string errMsg)
 {
     errMsg = "";
     try
     {
         model.Name        = model.Name.Trim();
         model.Description = model.Description.Trim();
         int[]          powers      = model.Powers.ToArray();
         string[]       powersArray = Array.ConvertAll(powers, delegate(int s) { return(s.ToString()); });
         SqlParameter[] para        = new SqlParameter[]
         {
             new SqlParameter("@Id", model.Id),
             new SqlParameter("@Name", model.Name),
             new SqlParameter("@Powers", string.Join(",", powersArray)),
             new SqlParameter("@Description", model.Description),
             new SqlParameter("@Modifier", model.Modifier),
             new SqlParameter("@ModifiedDate", model.ModifiedDate)
         };
         int i = DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, "proc_RoleByIdUpdate", para);
         if (i > 0)
         {
             EventLog e = new EventLog();
             e.TargetIds = model.Id.ToString();
             e.CodeTag   = "ModifyRoleById";
             e.LogName   = "修改角色";
             EventLogService.AddEventLog <Model.Role>(e, model);
             return(true);
         }
         else
         {
             errMsg = "该记录已被删除,不能修改!";
             return(false);
         }
     }
     catch (Exception ex)
     {
         errMsg = ex.Message;
         ErrorLog e = new ErrorLog();
         e.TargetIds = model.Id.ToString();
         e.CodeTag   = "ModifyRoleById";
         e.LogName   = "修改角色";
         e.ErrorMsg  = ex.Message.ToString();
         ErrorLogService.AddErrorLog <Model.Role>(e, model);
         return(false);
     }
 }
Esempio n. 9
0
        protected void BtnOk_Click(object sender, EventArgs e)
        {
            if (action!="modify")
            {
                role = new Role();
            }

            role.Name = tbName.Text;
            role.Description = tbDescription.Text;
            role.Purview = Request.Form["purview"];

            bool result = action == "modify" ? RoleBll.UpdateRole(role) : RoleBll.AddRole(role);
            LinkCollection c = new LinkCollection();
            c.Add("~/security/addrole.aspx", "添加角色");
            c.Add("~/security/rolemanage.aspx", "角色管理");
            WriteMessage(result?"操作执行成功":"当前操作失败,请选择下列操作", c, result);
        }
Esempio n. 10
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Role model)
        {
            //StringBuilder strSql = new StringBuilder();
            //strSql.Append("insert into Role(");
            //strSql.Append("RoleCode,RoleName,Status,IsAdmin,OrganID,SubSystemCode)");
            //strSql.Append(" values (");
            //strSql.Append("@RoleCode,@RoleName,@Status,@IsAdmin,@OrganID,@SubSystemCode)");
            //strSql.Append(";select @@IDENTITY");
            //SqlParameter[] parameters = {
            //        new SqlParameter("@RoleCode", SqlDbType.VarChar,20),
            //        new SqlParameter("@RoleName", SqlDbType.NChar,50),
            //        new SqlParameter("@Status", SqlDbType.Int,4),
            //        new SqlParameter("@IsAdmin", SqlDbType.Bit,1),
            //        new SqlParameter("@OrganID", SqlDbType.Int,4),
            //        new SqlParameter("@SubSystemCode", SqlDbType.VarChar,10)};
            //parameters[0].Value = model.RoleCode;
            //parameters[1].Value = model.RoleName;
            //parameters[2].Value = model.Status;
            //parameters[3].Value = model.IsAdmin;
            //parameters[4].Value = model.OrganID;
            //parameters[5].Value = model.SubSystemCode;

            //object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            //if (obj == null)
            //{
            //    return 0;
            //}
            //else
            //{
            //    return Convert.ToInt32(obj);
            //}

            SqlParameter[] parameters = {
                    new SqlParameter("@name", model.RoleName),
                    new SqlParameter("@subSystemCode", "S001"),
                    new SqlParameter("@isAdmin",false),
                    new SqlParameter("@InputBy", model.InputBy),
                    new SqlParameter("@organID", model.OrganID)};
            int re = 0;
            DbHelperSQL.RunProcedure("Proc_AddRole", parameters, out re);
            return re;
        }
Esempio n. 11
0
    protected void btn_Modity_Click(object sender, EventArgs e)
    {
        if (txt_Name.Text.Trim() == "系统管理员" || txt_Name.Text.Trim() == "超级管理员")
        {
            UtilityService.Alert(this.Page, "该名称是非法名,请换一个角色名称!");
            return;
        }

        Model.Role r = new Model.Role();
        r.RoleCode = lab_Code.Text;
        r.RoleName = txt_Name.Text.Trim();

        bool re = new RoleBLL().Update(r);
        if (re)
        {
            UtilityService.AlertAndRedirect(this, "修改成功!", "RoleMgr.aspx");
        }
        else
        {
            UtilityService.Alert(this, "修改失败!");
        }
    }
Esempio n. 12
0
        private bool tryValidate(Model.Role model, out string errMsg)
        {
            errMsg = "";
            bool re = true;

            if (model.Name == null || model.Name.Length == 0 || model.Name.Length > 20 ||
                model.Description.Length > 200)
            {
                errMsg = "输入数据不合法";
                re     = false;
            }
            if (re && RoleManager.CheckRepeat(model))
            {
                errMsg = "不能重复";
                re     = false;
            }
            if (re && model.Modifier != auth.UserId)
            {
                errMsg = "登录信息异常,请刷新浏览器以重启应用(APP请退出应用后重新打开)";
                re     = false;
            }
            return(re);
        }
Esempio n. 13
0
    protected void btn_Modity_Click(object sender, EventArgs e)
    {
        if (txt_Name.Text.Trim() == "系统管理员" || txt_Name.Text.Trim() == "超级管理员")
        {
            UtilityService.Alert(this.Page, "该名称是非法名,请换一个角色名称!");
            return;
        }

        Model.Role r = new Model.Role();
        r.RoleCode = lab_Code.Text;
        r.RoleName = txt_Name.Text.Trim();

        bool re = new RoleBLL().Update(r);

        if (re)
        {
            UtilityService.AlertAndRedirect(this, "修改成功!", "RoleMgr.aspx");
        }
        else
        {
            UtilityService.Alert(this, "修改失败!");
        }
    }
Esempio n. 14
0
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        if (txt_Name.Text.Trim() == "系统管理员" || txt_Name.Text.Trim() == "超级管理员")
        {
            UtilityService.Alert(this.Page, "该名称是非法名,请换一个角色名称!");
            return;
        }

        Model.Role r = new Model.Role();
        r.RoleName = txt_Name.Text.Trim();
        r.OrganID = (int)Session["OrganID"];
        r.InputBy = Session["UserID"].ToString();

        int re = new RoleBLL().Add(r);
        if (re > 0)
        {
            UtilityService.AlertAndRedirect(this, "添加成功!", "RoleMgr.aspx");
        }
        else
        {
            UtilityService.Alert(this, "添加失败!");
        }
    }
Esempio n. 15
0
        public ActionResult PstAddRole(List<int> powerId, Role role)
        {
            ModelState.Remove("ControllerIdList");
            if (ModelState.IsValid)
            {

                string idList = "," + String.Join(",", powerId) + ",";
                if (role.RoleID != 0)
                {
                    var mRole = powerSv.GetRole(role.RoleID);
                    if (mRole.ControllerIdList != idList)
                    {
                        mRole.ControllerIdList = idList;
                        UpdateModel(mRole);
                        powerSv.UpdateRoleController(mRole, powerId);
                    }
                    else
                    {
                        UpdateModel(mRole);
                        powerSv.Save();
                    }
                    return Json(new { res = "ok", url = Url.Action("RoleMange", "Power") });
                }
                else
                {

                    role.ControllerIdList = idList;

                    powerSv.SaveRole(role, powerId);
                    return Json(new { res = "ok", url = Url.Action("RoleMange", "Power") });
                }
            }
            else
            {
                return Json(new { res = "fail", msg = "操作失败!" });
            }
        }
Esempio n. 16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            action = RequestString("action");
            if (action == "modify")
            {
                role = RoleBll.GetRole(RequestInt32("id"));
                if (role == null)
                {
                    LinkCollection c = new LinkCollection();
                    c.Add("~/security/addrole.aspx", "添加角色");
                    c.Add("~/security/rolemanage.aspx", "角色管理");

                    WriteMessage("无法获取相关角色信息", c, false);
                }
            }
            if (!IsPostBack)
            {
                if (action == "modify")
                {
                    tbName.Text = role.Name;
                    tbDescription.Text = role.Description;
                    if (string.IsNullOrEmpty(role.Purview))
                    {
                        purviews = new string[0];
                    }
                    else
                    {
                        purviews = role.Purview.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    }
                }

                PageSecuritySection section = (PageSecuritySection)WebConfigurationManager.GetSection("PageSecurity");
                RptResource.DataSource = section.Resources.Resources;
                RptResource.DataBind();
            }
        }
Esempio n. 17
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Role GetModel(int Role_ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Role_ID,Role_Code,Role_Name,Role_Modules from T_Role ");
            strSql.Append(" where Role_ID=@Role_ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Role_ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = Role_ID;

            Role    model = new Model.Role();
            DataSet ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 18
0
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        if (txt_Name.Text.Trim() == "系统管理员" || txt_Name.Text.Trim() == "超级管理员")
        {
            UtilityService.Alert(this.Page, "该名称是非法名,请换一个角色名称!");
            return;
        }

        Model.Role r = new Model.Role();
        r.RoleName = txt_Name.Text.Trim();
        r.OrganID  = (int)Session["OrganID"];
        r.InputBy  = Session["UserID"].ToString();

        int re = new RoleBLL().Add(r);

        if (re > 0)
        {
            UtilityService.AlertAndRedirect(this, "添加成功!", "RoleMgr.aspx");
        }
        else
        {
            UtilityService.Alert(this, "添加失败!");
        }
    }
Esempio n. 19
0
 /// <summary>
 /// 创建新的 Role 对象。
 /// </summary>
 /// <param name="id">ID 属性的初始值。</param>
 public static Role CreateRole(global::System.Int32 id)
 {
     Role role = new Role();
     role.ID = id;
     return role;
 }
Esempio n. 20
0
 /// <summary>
 /// 检查是否重复
 /// </summary>
 /// <param name="Model.Role"></param>
 /// <returns></returns>
 public static bool CheckRepeat(Model.Role model)
 {
     return(RoleService.CheckRepeat(model));
 }
Esempio n. 21
0
 /// <summary>
 /// 根据id修改角色
 /// </summary>
 /// <param name="Model.Role"></param>
 /// <returns></returns>
 public static bool ModifyRoleById(ref Model.Role model, out string errMsg)
 {
     return(RoleService.ModifyRoleById(ref model, out errMsg));
 }
Esempio n. 22
0
 /// <summary>
 /// 添加角色
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool AddRole(ref Model.Role model, out string errMsg)
 {
     return(RoleService.AddRole(ref model, out errMsg));
 }
Esempio n. 23
0
 public Role(Role role)
 {
     Id = role.Id;
     Name = role.Name;
     Description = role.Description;
 }
        public IList<Role> GetAllRoles()
        {
            var list = new List<Role>();
            foreach (DataRow row in this["Role"].Rows)
            {
                var item = new Role
                {
                    Id = (Guid)row["Id"],
                    Description = row["Description"] == DBNull.Value ? null : row["Description"].ToString(),
                    Icon = row["Icon"] == DBNull.Value ? null : row["Icon"].ToString(),
                    Name = row["Name"] == DBNull.Value ? null : row["Name"].ToString(),
                    Etag = (byte[])row["Etag"],
                    SortCode = (int)row["SortCode"],
                    CategoryCode = row["CategoryCode"] == DBNull.Value ? null : row["CategoryCode"].ToString(),
                    IsEnabled = (int)row["IsEnabled"],
                    NumberId = (int)row["NumberId"]
                };
                var entity = item as IEntityBase;
                entity.CreateBy = row["CreateBy"] == DBNull.Value ? null : row["CreateBy"].ToString();
                entity.CreateOn = row["CreateOn"] == DBNull.Value ? null : (DateTime?)row["CreateOn"];
                entity.CreateUserId = row["CreateUserId"] == DBNull.Value ? null : (Guid?)row["CreateUserId"];
                entity.ModifiedBy = row["ModifiedBy"] == DBNull.Value ? null : row["ModifiedBy"].ToString();
                entity.ModifiedOn = row["ModifiedOn"] == DBNull.Value ? null : (DateTime?)row["ModifiedOn"];
                entity.ModifiedUserId = row["ModifiedUserId"] == DBNull.Value ? null : (Guid?)row["ModifiedUserId"];

                list.Add(item);
            }
            return list;
        }
Esempio n. 25
0
 public int UpdRole(Model.Role role)
 {
     return(DalBase.Updata(role));
 }
Esempio n. 26
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Role GetModel(string code)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from Role ");
            strSql.Append(" where RoleCode=@Code");
            SqlParameter[] parameters = {
                    new SqlParameter("@Code", code)
            };

            Role model = new Role();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RoleCode"] != null && ds.Tables[0].Rows[0]["RoleCode"].ToString() != "")
                {
                    model.RoleCode = ds.Tables[0].Rows[0]["RoleCode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["RoleName"] != null && ds.Tables[0].Rows[0]["RoleName"].ToString() != "")
                {
                    model.RoleName = ds.Tables[0].Rows[0]["RoleName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Status"] != null && ds.Tables[0].Rows[0]["Status"].ToString() != "")
                {
                    model.Status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsAdmin"] != null && ds.Tables[0].Rows[0]["IsAdmin"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsAdmin"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsAdmin"].ToString().ToLower() == "true"))
                    {
                        model.IsAdmin = true;
                    }
                    else
                    {
                        model.IsAdmin = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["OrganID"] != null && ds.Tables[0].Rows[0]["OrganID"].ToString() != "")
                {
                    model.OrganID = int.Parse(ds.Tables[0].Rows[0]["OrganID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SubSystemCode"] != null && ds.Tables[0].Rows[0]["SubSystemCode"].ToString() != "")
                {
                    model.SubSystemCode = ds.Tables[0].Rows[0]["SubSystemCode"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }
Esempio n. 27
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Role model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Role set ");
            strSql.Append("RoleName=@RoleName");
            strSql.Append(" where RoleCode=@RoleCode");
            SqlParameter[] parameters = {
                    new SqlParameter("@RoleName", model.RoleName),
                    new SqlParameter("@RoleCode", model.RoleCode)};

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Esempio n. 28
0
 /// <summary>
 /// 用于向 Role EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToRole(Role role)
 {
     base.AddObject("Role", role);
 }