private void signInBtn_Click(object sender, EventArgs e) { // Check with the Database the username and the password and move to the HomePage || AdminPage Employee resEmp = new DatabaseConnector().logInEmp(usernameText, AdditionalFunctions.MD5(AdditionalFunctions.MD5(passwordText))); if (resEmp != null) { if (resEmp.role == ConstVars.Roles.ADMIN) { // WinForms navigation needs to be like this AdminPage adminPage = new AdminPage(resEmp); adminPage.TopLevel = false; Controls.Clear(); Controls.Add(adminPage); adminPage.Show(); } else { MapPage mPage = new MapPage(resEmp); mPage.Show(); Hide(); } } }
private void submitButton_Click(object sender, EventArgs e) { if ( !AdditionalFunctions.isEmpty(id) && !AdditionalFunctions.isEmpty(name) && !AdditionalFunctions.isEmpty(birth_date) && !AdditionalFunctions.isEmpty(role) && !AdditionalFunctions.isEmpty(username) && !AdditionalFunctions.isEmpty(password) && !AdditionalFunctions.isEmpty(secPassword) && !AdditionalFunctions.isEmpty(phoneNumber) && !AdditionalFunctions.isEmpty(gender) && !AdditionalFunctions.isEmpty(street) && !AdditionalFunctions.isEmpty(house_num) && !AdditionalFunctions.isEmpty(city) && !AdditionalFunctions.isEmpty(zip_code) && isChanged ) { if (password == secPassword) { if (submitButton.Text == "Update") { try { bool res = db.updateEmployee( new Employee( id, name, new SqlDate(birth_date), role, username, password, phoneNumber, new Address( street, int.Parse(house_num), city, zip_code, 0.0, 0.0 ) ), address, addressID ); if (res) { Close(); parent.refreshTable(TabChooser.Employees); } else { MessageBox.Show($"Error occord with { name }'s update, Please try again later."); Close(); } } catch (Exception ex) { MessageBox.Show($"Error occord with { name }'s update, Please try again later."); Close(); } } else { db.addNewEmploeey( new Employee( id, name, new SqlDate(birth_date), role, username, AdditionalFunctions.MD5(AdditionalFunctions.MD5(password)), phoneNumber, gender, address ) ); } } } else { if (!isChanged) { MessageBox.Show("No data has changed, If you want to close please click the X button on the top"); } else { MessageBox.Show("One of the fields are not filled, Please fill and try again."); } if (AdditionalFunctions.isEmpty(id)) { idTextBox.BackColor = Color.Red; } } }