PageRenderTime 27ms CodeModel.GetById 16ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/pigeoncms/Modules/PigeonCms.PlaceholdersAdmin/views/Default.ascx.cs

http://pigeoncms.googlecode.com/
C# | 181 lines | 156 code | 23 blank | 2 comment | 17 complexity | 287d9b4925f88ac15fb33477c7153ed9 MD5 | raw file
  1using System;
  2using System.Data;
  3using System.Configuration;
  4using System.Collections;
  5using System.Web;
  6using System.Web.Security;
  7using System.Web.UI;
  8using System.Web.UI.WebControls;
  9using System.Web.UI.WebControls.WebParts;
 10using System.Web.UI.HtmlControls;
 11using System.Web.Caching;
 12using System.Collections.Generic;
 13using PigeonCms;
 14using PigeonCms.Core.Helpers;
 15
 16public partial class Controls_Default : PigeonCms.BaseModuleControl
 17{
 18    protected string Name
 19    {
 20        get { return base.GetStringParam("Name", "", "Name"); }
 21    }
 22
 23    protected void Page_Load(object sender, EventArgs e)
 24    {
 25        LblOk.Text = "";
 26        LblErr.Text = "";
 27
 28        if (this.BaseModule.DirectEditMode)
 29        {
 30            if (string.IsNullOrEmpty(this.Name))
 31                throw new ArgumentException();
 32            if (string.IsNullOrEmpty(
 33                new PlaceholdersManager().GetByName(this.Name).Name))
 34                throw new ArgumentException();
 35
 36            BtnNew.Visible = false;
 37            //BtnSave.OnClientClick = "closePopup();";
 38            BtnCancel.OnClientClick = "closePopup();";
 39            edit(this.Name);
 40        }
 41    }
 42
 43    protected void ObjDs1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
 44    {
 45        PlaceholderFilter filter = new PlaceholderFilter();
 46        filter.Visible = Utility.TristateBool.NotSet;
 47        if (!string.IsNullOrEmpty(this.Name))
 48            filter.Name = this.Name;
 49
 50        e.InputParameters["filter"] = filter;
 51    }
 52
 53
 54    protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
 55    {
 56        if (e.CommandName == "Select")
 57        {
 58            edit(e.CommandArgument.ToString());
 59        }
 60        if (e.CommandName == "DeleteRow")
 61        {
 62            delete(e.CommandArgument.ToString());
 63        }
 64    }
 65
 66    protected void Grid1_RowCreated(object sender, GridViewRowEventArgs e)
 67    {
 68        if (e.Row.RowType == DataControlRowType.Header)
 69            Utility.AddGlyph(Grid1, e.Row);
 70    }
 71
 72    protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
 73    {
 74        if (this.BaseModule.DirectEditMode)
 75        {
 76            //list view not allowed (in case of js hacking)
 77            if (MultiView1.ActiveViewIndex == 0)
 78                MultiView1.ActiveViewIndex = 1;
 79
 80        }
 81    }
 82
 83    protected void BtnSave_Click(object sender, EventArgs e)
 84    {
 85        LblErr.Text = "";
 86        LblOk.Text = "";
 87
 88        try
 89        {
 90            Placeholder p1 = new Placeholder();
 91            if (TxtId.Text == string.Empty)
 92            {
 93                form2obj(p1);
 94                p1 = new PlaceholdersManager().Insert(p1);
 95            }
 96            else
 97            {
 98                p1 = new PlaceholdersManager().GetByName(TxtName.Text);//precarico i campi esistenti e nn gestiti dal form
 99                form2obj(p1);
100                new PlaceholdersManager().Update(p1);
101            }
102            new CacheManager<Placeholder>("PigeonCms.Placeholder").Remove(p1.Name);
103
104            Grid1.DataBind();
105            LblOk.Text = Utility.GetLabel("RECORD_SAVED_MSG");
106            MultiView1.ActiveViewIndex = 0;
107        }
108        catch (Exception e1)
109        {
110            LblErr.Text = Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString();
111        }
112        finally
113        {
114        }
115    }
116
117    protected void BtnCancel_Click(object sender, EventArgs e)
118    {
119        MultiView1.ActiveViewIndex = 0;
120    }
121
122    protected void BtnNew_Click(object sender, EventArgs e)
123    {
124        edit("");
125    }
126
127
128    #region private methods
129    private void form2obj(Placeholder obj1)
130    {
131        obj1.Name = TxtName.Text;
132        obj1.Visible = ChkVisibile.Checked;
133        obj1.Content = TxtContent.Text;
134    }
135
136    private void obj2form(Placeholder obj1)
137    {
138        TxtName.Text = obj1.Name;
139        ChkVisibile.Checked = obj1.Visible;
140        TxtContent.Text = obj1.Content;
141    }
142
143    private void edit(string name)
144    {
145        LblOk.Text = "";
146        LblErr.Text = "";
147
148        TxtName.Text = name;
149        TxtName.Enabled = true;
150        ChkVisibile.Checked = true;
151        TxtId.Text = "";
152        TxtContent.Text = "";
153        if (name != "")
154        {
155            TxtId.Text = "1";
156            TxtName.Enabled = false;
157            Placeholder currObj = new Placeholder();
158            currObj = new PlaceholdersManager().GetByName(name);
159            obj2form(currObj);
160        }
161        MultiView1.ActiveViewIndex = 1;
162    }
163
164    private void delete(string name)
165    {
166        LblOk.Text = "";
167        LblErr.Text = "";
168
169        try
170        {
171            new PlaceholdersManager().Delete(name);
172            new CacheManager<Placeholder>("PigeonCms.Placeholder").Remove(name);
173        }
174        catch (Exception e)
175        {
176            LblErr.Text = e.Message;
177        }
178        Grid1.DataBind();
179    }
180    #endregion
181}