Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //spnAdmin.InnerHtml = common.projectAdmin;
        try
        {
            if (Session["userid"] != null)
            {
                string         UserID = Session["userid"].ToString();
                SqlConnection  con    = new SqlConnection(ConfigurationManager.ConnectionStrings["cnstring"].ConnectionString);
                string         s      = "select username,password from AdminLogin where AdminID=" + UserID + "";
                DataTable      dt     = new DataTable();
                SqlDataAdapter da     = new SqlDataAdapter(s, con);
                da.Fill(dt);
                string Username = "", pass = "";
                if (dt.Rows[0][0].ToString() != "")
                {
                    Username = dt.Rows[0]["username"].ToString();
                    pass     = dt.Rows[0]["password"].ToString();
                }
                Cls_userregistration_b obj = new Cls_userregistration_b();
                Int64 Result = obj.WebsiteUser_Status(Username, pass, false);
            }
        }
        catch { }
        finally { }

        Response.Redirect(Page.ResolveUrl("~/Default.aspx?logout=yes"));
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cnstring"].ConnectionString);

        try
        {
            string query = string.Empty;
            if (txtUserName.Text != string.Empty && txtPassword.Text != string.Empty)
            {
                query = "select * from AdminLogin where isdelete=0 and lower(username)=lower('" + txtUserName.Text.Trim() + "') and password='******'";
                SqlCommand     cmd    = new SqlCommand(query);
                SqlDataAdapter sda    = new SqlDataAdapter();
                DataTable      dtUser = new DataTable();
                con.Open();
                cmd.Connection    = con;
                sda.SelectCommand = cmd;
                sda.Fill(dtUser);
                if (dtUser != null)
                {
                    if (dtUser.Rows.Count > 0)
                    {
                        Cls_userregistration_b obj = new Cls_userregistration_b();
                        Int64 Result = obj.WebsiteUser_Status(txtUserName.Text, txtPassword.Text, true);


                        Session.Timeout     = 120;
                        Session["userid"]   = Convert.ToString(dtUser.Rows[0]["adminid"]);
                        Session["usertype"] = Convert.ToString(dtUser.Rows[0]["usertype"]);
                        Session["nameuser"] = Convert.ToString(dtUser.Rows[0]["name"]);
                        Session["usermail"] = Convert.ToString(dtUser.Rows[0]["email"]);
                        //                        Response.Redirect(Page.ResolveUrl("~/dashboard.aspx"));
                        Response.Redirect("dashboard.aspx");
                    }
                    else
                    {
                        bMsg.InnerText = "Please enter correct user name & password !!!";
                        Clear();
                    }
                }
                else
                {
                    bMsg.InnerText = "Please enter correct user name & password !!!";
                    Clear();
                }
            }
            else
            {
                bMsg.InnerText = "Please enter user name & password !!!";
            }
        }
        catch (Exception p)
        { }
        finally { con.Close(); }
    }