Repository navigation
Expand file tree
/
Copy pathDictController.cs
More file actions
282 lines (249 loc) · 10.3 KB
/
Copy pathDictController.cs
File metadata and controls
282 lines (249 loc) · 10.3 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebMvc.Controllers
{
public class DictController : MyController
{
//
// GET: /Dict/
public ActionResult Index()
{
return View();
}
public string Tree1()
{
Business.Platform.Dictionary BDict = new Business.Platform.Dictionary();
string rootid = Request.QueryString["root"];
Guid rootID = Guid.Empty;
if (!rootid.IsNullOrEmpty())
{
if (!rootid.IsGuid(out rootID))
{
var dict = BDict.GetByCode(rootid);
if (dict != null)
{
rootID = dict.ID;
}
}
}
var root = rootID != Guid.Empty ? BDict.Get(rootID) : BDict.GetRoot();
System.Text.StringBuilder json = new System.Text.StringBuilder("[", 1000);
json.Append("{");
json.AppendFormat("\"id\":\"{0}\",", root.ID);
json.AppendFormat("\"parentID\":\"{0}\",", root.ParentID);
json.AppendFormat("\"title\":\"{0}\",", root.Title);
json.AppendFormat("\"ico\":\"{0}\",", Url.Content("~/images/ico/role.gif"));
json.AppendFormat("\"hasChilds\":\"{0}\",", BDict.HasChilds(root.ID) ? "1" : "0");
json.Append("\"childs\":[");
var childs = BDict.GetChilds(root.ID);
int i = 0;
int count = childs.Count;
foreach (var child in childs)
{
json.Append("{");
json.AppendFormat("\"id\":\"{0}\",", child.ID);
json.AppendFormat("\"parentID\":\"{0}\",", child.ParentID);
json.AppendFormat("\"title\":\"{0}\",", child.Title);
json.AppendFormat("\"ico\":\"{0}\",", "");
json.AppendFormat("\"hasChilds\":\"{0}\",", BDict.HasChilds(child.ID) ? "1" : "0");
json.Append("\"childs\":[");
json.Append("]");
json.Append("}");
if (i++ < count - 1)
{
json.Append(",");
}
}
json.Append("]");
json.Append("}");
json.Append("]");
return json.ToString();
}
public string TreeRefresh()
{
string id = Request.QueryString["refreshid"];
Guid gid;
if (!id.IsGuid(out gid))
{
Response.Write("[]");
}
System.Text.StringBuilder json = new System.Text.StringBuilder("[", 1000);
Business.Platform.Dictionary BDict = new Business.Platform.Dictionary();
var childs = BDict.GetChilds(gid).OrderBy(p => p.Sort);
int i = 0;
int count = childs.Count();
foreach (var child in childs)
{
json.Append("{");
json.AppendFormat("\"id\":\"{0}\",", child.ID);
json.AppendFormat("\"parentID\":\"{0}\",", child.ParentID);
json.AppendFormat("\"title\":\"{0}\",", child.Title);
json.AppendFormat("\"ico\":\"{0}\",", "");
json.AppendFormat("\"hasChilds\":\"{0}\",", BDict.HasChilds(child.ID) ? "1" : "0");
json.Append("\"childs\":[");
json.Append("]");
json.Append("}");
if (i++ < count - 1)
{
json.Append(",");
}
}
json.Append("]");
return json.ToString();
}
public ActionResult Tree()
{
return View();
}
public ActionResult Body()
{
return Body(null);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Body(FormCollection collection)
{
Business.Platform.Dictionary bdict = new Business.Platform.Dictionary();
Data.Model.Dictionary dict = null;
string id = Request.QueryString["id"];
if (id.IsGuid())
{
dict = bdict.Get(id.ToGuid());
}
if (dict == null)
{
dict = bdict.GetRoot();
}
if (collection != null)
{
string refreshID = dict.ParentID == Guid.Empty ? dict.ID.ToString() : dict.ParentID.ToString();
//删除
if (!Request.Form["Delete"].IsNullOrEmpty())
{
int i = bdict.DeleteAndAllChilds(dict.ID);
bdict.RefreshCache();
Business.Platform.Log.Add("删除了数据字典及其下级共" + i.ToString() + "项", dict.Serialize(), Business.Platform.Log.Types.数据字典);
ViewBag.Script = "alert('删除成功!');parent.frames[0].reLoad('" + refreshID + "');window.location='Body?id=" + dict.ParentID.ToString() + "&appid=" + Request.QueryString["appid"] + "';";
return View(dict);
}
string title = Request.Form["Title"];
string code = Request.Form["Code"];
string values = Request.Form["Values"];
string note = Request.Form["Note"];
string other = Request.Form["Other"];
string oldXML = dict.Serialize();
dict.Code = code.IsNullOrEmpty() ? null : code.Trim();
dict.Note = note.IsNullOrEmpty() ? null : note.Trim();
dict.Other = other.IsNullOrEmpty() ? null : other.Trim();
dict.Title = title.Trim();
dict.Value = values.IsNullOrEmpty() ? null : values.Trim();
bdict.Update(dict);
bdict.RefreshCache();
Business.Platform.Log.Add("修改了数据字典项", "", Business.Platform.Log.Types.数据字典, oldXML, dict.Serialize());
ViewBag.Script = "alert('保存成功!');parent.frames[0].reLoad('" + refreshID + "');";
}
return View(dict);
}
public string CheckCode()
{
string code = Request.Form["value"];
string id = Request["id"];
return new Business.Platform.Dictionary().HasCode(code, id) ? "唯一代码重复" : "1";
}
public ActionResult Add()
{
return add1(null);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Add(FormCollection collection)
{
return add1(collection);
}
public ActionResult add1(FormCollection collection)
{
Data.Model.Dictionary dict = new Data.Model.Dictionary();
Business.Platform.Dictionary bdict = new Business.Platform.Dictionary();
string id = Request.QueryString["id"];
if (!id.IsGuid())
{
var dictRoot = bdict.GetRoot();
id = dictRoot != null ? dictRoot.ID.ToString() : "";
}
if (!id.IsGuid())
{
throw new Exception("未找到父级");
}
if (collection != null)
{
string title = Request.Form["Title"];
string code = Request.Form["Code"];
string values = Request.Form["Values"];
string note = Request.Form["Note"];
string other = Request.Form["Other"];
dict.ID = Guid.NewGuid();
dict.Code = code.IsNullOrEmpty() ? null : code.Trim();
dict.Note = note.IsNullOrEmpty() ? null : note.Trim();
dict.Other = other.IsNullOrEmpty() ? null : other.Trim();
dict.ParentID = id.ToGuid();
dict.Sort = bdict.GetMaxSort(id.ToGuid());
dict.Title = title.Trim();
dict.Value = values.IsNullOrEmpty() ? null : values.Trim();
bdict.Add(dict);
bdict.RefreshCache();
Business.Platform.Log.Add("添加了数据字典项", dict.Serialize(), Business.Platform.Log.Types.数据字典);
ViewBag.Script = "alert('添加成功!');parent.frames[0].reLoad('" + id + "');";
}
return View(dict);
}
public ActionResult Sort()
{
return Sort(null);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Sort(FormCollection collection)
{
Business.Platform.Dictionary BDict = new Business.Platform.Dictionary();
string id = Request.QueryString["id"];
string refreshID = "";
Guid dictid;
List<Data.Model.Dictionary> dicts = new List<Data.Model.Dictionary>();
if (id.IsGuid(out dictid))
{
var dict = BDict.Get(dictid);
if (dict != null)
{
dicts = BDict.GetChilds(dict.ParentID);
refreshID = dict.ParentID.ToString();
}
}
if (collection != null)
{
string sortdict = Request.Form["sort"];
if (sortdict.IsNullOrEmpty())
{
return View(dicts);
}
string[] sortArray = sortdict.Split(',');
int i = 1;
foreach (string id1 in sortArray)
{
Guid gid;
if (id1.IsGuid(out gid))
{
BDict.UpdateSort(gid, i++);
}
}
BDict.RefreshCache();
Business.Platform.Log.Add("保存了数据字典排序", "保存了ID为:" + id + "的同级排序", Business.Platform.Log.Types.数据字典);
ViewBag.Script = "parent.frames[0].reLoad('" + refreshID + "');";
dicts = BDict.GetChilds(refreshID.ToGuid());
}
return View(dicts);
}
}
}