Пример #1
0
        protected void btn_reg_Click(object sender, EventArgs e)
        {
            if (txt_username.Text.Trim() != "")
            {
                RedGlovePermission.BLL.Users bll = new RedGlovePermission.BLL.Users();
                RedGlovePermission.Model.Users model = new RedGlovePermission.Model.Users();
                model.UserName = txt_username.Text.Trim();
                model.Password = RedGlovePermission.Lib.SecurityEncryption.MD5(txt_password2.Text.Trim(), 32);
                model.Question = txt_question.Text.Trim();
                model.Answer = txt_answer.Text.Trim();
                if (RGP_Value.IsVerifyUser)
                {
                    model.UserGroup = RGP_Value.initGroupID;
                    model.RoleID = RGP_Value.InitRoleID;
                }
                model.IsLimit = false;

                switch (bll.CreateUser(model))
                {
                    case 1:
                        ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "MsgBox", "alert('" + ResourceManager.GetString("Pub_Msg_add_true") + "')", true);
                        break;
                    case 2:
                        ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "MsgBox", "alert('" + ResourceManager.GetString("Pub_Msg_IsUser") + "')", true);
                        break;
                    default:
                        ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "MsgBox", "alert('" + ResourceManager.GetString("Pub_Msg_add_false") + "')", true);
                        break;
                }
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "MsgBox", "alert('" + ResourceManager.GetString("Pub_Msg_V_1") + "')", true);
            }
        }
Пример #2
0
        protected void btn_reg_Click(object sender, EventArgs e)
        {
            RedGlovePermission.BLL.Users   bll   = new RedGlovePermission.BLL.Users();
            RedGlovePermission.Model.Users model = new RedGlovePermission.Model.Users();
            model.UserName = txt_username.Text.Trim();
            model.Password = RedGlovePermission.Lib.SecurityEncryption.MD5(txt_password2.Text.Trim(), 32);
            model.Question = txt_question.Text.Trim();
            model.Answer   = txt_answer.Text.Trim();
            if (RGP_Value.IsVerifyUser)
            {
                model.UserGroup = RGP_Value.initGroupID;
                model.RoleID    = RGP_Value.InitRoleID;
            }
            model.IsLimit = false;

            switch (bll.CreateUser(model))
            {
            case 1:
                ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "MsgBox", "alert('注册成功!')", true);
                break;

            case 2:
                ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "MsgBox", "alert('用户已经存在,请更换后重试!')", true);
                break;

            default:
                ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "MsgBox", "alert('注册失败!')", true);
                break;
            }
        }
Пример #3
0
 protected void GetUser(int id)
 {
     RedGlovePermission.BLL.Users   bll   = new RedGlovePermission.BLL.Users();
     RedGlovePermission.Model.Users model = new RedGlovePermission.Model.Users();
     model          = bll.GetUserModel(id);
     lab_name.Text  = model.UserName;
     Lab_group.Text = model.UserGroup.ToString();
     Lab_role.Text  = model.RoleID.ToString();
     Lab_state.Text = model.Status.ToString();
     Lab_time1.Text = model.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
     Lab_time2.Text = model.LastLoginTime.ToString("yyyy-MM-dd HH:mm:ss");
 }
Пример #4
0
 protected void GetUser(int id)
 {
     RedGlovePermission.BLL.Users bll = new RedGlovePermission.BLL.Users();
     RedGlovePermission.Model.Users model= new RedGlovePermission.Model.Users();
     model = bll.GetUserModel(id);
     lab_name.Text = model.UserName;
     Lab_group.Text= model.UserGroup.ToString();
     Lab_role.Text=model.RoleID.ToString();
     Lab_state.Text=model.Status.ToString();
     Lab_time1.Text=model.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
     Lab_time2.Text = model.LastLoginTime.ToString("yyyy-MM-dd HH:mm:ss");
 }
Пример #5
0
        /// <summary>
        /// 创建一个新用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int CreateUser(RedGlovePermission.Model.Users model)
        {
            int ret = 0;

            if (!UserExists(model.UserName))
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into Users(");
                strSql.Append("UserName,Password,Question,Answer,RoleID,UserGroup,CreateTime,IsLimit)");
                strSql.Append(" values (");
                strSql.Append("@UserName,@Password,@Question,@Answer,@RoleID,@UserGroup,@CreateTime,@IsLimit)");
                strSql.Append(";select @@IDENTITY");
                SqlParameter[] parameters =
                {
                    new SqlParameter("@UserName",   SqlDbType.NVarChar,  128),
                    new SqlParameter("@Password",   SqlDbType.NVarChar,  128),
                    new SqlParameter("@Question",   SqlDbType.NVarChar,  100),
                    new SqlParameter("@Answer",     SqlDbType.NVarChar,  100),
                    new SqlParameter("@RoleID",     SqlDbType.Int,         4),
                    new SqlParameter("@UserGroup",  SqlDbType.Int,         4),
                    new SqlParameter("@CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@IsLimit",    SqlDbType.Bit, 1)
                };
                parameters[0].Value = model.UserName;
                parameters[1].Value = model.Password;
                parameters[2].Value = model.Question;
                parameters[3].Value = model.Answer;
                parameters[4].Value = model.RoleID;
                parameters[5].Value = model.UserGroup;
                parameters[6].Value = DateTime.Now;
                parameters[7].Value = model.IsLimit;


                object obj = SqlServerHelper.GetSingle(strSql.ToString(), parameters);
                if (obj != null)
                {
                    ret = 1;
                }
            }
            else
            {
                ret = 2;
            }
            return(ret);
        }
