CNSA-212-FP/Louis'-Pharmacy_CNSA212-FP/frmPrescription.cs
2024-02-20 17:26:44 -05:00

253 lines
7.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Net.NetworkInformation;
namespace Louis__Pharmacy_CNSA212_FP
{
public partial class frmPrescription : Form
{
private readonly bool isAdd;
private frmInfo SourceForm;
ErrorProvider epLocal = new ErrorProvider();
public frmPrescription(frmInfo sourceForm, bool isNew)
{
SourceForm = sourceForm;
isAdd = isNew;
InitializeComponent();
if (isNew)
{
lblDisPurpose.Text = "Add Prescription";
btnGO.Text = "Create";
}
else
{
lblDisPurpose.Text = "Edit Prescription";
btnGO.Text = "Update";
}
KeyPreview = true;
KeyDown += frmPrescription_KeyDown;
}
private void frmPrescription_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
Close();
if (e.KeyCode == Keys.Enter) btnGO_Click(sender, e);
}
public void FillPrescription(string rxNum, string medID, string physID, string patID)
{
var ds = new DataSet();
var data = new PharmacyDataTier();
ds = PharmacyDataTier.PrescriptionInfoSearch(rxNum,medID,physID,patID);
txtRxNum.Text = ds.Tables[0].Rows[0]["RxNum"].ToString();
txtPatID.Text = ds.Tables[0].Rows[0]["Patient_id"].ToString();
txtMedID.Text = ds.Tables[0].Rows[0]["Medication_id"].ToString();
txtPhysName.Text = ds.Tables[0].Rows[0]["Physician_name"].ToString();
txtPhysID.Text = ds.Tables[0].Rows[0]["Physician_id"].ToString();
txtCompletedRefills.Text = ds.Tables[0].Rows[0]["Completed_refills"].ToString();
txtMaxRefills.Text = ds.Tables[0].Rows[0]["Max_refills"].ToString();
}
public void FillPrescription(string rxNum)
{
var ds = new DataSet();
var data = new PharmacyDataTier();
ds = PharmacyDataTier.PrescriptionInfoSearch(rxNum);
txtRxNum.Text = ds.Tables[0].Rows[0]["RxNum_id"].ToString();
txtPatID.Text = ds.Tables[0].Rows[0]["Patient_id"].ToString();
txtMedID.Text = ds.Tables[0].Rows[0]["Medication_id"].ToString();
txtPhysName.Text = ds.Tables[0].Rows[0]["PrescribedBy"].ToString();
txtPhysID.Text = ds.Tables[0].Rows[0]["Physician_id"].ToString();
txtCompletedRefills.Text = ds.Tables[0].Rows[0]["pastNumRefills"].ToString();
txtMaxRefills.Text = ds.Tables[0].Rows[0]["numRefills"].ToString();
}
private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
private void btnGO_Click(object sender, EventArgs e)
{
var hasFailed = false;
var Patient_id = "";
var Medication_id = "";
var Physician_name = "";
var Physician_id = "";
var Completed_refills = "";
var Max_refills = "";
var RxNum = "";
if (txtMedID.Text.Length + txtPhysName.Text.Length + txtMedID.Text.Length + txtPhysID.Text.Length + txtCompletedRefills.Text.Length + txtMaxRefills.Text.Length + txtRxNum.Text.Length > 0)
{
try
{
RxNum = txtRxNum.Text;
if (RxNum.Length > 30)
{
throw new Exception();
}
}
catch (Exception exception)
{
epLocal.SetError(txtRxNum, "Invalid Value");
hasFailed = true;
}
try
{
Physician_id = txtPhysID.Text;
if (Physician_id.Length > 8)
{
throw new Exception();
}
}
catch (Exception exception)
{
epLocal.SetError(txtPhysID, "Invalid Value");
hasFailed = true;
}
try
{
Physician_name = txtPhysName.Text;
if (Physician_name.Length > 30)
{
throw new Exception();
}
}
catch (Exception exception)
{
epLocal.SetError(txtPhysName, "Invalid Value");
hasFailed = true;
}
try
{
Medication_id = txtMedID.Text;
if (Medication_id.Length > 7)
{
throw new Exception();
}
while (Medication_id.Length < 7)
{
RxNum = "0" + RxNum;
}
}
catch (Exception exception)
{
epLocal.SetError(txtMedID, "Invalid Value");
hasFailed = true;
}
if (!hasFailed)
{
if (isAdd)
{
PharmacyDataTier.CreatePrescription(
RxNum,
Patient_id,
Medication_id,
Physician_name,
Physician_id,
Completed_refills,
Max_refills);
}
else
{
PharmacyDataTier.UpdatePrescription(
RxNum,
Patient_id,
Medication_id,
Physician_name,
Physician_id,
Completed_refills,
Max_refills);
}
SourceForm.txtRxNumber.Text = RxNum;
//SourceForm.btnRxSearch_Click(sender, e);
Close();
}
}
}
private void frmPrescription_Load(object sender, EventArgs e)
{
//txtMedID.Enabled = false;
if (isAdd)
{
var nextID = PharmacyDataTier.GetNextRxNum();
txtMedID.Text = nextID.ToString();
}
}
private void txtMedID_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtMedID, "");
}
private void txtPhysName_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtPhysName, "");
}
private void txtPhysID_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtPhysID, "");
}
private void txtCompletedRefills_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtCompletedRefills, "");
}
private void txtMaxRefills_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtMaxRefills, "");
}
private void txtRxNum_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtRxNum, "");
}
private void btnGO_Click_1(object sender, EventArgs e)
{
}
}
}