Clover.NET coverage report - Coverage

Coverage timestamp: viernes, 12 de agosto de 2005 12:53:38 PM

File Stats: LOC: 164   Methods: 6
NCLOC: 87 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Web\WebBuilders\ItemTemplates\ItemTemplate.cs 90,0 % 78,6 % 83,3 % 81,0 %
coverage coverage
1   #region Copyright
2   /*
3   ShowX. Maps business objects into presentation layer.
4   Copyright (C) 2005 Jesus Diaz.
5  
6   This library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Lesser General Public
8   License as published by the Free Software Foundation; either
9   version 2.1 of the License, or (at your option) any later version.
10  
11   This library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   Lesser General Public License for more details.
15  
16   You should have received a copy of the GNU Lesser General Public
17   License along with this library; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  
20   For project details see: http://showx.sourceforge.net
21   */
22   #endregion
23  
24   using System;
25   using System.Reflection;
26   using System.Web.UI;
27   using System.Web.UI.WebControls;
28   using ShowX.Config;
29   using ShowX.Model;
30   using DataGrid = ShowX.Web.WebControls.DataGrid;
31  
32   namespace ShowX.Web.WebBuilders.ItemTemplates
33   {
34   /// <summary>
35   /// This class is used to map a property information into a cell, in a view-only
36   /// fashion
37   /// </summary>
38   class ItemTemplate : ITemplate {
39  
40   /// <summary>
41   /// Information of the property to map
42   /// </summary>
43   protected PropertyInfo propertyInfo;
44  
45   /// <summary>
46   /// Constructor
47   /// </summary>
48   /// <param name="propertyInfo">Information of the property to map</param>
49 280 public ItemTemplate(PropertyInfo propertyInfo)
50   {
51 280 this.propertyInfo = propertyInfo;
52   }
53  
54   /// <summary>
55   /// Method called when instantiating a TemplateColumn by using this
56   /// ITemplate implementation
57   /// </summary>
58   /// <param name="container">Container that instantiate this Template</param>
59 890 public void InstantiateIn(Control container)
60   {
61 890 IPropertyMap dbattr =
62   Configuration.Session.MappingHandler.GetPropertyMap(propertyInfo);
63  
64 890 if (propertyInfo.PropertyType == typeof(Boolean)) {
65  
66 126 CheckBox cb = new CheckBox();
67 126 cb.DataBinding += new EventHandler(cb_DataBinding);
68  
69 126 container.Controls.Add(cb);
70   }
71 764 else if (propertyInfo.PropertyType == typeof(DateTime)) {
72  
73 126 Literal ldate = new Literal();
74 126 ldate.DataBinding += new EventHandler(ldate_DataBinding);
75  
76 126 container.Controls.Add(ldate);
77   }
78   else {
79  
80 638 if (dbattr.ItemStyle == ItemStyle.HyperLink) {
81  
82 0 LinkButton hl = new LinkButton();
83  
84 0 hl.DataBinding += new EventHandler(LinkButton_DataBinding);
85 0 hl.CommandName = "ItemCommand";
86  
87 0 container.Controls.Add(hl);
88   }
89   else {
90  
91 638 Literal lc = new Literal();
92  
93 638 if (dbattr.IsPassword)
94 126 lc.Text = "(Not show)";
95   else
96 512 lc.DataBinding += new EventHandler(TemplateControl_DataBinding);
97  
98 638 container.Controls.Add(lc);
99   }
100   }
101   }
102  
103   /// <summary>
104   /// DataBinding Event related with a control of the template. Very useful to
105   /// assign correct values to template controls.
106   /// </summary>
107   /// <param name="sender">Sender who invoke the data binding</param>
108   /// <param name="e">Arguments of the event</param>
109 512 private void TemplateControl_DataBinding(object sender, EventArgs e)
110   {
111 512 Literal lc;
112 512 lc = (Literal) sender;
113 512 DataGridItem container = (DataGridItem) lc.NamingContainer;
114  
115 512 lc.Text += DataBinder.Eval(container.DataItem,propertyInfo.Name);
116   }
117  
118   /// <summary>
119   /// DataBinding Event related with a control of the template. Very useful to
120   /// assign correct values to template controls.
121   /// </summary>
122   /// <param name="sender">Sender who invoke the data binding</param>
123   /// <param name="e">Arguments of the event</param>
124 126 private void cb_DataBinding(object sender, EventArgs e)
125   {
126 126 CheckBox cb;
127 126 cb = (CheckBox) sender;
128 126 DataGridItem container = (DataGridItem) cb.NamingContainer;
129 126 cb.Checked = Convert.ToBoolean(
130   DataBinder.Eval(container.DataItem,propertyInfo.Name));
131 126 cb.Enabled = false;
132   }
133  
134 126 private void ldate_DataBinding(object sender, EventArgs e)
135   {
136 126 Literal ldate;
137 126 ldate = (Literal) sender;
138 126 DataGridItem container = (DataGridItem) ldate.NamingContainer;
139 126 DateTime date = (DateTime)DataBinder.Eval(container.DataItem,
140   propertyInfo.Name);
141  
142 126 DataGrid dg = container.Parent.Parent as DataGrid;
143  
144 126 if (dg.DateTimeFormat == "")
145 35 ldate.Text = date.ToString();
146   else
147 91 ldate.Text = date.ToString(dg.DateTimeFormat);
148   }
149  
150 0 private void LinkButton_DataBinding(object sender, EventArgs e) {
151  
152   IPropertyMap dbattr =
153   Configuration.Session.MappingHandler.GetPropertyMap(propertyInfo);
154  
155   LinkButton hl;
156   hl = (LinkButton) sender;
157   DataGridItem container = (DataGridItem) hl.NamingContainer;
158  
159   hl.Text += DataBinder.Eval(container.DataItem,propertyInfo.Name);
160   //hl.NavigateUrl = dbattr.Translator.Translate(container.DataItem,hl.Text);
161   }
162   }
163   }
164