InputValueSetting.razor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. 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. Console.WriteLine($"End Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  148. }
  149. async void Delete(share.InputValueSettingObject setting)
  150. {
  151. Console.WriteLine($"Begin Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  152. Console.WriteLine($"Delete Setting:{ System.Text.Json.JsonSerializer.Serialize(setting)}");
  153. //此处添加删除代码
  154. if (EditAction.InputValueSettingObjects.Contains(setting))
  155. {
  156. EditAction.InputValueSettingObjects.Remove(setting);
  157. }
  158. else
  159. {
  160. foreach (var temObj in EditAction.InputValueSettingObjects)
  161. {
  162. if (temObj.Children != null && temObj.Children.Contains ( setting.InputValueSetting))
  163. {
  164. temObj.Children.Remove(setting.InputValueSetting);
  165. break;
  166. }
  167. }
  168. }
  169. if (EditAction.NewInputValueSettingObjects != null)
  170. {
  171. if (EditAction.NewInputValueSettingObjects.Contains(setting))
  172. {
  173. EditAction.NewInputValueSettingObjects.Remove(setting);
  174. }
  175. else
  176. {
  177. foreach (var temObj in EditAction.NewInputValueSettingObjects)
  178. {
  179. if (temObj.Children != null && temObj.Children.Contains(setting.InputValueSetting))
  180. {
  181. temObj.Children.Remove(setting.InputValueSetting);
  182. break;
  183. }
  184. }
  185. }
  186. }
  187. if (EditAction.UpdateInputValueSettingObjects != null)
  188. {
  189. if (EditAction.UpdateInputValueSettingObjects.Contains(setting))
  190. {
  191. EditAction.UpdateInputValueSettingObjects.Remove(setting);
  192. }
  193. else
  194. {
  195. foreach (var temObj in EditAction.UpdateInputValueSettingObjects)
  196. {
  197. if (temObj.Children != null && temObj.Children.Contains(setting.InputValueSetting))
  198. {
  199. temObj.Children.Remove(setting.InputValueSetting);
  200. break;
  201. }
  202. }
  203. }
  204. }
  205. if (setting.InputValueSetting.Id > 0)
  206. {
  207. //添加从数据库中删除代码;
  208. await wfService.DeleteInputValueSetting(setting.InputValueSetting.Id);
  209. }
  210. Console.WriteLine($"End Delete:{ System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  211. StateHasChanged();
  212. }
  213. void Edit(entity.workflowDefine.InputValueSetting setting)
  214. {
  215. EditObj = setting;
  216. }
  217. void Save(entity.workflowDefine.InputValueSetting setting)
  218. {
  219. if (setting.Id > 0)
  220. {
  221. var temObj = EditAction.InputValueSettingObjects.FirstOrDefault(p => p.InputValueSetting.Id == setting.Id);
  222. if (temObj != null)
  223. {
  224. if (EditAction.UpdateInputValueSettingObjects == null)
  225. {
  226. EditAction.UpdateInputValueSettingObjects = new List<share.InputValueSettingObject>();
  227. }
  228. if (!EditAction.UpdateInputValueSettingObjects.Contains(temObj))
  229. {
  230. EditAction.UpdateInputValueSettingObjects.Add(temObj);
  231. }
  232. }
  233. }
  234. EditObj = null;
  235. StateHasChanged();
  236. }
  237. async Task OnCancel(entity.workflowDefine.InputValueSetting setting)
  238. {
  239. if(setting.Id == 0)
  240. {
  241. foreach(var temobj in EditAction.InputValueSettingObjects)
  242. {
  243. if(temobj.InputValueSetting == setting)
  244. {
  245. EditAction.InputValueSettingObjects.Remove(temobj);
  246. break;
  247. }
  248. }
  249. foreach (var temobj in EditAction.NewInputValueSettingObjects )
  250. {
  251. if (temobj.InputValueSetting == setting)
  252. {
  253. EditAction.NewInputValueSettingObjects.Remove(temobj);
  254. break;
  255. }
  256. }
  257. }
  258. else
  259. {
  260. foreach (var temobj in EditAction.UpdateInputValueSettingObjects)
  261. {
  262. if (temobj.InputValueSetting == setting)
  263. {
  264. EditAction.UpdateInputValueSettingObjects.Remove(temobj);
  265. break;
  266. }
  267. }
  268. setting = await wfService.getInputValueSteeingById(setting.Id);
  269. }
  270. EditObj = null;
  271. }
  272. [Inject]
  273. Services.WorkflowService wfService { get; set; }
  274. }
  275. }