using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; namespace ICSSoft.Frame.Data.Entity { public class ParamModels { } public class MoInsertModel { [Required(AllowEmptyStrings = false)] public string Type { get; set; } [Required(AllowEmptyStrings = false)] public List datas { get; set; } } public class MoInsertData { /// /// 工单号 /// [Required(AllowEmptyStrings = false)] public string Mocode { get; set; } /// /// 行号 /// [Required(AllowEmptyStrings = false)] public int MOSEQ { get; set; } /// /// 工单数量 /// [Required(AllowEmptyStrings = false)] public decimal?MOPLANQTY { get; set; } /// /// 计划开始日期 /// [Required(AllowEmptyStrings = false)] public DateTime?MOPLANSTARTDATE { get; set; } /// /// 计划结束日期 /// [Required(AllowEmptyStrings = false)] public DateTime ?MOPLANENDDATE { get; set; } /// /// 工单下发时间 /// [Required(AllowEmptyStrings = false)] public DateTime? MODOWNDATE { get; set; } /// /// 产品编码 /// [Required(AllowEmptyStrings = false)] public string ITEMCODE { get; set; } /// /// ERP工单是否关闭 /// [Required(AllowEmptyStrings = false)] public bool? MOBIOSVER { get; set; } /// /// 制单人 /// [Required(AllowEmptyStrings = false)] public string CreateUser { get; set; } /// /// 制单时间 /// [Required(AllowEmptyStrings = false)] public DateTime ?CreateTime { get; set; } /// /// 部门名称 /// [Required(AllowEmptyStrings = false)] public string MDeptName { get; set; } /// /// 部门编码 /// [Required(AllowEmptyStrings = false)] public string MDeptCode { get; set; } /// /// 修改时间 /// [Required(AllowEmptyStrings = false)] public DateTime ?MTIME { get; set; } [Required(AllowEmptyStrings = true)] public string ProjectCode { get; set; } [Required(AllowEmptyStrings = true)] public string ProjectSeq { get; set; } /// /// 成本中心 /// [Required(AllowEmptyStrings = true)] public string CostCenter { get; set; } /// /// 母工单 /// [Required(AllowEmptyStrings = true)] public string MotherMo{ get; set; } /// /// 上级工单 /// [Required(AllowEmptyStrings = true)] public string SuperiorMo { get; set; } } } public class MoModifityModel { [Required(AllowEmptyStrings = false)] public string Type { get; set; } [Required(AllowEmptyStrings = false)] public List datas { get; set; } } public class MoModifityData { /// /// 工单号 /// [Required(AllowEmptyStrings = false)] public string Mocode { get; set; } /// /// 行号 /// [Required(AllowEmptyStrings = false)] public int MOSEQ { get; set; } /// /// 工单数量 /// [Required(AllowEmptyStrings = true)] public decimal? MOPLANQTY { get; set; } /// /// 计划开始日期 /// [Required(AllowEmptyStrings = true)] public DateTime? MOPLANSTARTDATE { get; set; } /// /// 计划结束日期 /// [Required(AllowEmptyStrings = true)] public DateTime? MOPLANENDDATE { get; set; } /// /// 工单下发时间 /// [Required(AllowEmptyStrings = true)] public DateTime? MODOWNDATE { get; set; } /// /// 产品编码 /// [Required(AllowEmptyStrings = true)] public string ITEMCODE { get; set; } /// /// ERP工单是否关闭 /// [Required(AllowEmptyStrings = true)] public bool? MOBIOSVER { get; set; } /// /// 制单人 /// [Required(AllowEmptyStrings = true)] public string CreateUser { get; set; } /// /// 制单时间 /// [Required(AllowEmptyStrings = true)] public DateTime? CreateTime { get; set; } /// /// 部门名称 /// [Required(AllowEmptyStrings = true)] public string MDeptName { get; set; } /// /// 部门编码 /// [Required(AllowEmptyStrings = true)] public string MDeptCode { get; set; } [Required(AllowEmptyStrings = true)] public DateTime? MTIME { get; set; } [Required(AllowEmptyStrings = true)] public string ProjectCode { get; set; } [Required(AllowEmptyStrings = true)] public string ProjectSeq { get; set; } [Required(AllowEmptyStrings = true)] public string CostCenter { get; set; } /// /// 母工单 /// [Required(AllowEmptyStrings = true)] public string MotherMo { get; set; } /// /// 上级工单 /// [Required(AllowEmptyStrings = true)] public string SuperiorMo { get; set; } } public static class ParamsValidateHelper { public static void CheckNull(T param) { var typeParm = typeof(T); foreach (var pro in typeParm.GetProperties()) { if (!pro.PropertyType.IsValueType&&pro.PropertyType.Name.ToUpper()!="STRING") //类 { var instance = pro.GetValue(param,null); if (typeof(IEnumerable).IsAssignableFrom(instance.GetType())) { foreach (var a in (IEnumerable)instance) { CheckNull(a); } } else CheckNull((D)instance); } else //值 { var proValue = pro.GetValue(param, null); var attrs = pro.GetCustomAttributes(typeof(RequiredAttribute), false); foreach (var attr in attrs) { if (attr is RequiredAttribute && (proValue == null || string.IsNullOrEmpty(proValue.ToString())) && ((RequiredAttribute)attr).AllowEmptyStrings == false) throw new Exception($"NullOrEmptyParam:{pro.Name}"); } } } } }