private void submit_id_button_Click(object sender, RoutedEventArgs e)
 {
     // Check to make sure entry is a number.
     bool flag = patient_query_textbox_hosp.Text.All(char.IsDigit);
     if (flag)
     {
         data_grid_hosp.Items.Clear();
         // Connect to database.
         AP_AB_Blood_Bank db_hospital = new AP_AB_Blood_Bank("Data Source=DEVSERVERB; Initial Catalog=AP_AB_Blood_Bank; Integrated Security=True");
         db_hospital.ObjectTrackingEnabled = false;
         // Grab Patient Table
         System.Data.Linq.Table<_ECERESEARCH_Aparisi_Student___Patient_Table_> patient_temp_table_hospital = db_hospital.GetTable<_ECERESEARCH_Aparisi_Student___Patient_Table_>();
         // Execute query that grabs patients that have a matching hospital ID with the entry.
         var patient_query_hospital = from p in patient_temp_table_hospital where p.HospitalID == Int32.Parse(patient_query_textbox_hosp.Text) select p;
         foreach (var entry in patient_query_hospital)
         {
             string blood_id;
             // Convert blood ID to a blood type.
             switch (entry.BloodID)
             {
                 case 1:
                     blood_id = "A+";
                     break;
                 case 2:
                     blood_id = "A-";
                     break;
                 case 3:
                     blood_id = "B+";
                     break;
                 case 4:
                     blood_id = "B-";
                     break;
                 case 5:
                     blood_id = "AB+";
                     break;
                 case 6:
                     blood_id = "AB-";
                     break;
                 case 7:
                     blood_id = "O+";
                     break;
                 case 8:
                     blood_id = "O-";
                     break;
                 default:
                     blood_id = "ERROR";
                     break;
             }
             // Add patients to the datagrid.
             data_grid_hosp.Items.Add(new patient_info { patientid = entry.PatientID.ToString(), firstname = entry.FirstName, lastname = entry.LastName, bloodtype = blood_id, amount = entry.Amount_pint.ToString(), hospitalid = entry.HospitalID.ToString() });
         }
     }
     // Else, display error.
     else
         patient_query_textbox_hosp.Text = "ERROR";
 }
 private void submit_id_button_Click_1(object sender, RoutedEventArgs e)
 {
     // Check to make sure the entry is a number.
     bool flag0 = patient_query_textbox.Text.All(char.IsDigit);
     if (flag0)
     {
         // Opens the database.
         AP_AB_Blood_Bank db_p = new AP_AB_Blood_Bank("Data Source=DEVSERVERB; Initial Catalog=AP_AB_Blood_Bank; Integrated Security=True");
         db_p.ObjectTrackingEnabled = false;
         // Opens the Patient Table
         System.Data.Linq.Table<_ECERESEARCH_Aparisi_Student___Patient_Table_> patient_temp_table_p = db_p.GetTable<_ECERESEARCH_Aparisi_Student___Patient_Table_>();
         // Execute a query to grab the patient with a matching Patient ID.
         var patient_query_p = from p in patient_temp_table_p where p.PatientID == Int32.Parse(patient_query_textbox.Text) select p;
         foreach (var entry in patient_query_p)
         {
             string blood_id;
             // Convert the blood ID to a blood type.
             switch (entry.BloodID)
             {
                 case 1:
                     blood_id = "A+";
                     break;
                 case 2:
                     blood_id = "A-";
                     break;
                 case 3:
                     blood_id = "B+";
                     break;
                 case 4:
                     blood_id = "B-";
                     break;
                 case 5:
                     blood_id = "AB+";
                     break;
                 case 6:
                     blood_id = "AB-";
                     break;
                 case 7:
                     blood_id = "O+";
                     break;
                 case 8:
                     blood_id = "O-";
                     break;
                 default:
                     blood_id = "ERROR";
                     break;
             }
             // Add patient to the data grid.
             data_grid_p.Items.Add(new patient_info_p { patientid_p = entry.PatientID.ToString(), firstname_p = entry.FirstName, lastname_p = entry.LastName, bloodtype_p = blood_id, amount_p = entry.Amount_pint.ToString(), hospitalid_p = entry.HospitalID.ToString() });
         }
     }
     // Display error if the entry is not a number.
     else
         patient_query_textbox.Text = "ERROR";
 }
 private void submit_name_button_Click(object sender, RoutedEventArgs e)
 {
     // Check if the entry is not a number.
     bool flag = patient_name_query_textbox.Text.All(char.IsDigit);
     if (!flag)
     {
         data_grid_n.Items.Clear();
         // Connect to database.
         AP_AB_Blood_Bank db_n = new AP_AB_Blood_Bank("Data Source=DEVSERVERB; Initial Catalog=AP_AB_Blood_Bank; Integrated Security=True");
         db_n.ObjectTrackingEnabled = false;
         // Obtain Patient Table.
         System.Data.Linq.Table<_ECERESEARCH_Aparisi_Student___Patient_Table_> patient_temp_table_n = db_n.GetTable<_ECERESEARCH_Aparisi_Student___Patient_Table_>();
         // Execute query that grabs patients that share a last name with the entry.
         var patient_query_n = from p in patient_temp_table_n where p.LastName == patient_name_query_textbox.Text select p;
         foreach (var entry in patient_query_n)
         {
             string blood_id;
             // Convert blood ID to a blood type.
             switch (entry.BloodID)
             {
                 case 1:
                     blood_id = "A+";
                     break;
                 case 2:
                     blood_id = "A-";
                     break;
                 case 3:
                     blood_id = "B+";
                     break;
                 case 4:
                     blood_id = "B-";
                     break;
                 case 5:
                     blood_id = "AB+";
                     break;
                 case 6:
                     blood_id = "AB-";
                     break;
                 case 7:
                     blood_id = "O+";
                     break;
                 case 8:
                     blood_id = "O-";
                     break;
                 default:
                     blood_id = "ERROR";
                     break;
             }
             // Add patient(s) to data grid.
             data_grid_n.Items.Add(new patient_info_n { patientid_n = entry.PatientID.ToString(), firstname_n = entry.FirstName, lastname_n = entry.LastName, bloodtype_n = blood_id, amount_n = entry.Amount_pint.ToString(), hospitalid_n = entry.HospitalID.ToString() });
         }
     }
     else
         patient_name_query_textbox.Text = "ERROR";
 }
 private void submit_bloodtype_button_Click(object sender, RoutedEventArgs e)
 {
     // Converts the entered blood type to a blood ID.
     string blood_entry = patient_bloodtype_query_textbox.Text;
     int blood_id_entry;
     switch (blood_entry)
     {
         case "A+":
         case "a+":
             blood_id_entry = 1;
             break;
         case "A-":
         case "a-":
             blood_id_entry = 2;
             break;
         case "B+":
         case "b+":
             blood_id_entry = 3;
             break;
         case "B-":
         case "b-":
             blood_id_entry = 4;
             break;
         case "AB+":
         case "ab+":
         case "Ab+":
         case "aB+":
             blood_id_entry = 5;
             break;
         case "AB-":
         case "ab-":
         case "Ab-":
         case "aB-":
             blood_id_entry = 6;
             break;
         case "O+":
         case "o+":
             blood_id_entry = 7;
             break;
         case "O-":
         case "o-":
             blood_id_entry = 8;
             break;
         default:
             blood_id_entry = 999;
             break;
     }
     // Checks to make sure the entry is a valid blood type, as the default case in the above switch statement is the flag.
     if (blood_id_entry != 999)
     {
         data_grid_b.Items.Clear();
         // Connect to database.
         AP_AB_Blood_Bank db_b = new AP_AB_Blood_Bank("Data Source=DEVSERVERB; Initial Catalog=AP_AB_Blood_Bank; Integrated Security=True");
         db_b.ObjectTrackingEnabled = false;
         // Grab Patient Table.
         System.Data.Linq.Table<_ECERESEARCH_Aparisi_Student___Patient_Table_> patient_temp_table_b = db_b.GetTable<_ECERESEARCH_Aparisi_Student___Patient_Table_>();
         var patient_query_b = from p in patient_temp_table_b where p.BloodID == blood_id_entry select p;
         foreach (var entry in patient_query_b)
         {
             // Convert blood ID back to a blood type.
             string blood_id;
             switch (entry.BloodID)
             {
                 case 1:
                     blood_id = "A+";
                     break;
                 case 2:
                     blood_id = "A-";
                     break;
                 case 3:
                     blood_id = "B+";
                     break;
                 case 4:
                     blood_id = "B-";
                     break;
                 case 5:
                     blood_id = "AB+";
                     break;
                 case 6:
                     blood_id = "AB-";
                     break;
                 case 7:
                     blood_id = "O+";
                     break;
                 case 8:
                     blood_id = "O-";
                     break;
                 default:
                     blood_id = "ERROR";
                     break;
             }
             // Add patients to the data grid.
             data_grid_b.Items.Add(new patient_info_b { patientid_b = entry.PatientID.ToString(), firstname_b = entry.FirstName, lastname_b = entry.LastName, bloodtype_b = blood_id, amount_b = entry.Amount_pint.ToString(), hospitalid_b = entry.HospitalID.ToString() });
         }
     }
     // Else, display an error.
     else
     {
         data_grid_b.Items.Clear();
         patient_bloodtype_query_textbox.Text = "ERROR";
     }
 }
 public IndividualPatientsbyAllWindow()
 {
     InitializeComponent();
     // Initializes data grid and establishes columns.
     DataGridTextColumn col1_all = new DataGridTextColumn();
     DataGridTextColumn col2_all = new DataGridTextColumn();
     DataGridTextColumn col3_all = new DataGridTextColumn();
     DataGridTextColumn col4_all = new DataGridTextColumn();
     DataGridTextColumn col5_all = new DataGridTextColumn();
     DataGridTextColumn col6_all = new DataGridTextColumn();
     data_grid_all.Columns.Add(col1_all);
     data_grid_all.Columns.Add(col2_all);
     data_grid_all.Columns.Add(col3_all);
     data_grid_all.Columns.Add(col4_all);
     data_grid_all.Columns.Add(col5_all);
     data_grid_all.Columns.Add(col6_all);
     col1_all.Header = "Patient ID";
     col2_all.Header = "First Name";
     col3_all.Header = "Last Name";
     col4_all.Header = "Blood Type";
     col5_all.Header = "Amount Required";
     col6_all.Header = "Hospital ID";
     // Create bindings for the columns.
     col1_all.Binding = new Binding("patientid_all");
     col2_all.Binding = new Binding("firstname_all");
     col3_all.Binding = new Binding("lastname_all");
     col4_all.Binding = new Binding("bloodtype_all");
     col5_all.Binding = new Binding("amount_all");
     col6_all.Binding = new Binding("hospitalid_all");
     data_grid_all.Items.Clear();
     // Connect to database.
     AP_AB_Blood_Bank db_all = new AP_AB_Blood_Bank("Data Source=DEVSERVERB; Initial Catalog=AP_AB_Blood_Bank; Integrated Security=True");
     db_all.ObjectTrackingEnabled = false;
     // Grab Patient Table.
     System.Data.Linq.Table<_ECERESEARCH_Aparisi_Student___Patient_Table_> patient_temp_table_all = db_all.GetTable<_ECERESEARCH_Aparisi_Student___Patient_Table_>();
     // Execute query to grab all patients.
     var patient_query_all = from p in patient_temp_table_all  select p;
     foreach (var entry in patient_query_all)
     {
         string blood_id;
         // Convert blood ID to a blood type.
         switch (entry.BloodID)
         {
             case 1:
                 blood_id = "A+";
                 break;
             case 2:
                 blood_id = "A-";
                 break;
             case 3:
                 blood_id = "B+";
                 break;
             case 4:
                 blood_id = "B-";
                 break;
             case 5:
                 blood_id = "AB+";
                 break;
             case 6:
                 blood_id = "AB-";
                 break;
             case 7:
                 blood_id = "O+";
                 break;
             case 8:
                 blood_id = "O-";
                 break;
             default:
                 blood_id = "ERROR";
                 break;
         }
         // Add all patients to the grid.
         data_grid_all.Items.Add(new patient_info_all { patientid_all = entry.PatientID.ToString(), firstname_all = entry.FirstName, lastname_all = entry.LastName, bloodtype_all = blood_id, amount_all = entry.Amount_pint.ToString(), hospitalid_all = entry.HospitalID.ToString() });
     }
 }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     // Read blood type
     // Create flag system to reject incorrect inputs to prevent database corruption.
     int blood_id = 0;
     int flag0 = 0;
     int flag1 = 0;
     int flag2 = 0;
     int flag3 = 0;
     int flag4 = 0;
     // Convert blood type to blood ID.
     switch(blood_type_textbox_d.Text)
     {
         case "A+":
         case "a+":
         case "A +":
         case "a +":
             blood_id = 1;
             break;
         case "A-":
         case "a-":
         case "A -":
         case "a -":
             blood_id = 2;
             break;
         case "B+":
         case "b+":
         case "B +":
         case "b +":
             blood_id = 3;
             break;
         case "B-":
         case "b-":
         case "B -":
         case "b -":
             blood_id = 4;
             break;
         case "AB+":
         case "ab+":
         case "Ab+":
         case "aB+":
         case "AB +":
         case "Ab +":
         case "aB +":
         case "ab +":
             blood_id = 5;
             break;
         case "AB-":
         case "ab-":
         case "Ab-":
         case "aB-":
         case "AB -":
         case "ab -":
         case "Ab -":
         case "aB -":
             blood_id = 6;
             break;
         case "O+":
         case "o+":
         case "O +":
         case "o +":
             blood_id = 7;
             break;
         case "O-":
         case "o-":
         case "O -":
         case "o -":
             blood_id = 8;
             break;
         default:
             blood_id = 999;
             break;
     }
     //Check data for errors
     bool first_name_check = first_name_textbox_d.Text.All(char.IsDigit);
     bool last_name_check = last_name_textbox_d.Text.All(char.IsDigit);
     bool amount_pint_check = blood_donated_textbox_d.Text.All(char.IsDigit);
     bool hospitalID_check = hospital_id_textbox_d.Text.All(char.IsDigit);
     if (first_name_check)
     {
         flag0 = 1;
     }
     if (last_name_check)
     {
         flag1 = 1;
     }
     if (blood_id == 999)
     {
         flag2 = 1;
     }
     if (!amount_pint_check)
     {
         flag3 = 1;
     }
     if (!hospitalID_check || Int32.Parse(hospital_id_textbox_d.Text) > 24)
     {
         flag4 = 1;
     }
     // Submit new entry to database if there are no errors
     if (flag0 == 0 && flag1 == 0 && flag2 == 0 && flag3 == 0 && flag4 == 0)
     {
         // Create new entry from data
         AP_AB_Blood_Bank db = new AP_AB_Blood_Bank("Data Source=DEVSERVERB; Initial Catalog=AP_AB_Blood_Bank; Integrated Security=True");
         _ECERESEARCH_Aparisi_Student___Donor_Table_ donor = new _ECERESEARCH_Aparisi_Student___Donor_Table_()
         {
             FirstName = first_name_textbox_d.Text,
             LastName = last_name_textbox_d.Text,
             BloodID = blood_id,
             Amount_pint = Int32.Parse(blood_donated_textbox_d.Text),
             HospitalID = Int32.Parse(hospital_id_textbox_d.Text)
         };
         // Submit data
         db._ECERESEARCH_Aparisi_Student___Donor_Table_s.InsertOnSubmit(donor);
         db.SubmitChanges();
         // Clear data
         first_name_textbox_d.Text = String.Empty;
         last_name_textbox_d.Text = String.Empty;
         blood_type_textbox_d.Text = String.Empty;
         blood_donated_textbox_d.Text = String.Empty;
         hospital_id_textbox_d.Text = String.Empty;
     }
     //Display any errors that may have occurred
     if (flag0 == 1)
     {
         first_name_textbox_d.Text = "ERROR";
     }
     if (flag1 == 1)
     {
         last_name_textbox_d.Text = "ERROR";
     }
     if (flag2 == 1)
     {
         blood_type_textbox_d.Text = "ERROR";
     }
     if (flag3 == 1)
     {
         blood_donated_textbox_d.Text = "ERROR";
     }
     if (flag4 == 1)
     {
         hospital_id_textbox_d.Text = "ERROR";
     }
 }