Example #1
0
        protected void btnCusLogin_Click(object sender, EventArgs e)
        {
            int intErr = 0;
            LoginDetails objLogDetails = new LoginDetails();
            objLogDetails.UserName = txtCUsername.Value.ToString();
            objLogDetails.UserPassword = txtCUserpassword.Value.ToString();

            //if (Request.Form["rdoLogType"] != null)
            //    sType = Request.Form["rdoLogType"].ToString();
            //else
            if (txtCUsername.Value.ToString().ToLower() == "admin")
                sType = "3";
            else
                sType = "1";
            try
            {
                //if (Request.Form["rdoLogType"] == null && txtCUsername.Value.ToString().ToLower() != "admin")
                //{
                //    intErr = 1;
                //    divCusErrMsg.InnerText = "Please Select Login type.";
                //    divCusErrMsg.Visible = true;
                //}
                //else
                {
                    int intLogId = 0;
                    ServeAtDoorstepService objService = new ServeAtDoorstepService();
                    if (sType == "1")
                        intLogId = objService.LoginCustomer(objLogDetails);
                    if (sType == "2")
                        intLogId = objService.LoginVendor(objLogDetails);
                    if (sType == "3")
                        intLogId = objService.LoginAdmin(objLogDetails);

                    if (string.IsNullOrEmpty(intLogId.ToString().Trim()))
                    {
                        intErr = 1;
                        divCusErrMsg.InnerText = "Invalid Loginname and Password! Please try again.";
                        divCusErrMsg.Visible = true;
                    }
                    else
                    {
                        Session.Abandon();
                        Session.RemoveAll();

                        Session.Add("LoginId", intLogId.ToString());
                        Session.Add("LoginType", sType);
                        HttpCookie cLoginId = new HttpCookie("LoginId", intLogId.ToString().Trim());
                        HttpCookie cLoginType = new HttpCookie("LoginType", sType);
                        cLoginId.Expires = DateTime.Now.AddDays(5);
                        cLoginType.Expires = DateTime.Now.AddDays(5);

                        Response.Cookies.Add(cLoginId);
                        Response.Cookies.Add(cLoginType);

                        if (chkCusAgree.Checked == true)
                        {
                            HttpCookie cLoginName = new HttpCookie("LoginName", txtCUsername.Value.ToString().Trim());
                            HttpCookie cPassword = new HttpCookie("Password", txtCUserpassword.Value.ToString().Trim());
                            cLoginName.Expires = DateTime.Now.AddDays(5);
                            cPassword.Expires = DateTime.Now.AddDays(5);

                            Response.Cookies.Add(cLoginName);
                            Response.Cookies.Add(cPassword);
                        }
                    }
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                divCusErrMsg.InnerText = ex.Message.ToString();
                intErr = 1;
            }

            if (intErr == 0 && Session["LoginType"].ToString() == "1")
                Response.Redirect("MyCustomerDash.aspx");
            else if (intErr == 0 && Session["LoginType"].ToString() == "2")
                Response.Redirect("MyVendorDash.aspx");
            else if (intErr == 0 && Session["LoginType"].ToString() == "3")
                Response.Redirect("MyAdminDash.aspx");
        }