示例#1
0
        protected void btnRemoveDrug_Click(object sender, EventArgs e)
        {
            int index = GridViewDrugItems.SelectedIndex;

            try
            {
                DataTable DT = new DataTable();
                DT.Columns.Add("drugId");
                DT.Columns.Add("drugName");
                DT.Columns.Add("quantity");
                DT.Columns.Add("instructions");

                foreach (GridViewRow row in GridViewDrugItems.Rows)
                {
                    DataRow DR = DT.NewRow();
                    DR["drugId"]       = row.Cells[1].Text;
                    DR["drugName"]     = row.Cells[2].Text;
                    DR["quantity"]     = row.Cells[3].Text;
                    DR["instructions"] = row.Cells[4].Text;
                    DT.Rows.Add(DR);
                }

                DT.Rows.RemoveAt(index);
                GridViewDrugItems.DataSource = DT;
                GridViewDrugItems.DataBind();
                this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "swal('Success!', 'Drug removed successfully', 'success');", true);

                btnDelete.CssClass = "btn btn-danger disabled";
                GridViewDrugItems.SelectedIndex = -1;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex);
            }
        }
示例#2
0
        protected void btnAddInputSubmit_Click(object sender, EventArgs e)
        {
            bool vFound = false;

            try
            {
                DataTable DT = new DataTable();
                DT.Columns.Add("drugId");
                DT.Columns.Add("drugName");
                DT.Columns.Add("quantity");
                DT.Columns.Add("instructions");

                foreach (GridViewRow row in GridViewDrugItems.Rows)
                {
                    DataRow DR = DT.NewRow();
                    DR["drugId"]       = row.Cells[1].Text;
                    DR["drugName"]     = row.Cells[2].Text;
                    DR["quantity"]     = row.Cells[3].Text;
                    DR["instructions"] = row.Cells[4].Text;
                    DT.Rows.Add(DR);
                }

                foreach (GridViewRow row in GridViewDrugItems.Rows)
                {
                    if (row.Cells[1].Text == txDrugId.Text)
                    {
                        vFound = true;
                        break;
                    }
                }

                if (vFound == true)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "swal('Error!', 'Selected Drug is already added', 'error');", true);
                }
                else
                {
                    DataRow newDR = DT.NewRow();
                    newDR["drugId"]       = txDrugId.Text;
                    newDR["drugName"]     = GridViewDrugs.SelectedRow.Cells[2].Text;
                    newDR["quantity"]     = txQuantity.Text;
                    newDR["instructions"] = txInstructions.Text;
                    DT.Rows.Add(newDR);

                    GridViewDrugItems.DataSource = DT;
                    GridViewDrugItems.DataBind();
                    this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "swal('Success!', 'Drug added successfully', 'success');", true);
                }

                btnAdd.CssClass             = "btn btn-success disabled";
                GridViewDrugs.SelectedIndex = -1;
                txQuantity.Text             = "";
                txInstructions.Text         = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex);
            }
        }