UploadHandlerPostParam.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using DaJiaoYan.Utils;
  2. using Newtonsoft.Json;
  3. using NTwain.Data;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace DaJiaoYan.Models
  7. {
  8. public class UploadHandlerPostParam
  9. {
  10. public enum UploadType
  11. {
  12. /// <summary>
  13. /// 扫描上传
  14. /// </summary>
  15. Scan = 1,
  16. /// <summary>
  17. /// 文件夹上传
  18. /// </summary>
  19. Directory = 2,
  20. }
  21. public enum MarkType
  22. {
  23. LocalMarking = 2,
  24. OnlineMarking = 1,
  25. }
  26. public enum ErrorType
  27. {
  28. None,
  29. TypeError,
  30. SchoolIdError,
  31. CampusIdError,
  32. TestIdError,
  33. SubjectIdError,
  34. IsSchoolNumberError,
  35. MarkingTypeError,
  36. SignWeightError,
  37. TokenError,
  38. ScannerError,
  39. DirectoryError,
  40. NoImageError,
  41. }
  42. private readonly Dictionary<ErrorType, string> errorInfos = new Dictionary<ErrorType, string>()
  43. {
  44. { ErrorType.None, "" },
  45. { ErrorType.TypeError, "上传类型错误" },
  46. { ErrorType.SchoolIdError, "学校信息错误" },
  47. { ErrorType.CampusIdError, "校区信息错误" },
  48. { ErrorType.SubjectIdError, "科目信息错误" },
  49. { ErrorType.TestIdError, "试卷信息错误" },
  50. { ErrorType.IsSchoolNumberError, "考号匹配模式错误" },
  51. { ErrorType.MarkingTypeError, "阅卷模式模式错误" },
  52. { ErrorType.SignWeightError, "填涂深浅参数错误" },
  53. { ErrorType.TokenError, "用户信息异常,请重新登录" },
  54. { ErrorType.ScannerError, "扫描仪异常" },
  55. { ErrorType.DirectoryError, "选择的文件夹异常" },
  56. { ErrorType.NoImageError, "没有可上传的图片" },
  57. };
  58. private readonly ErrorType errorType;
  59. [JsonProperty(PropertyName = "token")]
  60. public string Token { get; set; }
  61. [JsonProperty(PropertyName = "type")]
  62. public UploadType Type { get; set; }
  63. [JsonProperty(PropertyName = "school_id")]
  64. public int SchoolId { get; set; }
  65. [JsonProperty(PropertyName = "campus_id")]
  66. public int CampusId { get; set; }
  67. [JsonProperty(PropertyName = "class_id")]
  68. public int ClassId { get; set; }
  69. [JsonProperty(PropertyName = "test_id")]
  70. public int TestId { get; set; }
  71. [JsonProperty(PropertyName = "subject_id")]
  72. public int SubjectId { get; set; }
  73. [JsonProperty(PropertyName = "is_school_no")]
  74. public int IsSchoolNo { get; set; }
  75. [JsonProperty(PropertyName = "sign_weight")]
  76. public int SignWeight { get; set; }
  77. [JsonProperty(PropertyName = "scanner")]
  78. public string Scanner { get; set; }
  79. [JsonProperty(PropertyName = "directory")]
  80. public string Directory { get; set; }
  81. [JsonProperty(PropertyName = "ver")]
  82. public int Ver { get; set; }
  83. public List<string> Files { get; set; }
  84. public int Progress { get; set; }
  85. public bool ScanFinish { get; set; }
  86. public MarkType MarkingType { get; set; }
  87. public ErrorType GetErrorType
  88. {
  89. get
  90. {
  91. return errorType;
  92. }
  93. }
  94. public string ErrorMessage
  95. {
  96. get
  97. {
  98. return errorInfos[GetErrorType];
  99. }
  100. }
  101. public UploadHandlerPostParam(string token, string type, string schoolId, string campusId, string classId, string testId, string subjectId, string isSchoolNo, string signWeight, string scanner, string directory, string markingType, int ver)
  102. {
  103. if (string.IsNullOrEmpty(type) || !Reg.Match(type, "[12]"))
  104. {
  105. errorType = ErrorType.TypeError;
  106. }
  107. else if (string.IsNullOrEmpty(schoolId) || !Reg.Match(schoolId, Reg.NUMBER))
  108. {
  109. errorType = ErrorType.SchoolIdError;
  110. }
  111. else if (string.IsNullOrEmpty(campusId) || !Reg.Match(campusId, Reg.NUMBER))
  112. {
  113. errorType = ErrorType.CampusIdError;
  114. }
  115. else if (string.IsNullOrEmpty(testId) || !Reg.Match(testId, Reg.NUMBER))
  116. {
  117. errorType = ErrorType.TestIdError;
  118. }
  119. else if (string.IsNullOrEmpty(subjectId) || !Reg.Match(subjectId, Reg.NUMBER))
  120. {
  121. errorType = ErrorType.SubjectIdError;
  122. }
  123. else if (string.IsNullOrEmpty(isSchoolNo) || !Reg.Match(isSchoolNo, "[01]"))
  124. {
  125. errorType = ErrorType.IsSchoolNumberError;
  126. }
  127. else if (string.IsNullOrEmpty(signWeight) || !Reg.Match(signWeight, Reg.NUMBER))
  128. {
  129. errorType = ErrorType.SignWeightError;
  130. }
  131. else if (string.IsNullOrEmpty(markingType) || !Reg.Match(markingType, "[12]"))
  132. {
  133. errorType = ErrorType.MarkingTypeError;
  134. }
  135. if (errorType == ErrorType.None)
  136. {
  137. Token = token;
  138. Type = type.ConvertToEnum<UploadType>();
  139. SchoolId = Convert.ToInt32(schoolId);
  140. CampusId = Convert.ToInt32(campusId);
  141. if (Reg.Match(classId, Reg.NUMBER))
  142. {
  143. ClassId = Convert.ToInt32(classId);
  144. }
  145. TestId = Convert.ToInt32(testId);
  146. SubjectId = Convert.ToInt32(subjectId);
  147. IsSchoolNo = Convert.ToInt32(isSchoolNo);
  148. SignWeight = Convert.ToInt32(signWeight);
  149. Scanner = scanner;
  150. Directory = directory;
  151. MarkingType = markingType.ConvertToEnum<MarkType>();
  152. //Files = files;
  153. //Progress = progress;
  154. //ScanFinish = scanFinish;
  155. if (string.IsNullOrEmpty(Token))
  156. {
  157. errorType = ErrorType.TokenError;
  158. }
  159. else if (Type == UploadType.Scan && string.IsNullOrEmpty(Scanner))
  160. {
  161. errorType = ErrorType.ScannerError;
  162. }
  163. else if (Type == UploadType.Directory)
  164. {
  165. if (string.IsNullOrEmpty(Directory) || !FileExts.CheckDirectory(Directory, false))
  166. {
  167. errorType = ErrorType.DirectoryError;
  168. }
  169. else
  170. {
  171. Files = FileExts.GetImageFiles(Directory);
  172. if (Files?.Count < 1)
  173. {
  174. errorType = ErrorType.NoImageError;
  175. }
  176. }
  177. }
  178. }
  179. Ver = ver;
  180. }
  181. }
  182. }