protected void GridViewMedications_SelectedIndexChanged(object sender, EventArgs e)
        {
            ImageButton btn          = (ImageButton)sender;
            GridViewRow row          = (GridViewRow)btn.NamingContainer;
            string      medicationID = row.Cells[1].Text;

            SqlDataSourceMedications.DeleteParameters.Add("Medication_ID", medicationID);
            SqlDataSourceMedications.Delete();
            int inventoryQuantity = int.Parse(row.Cells[3].Text);

            SqlDataSourceInventory.UpdateCommand = "UPDATE Inventory SET Quantity = Quantity + " + inventoryQuantity + " WHERE Medication_ID = " + medicationID;
            SqlDataSourceInventory.Update();
            txtSearchInventory.Text = "";
            txtMedication.Text      = "";
            txtQuantity.Text        = "";
            bindInventoryGridView();
        }
        protected void btnAddMedication_Click(object sender, EventArgs e)
        {
            try
            {
                String id = txtID.Text;
                if (id == null || id == "")
                {
                    displayMessageAlert("Please save the new appointment record before adding a medication item!");
                    return;
                }

                if (txtMedicationID.Text == null || txtMedicationID.Text == "")
                {
                    displayMessageAlert("Please select a medication item!");
                    return;
                }
                int  quantity;
                bool isInt = int.TryParse(txtQuantity.Text, out quantity);
                if (!isInt)
                {
                    displayMessageAlert("Please enter a valid quantity value for the selected medication item!");
                    return;
                }
                int inventoryQuantity;
                int.TryParse(GridViewInventory.SelectedRow.Cells[3].Text, out inventoryQuantity);
                if (inventoryQuantity < int.Parse(txtQuantity.Text))
                {
                    displayMessageAlert("There is not enough stock of this medication! Please check inventory stock levels.");
                    return;
                }

                SqlDataSourceMedications.Insert();

                SqlDataSourceInventory.UpdateCommand = "UPDATE Inventory SET Quantity = Quantity - " + quantity + " WHERE Medication_ID = " + txtMedicationID.Text;
                SqlDataSourceInventory.Update();
                txtMedicationID.Text = "";
                txtMedication.Text   = "";
                txtQuantity.Text     = "";
                bindInventoryGridView();
            }
            catch (SqlException exc)
            {
                displayMessageAlert("Error adding a medication to the appointment!");
            }
        }