using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.SqlTypes; namespace Gateway_Security_System_and_Logs { public partial class bsl_login : Form { public bsl_login() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { textBox2.Clear(); textBox1.Focus(); } private void button1_Click(object sender, EventArgs e) { string userName = textBox1.Text; string Pass = textBox2.Text; if (userName == "" && Pass == "") { MessageBox.Show("Please Enter Login Id and Password"); } else { SqlConnection con = new SqlConnection(@"server=.\SQLEXPRESS ; database=bsl_login; Trusted_Connection=yes"); string query = "userlogin"; //stored Procedure Name SqlCommand com = new SqlCommand(query, con); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@Usename", userName); com.Parameters.AddWithValue("@Pass", Pass); con.Open(); int usercount = (Int32)com.ExecuteScalar(); if (usercount == 1) //if user credential is matched then Usercount value is 1 otherwise it is 0 { this.Hide(); //hiding form 1 bsl_user M1 = new bsl_user();//passing user Name to Second form so we can user Logged user Name M1.Show(); } else { bsl_login Lg = new bsl_login(); Lg.Show(); MessageBox.Show("LoginId or Password Is wrong"); //if user Name is not available in database } } } private void bsl_login_Load(object sender, EventArgs e) { } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { this.Hide(); bsl_admin ad1 = new bsl_admin(); ad1.Show(); } } } |