Esempio n. 1
0
        /// <summary>
        /// 页面加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                return;
            }

            // 修改
            if (Request.QueryString["ID"] != null)
            {
                var id = Convert.ToInt32(Request.QueryString["ID"]);
                if (id <= 0)
                {
                    return;
                }

                // 获取数据
                _systemRolesModel = _systemRolesBll.GetModel(id);
                if (_systemRolesModel == null)
                {
                    return;
                }

                tbRoleName.Text    = _systemRolesModel.RoleName; // 角色名称
                tbRoleName.Enabled = false;                      // 如果是修改,禁止编辑角色名称
                tbRemarks.Text     = _systemRolesModel.Remarks;  // 备注信息

                // 绑定数据
                Bind();

                // 对控件进行赋值
                foreach (Control item in MyMenus.Items)
                {
                    var checklist = item.FindControl("MyCheckBoxList") as CheckBoxList;
                    ControlTools.GetCheckList(checklist, _systemRolesModel.Actionstr);
                }
            }
            else // 添加
            {
                Bind();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Haikan.SchoolProjectsCore.MDB.Model.SystemRoles model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update SystemRoles set ");
            strSql.Append("RoleName=@RoleName,");
            strSql.Append("Remarks=@Remarks,");
            strSql.Append("Actionstr=@Actionstr,");
            strSql.Append("IsDelete=@IsDelete,");
            strSql.Append("AddTime=@AddTime,");
            strSql.Append("AddPeople=@AddPeople");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleName",  SqlDbType.VarChar,    50),
                new SqlParameter("@Remarks",   SqlDbType.VarChar,  1000),
                new SqlParameter("@Actionstr", SqlDbType.NVarChar,   -1),
                new SqlParameter("@IsDelete",  SqlDbType.Int,         4),
                new SqlParameter("@AddTime",   SqlDbType.VarChar,   255),
                new SqlParameter("@AddPeople", SqlDbType.VarChar,   255),
                new SqlParameter("@ID",        SqlDbType.Int, 4)
            };
            parameters[0].Value = model.RoleName;
            parameters[1].Value = model.Remarks;
            parameters[2].Value = model.Actionstr;
            parameters[3].Value = model.IsDelete;
            parameters[4].Value = model.AddTime;
            parameters[5].Value = model.AddPeople;
            parameters[6].Value = model.ID;

            int rows = DbHelperSql.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Haikan.SchoolProjectsCore.MDB.Model.SystemRoles model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into SystemRoles(");
            strSql.Append("RoleName,Remarks,Actionstr,IsDelete,AddTime,AddPeople)");
            strSql.Append(" values (");
            strSql.Append("@RoleName,@Remarks,@Actionstr,@IsDelete,@AddTime,@AddPeople)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleName",  SqlDbType.VarChar,    50),
                new SqlParameter("@Remarks",   SqlDbType.VarChar,  1000),
                new SqlParameter("@Actionstr", SqlDbType.NVarChar,   -1),
                new SqlParameter("@IsDelete",  SqlDbType.Int,         4),
                new SqlParameter("@AddTime",   SqlDbType.VarChar,   255),
                new SqlParameter("@AddPeople", SqlDbType.VarChar, 255)
            };
            parameters[0].Value = model.RoleName;
            parameters[1].Value = model.Remarks;
            parameters[2].Value = model.Actionstr;
            parameters[3].Value = model.IsDelete;
            parameters[4].Value = model.AddTime;
            parameters[5].Value = model.AddPeople;

            object obj = DbHelperSql.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Haikan.SchoolProjectsCore.MDB.Model.SystemRoles DataRowToModel(DataRow row)
 {
     Haikan.SchoolProjectsCore.MDB.Model.SystemRoles model = new Haikan.SchoolProjectsCore.MDB.Model.SystemRoles();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["RoleName"] != null)
         {
             model.RoleName = row["RoleName"].ToString();
         }
         if (row["Remarks"] != null)
         {
             model.Remarks = row["Remarks"].ToString();
         }
         if (row["Actionstr"] != null)
         {
             model.Actionstr = row["Actionstr"].ToString();
         }
         if (row["IsDelete"] != null && row["IsDelete"].ToString() != "")
         {
             model.IsDelete = int.Parse(row["IsDelete"].ToString());
         }
         if (row["AddTime"] != null)
         {
             model.AddTime = row["AddTime"].ToString();
         }
         if (row["AddPeople"] != null)
         {
             model.AddPeople = row["AddPeople"].ToString();
         }
     }
     return(model);
 }
