PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://pigeoncms.googlecode.com/
C# | 160 lines | 144 code | 16 blank | 0 comment | 12 complexity | 446d4ad6b9f1363da467a21108d511eb 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    protected void Page_Load(object sender, EventArgs e)
 18    {
 19        LblOk.Text = "";
 20        LblErr.Text = "";
 21    }
 22
 23    protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
 24    {
 25        if (e.CommandName == "Select")
 26        {
 27            editRow(e.CommandArgument.ToString());
 28        }
 29        if (e.CommandName == "DeleteRow")
 30        {
 31            deleteRow(e.CommandArgument.ToString());
 32        }
 33    }
 34
 35    protected void Grid1_RowCreated(object sender, GridViewRowEventArgs e)
 36    {
 37        if (e.Row.RowType == DataControlRowType.Header)
 38            Utility.AddGlyph(Grid1, e.Row);
 39    }
 40
 41    protected void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
 42    {
 43        if (e.Row.RowType == DataControlRowType.DataRow)
 44        {
 45            AppSetting app1 = new AppSetting();
 46            app1 = (AppSetting)e.Row.DataItem;
 47            Label LblKeyValue = (Label)e.Row.FindControl("LblKeyValue");
 48            LblKeyValue.Text = Utility.Html.GetTextPreview(app1.KeyValue, 40, "");
 49        }
 50    }
 51
 52    protected void BtnSave_Click(object sender, EventArgs e)
 53    {
 54        LblErr.Text = "";
 55        LblOk.Text = "";
 56
 57        try
 58        {
 59            AppSetting p1 = new AppSetting();
 60            form2obj(p1);
 61            if (HiddenNewRecord.Value == "true")
 62            {
 63                p1 = AppSettingsManager.Insert(p1);
 64            }
 65            else
 66            {
 67                AppSettingsManager.Update(p1);
 68            }
 69            Grid1.DataBind();
 70            LblOk.Text = Utility.GetLabel("RECORD_SAVED_MSG");
 71            MultiView1.ActiveViewIndex = 0;
 72        }
 73        catch (Exception e1)
 74        {
 75            LblErr.Text = Utility.GetLabel("RECORD_ERR_MSG") + "<br />" + e1.ToString();
 76        }
 77        finally
 78        {
 79        }
 80    }
 81
 82    protected void BtnCancel_Click(object sender, EventArgs e)
 83    {
 84        MultiView1.ActiveViewIndex = 0;
 85    }
 86
 87    protected void BtnNew_Click(object sender, EventArgs e)
 88    {
 89        editRow("");
 90    }
 91
 92    protected void BtnApply_Click(object sender, EventArgs e)
 93    {
 94        AppSettingsManager.RefreshApplicationVars();
 95    }
 96
 97
 98    #region private methods
 99    private void form2obj(AppSetting obj)
100    {
101        obj.KeyName = TxtKeyName.Text;
102        obj.KeyTitle = TxtKeyTitle.Text;
103        obj.KeyValue = TxtKeyValue.Text;
104        obj.KeyInfo = TxtKeyInfo.Text;
105    }
106
107    private void obj2form(AppSetting obj)
108    {
109        TxtKeyName.Text = obj.KeyName;
110        TxtKeyTitle.Text = obj.KeyTitle;
111        TxtKeyValue.Text = obj.KeyValue;
112        TxtKeyInfo.Text = obj.KeyInfo;
113    }
114
115    private void editRow(string keyName)
116    {
117        LblOk.Text = "";
118        LblErr.Text = "";
119
120        clearForm();
121        if (keyName != string.Empty)
122        {
123            AppSetting obj = new AppSetting();
124            obj = AppSettingsManager.GetSettingByKey(keyName);
125            TxtKeyName.Enabled = false;
126            obj2form(obj);
127        }
128        else
129        {
130            HiddenNewRecord.Value = "true";
131            TxtKeyName.Enabled = true;
132        }
133        MultiView1.ActiveViewIndex = 1;
134    }
135
136    private void deleteRow(string keyName)
137    {
138        LblOk.Text = "";
139        LblErr.Text = "";
140        try
141        {
142            AppSettingsManager.Delete(keyName);
143        }
144        catch (Exception e)
145        {
146            LblErr.Text = e.Message;
147        }
148        Grid1.DataBind();
149    }
150
151    private void clearForm()
152    {
153        HiddenNewRecord.Value = "";
154        TxtKeyName.Text = "";
155        TxtKeyTitle.Text = "";
156        TxtKeyValue.Text = "";
157        TxtKeyInfo.Text = "";
158    }
159    #endregion
160}