380 lines
11 KiB
C#
380 lines
11 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Louis__Pharmacy_CNSA212_FP
|
|
{
|
|
public partial class frmPatient : Form
|
|
{
|
|
private static bool isAdd;
|
|
|
|
private readonly frmInfo SourceForm;
|
|
|
|
public frmPatient(frmInfo sourceForm, bool isNew)
|
|
{
|
|
SourceForm = sourceForm;
|
|
|
|
isAdd = isNew;
|
|
InitializeComponent();
|
|
|
|
txtState.MaxLength = 2;
|
|
|
|
if (isNew)
|
|
{
|
|
lblDisPurpose.Text = "Add Patient";
|
|
btnGO.Text = "Create";
|
|
}
|
|
else
|
|
{
|
|
lblDisPurpose.Text = "Edit Patient";
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
}
|
|
|
|
PharmacyDataTier.FillComboBox("GENDER","*","GenderValue",cboGender);
|
|
}
|
|
|
|
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();
|
|
cboGender.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();
|
|
}
|
|
|
|
ErrorProvider epLocal = new ErrorProvider();
|
|
private void btnGO_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
var Patient_id = txtPatientID.Text;
|
|
var FirstName = txtFname.Text;
|
|
var LastName = txtLname.Text;
|
|
var MiddleIntials = txtMidInit.Text;
|
|
var City = txtCity.Text;
|
|
|
|
int lbs = 0;
|
|
int Height_feet = 0;
|
|
int Height_inches = 0;
|
|
DateTime DOB = new DateTime(1753,1,1);
|
|
string Gender = "";
|
|
short Zip = 0;
|
|
string UsState = "";
|
|
string PhoneNumber= "";
|
|
|
|
var parseHasFailed = false;
|
|
|
|
int intLimit = 2147483647;
|
|
|
|
|
|
if (City.Length > 30)
|
|
{
|
|
epLocal.SetError(txtCity, "Invalid Value");
|
|
parseHasFailed = true;
|
|
}
|
|
if (MiddleIntials.Length > 1)
|
|
{
|
|
epLocal.SetError(txtMidInit, "Invalid Value");
|
|
parseHasFailed = true;
|
|
}
|
|
if (LastName.Length > 30)
|
|
{
|
|
epLocal.SetError(txtLname, "Invalid Value");
|
|
parseHasFailed = true;
|
|
}
|
|
if (FirstName.Length > 30)
|
|
{
|
|
epLocal.SetError(txtFname, "Invalid Value");
|
|
parseHasFailed = true;
|
|
}
|
|
|
|
if (Patient_id.Length > 8)
|
|
{
|
|
epLocal.SetError(txtPatientID, "Invalid Value");
|
|
parseHasFailed = true;
|
|
}
|
|
else
|
|
{
|
|
while (Patient_id.Length < 8)
|
|
{
|
|
Patient_id = "0" + Patient_id;
|
|
}
|
|
}
|
|
|
|
|
|
try
|
|
{
|
|
|
|
if (txtPhone.Text.Length>0)
|
|
{
|
|
PhoneNumber = txtPhone.Text;
|
|
if (PhoneNumber.Length > 14)
|
|
{
|
|
throw new Exception();
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(txtPhone, "Invalid value");
|
|
parseHasFailed = true;
|
|
}
|
|
try
|
|
{
|
|
|
|
if (txtState.Text.Length > 0)
|
|
{
|
|
UsState = txtState.Text.ToUpper();
|
|
|
|
if (UsState.Length > 2)
|
|
{
|
|
throw new Exception();
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(txtState, "Invalid value");
|
|
parseHasFailed = true;
|
|
}
|
|
|
|
try
|
|
{
|
|
|
|
if (txtZip.Text.Length > 0)
|
|
{
|
|
Zip = short.Parse(txtZip.Text);
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(txtZip, "Invalid value");
|
|
parseHasFailed = true;
|
|
}
|
|
|
|
try
|
|
{
|
|
|
|
Gender = cboGender.Text;
|
|
|
|
if (Gender != "M" && Gender != "F")
|
|
{
|
|
throw new Exception();
|
|
}
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(cboGender, "Invalid value");
|
|
parseHasFailed = true;
|
|
}
|
|
try
|
|
{
|
|
|
|
if (txtDOB.Text.Length > 0)
|
|
{
|
|
DOB = DateTime.Parse(txtDOB.Text);
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(txtDOB, "Invalid value");
|
|
parseHasFailed = true;
|
|
}
|
|
try
|
|
{
|
|
|
|
if (txtHeightIn.Text.Length > 0)
|
|
{
|
|
Height_inches = int.Parse(txtHeightIn.Text);
|
|
if (Height_inches > 11 || Height_inches < 0)
|
|
{
|
|
throw new Exception();
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(txtHeightIn, "Invalid value");
|
|
parseHasFailed = true;
|
|
}
|
|
|
|
|
|
try
|
|
{
|
|
|
|
if (txtHeightFt.Text.Length > 0)
|
|
{
|
|
Height_feet = int.Parse(txtHeightFt.Text);
|
|
if (Height_feet > 11 || Height_feet < 0)
|
|
{
|
|
throw new Exception();
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(txtHeightFt, "Invalid value");
|
|
parseHasFailed = true;
|
|
}
|
|
|
|
try
|
|
{
|
|
|
|
if (txtWeight.Text.Length > 0)
|
|
{
|
|
lbs = int.Parse(txtWeight.Text);
|
|
if (lbs > intLimit || lbs < 0)
|
|
{
|
|
throw new Exception();
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(txtWeight, "Invalid value");
|
|
parseHasFailed = true;
|
|
}
|
|
|
|
|
|
if (isAdd && !parseHasFailed)
|
|
{
|
|
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(sender,e);
|
|
Close();
|
|
}
|
|
else if (!isAdd && !parseHasFailed)
|
|
{
|
|
PharmacyDataTier.UpdatePatient(Patient_id, FirstName, LastName, MiddleIntials, lbs, Height_feet, Height_inches, DOB, Gender, City, Zip, UsState, PhoneNumber);
|
|
|
|
SourceForm.txtPatientID.Text = Patient_id;
|
|
SourceForm.btnPatientSearch_Click(sender,e);
|
|
Close();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void txtPatientID_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtPatientID, "");
|
|
}
|
|
|
|
private void txtFname_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtFname, "");
|
|
}
|
|
|
|
private void txtLname_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtLname, "");
|
|
}
|
|
|
|
private void txtMidInit_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtMidInit, "");
|
|
}
|
|
|
|
private void txtWeight_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtWeight, "");
|
|
}
|
|
|
|
private void txtHeightFt_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtHeightFt, "");
|
|
}
|
|
|
|
private void txtHeightIn_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtHeightIn, "");
|
|
}
|
|
|
|
private void txtDOB_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtDOB, "");
|
|
}
|
|
|
|
private void txtCity_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtCity, "");
|
|
}
|
|
|
|
private void cboGender_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(cboGender, "");
|
|
}
|
|
|
|
private void txtZip_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtZip, "");
|
|
}
|
|
|
|
private void txtState_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtState, "");
|
|
}
|
|
|
|
private void txtPhone_TextChanged(object sender, EventArgs e)
|
|
{
|
|
epLocal.SetError(txtPhone, "");
|
|
}
|
|
}
|
|
} |