Esempio n. 1
0
        protected void dgIntake_ItemCommand(object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            Intake intake = new Intake();

            if (e.CommandName == "AddIntake")
            {
                TextBox txtTempIntake = (TextBox)e.Item.Cells[1].FindControl("txtMonthNew");

                if (txtTempIntake.Text.Trim() == "")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please fill in the intake Month!', 'error')</script>'");
                }
                else
                {
                    if (intake.Add(txtTempIntake.Text) == false)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'This intake " + txtTempIntake.Text + " is existed already, try another month', 'error')</script>'");
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Added!', text: '" + txtTempIntake.Text + " intake is added successfully', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'cpIntake.aspx'; }});</script>'");
                    }
                }
            }

            else if (e.CommandName == "DeleteIntake")
            {
                Label rowIntakeID = (Label)e.Item.Cells[0].FindControl("lblID");

                if (intake.DeleteIntake(rowIntakeID.Text) == false)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Delete intake unsuccessfully', 'error')</script>'");
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Deleted!', text: 'Deleted intake successfully', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'cpIntake.aspx'; }});</script>'");
                }
            }
        }