Esempio n. 5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Haikan.SchoolProjectsCore.MDB.Model.SystemRoles GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,RoleName,Remarks,Actionstr,IsDelete,AddTime,AddPeople from SystemRoles ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            Haikan.SchoolProjectsCore.MDB.Model.SystemRoles model = new Haikan.SchoolProjectsCore.MDB.Model.SystemRoles();
            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. 6
0
        /// <summary>
        /// 点击登陆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            // 先判断验证码
            _systemSetModel = _systemSetBll.GetModel(_systemSetBll.GetMaxId());
            // 判断是否需要验证码
            if (_systemSetModel.IsIdentifyingCode.ToString() == "0")
            {
                if (Session["yzm"] != null && !string.Equals(Session["yzm"].ToString(), TxtYZM.Text, StringComparison.CurrentCultureIgnoreCase))
                {
                    Alert("验证码错误");
                    return;
                }
            }

            // sql注入风险检查
            if (SystemPage.SqlFilter(TxtUserName.Text.Trim()) || SystemPage.SqlFilter(TxtUserPwd.Text.Trim()))
            {
                Alert("帐号错误,请注意非法字符!");
                return;
            }

            // 密码可能是原文或者md5加密后的
            var strWhere = "UserName = '******' and (UserPWD = '" + DesEncrypt.GetMd5String(TxtUserPwd.Text.Trim()) + "' or UserPWD = '" + TxtUserPwd.Text.Trim() + "')";

            var d = _systemUserBll.GetList(" UserName='******'");

            if (d.Tables[0].Rows.Count > 0)
            {
                // 检测是否非法登录3次
                var verify = _illegalityLogin.PwdIsCorrect(TxtUserName.Text.Trim(), 3, TxtUserPwd.Text.Trim());

                if (verify == "成功")
                {
                    // 获取该用户的相关信息
                    var ds = _systemUserBll.GetModelList(strWhere);

                    if (ds.Count <= 0)
                    {
                        Alert("对不起,没有找到对应的用户!");
                        return;
                    }

                    _systemUserModel = ds[0];
                    if (_systemUserModel == null)
                    {
                        Alert("对不起,没有找到对应的用户!");
                        return;
                    }

                    if (_systemUserModel.IsEnter == 1)
                    {
                        Alert("对不起,您已被禁止登录!");
                        return;
                    }

                    // 获取角色和权限
                    var roleId = Convert.ToInt32(_systemUserModel.RoleID);
                    _systemRolesModel = _systemRolesBll.GetModel(roleId);
                    if (_systemRolesModel != null)
                    {
                        Session["roleId"]    = _systemUserModel.RoleID;
                        Session["RoleName"]  = _systemRolesModel.RoleName;
                        Session["ActionStr"] = _systemRolesModel.Actionstr;
                    }

                    // 个人信息
                    Session["userid"]             = _systemUserModel.ID;
                    Session["TrueName"]           = _systemUserModel.TrueName;
                    Session["username"]           = TxtUserName.Text.Trim();
                    Session["Department"]         = _systemUserModel.DepartmentID;
                    Session["BirthDay"]           = _systemUserModel.BirthDay;
                    Session["IdentityCard"]       = _systemUserModel.SFZSerils;          //身份证号码
                    Session["Sex"]                = _systemUserModel.Sex;
                    Session["JiaRuBenDanWeiTime"] = _systemUserModel.JiaRuBenDanWeiTime; // 入职时间
                    Session["TelephoneNumber"]    = _systemUserModel.TelphoneNumber;     // 联系电话

                    // 判断是否选择了记住密码
                    if (chkRemembered.Checked)
                    {
                        var cookie = new HttpCookie("RememberPWD");
                        cookie.Values.Add("Name", TxtUserName.Text.Trim());

                        // 如果长度大于20,可以判定为md5加密后的密码,直接保存即可,否则需要加密后保存
                        cookie.Values.Add("UserPwd",
                                          TxtUserPwd.Text.Trim().Length > 20
                                ? TxtUserPwd.Text.Trim()
                                : DesEncrypt.GetMd5String(TxtUserPwd.Text.Trim()));

                        cookie.Expires = DateTime.Now.AddDays(60.0);// 有效期2个月
                        HttpContext.Current.Response.Cookies.Add(cookie);
                    }

                    // 左侧菜单,保存到cookies中
                    var menuStr = BindStr();
                    if (menuStr != "")
                    {
                        DataCache.SetCache("HaikanSchoolProjects-" + Session["userid"], menuStr);
                    }

                    // 跳转到主界面
                    Response.Redirect("/General/Main.aspx");
                }
                else
                {
                    Alert(verify);
                }
            }
            else
            {
                Alert("不存在该用户");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 点击提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            if (tbRoleName.Text != "")
            {
                if (Request.QueryString["ID"] != null)
                {
                    var id = Convert.ToInt32(Request.QueryString["ID"]);
                    if (id > 0) // 修改
                    {
                        _systemRolesModel = _systemRolesBll.GetModel(int.Parse(Request.QueryString["ID"]));

                        _systemRolesModel.RoleName = tbRoleName.Text;
                        _systemRolesModel.Remarks  = tbRemarks.Text;

                        var actionStr = "";

                        foreach (Control item1 in MyMenus.Items)
                        {
                            // 页面checkbox集合对象
                            var myCheckBoxList = item1.FindControl("MyCheckBoxList") as CheckBoxList;

                            // 添加子项的权限
                            actionStr += ControlTools.GetStringFromCheckList(myCheckBoxList);
                        }

                        _systemRolesModel.Actionstr = actionStr;
                        _systemRolesBll.Update(_systemRolesModel);

                        // 写系统日志
                        AddSystemLog("用户修改角色信息,角色名为:" + tbRoleName.Text + ",权限字符串为:" + actionStr, "修改");

                        // 提示框
                        AlertAndParentSkip("角色信息修改成功!", "SystemRolesList.aspx");
                    }
                }
                else // 添加
                {
                    // 如果是新增,则要判断是否存在同名的角色名称
                    var ds = _systemRolesBll.GetList("RoleName='" + tbRoleName.Text + "'");

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        Alert("该角色名已经存在,请更换其他名称!");
                    }
                    else
                    {
                        // 获取控件信息
                        _systemRolesModel.RoleName  = tbRoleName.Text;                                     // 角色名称
                        _systemRolesModel.Remarks   = tbRemarks.Text;                                      // 备注信息
                        _systemRolesModel.AddTime   = DateTime.Now.ToString(CultureInfo.InvariantCulture); // 添加时间
                        _systemRolesModel.AddPeople = Session["TrueName"].ToString();                      // 添加人真实姓名

                        var actionStr = "";

                        foreach (Control item1 in MyMenus.Items)
                        {
                            var checklist1 = item1.FindControl("MyCheckBoxList") as CheckBoxList;
                            actionStr += ControlTools.GetStringFromCheckList(checklist1);
                        }

                        _systemRolesModel.Actionstr = actionStr;
                        _systemRolesModel.IsDelete  = 1;
                        _systemRolesBll.Add(_systemRolesModel);

                        //写系统日志
                        AddSystemLog("用户添加角色信息,角色名为:" + tbRoleName.Text, "添加");

                        AlertAndParentSkip("角色信息添加成功!", "SystemRolesList.aspx");
                    }
                }
            }
            else
            {
                Alert("请输入角色名称!");
            }
        }