private void PictureBoxSave_Click(object sender, EventArgs e) { string firstName = textBoxFirstName.Text.Trim(); string lastName = textBoxLastName.Text.Trim(); string email = textBoxEmail.Text.Trim(); string password = textBoxPassword.Text.Trim(); string jmbg = textBoxJMBG.Text.Trim(); string gender = (radioButtonGenderMale.Checked == true) ? "Male":"Female"; string phone = textBoxPhone.Text.Trim(); string education = textBoxEducation.Text.Trim(); DateTime dateOfHire = dateTimePickerDateOfHire.Value; string jobTitle = textBoxJobTitle.Text.Trim(); decimal salary = Convert.ToDecimal(textBoxSalary.Text.Trim()); //If there is not empty field insert new employee if (firstName != "" && lastName != "" && email != "" && password != "" && jmbg != "" && gender != "" && phone != "" && education != "" && dateOfHire < DateTime.Now && jobTitle != "" && salary > 0) { SqlCommand cmd = conn.Command("INSERT INTO Employees (first_name, last_name, email, password, JMBG, gender, phone, education, date_of_hire, job_title, salary) " + "VALUES (@FirstName, @LastName, @Email, @Password, @JMBG, @Gender, @Phone, @Education, @DateOfHire, @JobTitle, @Salary)"); cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@FirstName", firstName); cmd.Parameters.AddWithValue("@LastName", lastName); cmd.Parameters.AddWithValue("@Email", email); cmd.Parameters.AddWithValue("@Password", password); cmd.Parameters.AddWithValue("@JMBG", jmbg); cmd.Parameters.AddWithValue("@Gender", gender); cmd.Parameters.AddWithValue("@Phone", phone); cmd.Parameters.AddWithValue("@Education", education); cmd.Parameters.AddWithValue("@DateOfHire", dateOfHire); cmd.Parameters.AddWithValue("@JobTitle", jobTitle); cmd.Parameters.AddWithValue("@Salary", salary); try { conn.OpenConnection(); int result = cmd.ExecuteNonQuery(); if (result > 0) { MessageBox.Show("New employee is successfully added."); PageController.HomeAdmin(); this.Hide(); this.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.CloseConnection(); } } else { MessageBox.Show("All field are required. Please try again."); } }
private void ButtonLogin_Click(object sender, EventArgs e) { //If admin is logged-in if (textBoxEmail.Text.Trim() == "admin" && textBoxPassword.Text.Trim() == "admin") { User.UserID = 0; User.Username = "******"; PageController.HomeAdmin(); this.Hide(); } //If employee is logged-in else { SqlCommand cmd = conn.Command("SELECT ID,First_name,Last_name FROM Employees WHERE email = @Email AND Password=@Password"); cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Email", textBoxEmail.Text.Trim()); cmd.Parameters.AddWithValue("@Password", textBoxPassword.Text.Trim()); try { conn.OpenConnection(); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { User.UserID = Convert.ToInt32(reader["ID"].ToString()); User.Username = reader["First_name"].ToString() + " " + reader["Last_name"].ToString(); PageController.Home(); this.Hide(); } else { MessageBox.Show("There is no user with that credentials, please try again."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.CloseConnection(); } } }
private void PictureBoxDelete_Click(object sender, EventArgs e) { try { conn.OpenConnection(); if (conn.DeleteWithID("Employees", id)) { MessageBox.Show("Employee is successfully deleted."); PageController.HomeAdmin(); this.Hide(); this.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.CloseConnection(); } }
private void PictureBoxBack_Click(object sender, EventArgs e) { PageController.HomeAdmin(); this.Hide(); this.Dispose(); }