Fixed update refill bug.

This commit is contained in:
Adam McCane 2024-02-20 14:57:03 -05:00
parent 545cd84540
commit c328e47946
2 changed files with 22 additions and 18 deletions

View File

@ -87,7 +87,7 @@ namespace Louis__Pharmacy_CNSA212_FP
if (dgvRefills.Rows.Count > 0)
{
dgvRefills.DataSource = ds.Tables[0];
//dgvRefills.DataSource = ds.Tables[0];
DataGridViewRow row = new DataGridViewRow();
row = dgvRefills.SelectedRows[0];
refillID = (row.Cells[0].Value).ToString();

View File

@ -14,6 +14,7 @@ namespace Louis__Pharmacy_CNSA212_FP
public partial class frmRefillAdd : Form
{
private static bool isAdd;
public DataSet ds = new DataSet();
public frmRefillAdd(bool isNew)
{
@ -57,7 +58,7 @@ namespace Louis__Pharmacy_CNSA212_FP
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();
txtRxNumber.Text = ds.Tables[0].Rows[0]["RxNum"].ToString();
txtRxNumber.Text = ds.Tables[0].Rows[0]["RxNum_id"].ToString();
}
private void btnAdd_Click(object sender, EventArgs e)
@ -82,31 +83,34 @@ namespace Louis__Pharmacy_CNSA212_FP
numRefills = Int32.Parse(ds.Tables[0].Rows[0]["numRefills"].ToString());
pastNumRefills = Int32.Parse(ds.Tables[0].Rows[0]["pastNumRefills"].ToString());
if (numRefills == pastNumRefills)
if (isAdd != true)
{
MessageBox.Show("This prescription has reached the maximum number of refills.", "Max Refill", MessageBoxButtons.OK, MessageBoxIcon.Error);
refillID = txtRefillID.Text.Trim();
date = DateTime.Parse(txtRefillDate.Text.Trim());
patientID = txtPatientID.Text.Trim();
medicationID = txtMedicationID.Text.Trim();
rxNum = txtRxNumber.Text.Trim();
PharmacyDataTier.UpdateRefill(refillID, date, patientID, medicationID, rxNum);
}
else
{
if (isAdd)
if (numRefills == pastNumRefills)
{
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);
MessageBox.Show("This prescription has reached the maximum number of refills.", "Max Refill", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
refillID = txtRefillID.Text.Trim();
date = DateTime.Parse(txtRefillDate.Text.Trim());
patientID = txtPatientID.Text.Trim();
medicationID = txtMedicationID.Text.Trim();
rxNum = txtRxNumber.Text.Trim();
if (isAdd)
{
refillID = txtRefillID.Text.Trim();
date = DateTime.Parse(txtRefillDate.Text.Trim());
patientID = txtPatientID.Text.Trim();
medicationID = txtMedicationID.Text.Trim();
PharmacyDataTier.UpdateRefill(refillID, date, patientID, medicationID, rxNum);
PharmacyDataTier.AddRefill(refillID, date, patientID, medicationID, rxNum);
PharmacyDataTier.PastRefills(rxNum);
}
}
}
}