Repository navigation
Expand file tree
/
Copy pathUserAppController.cs
More file actions
347 lines (309 loc) · 13.7 KB
/
Copy pathUserAppController.cs
File metadata and controls
347 lines (309 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebMvc.Controllers
{
public class UserAppController : MyController
{
//
// GET: /UserApp/
public ActionResult Index()
{
return View();
}
public ActionResult Tree()
{
string userid = Request.QueryString["id"];
Business.Platform.Role brole = new Business.Platform.Role();
var roles = new Business.Platform.UsersRole().GetByUserID(userid.ToGuid());
List<Data.Model.Role> roleList = new List<Data.Model.Role>();
foreach (var role in roles)
{
var role1 = brole.Get(role.RoleID);
if (role1 == null)
{
continue;
}
roleList.Add(role1);
}
ViewBag.RoleOptions = new Business.Platform.Role().GetRoleOptions(Request.QueryString["roleid"], "", roleList);
return View();
}
public string Tree1()
{
string roleID = Request.QueryString["roleid"];
Guid roleGuid;
if (!roleID.IsGuid(out roleGuid))
{
return "[]";
}
Business.Platform.RoleApp BRoleApp = new Business.Platform.RoleApp();
var appDt = BRoleApp.GetAllDataTableByRoleID(roleGuid);
if (appDt.Rows.Count == 0)
{
return "[]";
}
var root = appDt.Select("ParentID='" + Guid.Empty.ToString() + "'");
if (root.Length == 0)
{
return "[]";
}
var apps = appDt.Select("ParentID='" + root[0]["ID"].ToString() + "'");
System.Text.StringBuilder json = new System.Text.StringBuilder("[", 1000);
System.Data.DataRow rootDr = root[0];
json.Append("{");
json.AppendFormat("\"id\":\"{0}\",", rootDr["ID"]);
json.AppendFormat("\"title\":\"{0}\",", rootDr["Title"]);
json.AppendFormat("\"ico\":\"{0}\",", rootDr["Ico"]);
json.AppendFormat("\"link\":\"{0}\",", rootDr["Address"]);
json.AppendFormat("\"type\":\"{0}\",", "0");
json.AppendFormat("\"model\":\"{0}\",", rootDr["OpenMode"]);
json.AppendFormat("\"width\":\"{0}\",", rootDr["Width"]);
json.AppendFormat("\"height\":\"{0}\",", rootDr["Height"]);
json.AppendFormat("\"hasChilds\":\"{0}\",", apps.Length > 0 ? "1" : "0");
json.AppendFormat("\"childs\":[");
for (int i = 0; i < apps.Length; i++)
{
System.Data.DataRow dr = apps[i];
var childs = appDt.Select("ParentID='" + dr["ID"].ToString() + "'");
json.Append("{");
json.AppendFormat("\"id\":\"{0}\",", dr["ID"]);
json.AppendFormat("\"title\":\"{0}\",", dr["Title"]);
json.AppendFormat("\"ico\":\"{0}\",", dr["Ico"]);
json.AppendFormat("\"link\":\"{0}\",", dr["Address"]);
json.AppendFormat("\"type\":\"{0}\",", "0");
json.AppendFormat("\"model\":\"{0}\",", dr["OpenMode"]);
json.AppendFormat("\"width\":\"{0}\",", dr["Width"]);
json.AppendFormat("\"height\":\"{0}\",", dr["Height"]);
json.AppendFormat("\"hasChilds\":\"{0}\",", childs.Length > 0 ? "1" : "0");
json.AppendFormat("\"childs\":[");
json.Append("]");
json.Append("}");
if (i < apps.Length - 1)
{
json.Append(",");
}
}
json.Append("]");
json.Append("}");
json.Append("]");
return json.ToString();
}
public string TreeRefresh()
{
string id = Request["refreshid"];
string userID = Request.QueryString["userid"];
Guid rid;
if (!id.IsGuid(out rid))
{
return "[]";
}
Business.Platform.RoleApp BRoleApp = new Business.Platform.RoleApp();
Business.Platform.UsersApp BUsersApp = new Business.Platform.UsersApp();
var childs = BRoleApp.GetChild(rid);
//加载个人应用
if (userID.IsGuid())
{
BUsersApp.AppendUserApps(userID.ToGuid(), rid, childs);
}
System.Text.StringBuilder json = new System.Text.StringBuilder("[", childs.Count * 50);
int count = childs.Count;
int i = 0;
foreach (var child in childs.OrderBy(p => p.Sort))
{
json.Append("{");
json.AppendFormat("\"id\":\"{0}\",", child.ID.ToString());
json.AppendFormat("\"title\":\"{0}\",", child.Title);
json.AppendFormat("\"ico\":\"{0}\",", child.Ico);
json.AppendFormat("\"link\":\"{0}\",", "");
json.AppendFormat("\"type\":\"{0}\",", child.Type);
json.AppendFormat("\"model\":\"{0}\",", "");
json.AppendFormat("\"width\":\"{0}\",", "");
json.AppendFormat("\"height\":\"{0}\",", "");
json.AppendFormat("\"hasChilds\":\"{0}\",", BRoleApp.HasChild(child.ID) || BUsersApp.HasChild(child.ID) ? "1" : "0");
json.AppendFormat("\"childs\":[");
json.Append("]");
json.Append("}");
if (i++ < count - 1)
{
json.Append(",");
}
}
json.Append("]");
return json.ToString();
}
public ActionResult Empty()
{
return null;
}
public ActionResult Body()
{
Business.Platform.AppLibrary bappLibrary = new Business.Platform.AppLibrary();
Business.Platform.RoleApp broleApp = new Business.Platform.RoleApp();
Data.Model.RoleApp roleApp = null;
string id = Request.QueryString["id"];
string name = string.Empty;
string type = string.Empty;
string appid = string.Empty;
string params1 = string.Empty;
string ico = string.Empty;
Guid appID;
if (id.IsGuid(out appID))
{
roleApp = broleApp.Get(appID);
if (roleApp != null)
{
name = roleApp.Title;
type = roleApp.AppID.HasValue ? bappLibrary.GetTypeByID(roleApp.AppID.Value) : "";
appid = roleApp.AppID.ToString();
params1 = roleApp.Params;
ico = roleApp.Ico;
}
}
if (roleApp == null)
{
roleApp = new Data.Model.RoleApp();
}
ViewBag.AppID = appid;
ViewBag.AppTypesOptions = bappLibrary.GetTypeOptions(type);
return View(roleApp);
}
public ActionResult AddApp()
{
return AddApp(null);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AddApp(FormCollection collection)
{
Business.Platform.AppLibrary bappLibrary = new Business.Platform.AppLibrary();
Business.Platform.UsersApp busersApp = new Business.Platform.UsersApp();
Business.Platform.RoleApp broleApp = new Business.Platform.RoleApp();
Data.Model.UsersApp usersApp = null;
string id = Request.QueryString["id"];
string userID = Request.QueryString["userid"];
string roleID = Request.QueryString["roleid"];
if (collection != null && id.IsGuid() && userID.IsGuid())
{
usersApp = busersApp.Get(id.ToGuid());
if (!Request.Form["Save"].IsNullOrEmpty())
{
string name = Request.Form["Name"];
string type = Request.Form["Type"];
string appid = Request.Form["AppID"];
string params1 = Request.Form["Params"];
string ico = Request.Form["Ico"];
Data.Model.UsersApp usersApp1 = new Data.Model.UsersApp();
usersApp1.ID = Guid.NewGuid();
usersApp1.ParentID = id.ToGuid();
usersApp1.Title = name.Trim();
usersApp1.Sort = broleApp.GetMaxSort(id.ToGuid());
usersApp1.UserID = userID.ToGuid();
usersApp1.RoleID = roleID.IsGuid() ? roleID.ToGuid() : Guid.Empty;
if (appid.IsGuid())
{
usersApp1.AppID = appid.ToGuid();
}
else
{
usersApp1.AppID = null;
}
usersApp1.Params = params1.IsNullOrEmpty() ? null : params1.Trim();
if (!ico.IsNullOrEmpty())
{
usersApp1.Ico = ico;
}
busersApp.Add(usersApp1);
busersApp.ClearCache();
Business.Platform.Log.Add("添加了个人应用", busersApp.Serialize(), Business.Platform.Log.Types.角色应用);
string refreshID = id;
ViewBag.Script = "alert('添加成功!'); parent.frames[0].reLoad('" + refreshID + "')";
}
}
ViewBag.AppTypesOptions = bappLibrary.GetTypeOptions();
return View();
}
public ActionResult Body1()
{
return Body1(null);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Body1(FormCollection collection)
{
Business.Platform.AppLibrary bappLibrary = new Business.Platform.AppLibrary();
Business.Platform.RoleApp broleApp = new Business.Platform.RoleApp();
Business.Platform.UsersApp buserApp = new Business.Platform.UsersApp();
Data.Model.UsersApp usersApp = null;
string id = Request.QueryString["id"];
string name = string.Empty;
string type = string.Empty;
string appid = string.Empty;
string params1 = string.Empty;
string ico = string.Empty;
Guid appID;
if (id.IsGuid(out appID))
{
usersApp = buserApp.Get(appID);
if (usersApp != null)
{
name = usersApp.Title;
type = usersApp.AppID.HasValue ? bappLibrary.GetTypeByID(usersApp.AppID.Value) : "";
appid = usersApp.AppID.ToString();
params1 = usersApp.Params;
ico = usersApp.Ico;
}
}
if (collection != null && usersApp != null)
{
if (!Request.Form["Save"].IsNullOrEmpty())
{
name = Request.Form["Name"];
type = Request.Form["Type"];
appid = Request.Form["AppID"];
params1 = Request.Form["Params"];
ico = Request.Form["Ico"];
string oldXML = usersApp.Serialize();
usersApp.Title = name.Trim();
if (appid.IsGuid())
{
usersApp.AppID = appid.ToGuid();
}
else
{
usersApp.AppID = null;
}
usersApp.Params = params1.IsNullOrEmpty() ? null : params1.Trim();
if (!ico.IsNullOrEmpty())
{
usersApp.Ico = ico;
}
else
{
usersApp.Ico = null;
}
buserApp.Update(usersApp);
buserApp.ClearCache();
Business.Platform.Log.Add("修改了个人应用", "", Business.Platform.Log.Types.角色应用, oldXML, usersApp.Serialize());
string refreshID = usersApp.ParentID.ToString();
ViewBag.Script = "alert('保存成功!'); parent.frames[0].reLoad('" + refreshID + "')";
}
if (!Request.Form["Delete"].IsNullOrEmpty())
{
int i = buserApp.DeleteAndAllChilds(usersApp.ID);
buserApp.ClearCache();
Business.Platform.Log.Add("删除了个人应用", usersApp.Serialize(), Business.Platform.Log.Types.角色应用);
string refreshID = usersApp.ParentID.ToString();
var parent = buserApp.Get(usersApp.ParentID);
string page = parent == null ? "Body" : "Body1";
ViewBag.Script = "parent.frames[0].reLoad('" + refreshID + "');window.location='" + page + "?id=" + refreshID + "&appid=" + Request.QueryString["appid"] + "&tabid=" + Request.QueryString["tabid"] + "&userid=" + Request.QueryString["userid"] + "';";
}
}
ViewBag.AppID = appid;
ViewBag.AppTypesOptions = bappLibrary.GetTypeOptions(type);
return View(usersApp == null ? new Data.Model.UsersApp() : usersApp);
}
}
}