private void button1_Click(object sender, EventArgs e)
        {
            string userName = textUserName.Text.Trim();
            string pass     = textUserPass.Text.Trim();

            if (userName == "" || pass == "")
            {
                MessageBox.Show("登录名或密码不能为空!", "错误提示");
                textUserName.Focus();
                return;
            }
            else
            {
                BLL.Admin bll = new BLL.Admin();
                if (bll.Login(userName, pass))//登录成功
                {
                    AdminHelper.name  = textUserName.Text.Trim();
                    AdminHelper.pass  = textUserPass.Text.Trim();
                    textUserName.Text = "";
                    textUserPass.Text = "";
                    this.Hide();
                    FormMain f = new FormMain();
                    f.Show();
                }
                else
                {
                    MessageBox.Show("用户名或密码错误,请重新输入!", "错误提示");
                    textUserName.Text = "";
                    textUserPass.Text = "";
                    textUserName.Focus();
                }
            }
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string json = "{'info':'登录失败','ID':-1}";

            //获取GET方法传递参数:Request.QueryString["参数名称"];
            //获取POST方法传递参数:Request.Form["参数名称"];
            string txtUserName = context.Request.Form["UserName"]; //保存文本框对象,提高效率
            string txtPassWord = context.Request.Form["PassWord"];

            BLL.Admin bll     = new BLL.Admin();
            int       n       = bll.Login(txtUserName, txtPassWord);
            int       ifadmin = bll.IfAdmin(n);

            //返回单个文字信息
            if (n > 0)
            {
                json = "{'info':'登录成功!','ID':" + n + "}";
                context.Session["ID"]     = n;
                context.Session["Name"]   = txtUserName;
                context.Session["UState"] = ifadmin;
            }
            context.Response.Write(json);
        }