/***** Methods to view patients data in the PatientDataGridView ***/ // This method will allow us to display a record based on the patient's full name search public Int32 PatientsInDataGridView(string firstNameFilter, string lastNameFilter) { //create an instance of the class clsPatientCollection clsPatientCollection MyPatients = new clsPatientCollection(); //apply the method FindPatientByName to find the patients in the database MyPatients.FindPatientByName(firstNameFilter, lastNameFilter); // apply the data table method to the gridview now and don't forget it is not a method as such it is a property PatientDataGridView.DataSource = MyPatients.Patients_DataTable; //Now Bind the data to the gridview PatientDataGridView.DataBind(); // Make the the Gridview visible now PatientDataGridView.Visible = true; // variable to store the count of records in the object MyPatients Int32 recordCount = MyPatients.Count; // see the number of records found lblPatientMessage.Text = " There are " + recordCount + " Patient(s) found and they are sorted alphabetically by their Last Name."; //return the count of the records return(recordCount); }
// Filter all patients to be displayed in the listbox based on their fullname public Int32 ViewAllPatients(string firstNameFilter, string lastNameFilter) { //Declare the variables that will be visible in the list Int32 patientID; string gender; string firstName; string lastName; DateTime dateOfBirth; DateTime dateAdmitted; DateTime dateDischarged; //The foreign keys in the tblPatient are WardNo and TreatmentId .. //Int32 WardNo; //Int32 TreatmentID; //create an instance of the class clsPatientCollection clsPatientCollection MyPatients = new clsPatientCollection(); // apply the filter by full name MyPatients.FindPatientByName(firstNameFilter, lastNameFilter); // variable to store the count of records in the object MyPatients Int32 recordCount = MyPatients.Count; // variable to store the index for the loop Int32 index = 0; // clear any data off the list first lstPatients.Items.Clear(); // loop while there are still some records to process while (index < recordCount) { patientID = MyPatients.PatientList[index].PatientID; // get the primary key of the patient gender = MyPatients.PatientList[index].Gender; //get the patient's gender firstName = MyPatients.PatientList[index].FirstName; //get the patient's firstname lastName = MyPatients.PatientList[index].LastName; //get the patient's LastName dateOfBirth = MyPatients.PatientList[index].DateOfBirth; dateAdmitted = MyPatients.PatientList[index].DateAdmitted; // get the date admmited dateDischarged = MyPatients.PatientList[index].DateDischarged; // get the date discharged // create a new entry for the listbox in the UI ListItem newEntry = new ListItem(gender + " " + firstName + " " + lastName + " " + dateOfBirth.ToString("dd/MM/yyyy") + " " + // ToString() to display just date without time dateAdmitted + " " + dateDischarged + " ", patientID.ToString()); // add the patients data collected from newEntry to the list lstPatients.Items.Add(newEntry); // move the index to the next record for the loop to continue index++; } // Tell the user how many records were found lblPatientMessage.Text = "There are " + recordCount + " Patient(s) found and they are sorted alphabetically by their Last Name."; // return the count of the records found return(recordCount); }