CNSA-212-FP/Louis'-Pharmacy_CNSA212-FP/frmPatient.cs

460 lines
21 KiB
C#
Raw Normal View History

using System;
2024-02-15 12:04:26 -05:00
using System.Data;
2024-02-16 13:57:58 -05:00
using System.Windows.Forms;
namespace Louis__Pharmacy_CNSA212_FP
{
public partial class frmPatient : Form
{
private static bool isAdd;
2024-02-16 13:57:58 -05:00
private readonly frmInfo SourceForm;
2024-02-16 20:13:30 -05:00
public frmPatient(frmInfo sourceForm, bool isNew)
{
2024-02-16 20:13:30 -05:00
SourceForm = sourceForm;
isAdd = isNew;
InitializeComponent();
2024-02-16 13:57:58 -05:00
txtState.MaxLength = 2;
if (isNew)
{
lblDisPurpose.Text = "Add Patient";
2024-02-15 12:04:26 -05:00
btnGO.Text = "Create";
}
else
{
lblDisPurpose.Text = "Edit Patient";
2024-02-15 12:04:26 -05:00
btnGO.Text = "Update";
}
KeyPreview = true;
KeyDown += frmPatient_KeyDown;
}
private void frmPatient_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
Close();
if (e.KeyCode == Keys.Enter) btnGO_Click(sender, e);
}
2024-02-16 13:57:58 -05:00
private void label1_Click(object sender, EventArgs e)
{
}
private void frmPatientAdd_Load(object sender, EventArgs e)
{
txtPatientID.Enabled = false;
if (isAdd)
{
2024-02-16 13:57:58 -05:00
var nextID = PharmacyDataTier.GetNextPatientID();
2024-02-15 12:04:26 -05:00
txtPatientID.Text = nextID.ToString();
}
2024-02-19 22:24:03 -05:00
PharmacyDataTier.FillComboBox("GENDER","*","GenderValue",cboGender);
2024-02-15 12:04:26 -05:00
}
2024-02-15 12:04:26 -05:00
public void FillPatient(string patID)
{
2024-02-16 13:57:58 -05:00
var ds = new DataSet();
var data = new PharmacyDataTier();
2024-02-15 12:04:26 -05:00
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();
2024-02-16 11:32:00 -05:00
txtMidInit.Text = ds.Tables[0].Rows[0]["MiddleIntials"].ToString();
2024-02-15 12:04:26 -05:00
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();
2024-02-19 22:24:03 -05:00
cboGender.Text = ds.Tables[0].Rows[0]["Gender"].ToString();
2024-02-15 12:04:26 -05:00
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();
}
2024-02-16 13:57:58 -05:00
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;
if (!isAdd)
2024-02-16 13:57:58 -05:00
try
{
2024-02-19 10:47:16 -05:00
lbs = int.Parse(txtWeight.Text);
2024-02-16 13:57:58 -05:00
try
{
2024-02-19 10:47:16 -05:00
Height_feet = int.Parse(txtHeightFt.Text);
2024-02-16 13:57:58 -05:00
try
{
2024-02-19 10:47:16 -05:00
Height_inches = int.Parse(txtHeightIn.Text);
2024-02-16 13:57:58 -05:00
try
{
2024-02-19 10:47:16 -05:00
DOB = DateTime.Parse(txtDOB.Text);
2024-02-16 13:57:58 -05:00
try
{
2024-02-19 22:24:03 -05:00
Gender = cboGender.Text;
2024-02-16 13:57:58 -05:00
try
{
2024-02-19 10:47:16 -05:00
Zip = short.Parse(txtZip.Text);
2024-02-16 13:57:58 -05:00
try
{
2024-02-19 10:47:16 -05:00
UsState = txtState.Text;
2024-02-16 13:57:58 -05:00
try
{
2024-02-19 10:47:16 -05:00
PhoneNumber = txtPhone.Text;
try
{
2024-02-19 10:47:16 -05:00
if (Patient_id.Length > 8)
{
2024-02-19 10:47:16 -05:00
epLocal.SetError(txtPatientID, "Error");
throw new Exception();
}
while (Patient_id.Length < 8) Patient_id = "0" + Patient_id;
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (FirstName.Length > 30)
{
epLocal.SetError(txtFname, "Error");
throw new Exception();
}
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (LastName.Length > 30)
{
epLocal.SetError(txtLname, "Error");
throw new Exception();
}
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (MiddleIntials.Length > 1)
{
epLocal.SetError(txtMidInit, "Error");
throw new Exception();
}
MiddleIntials = MiddleIntials.ToUpper();
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (Zip > 65535)
{
epLocal.SetError(txtZip, "Error");
throw new Exception();
}
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (City.Length > 30)
{
epLocal.SetError(txtCity, "Error");
throw new Exception();
}
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (UsState.Length > 2)
{
epLocal.SetError(txtState, "Error");
throw new Exception();
}
UsState = UsState.ToUpper();
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (lbs > 2147483647)
{
epLocal.SetError(txtWeight, "Error");
throw new Exception();
}
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (Height_feet > 2147483647)
{
epLocal.SetError(txtHeightFt, "Error");
throw new Exception();
}
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (Height_inches > 2147483647)
{
epLocal.SetError(txtHeightIn, "Error");
throw new Exception();
}
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (PhoneNumber.Length > 14)
{
epLocal.SetError(txtPhone, "Error");
throw new Exception();
}
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
if (Gender.Length > 1)
{
2024-02-19 22:24:03 -05:00
epLocal.SetError(cboGender, "Error");
2024-02-19 10:47:16 -05:00
throw new Exception();
}
Gender = Gender.ToUpper();
2024-02-16 13:57:58 -05:00
2024-02-19 10:47:16 -05:00
PharmacyDataTier.UpdatePatient(
Patient_id,
FirstName,
LastName,
MiddleIntials,
lbs,
Height_feet,
Height_inches,
DOB,
Gender,
City,
Zip,
UsState,
PhoneNumber);
SourceForm.txtPatientID.Text = Patient_id;
2024-02-19 10:47:16 -05:00
SourceForm.btnPatientSearch_Click(SourceForm, e);
2024-02-19 10:47:16 -05:00
Close();
}
catch (Exception exception)
{
epLocal.SetError(btnGO, "Error Creating Patient");
}
}
2024-02-19 10:47:16 -05:00
catch (Exception ex)
{
2024-02-19 10:47:16 -05:00
epLocal.SetError(txtPhone, "Invalid Value");
}
}
catch (Exception ex)
{
2024-02-19 10:47:16 -05:00
epLocal.SetError(txtState, "Invalid Value");
}
}
catch (Exception ex)
{
2024-02-19 10:47:16 -05:00
epLocal.SetError(txtZip, "Invalid Value");
}
}
catch (Exception ex)
{
2024-02-19 22:24:03 -05:00
epLocal.SetError(cboGender, "Invalid Value");
}
}
catch (Exception ex)
{
2024-02-19 10:47:16 -05:00
epLocal.SetError(txtDOB, "Invalid Value");
}
}
catch (Exception ex)
{
2024-02-19 10:47:16 -05:00
epLocal.SetError(txtHeightIn, "Invalid Value");
}
}
catch (Exception ex)
{
2024-02-19 10:47:16 -05:00
epLocal.SetError(txtHeightFt, "Invalid Value");
}
}
catch (Exception ex)
{
2024-02-19 10:47:16 -05:00
epLocal.SetError(txtWeight, "Invalid Value");
}
else if (isAdd)
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
{
2024-02-19 22:24:03 -05:00
Gender = cboGender.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();
}
while (Patient_id.Length < 8) Patient_id = "0" + Patient_id;
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();
}
MiddleIntials = MiddleIntials.ToUpper();
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();
}
UsState = UsState.ToUpper();
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)
{
2024-02-19 22:24:03 -05:00
epLocal.SetError(cboGender, "Error");
throw new Exception();
}
Gender = Gender.ToUpper();
PharmacyDataTier.CreatePatient(
Patient_id,
FirstName,
LastName,
MiddleIntials,
lbs,
Height_feet,
Height_inches,
DOB,
Gender,
City,
Zip,
UsState,
PhoneNumber);
SourceForm.txtPatientID.Text = Patient_id;
SourceForm.btnPatientSearch_Click(SourceForm, e);
Close();
}
catch (Exception exception)
{
epLocal.SetError(btnGO, "Error Creating Patient");
}
2024-02-16 13:57:58 -05:00
}
catch (Exception ex)
2024-02-16 13:57:58 -05:00
{
epLocal.SetError(txtPhone, "Invalid Value");
2024-02-16 13:57:58 -05:00
}
}
catch (Exception ex)
{
epLocal.SetError(txtState, "Invalid Value");
2024-02-16 13:57:58 -05:00
}
}
catch (Exception ex)
{
epLocal.SetError(txtZip, "Invalid Value");
2024-02-16 13:57:58 -05:00
}
}
catch (Exception ex)
{
2024-02-19 22:24:03 -05:00
epLocal.SetError(cboGender, "Invalid Value");
2024-02-16 13:57:58 -05:00
}
}
catch (Exception ex)
{
epLocal.SetError(txtDOB, "Invalid Value");
2024-02-16 13:57:58 -05:00
}
}
catch (Exception ex)
{
epLocal.SetError(txtHeightIn, "Invalid Value");
2024-02-16 13:57:58 -05:00
}
}
catch (Exception ex)
{
epLocal.SetError(txtHeightFt, "Invalid Value");
2024-02-16 13:57:58 -05:00
}
}
catch (Exception ex)
{
epLocal.SetError(txtWeight, "Invalid Value");
2024-02-16 13:57:58 -05:00
}
}
private void btnClose_Click(object sender, EventArgs e)
{
Close();
2024-02-16 13:57:58 -05:00
}
}
}