From 546e75677e78c16cd4660e1e092b826865c27455 Mon Sep 17 00:00:00 2001 From: Adam McCane Date: Mon, 19 Feb 2024 12:24:56 -0500 Subject: [PATCH] Added working delete functionality to refill form. --- .../PharmacyDataTier.cs | 30 +++++++++++++++++++ .../frmRefill.Designer.cs | 1 + Louis'-Pharmacy_CNSA212-FP/frmRefill.cs | 29 +++++++++++++----- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs index a5bd2c2..a6bf4a2 100644 --- a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs +++ b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs @@ -675,5 +675,35 @@ namespace Louis__Pharmacy_CNSA212_FP } } + public static void DeleteRefill(string Refill_id) + { + + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "DeleteRefill"; + // Define input parameter + cmdString.Parameters.Add("@Refill_id", SqlDbType.Char, 10).Value = Refill_id; + + cmdString.ExecuteNonQuery(); + } + catch (Exception ex) + { + throw new ArgumentException(ex.Message); + } + finally + { + myConn.Close(); + } + + } + } } \ No newline at end of file diff --git a/Louis'-Pharmacy_CNSA212-FP/frmRefill.Designer.cs b/Louis'-Pharmacy_CNSA212-FP/frmRefill.Designer.cs index ee771d2..e4dfd84 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmRefill.Designer.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmRefill.Designer.cs @@ -208,6 +208,7 @@ namespace Louis__Pharmacy_CNSA212_FP this.cmuDelete.Name = "cmuDelete"; this.cmuDelete.Size = new System.Drawing.Size(180, 22); this.cmuDelete.Text = "Delete"; + this.cmuDelete.Click += new System.EventHandler(this.cmuDelete_Click); // // splitContainer1 // diff --git a/Louis'-Pharmacy_CNSA212-FP/frmRefill.cs b/Louis'-Pharmacy_CNSA212-FP/frmRefill.cs index 14a6534..2c7566f 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmRefill.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmRefill.cs @@ -85,17 +85,32 @@ namespace Louis__Pharmacy_CNSA212_FP { string refillID = ""; + if (dgvRefills.Rows.Count > 0) + { + dgvRefills.DataSource = ds.Tables[0]; + DataGridViewRow row = new DataGridViewRow(); + row = dgvRefills.SelectedRows[0]; + refillID = (row.Cells[0].Value).ToString(); + + frmRefillAdd refillUpdate = new frmRefillAdd(false); + refillUpdate.MdiParent = MdiParent; + refillUpdate.StartPosition = FormStartPosition.CenterScreen; + refillUpdate.Show(); + refillUpdate.Focus(); + refillUpdate.FillRefill(refillID); + } + } + + private void cmuDelete_Click(object sender, EventArgs e) + { + string refillID = ""; + dgvRefills.DataSource = ds.Tables[0]; DataGridViewRow row = new DataGridViewRow(); row = dgvRefills.SelectedRows[0]; refillID = (row.Cells[0].Value).ToString(); - - frmRefillAdd refillUpdate = new frmRefillAdd(false); - refillUpdate.MdiParent = MdiParent; - refillUpdate.StartPosition = FormStartPosition.CenterScreen; - refillUpdate.Show(); - refillUpdate.Focus(); - refillUpdate.FillRefill(refillID); + PharmacyDataTier.DeleteRefill(refillID); + btnSearch_Click(sender, e); } } }