From 263848a354a5aa0d579cbf240f2153ac5cc7d9f8 Mon Sep 17 00:00:00 2001 From: Adam McCane Date: Tue, 20 Feb 2024 01:24:59 -0500 Subject: [PATCH] Working on add blocking functionality in the refill add form. --- .../PharmacyDataTier.cs | 36 +++++++ .../frmRefill.Designer.cs | 94 +++++++++---------- Louis'-Pharmacy_CNSA212-FP/frmRefill.cs | 6 +- Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.cs | 44 ++++++--- 4 files changed, 115 insertions(+), 65 deletions(-) diff --git a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs index 25b302e..0a864b8 100644 --- a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs +++ b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs @@ -529,6 +529,42 @@ namespace Louis__Pharmacy_CNSA212_FP } } + public static DataSet NumberofRefills(string rxID) + { + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "NumberofRefills"; + // Define input parameter + cmdString.Parameters.Add("@rxID", SqlDbType.VarChar, 11).Value = rxID; + // adapter and dataset + SqlDataAdapter aAdapter = new SqlDataAdapter(); + aAdapter.SelectCommand = cmdString; + DataSet aDataSet = new DataSet(); + + // fill adapter + aAdapter.Fill(aDataSet); + + // return dataSet + return aDataSet; + } + catch (Exception ex) + { + throw new ArgumentException(ex.Message); + } + finally + { + myConn.Close(); + } + } + public static DataSet PhysicianInfoSearch(string fname,string lname, string phyID) { diff --git a/Louis'-Pharmacy_CNSA212-FP/frmRefill.Designer.cs b/Louis'-Pharmacy_CNSA212-FP/frmRefill.Designer.cs index e4dfd84..f4316a0 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmRefill.Designer.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmRefill.Designer.cs @@ -45,11 +45,6 @@ namespace Louis__Pharmacy_CNSA212_FP this.bindingNavigatorSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.rEFILLSBindingNavigatorSaveItem = new System.Windows.Forms.ToolStripButton(); this.dgvRefills = new System.Windows.Forms.DataGridView(); - this.refillid = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.refilldate = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.patientid = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.medicationid = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.rxnumber = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.cmuRefill = new System.Windows.Forms.ContextMenuStrip(this.components); this.cmuAdd = new System.Windows.Forms.ToolStripMenuItem(); this.cmuUpdate = new System.Windows.Forms.ToolStripMenuItem(); @@ -60,6 +55,11 @@ namespace Louis__Pharmacy_CNSA212_FP this.btnSearch = new System.Windows.Forms.Button(); this.lblPatientID = new System.Windows.Forms.Label(); this.lblDate = new System.Windows.Forms.Label(); + this.refillid = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.refilldate = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.patientid = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.medicationid = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.rxnumber = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dgvRefills)).BeginInit(); this.cmuRefill.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); @@ -147,39 +147,6 @@ namespace Louis__Pharmacy_CNSA212_FP this.dgvRefills.Size = new System.Drawing.Size(625, 239); this.dgvRefills.TabIndex = 0; // - // refillid - // - this.refillid.DataPropertyName = "Refill_id"; - this.refillid.HeaderText = "Refill ID"; - this.refillid.Name = "refillid"; - // - // refilldate - // - this.refilldate.DataPropertyName = "RefillDate"; - dataGridViewCellStyle1.Format = "d"; - dataGridViewCellStyle1.NullValue = null; - this.refilldate.DefaultCellStyle = dataGridViewCellStyle1; - this.refilldate.HeaderText = "Date of Refill"; - this.refilldate.Name = "refilldate"; - // - // patientid - // - this.patientid.DataPropertyName = "Patient_id"; - this.patientid.HeaderText = "Patient ID"; - this.patientid.Name = "patientid"; - // - // medicationid - // - this.medicationid.DataPropertyName = "Medication_id"; - this.medicationid.HeaderText = "Medication ID"; - this.medicationid.Name = "medicationid"; - // - // rxnumber - // - this.rxnumber.DataPropertyName = "RxNum"; - this.rxnumber.HeaderText = "Rx Number"; - this.rxnumber.Name = "rxnumber"; - // // cmuRefill // this.cmuRefill.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -187,26 +154,26 @@ namespace Louis__Pharmacy_CNSA212_FP this.cmuUpdate, this.cmuDelete}); this.cmuRefill.Name = "contextMenuStrip1"; - this.cmuRefill.Size = new System.Drawing.Size(181, 92); + this.cmuRefill.Size = new System.Drawing.Size(113, 70); // // cmuAdd // this.cmuAdd.Name = "cmuAdd"; - this.cmuAdd.Size = new System.Drawing.Size(180, 22); + this.cmuAdd.Size = new System.Drawing.Size(112, 22); this.cmuAdd.Text = "Add"; this.cmuAdd.Click += new System.EventHandler(this.cmuAdd_Click); // // cmuUpdate // this.cmuUpdate.Name = "cmuUpdate"; - this.cmuUpdate.Size = new System.Drawing.Size(180, 22); + this.cmuUpdate.Size = new System.Drawing.Size(112, 22); this.cmuUpdate.Text = "Update"; this.cmuUpdate.Click += new System.EventHandler(this.cmuUpdate_Click); // // cmuDelete // this.cmuDelete.Name = "cmuDelete"; - this.cmuDelete.Size = new System.Drawing.Size(180, 22); + this.cmuDelete.Size = new System.Drawing.Size(112, 22); this.cmuDelete.Text = "Delete"; this.cmuDelete.Click += new System.EventHandler(this.cmuDelete_Click); // @@ -273,6 +240,39 @@ namespace Louis__Pharmacy_CNSA212_FP this.lblDate.TabIndex = 0; this.lblDate.Text = "Date of Refill:"; // + // refillid + // + this.refillid.DataPropertyName = "Refill_id"; + this.refillid.HeaderText = "Refill ID"; + this.refillid.Name = "refillid"; + // + // refilldate + // + this.refilldate.DataPropertyName = "RefillDate"; + dataGridViewCellStyle1.Format = "d"; + dataGridViewCellStyle1.NullValue = null; + this.refilldate.DefaultCellStyle = dataGridViewCellStyle1; + this.refilldate.HeaderText = "Date of Refill"; + this.refilldate.Name = "refilldate"; + // + // patientid + // + this.patientid.DataPropertyName = "Patient_id"; + this.patientid.HeaderText = "Patient ID"; + this.patientid.Name = "patientid"; + // + // medicationid + // + this.medicationid.DataPropertyName = "Medication_id"; + this.medicationid.HeaderText = "Medication ID"; + this.medicationid.Name = "medicationid"; + // + // rxnumber + // + this.rxnumber.DataPropertyName = "RxNum_id"; + this.rxnumber.HeaderText = "Rx Number ID"; + this.rxnumber.Name = "rxnumber"; + // // frmRefill // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -324,11 +324,6 @@ namespace Louis__Pharmacy_CNSA212_FP private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn14; private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn15; private System.Windows.Forms.DataGridView dgvRefills; - private System.Windows.Forms.DataGridViewTextBoxColumn refillid; - private System.Windows.Forms.DataGridViewTextBoxColumn refilldate; - private System.Windows.Forms.DataGridViewTextBoxColumn patientid; - private System.Windows.Forms.DataGridViewTextBoxColumn medicationid; - private System.Windows.Forms.DataGridViewTextBoxColumn rxnumber; private System.Windows.Forms.ContextMenuStrip cmuRefill; private System.Windows.Forms.ToolStripMenuItem cmuAdd; private System.Windows.Forms.ToolStripMenuItem cmuUpdate; @@ -339,5 +334,10 @@ namespace Louis__Pharmacy_CNSA212_FP private System.Windows.Forms.Button btnSearch; private System.Windows.Forms.Label lblPatientID; private System.Windows.Forms.Label lblDate; + private System.Windows.Forms.DataGridViewTextBoxColumn refillid; + private System.Windows.Forms.DataGridViewTextBoxColumn refilldate; + private System.Windows.Forms.DataGridViewTextBoxColumn patientid; + private System.Windows.Forms.DataGridViewTextBoxColumn medicationid; + private System.Windows.Forms.DataGridViewTextBoxColumn rxnumber; } } \ No newline at end of file diff --git a/Louis'-Pharmacy_CNSA212-FP/frmRefill.cs b/Louis'-Pharmacy_CNSA212-FP/frmRefill.cs index 2c7566f..b728c52 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmRefill.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmRefill.cs @@ -41,7 +41,7 @@ namespace Louis__Pharmacy_CNSA212_FP try { - //DataSet ds = new DataSet(); + DataSet ds = new DataSet(); //PharmacyDataTier phaDT = new PharmacyDataTier(); patientID = txtPatientID.Text.Trim(); @@ -50,7 +50,7 @@ namespace Louis__Pharmacy_CNSA212_FP date = DateTime.Parse(txtDate.Text.Trim()); } - ds = PharmacyDataTier.RefillSearch(date, patientID); + ds = PharmacyDataTier.RefillSearch(date, patientID); if (ds.Tables[0].Rows.Count > 0 ) { @@ -105,7 +105,7 @@ namespace Louis__Pharmacy_CNSA212_FP { string refillID = ""; - dgvRefills.DataSource = ds.Tables[0]; + //dgvRefills.DataSource = ds.Tables[0]; DataGridViewRow row = new DataGridViewRow(); row = dgvRefills.SelectedRows[0]; refillID = (row.Cells[0].Value).ToString(); diff --git a/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.cs b/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.cs index 18574a8..b0338a3 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.cs @@ -67,27 +67,41 @@ namespace Louis__Pharmacy_CNSA212_FP string patientID = ""; string medicationID = ""; string rxNum = ""; + string numRefills = ""; + string pastNumRefills = ""; - if (isAdd) + rxNum = txtRxNumber.Text.Trim(); + + DataSet ds = new DataSet(); + + ds = PharmacyDataTier.NumberofRefills(rxNum); + + if (ds.Tables[0].Columns[0] == ds.Tables[0].Columns[1]) { - refillID = txtRefillID.Text.Trim(); - date = DateTime.Parse(txtRefillDate.Text.Trim()); - patientID = txtPatientID.Text.Trim(); - medicationID= txtMedicationID.Text.Trim(); - rxNum = txtRxNumber.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); + } + else + { + 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); + } } } }