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) if (dgvRefills.Rows.Count > 0)
{ {
dgvRefills.DataSource = ds.Tables[0]; //dgvRefills.DataSource = ds.Tables[0];
DataGridViewRow row = new DataGridViewRow(); DataGridViewRow row = new DataGridViewRow();
row = dgvRefills.SelectedRows[0]; row = dgvRefills.SelectedRows[0];
refillID = (row.Cells[0].Value).ToString(); refillID = (row.Cells[0].Value).ToString();

View File

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