PageRenderTime 41ms CodeModel.GetById 11ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://pigeoncms.googlecode.com/
C# | 318 lines | 278 code | 40 blank | 0 comment | 22 complexity | e0348862c16daf4771daf077f3aa0682 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        if (!Page.IsPostBack)
 20        {
 21            loadDropTopRowsFilter();
 22            loadDropsModuleTypes();
 23            loadDropTracerItemTypeFilter();
 24            loadDropDatesRangeFilter();
 25        }
 26    }
 27
 28    protected void DropTopRowsFilter_SelectedIndexChanged(object sender, EventArgs e)
 29    {
 30        try { Grid1.DataBind(); }
 31        catch (Exception ex)
 32        {
 33            LblErr.Text = ex.Message;
 34        }
 35    }
 36
 37    protected void DropTracerItemTypeFilter_SelectedIndexChanged(object sender, EventArgs e)
 38    {
 39        try { Grid1.DataBind(); }
 40        catch(Exception ex)
 41        {
 42            LblErr.Text = ex.Message;
 43        }
 44    }
 45
 46    protected void DropModuleTypesFilter_SelectedIndexChanged(object sender, EventArgs e)
 47    {
 48        try { Grid1.DataBind(); }
 49        catch (Exception ex)
 50        {
 51            LblErr.Text = ex.Message;
 52        }
 53    }
 54
 55    protected void DropDatesRangeFilter_SelectedIndexChanged(object sender, EventArgs e)
 56    {
 57        try { Grid1.DataBind(); }
 58        catch (Exception ex)
 59        {
 60            LblErr.Text = ex.Message;
 61        }
 62    }
 63
 64    protected void TxtDescriptionFilter_TextChanged(object sender, EventArgs e)
 65    {
 66        try { Grid1.DataBind(); }
 67        catch (Exception ex)
 68        {
 69            LblErr.Text = ex.Message;
 70        }
 71    }
 72
 73    protected void ObjDs1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
 74    {
 75        var filter = new LogItemsFilter();
 76
 77        filter.TopRows = int.Parse(DropTopRowsFilter.SelectedValue);
 78
 79        if (DropTracerItemTypeFilter.SelectedValue != "")
 80        {
 81            filter.FilterType = true;
 82            filter.Type = (TracerItemType)Enum.Parse(typeof(TracerItemType), DropTracerItemTypeFilter.SelectedValue);
 83        }
 84
 85        if (DropModuleTypesFilter.SelectedValue != "")
 86        {
 87            filter.ModuleFullName = DropModuleTypesFilter.SelectedValue;
 88        }
 89
 90        if (DropDatesRangeFilter.SelectedValue != "")
 91        {
 92            DatesRange.RangeType rangeType =
 93                (DatesRange.RangeType)Enum.Parse(typeof(DatesRange.RangeType), DropDatesRangeFilter.SelectedValue);
 94            DatesRange datesRange = new DatesRange(rangeType);
 95            filter.DateInsertedRange = datesRange;
 96        }
 97
 98        if (!string.IsNullOrEmpty(TxtDescriptionFilter.Text))
 99        {
100            filter.DescriptionPart = TxtDescriptionFilter.Text;
101        }
102
103        e.InputParameters["filter"] = filter;
104    }
105
106    protected void Grid1_DataBinding(object sender, EventArgs e)
107    {
108
109    }
110
111    protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
112    {
113        if (e.CommandName == "Select")
114        {
115            editRow(int.Parse(e.CommandArgument.ToString()));
116        }
117        if (e.CommandName == "DeleteRow")
118        {
119            deleteRow(int.Parse(e.CommandArgument.ToString()));
120        }
121    }
122
123    protected void Grid1_RowCreated(object sender, GridViewRowEventArgs e)
124    {
125        if (e.Row.RowType == DataControlRowType.Header)
126            Utility.AddGlyph(Grid1, e.Row);
127    }
128
129    protected void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
130    {
131        if (e.Row.RowType == DataControlRowType.DataRow)
132        {
133            var item = new PigeonCms.LogItem();
134            item = (PigeonCms.LogItem)e.Row.DataItem;
135
136            Literal LitModule = (Literal)e.Row.FindControl("LitModule");
137            LitModule.Text = item.ModuleFullName;
138
139            Literal LitUrl = (Literal)e.Row.FindControl("LitUrl");
140            LitUrl.Text = Utility.Html.GetTextPreview(item.Url, 40, "");
141
142            Literal LitDescription = (Literal)e.Row.FindControl("LitDescription");
143            LitDescription.Text = Utility.Html.GetTextPreview(item.Description, 80, "");
144
145            Image ImgSel = (Image)e.Row.FindControl("ImgSel");
146            switch (item.Type)
147            {
148                case TracerItemType.Debug:
149                    ImgSel.ImageUrl = Utility.GetThemedImageSrc("debug.gif");
150                    break;
151                case TracerItemType.Info:
152                    ImgSel.ImageUrl = Utility.GetThemedImageSrc("info.gif");
153                    break;
154                case TracerItemType.Warning:
155                    ImgSel.ImageUrl = Utility.GetThemedImageSrc("warning.gif");
156                    break;
157                case TracerItemType.Alert:
158                    ImgSel.ImageUrl = Utility.GetThemedImageSrc("alert.gif");
159                    break;
160                case TracerItemType.Error:
161                    ImgSel.ImageUrl = Utility.GetThemedImageSrc("error.gif");
162                    break;
163                default:
164                    ImgSel.ImageUrl = Utility.GetThemedImageSrc("editfile.gif");
165                    break;
166            }
167        }
168    }
169
170    protected void BtnCancel_Click(object sender, EventArgs e)
171    {
172        LblErr.Text = "";
173        LblOk.Text = "";
174        MultiView1.ActiveViewIndex = 0;
175    }
176
177    protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
178    {
179        if (MultiView1.ActiveViewIndex == 0)    //list view
180        {
181        }
182    }
183
184    #region private methods
185
186    private void clearForm()
187    {
188        LitId.Text = "";
189        LitCreated.Text = "";
190        LitType.Text = "";
191        LitModuleType.Text = "";
192        LitView.Text = "";
193        LitUrl.Text = "";
194        LitDescription.Text = "";
195    }
196
197    private void form2obj(LogItem obj)
198    {
199        throw new NotImplementedException("form2obj");
200    }
201
202    private void obj2form(LogItem obj)
203    {
204        LitId.Text = obj.Id.ToString();
205        LitCreated.Text = obj.DateInserted + " " + obj.UserInserted;
206        LitType.Text = obj.Type.ToString();
207
208        var module = new Module();
209        module = new ModulesManager().GetByKey(obj.ModuleId);
210        LitModuleType.Text = module.ModuleFullName;
211        if (string.IsNullOrEmpty(module.ModuleFullName))
212        {
213            LitModuleType.Text += " " + Utility.GetErrorLabel("NotInstalledModuleType", "Not installed module type");
214        }
215        LitView.Text = module.CurrView;
216        LitUserHostAddress.Text = obj.UserHostAddress;
217        LitUserInserted.Text = obj.UserInserted;
218        LitUrl.Text = obj.Url;
219        LitDescription.Text = obj.Description;
220    }
221
222    private void editRow(int recordId)
223    {
224        var obj = new LogItem();
225        LblOk.Text = "";
226        LblErr.Text = "";
227
228        clearForm();
229        base.CurrentId = recordId;
230
231        if (base.CurrentId == 0)
232        { }
233        else
234        {
235            obj = new LogItemsManager().GetByKey(base.CurrentId);
236            obj2form(obj);
237        }
238        MultiView1.ActiveViewIndex = 1;
239    }
240
241    private void deleteRow(int recordId)
242    {
243        LblOk.Text = "";
244        LblErr.Text = "";
245
246        try
247        {
248            new LogItemsManager().DeleteById(recordId);
249        }
250        catch (Exception e)
251        {
252            LblErr.Text = e.Message;
253        }
254        Grid1.DataBind();
255    }
256
257    private void loadDropTracerItemTypeFilter()
258    {
259        DropTracerItemTypeFilter.Items.Clear();
260        DropTracerItemTypeFilter.Items.Add(
261            new ListItem(Utility.GetLabel("LblSelectType", "Select type"), ""));
262        foreach (string item in Enum.GetNames(typeof(TracerItemType)))
263        {
264            int value = (int)Enum.Parse(typeof(TracerItemType), item);
265            ListItem listItem = new ListItem(item, value.ToString());
266            DropTracerItemTypeFilter.Items.Add(listItem);
267        }
268    }
269
270    private void loadDropsModuleTypes()
271    {
272        try
273        {
274            DropModuleTypesFilter.Items.Clear();
275            DropModuleTypesFilter.Items.Add(new ListItem(Utility.GetLabel("LblSelectModule", "Select module"), ""));
276
277            ModuleTypeFilter filter = new ModuleTypeFilter();
278            List<ModuleType> recordList = new ModuleTypeManager(true).GetByFilter(filter, "FullName");
279            foreach (ModuleType record1 in recordList)
280            {
281                DropModuleTypesFilter.Items.Add(
282                    new ListItem(record1.FullName, record1.FullName));
283            }
284        }
285        catch (Exception ex)
286        {
287            LblErr.Text = ex.ToString();
288        }
289    }
290
291    private void loadDropDatesRangeFilter()
292    {
293        try
294        {
295            DropDatesRangeFilter.Items.Clear();
296            DropDatesRangeFilter.Items.Add(new ListItem("Today", "3"));
297            DropDatesRangeFilter.Items.Add(new ListItem("Always", "2"));
298            DropDatesRangeFilter.Items.Add(new ListItem("Last week", "4"));
299            DropDatesRangeFilter.Items.Add(new ListItem("Last month", "5"));
300        }
301        catch (Exception ex)
302        {
303            LblErr.Text = ex.ToString();
304        }
305    }
306
307    private void loadDropTopRowsFilter()
308    {
309        DropTopRowsFilter.Items.Clear();
310        DropTopRowsFilter.Items.Add(new ListItem("Last 50 items", "50"));
311        DropTopRowsFilter.Items.Add(new ListItem("Last 100 items", "100"));
312        DropTopRowsFilter.Items.Add(new ListItem("Last 200 items", "200"));
313        DropTopRowsFilter.Items.Add(new ListItem("Last 500 items", "500"));
314        DropTopRowsFilter.Items.Add(new ListItem("All items", "0"));
315    }
316
317    #endregion
318}