private void buttonCreateStaff_Click(object sender, EventArgs e) { //Validate the text box in the form before proceeding to store in Database var emptyornull = Controls.OfType <TextBox>().Where(box => box.Name.StartsWith("_")).OrderBy(box => box.TabIndex); var emptyornull2 = Controls.OfType <ComboBox>().Where(box => box.Name.StartsWith("_")).OrderBy(box => box.TabIndex); foreach (var testControl in emptyornull) { if (string.IsNullOrEmpty(testControl.Text)) { this.errorProvider1.SetError((Control)testControl, "error"); return; } this.errorProvider1.SetError((Control)testControl, (string)null); } // I am trying to combine these two loops into one loop foreach (var testControl in emptyornull2) { if (string.IsNullOrEmpty(testControl.Text)) { this.errorProvider1.SetError((Control)testControl, "error"); return; } this.errorProvider1.SetError((Control)testControl, (string)null); } EncryptText password = new EncryptText(); DBConnector.Instance.recordInDB(_textBoxName.Text, _textBoxSurname.Text, _ComboBoxGender.Text, _textBoxStaffID.Text, password.createHash(_textBoxStaffPassword.Text), _comboBoxStaffRole.Text, _dateTimePickerDOB.Value.ToString("dd/MM/yyyy"), _dateTimePickerEmployDate.Value.ToString("dd/MM/yyyy"), _textBoxEmail.Text, _textBoxPhone.Text); // update the dataGridView populateGridView(); ClearFormEntry(); }
private void buttonLogin_Click(object sender, EventArgs e) { //Validate the text box in the form before proceeding to store in Database var emptyornull = Controls.OfType <TextBox>().Where(box => box.Name.StartsWith("_")).OrderBy(box => box.TabIndex); foreach (var testControl in emptyornull) { if (string.IsNullOrEmpty(testControl.Text)) { this.errorProviderLoginForm.SetError((Control)testControl, "error"); return; } this.errorProviderLoginForm.SetError((Control)testControl, (string)null); } string enteredStaffID = _textBoxStaffID.Text.Trim(); //string enteredStaffPassword = _textBoxPassword.Text.Trim(); EncryptText passwordHash = new EncryptText(); string ss = passwordHash.createHash(_textBoxPassword.Text.Trim()).ToString(); string authenticationOutcome = StaffLoginDetails(enteredStaffID, ss).ToString(); if (authenticationOutcome == "True") { this.Hide(); new DBManagementForm().Show(); } else { labelErrorMessage.ForeColor = Color.Red; labelErrorMessage.Text = "Staff details entered does not exist. Please try again."; } }