private void submitB_Click(object sender, EventArgs e) { MySqlConnection con = Database.dbConnect.Initialize(); con.Open(); if (tnameTB.Text == "" || deptCB.Text == "" || desigCB.Text == "" || usernameTB.Text == "" || passwordTB.Text == "") { MessageBox.Show("Empty field is not allow. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { try { AdminF AdminObj = new AdminF(); try { String selectQuery1 = "select password from master"; MySqlCommand command1 = new MySqlCommand(selectQuery1, con); MySqlDataReader reader1 = command1.ExecuteReader(); reader1.Read(); AdminObj.masterPassword = Convert.ToString(reader1[0]); con.Close(); } catch (Exception exp) { MessageBox.Show("Error in Database." + exp, "Database Error"); } if (mpasswordTB.Text == AdminObj.masterPassword) { con.Open(); String insertQuery = "INSERT into teacher (t_name,department,designation,username,password) values('" + tnameTB.Text + "','" + deptCB.Text + "','" + desigCB.Text + "','" + usernameTB.Text + "','" + passwordTB.Text + "')"; MySqlCommand commandObj = new MySqlCommand(insertQuery, con); commandObj.ExecuteNonQuery(); con.Close(); tnameTB.Text = ""; deptCB.Text = ""; desigCB.Text = ""; usernameTB.Text = ""; passwordTB.Text = ""; mpasswordTB.Text = ""; MessageBox.Show("Id Creation Successful."); } else { mpasswordTB.Text = ""; mpasswordTB.Focus(); errorLabel.Show(); } } catch (Exception exp) { MessageBox.Show("Error: " + exp); } } }
private void logB_Click(object sender, EventArgs e) { MySqlConnection con = Database.dbConnect.Initialize(); if (usernameTB.Text == "" || passwordTB.Text == "") { MessageBox.Show("The username or password you entered is empty.", "Entry Error"); return; } con.Open(); string query = ""; if (adminRB.Checked) { query = "SELECT `username`, `password` FROM `admin` WHERE `username`='" + usernameTB.Text + "' and `password` = '" + passwordTB.Text + "'"; } if (teacherRB.Checked) { query = "SELECT `username`, `password` FROM `teacher` WHERE `username`='" + usernameTB.Text + "' and `password` ='" + passwordTB.Text + "'"; } MySqlCommand cmd = new MySqlCommand(query, con); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { if (adminRB.Checked) { AdminF aa = new AdminF(); Cursor.Current = Cursors.WaitCursor; aa.Visible = true; this.Hide(); Cursor.Current = Cursors.Default; } if (teacherRB.Checked) { Teacher.markF tf = new Teacher.markF(); tf.Visible = true; this.Hide(); } } else { MessageBox.Show("The username or password you entered is incorrect. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } reader.Close(); con.Close(); }