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); } } }