using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; namespace WebApplication1.Models { public class ParamModels { } public class MoInsertModel { /// /// 工单号 /// [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 = true)] public string 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 = false)] public DateTime MTIME { get; set; } } public class MoModifityModel { /// /// 工单号 /// [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 string 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 DateTime MTIME { 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.IsClass) //类 { var instance = pro.GetValue(param); CheckNull(instance); } else if (pro.PropertyType.IsValueType) //值 { var proValue = pro.GetValue(param, null); var attrs = pro.GetCustomAttributes(typeof(RequiredAttribute), false); foreach (var attr in attrs) { if (attr is RequiredAttribute && string.IsNullOrEmpty(pro.GetValue(param).ToString()) && ((RequiredAttribute)attr).AllowEmptyStrings == false) throw new Exception($"NullOrEmptyParam:{pro.Name}"); } } } } } }