chr
2025-01-03 31a636e735a0addc56e4f4527f500b7aa0874eb5
PdmSwPlugin.PDM/PdmControl.xaml.cs
@@ -1,45 +1,40 @@
using 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;
using 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();
            // 不跳过检查的加工件,如果工程图不存在,设置noDrw为true
            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, "正在请求数据...");
           // 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>();
                    // 然后筛选选中的BOM
@@ -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())