From 4cb676856f0c791ffcbef569c0ca8195bf8b0938 Mon Sep 17 00:00:00 2001 From: wells.liu <wells.liu@broconcentric.com> Date: 星期六, 04 七月 2020 18:05:47 +0800 Subject: [PATCH] 数据库操作 --- src/Bro.Process.DBManager/BaseModel.cs | 354 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 177 insertions(+), 177 deletions(-) diff --git a/src/Bro.Process.DBManager/BaseModel.cs b/src/Bro.Process.DBManager/BaseModel.cs index f827c7c..cc6e86b 100644 --- a/src/Bro.Process.DBManager/BaseModel.cs +++ b/src/Bro.Process.DBManager/BaseModel.cs @@ -1,200 +1,200 @@ -锘縰sing 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; +// } +//} -- Gitblit v1.8.0