Exemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Data = new DAL.Sql.Modles.Category();
     if (!IsPostBack)
     {
         EditIndex = -1;
         PopulateControls();
     }
 }
Exemplo n.º 2
0
        void rptCategories_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "update")
            {
                EditIndex = e.Item.ItemIndex;
            }
            else if (e.CommandName == "changeIsActive")
            {
                string[] args = e.CommandArgument.ToString().Split('_');
                DAL.Sql.Modles.Category data = repository.Single(int.Parse(args[0]));
                data.IsActive = !Boolean.Parse(args[1]);
                string errorMessage = manager.InsertOrUpdate(data).GetErrorMessages();
                if (errorMessage.Length > 0)
                {
                    ScriptManager.RegisterStartupScript(Page, GetType(), "JsStatus", String.Format("ShowError('{0}');", errorMessage.Substring(0, errorMessage.Length > 100 ? 100 : errorMessage.Length - 1) + "..."), true);
                }
                EditIndex = -1;
            }
            else if (e.CommandName == "save")
            {
                if (Data != null)
                {
                    HiddenField t = e.Item.FindControl("categoryIDHidden") as HiddenField;
                    Data = repository.Single(int.Parse(t.Value));

                    HtmlInputHidden temp = e.Item.FindControl("nameHidden") as HtmlInputHidden;
                    Data.Name = temp.Value;

                    temp             = e.Item.FindControl("descriptionHidden") as HtmlInputHidden;
                    Data.Description = temp.Value;

                    HtmlInputHidden temps = e.Item.FindControl("parentNameHidden") as HtmlInputHidden;
                    try
                    {
                        Data.ParentID = int.Parse(temps.Value);
                    }
                    catch
                    {
                        Data.ParentID = null;
                    }

                    List <string> liMessage = manager.Validate(Data).Messages;
                    string        mgs;
                    if (liMessage.Count > 0)
                    {
                        mgs = liMessage[0];
                        ScriptManager.RegisterStartupScript(Page, GetType(), "JsStatus", String.Format("ShowError(\"" + "{0}" + "\");", mgs.Substring(0, mgs.Length > 90 ? 90 : mgs.Length - 1) + "..."), true);
                    }
                    else
                    {
                        mgs = manager.InsertOrUpdate(Data).GetErrorMessages();
                        if (mgs.Length > 0)
                        {
                            ScriptManager.RegisterStartupScript(Page, GetType(), "JsStatus", String.Format("ShowError(\"" + "{0}" + "\");", mgs.Substring(0, mgs.Length > 90 ? 90 : mgs.Length - 1) + "..."), true);
                        }
                        else
                        {
                            string s = String.Format("ShowInfo(\"{0}\")", String.Format("Update category have id = {0} successfull", Data.CategoryID));
                            ScriptManager.RegisterStartupScript(Page, GetType(), "JsStatus", s, true);
                            EditIndex = -1;
                        }
                    }
                }
            }
            PopulateControls();
        }