From 981923c2a2cff6d61cd5a474d2ba398ba48f1fd5 Mon Sep 17 00:00:00 2001 From: chr <chr@chr.com> Date: 星期一, 02 九月 2024 17:40:17 +0800 Subject: [PATCH] 更新代码; --- PdmSwPlugin.DrawApprove/DrawApprove.xaml.cs | 133 +++++++++++++++++++++++++++++++++---------- 1 files changed, 101 insertions(+), 32 deletions(-) diff --git a/PdmSwPlugin.DrawApprove/DrawApprove.xaml.cs b/PdmSwPlugin.DrawApprove/DrawApprove.xaml.cs index 6c27ce6..551bee0 100644 --- a/PdmSwPlugin.DrawApprove/DrawApprove.xaml.cs +++ b/PdmSwPlugin.DrawApprove/DrawApprove.xaml.cs @@ -4,6 +4,7 @@ using PdmSwPlugin.Common; 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; @@ -64,8 +65,36 @@ public ObservableCollection<DrawAudit> dataSource { get => _dataSource; - set => RaiseAndSetIfChanged(ref _dataSource, value); + set + { + RaiseAndSetIfChanged(ref _dataSource, value); + if (value == null) + { + StatusBarText = $"鍏� 0 鏉�"; + } + else + { + StatusBarText = $"鍏� {value.Count} 鏉�"; + } + RefreshSelectedCount(); + } } + + private string _SelectBomText = "宸查�変腑 0 鏉�"; + public string SelectBomText + { + get => _SelectBomText; + set => RaiseAndSetIfChanged(ref _SelectBomText, value); + } + + private string _StatusBarText = "鍏� 0 鏉�"; + + public string StatusBarText + { + get { return _StatusBarText; } + set => RaiseAndSetIfChanged(ref _StatusBarText, value); + } + public DrawApproveControl() : this(null) @@ -100,7 +129,32 @@ { data.selected = cb.IsChecked.Value; } + int count = cb.IsChecked.Value ? (dataSource == null ? 0 : dataSource.Count) : 0; + SelectBomText = $"宸查�変腑 {count} 鏉�"; } + + private void RefreshSelectedCount() + { + if (dataSource == null || dataSource.Count <= 0) + { + SelectBomText = "宸查�変腑 0 鏉�"; + return; + } + int count = dataSource.Where(e => e.selected).Count(); + SelectBomText = $"宸查�変腑 {count} 鏉�"; + } + + /// <summary> + /// 鍗曚釜鐐归�変簨浠� + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + private void SingleCheckBox_Event(object sender, RoutedEventArgs e) + { + RefreshSelectedCount(); + } + + private void Button_Click(object sender, RoutedEventArgs e) { @@ -117,8 +171,8 @@ } catch (Exception ex) { - Logger.Error("UI update failed.", ex); - this.Error($"UI鏇存柊鍒楄〃澶辫触锛佸紓甯�:{ex}"); + Logger.Error($"V{PdmUser.LoginUser.pluginVersion}, UI update failed.", ex); + this.Error($"V{PdmUser.LoginUser.pluginVersion}锛孶I鏇存柊鍒楄〃澶辫触锛佸紓甯�:{ex}"); dataSource = new ObservableCollection<DrawAudit>(); } finally @@ -187,7 +241,7 @@ } else if (err != 0) { - Logger.Error($"OpenDoc6 Failed,Error:{err}.See Solidworks Doc."); + Logger.Error($"V{PdmUser.LoginUser.pluginVersion}, OpenDoc6 Failed,Error:{err}.See Solidworks Doc."); } else if (warn == 128) { @@ -207,39 +261,36 @@ { Button btn = sender as Button; DrawAudit da = btn.DataContext as DrawAudit; - string fileName = Path.GetFileName(da.d2RelativePath); - if (string.IsNullOrEmpty(fileName)) + string filePath = GetRealFilePath(da.d2RelativePath); + if (!File.Exists(filePath)) { - this.Error("鏃犳晥鏂囦欢鍚�"); + this.Error($"鏈嶅姟鍣ㄤ腑鏈壘鍒板伐绋嬪浘鏂囦欢锛岃矾寰�:{filePath}"); return; } - fileName = Path.Combine(PluginSetting.Instance.SwFilePath, fileName); - if (!File.Exists(fileName)) - { - this.Error($"鏈嶅姟鍣ㄤ腑鏈壘鍒板伐绋嬪浘鏂囦欢锛岃矾寰�:{fileName}"); - return; - } - OpenDocMayError(fileName, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_ReadOnly, + OpenDocMayError(filePath, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_ReadOnly, ""); + } + + private string GetRealFilePath(string relativePath) + { + // string fileName = Path.GetFileName(dbPath); + // string filePath = Path.Combine(PluginSetting.Instance.SwFilePath, dbPath); + string filePath = PluginSetting.Instance.SwFilePath + relativePath; + return filePath; } private void OpenDoc_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; DrawAudit da = btn.DataContext as DrawAudit; - string fileName = Path.GetFileName(da.d3RelativePath); - if (string.IsNullOrEmpty(fileName)) + string filePath = GetRealFilePath(da.d3RelativePath); + if (!File.Exists(filePath)) { - this.Error("鏃犳晥鏂囦欢鍚�"); + this.Error($"鏈嶅姟鍣ㄤ腑鏈壘鍒板浘绾告枃浠讹紝璺緞:{filePath}"); return; } - fileName = Path.Combine(PluginSetting.Instance.SwFilePath, fileName); - if (!File.Exists(fileName)) - { - this.Error($"鏈嶅姟鍣ㄤ腑鏈壘鍒板伐绋嬪浘鏂囦欢锛岃矾寰�:{fileName}"); - return; - } - OpenDocMayError(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_ReadOnly, + + OpenDocMayError(filePath, (int)FileExtentionChecker.Check(filePath, out _), (int)swOpenDocOptions_e.swOpenDocOptions_ReadOnly, ""); } @@ -252,8 +303,8 @@ } catch (Exception ex) { - Logger.Error("Get draw audit data list failed.", ex); - this.Error($"鍒锋柊鍒楄〃澶辫触锛佸紓甯�:{ex.Message}"); + Logger.Error($"V{PdmUser.LoginUser.pluginVersion}, Get draw audit data list failed.", ex); + this.Error($"V{PdmUser.LoginUser.pluginVersion}锛屽埛鏂板垪琛ㄥけ璐ワ紒寮傚父:{ex.Message}"); return new List<DrawAudit>(); } } @@ -262,14 +313,14 @@ { try { - string modelPath = Path.Combine(PluginSetting.Instance.SwFilePath, Path.GetFileName(da.d3RelativePath)); - string drawingPath = Path.Combine(PluginSetting.Instance.SwFilePath, Path.GetFileName(da.d2RelativePath)); + string modelPath = GetRealFilePath(da.d3RelativePath); + string drawingPath = GetRealFilePath(da.d2RelativePath); SwApp.CloseDoc(modelPath); SwApp.CloseDoc(drawingPath); } catch (Exception exx) { - Logger.Error("Auto close open doc failed.", exx); + Logger.Error($"V{PdmUser.LoginUser.pluginVersion}, Auto close open doc failed.", exx); } } @@ -295,6 +346,23 @@ { try { + string filePath = GetRealFilePath(da.d3RelativePath); + if (!File.Exists(filePath)) + { + this.Error($"鏈嶅姟鍣ㄤ腑鏈壘鍒板浘绾告枃浠讹紝璺緞:{filePath}"); + return; + } + + double[] massData = SwDMUtil.GetMassProperty(filePath, out string errMsg); + if (massData == null) + { + this.Error($"鑾峰彇鍥剧焊涓�鑷存�ф暟鎹け璐ワ紒{errMsg}"); + return; + } + da.fileName = Path.GetFileName(filePath); + da.volume = NumberUtil.HandleMass(massData[3]); + da.surfaceArea = NumberUtil.HandleMass(massData[4]); + da.mass = NumberUtil.HandleMass(massData[5]); da.pass = true; Result<object> res = Client.PostSyncAction<object>(da, "drawAudit/complete"); object obj = res.HandleResult(); @@ -306,7 +374,8 @@ } catch (Exception ex) { - Logger.Error("Draw complete failed.", ex); + Logger.Error($"V{PdmUser.LoginUser.pluginVersion}, Draw complete failed.", ex); + this.Error($"V{PdmUser.LoginUser.pluginVersion}锛屽鏍稿け璐ワ紒{ex.Message}"); } finally { @@ -375,8 +444,8 @@ } catch (Exception ex) { - Logger.Error("Get draw audit history failed.", ex); - this.Error($"鑾峰彇瀹℃牳鍘嗗彶澶辫触锛亄ex.Message}"); + Logger.Error($"V{PdmUser.LoginUser.pluginVersion},Get draw audit history failed.", ex); + this.Error($"V{PdmUser.LoginUser.pluginVersion}锛岃幏鍙栧鏍稿巻鍙插け璐ワ紒{ex.Message}"); } finally { -- Gitblit v1.9.1