using System; using System.Data; using System.Windows.Forms; namespace Louis__Pharmacy_CNSA212_FP { public partial class frmPatientAdd : Form { private static bool isAdd; public frmPatientAdd(bool isNew) { isAdd = isNew; InitializeComponent(); txtState.MaxLength = 2; if (isNew) { lblDisPurpose.Text = "Add Patient"; btnGO.Text = "Create"; } else { lblDisPurpose.Text = "Edit Patient"; btnGO.Text = "Update"; } } private void label1_Click(object sender, EventArgs e) { } private void frmPatientAdd_Load(object sender, EventArgs e) { txtPatientID.Enabled = false; if (isAdd) { var nextID = PharmacyDataTier.GetNextPatientID(); txtPatientID.Text = nextID.ToString(); } } public void FillPatient(string patID) { var ds = new DataSet(); var data = new PharmacyDataTier(); ds = PharmacyDataTier.PatientInfoSearch(patID); txtPatientID.Text = ds.Tables[0].Rows[0]["Patient_id"].ToString(); txtFname.Text = ds.Tables[0].Rows[0]["FirstName"].ToString(); txtLname.Text = ds.Tables[0].Rows[0]["LastName"].ToString(); txtMidInit.Text = ds.Tables[0].Rows[0]["MiddleIntials"].ToString(); txtWeight.Text = ds.Tables[0].Rows[0]["lbs"].ToString(); txtHeightFt.Text = ds.Tables[0].Rows[0]["Height_feet"].ToString(); txtHeightIn.Text = ds.Tables[0].Rows[0]["Height_inches"].ToString(); txtDOB.Text = ds.Tables[0].Rows[0]["DOB"].ToString(); txtGender.Text = ds.Tables[0].Rows[0]["Gender"].ToString(); txtCity.Text = ds.Tables[0].Rows[0]["City"].ToString(); txtZip.Text = ds.Tables[0].Rows[0]["Zip"].ToString(); txtState.Text = ds.Tables[0].Rows[0]["UsState"].ToString(); txtPhone.Text = ds.Tables[0].Rows[0]["PhoneNumber"].ToString(); } private void btnGO_Click(object sender, EventArgs e) { var epLocal = new ErrorProvider(); var Patient_id = txtPatientID.Text; var FirstName = txtFname.Text; var LastName = txtLname.Text; var MiddleIntials = txtMidInit.Text; var City = txtCity.Text; int lbs; int Height_feet; int Height_inches; DateTime DOB; string Gender; short Zip; string UsState; string PhoneNumber; var parseHasFailed = false; try { lbs = int.Parse(txtWeight.Text); try { Height_feet = int.Parse(txtHeightFt.Text); try { Height_inches = int.Parse(txtHeightIn.Text); try { DOB = DateTime.Parse(txtDOB.Text); try { Gender = txtGender.Text; try { Zip = short.Parse(txtZip.Text); try { UsState = txtState.Text; try { PhoneNumber = txtPhone.Text; try { if (Patient_id.Length > 8) { epLocal.SetError(txtPatientID, "Error"); throw new Exception(); } if (FirstName.Length > 30) { epLocal.SetError(txtFname, "Error"); throw new Exception(); } if (LastName.Length > 30) { epLocal.SetError(txtLname, "Error"); throw new Exception(); } if (MiddleIntials.Length > 1) { epLocal.SetError(txtMidInit, "Error"); throw new Exception(); } if (Zip > 65535) { epLocal.SetError(txtZip, "Error"); throw new Exception(); } if (City.Length > 30) { epLocal.SetError(txtCity, "Error"); throw new Exception(); } if (UsState.Length > 2) { epLocal.SetError(txtState, "Error"); throw new Exception(); } if (lbs > 2147483647) { epLocal.SetError(txtWeight, "Error"); throw new Exception(); } if (Height_feet > 2147483647) { epLocal.SetError(txtHeightFt, "Error"); throw new Exception(); } if (Height_inches > 2147483647) { epLocal.SetError(txtHeightIn, "Error"); throw new Exception(); } if (PhoneNumber.Length > 14) { epLocal.SetError(txtPhone, "Error"); throw new Exception(); } if (Gender.Length > 1) { epLocal.SetError(txtGender, "Error"); throw new Exception(); } PharmacyDataTier.UpdatePatient( Patient_id, FirstName, LastName, MiddleIntials, lbs, Height_feet, Height_inches, DOB, Gender, City, Zip, UsState, PhoneNumber); } catch (Exception exception) { epLocal.SetError(btnGO, "Error Updating Patient Info"); } } catch (Exception ex) { epLocal.SetError(txtPhone, "Invalid Value"); } } catch (Exception ex) { epLocal.SetError(txtState, "Invalid Value"); } } catch (Exception ex) { epLocal.SetError(txtZip, "Invalid Value"); } } catch (Exception ex) { epLocal.SetError(txtGender, "Invalid Value"); } } catch (Exception ex) { epLocal.SetError(txtDOB, "Invalid Value"); } } catch (Exception ex) { epLocal.SetError(txtHeightIn, "Invalid Value"); } } catch (Exception ex) { epLocal.SetError(txtHeightFt, "Invalid Value"); } } catch (Exception ex) { epLocal.SetError(txtWeight, "Invalid Value"); } } } }