private void saveBtn_Click(object sender, EventArgs e) { if (!isTextBoxEmpty()) { /*string conString = @"Data Source=localhost;port=3306;Initial Catalog=pharmacymanagement;User Id=root;password=''"; * string query = "insert into employee (EmpID,FirstName,LastName,NIC,Address,ContactNo,Shop,Type,Password) values ('" + employeeIdTxt.Text + "','" + firstNameTxt.Text + "','" + lastNameTxt.Text + "','" + nicTxt.Text + "','" + addressTxt.Text + "','" + contactNoTxt.Text + "','" + shopCbx.Text + "','" + typeCbx.Text + "','" + passwordTxt.Text + "');"; * MySqlConnection con = new MySqlConnection(conString); * try * { * con.Open(); * MySqlCommand cmd = new MySqlCommand(query, con); * cmd.ExecuteNonQuery(); * clearAll(); * MessageBox.Show("Successfully added the new Employee!"); * } * catch (Exception ex) * { * MessageBox.Show(ex.Message); * } * finally * { * con.Close(); * }*/ if (contactNoTxt.Text == "") { contactNoTxt.Text = "0"; } if (typeCbx.Text == "Owner") { User owner = new Owner(employeeIdTxt.Text, fullNameTxt.Text, firstNameTxt.Text, nicTxt.Text, addressTxt.Text, Int32.Parse(contactNoTxt.Text), shopCbx.Text, typeCbx.Text, statusCbx.Text, passwordTxt.Text); } else if (typeCbx.Text == "Supervisor") { User supervisor = new Supervisor(employeeIdTxt.Text, fullNameTxt.Text, firstNameTxt.Text, nicTxt.Text, addressTxt.Text, Int32.Parse(contactNoTxt.Text), shopCbx.Text, typeCbx.Text, statusCbx.Text, passwordTxt.Text); } else { User cashier = new Cashier(employeeIdTxt.Text, fullNameTxt.Text, firstNameTxt.Text, nicTxt.Text, addressTxt.Text, Int32.Parse(contactNoTxt.Text), shopCbx.Text, typeCbx.Text, statusCbx.Text, passwordTxt.Text); } } else { MessageBox.Show("Fail in adding the new Employee!"); } }
public static void loginUsers(String userName, String password) { MySqlConnection con = DBConnection.getConn(); try { con.Open(); String query = "Select Type,Password,Status,Shop from employee where EmpID = '" + userName + "'"; MySqlCommand cmd = new MySqlCommand(query, con); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { //string type = reader["Type"].ToString(); string type = reader.GetString(0); string status = reader.GetString(2); if (status == "Active") { if (reader.GetString(1) == password) { User.CurrentUserName = userName; User.UserShop = reader.GetString(3); User.UserType = type; if (type == "Owner") { /*AdminInterface owner = new AdminInterface(); * owner.Show(); * this.Hide();*/ Owner.login(); LogObj.Hide(); } else if (type == "Supervisor") { /*SupervisorInterface sp = new SupervisorInterface(); * sp.Show(); * this.Hide();*/ Supervisor.login(); LogObj.Hide(); } else if (type == "Cashier") { /*CashierInterface emp = new CashierInterface(); * emp.Show(); * this.Hide();*/ Cashier.login(); LogObj.Hide(); } else { //nameErLbl.Visible = true; User.LogObj.displayErr(); } } else { //nameErLbl.Visible = true; User.LogObj.displayErr(); User.LogObj.showForgotPassButton(); } } else { User.LogObj.inactiveErr(); } } if (!reader.HasRows) { //nameErLbl.Visible = true; User.LogObj.displayErr(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { con.Close(); DBConnection.returnConn(con); con = null; } }