Class1.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net.Http;
  6. using System.Net.Http.Json;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using wispro.sp.entity;
  10. namespace wispro.sp.winClient
  11. {
  12. public class CreateAppealModel
  13. {
  14. public PerformanceItem Item { get; set; }
  15. public AppealType AppealType { get; set; }
  16. public List<InputField> inputFields { get; set; }
  17. public List<InputFieldValue> inputFieldValues { get; set; }
  18. public AppealRecord AppealRecord { get; set; }
  19. private async Task<List<InputField>> GetInputFields(int appealTypeId,int State)
  20. {
  21. HttpClient _httpClient = new HttpClient();
  22. var data = await _httpClient.GetFromJsonAsync<List<InputField>>($"http://localhost:39476/api/Appeal/GetInputField?appealTypeId={appealTypeId}&state={State}");
  23. return data;
  24. }
  25. //public System.Collections.Hashtable _GroupInputValues { get; set; }
  26. //public List<InputFieldValue> noMultiValues { get; set; }
  27. public CreateAppealModel() { }
  28. public async Task Init(PerformanceItem item, AppealType appealType)
  29. {
  30. Item = item;
  31. AppealType = appealType;
  32. AppealRecord = new AppealRecord();
  33. AppealRecord.TypeId = appealType.Id;
  34. AppealRecord.ItemId = item.Id;
  35. AppealRecord.State = 0;
  36. if (AppealType != null)
  37. {
  38. inputFieldValues = new List<InputFieldValue>();
  39. inputFields = await GetInputFields(AppealType.Id, 0);
  40. foreach (var field in inputFields)
  41. {
  42. if (!string.IsNullOrEmpty(field.MapObjectField) && !string.IsNullOrEmpty(field.MapObjectFieldLabel))
  43. {
  44. List<InputFieldValue> temValues = new List<InputFieldValue>();
  45. string[] pList = field.MapObjectField.Split(new char[] { '.' });
  46. string[] plList = field.MapObjectFieldLabel.Split(new char[] { '.' });
  47. var pInfo = Item.GetType().GetProperty(pList[0]);
  48. var o = pInfo.GetValue(item);
  49. if (Array.IndexOf(o.GetType().GetInterfaces(), typeof(IEnumerable)) > -1)
  50. {
  51. List<string> Values = new List<string>();
  52. List<string> Labels = new List<string>();
  53. var objList = o as IEnumerable;
  54. foreach (var obj in objList)
  55. {
  56. var objValue = obj;
  57. var objLabel = obj;
  58. for (int i = 1; i < pList.Length; i++)
  59. {
  60. objValue = objValue.GetType().GetProperty(pList[i]).GetValue(objValue);
  61. }
  62. for (int i = 1; i < plList.Length; i++)
  63. {
  64. objLabel = objLabel.GetType().GetProperty(plList[i]).GetValue(objLabel);
  65. }
  66. var fValue = new InputFieldValue();
  67. fValue.InputField = field;
  68. fValue.InputFieldId = field.Id;
  69. fValue.Label = objLabel.ToString();
  70. if (objValue != null)
  71. {
  72. fValue.Value = objValue.ToString();
  73. }
  74. inputFieldValues.Add(fValue);
  75. temValues.Add(fValue);
  76. }
  77. }
  78. else
  79. {
  80. var fValue = new InputFieldValue();
  81. fValue.InputField = field;
  82. fValue.InputFieldId = field.Id;
  83. inputFieldValues.Add(fValue);
  84. }
  85. }
  86. else
  87. {
  88. var fValue = new InputFieldValue();
  89. fValue.InputField = field;
  90. fValue.InputFieldId = field.Id;
  91. inputFieldValues.Add(fValue);
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }