| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.ComponentModel.DataAnnotations; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | //using System; |
| | | //using System.Collections.Generic; |
| | | //using System.ComponentModel; |
| | | //using System.ComponentModel.DataAnnotations; |
| | | //using System.Linq; |
| | | //using System.Reflection; |
| | | //using System.Text; |
| | | //using System.Threading.Tasks; |
| | | |
| | | namespace Bro.Process.DataBase |
| | | { |
| | | public class BaseModel |
| | | { |
| | | /// <summary> |
| | | /// 编号,唯一值,使用GUID |
| | | /// </summary> |
| | | [Key] |
| | | [Required(ErrorMessage = "编号不可为空!")] |
| | | [StringLength(64)] |
| | | public string ID { get; set; } = Guid.NewGuid().ToString().ToUpper(); |
| | | //namespace Bro.Process.DataBase |
| | | //{ |
| | | // public class BaseModel |
| | | // { |
| | | // /// <summary> |
| | | // /// 编号,唯一值,使用GUID |
| | | // /// </summary> |
| | | // [Key] |
| | | // [Required(ErrorMessage = "编号不可为空!")] |
| | | // [StringLength(64)] |
| | | // public string ID { get; set; } = Guid.NewGuid().ToString().ToUpper(); |
| | | |
| | | /// <summary> |
| | | /// 禁用状态 0 未禁用 1 已禁用 |
| | | /// </summary> |
| | | [Required] |
| | | public int IS_DISABLED { get; set; } = 0; |
| | | // /// <summary> |
| | | // /// 禁用状态 0 未禁用 1 已禁用 |
| | | // /// </summary> |
| | | // [Required] |
| | | // public int IS_DISABLED { get; set; } = 0; |
| | | |
| | | /// <summary> |
| | | /// 删除状态 0 未删除 1 已删除 |
| | | /// </summary> |
| | | [Required] |
| | | public int IS_DELETED { get; set; } = 0; |
| | | // /// <summary> |
| | | // /// 删除状态 0 未删除 1 已删除 |
| | | // /// </summary> |
| | | // [Required] |
| | | // public int IS_DELETED { get; set; } = 0; |
| | | |
| | | /// <summary> |
| | | /// 创建人信息 |
| | | /// </summary> |
| | | //[Required] |
| | | [StringLength(64)] |
| | | public string CREATE_USER { get; set; } |
| | | // /// <summary> |
| | | // /// 创建人信息 |
| | | // /// </summary> |
| | | // //[Required] |
| | | // [StringLength(64)] |
| | | // public string CREATE_USER { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 创建时间 |
| | | /// </summary> |
| | | //[Required] |
| | | public DateTime? CREATE_TIME { get; set; } = DateTime.Now; |
| | | // /// <summary> |
| | | // /// 创建时间 |
| | | // /// </summary> |
| | | // //[Required] |
| | | // public DateTime? CREATE_TIME { get; set; } = DateTime.Now; |
| | | |
| | | /// <summary> |
| | | /// 更新人信息 |
| | | /// </summary> |
| | | [StringLength(64)] |
| | | public string UPDATE_USER { get; set; } |
| | | // /// <summary> |
| | | // /// 更新人信息 |
| | | // /// </summary> |
| | | // [StringLength(64)] |
| | | // public string UPDATE_USER { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 更新时间 |
| | | /// </summary> |
| | | public DateTime? UPDATE_TIME { get; set; } |
| | | } |
| | | // /// <summary> |
| | | // /// 更新时间 |
| | | // /// </summary> |
| | | // public DateTime? UPDATE_TIME { get; set; } |
| | | // } |
| | | |
| | | public static class BaseModelHelper |
| | | { |
| | | public static void SetNew<T>(this T t, string userId) where T : BaseModel |
| | | { |
| | | t.CREATE_USER = userId; |
| | | t.CREATE_TIME = DateTime.Now; |
| | | } |
| | | // public static class BaseModelHelper |
| | | // { |
| | | // public static void SetNew<T>(this T t, string userId) where T : BaseModel |
| | | // { |
| | | // t.CREATE_USER = userId; |
| | | // t.CREATE_TIME = DateTime.Now; |
| | | // } |
| | | |
| | | public static void SetUpdate<T>(this T t, string userId) where T : BaseModel |
| | | { |
| | | t.UPDATE_USER = userId; |
| | | t.UPDATE_TIME = DateTime.Now; |
| | | } |
| | | // public static void SetUpdate<T>(this T t, string userId) where T : BaseModel |
| | | // { |
| | | // t.UPDATE_USER = userId; |
| | | // t.UPDATE_TIME = DateTime.Now; |
| | | // } |
| | | |
| | | static List<string> NoTransferProps = new List<string>() { "ID", "CREATE_USER", "CREATE_TIME", "UPDATE_USER", "UPDATE_TIME", "IS_DELETED" }; |
| | | public static void DataTransfer<T>(this T destT, T sourceT) where T : BaseModel |
| | | { |
| | | destT.DataFrom(sourceT, NoTransferProps); |
| | | } |
| | | // static List<string> NoTransferProps = new List<string>() { "ID", "CREATE_USER", "CREATE_TIME", "UPDATE_USER", "UPDATE_TIME", "IS_DELETED" }; |
| | | // public static void DataTransfer<T>(this T destT, T sourceT) where T : BaseModel |
| | | // { |
| | | // destT.DataFrom(sourceT, NoTransferProps); |
| | | // } |
| | | |
| | | public static void DataFrom<T1, T2>(this T1 destT, T2 sourceT, List<string> exceptionProps = null) where T1 : class where T2 : class |
| | | { |
| | | PropertyInfo[] propDest = destT.GetType().GetProperties().Where(p => !(p.GetMethod.IsVirtual && !p.GetMethod.IsFinal)).ToArray(); |
| | | PropertyInfo[] propSource = sourceT.GetType().GetProperties(); |
| | | // public static void DataFrom<T1, T2>(this T1 destT, T2 sourceT, List<string> exceptionProps = null) where T1 : class where T2 : class |
| | | // { |
| | | // PropertyInfo[] propDest = destT.GetType().GetProperties().Where(p => !(p.GetMethod.IsVirtual && !p.GetMethod.IsFinal)).ToArray(); |
| | | // PropertyInfo[] propSource = sourceT.GetType().GetProperties(); |
| | | |
| | | Array.ForEach(propDest, prop => |
| | | { |
| | | if (exceptionProps == null || !exceptionProps.Contains(prop.Name)) |
| | | { |
| | | if (prop.CanWrite) |
| | | { |
| | | PropertyInfo propS = propSource.FirstOrDefault(p => p.Name == prop.Name); |
| | | if (propS != null && propS.CanRead) |
| | | { |
| | | prop.SetValue(destT, propS.GetValue(sourceT)); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | // Array.ForEach(propDest, prop => |
| | | // { |
| | | // if (exceptionProps == null || !exceptionProps.Contains(prop.Name)) |
| | | // { |
| | | // if (prop.CanWrite) |
| | | // { |
| | | // PropertyInfo propS = propSource.FirstOrDefault(p => p.Name == prop.Name); |
| | | // if (propS != null && propS.CanRead) |
| | | // { |
| | | // prop.SetValue(destT, propS.GetValue(sourceT)); |
| | | // } |
| | | // } |
| | | // } |
| | | // }); |
| | | // } |
| | | |
| | | public static List<T> ToPagedList<T>(this IQueryable<T> orderQuery, BaseRequest request) where T : class |
| | | { |
| | | return orderQuery.Skip((request.PageNum - 1) * request.PageSize).Take(request.PageSize).ToList(); |
| | | } |
| | | } |
| | | // public static List<T> ToPagedList<T>(this IQueryable<T> orderQuery, BaseRequest request) where T : class |
| | | // { |
| | | // return orderQuery.Skip((request.PageNum - 1) * request.PageSize).Take(request.PageSize).ToList(); |
| | | // } |
| | | // } |
| | | |
| | | public class BaseRequest : INotifyPropertyChanged |
| | | { |
| | | // public class BaseRequest : INotifyPropertyChanged |
| | | // { |
| | | |
| | | private int pageNum = 1; |
| | | /// <summary> |
| | | /// 查询结果页数 |
| | | /// </summary> |
| | | public int PageNum |
| | | { |
| | | get => pageNum; |
| | | set |
| | | { |
| | | if (pageNum != value) |
| | | { |
| | | pageNum = value; |
| | | PropertyChanged?.BeginInvoke(this, new PropertyChangedEventArgs("PageNum"), null, null); |
| | | } |
| | | } |
| | | } |
| | | // private int pageNum = 1; |
| | | // /// <summary> |
| | | // /// 查询结果页数 |
| | | // /// </summary> |
| | | // public int PageNum |
| | | // { |
| | | // get => pageNum; |
| | | // set |
| | | // { |
| | | // if (pageNum != value) |
| | | // { |
| | | // pageNum = value; |
| | | // PropertyChanged?.BeginInvoke(this, new PropertyChangedEventArgs("PageNum"), null, null); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | private int pageSize = 100; |
| | | /// <summary> |
| | | /// 每页的查询结果条数 |
| | | /// </summary> |
| | | public int PageSize |
| | | { |
| | | get => pageSize; |
| | | set |
| | | { |
| | | if (pageSize != value) |
| | | { |
| | | pageSize = value; |
| | | PropertyChanged?.BeginInvoke(this, new PropertyChangedEventArgs("PageSize"), null, null); |
| | | } |
| | | } |
| | | } |
| | | // private int pageSize = 100; |
| | | // /// <summary> |
| | | // /// 每页的查询结果条数 |
| | | // /// </summary> |
| | | // public int PageSize |
| | | // { |
| | | // get => pageSize; |
| | | // set |
| | | // { |
| | | // if (pageSize != value) |
| | | // { |
| | | // pageSize = value; |
| | | // PropertyChanged?.BeginInvoke(this, new PropertyChangedEventArgs("PageSize"), null, null); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// 查询起始时间 |
| | | /// </summary> |
| | | public DateTime? StartTime { get; set; } |
| | | // /// <summary> |
| | | // /// 查询起始时间 |
| | | // /// </summary> |
| | | // public DateTime? StartTime { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 查询结束时间 |
| | | /// </summary> |
| | | public DateTime? EndTime { get; set; } |
| | | // /// <summary> |
| | | // /// 查询结束时间 |
| | | // /// </summary> |
| | | // public DateTime? EndTime { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 启用状态过滤器 1:仅未启用 0:仅启用 -1:全部 |
| | | /// </summary> |
| | | public int DisableFilter { get; set; } = 0; |
| | | // /// <summary> |
| | | // /// 启用状态过滤器 1:仅未启用 0:仅启用 -1:全部 |
| | | // /// </summary> |
| | | // public int DisableFilter { get; set; } = 0; |
| | | |
| | | /// <summary> |
| | | /// 查询字符串 |
| | | /// </summary> |
| | | public string SearchTxt { get; set; } |
| | | // /// <summary> |
| | | // /// 查询字符串 |
| | | // /// </summary> |
| | | // public string SearchTxt { get; set; } |
| | | |
| | | private int totalNum = 0; |
| | | /// <summary> |
| | | /// 数据总数 |
| | | /// </summary> |
| | | public int TotalNum |
| | | { |
| | | get => totalNum; |
| | | set |
| | | { |
| | | if (totalNum != value) |
| | | { |
| | | totalNum = value; |
| | | PropertyChanged?.BeginInvoke(this, new PropertyChangedEventArgs("TotalNum"), null, null); |
| | | } |
| | | TotalPage = (int)Math.Ceiling((double)TotalNum / PageSize); |
| | | } |
| | | } |
| | | // private int totalNum = 0; |
| | | // /// <summary> |
| | | // /// 数据总数 |
| | | // /// </summary> |
| | | // public int TotalNum |
| | | // { |
| | | // get => totalNum; |
| | | // set |
| | | // { |
| | | // if (totalNum != value) |
| | | // { |
| | | // totalNum = value; |
| | | // PropertyChanged?.BeginInvoke(this, new PropertyChangedEventArgs("TotalNum"), null, null); |
| | | // } |
| | | // TotalPage = (int)Math.Ceiling((double)TotalNum / PageSize); |
| | | // } |
| | | // } |
| | | |
| | | private int totalPage = 0; |
| | | /// <summary> |
| | | /// 总页数 |
| | | /// </summary> |
| | | public int TotalPage |
| | | { |
| | | get => totalPage; |
| | | set |
| | | { |
| | | if (totalPage != value) |
| | | { |
| | | totalPage = value; |
| | | PropertyChanged?.BeginInvoke(this, new PropertyChangedEventArgs("TotalPage"), null, null); |
| | | } |
| | | } |
| | | } |
| | | // private int totalPage = 0; |
| | | // /// <summary> |
| | | // /// 总页数 |
| | | // /// </summary> |
| | | // public int TotalPage |
| | | // { |
| | | // get => totalPage; |
| | | // set |
| | | // { |
| | | // if (totalPage != value) |
| | | // { |
| | | // totalPage = value; |
| | | // PropertyChanged?.BeginInvoke(this, new PropertyChangedEventArgs("TotalPage"), null, null); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | public event PropertyChangedEventHandler PropertyChanged; |
| | | } |
| | | } |
| | | // public event PropertyChangedEventHandler PropertyChanged; |
| | | // } |
| | | //} |