private void BtnLogin_Click(object sender, EventArgs e) { if (txtName.Text == "") { MessageBox.Show("Name cannot be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } else if (txtPassword.Text == "") { MessageBox.Show("Password cannot be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } else { try { SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\Pbs\\source\\repos\\CorporateCoders\\CorporateCoders\\Database1.mdf;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand("select *from [Admin] where Name = @name COLLATE SQL_Latin1_General_CP1_CS_AS and Password = @password COLLATE SQL_Latin1_General_CP1_CS_AS", con); cmd.Parameters.AddWithValue("@name", txtName.Text.ToString()); cmd.Parameters.AddWithValue("@password", txtPassword.Text.ToString()); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { con.Close(); uname = txtName.Text.ToString(); psd = txtPassword.Text.ToString(); Form10 form = new Form10(this); form.Show(); } else { MessageBox.Show("Invalid Admin Name or Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } con.Close(); } catch (Exception ex) { MessageBox.Show("UNFORTUNATELY STOPPED!\nAN UNEXPECTED ERROR OCCURED DURING LOGIN.", "PLEASE TRY AGAIN", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } } }
private void BtnHome_Click(object sender, EventArgs e) { f10.Show(); this.Close(); }
private void BtnHome_Click(object sender, EventArgs e) { this.Close(); userAttendance.Close(); f10.Show(); }