PageRenderTime 64ms CodeModel.GetById 56ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://pigeoncms.googlecode.com/
C# | 162 lines | 142 code | 20 blank | 0 comment | 14 complexity | bb452a4b464abde98b5121a30a538f99 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;
 14
 15public partial class Controls_Default : PigeonCms.BaseModuleControl
 16{
 17
 18    protected void Page_Load(object sender, EventArgs e)
 19    {
 20        if (!Page.IsPostBack)
 21        {
 22        }
 23    }
 24
 25    protected void ObjDs1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
 26    {
 27        MenutypeFilter filter = new MenutypeFilter();
 28        e.InputParameters["filter"] = filter;
 29    }
 30
 31    protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
 32    {
 33        if (e.CommandName == "Select")
 34        {
 35            editRow(int.Parse(e.CommandArgument.ToString()));
 36        }
 37        if (e.CommandName == "DeleteRow")
 38        {
 39            deleteRow(int.Parse(e.CommandArgument.ToString()));
 40        }
 41    }
 42
 43    protected void Grid1_RowCreated(object sender, GridViewRowEventArgs e)
 44    {
 45        if (e.Row.RowType == DataControlRowType.Header)
 46            Utility.AddGlyph(Grid1, e.Row);
 47    }
 48
 49    protected void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
 50    {
 51        if (e.Row.RowType == DataControlRowType.DataRow)
 52        {
 53        }
 54    }
 55
 56    protected void BtnNew_Click(object sender, EventArgs e)
 57    {
 58        editRow(0);
 59    }
 60
 61    protected void BtnSave_Click(object sender, EventArgs e)
 62    {
 63        LblErr.Text = "";
 64        LblOk.Text = "";
 65
 66        try
 67        {
 68            Menutype o1 = new PigeonCms.Menutype();
 69            if (base.CurrentId == 0)
 70            {
 71                form2obj(o1);
 72                o1 = new MenutypesManager().Insert(o1);
 73            }
 74            else
 75            {
 76                o1 = new MenutypesManager().GetByKey(base.CurrentId);
 77                form2obj(o1);
 78                new MenutypesManager().Update(o1);
 79            }
 80            Grid1.DataBind();
 81            LblOk.Text = Utility.GetLabel("RECORD_SAVED_MSG");
 82            MultiView1.ActiveViewIndex = 0;
 83        }
 84        catch (Exception e1)
 85        {
 86            LblErr.Text = Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString();
 87        }
 88        finally
 89        {
 90        }
 91    }
 92
 93    protected void BtnCancel_Click(object sender, EventArgs e)
 94    {
 95        MultiView1.ActiveViewIndex = 0;
 96    }
 97
 98    protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
 99    {
100        if (MultiView1.ActiveViewIndex == 1)    //edit view
101        {
102        }
103    }
104
105    #region private methods
106
107    private void clearForm()
108    {
109        TxtMenuType.Text = "";
110        TxtTitle.Text = "";
111        TxtDescription.Text = "";
112    }
113
114    private void form2obj(Menutype obj)
115    {
116        obj.Id = base.CurrentId;
117        obj.MenuType = TxtMenuType.Text;
118        obj.Title = TxtTitle.Text;
119        obj.Description = TxtDescription.Text;
120    }
121
122    private void obj2form(Menutype obj)
123    {
124        TxtMenuType.Text = obj.MenuType;
125        TxtTitle.Text = obj.Title;
126        TxtDescription.Text = obj.Description;
127    }
128
129    private void editRow(int recordId)
130    {
131        LblOk.Text = "";
132        LblErr.Text = "";
133
134        clearForm();
135        base.CurrentId = recordId;
136        if (base.CurrentId > 0)
137        {
138            Menutype obj = new Menutype();
139            obj = new MenutypesManager().GetByKey(base.CurrentId);
140            obj2form(obj);
141        }
142        MultiView1.ActiveViewIndex = 1;
143    }
144
145    private void deleteRow(int recordId)
146    {
147        LblOk.Text = "";
148        LblErr.Text = "";
149
150        try
151        {
152            new MenutypesManager().DeleteById(recordId);
153        }
154        catch (Exception e)
155        {
156            LblErr.Text = e.Message;
157        }
158        Grid1.DataBind();
159    }
160
161    #endregion
162}