Clover.NET coverage report - Coverage

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

File Stats: LOC: 175   Methods: 6
NCLOC: 97 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Web\WebBuilders\ItemTemplates\EditItemTemplate.cs 87,5 % 97,9 % 100,0 % 96,8 %
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 ShowX.Web.WebControls;
31   using Calendar = ShowX.Web.WebControls.Calendar;
32   using DataGrid = ShowX.Web.WebControls.DataGrid;
33  
34   namespace ShowX.Web.WebBuilders.ItemTemplates
35   {
36   /// <summary>
37   /// This class is used to map a property information into a cell, in an editable
38   /// fashion.
39   /// </summary>
40   class EditItemTemplate : ITemplate {
41  
42   /// <summary>
43   /// Information of the property to map
44   /// </summary>
45   protected PropertyInfo propertyInfo;
46  
47   /// <summary>
48   /// Constructor
49   /// </summary>
50   /// <param name="propertyInfo">Information of the property to map</param>
51 175 public EditItemTemplate(PropertyInfo propertyInfo)
52   {
53 175 this.propertyInfo = propertyInfo;
54   }
55  
56   /// <summary>
57   /// Method called when instantiating a TemplateColumn by using this
58   /// ITemplate implementation
59   /// </summary>
60   /// <param name="container">Container that instantiate this Template</param>
61 20 public void InstantiateIn(Control container)
62   {
63 20 IPropertyMap dbattr = Configuration.Session.MappingHandler
64   .GetPropertyMap(propertyInfo);
65  
66 20 if (propertyInfo.PropertyType == typeof(Boolean)) {
67  
68 4 CheckBox cb = new CheckBox();
69 4 cb.DataBinding += new EventHandler(cb_DataBinding);
70 4 container.Controls.Add(cb);
71   }
72 16 else if (propertyInfo.PropertyType == typeof(DateTime)) {
73  
74 4 Calendar date = new Calendar(propertyInfo);
75 4 date.DataBinding += new EventHandler(date_DataBinding);
76  
77 4 container.Controls.Add(date);
78   }
79 12 else if (dbattr.IsPassword) {
80  
81 4 ChangePassword cp = new ChangePassword();
82  
83 4 container.Controls.Add(cp);
84 4 cp.DataBinding += new EventHandler(cp_DataBinding);
85  
86 4 cp.Validators.AddRange(Configuration.Session
87   .MappingHandler.GetValidators(propertyInfo));
88  
89   }
90   else {
91  
92 8 TextField tf = new TextField();
93  
94 8 tf.DataBinding += new EventHandler(tf_DataBinding);
95 8 tf.Width = Unit.Percentage(100);
96 8 container.Controls.Add(tf);
97  
98 8 tf.Validators.AddRange(Configuration.Session.MappingHandler
99   .GetValidators(propertyInfo));
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 8 private void tf_DataBinding(object sender, EventArgs e)
110   {
111 8 TextField tf;
112 8 tf = (TextField) sender;
113 8 DataGridItem container = (DataGridItem) tf.NamingContainer;
114 8 tf.InputText += DataBinder.Eval(container.DataItem,propertyInfo.Name);
115  
116 8 DataGrid dg = container.Parent.Parent
117   as DataGrid;
118  
119 8 int pos = container.DataSetIndex - dg.PageSize*dg.CurrentPageIndex;
120  
121 8 tf.MergeTextStyle((pos % 2 == 0) ? dg.ItemStyle : dg.AlternatingItemStyle);
122 8 tf.MergeControlStyle(dg.ChildControlStyle);
123   }
124  
125   /// <summary>
126   /// DataBinding Event related with a control of the template. Very useful to
127   /// assign correct values to template controls.
128   /// </summary>
129   /// <param name="sender">Sender who invoke the data binding</param>
130   /// <param name="e">Arguments of the event</param>
131 4 private void cb_DataBinding(object sender, EventArgs e)
132   {
133 4 CheckBox cb;
134 4 cb = (CheckBox) sender;
135 4 DataGridItem container = (DataGridItem) cb.NamingContainer;
136 4 cb.Checked = Convert.ToBoolean(
137   DataBinder.Eval(container.DataItem,propertyInfo.Name));
138   }
139  
140 4 private void cp_DataBinding(object sender, EventArgs e)
141   {
142 4 ChangePassword cp;
143 4 cp = (ChangePassword) sender;
144 4 DataGridItem container = (DataGridItem) cp.NamingContainer;
145 4 DataGrid dg = container.Parent.Parent
146   as DataGrid;
147  
148 4 int pos = container.DataSetIndex - dg.PageSize*dg.CurrentPageIndex;
149  
150 4 cp.MergeTextStyle((pos % 2 == 0) ? dg.ItemStyle : dg.AlternatingItemStyle);
151 4 cp.MergeControlStyle(dg.ChildControlStyle);
152   }
153  
154 4 private void date_DataBinding(object sender, EventArgs e)
155   {
156 4 Calendar date;
157 4 date = (Calendar)sender;
158 4 DataGridItem container = (DataGridItem) date.NamingContainer;
159  
160 4 DataGrid dg = container.Parent.Parent
161   as DataGrid;
162  
163 4 DateTime selDate = Convert.ToDateTime(
164   DataBinder.Eval(container.DataItem,propertyInfo.Name));
165  
166 4 if (dg.DateTimeFormat == "")
167 4 date.SelectedDate = selDate.ToString();
168   else
169 0 date.SelectedDate = selDate.ToString(dg.DateTimeFormat);
170  
171 4 date.MergeControlStyle(dg.ChildControlStyle);
172   }
173   }
174   }
175