diff --git a/CNAS_RunSync/ucSynchrousMain.cs b/CNAS_RunSync/ucSynchrousMain.cs index 025b4a0..330d4fe 100644 --- a/CNAS_RunSync/ucSynchrousMain.cs +++ b/CNAS_RunSync/ucSynchrousMain.cs @@ -73,6 +73,13 @@ namespace CNAS_RunSync this.lblTitleMsg.Text= string.Format("类型:{0} 路径:{1}", syncInstrumentItem.SyncInstrumentDSInfo.InstrumentDataSourceType.ToString(),syncInstrumentItem.SyncInstrumentDSInfo.Path); + //获取目标表最近上传时间 + Dictionary times = this.ReadSyncTime(); + if (true == times?.ContainsKey(this.syncInstrumentItem.Code)) + { + this.lblTitleLastUpdateTime.Text = $"最近上传时间:{times[this.syncInstrumentItem.Code]}"; + } + //清空现有绑定 DictComboBox.Clear(); dictSource.Clear(); @@ -129,14 +136,6 @@ namespace CNAS_RunSync cmbColumns.ValueMember = "Key"; cmbColumns.DisplayMember = "Key"; } - - //4.初始化最近上传时间 - //4.1 获取目标表最近上传时间 - Dictionary times = this.ReadSyncTime(); - if (true == times?.ContainsKey(this.syncInstrumentItem.Code)) - { - this.lblTitleLastUpdateTime.Text = $"最近上传时间:{times[this.syncInstrumentItem.Code]}"; - } } /// diff --git a/CNAS_SyncService/CNAS_SyncService.csproj b/CNAS_SyncService/CNAS_SyncService.csproj index abde1f8..1c04473 100644 --- a/CNAS_SyncService/CNAS_SyncService.csproj +++ b/CNAS_SyncService/CNAS_SyncService.csproj @@ -42,6 +42,10 @@ False ..\dll\log4net.dll + + False + ..\dll\Newtonsoft.Json.dll + diff --git a/CNAS_SyncService/SyncServiceOperation.cs b/CNAS_SyncService/SyncServiceOperation.cs index 4a94650..989c253 100644 --- a/CNAS_SyncService/SyncServiceOperation.cs +++ b/CNAS_SyncService/SyncServiceOperation.cs @@ -2,9 +2,11 @@ using CnasSynchronousCommon; using CnasSynchronusClient; using CnasSynchrousModel; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -145,7 +147,12 @@ namespace CNAS_SyncService if (query.Count == 1) { string strCompareTime = ""; - string strDateTime = CnasDataOperationFact.CnasDataOperation().GetMaxTimeByTableName(syncInstrumentItem.SyncTargetDBInfo, syncInstrumentItem.LstSyncPramas[0].TargetTable, query[0].TargetField, syncInstrumentItem.CnasInstrumentColumn, syncInstrumentItem.GUID); + string strDateTime = ""; + Dictionary times = this.ReadSyncTime(); + if (true == times?.ContainsKey(syncInstrumentItem.Code)) + { + strDateTime = $"{times[syncInstrumentItem.Code]}"; + } //strDateTime = "2016-07-01 00:00:00"; if (strDateTime == "1899-1-1") @@ -368,5 +375,43 @@ namespace CNAS_SyncService } return config; } + + /// + /// + /// + private Dictionary ReadSyncTime() + { + Dictionary times = null; + + if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Cache", $"SyncTime.bin"))) + { + try + { + using (StreamReader reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Cache", $"SyncTime.bin"), Encoding.UTF8)) + { + try + { + string json = reader.ReadToEnd(); + times = JsonConvert.DeserializeObject>(json); + } + catch + { + + } + finally + { + reader.Close(); + reader.Dispose(); + } + } + } + catch (Exception exception) + { + Debug.WriteLine(exception.Message); + } + } + + return times; + } } }