private void detach__ECERESEARCH_Aparisi_Student___Donor_Table_s(_ECERESEARCH_Aparisi_Student___Donor_Table_ entity) { this.SendPropertyChanging(); entity._ECERESEARCH_Aparisi_Student___Hospital_Table_ = null; }
partial void Delete_ECERESEARCH_Aparisi_Student___Donor_Table_(_ECERESEARCH_Aparisi_Student___Donor_Table_ instance);
private void attach__ECERESEARCH_Aparisi_Student___Donor_Table_s(_ECERESEARCH_Aparisi_Student___Donor_Table_ entity) { this.SendPropertyChanging(); entity._ECERESEARCH_Aparisi_Student___Blood_Table_ = this; }
partial void Insert_ECERESEARCH_Aparisi_Student___Donor_Table_(_ECERESEARCH_Aparisi_Student___Donor_Table_ instance);
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"; } }