private void detach__ECERESEARCH_Aparisi_Student___Patient_Table_s(_ECERESEARCH_Aparisi_Student___Patient_Table_ entity)
	{
		this.SendPropertyChanging();
		entity._ECERESEARCH_Aparisi_Student___Hospital_Table_ = null;
	}
 partial void Delete_ECERESEARCH_Aparisi_Student___Patient_Table_(_ECERESEARCH_Aparisi_Student___Patient_Table_ instance);
	private void attach__ECERESEARCH_Aparisi_Student___Patient_Table_s(_ECERESEARCH_Aparisi_Student___Patient_Table_ entity)
	{
		this.SendPropertyChanging();
		entity._ECERESEARCH_Aparisi_Student___Blood_Table_ = this;
	}
 partial void Insert_ECERESEARCH_Aparisi_Student___Patient_Table_(_ECERESEARCH_Aparisi_Student___Patient_Table_ instance);
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int blood_id = 0;
            int flag0 = 0;
            int flag1 = 0;
            int flag2 = 0;
            int flag3 = 0;
            int flag4 = 0;
            // Read blood type
            switch (blood_type_textbox.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
            // Flags are used to signal that an error has occurred
            bool first_name_check = first_name_textbox.Text.All(char.IsDigit);
            bool last_name_check = last_name_textbox.Text.All(char.IsDigit);
            bool amount_pint_check = blood_required_textbox.Text.All(char.IsDigit);
            bool hospitalID_check = hospital_id_textbox.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.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___Patient_Table_ patient = new _ECERESEARCH_Aparisi_Student___Patient_Table_()
                {
                    FirstName = first_name_textbox.Text,
                    LastName = last_name_textbox.Text,
                    BloodID = blood_id,
                    Amount_pint = Int32.Parse(blood_required_textbox.Text),
                    HospitalID = Int32.Parse(hospital_id_textbox.Text)
                };
                // Submit data
                db._ECERESEARCH_Aparisi_Student___Patient_Table_s.InsertOnSubmit(patient);
                db.SubmitChanges();
                // Clear data
                first_name_textbox.Text = String.Empty;
                last_name_textbox.Text = String.Empty;
                blood_type_textbox.Text = String.Empty;
                blood_required_textbox.Text = String.Empty;
                hospital_id_textbox.Text = String.Empty;
            }
            //Display any errors that may have occurred
            //No data is submitted to the database if any errors occur, preventing data corruption.
            if(flag0 == 1)
            {
                first_name_textbox.Text = "ERROR";
            }
            if(flag1 == 1)
            {
                last_name_textbox.Text = "ERROR";
            }
            if(flag2 == 1)
            {
                blood_type_textbox.Text = "ERROR";
            }
            if(flag3 == 1)
            {
                blood_required_textbox.Text = "ERROR";
            }
            if(flag4 == 1)
            {
                hospital_id_textbox.Text = "ERROR";
            }
        }