Ejemplo n.º 1
0
        private void btn_login_Click_1(object sender, EventArgs e)
        {
            FinalConString = conString;
            Database_Connection conlast = new Database_Connection();
            string user = textbox_username_login.Text;
            string pass = textbox_pass_login.Text;
            string sq   = @"SELECT Count(*) FROM LoginInfoTable WHERE Username=@NewName AND Password=@NewPass";

            try
            {
                SqlCommand dbCommand = new SqlCommand(sq, FinalCon);
                dbCommand.Parameters.AddWithValue("@NewName", user);
                dbCommand.Parameters.AddWithValue("@NewPass", pass);


                FinalCon.Open();
                SqlDataAdapter sda = new SqlDataAdapter(dbCommand);

                DataTable dt = new DataTable();
                sda.Fill(dt);
                FinalCon.Close();

                if (dt.Rows[0][0].ToString() == "1")
                {
                    FinalCon.Open();
                    sq  = "select * from LoginInfoTable where Username = '******' ";
                    sda = new SqlDataAdapter(sq, FinalCon);

                    dt = new DataTable();
                    sda.Fill(dt);
                    MessageBox.Show(dt.Rows[0][3].ToString());

                    int roleid = Convert.ToInt32(dt.Rows[0][3]);

                    sq  = "select RoleName from RoleTable where Role_ID = " + roleid + " ";
                    sda = new SqlDataAdapter(sq, FinalCon);
                    DataTable dt1 = new DataTable();
                    sda.Fill(dt1);

                    State = dt1.Rows[0][0].ToString();

                    FinalCon.Close();

                    UserName = dt.Rows[0][1].ToString();
                    this.Close();


                    label_Status_Login.ForeColor = Color.Green;
                    label_Status_Login.Text      = "Login Success";
                }
            }
            catch (Exception ex)
            {
                label_Status_Login.ForeColor = Color.Red;
                label_Status_Login.Text      = "Login Failed";
            }
        }
Ejemplo n.º 2
0
        private void btn_login_Click_1(object sender, EventArgs e)
        {
            FinalConString = conString;
            Database_Connection conlast = new Database_Connection();
            string user = textbox_username_login.Text;
            string pass = textbox_pass_login.Text;
            string sq   = @"SELECT * FROM LoginInfoTable WHERE Username=@NewName AND Password=@NewPass";

            try
            {
                SqlCommand dbCommand = new SqlCommand(sq, FinalCon);
                dbCommand.Parameters.AddWithValue("@NewName", user);
                dbCommand.Parameters.AddWithValue("@NewPass", pass);


                // SqlCommand cmd = new SqlCommand("SELECT * FROM LoginInfoTable WHERE Username='******' AND Password='******'", FinalCon);
                FinalCon.Open();
                SqlDataAdapter sda = new SqlDataAdapter(dbCommand);

                DataTable dt = new DataTable();
                sda.Fill(dt);
                FinalCon.Close();

                if (dt.Rows[0][0].ToString() == "1")
                {
                    UserName = dt.Rows[0][1].ToString();
                    //MessageBox.Show("Login Success " + dt.Rows[0][3].ToString());
                    SqlCommand cmd1 = new SqlCommand("SELECT * FROM RoleTable", FinalCon);
                    FinalCon.Open();
                    SqlDataAdapter sda1 = new SqlDataAdapter(cmd1);

                    DataTable dt1 = new DataTable();
                    sda1.Fill(dt1);
                    //MessageBox.Show("Login Success " + dt1.Rows[0][1].ToString());
                    State = dt1.Rows[0][1].ToString();
                    FinalCon.Close();
                    this.Close();


                    label_Status_Login.ForeColor = Color.Green;
                    label_Status_Login.Text      = "Login Success";
                }
            }
            catch (Exception ex)
            {
                label_Status_Login.ForeColor = Color.Red;
                label_Status_Login.Text      = "Login Failed";
            }
        }