| |||||||||||||||||
Source File | Conditionals | Statements | Methods | TOTAL | |||||||||||||
Web\WebControls\CheckBoxList.cs | 100,0 % | 100,0 % | 100,0 % | 100,0 % |
|
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.ComponentModel; | |
25 | using System.Reflection; | |
26 | using System.Web.UI; | |
27 | using System.Web.UI.WebControls; | |
28 | using ShowX.Config; | |
29 | using ShowX.Model; | |
30 | ||
31 | namespace ShowX.Web.WebControls | |
32 | { | |
33 | /// <summary> | |
34 | /// CheckBoxList control define a compound control with a Web Calendar and a label. | |
35 | /// </summary> | |
36 | [DefaultProperty("Text"), | |
37 | ToolboxData("<{0}:DataGrid runat=server></{0}:DataGrid>")] | |
38 | public class CheckBoxList : ValidatedControl | |
39 | { | |
40 | /// <summary> | |
41 | /// Property info instance associated to collection property. | |
42 | /// </summary> | |
43 | protected PropertyInfo propertyInfo; | |
44 | ||
45 | /// <summary> | |
46 | /// CheckBoxList control contained by this control. | |
47 | /// </summary> | |
48 | protected System.Web.UI.WebControls.CheckBoxList cblist; | |
49 | ||
50 | /// <summary> | |
51 | /// Constructor. | |
52 | /// </summary> | |
53 | /// <param name="propertyInfo">Property info instance associated to collection | |
54 | /// property.</param> | |
55 | 29 | public CheckBoxList(PropertyInfo propertyInfo) : base() |
56 | { | |
57 | 29 | this.propertyInfo = propertyInfo; |
58 | } | |
59 | ||
60 | /// <summary> | |
61 | /// Collection mapping associated to this control. | |
62 | /// </summary> | |
63 | public ICollectionMap CollectionMap | |
64 | { | |
65 | 10 | get |
66 | { | |
67 | 10 | return Configuration.Session.MappingHandler |
68 | .GetPropertyMap(propertyInfo) as ICollectionMap; | |
69 | } | |
70 | } | |
71 | ||
72 | /// <summary> | |
73 | /// Create child controls for this control. | |
74 | /// </summary> | |
75 | 29 | protected override void CreateChildControls() |
76 | { | |
77 | 29 | base.CreateChildControls (); |
78 | 29 | this.cblist = new System.Web.UI.WebControls.CheckBoxList(); |
79 | 29 | Controls.Add(cblist); |
80 | } | |
81 | ||
82 | /// <summary> | |
83 | /// Expose by delegation the Items collection of the contained CheckBoxList | |
84 | /// control. | |
85 | /// </summary> | |
86 | public ListItemCollection Items | |
87 | { | |
88 | 115 | get { return cblist.Items; } |
89 | } | |
90 | ||
91 | /// <summary> | |
92 | /// Merge current styles with a new one. | |
93 | /// </summary> | |
94 | /// <param name="style">New style to merge.</param> | |
95 | 29 | public override void MergeControlStyle(Style style) |
96 | { | |
97 | 29 | EnsureChildControls(); |
98 | 29 | cblist.MergeStyle(style); |
99 | 29 | messageL.MergeStyle(style); |
100 | } | |
101 | ||
102 | /// <summary> | |
103 | /// Allow to check whether the selection over the list box match | |
104 | /// restrictions. | |
105 | /// </summary> | |
106 | /// <returns>True if the selection match restrictions, false otherwise. | |
107 | /// </returns> | |
108 | 6 | public override bool Validate(object context) |
109 | { | |
110 | 6 | string message = string.Empty; |
111 | 6 | Validated = true; |
112 | ||
113 | 6 | int selCant = 0; |
114 | ||
115 | 6 | foreach (ListItem il in this.Items) |
116 | 18 | if (il.Selected) selCant++; |
117 | ||
118 | 6 | foreach(IValidationMap val in Validators) { |
119 | ||
120 | 6 | if (!val.Validate(context,selCant.ToString())) { |
121 | ||
122 | 2 | message += " " + val.Message + "."; |
123 | 2 | Validated = false ; |
124 | ||
125 | } | |
126 | } | |
127 | ||
128 | 6 | messageL.Text = message; |
129 | 6 | return Validated; |
130 | } | |
131 | ||
132 | /// <summary> | |
133 | /// Method Render is in charge of render the control to html code | |
134 | /// </summary> | |
135 | /// <param name="writer">Writer to output html code</param> | |
136 | 25 | protected override void Render(HtmlTextWriter writer) |
137 | { | |
138 | 25 | writer.Write(@" |
139 | <table border=0 cellpadding=0 width=100%> | |
140 | <tbody> | |
141 | <tr> | |
142 | <td>"); | |
143 | ||
144 | 25 | cblist.RenderControl(writer); |
145 | ||
146 | 25 | writer.Write(@" |
147 | </td> | |
148 | </tr>"); | |
149 | ||
150 | 25 | if (!Validated) { |
151 | ||
152 | 2 | writer.Write(@" |
153 | <tr> | |
154 | <td>"); | |
155 | ||
156 | 2 | messageL.RenderControl(writer); |
157 | ||
158 | 2 | writer.Write(@" |
159 | </td> | |
160 | </tr>"); | |
161 | ||
162 | } | |
163 | 25 | writer.Write(@" |
164 | </tbody> | |
165 | </table>"); | |
166 | } | |
167 | } | |
168 | } | |
169 |
|