private void new_ID() { try { SqlConnection con = new SqlConnection(cls.setConnectionString()); con.Open(); SqlCommand cmddr = new SqlCommand("select max(Leave_Id) as ids from Leave_Details", con); SqlDataReader dr = cmddr.ExecuteReader(); while (dr.Read()) { string strid = dr["ids"].ToString(); if (strid == "") { txtleaveid.Text = "L00001"; } else { strid = txtleaveid.Text; string current = dr["ids"].ToString();// txtattid.Text; string next = GetNextValue(current); txtleaveid.Text = GetNextValue(current); } } dr.Close(); con.Close(); cmddr.Dispose(); } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private void btnlogin_Click(object sender, EventArgs e) { string query = "SELECT Username, Password FROM Login WHERE Username = @Username"; using (SqlConnection conn = new SqlConnection(cls.setConnectionString())) { using (SqlCommand cmd = new SqlCommand(query, conn)) { //add a parameter to sql query cmd.Parameters.AddWithValue("Username", txtuname.Text); conn.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { //read the first row that reader returned and save password from DB into variable reader.Read(); string username = reader["Username"].ToString(); string password = reader["Password"].ToString(); //string priviledgeLevel = reader["PriviledgeLvl"].ToString(); // string prv; if (reader.Read() == true) { return; } else if (txtpwrd.Text == password) { this.Visible = false; MainMenu main = new MainMenu(); main.ShowDialog(); } else if (txtuname.Text != username || txtpwrd.Text != password) { MessageBox.Show("Password not Valid, Please TryAgain", "User Login", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Invalid Access Please TryAgain", "UserLogin", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }