Update frmPrescription.cs code to the code before reverting

This commit is contained in:
Noah 2024-02-20 12:52:10 -05:00
parent 994df5e702
commit a08b3065c8
2 changed files with 225 additions and 11 deletions

View File

@ -35,7 +35,7 @@ namespace Louis__Pharmacy_CNSA212_FP
this.txtPhysName = new System.Windows.Forms.TextBox();
this.txtMedID = new System.Windows.Forms.TextBox();
this.txtPatID = new System.Windows.Forms.TextBox();
this.txtRxNumber = new System.Windows.Forms.TextBox();
this.txtRxNum = new System.Windows.Forms.TextBox();
this.lblDisPurpose = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.btnGO = new System.Windows.Forms.Button();
@ -96,13 +96,13 @@ namespace Louis__Pharmacy_CNSA212_FP
this.txtPatID.Size = new System.Drawing.Size(163, 22);
this.txtPatID.TabIndex = 28;
//
// txtRxNumber
// txtRxNum
//
this.txtRxNumber.Location = new System.Drawing.Point(433, 141);
this.txtRxNumber.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtRxNumber.Name = "txtRxNumber";
this.txtRxNumber.Size = new System.Drawing.Size(163, 22);
this.txtRxNumber.TabIndex = 27;
this.txtRxNum.Location = new System.Drawing.Point(433, 141);
this.txtRxNum.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtRxNum.Name = "txtRxNum";
this.txtRxNum.Size = new System.Drawing.Size(163, 22);
this.txtRxNum.TabIndex = 27;
//
// lblDisPurpose
//
@ -207,7 +207,7 @@ namespace Louis__Pharmacy_CNSA212_FP
this.Controls.Add(this.txtPhysName);
this.Controls.Add(this.txtMedID);
this.Controls.Add(this.txtPatID);
this.Controls.Add(this.txtRxNumber);
this.Controls.Add(this.txtRxNum);
this.Controls.Add(this.lblDisPurpose);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnGO);
@ -234,7 +234,7 @@ namespace Louis__Pharmacy_CNSA212_FP
private System.Windows.Forms.TextBox txtPhysName;
private System.Windows.Forms.TextBox txtMedID;
private System.Windows.Forms.TextBox txtPatID;
private System.Windows.Forms.TextBox txtRxNumber;
private System.Windows.Forms.TextBox txtRxNum;
private System.Windows.Forms.Label lblDisPurpose;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnGO;

View File

@ -8,16 +8,230 @@ 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
{
public frmPrescription()
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 rxID)
{
var ds = new DataSet();
var data = new PharmacyDataTier();
ds = PharmacyDataTier.PrescriptionInfoSearch(rxID);
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();
}
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.btnPrescriptionSearch_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)
{
}