Added working delete functionality to refill form.

This commit is contained in:
Adam McCane 2024-02-19 12:24:56 -05:00
parent b29be83709
commit 546e75677e
3 changed files with 53 additions and 7 deletions

View File

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

View File

@ -208,6 +208,7 @@ namespace Louis__Pharmacy_CNSA212_FP
this.cmuDelete.Name = "cmuDelete"; this.cmuDelete.Name = "cmuDelete";
this.cmuDelete.Size = new System.Drawing.Size(180, 22); this.cmuDelete.Size = new System.Drawing.Size(180, 22);
this.cmuDelete.Text = "Delete"; this.cmuDelete.Text = "Delete";
this.cmuDelete.Click += new System.EventHandler(this.cmuDelete_Click);
// //
// splitContainer1 // splitContainer1
// //

View File

@ -85,6 +85,8 @@ namespace Louis__Pharmacy_CNSA212_FP
{ {
string refillID = ""; string refillID = "";
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];
@ -98,4 +100,17 @@ namespace Louis__Pharmacy_CNSA212_FP
refillUpdate.FillRefill(refillID); 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();
PharmacyDataTier.DeleteRefill(refillID);
btnSearch_Click(sender, e);
}
}
} }