Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            User loggedUser = UserOpr.isLogged(Request);

            if (loggedUser == null)
            {
                LoginStatus.Text    = "您未登录或登录过期,请重新登录,3秒后跳转到用户登录页面";
                LoginStatus.Visible = true;
                HtmlMeta RedirectMeta = new HtmlMeta();                                               //重定向用Meta标签
                RedirectMeta.HttpEquiv = "refresh";                                                   //指定行为为跳转
                RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("LoginPageURL"); //时间为三秒,跳转到首页
                this.Page.Header.Controls.Add(RedirectMeta);
            }
            else
            {
                if (!Page.IsPostBack)
                {
                    if (loggedUser.User_isChecked)
                    {
                        //已激活
                        LoginStatus.Text    = "您已经完成用户激活,无需再次激活";
                        LoginStatus.Visible = true;
                    }
                    else
                    {
                        //未激活
                        UserOpr.SendVerifyMailToNewUser(loggedUser);
                        LoginStatus.Text    = "确认信已经发往您登录时所用邮箱,请查收";
                        LoginStatus.Visible = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            User loggedUser = UserOpr.isLogged(Request);

            if (loggedUser == null)
            {
                //未登录
                CheckUserForm.Visible  = false;
                lblLoginStatus.Text    = "您未登录或者已经登录过期,请登录后再进行激活。3秒后转向登录页面";
                lblLoginStatus.Visible = true;

                //重定向
                HtmlMeta RedirectMeta = new HtmlMeta();                                               //重定向用Meta标签
                RedirectMeta.HttpEquiv = "refresh";                                                   //指定行为为跳转
                RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("LoginPageURL"); //时间为三秒,跳转到首页
                this.Page.Header.Controls.Add(RedirectMeta);
            }
            if (loggedUser.User_isChecked)
            {
                //已经激活
                lblLoginStatus.Text    = "您已经是激活用户,无需再次激活";
                lblLoginStatus.Visible = true;
            }
            else
            {
                lblLoginStatus.Visible = false;
                //获取Guid
                if (Request.QueryString["VerifyCode"] != null)
                {
                    try
                    {
                        //这里有可能出错所以要用try...catch
                        Guid userVerifyCode = new Guid(Request.QueryString["VerifyCode"]);
                        if (UserOpr.CheckUser(loggedUser, userVerifyCode))
                        {
                            //验证通过
                            lblCheckStatus.Text    = "恭喜您,验证成功";
                            lblCheckStatus.Visible = true;
                        }
                        else
                        {
                            lblCheckStatus.Text    = "验证码不符,请尝试重发确认信";
                            lblCheckStatus.Visible = true;
                        }
                    }
                    catch
                    {
                        lblCheckStatus.Text    = "验证码格式不正确";
                        lblCheckStatus.Visible = true;
                    }
                }
                else
                {
                    lblCheckStatus.Text    = "验证码不可以为空";
                    lblCheckStatus.Visible = true;
                }
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //判断是否已经登录
            User loggedUser = UserOpr.isLogged(Request);

            //未登录
            if (loggedUser == null)
            {
                //登录界面不显示
                loggedDiv.Visible = false;
                //提示信息
                logStatus.Text    = "主人大人,您未登录或已经登录过期哦!3秒后自动转向登录页面哦!请登录了再来调戏人家啦";
                logStatus.Visible = true; //提示信息开启

                //重定向
                HtmlMeta RedirectMeta = new HtmlMeta();                                               //重定向用Meta标签
                RedirectMeta.HttpEquiv = "refresh";                                                   //指定行为为跳转
                RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("LoginPageURL"); //时间为三秒,跳转到首页
                this.Page.Header.Controls.Add(RedirectMeta);
            }
            else //已登录
            {
                if (!Page.IsPostBack)
                {
                    //第一次访问,在这里读取数据减轻服务器压力
                    //读取用户信息
                    nickName.Text        = loggedUser.User_nickname;
                    head.ImageUrl        = loggedUser.User_head.Trim();                //这里不取Domain是为了在以后上传的时候保持一致
                    last_login_time.Text = loggedUser.User_last_login_date.ToString(); //本地日期保持一致
                    last_login_ip.Text   = loggedUser.User_last_login_ip;
                    money.Text           = loggedUser.User_money.ToString();
                    //判断是否激活
                    if (loggedUser.User_isChecked)
                    {
                        isChecked.Text = "已激活";
                    }
                    else
                    {
                        isChecked.Text = "未激活";
                    }
                    //判断是否被删除
                    if (loggedUser.User_isDeleted)
                    {
                        isDeleted.Text = "已被冻结";
                    }
                    else
                    {
                        isDeleted.Text = "未被冻结";
                    }

                    user_introduction.Text = loggedUser.User_introduction; //用户介绍
                }
            }
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //每1分钟才能发一次找回密码请求
            Session.Timeout = 1;
            if (!Page.IsPostBack)
            {
                //第一次访问页面
                ForgetPasswordForm.Visible = true;       //找回密码窗体可见
                ForgetPswInfo.Text         = "请输入注册邮箱:"; //重设提示信息
                ForgetPswInfo.Visible      = true;       //提示信息可见
            }
            else
            {
                //用户提交
                User   forgetUser  = new User();
                String userAccount = Request.Form["UserAccount"].Trim();
                forgetUser.User_account = userAccount;
                //防止email轰炸
                if (Session[forgetUser.User_account] == null)
                {
                    if (UserOpr.GetForgetPassword(forgetUser))
                    {
                        //成功取回密码
                        ForgetPswInfo.Text = "取回密码成功!请进入您的注册邮箱查收密码,3秒后跳转到主页";
                        //重定向
                        HtmlMeta RedirectMeta = new HtmlMeta();                                         //重定向用Meta标签
                        RedirectMeta.HttpEquiv = "refresh";                                             //指定行为为跳转
                        RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("Domain"); //时间为三秒,跳转到首页
                        this.Page.Header.Controls.Add(RedirectMeta);

                        //分配Session避免邮箱轰炸
                        Session.Add(forgetUser.User_account, DateTime.Now.ToString());

                        //UI操作
                        ForgetPasswordForm.Visible = false; //取回密码窗体不可见
                        ForgetPswInfo.Visible      = true;
                    }
                    else
                    {
                        ForgetPswInfo.Text         = "取回密码失败,请检查输入的账户是否正确";
                        ForgetPasswordForm.Visible = true;
                        ForgetPswInfo.Visible      = true;
                    }
                }
                else
                {
                    //给出误导信息,实际上一分钟就行,防止黑客利用
                    ForgetPswInfo.Text         = "您的操作过于频繁,请3分钟后再试";
                    ForgetPasswordForm.Visible = true;
                    ForgetPswInfo.Visible      = true;
                }
            }
        }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin loginAdmin = AdminOpr.isLogged(Request);

            if (loginAdmin == null)
            {
                //未登录
                lblLoginStatus.Text     = "您未登录或已经登录过期,请重新登录,3秒后转回管理员登录页。";
                lblLoginStatus.Visible  = true;
                AdminLoggedForm.Visible = false;
                //重定向
                HtmlMeta RedirectMeta = new HtmlMeta();            //重定向用Meta标签
                RedirectMeta.HttpEquiv = "refresh";                //指定行为为跳转
                RedirectMeta.Content   = "3;url=admin_login.aspx"; //时间为三秒,跳转到首页
                this.Page.Header.Controls.Add(RedirectMeta);
            }
            else
            {
                //已经登录
                if (!Page.IsPostBack)
                {
                    //未点击登出按钮
                    lblAdminInfo.Text = "尊敬的管理员:" + loginAdmin.User_nickname + "您好";
                    lblShortInfo.Text =
                        "您最后一次登录时间是" + loginAdmin.User_last_login_date.ToString()
                        + ",最后一次登录IP为" + loginAdmin.User_last_login_ip;
                    lblAdminInfo.Visible    = true;
                    AdminLoggedForm.Visible = true;
                    lblLoginStatus.Visible  = false;
                }
                else
                {
                    //点击登出
                    //删除admin cookie
                    HttpCookie userAccountCookie = new HttpCookie("adminAccount");
                    userAccountCookie.Expires = DateTime.Now.AddDays(-1D);
                    Response.Cookies.Add(userAccountCookie);
                    //删除password cookie
                    HttpCookie userPasswordCookie = new HttpCookie("adminPassword");
                    userPasswordCookie.Expires = DateTime.Now.AddDays(-1D);
                    Response.Cookies.Add(userPasswordCookie);
                    //给出提示信息,转回主页
                    lblLoginStatus.Text     = "您已经成功登出,3秒后转回站点主页";
                    AdminLoggedForm.Visible = false;
                    lblLoginStatus.Visible  = true;
                    //重定向
                    HtmlMeta RedirectMeta = new HtmlMeta();                                         //重定向用Meta标签
                    RedirectMeta.HttpEquiv = "refresh";                                             //指定行为为跳转
                    RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("Domain"); //时间为三秒,跳转到首页
                    this.Page.Header.Controls.Add(RedirectMeta);
                }
            }
        }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            User loggedUser = UserOpr.isLogged(Request);

            if (loggedUser == null)
            {
                //未登录
                lblLoginStatus.Text         = "主人大人,您未登录或已经登录过期哦!3秒后自动转向登录页面哦!请登录了再来调戏人家啦";
                lblLoginStatus.Visible      = true; //提示信息开启
                UserStatisticalForm.Visible = false;
                //重定向
                HtmlMeta RedirectMeta = new HtmlMeta();                                               //重定向用Meta标签
                RedirectMeta.HttpEquiv = "refresh";                                                   //指定行为为跳转
                RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("LoginPageURL"); //时间为三秒,跳转到首页
                this.Page.Header.Controls.Add(RedirectMeta);
            }
            else
            {
                //登录后
                //给个值
                UserStatisticalDataSource.SelectParameters["user_id"].DefaultValue = loggedUser.User_id.ToString();
            }
        }
Exemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //第一次打开该页面
                //View处理部分:
                RegResult.Visible = false; //注册结果不可见。
                RegUser.Visible   = true;  //显示注册表单
            }
            else
            {
                //用户填写好了表单,回传到了本页。
                #region Control处理部分
                //获取提交表单的信息,去掉所有前导和滞后空格
                String userAccount  = Request.Form["UserAccount"].Trim();
                String userPassword = Request.Form["UserPassword"];     //密码不用去空格
                if (userPassword.Length < 6 || userPassword.Length > 16)
                {
                    RegResult.Text    = "密码长度应该在6-16位之间,请重新输入";
                    RegResult.Visible = true;
                    return;
                }
                String strUserSex       = Request.Form["UserSex"].Trim();
                String userIntroduction = Request.Form["UserIntroduction"].Trim();
                String userNickname     = Request.Form["UserNickname"].Trim();
                //用户验证码
                String regVerifyCode = Request.Form["RegVerifyCode"].Trim().ToUpper();
                //最后一次登录IP即为注册IP.
                String userLastLoginIp = HttpContext.Current.Request.UserHostAddress;

                //转换为布尔型,注意用户性别1为男0为女
                Boolean userSex = strUserSex.ToUpper().Trim().Equals("MALE");

                //密码MD5加密
                userPassword = UserOpr.MD5(userPassword);
                //测试用语句

                /* RegResult.Text =
                 *  "注册信息为:" + "账号" + userAccount + "密码" + userPassword + "性别" + strUserSex +
                 *  "密码" + userPassword + "昵称" + userNickname + "最后登录ip" + userLastLoginIp + "个人说明" + userIntroduction;
                 */
                if (     //验证码判定
                    Session[RegVerifyCodeGenerator.strIdentify] != null &&
                    regVerifyCode.ToUpper().Equals
                        (Session[RegVerifyCodeGenerator.strIdentify].ToString().ToUpper()) &&
                    !regVerifyCode.Equals("") &&
                    regVerifyCode != null
                    )
                {
                    //验证码正确,这里记得刷新验证码以防后退提交!
                    Session.Remove(RegVerifyCodeGenerator.strIdentify);     //防止后退提交
                    #region 用户注册,与UserOpr打交道
                    //开始注册用户,数据完整性检查在BLL.UserOpr类中
                    String user_head = "img/01.jpg"; //男生默认头像
                    if (userSex == false)            //是女生
                    {
                        user_head = "img/00.jpg";    //女生默认头像
                    }
                    User newUser = new User(userAccount, userPassword, userNickname, userSex, userLastLoginIp, user_head.Trim());
                    newUser.User_introduction = userIntroduction;

                    if (UserOpr.CreateUser(newUser) > 0)
                    {
                        RegResult.Text  = "注册成功!请到您的邮箱" + userAccount + "中打开确认信完成激活,3秒钟之后自动跳转回主页";
                        RegUser.Visible = false;                                                        //注册表单不可见
                        HtmlMeta RedirectMeta = new HtmlMeta();                                         //重定向用Meta标签
                        RedirectMeta.HttpEquiv = "refresh";                                             //指定行为为跳转
                        RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("Domain"); //时间为三秒,跳转到首页
                        this.Page.Header.Controls.Add(RedirectMeta);
                    }
                    else
                    {
                        RegResult.Text = "注册失败!请检查输入项!";

                        RegUser.Visible = true;     //注册表单可见
                    }
                    #endregion
                }
                else                             //验证码输入不正确
                {
                    RegResult.Text  = "验证码验证出错"; //提示状态
                    RegUser.Visible = true;      //注册表单可见
                }

                #endregion
                #region 通用View处理部分
                RegResult.Visible = true;   //提示状态
                UserPassword.Text = "";     //清空密码框
                #endregion
            }
        }
Exemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //第一次访问
                LoginForm.Visible = true;
            }
            else
            {
                //提交回来了,校验。
                String userAccount     = Request.Form["UserAccount"].Trim();
                String userPassword    = Request.Form["UserPassword"];
                String loginVerifyCode = Request.Form["LoginVerifyCode"];

                //先校验验证码
                if (
                    Session[LoginVerifyCodeGenerator.strIdentify] != null &&
                    Session[LoginVerifyCodeGenerator.strIdentify].ToString().ToUpper().Equals
                        (loginVerifyCode.ToUpper()) &&
                    !loginVerifyCode.Equals("") &&
                    loginVerifyCode != null
                    //以上三行防止后退提交用的
                    )
                {
                    Session.Remove(LoginVerifyCodeGenerator.strIdentify); //防止后退提交
                    //验证码校验通过,设定要取回的User的账号密码
                    User verifyUser = new User();
                    verifyUser.User_account  = userAccount;
                    verifyUser.User_password = UserOpr.MD5(userPassword);
                    //验证用户是否是合法登录请求
                    User entireUser = UserOpr.isLegalLogin(verifyUser);
                    if (entireUser == null) //账号或密码错误,未注册,都是这个
                    {
                        LoginInfo.Text    = "账号或密码错误";
                        LoginForm.Visible = true;
                    }
                    else
                    {
                        //登录成功,更改提示信息,更新登录信息中的IP和日期,这里记得换成UpdateUserInfo!

                        entireUser.User_last_login_date = DateTime.Now;                                //获取当前登录日期
                        entireUser.User_last_login_ip   = HttpContext.Current.Request.UserHostAddress; //最后一次登录ip
                        UserOpr.UpdateUserInfo(entireUser);
                        LoginInfo.Text = "登录成功!3秒后跳转回主页";
                        //授予Cookies,相当于授权了

                        HttpCookie userAccountCookie  = new HttpCookie("userAccount");
                        HttpCookie userPasswordCookie = new HttpCookie("userPassword");
                        userAccountCookie.Value  = verifyUser.User_account;
                        userPasswordCookie.Value = verifyUser.User_password;

                        if (RememberMe.Checked) //这个判断很诡异,貌似Request.Form不好用的样子。
                        {
                            //如果选了RememberMe就保留一个星期
                            userPasswordCookie.Expires = DateTime.Now.AddDays(7D);
                            userAccountCookie.Expires  = DateTime.Now.AddDays(7D);
                        }
                        else
                        {
                            //否则只保存1天
                            userPasswordCookie.Expires = DateTime.Now.AddDays(1D);
                            userAccountCookie.Expires  = DateTime.Now.AddDays(1D);
                        }
                        //添加Cookie,相当于授权
                        Response.Cookies.Add(userAccountCookie);
                        Response.Cookies.Add(userPasswordCookie);
                        //重定向
                        HtmlMeta RedirectMeta = new HtmlMeta();                                         //重定向用Meta标签
                        RedirectMeta.HttpEquiv = "refresh";                                             //指定行为为跳转
                        RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("Domain"); //时间为三秒,跳转到首页
                        this.Page.Header.Controls.Add(RedirectMeta);
                        //UI操作
                        LoginForm.Visible = false;
                    }
                }
                else
                {
                    //验证码校验失败
                    LoginInfo.Text    = "验证码输入错误,请检查";
                    LoginForm.Visible = true;
                }
            }
        }
Exemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //判断是否已经登录,注意,由于这里不管是不是postBack,因此取到的对象,timeStamp一定是最新的那个!
            //换而言之,我们的策略就是LastComesWin——最新的一次提交总是屌的!
            User loggedUser = UserOpr.isLogged(Request);

            //未登录
            if (loggedUser == null)
            {
                //登录界面不显示
                loggedDiv.Visible = false;
                //提示信息
                logStatus.Text    = "主人大人,您未登录或已经登录过期哦!3秒后自动转向登录页面哦!请登录了再来调戏人家啦";
                logStatus.Visible = true; //提示信息开启

                //重定向
                HtmlMeta RedirectMeta = new HtmlMeta();                                               //重定向用Meta标签
                RedirectMeta.HttpEquiv = "refresh";                                                   //指定行为为跳转
                RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("LoginPageURL"); //时间为三秒,跳转到首页
                this.Page.Header.Controls.Add(RedirectMeta);
            }
            else //已登录
            {
                //显示登录界面
                loggedDiv.Visible = true;
                //提示信息隐藏
                logStatus.Visible = false;

                if (!Page.IsPostBack)
                {
                    //用户未提交修改信息

                    //设置页面中对应的用户信息
                    //账户
                    txtUserAccount.Text = loggedUser.User_account;
                    //余额
                    lblMoney.Text = lblMoney.Text + loggedUser.User_money.ToString();
                    //头像,记得去空格
                    imgHead.ImageUrl = loggedUser.User_head.Trim();
                    //简介,记得去空格
                    txtUserIntroduction.Text = loggedUser.User_introduction.Trim();
                    //昵称。记得去空格
                    txtUserNickname.Text = loggedUser.User_nickname.Trim();
                    if (loggedUser.User_sex) //男生
                    {
                        UserSex.Items[0].Selected = true;
                        UserSex.Items[1].Selected = false;
                    }
                    else
                    {
                        UserSex.Items[0].Selected = false;
                        UserSex.Items[1].Selected = true; //女生
                    }
                }
                else
                {
                    //用户提交修改信息,验证的时候注意,从loggedUser里取账号和旧密码,旧密码和输入比对,账号直接带入操作
                    String oldPassword       = Request.Form["txtUserOldPassword"];
                    String newPassword       = Request.Form["txtUserNewPassword"];
                    String verifyNewPassword = Request.Form["txtUserVerifyNewPassword"];
                    String userIntroduction  = Request.Form["txtUserIntroduction"].Trim();
                    String userNickname      = Request.Form["txtUserNickName"].Trim(); //记得去空格
                    //头像!这里用完记得立刻释放掉Cookie
                    String userHead = Request.Cookies["userHead"].Value;

                    //转换为布尔型,注意用户性别1为男0为女
                    String  strUserSex = Request.Form["UserSex"].Trim();
                    Boolean userSex    = strUserSex.ToUpper().Trim().Equals("MALE");

                    User newInfoUser = new User(loggedUser);
                    #region 验证是否需要修改密码
                    if (!oldPassword.Equals("") &&
                        oldPassword != null)
                    //填写了旧密码,意味着要修改密码
                    {
                        if (!newPassword.Equals(verifyNewPassword)) //新密码与确认密码不匹配
                        {
                            lblChangePasswordStatus.Text    = "新密码与确认密码不匹配,请检查后再输入";
                            lblChangePasswordStatus.Visible = true;
                            return; //停止提交
                        }
                        else
                        {
                            if (!UserOpr.MD5(oldPassword).Equals(loggedUser.User_password))
                            {
                                //旧密码与账号密码不匹配
                                lblChangePasswordStatus.Text    = "旧密码输入错误,请重新输入";
                                lblChangePasswordStatus.Visible = true;
                                return; //停止提交
                            }
                            else
                            {
                                //旧密码与账号密码匹配,且新密码与确认密码匹配的情况下
                                if (newPassword.Length > 16 ||
                                    newPassword.Length < 6)
                                {
                                    //新密码长度不对
                                    lblChangePasswordStatus.Text    = "新密码长度不正确,请重新提交";
                                    lblChangePasswordStatus.Visible = true;
                                    return; //停止提交
                                }
                                else
                                {
                                    //修改后一并提交
                                    newInfoUser.User_password = UserOpr.MD5(newPassword);

                                    /*
                                     * //修改用户密码
                                     * if (UserOpr.ChagneUserPassword(newInfoUser, UserOpr.MD5(newPassword)))
                                     * {
                                     *  //更改成功
                                     *  lblChangePasswordStatus.Text = "修改密码成功,请重新登录";
                                     *  lblChangePasswordStatus.Visible = true;
                                     *  return;//停止提交
                                     * }
                                     * else
                                     * {
                                     *  //更改失败
                                     *  lblChangePasswordStatus.Text = "修改密码失败,请检查输入是否正确";
                                     *  lblChangePasswordStatus.Visible = true;
                                     *  return; //停止提交
                                     * }
                                     * */
                                }
                            }
                        }
                    }
                    #endregion

                    #region 修改用户信息,这里不用加验证,userOpr里有

                    newInfoUser.User_introduction = userIntroduction;
                    newInfoUser.User_nickname     = userNickname;
                    if (userHead != null)
                    {
                        newInfoUser.User_head = userHead; //这里注意看一下是相对路径还是绝对路径
                        //释放Cookie
                        HttpCookie userHeadCookie = new HttpCookie("userHead");
                        userHeadCookie.Expires = DateTime.Now.AddDays(-1D);
                        Response.Cookies.Add(userHeadCookie);
                    }

                    newInfoUser.User_sex = userSex;
                    #endregion


                    //开始调用BLL
                    if (UserOpr.UpdateUserInfo(newInfoUser))
                    {
                        //修改成功
                        logStatus.Text    = "资料修改成功了哦,3秒后回到用户主页哦";
                        logStatus.Visible = true;
                        loggedDiv.Visible = false;
                        //重定向
                        HtmlMeta RedirectMeta = new HtmlMeta();           //重定向用Meta标签
                        RedirectMeta.HttpEquiv = "refresh";               //指定行为为跳转
                        RedirectMeta.Content   = "3;url=user_index.aspx"; //时间为三秒,跳转到首页
                        this.Page.Header.Controls.Add(RedirectMeta);
                    }
                    else
                    {
                        //修改失败,给出提示信息
                        logStatus.Text    = "修改资料失败了呢,真是抱歉,是不是主人大人什么地方填错了呢?";
                        logStatus.Visible = true;
                    }
                }
            }
        }
Exemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            User loggedUser = UserOpr.isLogged(Request);

            if (loggedUser == null) //如果未登录
            {
                BuyCourseForm.Visible = false;
                lblLoginStatus.Text   = "您未登录或已登录过期,请登录后再进行召唤。3秒后跳转到用户登录界面";
                //重定向
                HtmlMeta RedirectMeta = new HtmlMeta();                                               //重定向用Meta标签
                RedirectMeta.HttpEquiv = "refresh";                                                   //指定行为为跳转
                RedirectMeta.Content   = "3;url=" + ReadWebConfig.GetAppSettingValue("LoginPageURL"); //时间为三秒,跳转到首页
                this.Page.Header.Controls.Add(RedirectMeta);
            }
            else
            {
                if (loggedUser.User_isChecked == false ||
                    loggedUser.User_isDeleted == true
                    )
                {
                    BuyCourseForm.Visible = false;
                    lblLoginStatus.Text   = "您的账户未激活或已被删除,无法购买";
                }
                else
                {
                    //已经登录
                    if (!Page.IsPostBack)
                    {
                        //如果页面不是提交回来的
                        try
                        {
                            //这句可能有错
                            Guid   courseID    = new Guid(Request.QueryString["course_id"]);
                            Course toBuyCourse = new Course();
                            toBuyCourse.Course_id = courseID;
                            Course entireCourse = CourseOpr.GetCourseByID(toBuyCourse);
                            if (entireCourse != null)
                            {
                                //如果找到了课程
                                lblCourseName.Text  = "要购买的课程为:" + entireCourse.Course_name;
                                lblCoursePrice.Text = "单价为:" + entireCourse.Course_price.ToString() + "令咒每日";
                                lblUserMoney.Text   = "您当前余额为:" + loggedUser.User_money + "令咒";
                            }
                            else
                            {
                                lblCourseStateus.Text    = "课程不存在";
                                lblCourseStateus.Visible = true;
                                BuyCourseForm.Visible    = false;
                            }
                        }
                        catch
                        {
                            lblCourseStateus.Text    = "课程ID错误";
                            lblCourseStateus.Visible = true;
                            BuyCourseForm.Visible    = false;
                        }
                    }
                    else
                    {
                        //用户选择进行购买
                        try
                        {
                            Guid   courseID    = new Guid(Request.QueryString["course_id"]);
                            Course toBuyCourse = new Course();
                            toBuyCourse.Course_id = courseID;
                            Course entireCourse = CourseOpr.GetCourseByID(toBuyCourse);
                            if (entireCourse != null)
                            {
                                //找到了课程
                                //好,这里Course和User全有了,我们就要Create一个Order了!
                                Order newOrder = OrderOpr.CreateOrderByUserAndCourse(entireCourse, loggedUser);
                                //这句话转换可能出错
                                int toBuyDays = Convert.ToInt32(Request.Form[txtCourseTime.ID]);
                                if (toBuyDays < 0)
                                {
                                    lblCourseStateus.Text    = "购买天数不能小于0";
                                    lblCourseStateus.Visible = true;
                                }
                                else
                                {
                                    if (newOrder != null)
                                    {
                                        //这个newOrder里面只包含了course_id和user_id因此我们需要手动填充
                                        newOrder.Order_price     = toBuyDays * entireCourse.Course_price;
                                        newOrder.Order_isDeleted = false;
                                        //因为存储过程里是直接扣钱的,所以这里默认付款
                                        newOrder.Order_isPaid = true;
                                        newOrder.Order_date   = DateTime.Now;
                                        if (newOrder.Order_price <= loggedUser.User_money &&
                                            OrderOpr.CreateOrder(newOrder)
                                            )
                                        {
                                            lblCourseStateus.Text    = "恭喜!召唤女友成功,快去后宫里面转转吧~";
                                            lblCourseStateus.Visible = true;
                                        }
                                        else
                                        {
                                            lblCourseStateus.Text    = "创建订单出错,可能是您余额不足导致的,请确保令咒充足后重试";
                                            lblCourseStateus.Visible = true;
                                        }
                                    }
                                    else
                                    {
                                        lblCourseStateus.Text    = "创建订单出错,请稍后再试";
                                        lblCourseStateus.Visible = true;
                                    }
                                }
                            }
                            else
                            {
                                lblCourseStateus.Text    = "所购买的课程不存在";
                                lblCourseStateus.Visible = true;
                            }
                        }
                        catch
                        {
                            BuyCourseForm.Visible    = false;
                            lblCourseStateus.Text    = "课程ID不正确";
                            lblCourseStateus.Visible = true;
                        }
                    }
                }
            }
        }