using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Windows.Forms.VisualStyles; using Chloe; using DB.Dto; using DB.Entity; using Tool; namespace DB.Service { /// /// 参数修改日志 /// public class UpdateLogService { public bool AddOrUpdateLog(UserDto user,string address,uint value) { UpdateLog log = new UpdateLog { ID = SnowflakeFactory.NewId, PointName = address, CreateDate = DateTime.Now, CreateUserId = user.Id.ToString(), CreateUserName = user.UserName, LastModifyUserId = "", LastModifyUserName = "", LastModifyDate = DateTime.Now }; using (var dbContext = DbFactory.GetContext) { var firstOrDefault = dbContext.Query() .Where(x=>x.PointName==address) .OrderByDesc(x=>x.ID).FirstOrDefault(); if (firstOrDefault != null) { if (firstOrDefault.NewValue != value.ToString()) { log.OldValue = firstOrDefault.NewValue; log.NewValue = value.ToString(); dbContext.Insert(log); } } else { log.OldValue = ""; log.NewValue = value.ToString(); dbContext.Insert(log); } } return true; } public PagedList GetPagedList(int pageIndex, int pageSize, string key) { PagingResult pagePagingResult; using (var dbContext = DbFactory.GetContext) { pagePagingResult = dbContext.Query() .WhereIf(!string.IsNullOrEmpty(key),x=>x.PointName.Contains(key)) .OrderByDesc(x => x.ID) .Paging(pageIndex, pageSize); } PagedList paged = new PagedList(pagePagingResult.DataList, pagePagingResult.Totals.ToInt(), pageIndex, pageSize); return paged; } } }