From 31a636e735a0addc56e4f4527f500b7aa0874eb5 Mon Sep 17 00:00:00 2001 From: chr <chr@mailcom> Date: 星期五, 03 一月 2025 11:21:46 +0800 Subject: [PATCH] 改了一大堆; --- PdmSwPlugin.PDM/PdmControl.xaml.cs | 325 +++++++++++++++++++++++++++++++++-------------------- 1 files changed, 202 insertions(+), 123 deletions(-) diff --git a/PdmSwPlugin.PDM/PdmControl.xaml.cs b/PdmSwPlugin.PDM/PdmControl.xaml.cs index 6e6148a..e7667fb 100644 --- a/PdmSwPlugin.PDM/PdmControl.xaml.cs +++ b/PdmSwPlugin.PDM/PdmControl.xaml.cs @@ -1,45 +1,40 @@ -锘縰sing PdmSwPlugin.Common.Interface; -using SolidWorks.Interop.sldworks; -using System.Collections.Generic; -using System.Linq; -using System.Windows.Controls; -using PdmSwPlugin.Common; -using System.Collections.ObjectModel; -using System.Net.Http; -using System.Threading.Tasks; -using System.Windows; -using System; -using NPOI.SS.UserModel; -using NPOI.XSSF.UserModel; -using System.IO; +锘縰sing log4net; using Microsoft.Win32; +using NPOI.SS.UserModel; using NPOI.Util; +using NPOI.XSSF.UserModel; +using PdmSwPlugin.Commmon.Control; +using PdmSwPlugin.Commmon.Util.UI; +using PdmSwPlugin.Common; using PdmSwPlugin.Common.Constants; -using System.Threading; -using log4net; +using PdmSwPlugin.Common.Control.TreeGrid; +using PdmSwPlugin.Common.Entity.DrawAudit; +using PdmSwPlugin.Common.Entity.Pdm; +using PdmSwPlugin.Common.Entity.System; +using PdmSwPlugin.Common.Interface; +using PdmSwPlugin.Common.Setting; using PdmSwPlugin.Common.Util; using PdmSwPlugin.Common.Util.Http; -using PdmSwPlugin.Commmon.Util.UI; -using PdmSwPlugin.Common.Entity.Pdm; -using PdmSwPlugin.Common.Control.TreeGrid; -using System.Windows.Data; -using SolidWorks.Interop.swconst; -using PdmSwPlugin.Common.Entity.DrawAudit; -using System.Collections.Concurrent; using PdmSwPlugin.Common.Util.UI; -using PdmSwPlugin.Common.Setting; -using PdmSwPlugin.PDM.Model; -using System.Diagnostics; using PdmSwPlugin.PDM.Constant; -using static PdmSwPlugin.PDM.Event.PdmEvent; +using PdmSwPlugin.PDM.Model; +using SolidWorks.Interop.sldworks; +using SolidWorks.Interop.swconst; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; using System.Windows.Interop; -using PdmSwPlugin.Commmon.Control; -using PdmSwPlugin.Common.Entity.System; -using System.Windows.Documents; -using System.Windows.Input; -using NPOI.POIFS.Properties; -using NPOI.POIFS.Crypt; -using System.Threading.Tasks.Schedulers; +using static PdmSwPlugin.PDM.Event.PdmEvent; namespace PdmSwPlugin.PDM { @@ -169,6 +164,15 @@ } } + public void AutoSaveAlert(List<string> msgs) + { + //Dispatcher.Invoke(() => + //{ + // MultiExWindow exWin = new MultiExWindow(this, "浠ヤ笅鏂囨。鍥犲垹闄ょ壒瀹氶厤缃�岃淇濆瓨", msgs, "鏂囦欢璺緞"); + // ShowExWindow(exWin); + //}); + } + /// <summary> /// 鍒锋柊鎸夐挳 /// </summary> @@ -187,6 +191,11 @@ await Task.Run(() => { RefreshBomList(SwApp.IActiveDoc2); + if (model.bomTreeReader.needSaveList.Count > 0) + { + List<string> msgs = new List<string>(model.bomTreeReader.needSaveList); + AutoSaveAlert(msgs); + } }); Logger.Debug("PDM鎻掍欢锛屽垪琛ㄥ埛鏂板畬鎴愶紒"); } @@ -1004,8 +1013,13 @@ allProperties["鍘嗗彶鍥剧焊"] = drawInfo.HistoryData.ToString(); string drawFilePath = filepath.Replace(Path.GetExtension(filepath), ".slddrw"); bool drawExists = File.Exists(drawFilePath); - // 宸ョ▼鍥句竴鑷存�ф鏌� + // 宸ョ▼鍥句竴鑷存�ф鏌� allProperties["宸ョ▼鍥炬槸鍚﹀瓨鍦�"] = drawExists.ToString(); + // 涓嶈烦杩囨鏌ョ殑鍔犲伐浠讹紝濡傛灉宸ョ▼鍥句笉瀛樺湪锛岃缃畁oDrw涓簍rue + if (!drawExists && !bom.skipCheck && bom.produceWay == "鍔犲伐浠�") + { + drawInfo.noDrw = true; + } allProperties["md5"] = bom.localD3Md5; if (bom.lost || bom.BomInfo.isHidden || sldDoc == null) { @@ -1107,11 +1121,10 @@ if (!bom.skipCheck) { result[filepath] = GetSingleDrawInfo(bom); + if (bom.BomInfo.inKeeDeeDb == true) result[filepath]._inKeeDeeDb = true; + } } - - - ObservableCollection<PdmBom> children = bom.modules; if (children != null) @@ -1186,7 +1199,7 @@ bool allSuccess = true; Dictionary<string, DrawInfo> properties = GetAllPropertiesByTask(temp); MaskAdorner.ShowMessage(content, "姝e湪璇锋眰鏁版嵁..."); - // var factory = LimitedConcurrencyLevelTaskScheduler.Factory; + // var factory = LimitedConcurrencyLevelTaskScheduler.Factory; CountdownEvent counter = new CountdownEvent(properties.Count); int iii = 0; foreach (KeyValuePair<string, DrawInfo> property in properties) @@ -1199,24 +1212,29 @@ try { Logger.Error($"{key} checking rule..."); + DrawInfo checkResult; Result<DrawInfo> result = Client.PostSyncAction<DrawInfo>(property.Value, "wpf/bom/openApi/checkRuleSingle"); - DrawInfo checkResult = result.HandleResult(); + checkResult = result.HandleResult(); properties[key].checkRuleResult = checkResult.checkRuleResult; properties[key].errMessages = checkResult.errMessages; var msgs = checkResult.errMessages; - if (!properties[key].HistoryData && (!checkResult.checkRuleOk||property.Value.isHidden)) + if (property.Value.noDrw || property.Value.isHidden || (!properties[key].HistoryData && (!checkResult.checkRuleOk))) { allSuccess = false; } - if (!properties[key].HistoryData) + lock (temp) { - lock (temp) + if (property.Value.isHidden) { - if (property.Value.isHidden) - { - temp.Add($"鐗╂枡銆恵key}銆戣璁剧疆涓洪殣钘�!"); - } + temp.Add($"鐗╂枡銆恵key}銆戣璁剧疆涓洪殣钘�!"); + } + if (property.Value.noDrw && property.Value.HistoryData) + { + temp.Add($"鐗╂枡銆恵key}銆戞湭鎵惧埌宸ョ▼鍥�!"); + } + if (!properties[key].HistoryData) + { if (msgs != null && msgs.Count > 0) { foreach (string msg in msgs) @@ -1419,6 +1437,12 @@ try { RefreshBomList(SwApp.IActiveDoc2); + if (model.bomTreeReader.needSaveList.Count > 0) + { + List<string> infos = new List<string>(model.bomTreeReader.needSaveList); + AutoSaveAlert(infos); + } + if (!DoCheckRuleAsync(out List<string> msgs)) { Dispatcher.Invoke(() => @@ -1468,7 +1492,7 @@ try { // 瀵规墍鏈夌殑BOM鍋氳鍒欐鏌� - bool allSuccess = DoCheckRule(out _); + bool allSuccess = DoCheckRuleAsync(out _); // 鍏堣幏鍙栨墍鏈夌殑BOM HashSet<string> cache = new HashSet<string>(); // 鐒跺悗绛涢�夐�変腑鐨凚OM @@ -1497,12 +1521,20 @@ if (!allSuccess) { // 濡傛灉鏈夋湭閫氳繃鐨勫浘绾革紝闇�瑕佹彁绀� - var err = boms.Where(b => !b.IsHistoryData && !b.checkRuleOk).ToList(); + var err = boms.Where(b => b.noDrw || b.isHidden || (!b.IsHistoryData && (!b.checkRuleOk))).ToList(); if (err != null && err.Count > 0) { List<string> msgs = new List<string>(); foreach (var ee in err) { + if (ee.noDrw && ee.IsHistoryData) + { + msgs.Add($"鐗╂枡銆恵ee.partNo}銆戞湭閫氳繃瑙勫垯妫�鏌ワ紒鏈壘鍒板伐绋嬪浘"); + } + if (ee.drawInfo.isHidden) + { + msgs.Add($"鐗╂枡銆恵ee.partNo}銆戞湭閫氳繃瑙勫垯妫�鏌ワ紒琚涓洪殣钘�"); + } if (ee.drawInfo.errMessages == null) { msgs.Add($"鐗╂枡銆恵ee.partNo}銆戞湭閫氳繃瑙勫垯妫�鏌ワ紒"); @@ -1524,6 +1556,10 @@ } // 閮介�氳繃浜嗭紝鍐嶈繘琛屽鎵� + + // 绛涢�夐潪鐗规畩鐨勫鏍� + boms = boms.Where(b => !b._drawInfo.isSpecial).ToList(); + if (boms == null || boms.Count <= 0) return; // 鍏堢敵璇峰崟鍙� DrawAuditOrder daOrder = new DrawAuditOrder @@ -1760,50 +1796,69 @@ /// <param name="e"></param> private void TextBox_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { - // 妫�鏌ユ槸鍚︽槸鍙屽嚮 - if (e.ClickCount == 2) + try { - TextBlock textBlock = sender as TextBlock; - PdmBom bom = textBlock.DataContext as PdmBom; - if (bom.checkRuleResult == 0) + // 妫�鏌ユ槸鍚︽槸鍙屽嚮 + if (e.ClickCount == 2) { - this.Warning("璇ュ浘绾歌繕鏈鏌�"); - return; - } - if (bom.checkRuleResult == 3) - { - string title = string.Empty; - if (bom.IsHistoryData) + TextBlock textBlock = sender as TextBlock; + PdmBom bom = textBlock.DataContext as PdmBom; + if (bom.checkRuleResult == 0) { - title = "鍘嗗彶鍥剧焊鏃犻渶妫�鏌�"; + this.Warning("璇ュ浘绾歌繕鏈鏌�"); + return; } - else if (bom.ExcludeFromBOM) - { - title = "涓嶅湪鐗╂枡鏄庣粏琛ㄤ腑鐨勭墿鏂欐棤闇�妫�鏌�"; - } - else if (bom.component?.IsVirtual == true) - { - title = "铏氭嫙浠舵棤闇�妫�鏌�"; - } - this.Info(title); - return; - } - if (bom.checkRuleOk && !bom.isHidden) - { - this.Show("瑙勫垯妫�鏌ラ�氳繃"); - } - else - { List<string> errs = new List<string>(); + if (bom.noDrw && bom.IsHistoryData) + { + errs.Add("宸ョ▼鍥句笉瀛樺湪 "); + } if (bom.isHidden) { errs.Add("鏂囨。琚缃负闅愯棌"); } - errs.AddRange(bom.drawInfo.errMessages); - MultiExWindow exWin = new MultiExWindow(this, "妫�鏌ョ粨鏋�", errs); - exWin.ShowDialog(); + if (bom.drawInfo.errMessages != null) + { + errs.AddRange(bom.drawInfo.errMessages); + } + if (errs.Count > 0) + { + MultiExWindow exWin = new MultiExWindow(this, "妫�鏌ョ粨鏋�", errs); + exWin.ShowDialog(); + } + else if (bom.checkRuleResult == 3) + { + string title = string.Empty; + if (bom.IsHistoryData) + { + title = "鍘嗗彶鍥剧焊鏃犻渶妫�鏌�"; + } + else if (bom.ExcludeFromBOM) + { + title = "涓嶅湪鐗╂枡鏄庣粏琛ㄤ腑鐨勭墿鏂欐棤闇�妫�鏌�"; + } + else if (bom.component?.IsVirtual == true) + { + title = "铏氭嫙浠舵棤闇�妫�鏌�"; + } + else + { + title = "鏃犻渶妫�鏌�"; + } + this.Info(title); + return; + } + else if (bom.checkRuleOk && !bom.isHidden) + { + this.Show("瑙勫垯妫�鏌ラ�氳繃"); + } } + } + catch (Exception ex) + { + Logger.Error("Double Click CheckRule Exception.", ex); + this.Error($"鏈煡寮傚父:{ex.Message}"); } } @@ -1814,59 +1869,77 @@ /// <param name="e"></param> private void AuditTextBox_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { - // 妫�鏌ユ槸鍚︽槸鍙屽嚮 - if (e.ClickCount == 2) + try { - TextBlock textBlock = sender as TextBlock; - PdmBom bom = textBlock.DataContext as PdmBom; - if (string.IsNullOrEmpty(bom.BomInfo.status)) + // 妫�鏌ユ槸鍚︽槸鍙屽嚮 + if (e.ClickCount == 2) { - if (bom.produceWay == "妯$粍" || bom.produceWay == "鏍囧噯浠�") + TextBlock textBlock = sender as TextBlock; + PdmBom bom = textBlock.DataContext as PdmBom; + if (bom._drawInfo.isSpecial) { - this.Info($"{bom.produceWay}鏃犻渶瀹℃牳"); + this.Info("鏃犻渶瀹℃牳"); return; } - if (bom.IsHistoryData && !bom.localDocChanged) + if (bom.BomInfo.inKeeDeeDb == true) { - this.Info("鍘嗗彶鍥剧焊鏃犻渶瀹℃牳"); + this.Info("宸插叆绯荤粺"); return; } - if (bom.IsHistoryData && bom.localDocChanged) + if (string.IsNullOrEmpty(bom.BomInfo.status)) { - this.Info("鍘嗗彶鍥剧焊涓�鑷存�у彉鏇达紝闇�瀹℃牳"); - return; - } - this.Warning("璇ュ浘绾告湭瀹℃牳"); - return; - } - MaskAdorner.ShowMask(content, "璇锋眰涓紝璇风◢鍚�..."); - Task.Run(() => - { - try - { - Result<List<DrawAuditHis>> res = Client.GetSyncAction<List<DrawAuditHis>>("drawAudit/listTaskHis", new DrawAudit + if (bom.produceWay == "妯$粍" || bom.produceWay == "鏍囧噯浠�") { - id = bom.BomInfo.id - }); - var datas = res.HandleResult(); - Dispatcher.Invoke(() => + this.Info($"{bom.produceWay}鏃犻渶瀹℃牳"); + return; + } + if (bom.IsHistoryData && !bom.localDocChanged) { - //DrawAuditHisWindow window = new DrawAuditHisWindow(this, $"銆恵bom.partModel}銆戝鏍歌鎯�", datas); - RichHisWindow window = new RichHisWindow(this, $"銆恵bom.partModel}銆戝鏍歌鎯�", datas); + this.Info("鍘嗗彶鍥剧焊鏃犻渶瀹℃牳"); + return; + } + if (bom.IsHistoryData && bom.localDocChanged) + { + this.Info("鍘嗗彶鍥剧焊涓�鑷存�у彉鏇达紝闇�瀹℃牳"); + return; + } + this.Warning("璇ュ浘绾告湭瀹℃牳"); + return; + } + MaskAdorner.ShowMask(content, "璇锋眰涓紝璇风◢鍚�..."); + Task.Run(() => + { + try + { + Result<List<DrawAuditHis>> res = Client.GetSyncAction<List<DrawAuditHis>>("drawAudit/listTaskHis", new DrawAudit + { + id = bom.BomInfo.id + }); + var datas = res.HandleResult(); + Dispatcher.Invoke(() => + { + //DrawAuditHisWindow window = new DrawAuditHisWindow(this, $"銆恵bom.partModel}銆戝鏍歌鎯�", datas); + RichHisWindow window = new RichHisWindow(this, $"銆恵bom.partModel}銆戝鏍歌鎯�", datas); - window.ShowDialog(); - }); - } - catch (Exception ex) - { - Logger.Error($"V{PdmUser.LoginUser.pluginVersion}, Get draw audit history failed.", ex); - this.Error($"V{PdmUser.LoginUser.pluginVersion}锛岃幏鍙栧鏍稿巻鍙插け璐ワ紒{ex.Message}"); - } - finally - { - MaskAdorner.HideMask(content); - } - }); + window.ShowDialog(); + }); + } + catch (Exception ex) + { + Logger.Error($"V{PdmUser.LoginUser.pluginVersion}, Get draw audit history failed.", ex); + this.Error($"V{PdmUser.LoginUser.pluginVersion}锛岃幏鍙栧鏍稿巻鍙插け璐ワ紒{ex.Message}"); + } + finally + { + MaskAdorner.HideMask(content); + } + }); + } + } + catch (Exception ex) + { + Logger.Error("Double Click Audit Status Exception.", ex); + this.Error($"鏈煡寮傚父:{ex.Message}"); } } @@ -1997,6 +2070,12 @@ { throw new CantCheckInException(new List<string> { "璇锋墦寮�涓�寮犲浘绾�" }); } + if (model.bomTreeReader.needSaveList.Count > 0) + { + List<string> infos = new List<string>(model.bomTreeReader.needSaveList); + AutoSaveAlert(infos); + } + DoCheckRuleAsync(out _); // 绛涢�夋墍鏈夊湪鐗╂枡鏄庣粏琛ㄤ腑锛屼笉璺宠繃妫�鏌ュ苟涓旀鏌ユ湭閫氳繃鐨勶紝绫诲瀷鏄姞宸ヤ欢鐨勬湭閫氳繃瀹℃牳鐨勶紝鍔犲伐浠跺鏍搁�氳繃鐨勪絾鍥剧焊鍙樻洿鐨� List<string> errs = model.bomTreeReader.CacheList.Select(b => b.NeedStopCheckIn()) -- Gitblit v1.9.1