InputValueSetting.razor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. using AntDesign;
  2. using Microsoft.AspNetCore.Components;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using wispro.sp.entity;
  8. namespace wispro.sp.web.Components
  9. {
  10. public partial class InputValueSetting
  11. {
  12. List<wispro.sp.entity.EnumnDescription<wispro.sp.entity.workflowDefine.EnumFieldType>> FieldTypes
  13. = entity.EnumHelper.getEnumDescriptionDic<wispro.sp.entity.workflowDefine.EnumFieldType>();
  14. entity.workflowDefine.InputValueSetting EditObj;
  15. [Parameter]
  16. public share.ActionObject EditAction { get; set; }
  17. IDictionary<string, (bool edit, entity.workflowDefine.InputValueSetting data)> editCache = new Dictionary<string, (bool edit, entity.workflowDefine.InputValueSetting data)>();
  18. private List<entity.workflowDefine.InputValueSetting > GetChildItem(share.InputValueSettingObject setting)
  19. {
  20. if(setting.Children == null)
  21. {
  22. setting.Children = new List<entity.workflowDefine.InputValueSetting>();
  23. }
  24. return setting.Children;
  25. //return DataSource.Where<entity.workflowDefine.InputValueSetting>(p => p.ParentSetting == setting).ToList();
  26. }
  27. void AddNew(entity.workflowDefine.InputValueSetting setting)
  28. {
  29. Console.WriteLine("AddNew");
  30. var newObj = new entity.workflowDefine.InputValueSetting()
  31. {
  32. valueType = entity.workflowDefine.EnumFieldType.Text,
  33. DisplayName = "新添栏位",
  34. ParentSetting = setting
  35. };
  36. EditObj = newObj;
  37. Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(EditObj));
  38. if (setting != null)
  39. {
  40. foreach(var ss in EditAction.InputValueSettingObjects)
  41. {
  42. if(ss.InputValueSetting == setting)
  43. {
  44. if(ss.Children == null)
  45. {
  46. ss.Children = new List<entity.workflowDefine.InputValueSetting>();
  47. ss.Children.Add(newObj);
  48. break;
  49. }
  50. }
  51. }
  52. }
  53. else
  54. {
  55. share.InputValueSettingObject newSettingobj = new share.InputValueSettingObject();
  56. newSettingobj.InputValueSetting = EditObj;
  57. EditAction.InputValueSettingObjects.Add(newSettingobj);
  58. if (EditAction.NewInputValueSettingObjects == null)
  59. {
  60. EditAction.NewInputValueSettingObjects = new List<share.InputValueSettingObject>();
  61. }
  62. EditAction.NewInputValueSettingObjects.Add(newSettingobj);
  63. }
  64. }
  65. async void Delete(entity.workflowDefine.InputValueSetting setting)
  66. {
  67. //Console.WriteLine($"begin Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  68. //Console.WriteLine($"Delete Setting:{ System.Text.Json.JsonSerializer.Serialize(setting)}");
  69. foreach (var temObj in EditAction.InputValueSettingObjects)
  70. {
  71. if (temObj.InputValueSetting.DisplayName == setting.DisplayName )
  72. {
  73. EditAction.InputValueSettingObjects.Remove(temObj);
  74. }
  75. bool isFound = false;
  76. if (temObj.Children != null)
  77. {
  78. foreach (var iv in temObj.Children)
  79. {
  80. if (iv.DisplayName == setting.DisplayName)
  81. {
  82. temObj.Children.Remove(iv);
  83. isFound = true;
  84. break;
  85. }
  86. }
  87. }
  88. if (isFound)
  89. {
  90. break;
  91. }
  92. }
  93. if (EditAction.NewInputValueSettingObjects != null)
  94. {
  95. foreach (var temObj in EditAction.NewInputValueSettingObjects)
  96. {
  97. if (temObj.InputValueSetting.DisplayName == setting.DisplayName)
  98. {
  99. EditAction.NewInputValueSettingObjects.Remove(temObj);
  100. }
  101. bool isFound = false;
  102. if (temObj.Children != null)
  103. {
  104. foreach (var iv in temObj.Children)
  105. {
  106. if (iv.DisplayName == setting.DisplayName)
  107. {
  108. temObj.Children.Remove(iv);
  109. isFound = true;
  110. break;
  111. }
  112. }
  113. }
  114. if (isFound)
  115. {
  116. break;
  117. }
  118. }
  119. }
  120. if (EditAction.UpdateInputValueSettingObjects != null)
  121. {
  122. foreach (var temObj in EditAction.UpdateInputValueSettingObjects)
  123. {
  124. if (temObj.InputValueSetting.DisplayName == setting.DisplayName)
  125. {
  126. EditAction.UpdateInputValueSettingObjects.Remove(temObj);
  127. }
  128. bool isFound = false;
  129. if (temObj.Children != null)
  130. {
  131. foreach (var iv in temObj.Children)
  132. {
  133. if (iv.DisplayName == setting.DisplayName)
  134. {
  135. temObj.Children.Remove(iv);
  136. isFound = true;
  137. break;
  138. }
  139. }
  140. }
  141. if (isFound)
  142. {
  143. break;
  144. }
  145. }
  146. }
  147. if (setting.Id > 0)
  148. {
  149. //添加从数据库中删除代码;
  150. await wfService.DeleteInputValueSetting(setting.Id);
  151. }
  152. //Console.WriteLine($"End Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  153. }
  154. async void Delete(share.InputValueSettingObject setting)
  155. {
  156. //Console.WriteLine($"Begin Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  157. //Console.WriteLine($"Delete Setting:{ System.Text.Json.JsonSerializer.Serialize(setting)}");
  158. //此处添加删除代码
  159. if (EditAction.InputValueSettingObjects.Contains(setting))
  160. {
  161. EditAction.InputValueSettingObjects.Remove(setting);
  162. }
  163. else
  164. {
  165. foreach (var temObj in EditAction.InputValueSettingObjects)
  166. {
  167. if (temObj.Children != null && temObj.Children.Contains ( setting.InputValueSetting))
  168. {
  169. temObj.Children.Remove(setting.InputValueSetting);
  170. break;
  171. }
  172. }
  173. }
  174. if (EditAction.NewInputValueSettingObjects != null)
  175. {
  176. if (EditAction.NewInputValueSettingObjects.Contains(setting))
  177. {
  178. EditAction.NewInputValueSettingObjects.Remove(setting);
  179. }
  180. else
  181. {
  182. foreach (var temObj in EditAction.NewInputValueSettingObjects)
  183. {
  184. if (temObj.Children != null && temObj.Children.Contains(setting.InputValueSetting))
  185. {
  186. temObj.Children.Remove(setting.InputValueSetting);
  187. break;
  188. }
  189. }
  190. }
  191. }
  192. if (EditAction.UpdateInputValueSettingObjects != null)
  193. {
  194. if (EditAction.UpdateInputValueSettingObjects.Contains(setting))
  195. {
  196. EditAction.UpdateInputValueSettingObjects.Remove(setting);
  197. }
  198. else
  199. {
  200. foreach (var temObj in EditAction.UpdateInputValueSettingObjects)
  201. {
  202. if (temObj.Children != null && temObj.Children.Contains(setting.InputValueSetting))
  203. {
  204. temObj.Children.Remove(setting.InputValueSetting);
  205. break;
  206. }
  207. }
  208. }
  209. }
  210. if (setting.InputValueSetting.Id > 0)
  211. {
  212. //添加从数据库中删除代码;
  213. await wfService.DeleteInputValueSetting(setting.InputValueSetting.Id);
  214. }
  215. //Console.WriteLine($"End Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  216. StateHasChanged();
  217. }
  218. void Edit(entity.workflowDefine.InputValueSetting setting)
  219. {
  220. EditObj = setting;
  221. }
  222. void Save(entity.workflowDefine.InputValueSetting setting)
  223. {
  224. if (setting.Id > 0)
  225. {
  226. var temObj = EditAction.InputValueSettingObjects.FirstOrDefault(p => p.InputValueSetting.Id == setting.Id);
  227. if (temObj != null)
  228. {
  229. if (EditAction.UpdateInputValueSettingObjects == null)
  230. {
  231. EditAction.UpdateInputValueSettingObjects = new List<share.InputValueSettingObject>();
  232. }
  233. if (!EditAction.UpdateInputValueSettingObjects.Contains(temObj))
  234. {
  235. EditAction.UpdateInputValueSettingObjects.Add(temObj);
  236. }
  237. }
  238. }
  239. EditObj = null;
  240. StateHasChanged();
  241. }
  242. async Task OnCancel(entity.workflowDefine.InputValueSetting setting)
  243. {
  244. if(setting.Id == 0)
  245. {
  246. foreach(var temobj in EditAction.InputValueSettingObjects)
  247. {
  248. if(temobj.InputValueSetting == setting)
  249. {
  250. EditAction.InputValueSettingObjects.Remove(temobj);
  251. break;
  252. }
  253. }
  254. foreach (var temobj in EditAction.NewInputValueSettingObjects )
  255. {
  256. if (temobj.InputValueSetting == setting)
  257. {
  258. EditAction.NewInputValueSettingObjects.Remove(temobj);
  259. break;
  260. }
  261. }
  262. }
  263. else
  264. {
  265. foreach (var temobj in EditAction.UpdateInputValueSettingObjects)
  266. {
  267. if (temobj.InputValueSetting == setting)
  268. {
  269. EditAction.UpdateInputValueSettingObjects.Remove(temobj);
  270. break;
  271. }
  272. }
  273. setting = await wfService.getInputValueSteeingById(setting.Id);
  274. }
  275. EditObj = null;
  276. }
  277. [Inject]
  278. Services.WorkflowService wfService { get; set; }
  279. }
  280. }