socialSecurityNumber.LostFocus += new EventHandler(socialSecurityNumber_LostFocus); // When the socialSecurityNumber field loses focus we will attempt to do a person seach based on this field private void socialSecurityNumber_LostFocus(object sender, EventArgs e) { verifyPagesCommon.socialSecurityNumber_LostFocus(); } // from verifyPagesCommon public void socialSecurityNumber_LostFocus() { if (!currentSocialSecurityNumber.Equals(socialSecurityNumber.Text)) { autoPopulate("NATIONAL_ID", socialSecurityNumber.Text); } } //autopopulates Employee ID, Social Security Number, Registration Number, System, First and Last Name //fields when either Employee ID or Social Security Number or Registration Number fields lose their focus //using the value of the field that lost its as a search parameter public void autoPopulate(string filterDatabaseField, string filterValue) { bool clearValues = false; if (!String.IsNullOrEmpty(filterValue)) { DataTable dt = new DataTable(); string queryString = "SELECT EMPLID, FIRST_NAME, LAST_NAME, NATIONAL_ID, NY_REGISTRATION_NM, NY_RETIREMENT_SYS " + "FROM " + filterDatabaseField + " = '" + filterValue + "'"; using (OracleConnection connection = new OracleConnection(ConnectionString)) { OracleCommand command = new OracleCommand(queryString); command.Connection = connection; OracleDataAdapter oda = new OracleDataAdapter(command); oda.Fill(dt); } //search was either unsuccessful and returned 0 results or it returned multiple results if (dt.Rows.Count != 1) { string errorField = String.Empty; switch (filterDatabaseField) { case "EMPLID": //resets Employee ID field to the value it had before this unsuccessful search //was launched errorField = "Employee ID"; break; case "NATIONAL_ID": //resets Social Security Number field to the value it had before this unsuccessful search //was launched errorField = "Social Security Number"; break; case "NY_REGISTRATION_NM": //resets Registration Number field to the value it had before this unsuccessful search //was launched errorField = "Registration Number"; break; } if (dt.Rows.Count == 0) { MessageBox.Show("No results found for a given " + errorField + " value."); } else if (dt.Rows.Count > 1) { MessageBox.Show("Several results found for " + errorField + " value of " + filterValue + ".\n\nPlease, press a Search button in order to conduct a more advanced\nsearch."); } clearValues = true; } if (dt.Rows.Count == 1) { employeeID.Text = dt.Rows[0][0].ToString(); //save the Employee ID value for the situation when the Employee ID field needs to be repopulated //in case of either an unsuccessful additonal search or search that returns multiple results currentEmployeedID = dt.Rows[0][0].ToString(); socialSecurityNumber.Text = dt.Rows[0][3].ToString(); //save the Social Security Number value for the situation when the Social Security Number field //needs to be repopulated in case of either an unsuccessful additonal search or search that //returns multiple results currentSocialSecurityNumber = dt.Rows[0][3].ToString(); registrationNumber.Text = dt.Rows[0][4].ToString(); //save the Registration Number value for the situation when the Registration Number field needs //to be repopulated in case of either an unsuccessful additonal search or search that returns //multiple results currentRegistrationNumber = dt.Rows[0][4].ToString(); // Auto populate system field override the value read from new form - HW 2018.10.31 dcedSystem.Select(); dcedSystem.CtlText = dt.Rows[0][5].ToString(); ; dcedFirstName.Select(); dcedFirstName.CtlText = dt.Rows[0][1].ToString(); dcedLastName.Select(); dcedLastName.CtlText = dt.Rows[0][2].ToString(); // datacapComments.Select(); RB commented updateLabels(); dcedReceivedDate.Select(); // RB added } } else { clearValues = true; } if (clearValues) { //prevent loop employeeID.Text = String.Empty; currentEmployeedID = employeeID.Text; socialSecurityNumber.Text = String.Empty; currentSocialSecurityNumber = socialSecurityNumber.Text; registrationNumber.Text = String.Empty; currentRegistrationNumber = registrationNumber.Text; // Clear Labels and datacap fields dcedSystem.Select(); dcedSystem.CtlText = ((int)SystemType.None).ToString(); systemDisplay.Text = String.Empty; dcedFirstName.Select(); dcedFirstName.CtlText = String.Empty; firstNameDisplay.Text = String.Empty; dcedLastName.Select(); dcedLastName.CtlText = String.Empty; lastNameDisplay.Text = String.Empty; employeeID.Select(); } }