private void ClearTextFields() { NameTextBox.Clear(); MailTextBox.Clear(); MailUserLabel.Content = $"Mail: "; MailAdminLabel.Content = $"Mail: "; }
/// <summary> /// Click event, Send a mail on the contact section. /// </summary> private void ContactSendButton_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(NameTextBox.Text) || String.IsNullOrEmpty(MailTextBox.Text) || String.IsNullOrEmpty(SubjectTextBox.Text) || String.IsNullOrEmpty(ContentTextBox.Text)) { Alert.AlertCreation("Fill Every Field!", AlertType.error); return; } else { string emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\." + "[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+\\.)+[a-z" + "A-Z]{2,7}$"; bool isEmail = Regex.IsMatch(MailTextBox.Text, emailRegex); if (isEmail) { bool result = informationParser.SendMail(mailSender, log, SubjectTextBox.Text, "Mail sender Name: " + NameTextBox.Text + "<br>" + "Mail Sender Address: " + MailTextBox.Text + "<br>" + ContentTextBox.Text, null); if (result) { Alert.AlertCreation("Mail has been sent.", AlertType.success); NameTextBox.Clear(); MailTextBox.Clear(); SubjectTextBox.Clear(); ContentTextBox.Clear(); } else { Alert.AlertCreation("Mail Problem. (Check SMTP)", AlertType.error); return; } } else { Alert.AlertCreation("Mail Address Format Problem.", AlertType.error); return; } } }
//enters in the details of the textboxes as a new employee or replacing a deleted employee private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(ForeTextBox.Text))//Employee won't be entered if Forename text box is empty { MessageBox.Show("You have not entered the forename of this new employee"); } else { if (string.IsNullOrEmpty(SurTextBox.Text))//Employee won't be entered if Surname text box is empty { MessageBox.Show("You have not entered the surname of this new employee"); } else { if (string.IsNullOrEmpty(MailTextBox.Text))//Employee won't be entered if Email text box is empty { MessageBox.Show("You have not entered the email of this new employee"); } else { if (!MailTextBox.Text.Contains("@"))//Employee won't be entered if Email text box does not contain @ { MessageBox.Show("You have not entered the email of this new employee correctly"); } else { connection = new SqlConnection(connectionString); String query = "declare @a int; " + "declare @b int; " + "declare @c int; " + "if ((select count(*) from Employee) > 0) Begin set @c = (select max(EmployeeID) from Employee) end else Begin set @c = 0 end " + // if there are no employees in the table c = 0 but if there's at least 1 employee, c = the highest employee ID in the table "set @a = (select count(*) from Employee where Forename is null and Surname is null and Email is null) " + //a = the number of jobs with no details except the EmployeeID "if @a > 0 " + "Begin " + "set @b = (select min(EmployeeID) from Employee where Forename is null and Surname is null and Email is null) " + //b = the ID number of the employee with the lowest ID number with no other details "update Employee set Forename = (@Forename), Surname = @Surname, Email = @Email, JobID = @JobID, [Works Under] = @WorksUnder where EmployeeID = @b " + //updates the details of the Employee with the EmployeeID of b with the details from the text boxes "end " + "else " + "begin " + "DBCC CHECKIDENT(Employee, RESEED, @c) " + "Insert into [Employee](Forename, Surname, Email, JobID, [Works Under]) Values (@Forename, @Surname, @Email, @JobID, @WorksUnder); " + //inserts the details from the text boxes at the end of the table "end"; using (connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(query, connection)) using (SqlDataAdapter adapter = new SqlDataAdapter(command)) { connection.Open(); command.Parameters.AddWithValue("@Forename", ForeTextBox.Text); command.Parameters.AddWithValue("@Surname", SurTextBox.Text); command.Parameters.AddWithValue("@Email", MailTextBox.Text); if (string.IsNullOrEmpty(JobIDBox.Text))//allows the employee to be entered if there are no jobs since there is the chance that the user will chose to enter in the employees first { command.Parameters.AddWithValue("@JobID", DBNull.Value); } else { command.Parameters.AddWithValue("@JobID", JobIDBox.Text); } if (string.IsNullOrEmpty(WUIDBox.Text))//allows the employee to be entered if there are no other employees since there will be no other employees when the database is cleared { command.Parameters.AddWithValue("@WorksUnder", DBNull.Value); } else { command.Parameters.AddWithValue("@WorksUnder", WUIDBox.Text); } try { command.ExecuteReader(); MessageBox.Show("Employee Entered"); } catch (System.Data.SqlClient.SqlException ex) { MessageBox.Show(ex.Message); } } ForeTextBox.Clear(); SurTextBox.Clear(); MailTextBox.Clear(); showchngJobName(); showID(); showWID(); } } } } }