protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                string username = Request.Form["username"];
                string password = Request.Form["password"];
                int    uid;

                if (username == "username")
                {
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "PopUp", "<script>$(function () {window.pop('请输入用户名');});</script>");
                    return;
                }
                if (password == "password")
                {
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "PopUp", "<script>$(function () {window.pop('请输入密码');});</script>");
                    return;
                }

                AdminsBLL adminBLL = new AdminsBLL();
                if (adminBLL.GetModelList("AdminAccount = '" + username + "'").Count > 0)
                {
                    if (adminBLL.GetModelList("AdminAccount = '" + username + "' and AdminPwd = '" + password + "'").Count > 0)
                    {
                        int aid = adminBLL.GetModelList("AdminAccount = '" + username + "' and AdminPwd = '" + password + "'")[0].AdminID;
                        HttpContext.Current.Session["aid"] = aid;
                        Response.Redirect("a_MainPage.aspx");
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "PopUp", "<script>$(function () {window.pop('用户名或密码错误');});</script>");
                        return;
                    }
                }
                else
                {
                    Regex rex_telnumber = new Regex(@"^1([38]\d|5[0-35-9]|7[3678])\d{8}$");
                    if (!rex_telnumber.IsMatch(username))
                    {
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "PopUp", "<script>$(function () {window.pop('请检查用户名是否有误');});</script>");
                        return;
                    }

                    UsersBLL     userBll = new UsersBLL();
                    List <Users> userList;
                    Users        user = new Users();
                    // 对密码进行MD5加密(基于base64编码)然后与数据库中的密码值进行比对
                    var bytes = Encoding.UTF8.GetBytes(password);
                    using (var md5 = MD5.Create())
                    {
                        var hash = md5.ComputeHash(bytes);
                        password = Convert.ToBase64String(hash);
                    }
                    userList = userBll.GetModelList("TelNumber = " + decimal.Parse(username) + " and Pwd = '" + password + "'");
                    if (userBll.GetModelList("TelNumber = " + decimal.Parse(username)).Count > 0)
                    {
                        if (userBll.GetModelList("TelNumber = " + decimal.Parse(username) + " and Pwd = '" + password + "'").Count > 0)
                        {
                            uid                = userList[0].Uid;
                            user               = userBll.GetModel(uid);
                            user.LoginStatus   = 1;
                            user.LastLoginTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                            userBll.Update(user);
                            //HttpCookie httpCookie = new HttpCookie("uid")
                            //{
                            //    Value = uid.ToString(),
                            //    Expires = DateTime.Now.AddMinutes(15);
                            //};
                            //HttpContext.Current.Response.Cookies.Add(httpCookie);
                            HttpContext.Current.Session["uid"] = uid;
                            //uid = Encode(usersList[0].Uid.ToString(), "iRanania");
                            Response.Redirect("u_MainPage.aspx?uid=" + uid);
                        }
                        else
                        {
                            ClientScript.RegisterStartupScript(ClientScript.GetType(), "PopUp", "<script>$(function () {window.pop('用户名或密码错误');});</script>");
                            return;
                        }
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "PopUp", "<script>$(function () {window.pop('用户不存在');});</script>");
                        return;
                    }
                }
            }
            if (!string.IsNullOrEmpty(Request.QueryString["res"]))
            {
                if (int.Parse(Request.QueryString["res"]) == 5)
                {
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "PopUp", "<script>$(function () {window.pop('请先登录');});</script>");
                }
            }
            SignUpAdd = "Sign up.aspx";
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rgCount = userbll.GetModelList("").Count;
                if (rgCount % 5 == 0)
                {
                    rgMaxPage = rgCount / 5;
                }
                else
                {
                    rgMaxPage = rgCount / 5 + 1;
                }
            }

            // 页面加载时获取房型信息
            if (!string.IsNullOrEmpty(Request["postTag"]))
            {
                if (Request["postTag"] == "load")
                {
                    string sqlStrByPage = "select * from (" +
                                          " select ROW_NUMBER() over(order by Uid ASC) AS Row, Uid, TelNumber, Fname, IdCard, CheckinCount" +
                                          " from Users) T where T.Row between 1 and 5";

                    Response.Write(Get_Serialize_Data_FromSql(connectString, sqlStrByPage));
                    Response.End();
                }
            }

            // Ajax分页查询房型信息
            if (!string.IsNullOrEmpty(Request["postTag"]))
            {
                if (Request["postTag"] == "rgByPage")
                {
                    rgNowPage = int.Parse(Request["rgNowPage"]);
                    StringBuilder sqlPage = new StringBuilder();
                    sqlPage.AppendFormat("select * from (" +
                                         " select ROW_NUMBER() over(order by Uid ASC) AS Row, Uid, TelNumber, Fname, IdCard, CheckinCount" +
                                         " from Users) T where T.Row between {0} and {1}",
                                         (rgNowPage - 1) * 5 + 1, rgNowPage * 5);

                    Response.Write(Get_Serialize_Data_FromSql(connectString, sqlPage.ToString()));
                    Response.End();
                }
            }

            // Reset
            if (!string.IsNullOrEmpty(Request["postTag"]))
            {
                if (Request["postTag"] == "update")
                {
                    int   uid  = int.Parse(Request["uid"]);
                    Users user = userbll.GetModel(uid);

                    string pwd   = user.Idcard.Substring(12, 6);
                    var    bytes = Encoding.UTF8.GetBytes(pwd);
                    using (var md5 = System.Security.Cryptography.MD5.Create())
                    {
                        var hash = md5.ComputeHash(bytes);
                        pwd = Convert.ToBase64String(hash);
                    }
                    user.Pwd = pwd;

                    Response.Write(userbll.Update(user) ? 1 : 0);
                    Response.End();
                }
            }
        }