Пример #6
0
        /// <summary>
        /// 创建一个新用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int CreateUser(RedGlovePermission.Model.Users model)
        {
            int ret = 0;

            if (!UserExists(model.UserName))
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into Users(");
                strSql.Append("UserName,Password,Question,Answer,RoleID,UserGroup,CreateTime,IsLimit)");
                strSql.Append(" values (");
                strSql.Append("?UserName,?Password,?Question,?Answer,?RoleID,?UserGroup,?CreateTime,?IsLimit)");
                strSql.Append(";select LAST_INSERT_ID()");
                MySqlParameter[] parameters =
                {
                    new MySqlParameter("?UserName",   MySqlDbType.VarChar,   128),
                    new MySqlParameter("?Password",   MySqlDbType.VarChar,   128),
                    new MySqlParameter("?Question",   MySqlDbType.VarChar,   100),
                    new MySqlParameter("?Answer",     MySqlDbType.VarChar,   100),
                    new MySqlParameter("?RoleID",     MySqlDbType.Int32,      11),
                    new MySqlParameter("?UserGroup",  MySqlDbType.Int32,      11),
                    new MySqlParameter("?CreateTime", MySqlDbType.DateTime),
                    new MySqlParameter("?IsLimit",    MySqlDbType.Bit, 1)
                };
                parameters[0].Value = model.UserName;
                parameters[1].Value = model.Password;
                parameters[2].Value = model.Question;
                parameters[3].Value = model.Answer;
                parameters[4].Value = model.RoleID;
                parameters[5].Value = model.UserGroup;
                parameters[6].Value = DateTime.Now;
                parameters[7].Value = model.IsLimit;


                object obj = RedGlovePermission.DBUtility.MySqlHelper.GetSingle(strSql.ToString(), parameters);
                if (obj != null)
                {
                    ret = 1;
                }
            }
            else
            {
                ret = 2;
            }
            return(ret);
        }
