using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Windows.Forms.VisualStyles; 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; } } }