300 lines
9.5 KiB
C#
300 lines
9.5 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Louis__Pharmacy_CNSA212_FP
|
|
{
|
|
public partial class frmPhysician : Form
|
|
{
|
|
private readonly bool isAdd;
|
|
private frmInfo SourceForm;
|
|
|
|
public frmPhysician(frmInfo sourceForm, bool isNew)
|
|
{
|
|
SourceForm = sourceForm;
|
|
|
|
isAdd = isNew;
|
|
InitializeComponent();
|
|
|
|
txtState.MaxLength = 2;
|
|
|
|
if (isNew)
|
|
{
|
|
lblDisPurpose.Text = "Add Physician";
|
|
btnGO.Text = "Create";
|
|
}
|
|
else
|
|
{
|
|
lblDisPurpose.Text = "Edit Physician";
|
|
btnGO.Text = "Update";
|
|
}
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void btnGO_Click(object sender, EventArgs e)
|
|
{
|
|
var epLocal = new ErrorProvider();
|
|
|
|
var hasFailed = false;
|
|
|
|
var Physician_id = "";
|
|
var FirstName = "";
|
|
var LastName = "";
|
|
var MiddleIntials = "";
|
|
var City = "";
|
|
short Zip = 0;
|
|
var UsState = "";
|
|
var DOB = new DateTime(1753, 1, 1);
|
|
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);
|
|
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
|
|
{
|
|
if (txtZip.Text.Length <= 5)
|
|
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;
|
|
}
|
|
|
|
try
|
|
{
|
|
if (txtLastName.Text.Length <= 30)
|
|
LastName = txtLastName.Text;
|
|
else
|
|
throw new Exception();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(txtLastName, "Invalid Value");
|
|
hasFailed = true;
|
|
}
|
|
|
|
try
|
|
{
|
|
if (txtFirstName.Text.Length <= 30)
|
|
FirstName = txtFirstName.Text;
|
|
else
|
|
throw new Exception();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(txtFirstName, "Invalid Value");
|
|
hasFailed = true;
|
|
}
|
|
|
|
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
|
|
{
|
|
Zip = short.Parse(txtZip.Text);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
epLocal.SetError(txtZip, "Invalid Value");
|
|
hasFailed = true;
|
|
}
|
|
|
|
try
|
|
{
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Console.WriteLine(exception);
|
|
throw;
|
|
}
|
|
|
|
if (!hasFailed)
|
|
{
|
|
if (isAdd)
|
|
{
|
|
PharmacyDataTier.CreatePhysician(
|
|
Physician_id,
|
|
FirstName,
|
|
LastName,
|
|
MiddleIntials,
|
|
DOB,
|
|
Gender,
|
|
City,
|
|
Zip,
|
|
UsState,
|
|
PhoneNumber,
|
|
Speciality);
|
|
}
|
|
else
|
|
{
|
|
PharmacyDataTier.UpdatePhysician(
|
|
Physician_id,
|
|
FirstName,
|
|
LastName,
|
|
MiddleIntials,
|
|
DOB,
|
|
Gender,
|
|
City,
|
|
Zip,
|
|
UsState,
|
|
PhoneNumber,
|
|
Speciality);
|
|
}
|
|
|
|
SourceForm.txtPhysicianID.Text = Physician_id;
|
|
SourceForm.btnPhysicianSearch_Click(sender, e);
|
|
Close();
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void frmPhysician_Load(object sender, EventArgs e)
|
|
{
|
|
txtPhyID.Enabled = false;
|
|
|
|
if (isAdd)
|
|
{
|
|
var nextID = PharmacyDataTier.GetNextPhysicianID();
|
|
txtPhyID.Text = nextID.ToString();
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
} |