Clover.NET coverage report - Coverage

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

File Stats: LOC: 203   Methods: 9
NCLOC: 104 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Web\WebControls\Calendar.cs 100,0 % 97,4 % 88,9 % 96,1 %
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.ComponentModel;
26   using System.Reflection;
27   using System.Web.UI;
28   using System.Web.UI.WebControls;
29   using System.Web.UI.HtmlControls;
30   using ShowX.Config;
31   using ShowX.Model;
32   using ShowX.Web.Scripts;
33  
34   namespace ShowX.Web.WebControls
35   {
36   /// <summary>
37   /// Calendar control define a compound control with a Web Calendar and a label.
38   /// </summary>
39   [DefaultProperty("Text"),
40   ToolboxData("<{0}:DataGrid runat=server></{0}:DataGrid>")]
41   public class Calendar : ValidatedControl
42   {
43   /// <summary>
44   /// Property info instance associated to collection property.
45   /// </summary>
46   protected PropertyInfo propertyInfo;
47  
48   /// <summary>
49   /// Represents the date text.
50   /// </summary>
51   protected System.Web.UI.WebControls.TextBox calendarText;
52  
53   /// <summary>
54   /// Button to activate jsCalendar.
55   /// </summary>
56   protected System.Web.UI.HtmlControls.HtmlButton activationBtn;
57  
58   /// <summary>
59   /// Constructor.
60   /// </summary>
61   /// <param name="propertyInfo">Property info instance associated to collection
62   /// property.</param>
63 29 public Calendar(PropertyInfo propertyInfo) : base()
64   {
65 29 this.propertyInfo = propertyInfo;
66   }
67  
68   /// <summary>
69   /// Collection mapping associated to this control.
70   /// </summary>
71 0 public ICollectionMap CollectionMap
72   {
73   get
74   {
75   return Configuration.Session.MappingHandler
76   .GetPropertyMap(propertyInfo) as ICollectionMap;
77   }
78   }
79  
80   /// <summary>
81   /// OnLoad event handler.
82   /// </summary>
83   /// <param name="e">Arguments for the OnLoad event.</param>
84 29 protected override void OnLoad(EventArgs e)
85   {
86 29 CreateChildControls();
87   }
88  
89   /// <summary>
90   /// Create child controls for this control.
91   /// </summary>
92 58 protected override void CreateChildControls()
93   {
94 58 base.CreateChildControls();
95  
96 58 if (this.Page != null)
97 33 new IncludeJSCalendarScriptBlock().Register(this.Page);
98  
99 58 calendarText = new TextBox();
100 58 calendarText.Text = "(not specified)";
101 58 calendarText.ReadOnly = true;
102 58 activationBtn = new HtmlButton();
103 58 activationBtn.InnerText = "...";
104 58 activationBtn.ID = System.Guid.NewGuid().ToString();
105 58 Controls.Add(calendarText);
106 58 Controls.Add(activationBtn);
107   }
108  
109   /// <summary>
110   /// Expose the selected date.
111   /// control.
112   /// </summary>
113   public string SelectedDate
114   {
115 5 get
116   {
117 5 EnsureChildControls();
118 5 return this.calendarText.Text;
119   }
120  
121 4 set
122   {
123 4 EnsureChildControls();
124 4 this.calendarText.Text = value;
125   }
126   }
127  
128   /// <summary>
129   /// Merge current styles with a new one.
130   /// </summary>
131   /// <param name="style">New style to merge.</param>
132 54 public override void MergeControlStyle(Style style)
133   {
134 54 EnsureChildControls();
135 54 calendarText.MergeStyle(style);
136 54 messageL.ControlStyle.MergeWith(style);
137   }
138  
139   /// <summary>
140   /// Allow to check whether the selection over the list box match
141   /// restrictions.
142   /// </summary>
143   /// <returns>True if the selection match restrictions, false otherwise.
144   /// </returns>
145 4 public override bool Validate(object context)
146   {
147 4 Validated = true;
148  
149 4 try {
150  
151 4 Convert.ToDateTime(calendarText.Text);
152   }
153   catch {
154  
155 1 Validated = false;
156 1 messageL.Text = "You have to select a valid date";
157   }
158  
159 4 return Validated;
160   }
161  
162   /// <summary>
163   /// Method Render is in charge of render the control to html code
164   /// </summary>
165   /// <param name="writer">Writer to output html code</param>
166 25 protected override void Render(HtmlTextWriter writer)
167   {
168 25 writer.Write(@"
169   <table border=0 cellpadding=0 width=100%>
170   <tbody>
171   <tr>
172   <td>");
173  
174 25 calendarText.RenderControl(writer);
175  
176 25 writer.Write(@"
177   </td><td>");
178  
179 25 activationBtn.RenderControl(writer);
180 25 writer.Write("</td></tr>");
181  
182 25 if (!Validated) {
183  
184 1 writer.Write(@"
185   <tr>
186   <td colspan=2>");
187  
188 1 messageL.RenderControl(writer);
189  
190 1 writer.Write(@"
191   </td>
192   </tr>");
193   }
194 25 writer.Write(@"
195   </tbody>
196   </table>");
197  
198 25 new JSCalendarSetupScriptBlock(calendarText.UniqueID,activationBtn.ClientID)
199   .Register(this.Page);
200   }
201   }
202   }
203