| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- using DaJiaoYan.Utils;
- using Newtonsoft.Json;
- using NTwain.Data;
- using System;
- using System.Collections.Generic;
- namespace DaJiaoYan.Models
- {
- public class UploadHandlerPostParam
- {
- public enum UploadType
- {
- /// <summary>
- /// 扫描上传
- /// </summary>
- Scan = 1,
- /// <summary>
- /// 文件夹上传
- /// </summary>
- Directory = 2,
- }
- public enum MarkType
- {
- LocalMarking = 2,
- OnlineMarking = 1,
- }
- public enum ErrorType
- {
- None,
- TypeError,
- SchoolIdError,
- CampusIdError,
- TestIdError,
- SubjectIdError,
- IsSchoolNumberError,
- MarkingTypeError,
- SignWeightError,
- TokenError,
- ScannerError,
- DirectoryError,
- NoImageError,
- }
- private readonly Dictionary<ErrorType, string> errorInfos = new Dictionary<ErrorType, string>()
- {
- { ErrorType.None, "" },
- { ErrorType.TypeError, "上传类型错误" },
- { ErrorType.SchoolIdError, "学校信息错误" },
- { ErrorType.CampusIdError, "校区信息错误" },
- { ErrorType.SubjectIdError, "科目信息错误" },
- { ErrorType.TestIdError, "试卷信息错误" },
- { ErrorType.IsSchoolNumberError, "考号匹配模式错误" },
- { ErrorType.MarkingTypeError, "阅卷模式模式错误" },
- { ErrorType.SignWeightError, "填涂深浅参数错误" },
- { ErrorType.TokenError, "用户信息异常,请重新登录" },
- { ErrorType.ScannerError, "扫描仪异常" },
- { ErrorType.DirectoryError, "选择的文件夹异常" },
- { ErrorType.NoImageError, "没有可上传的图片" },
- };
- private readonly ErrorType errorType;
- [JsonProperty(PropertyName = "token")]
- public string Token { get; set; }
- [JsonProperty(PropertyName = "type")]
- public UploadType Type { get; set; }
- [JsonProperty(PropertyName = "school_id")]
- public int SchoolId { get; set; }
- [JsonProperty(PropertyName = "campus_id")]
- public int CampusId { get; set; }
- [JsonProperty(PropertyName = "class_id")]
- public int ClassId { get; set; }
- [JsonProperty(PropertyName = "test_id")]
- public int TestId { get; set; }
- [JsonProperty(PropertyName = "subject_id")]
- public int SubjectId { get; set; }
- [JsonProperty(PropertyName = "is_school_no")]
- public int IsSchoolNo { get; set; }
- [JsonProperty(PropertyName = "sign_weight")]
- public int SignWeight { get; set; }
- [JsonProperty(PropertyName = "scanner")]
- public string Scanner { get; set; }
- [JsonProperty(PropertyName = "directory")]
- public string Directory { get; set; }
- [JsonProperty(PropertyName = "ver")]
- public int Ver { get; set; }
- public List<string> Files { get; set; }
- public int Progress { get; set; }
- public bool ScanFinish { get; set; }
- public MarkType MarkingType { get; set; }
- public ErrorType GetErrorType
- {
- get
- {
- return errorType;
- }
- }
- public string ErrorMessage
- {
- get
- {
- return errorInfos[GetErrorType];
- }
- }
- 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)
- {
- if (string.IsNullOrEmpty(type) || !Reg.Match(type, "[12]"))
- {
- errorType = ErrorType.TypeError;
- }
- else if (string.IsNullOrEmpty(schoolId) || !Reg.Match(schoolId, Reg.NUMBER))
- {
- errorType = ErrorType.SchoolIdError;
- }
- else if (string.IsNullOrEmpty(campusId) || !Reg.Match(campusId, Reg.NUMBER))
- {
- errorType = ErrorType.CampusIdError;
- }
- else if (string.IsNullOrEmpty(testId) || !Reg.Match(testId, Reg.NUMBER))
- {
- errorType = ErrorType.TestIdError;
- }
- else if (string.IsNullOrEmpty(subjectId) || !Reg.Match(subjectId, Reg.NUMBER))
- {
- errorType = ErrorType.SubjectIdError;
- }
- else if (string.IsNullOrEmpty(isSchoolNo) || !Reg.Match(isSchoolNo, "[01]"))
- {
- errorType = ErrorType.IsSchoolNumberError;
- }
- else if (string.IsNullOrEmpty(signWeight) || !Reg.Match(signWeight, Reg.NUMBER))
- {
- errorType = ErrorType.SignWeightError;
- }
- else if (string.IsNullOrEmpty(markingType) || !Reg.Match(markingType, "[12]"))
- {
- errorType = ErrorType.MarkingTypeError;
- }
- if (errorType == ErrorType.None)
- {
- Token = token;
- Type = type.ConvertToEnum<UploadType>();
- SchoolId = Convert.ToInt32(schoolId);
- CampusId = Convert.ToInt32(campusId);
- if (Reg.Match(classId, Reg.NUMBER))
- {
- ClassId = Convert.ToInt32(classId);
- }
- TestId = Convert.ToInt32(testId);
- SubjectId = Convert.ToInt32(subjectId);
- IsSchoolNo = Convert.ToInt32(isSchoolNo);
- SignWeight = Convert.ToInt32(signWeight);
- Scanner = scanner;
- Directory = directory;
- MarkingType = markingType.ConvertToEnum<MarkType>();
- //Files = files;
- //Progress = progress;
- //ScanFinish = scanFinish;
- if (string.IsNullOrEmpty(Token))
- {
- errorType = ErrorType.TokenError;
- }
- else if (Type == UploadType.Scan && string.IsNullOrEmpty(Scanner))
- {
- errorType = ErrorType.ScannerError;
- }
- else if (Type == UploadType.Directory)
- {
- if (string.IsNullOrEmpty(Directory) || !FileExts.CheckDirectory(Directory, false))
- {
- errorType = ErrorType.DirectoryError;
- }
- else
- {
- Files = FileExts.GetImageFiles(Directory);
- if (Files?.Count < 1)
- {
- errorType = ErrorType.NoImageError;
- }
- }
- }
- }
- Ver = ver;
- }
- }
- }
|