InputValueSetting.razor.cs 12 KB

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