From 574fabd3ec1efae3eedea45121efeda2d6ccc2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E5=87=AF?= Date: Sun, 16 Feb 2025 19:38:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8A=E6=AC=A1=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=97=B6=E9=97=B4=E8=8E=B7=E5=8F=96=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E3=80=82=E4=BC=98=E5=8C=96=E5=90=8C=E6=AD=A5=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=8E=B7=E5=8F=96=E5=90=8C=E6=AD=A5=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CNAS_RunSync/ucSynchrousMain.cs | 15 ++++---- CNAS_SyncService/CNAS_SyncService.csproj | 4 ++ CNAS_SyncService/SyncServiceOperation.cs | 47 +++++++++++++++++++++++- 3 files changed, 57 insertions(+), 9 deletions(-) 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; + } } }