コード例 #1
0
        protected void gvCustomers_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Customer clnt = Customer.GetCustomerDetails(Convert.ToInt32(e.CommandArgument));

            Session["SelectedCustomer"] = clnt;
            switch (e.CommandName)
            {
            case "Select":
                LoadCustomerData(Convert.ToInt32(e.CommandArgument));
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "$('#myModal').modal('show');", true);
                break;

            case "Activate":
                Customer c = Customer.GetCustomerDetails(Convert.ToInt32(e.CommandArgument));
                if (Customer.ActivateUser(Convert.ToInt32(e.CommandArgument)))
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('The customer #" + e.CommandArgument + " has been activated.');", true);
                    gvCustomers.DataBind();
                    NotifyCustomer(c);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('Failed activating customer #" + e.CommandArgument + ".');", true);
                }
                break;

            case "Deactivate":
                if (Customer.DeactivateUser(Convert.ToInt32(e.CommandArgument)))
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('The customer #" + e.CommandArgument + " has been deactivated.');", true);
                    gvCustomers.DataBind();
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Info", "alert('Failed deaktivating customer #" + e.CommandArgument + ".');", true);
                }
                break;

            case "NewAd":
                Response.Redirect("~/account/advertise.aspx?Customer=" + clnt.Id);
                break;

            case "NewItem":
                Response.Redirect("~/account/addvehicle.aspx?Customer=" + clnt.Id);
                break;

            default:
                break;
            }
        }