using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
     
  
    
    }


    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string userName = this.userTxt.Text;
        string userPwd = this.pwdTxt.Text;
        string code = this.codeTxt.Text.ToLower();
        string getCode = Request.Cookies["CheckCode"].Value.ToLower();
        if (getCode == null)
        {
            this.cusVal.ErrorMessage = "你的浏览器不支持cookie，请设置你的浏览器支持cookie!";
            args.IsValid=false;
        }
        else
        {
            if (getCode == code)
            {
                string getLevel = BLL.check.checkUser(userName, userPwd);
                switch (getLevel)
                {
                    case "0":
                        this.cusVal.ErrorMessage = "用户名或密码错误！";
                        args.IsValid = false;
                        break;
                    case "1":
                        args.IsValid = true;
                        Session["user"] = args.Value;
                        Response.Redirect("~/Employees/Employee.aspx");
                        break;
                    case "2":
                        args.IsValid = true;
                        Session["user"] = args.Value;
                        Response.Redirect("~/Managers/Manager.aspx");
                        break;
                    case "3":
                        args.IsValid = true;
                        Session["user"] = args.Value;
                        Response.Redirect("~/BOSS/BOSS.aspx");
                        break;
                    default:
                        break;
                }
               

            }
            else {
                this.cusVal.ErrorMessage = "验证码不正确，请重新输入！";
                args.IsValid = false;
                this.codeTxt.Text = "";
            }

        }

    }
}
