1 // Mainsoft.Web.AspnetConfig - Site AspnetConfig utility
\r
2 // (C) 2006 Mainsoft Corporation (http://www.mainsoft.com)
\r
3 // Permission is hereby granted, free of charge, to any person obtaining
\r
4 // a copy of this software and associated documentation files (the
\r
5 // "Software"), to deal in the Software without restriction, including
\r
6 // without limitation the rights to use, copy, modify, merge, publish,
\r
7 // distribute, sublicense, and/or sell copies of the Software, and to
\r
8 // permit persons to whom the Software is furnished to do so, subject to
\r
9 // the following conditions:
\r
11 // The above copyright notice and this permission notice shall be
\r
12 // included in all copies or substantial portions of the Software.
\r
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
25 using System.Configuration;
\r
27 using System.Web.Security;
\r
28 using System.Web.UI;
\r
29 using System.Web.UI.WebControls;
\r
30 using System.Web.UI.HtmlControls;
\r
31 using System.Text.RegularExpressions;
\r
33 namespace Mainsoft.Web.AspnetConfig
\r
35 public class RolesDS
\r
37 public static DataTable Select()
\r
39 return CreateDataTable();
\r
42 public static DataTable SelectUser()
\r
44 return CreateUserDataTable();
\r
47 public static DataTable SelectUser(string searchtag, string searchby)
\r
49 return CreateUserDataTable(searchtag, searchby);
\r
52 public static DataTable SelectUsersRole(string user)
\r
54 return CreateUsersRoles(user);
\r
57 public static DataTable CreateUsersRoles(string user)
\r
59 DataTable aTable = new DataTable("A");
\r
65 // Create User Name column and add to the table
\r
66 dtCol = new DataColumn();
\r
67 dtCol.DataType = Type.GetType("System.String");
\r
68 dtCol.ColumnName = "Role";
\r
69 dtCol.AutoIncrement = false;
\r
70 dtCol.ReadOnly = false;
\r
71 dtCol.Unique = true;
\r
72 aTable.Columns.Add(dtCol);
\r
74 dtCol1 = new DataColumn();
\r
75 dtCol1.DataType = Type.GetType("System.Boolean");
\r
76 dtCol1.ColumnName = "IsInRole";
\r
77 dtCol1.AutoIncrement = false;
\r
78 dtCol1.ReadOnly = false;
\r
79 dtCol1.Unique = false;
\r
80 aTable.Columns.Add(dtCol1);
\r
82 if (Roles.Enabled) {
\r
83 // Create rows to the table
\r
84 foreach (String role in Roles.GetAllRoles ()) {
\r
85 dtRow = aTable.NewRow ();
\r
86 dtRow["Role"] = role;
\r
87 dtRow["IsInRole"] = Roles.IsUserInRole (user, role);
\r
88 aTable.Rows.Add (dtRow);
\r
91 aTable.PrimaryKey = new DataColumn[] { aTable.Columns["Role"] };
\r
95 public static DataTable Delete(string Role)
\r
97 if (Roles.RoleExists(Role))
\r
99 Roles.DeleteRole(Role,false);
\r
104 public static DataTable DeleteUser(string User)
\r
106 Membership.DeleteUser(User, true);
\r
107 return SelectUser();
\r
110 public static DataTable CreateUserDataTable()
\r
112 DataTable aTable = new DataTable("A");
\r
117 // Create User Name column and add to the table
\r
118 dtCol = new DataColumn();
\r
119 dtCol.DataType = Type.GetType("System.String");
\r
120 dtCol.ColumnName = "User";
\r
121 dtCol.AutoIncrement = false;
\r
122 dtCol.ReadOnly = false;
\r
123 dtCol.Unique = true;
\r
124 aTable.Columns.Add(dtCol);
\r
126 dtCol1 = new DataColumn();
\r
127 dtCol1.DataType = Type.GetType("System.Boolean");
\r
128 dtCol1.ColumnName = "Active";
\r
129 dtCol1.AutoIncrement = false;
\r
130 dtCol1.ReadOnly = false;
\r
131 dtCol1.Unique = false;
\r
132 aTable.Columns.Add(dtCol1);
\r
134 // Create rows to the table
\r
135 foreach (MembershipUser user in Membership.GetAllUsers())
\r
137 dtRow = aTable.NewRow();
\r
138 dtRow["User"] = user.UserName;
\r
139 dtRow["Active"] = user.IsApproved;
\r
140 aTable.Rows.Add(dtRow);
\r
143 aTable.PrimaryKey = new DataColumn[] { aTable.Columns["User"] };
\r
147 public static DataTable CreateUserDataTable(string searchtag, string searchby)
\r
149 DataTable aTable = new DataTable("A");
\r
154 dtCol = new DataColumn();
\r
155 dtCol.DataType = Type.GetType("System.String");
\r
156 dtCol.ColumnName = "User";
\r
157 dtCol.AutoIncrement = false;
\r
158 dtCol.ReadOnly = false;
\r
159 dtCol.Unique = true;
\r
160 aTable.Columns.Add(dtCol);
\r
162 dtCol1 = new DataColumn();
\r
163 dtCol1.DataType = Type.GetType("System.Boolean");
\r
164 dtCol1.ColumnName = "Active";
\r
165 dtCol1.AutoIncrement = false;
\r
166 dtCol1.ReadOnly = false;
\r
167 dtCol1.Unique = false;
\r
168 aTable.Columns.Add(dtCol1);
\r
170 string text = searchtag;
\r
171 text = text.Replace("*", "%");
\r
172 text = text.Replace("?", "_");
\r
174 if (text.Trim() == "\"\"")
\r
177 if (searchby == "Name")
\r
179 foreach (MembershipUser user in Membership.FindUsersByName(text))
\r
181 dtRow = aTable.NewRow();
\r
182 dtRow["User"] = user.UserName;
\r
183 dtRow["Active"] = user.IsApproved;
\r
184 aTable.Rows.Add(dtRow);
\r
189 foreach (MembershipUser user in Membership.FindUsersByEmail(text))
\r
191 dtRow = aTable.NewRow();
\r
192 dtRow["User"] = user.UserName;
\r
193 dtRow["Active"] = user.IsApproved;
\r
194 aTable.Rows.Add(dtRow);
\r
198 aTable.PrimaryKey = new DataColumn[] { aTable.Columns["User"] };
\r
202 public static DataTable CreateDataTable()
\r
204 DataTable aTable = new DataTable("A");
\r
208 // Create Name column and add to the table
\r
209 dtCol = new DataColumn();
\r
210 dtCol.DataType = Type.GetType("System.String");
\r
211 dtCol.ColumnName = "Role";
\r
212 dtCol.AutoIncrement = false;
\r
213 dtCol.Caption = "Role Name";
\r
214 dtCol.ReadOnly = false;
\r
215 dtCol.Unique = false;
\r
216 aTable.Columns.Add(dtCol);
\r
218 if (Roles.Enabled) {
\r
219 // Create rows to the table
\r
220 foreach (string str in Roles.GetAllRoles ()) {
\r
221 dtRow = aTable.NewRow ();
\r
222 dtRow["Role"] = str;
\r
223 aTable.Rows.Add (dtRow);
\r
227 aTable.PrimaryKey = new DataColumn[] { aTable.Columns["Role"] };
\r
231 public static DataTable CreateManageRoleTable(string role, string searchtag, string searchby)
\r
233 DataTable aTable = new DataTable("A");
\r
238 // Create UserName column and add to the table
\r
239 dtCol = new DataColumn();
\r
240 dtCol.DataType = Type.GetType("System.String");
\r
241 dtCol.ColumnName = "User";
\r
242 dtCol.AutoIncrement = false;
\r
243 dtCol.Caption = "User Name";
\r
244 dtCol.ReadOnly = false;
\r
245 dtCol.Unique = true;
\r
246 aTable.Columns.Add(dtCol);
\r
248 // Create User in role bool column and add to the table
\r
249 dtCol1 = new DataColumn();
\r
250 dtCol1.DataType = Type.GetType("System.Boolean");
\r
251 dtCol1.ColumnName = "InRole";
\r
252 dtCol1.AutoIncrement = false;
\r
253 dtCol1.Caption = "User Is In Role";
\r
254 dtCol1.ReadOnly = false;
\r
255 dtCol1.Unique = false;
\r
256 aTable.Columns.Add(dtCol1);
\r
258 string text = searchtag;
\r
259 text = text.Replace("*", "%");
\r
260 text = text.Replace("?", "_");
\r
262 if (text.Trim() == "\"\"")
\r
265 if (searchby == "Name")
\r
267 foreach (MembershipUser user in Membership.FindUsersByName(text))
\r
269 dtRow = aTable.NewRow();
\r
270 dtRow["User"] = user.UserName;
\r
271 if (Roles.Enabled) {
\r
272 dtRow["InRole"] = Roles.IsUserInRole (user.UserName, role);
\r
275 dtRow["InRole"] = false;
\r
277 aTable.Rows.Add(dtRow);
\r
282 foreach (MembershipUser user in Membership.FindUsersByEmail(text))
\r
284 dtRow = aTable.NewRow();
\r
285 dtRow["User"] = user.UserName;
\r
286 if (Roles.Enabled) {
\r
287 dtRow["InRole"] = Roles.IsUserInRole (user.UserName, role);
\r
290 dtRow["InRole"] = false;
\r
292 aTable.Rows.Add(dtRow);
\r
295 aTable.PrimaryKey = new DataColumn[] { aTable.Columns["User"] };
\r