Пример #7
0
        protected void btn_login_Click(object sender, EventArgs e)
        {
            RedGlovePermission.BLL.Users bll = new RedGlovePermission.BLL.Users();
            RedGlovePermission.Model.Users model = new RedGlovePermission.Model.Users();

            if (UserName.Text.Trim() == "" || Password.Text.Trim() == "")
            {
                ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('" + ResourceManager.GetString("Login_Msg_V_3") + "');", true);
            }
            else
            {
                if (bll.CheckLogin(UserName.Text.Trim(), RedGlovePermission.Lib.SecurityEncryption.MD5(Password.Text.Trim(), 32)))
                {
                    model = bll.GetUserModel(UserName.Text.Trim());
                    if (model.RoleID != 0)
                    {
                        if (model.Status != 0)
                        {
                            #region 登录成功,将登录id存入hash表

                            Hashtable hOnline = (Hashtable)Application["Online"];
                            if (hOnline != null)
                            {
                                int i = 0;
                                while (i < hOnline.Count) //增加此判断强制查询到底 
                                {
                                    IDictionaryEnumerator idE = hOnline.GetEnumerator();
                                    string strKey = "";
                                    while (idE.MoveNext())
                                    {
                                        if (idE.Value != null && idE.Value.ToString().Equals(model.UserName))
                                        {
                                            //已经登录             
                                            strKey = idE.Key.ToString();
                                            hOnline[strKey] = "XXXXXX";
                                            break;
                                        }
                                    }
                                    i = i + 1;
                                }
                            }
                            else
                            {
                                hOnline = new Hashtable();
                            }
                            hOnline[Session.SessionID] = model.UserName;
                            Application.Lock();
                            Application["Online"] = hOnline;
                            Application.UnLock();

                            #endregion

                            bll.UpdateLoginTime(model.UserID);//更新登录时间
                            Session["userLanguage"] = Language.SelectedValue;
                            SessionBox.CreateUserSession(new UserSession(model.UserID, model.UserName, model.RoleID, model.IsLimit, model.Status));

                            Response.Redirect("~/Admin/Frameset/Default.aspx");
                        }
                        else
                        {
                            ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('" + ResourceManager.GetString("Login_Msg_2") + "');", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('" + ResourceManager.GetString("Login_Msg_3") + "');", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('" + ResourceManager.GetString("Login_Msg_2") + "');", true);
                }
            }
        }
Пример #8
0
        /// <summary>
        /// 根据用户名得到用户对象实体
        /// </summary>
        public RedGlovePermission.Model.Users GetUserModel(string UserName)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 UserID,UserName,Password,Question,Answer,RoleID,UserGroup,CreateTime,LastLoginTime,Status,IsOnline,IsLimit from Users ");
            strSql.Append(" where UserName=@UserName ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserName", SqlDbType.NVarChar, 128)
            };
            parameters[0].Value = UserName;

            RedGlovePermission.Model.Users model = new RedGlovePermission.Model.Users();
            DataSet ds = SqlServerHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["UserID"].ToString() != "")
                {
                    model.UserID = int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString());
                }
                model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                model.Password = ds.Tables[0].Rows[0]["Password"].ToString();
                model.Question = ds.Tables[0].Rows[0]["Question"].ToString();
                model.Answer   = ds.Tables[0].Rows[0]["Answer"].ToString();
                if (ds.Tables[0].Rows[0]["RoleID"].ToString() != "")
                {
                    model.RoleID = int.Parse(ds.Tables[0].Rows[0]["RoleID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserGroup"].ToString() != "")
                {
                    model.UserGroup = int.Parse(ds.Tables[0].Rows[0]["UserGroup"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastLoginTime"].ToString() != "")
                {
                    model.LastLoginTime = DateTime.Parse(ds.Tables[0].Rows[0]["LastLoginTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Status"].ToString() != "")
                {
                    model.Status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsOnline"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsOnline"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsOnline"].ToString().ToLower() == "true"))
                    {
                        model.IsOnline = true;
                    }
                    else
                    {
                        model.IsOnline = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["IsLimit"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsLimit"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsLimit"].ToString().ToLower() == "true"))
                    {
                        model.IsLimit = true;
                    }
                    else
                    {
                        model.IsLimit = false;
                    }
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #9
0
        protected void btn_login_Click(object sender, EventArgs e)
        {
            RedGlovePermission.BLL.Users   bll   = new RedGlovePermission.BLL.Users();
            RedGlovePermission.Model.Users model = new RedGlovePermission.Model.Users();

            if (UserName.Text.Trim() == "" || Password.Text.Trim() == "")
            {
                ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('" + ResourceManager.GetString("Login_Msg_V_3") + "');", true);
            }
            else
            {
                if (bll.CheckLogin(UserName.Text.Trim(), RedGlovePermission.Lib.SecurityEncryption.MD5(Password.Text.Trim(), 32)))
                {
                    model = bll.GetUserModel(UserName.Text.Trim());
                    if (model.RoleID != 0)
                    {
                        if (model.Status != 0)
                        {
                            #region 登录成功,将登录id存入hash表

                            Hashtable hOnline = (Hashtable)Application["Online"];
                            if (hOnline != null)
                            {
                                int i = 0;
                                while (i < hOnline.Count) //增加此判断强制查询到底
                                {
                                    IDictionaryEnumerator idE = hOnline.GetEnumerator();
                                    string strKey             = "";
                                    while (idE.MoveNext())
                                    {
                                        if (idE.Value != null && idE.Value.ToString().Equals(model.UserName))
                                        {
                                            //已经登录
                                            strKey          = idE.Key.ToString();
                                            hOnline[strKey] = "XXXXXX";
                                            break;
                                        }
                                    }
                                    i = i + 1;
                                }
                            }
                            else
                            {
                                hOnline = new Hashtable();
                            }
                            hOnline[Session.SessionID] = model.UserName;
                            Application.Lock();
                            Application["Online"] = hOnline;
                            Application.UnLock();

                            #endregion

                            bll.UpdateLoginTime(model.UserID);//更新登录时间
                            Session["userLanguage"] = Language.SelectedValue;
                            SessionBox.CreateUserSession(new UserSession(model.UserID, model.UserName, model.RoleID, model.IsLimit, model.Status));

                            Response.Redirect("~/Admin/Frameset/Default.aspx");
                        }
                        else
                        {
                            ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('" + ResourceManager.GetString("Login_Msg_2") + "');", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('" + ResourceManager.GetString("Login_Msg_3") + "');", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('" + ResourceManager.GetString("Login_Msg_2") + "');", true);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// 根据ID得到用户对象实体
        /// </summary>
        public RedGlovePermission.Model.Users GetUserModel(int UserID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from Users ");
            strSql.Append(" where UserID=?UserID ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("?UserID", MySqlDbType.Int32, 11)
            };
            parameters[0].Value = UserID;

            RedGlovePermission.Model.Users model = new RedGlovePermission.Model.Users();
            DataSet ds = RedGlovePermission.DBUtility.MySqlHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["UserID"].ToString() != "")
                {
                    model.UserID = int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString());
                }
                model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                model.Password = ds.Tables[0].Rows[0]["Password"].ToString();
                model.Question = ds.Tables[0].Rows[0]["Question"].ToString();
                model.Answer   = ds.Tables[0].Rows[0]["Answer"].ToString();
                if (ds.Tables[0].Rows[0]["RoleID"].ToString() != "")
                {
                    model.RoleID = int.Parse(ds.Tables[0].Rows[0]["RoleID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserGroup"].ToString() != "")
                {
                    model.UserGroup = int.Parse(ds.Tables[0].Rows[0]["UserGroup"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastLoginTime"].ToString() != "")
                {
                    model.LastLoginTime = DateTime.Parse(ds.Tables[0].Rows[0]["LastLoginTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Status"].ToString() != "")
                {
                    model.Status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsOnline"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsOnline"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsOnline"].ToString().ToLower() == "true"))
                    {
                        model.IsOnline = true;
                    }
                    else
                    {
                        model.IsOnline = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["IsLimit"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsLimit"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsLimit"].ToString().ToLower() == "true"))
                    {
                        model.IsLimit = true;
                    }
                    else
                    {
                        model.IsLimit = false;
                    }
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #11
0
 /// <summary>
 /// 更新資料
 /// </summary>
 protected void UserList_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
     RedGlovePermission.Model.Users model = new RedGlovePermission.Model.Users();
     model.UserID = int.Parse(UserList.DataKeys[e.RowIndex].Values[0].ToString());
     model.Password = RedGlovePermission.Lib.SecurityEncryption.MD5(((TextBox)UserList.Rows[e.RowIndex].FindControl("txt_password")).Text.Trim(), 32); 
     model.RoleID = int.Parse(((TextBox)UserList.Rows[e.RowIndex].FindControl("txt_roleid")).Text.Trim());
     model.UserGroup = int.Parse(((TextBox)UserList.Rows[e.RowIndex].FindControl("txt_usergroup")).Text.Trim());
     model.Status = int.Parse(((TextBox)UserList.Rows[e.RowIndex].FindControl("txt_status")).Text.Trim());
     if (!bll.UpdateUser(model))
     {
         ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "MsgBox", "alert('" + ResourceManager.GetString("Pub_Msg_update_false") + "')", true);
     }
     /// 返回瀏覽狀態
     UserList.EditIndex = -1;
     BindOrder();
 }
Пример #12
0
        /// <summary>
        /// 根据用户名得到用户对象实体
        /// </summary>
        public RedGlovePermission.Model.Users GetUserModel(string UserName)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from Users ");
            strSql.Append(" where UserName=?UserName ");
            MySqlParameter[] parameters = {
					new MySqlParameter("?UserName", MySqlDbType.VarChar,128)};
            parameters[0].Value = UserName;

            RedGlovePermission.Model.Users model = new RedGlovePermission.Model.Users();
            DataSet ds = RedGlovePermission.DBUtility.MySqlHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["UserID"].ToString() != "")
                {
                    model.UserID = int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString());
                }
                model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                model.Password = ds.Tables[0].Rows[0]["Password"].ToString();
                model.Question = ds.Tables[0].Rows[0]["Question"].ToString();
                model.Answer = ds.Tables[0].Rows[0]["Answer"].ToString();
                if (ds.Tables[0].Rows[0]["RoleID"].ToString() != "")
                {
                    model.RoleID = int.Parse(ds.Tables[0].Rows[0]["RoleID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserGroup"].ToString() != "")
                {
                    model.UserGroup = int.Parse(ds.Tables[0].Rows[0]["UserGroup"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastLoginTime"].ToString() != "")
                {
                    model.LastLoginTime = DateTime.Parse(ds.Tables[0].Rows[0]["LastLoginTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Status"].ToString() != "")
                {
                    model.Status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsOnline"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsOnline"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsOnline"].ToString().ToLower() == "true"))
                    {
                        model.IsOnline = true;
                    }
                    else
                    {
                        model.IsOnline = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["IsLimit"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsLimit"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsLimit"].ToString().ToLower() == "true"))
                    {
                        model.IsLimit = true;
                    }
                    else
                    {
                        model.IsLimit = false;
                    }
                }
                return model;
            }
            else
            {
                return null;
            }
        }