private void btnConfirmChanges_Click(object sender, EventArgs e) { if (lvAllEmployees.SelectedItems.Count == 0) { MessageBox.Show("Please select an employee from the list"); return; } if (MessageBox.Show("Confirm changes ?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No) { return; } int index; index = lvAllEmployees.FocusedItem.Index; TextBox[] textBoxes = new TextBox[] { tbInsFirstName, tbInsLastName, tbInsTelNumber, tbInsContactName, tbInsContactPhone, tbInsSalary, tbInsUsername, tbInsPassword, tbInsConfirmPassword }; ComboBox[] comboBoxes = new ComboBox[] { cbxInsPosition, cbxInsDepartment }; RichTextBox[] richTextBoxes = new RichTextBox[] { tbInsAddress }; if (CheckForErrors(textBoxes, comboBoxes, richTextBoxes) == true) { return; } MySqlConnection connection; string connectionString; connectionString = "Server=studmysql01.fhict.local;Uid=dbi400999;Database=dbi400999;Pwd=Group6Project;"; connection = new MySqlConnection(connectionString); try { connection.Open(); if (connection.State == ConnectionState.Open) { MySqlCommand cmd = new MySqlCommand($"UPDATE employee SET firstName = @firstName, lastName = @lastName, dateOfBirth = @dateOfBirth, phone = @phone, address = @address, contactFirstName = @contactFirstName, contactPhone = @contactPhone, salary = @salary, position = @position, departmentName = @departmentName, pass = @pass, username = @username WHERE employeeID = {allEmployees[index].id}", connection); cmd.Parameters.AddWithValue("@firstName", Convert.ToString(tbInsFirstName.Text)); cmd.Parameters.AddWithValue("@lastName", Convert.ToString(tbInsLastName.Text)); cmd.Parameters.AddWithValue("@dateOfBirth", Convert.ToDateTime(dateTimePickerIns.Value)); cmd.Parameters.AddWithValue("@phone", Convert.ToString(tbInsTelNumber.Text)); cmd.Parameters.AddWithValue("@address", Convert.ToString(tbInsAddress.Text)); cmd.Parameters.AddWithValue("@contactFirstName", Convert.ToString(tbInsContactName.Text)); cmd.Parameters.AddWithValue("@contactPhone", Convert.ToString(tbInsContactPhone.Text)); cmd.Parameters.AddWithValue("@salary", Convert.ToDecimal(tbInsSalary.Text)); cmd.Parameters.AddWithValue("@position", Convert.ToString(cbxInsPosition.SelectedItem)); cmd.Parameters.AddWithValue("@departmentName", Convert.ToString(cbxInsDepartment.SelectedItem)); cmd.Parameters.AddWithValue("@pass", Convert.ToString(tbInsPassword.Text)); cmd.Parameters.AddWithValue("@username", Convert.ToString(tbInsUsername.Text)); cmd.ExecuteNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } connection.Close(); if (currentWorkerInfo.MakeNewContract(cbxInsPosition.Text, cbxInsDepartment.Text, Convert.ToInt32(tbInsSalary.Text)) == true) { NewContract(currentWorkerInfo.Id, Convert.ToInt32(tbInsSalary.Text), cbxInsDepartment.Text, cbxInsPosition.Text); } connection = new MySqlConnection(connectionString); try { connection.Open(); if (connection.State == ConnectionState.Open) { MySqlCommand cmd = new MySqlCommand($"UPDATE morningshifts SET {cbxInsDepartment.Text} = @username WHERE {cbxInsDepartment.Text} = '{currentUser}'", connection); MySqlCommand cmd1 = new MySqlCommand($"UPDATE afternoonshifts SET {cbxInsDepartment.Text} = @username WHERE {cbxInsDepartment.Text} = '{currentUser}'", connection); MySqlCommand cmd2 = new MySqlCommand($"UPDATE eveningshifts SET {cbxInsDepartment.Text} = @username WHERE {cbxInsDepartment.Text} = '{currentUser}'", connection); //MySqlCommand cmd = new MySqlCommand($"UPDATE morningshifts SET Electronics = 'j_bond008' WHERE Electronics = 'j_bond007'", connection); cmd.Parameters.AddWithValue("@username", tbInsUsername.Text); cmd1.Parameters.AddWithValue("@username", tbInsUsername.Text); cmd2.Parameters.AddWithValue("@username", tbInsUsername.Text); cmd.ExecuteNonQuery(); cmd1.ExecuteNonQuery(); cmd2.ExecuteNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } connection.Close(); LoadAllEmployees(); LoadStats(); foreach (TextBox textBox in textBoxes) { textBox.Clear(); } foreach (ComboBox combo in comboBoxes) { combo.Text = ""; } foreach (RichTextBox rich in richTextBoxes) { rich.Clear(); } dateTimePickerIns.Value = DateTime.Now; MessageBox.Show("Changes confirmed."); }