Clover.NET coverage report - Coverage

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

File Stats: LOC: 233   Methods: 8
NCLOC: 101 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Web\WebControls\ProgressBar.cs 0,0 % 0,0 % 0,0 % 0,0 %
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.IO;
26   using System.Reflection;
27   using System.Web.UI;
28   using System.Web.UI.WebControls;
29   using System.ComponentModel;
30   using ShowX.Model;
31   using ShowX.Helper;
32   using ShowX.Config;
33  
34   namespace ShowX.Web.WebControls
35   {
36   /// <summary>
37   /// ProgressBar show result as a percent of the total.
38   /// </summary>
39   [DefaultProperty("Text"),
40   ToolboxData("<{0}:ProgressBar runat=server></{0}:ProgressBar>")]
41   public class ProgressBar : System.Web.UI.WebControls.WebControl, INamingContainer
42   {
43   /// <summary>
44   /// Name of file where to write bluedot image
45   /// </summary>
46   protected static string blueDotFileName = "bluedot.png";
47  
48   /// <summary>
49   /// Name of file where to write blackdot image
50   /// </summary>
51   protected static string blackDotFileName = "blackdot.png";
52  
53   /// <summary>
54   /// Name of the embedded resource that represents bluedot image.
55   /// </summary>
56   protected static string blueDotEmbeddedPath =
57   "ShowX.Web.WebControls.Resources.bluedot.png";
58  
59   /// <summary>
60   /// Name of the embedded resource that represents blackdot image.
61   /// </summary>
62   protected static string blackDotEmbeddedPath =
63   "ShowX.Web.WebControls.Resources.blackdot.png";
64  
65   /// <summary>
66   /// Property to show result
67   /// </summary>
68   protected PropertyInfo propertyInfo = null;
69  
70   /// <summary>
71   /// Max value of this progressbar
72   /// </summary>
73   protected string maxProperty = string.Empty;
74  
75   /// <summary>
76   /// Instance of an ShowX type to represent value
77   /// </summary>
78   protected object xInstance = null;
79  
80   /// <summary>
81   /// Keep track whether we want to show the property name on the control
82   /// </summary>
83   protected bool showName = true;
84  
85   /// <summary>
86   /// Keep track whether we want to show the used percent on the control
87   /// </summary>
88   protected bool showPercent = true;
89  
90   /// <summary>
91   /// Control to show the property name
92   /// </summary>
93   protected Label propertyNameL;
94  
95   /// <summary>
96   /// Control to show percent name
97   /// </summary>
98   protected Label percentTextL;
99  
100   /// <summary>
101   /// Constructor
102   /// </summary>
103   /// <param name="maxProperty">Max value of this progressbar</param>
104   /// <param name="propertyInfo">Property to show result</param>
105 0 public ProgressBar(string maxProperty, PropertyInfo propertyInfo)
106   {
107   this.maxProperty = maxProperty;
108   this.propertyInfo = propertyInfo;
109   Controls.Add(propertyNameL = new Label());
110   Controls.Add(percentTextL = new Label());
111   }
112  
113   /// <summary>
114   /// Reflex the xinstance attribute, in a read-only way
115   /// </summary>
116 0 public object XInstance
117   {
118   set { xInstance = value; }
119   }
120  
121   /// <summary>
122   /// Reflex the showName attribute, in a read-only way
123   /// </summary>
124 0 public bool ShowName
125   {
126   get { return showName; }
127   set { showName = value; }
128   }
129  
130   /// <summary>
131   /// Reflex the showPercent attribute, in a read-only way
132   /// </summary>
133 0 public bool ShowPercent
134   {
135   get { return showPercent; }
136   set { showPercent = value; }
137   }
138  
139   /// <summary>
140   /// Allow to change style to the texts shown on the control (Property name
141   /// and percent)
142   /// </summary>
143 0 public TableItemStyle TextStyle
144   {
145   set
146   {
147   propertyNameL.ApplyStyle(value);
148   percentTextL.ApplyStyle(value);
149   }
150   }
151  
152   /// <summary>
153   /// Method Render is in charge of render the control to html code
154   /// </summary>
155   /// <param name="writer">Writer to output html code</param>
156 0 protected override void Render(HtmlTextWriter writer)
157   {
158   if (!File.Exists(this.Page.MapPath(blueDotFileName)))
159   ResourceHelper.WriteResourceToFile(Assembly.GetExecutingAssembly(),
160   blueDotEmbeddedPath,
161   Page.MapPath(blueDotFileName));
162  
163   if (!File.Exists(this.Page.MapPath(blackDotFileName)))
164   ResourceHelper.WriteResourceToFile(Assembly.GetExecutingAssembly(),
165   blackDotEmbeddedPath,
166   Page.MapPath(blackDotFileName));
167  
168   int percent = 0;
169  
170   Type xType = propertyInfo.DeclaringType;
171  
172   int max = Convert.ToInt32(
173   xType.GetProperty(maxProperty).GetValue(xInstance,null));
174   int size = Convert.ToInt32(propertyInfo.GetValue(xInstance,null));
175  
176   IPropertyMap attr = Configuration.Session.MappingHandler
177   .GetPropertyMap(propertyInfo);
178  
179   percent = size*100/max;
180  
181   writer.Write(@"
182   <table border=0 cellpadding=0 cellspacing=5>
183   <tbody>
184   <tr>");
185  
186   if (ShowName) {
187  
188   propertyNameL.Text = attr.Name;
189   writer.Write(@"<td>");
190   propertyNameL.RenderControl(writer);
191   writer.Write("</td>");
192   }
193  
194   writer.Write(@"
195   <td>
196   <table border=0 cellpadding=0 cellspacing=0>
197   <tbody>
198   <tr>
199   <td><img src=blackdot.png height=1 width=1></td>
200   <td><img src=blackdot.png height=1 width=50></td>
201   <td><img src=blackdot.png height=1 width=1></td>
202   </tr>
203   <tr>
204   <td><img src=blackdot.png height=5 width=1></td>
205   <td align=left bgcolor=#e0e0e0><img src=bluedot.png height=5 width="
206   + percent
207   + @"%></td>
208   <td><img src=blackdot.png height=5 width=1></td>
209   </tr>
210   <tr>
211   <td><img src=blackdot.png height=1 width=1></td>
212   <td><img src=blackdot.png height=1 width=50></td>
213   <td><img src=blackdot.png height=1 width=1></td>
214   </tr>
215   </tbody>
216   </table>
217   </td>");
218  
219   if (ShowPercent) {
220  
221   percentTextL.Text = percent + "%";
222   writer.Write(@"<td>");
223   percentTextL.RenderControl(writer);
224   writer.Write("</td>");
225   }
226   writer.Write(@"
227   </tr>
228   </tbody>
229   </table>");
230   }
231   }
232   }
233