示例#1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //if(FormsAuthentication.Authenticate(UserName.Text,UserPass.Text))
            //{
            //    FormsAuthentication.RedirectFromLoginPage(UserName.Text,chkboxPersist.Checked);
            //}
            //else
            //{
            //    Msg.Text = "Invalid User Name and/or Password";
            //}
            //Msg.Visible = true;

            if (DropDownList1.Text == "Trainer")
            {
                LoginCheck login    = new LoginCheck();
                string     username = UserName.Text;
                string     password = UserPass.Text;
                int        value    = login.logincheckuserid(username, password);
                if (value == 1)
                {
                    Session["adminlogin"] = username;
                    Response.Redirect("TrainerHome.aspx");
                }
                else
                {
                    Msg.Visible = true;
                    Msg.Text    = "Invalid username/password";
                }
            }
            else if (DropDownList1.Text == "SME")
            {
                LoginCheck login    = new LoginCheck();
                string     username = UserName.Text;
                string     password = UserPass.Text;
                int        value    = login.smecheckuserid(username, password);
                if (value == 1)
                {
                    Session["adminlogin"] = username;
                    Response.Redirect("SmeHome.aspx");
                }
                else
                {
                    Msg.Visible = true;
                    Msg.Text    = "Invalid username/password";
                }
            }
            else if (DropDownList1.Text == "Requestor")
            {
                LoginCheck login    = new LoginCheck();
                string     username = UserName.Text;
                string     password = UserPass.Text;
                int        value    = login.requestorcheckuserid(username, password);
                if (value == 1)
                {
                    Session["adminlogin"] = username;
                    Response.Redirect("RequestorHome.aspx");
                }
                else
                {
                    Msg.Visible = true;
                    Msg.Text    = "Invalid username/password";
                }
            }
            else if (DropDownList1.Text == "Admin")
            {
                LoginCheck login    = new LoginCheck();
                string     username = UserName.Text;
                string     password = UserPass.Text;
                Admin      ad       = new Admin();
                //ad.admindetails()
                int value = login.admincheckuserid(username, password);
                if (value == 1)
                {
                    Session["adminlogin"] = username;
                    Response.Redirect("Admin1.aspx");
                }
                else
                {
                    Msg.Visible = true;
                    Msg.Text    = "Inavlid username/password";
                }
            }
            else
            {
                Msg.Visible = true;
                Msg.Text    = "Select Usertype";
            }
            //if (chkboxPersist.Checked)
            //{
            //    Response.Cookies["UserId"].Expires = DateTime.Now.AddDays(30);
            //    Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30);
            //}
            //else
            //{
            //    Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
            //    Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);

            //}
            Response.Cookies["UserName"].Value = UserName.Text.Trim();
            Response.Cookies["Password"].Value = UserPass.Text.Trim();
        }