CNSA-212-FP/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.cs

138 lines
4.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Louis__Pharmacy_CNSA212_FP
{
public partial class frmRefillAdd : Form
{
private static bool isAdd;
2024-02-20 11:57:03 -08:00
public DataSet ds = new DataSet();
public string currentID = "";
public frmRefillAdd(bool isNew)
{
isAdd = isNew;
InitializeComponent();
if (isNew)
{
lblPurpose.Text = "Add Refill";
btnAdd.Text = "Add";
}
else
{
lblPurpose.Text = "Edit Refill";
btnAdd.Text = "Edit";
}
}
private void frmRefillAdd_Load(object sender, EventArgs e)
{
txtRefillID.Enabled = false;
if (isAdd)
{
double nextID = PharmacyDataTier.GetNextRefillID();
txtRefillID.Text = nextID.ToString();
}
else
{
}
}
public void FillRefill(string refillID)
{
DataSet ds = new DataSet();
PharmacyDataTier data = new PharmacyDataTier();
ds = PharmacyDataTier.RefillSearch(refillID);
txtRefillID.Text = ds.Tables[0].Rows[0]["Refill_id"].ToString();
txtRefillDate.Text = ds.Tables[0].Rows[0]["RefillDate"].ToString();
txtPatientID.Text = ds.Tables[0].Rows[0]["Patient_id"].ToString();
txtMedicationID.Text = ds.Tables[0].Rows[0]["Medication_id"].ToString();
2024-02-20 11:57:03 -08:00
txtRxNumber.Text = ds.Tables[0].Rows[0]["RxNum_id"].ToString();
currentID = txtRxNumber.Text;
}
private void btnAdd_Click(object sender, EventArgs e)
{
string refillID = "";
DateTime date = new DateTime();
string patientID = "";
string medicationID = "";
string rxNum = "";
Int32 numRefills = 0;
Int32 pastNumRefills = 0;
rxNum = txtRxNumber.Text.Trim();
try
{
DataSet ds = new DataSet();
PharmacyDataTier phaDT = new PharmacyDataTier();
ds = phaDT.NumberofRefills(rxNum);
numRefills = Int32.Parse(ds.Tables[0].Rows[0]["numRefills"].ToString());
pastNumRefills = Int32.Parse(ds.Tables[0].Rows[0]["pastNumRefills"].ToString());
2024-02-20 11:57:03 -08:00
if (isAdd != true)
{
2024-02-20 11:57:03 -08:00
refillID = txtRefillID.Text.Trim();
date = DateTime.Parse(txtRefillDate.Text.Trim());
patientID = txtPatientID.Text.Trim();
medicationID = txtMedicationID.Text.Trim();
rxNum = txtRxNumber.Text.Trim();
frmRefill refill = new frmRefill(0);
2024-02-20 11:57:03 -08:00
PharmacyDataTier.UpdateRefill(refillID, date, patientID, medicationID, rxNum);
if (currentID != rxNum)
{
PharmacyDataTier.DecrementPastRefills(currentID);
PharmacyDataTier.PastRefills(rxNum);
}
}
else
{
//if (numRefills == pastNumRefills)
//{
// MessageBox.Show("This prescription has reached the maximum number of refills.", "Max Refill", MessageBoxButtons.OK, MessageBoxIcon.Error);
//}
//else
//{
// if (isAdd)
// {
// refillID = txtRefillID.Text.Trim();
// date = DateTime.Parse(txtRefillDate.Text.Trim());
// patientID = txtPatientID.Text.Trim();
// medicationID = txtMedicationID.Text.Trim();
// PharmacyDataTier.AddRefill(refillID, date, patientID, medicationID, rxNum);
// PharmacyDataTier.PastRefills(rxNum);
// }
//}
}
}
catch (Exception exception)
{
}
}
}
}