// Validate Bed Id exists in Database protected void BedIdValidate(object sender, ServerValidateEventArgs e) { try { int id; // Try parse input to int if (int.TryParse(e.Value, out id)) { // Get bed from database with provided id // using stored procedure Bed bed = BedUtility.GetBed(id); // Valid if found if (bed != null) { e.IsValid = true; return; } } // Throw exception if no valid bed found // or input not parsable to int throw new Exception(); } // Invalid if any exception caught catch (Exception) { e.IsValid = false; } }
// Get bed ID if exists or convert DBNull to Null string // for gridview protected string GetBedId(object bed) { if (object.ReferenceEquals(bed, DBNull.Value)) { return("Null"); } else { return(BedUtility.GetBed(Convert.ToInt32( bed.ToString())).name); } }
// Get price of visit for GridView protected string GetPrice(object bed) { if (object.ReferenceEquals(bed, DBNull.Value)) { return("Null"); } else { int price = BedUtility.GetBed(Convert.ToInt32( bed.ToString())).rate; return(String.Format("${0}", price)); } }
// Return bed name from id for gridview protected string GetBedId(object bed) { // If database has null bed return // empty string if (bed.ToString() == "Null") { return(""); } // Else return bed name as string else { return(BedUtility.GetBed(Convert.ToInt32( bed.ToString())).name); } }
// Add new visit submit protected void AssignClick(object sender, EventArgs e) { try { // Hide error messages when assign button is clicked DatabaseError.Visible = false; AssignSuccess.Visible = false; AssignFail.Visible = false; // Get patient and doctor Patient patient = PatientUtility.GetPatient( int.Parse(PatientId.Text)); Doctor doctor = DoctorUtility.GetDoctor( int.Parse(DoctorId.Text)); // Break if either not found, error messages will // be given by validators if (patient == null || doctor == null) { return; } // Generate pseudo id for object creation // (real id assigned by database) int visitId = VisitUtility.GetNewId(); // Get system date string fullDate = DateTime.Now.ToString(); // Split date from time string[] fullDateSplit = fullDate.Split(' '); // Split date into 3 parts (D,M,Y) string[] dateArray = fullDateSplit[0].Split('/'); // Recreate date in MM/DD/YYYY format for storing string date = String.Format("{0}/{1}/{2} {3}", dateArray[1], dateArray[0], dateArray[2], fullDateSplit[1]); // Set type to outpatient int visitType = 1; // If inpatient if (PatientTypeRadioButtonList.SelectedItem.ToString() == "Inpatient") { // Change type visitType = 0; // Get Bed Bed bed = BedUtility.GetBed(int.Parse(Bed.Text)); // Create new invisit InVisit inVisit = new InVisit(visitId, patient.id, visitType, doctor.id, date, "", bed.id); // Attempt to add object to database throw exception // on failure if (!VisitUtility.AddVisit(inVisit)) { throw new Exception(); } } // If outpatient else { // Set discharge date to visit date string discharge = date; // Create new outvisit object OutVisit outVisit = new OutVisit(visitId, patient.id, visitType, doctor.id, date, discharge); // Attempt to add object to database throw exception // on failure if (!VisitUtility.AddVisit(outVisit)) { throw new Exception(); } } // If no exception thrown operation was a success, show // confirmation message and hide errors AssignFail.Visible = false; AssignSuccess.Visible = true; AssignSubmit.Enabled = false; } // If exception is caught there is an issue with database connection // show appropriate error messages catch (Exception) { AssignSuccess.Visible = false; AssignFail.Visible = true; DatabaseError.Visible = true; } }