2024-02-16 20:13:30 -05:00
|
|
|
|
using System;
|
2024-02-19 10:47:16 -05:00
|
|
|
|
using System.Data;
|
2024-02-19 11:56:51 -05:00
|
|
|
|
using System.Windows.Forms;
|
2024-02-20 14:50:47 -05:00
|
|
|
|
using DateTime = System.DateTime;
|
2024-02-16 19:41:26 -05:00
|
|
|
|
|
|
|
|
|
namespace Louis__Pharmacy_CNSA212_FP
|
|
|
|
|
{
|
|
|
|
|
public partial class frmPhysician : Form
|
|
|
|
|
{
|
2024-02-19 11:56:51 -05:00
|
|
|
|
private readonly bool isAdd;
|
2024-02-16 20:13:30 -05:00
|
|
|
|
private frmInfo SourceForm;
|
2024-02-19 11:56:51 -05:00
|
|
|
|
|
2024-02-16 20:13:30 -05:00
|
|
|
|
public frmPhysician(frmInfo sourceForm, bool isNew)
|
2024-02-16 19:41:26 -05:00
|
|
|
|
{
|
2024-02-16 20:13:30 -05:00
|
|
|
|
SourceForm = sourceForm;
|
2024-02-19 11:56:51 -05:00
|
|
|
|
|
2024-02-16 20:13:30 -05:00
|
|
|
|
isAdd = isNew;
|
2024-02-16 19:41:26 -05:00
|
|
|
|
InitializeComponent();
|
2024-02-16 20:13:30 -05:00
|
|
|
|
|
|
|
|
|
txtState.MaxLength = 2;
|
|
|
|
|
|
|
|
|
|
if (isNew)
|
|
|
|
|
{
|
2024-02-19 10:47:16 -05:00
|
|
|
|
lblDisPurpose.Text = "Add Physician";
|
|
|
|
|
btnGO.Text = "Create";
|
2024-02-16 20:13:30 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-19 10:47:16 -05:00
|
|
|
|
lblDisPurpose.Text = "Edit Physician";
|
|
|
|
|
btnGO.Text = "Update";
|
2024-02-16 20:13:30 -05:00
|
|
|
|
}
|
2024-02-19 14:19:36 -05:00
|
|
|
|
KeyPreview = true;
|
|
|
|
|
KeyDown += frmPhysician_KeyDown;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-19 14:37:25 -05:00
|
|
|
|
ErrorProvider epLocal = new ErrorProvider();
|
2024-02-19 14:19:36 -05:00
|
|
|
|
private void frmPhysician_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Escape)
|
|
|
|
|
Close();
|
|
|
|
|
|
|
|
|
|
if (e.KeyCode == Keys.Enter) btnGO_Click(sender, e);
|
2024-02-19 14:37:25 -05:00
|
|
|
|
|
2024-02-16 20:13:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-02-19 11:56:51 -05:00
|
|
|
|
Close();
|
2024-02-16 20:13:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnGO_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-02-19 14:37:25 -05:00
|
|
|
|
|
2024-02-19 11:56:51 -05:00
|
|
|
|
|
|
|
|
|
var hasFailed = false;
|
|
|
|
|
|
|
|
|
|
var Physician_id = "";
|
|
|
|
|
var FirstName = "";
|
|
|
|
|
var LastName = "";
|
|
|
|
|
var MiddleIntials = "";
|
|
|
|
|
var City = "";
|
|
|
|
|
short Zip = 0;
|
|
|
|
|
var UsState = "";
|
2024-02-20 14:50:47 -05:00
|
|
|
|
DateTime DOB = new DateTime(1753, 1, 1);
|
2024-02-19 11:56:51 -05:00
|
|
|
|
var PhoneNumber = "";
|
|
|
|
|
var Gender = "";
|
|
|
|
|
var Speciality = "";
|
|
|
|
|
|
|
|
|
|
if (txtFirstName.Text.Length + txtLastName.Text.Length + txtMiddleInit.Text.Length + txtCity.Text.Length +
|
|
|
|
|
txtZip.Text.Length + txtState.Text.Length + txtDOB.Text.Length + txtGender.Text.Length
|
|
|
|
|
+ txtPhone.Text.Length + txtSpeciality.Text.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (txtSpeciality.Text.Length <= 100)
|
|
|
|
|
Speciality = txtSpeciality.Text;
|
|
|
|
|
else
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtSpeciality, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (txtGender.Text.Length == 1)
|
|
|
|
|
Gender = txtGender.Text.ToUpper();
|
|
|
|
|
else if (txtGender.Text.Length == 0)
|
|
|
|
|
Gender = "NA";
|
|
|
|
|
else
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtGender, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (txtPhone.Text.Length <= 14)
|
|
|
|
|
PhoneNumber = txtPhone.Text;
|
|
|
|
|
else
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtPhone, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (txtDOB.Text.Length > 0)
|
|
|
|
|
DOB = DateTime.Parse(txtDOB.Text);
|
2024-02-19 14:37:25 -05:00
|
|
|
|
if (DOB < new DateTime(1753,1,1))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
2024-02-19 11:56:51 -05:00
|
|
|
|
else
|
|
|
|
|
DOB = new DateTime(1753, 1, 1);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtDOB, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (txtState.Text.Length <= 2)
|
|
|
|
|
UsState = txtState.Text;
|
|
|
|
|
else
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtState, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-02-20 14:50:47 -05:00
|
|
|
|
if (txtZip.Text.Length <= 5 && txtZip.Text.Length > 0)
|
2024-02-19 11:56:51 -05:00
|
|
|
|
Zip = short.Parse(txtZip.Text);
|
|
|
|
|
else if (txtZip.Text.Length == 0)
|
|
|
|
|
Zip = 0;
|
|
|
|
|
else
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtZip, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (txtCity.Text.Length <= 30)
|
|
|
|
|
City = txtCity.Text;
|
|
|
|
|
else
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtCity, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (txtMiddleInit.Text.Length <= 1)
|
|
|
|
|
MiddleIntials = txtMiddleInit.Text;
|
|
|
|
|
else
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtMiddleInit, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 14:50:47 -05:00
|
|
|
|
|
|
|
|
|
if (txtLastName.Text.Length <= 30 && txtLastName.Text.Length>=1)
|
2024-02-19 11:56:51 -05:00
|
|
|
|
{
|
2024-02-20 14:50:47 -05:00
|
|
|
|
LastName = txtLastName.Text;
|
|
|
|
|
}else if (txtLastName.Text.Length < 1)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtLastName, "Must Provide a Last Name");
|
|
|
|
|
hasFailed = true;
|
2024-02-19 11:56:51 -05:00
|
|
|
|
}
|
2024-02-20 14:50:47 -05:00
|
|
|
|
else
|
2024-02-19 11:56:51 -05:00
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtLastName, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 14:50:47 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (txtFirstName.Text.Length <= 30 && txtFirstName.Text.Length>=1)
|
2024-02-19 11:56:51 -05:00
|
|
|
|
{
|
2024-02-20 14:50:47 -05:00
|
|
|
|
FirstName = txtFirstName.Text;
|
|
|
|
|
}else if (txtFirstName.Text.Length < 1)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtFirstName, "Must Provide a First Name");
|
|
|
|
|
hasFailed = true;
|
2024-02-19 11:56:51 -05:00
|
|
|
|
}
|
2024-02-20 14:50:47 -05:00
|
|
|
|
else
|
2024-02-19 11:56:51 -05:00
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtFirstName, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
2024-02-20 14:50:47 -05:00
|
|
|
|
|
|
|
|
|
|
2024-02-19 11:56:51 -05:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (txtPhyID.Text.Length <= 8)
|
|
|
|
|
Physician_id = txtPhyID.Text;
|
|
|
|
|
else
|
|
|
|
|
throw new Exception();
|
|
|
|
|
|
|
|
|
|
while (Physician_id.Length < 8) Physician_id = "0" + Physician_id;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
epLocal.SetError(txtPhyID, "Invalid Value");
|
|
|
|
|
hasFailed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(exception);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hasFailed)
|
|
|
|
|
{
|
2024-02-19 13:38:27 -05:00
|
|
|
|
if (isAdd)
|
|
|
|
|
{
|
2024-02-19 11:56:51 -05:00
|
|
|
|
PharmacyDataTier.CreatePhysician(
|
|
|
|
|
Physician_id,
|
|
|
|
|
FirstName,
|
|
|
|
|
LastName,
|
|
|
|
|
MiddleIntials,
|
|
|
|
|
DOB,
|
|
|
|
|
Gender,
|
|
|
|
|
City,
|
|
|
|
|
Zip,
|
|
|
|
|
UsState,
|
|
|
|
|
PhoneNumber,
|
|
|
|
|
Speciality);
|
2024-02-19 13:38:27 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PharmacyDataTier.UpdatePhysician(
|
|
|
|
|
Physician_id,
|
|
|
|
|
FirstName,
|
|
|
|
|
LastName,
|
|
|
|
|
MiddleIntials,
|
|
|
|
|
DOB,
|
|
|
|
|
Gender,
|
|
|
|
|
City,
|
|
|
|
|
Zip,
|
|
|
|
|
UsState,
|
|
|
|
|
PhoneNumber,
|
|
|
|
|
Speciality);
|
|
|
|
|
}
|
2024-02-19 11:56:51 -05:00
|
|
|
|
|
|
|
|
|
SourceForm.txtPhysicianID.Text = Physician_id;
|
|
|
|
|
SourceForm.btnPhysicianSearch_Click(sender, e);
|
|
|
|
|
Close();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2024-02-20 14:50:47 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("You Must Enter Some Information!", "", MessageBoxButtons.OK);
|
|
|
|
|
}
|
2024-02-16 19:41:26 -05:00
|
|
|
|
}
|
2024-02-19 10:47:16 -05:00
|
|
|
|
|
|
|
|
|
private void frmPhysician_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
txtPhyID.Enabled = false;
|
|
|
|
|
|
|
|
|
|
if (isAdd)
|
|
|
|
|
{
|
|
|
|
|
var nextID = PharmacyDataTier.GetNextPhysicianID();
|
|
|
|
|
txtPhyID.Text = nextID.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-19 11:56:51 -05:00
|
|
|
|
|
2024-02-19 10:47:16 -05:00
|
|
|
|
public void FillPhysician(string phyID)
|
|
|
|
|
{
|
|
|
|
|
var ds = new DataSet();
|
|
|
|
|
var data = new PharmacyDataTier();
|
|
|
|
|
|
|
|
|
|
ds = PharmacyDataTier.PhysicianInfoSearch(phyID);
|
|
|
|
|
txtPhyID.Text = ds.Tables[0].Rows[0]["Physician_id"].ToString();
|
|
|
|
|
txtFirstName.Text = ds.Tables[0].Rows[0]["FirstName"].ToString();
|
|
|
|
|
txtLastName.Text = ds.Tables[0].Rows[0]["LastName"].ToString();
|
|
|
|
|
txtMiddleInit.Text = ds.Tables[0].Rows[0]["MiddleIntials"].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();
|
|
|
|
|
txtSpeciality.Text = ds.Tables[0].Rows[0]["Specialty"].ToString();
|
|
|
|
|
}
|
2024-02-19 14:37:25 -05:00
|
|
|
|
|
|
|
|
|
private void txtPhyID_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtPhyID, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtFirstName_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtFirstName, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtLastName_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtLastName, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtMiddleInit_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtMiddleInit, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtDOB_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtDOB, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtGender_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtGender, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtSpeciality_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtSpeciality, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtCity_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtCity, "");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtState_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtState, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtZip_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtZip, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtPhone_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
epLocal.SetError(txtPhone, "");
|
|
|
|
|
}
|
2024-02-16 19:41:26 -05:00
|
|
|
|
}
|
|
|
|
|
}
|