Beispiel #1
0
        private void btnlogin_Click(object sender, EventArgs e)
        {
            if (txtusername.Text == string.Empty)
            {
                ErrorCheckTextBox.SetError(txtusername, "username field is required!!");
            }
            else if (txtpassword.Text == String.Empty)
            {
                ErrorCheckTextBox.SetError(txtpassword, "password field is required!!");
            }
            else
            {
                try
                {
                    con = new SqlConnection();
                    con.ConnectionString = strcon;

                    var qry = "select * from staff_details where username ='******' and password = '******'";
                    var cmd = new SqlCommand(qry, con);
                    con.Open();

                    var dr = cmd.ExecuteReader();

                    if (dr.HasRows)
                    {
                        GlobalUname.GlobalVar = txtusername.Text;
                        while (dr.Read())
                        {
                            GetLoginData(dr);
                            txtusername.Text = string.Empty;
                            txtpassword.Text = string.Empty;
                        }
                    }
                    else
                    {
                        lblErrorMessage.Text    = @"Wrong username or Password!!";
                        lblErrorMessage.Visible = true;
                    }
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUsername.Text == String.Empty)
            {
                ErrorCheckTextBox.SetError(txtUsername, "username field is required!!");
            }
            else if (txtPassword.Text == String.Empty)
            {
                ErrorCheckTextBox.SetError(txtPassword, "password field is required!!");
            }
            else
            {
                try
                {
                    var strcon = ConfigurationManager.ConnectionStrings["HMSConStr"].ToString();
                    var con    = new SqlConnection();
                    con.ConnectionString = strcon;

                    var qry = "select * from LoginTB where Username ='******' and Password = '******'";
                    var cmd = new SqlCommand(qry, con);
                    con.Open();

                    var dr = cmd.ExecuteReader();

                    if (dr.HasRows)
                    {
                        GlobalUname.GlobalVar = txtUsername.Text;
                        while (dr.Read())
                        {
                            ReadLogData(dr);
                        }
                    }
                    else
                    {
                        lblErrorLoginFailed.Text    = "Wrong username or Password!!";
                        lblErrorLoginFailed.Visible = true;
                    }
                    con.Close();
                }
                catch (Exception ex)
                {
                    lblError.Text    = ex.Message;
                    lblError.Visible = true;
                }
            }
        }