using Newtonsoft.Json; using PdmSwPlugin.Common.Util; using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Windows.Interop; namespace PdmSwPlugin.Common.Entity.Pdm { public class PdmBomParam { public string id { get; set; } public string checkUserName { get; set; } public string topPartModel { get; set; } public HashSet allModels { get; set; } public Dictionary needCheckProperties { get; set; } } /// /// 跟随图纸的BomInfo,多个PdmBom之间可能公用 /// public class BomInfo : NotifyBase { public string id { get; set; } public string name { get; set; } public string partNo { get; set; } public string partName { get; set; } public string partModel { get; set; } public string partBrandName { get; set; } public string filePath { get; set; } public int level { get; set; } public int drawingType { get; set; } public bool HistoryData = false; public ModelDoc2 doc { get; set; } public Component2 component { get; set; } public bool lost { get; set; } = false; public bool suppressed { get; set; } = false; public bool lightWeight { get; set; } = false; private Dictionary _properties; public Dictionary properties { get => _properties; set => RaiseAndSetIfChanged(ref _properties, value); } public string jgj { get => properties.Get("文件格式", "标准件"); } public string bomVersion { get; set; } public int checkStatus { get; set; } public string checkUserId { get; set; } public string checkUserName { get; set; } public string d3FilePath { get; set; } public string d2FilePath { get; set; } public string pdfFilePath { get; set; } public string d3Md5 { get; set; } public string d2Md5 { get; set; } public string pdfMd5 { get; set; } public string d3FileId { get; set; } public string d2FileId { get; set; } public string pdfFileId { get; set; } private string _status; public string status { get => _status; set => RaiseAndSetIfChanged(ref _status, value); } private string _auditId; public string auditId { get => _auditId; set => RaiseAndSetIfChanged(ref _auditId, value); } private string _requestUser; public string requestUser { get => _requestUser; set => RaiseAndSetIfChanged(ref _requestUser, value); } private string _auditUser; public string auditUser { get => _auditUser; set => RaiseAndSetIfChanged(ref _auditUser, value); } public string requestUserId { get; set; } public string auditUserId { get; set; } } /// /// 图纸信息 /// 这些信息要根据web更新,单独抽出来管理 /// public class DrawInfo : NotifyBase { /// /// 3Dmd5 /// public string d3Md5 { get; set; } /// /// 2Dmd5 /// public string d2Md5 { get; set; } /// /// pdfMd5 /// public string pdfMd5 { get; set; } /// /// 3D图纸FileId /// public string d3FileId { get; set; } /// /// 2D图纸FileId /// public string d2FileId { get; set; } /// /// PDF图纸FileId /// public string pdfFileId { get; set; } private int? _checkRuleResult = 0; public int? checkRuleResult { get => _checkRuleResult; set => RaiseAndSetIfChanged(ref _checkRuleResult, value); } public bool checkRuleOk => checkRuleResult == 1 || checkRuleResult == 3; private bool _HistoryData = false; public bool HistoryData { get => _HistoryData; set => RaiseAndSetIfChanged(ref _HistoryData, value); } public List errMessages { get; set; } public Dictionary allProperties { get; set; } } [Serializable] public class PdmBom : NotifyBase, ICloneable { public static event EventHandler InBomChanged; /// /// 是否级联选中 /// private static bool cascade = true; private BomInfo _bomInfo; public BomInfo BomInfo { get => _bomInfo; set => RaiseAndSetIfChanged(ref _bomInfo, value); } private string _treeId; public string treeId { get => _treeId; set => RaiseAndSetIfChanged(ref _treeId, value); } public string id => BomInfo?.id; public string name => BomInfo?.name; public string partNo => BomInfo?.partNo; public string partName => BomInfo?.partName; public string partModel => BomInfo?.partModel; public string partBrandName => BomInfo?.partBrandName; public int? drawingType => BomInfo?.drawingType; public Dictionary properties => BomInfo?.properties; public string d3FilePath => BomInfo?.d3FilePath; public string filePath => BomInfo?.filePath; public bool lost => BomInfo?.lost == true; public bool suppressed => BomInfo?.suppressed == true; public bool lightWeight => BomInfo?.lightWeight == true; public ModelDoc2 doc => BomInfo?.doc; public Component2 component { get; set; } public string bomVersion => BomInfo?.bomVersion; public int? checkStatus => BomInfo?.checkStatus; public string checkUserId => BomInfo?.checkUserId; public string checkUserName => BomInfo?.checkUserName; #region 规则检查相关字段 #endregion #region 图纸审核相关字段 public string drawStatus => BomInfo?.status; public string requestUserId => BomInfo?.requestUserId; public string requestUser => BomInfo?.requestUser; public string auditUserId => BomInfo?.auditUserId; public string auditUser => BomInfo?.auditUser; /// /// 是否是历史图纸 /// public bool IsHistoryData => _drawInfo?.HistoryData == true; /// /// 是否跳过规则检查 /// public bool skipCheck => produceWay == "模组" || ExcludeFromBOM || component?.IsVirtual == true; /// /// 图纸是否发生变更 非历史图纸看2D图MD5 历史图纸看一致性检查没通过 /// public bool localDocChanged => (!IsHistoryData && localD2Md5 != _drawInfo?.d2Md5) || (IsHistoryData && _drawInfo?.checkRuleResult == 2); //localD3Md5 != _drawInfo?.d3Md5; /// /// 规则检查结果 /// public int? checkRuleResult => (IsHistoryData || skipCheck) ? 3 : _drawInfo?.checkRuleResult; /// /// 检查是否OK /// public bool checkRuleOk => _drawInfo != null && _drawInfo.checkRuleOk; /// /// 是否不在物料明细表中 /// public bool ExcludeFromBOM { get => component == null ? false : component.ExcludeFromBOM; set { InBomChanged?.Invoke(this, value); } } /// /// 是否需要审核 /// public bool NeedAudit { get { // 找不到文档的不审核 if (lost) return false; // 不在物料明细表中不审核 if (ExcludeFromBOM) return false; if (IsHistoryData) { // 历史图纸只审核一致性不通过的 return _drawInfo.checkRuleResult == 2; } else { // 非历史图纸只审核 允许审核的加工件 return produceWay == "加工件" && (drawStatus != "submitted" && drawStatus != "resubmitted") && (drawStatus != "completed" || localDocChanged); } } } /// /// 是否需要终止检入/导入 /// /// public string NeedStopCheckIn() { if (produceWay == "模组") return null; if (ExcludeFromBOM) return null; if (IsHistoryData && localDocChanged) { return $"历史图纸【{partModel}】变更后未重新审核"; } if (!IsHistoryData) { bool error = false; string msg = $"【{partModel}】"; if (!skipCheck && !checkRuleOk) { error = true; msg += "未通过规则检查"; } if (produceWay == "加工件" && drawStatus != "completed") { error = true; msg += "未通过审核;"; } if (produceWay == "加工件" && drawStatus == "completed" && localDocChanged) { error = true; msg += "图纸变更后未重新审核"; } return error ? msg : null; } return null; } public void UpdateInBom(bool value) { if (component != null) { if (value) selected = false; component.ExcludeFromBOM = value; } if (modules != null) { foreach (PdmBom child in modules) { child.UpdateInBom(value); } } } #endregion public int _level; public int level { get => _level; set => RaiseAndSetIfChanged(ref _level, value); } public bool _selected = false; public bool selected { get => _selected; set { if (!checkBoxEnabled) { return; } RaiseAndSetIfChanged(ref _selected, value); if (cascade && modules != null && modules.Count > 0) { foreach (var m in modules) { m.selected = value; } } } } public string _parentTreeId => parent?.treeId; public string _partBrand; public string partBrand { get => _partBrand; set => RaiseAndSetIfChanged(ref _partBrand, value); } public string _produceWay; public string produceWay { get => _produceWay; set => RaiseAndSetIfChanged(ref _produceWay, value); } public double? _quantity; public double? quantity { get => _quantity; set => RaiseAndSetIfChanged(ref _quantity, value); } [JsonIgnore] public PdmBom _parent; [JsonIgnore] public PdmBom parent { get => _parent; set => RaiseAndSetIfChanged(ref _parent, value); } public string parentId { get => parent == null ? null : parent.id; } /// /// 加工件 /// public bool? _jgj; public bool? jgj { get => _jgj; set => RaiseAndSetIfChanged(ref _jgj, value); } /// /// 模拟件 /// public bool? _mn; public bool? mn { get => _mn; set => RaiseAndSetIfChanged(ref _mn, value); } /// /// 是否是型材 /// public bool? _xc; public bool? xc { get => _xc; set => RaiseAndSetIfChanged(ref _xc, value); } /// /// 是否是型材子料 /// public bool _xcChild = false; public bool xcChild { get => _xcChild; set => RaiseAndSetIfChanged(ref _xcChild, value); } /// /// 是否建料 /// public bool? _inDb; public bool? inDb { get => _inDb; set => RaiseAndSetIfChanged(ref _inDb, value); } /// /// 是否可检入 /// public bool? _canCheckIn; public bool? canCheckIn { get => _canCheckIn; set => RaiseAndSetIfChanged(ref _canCheckIn, value); } /// /// 也是子模组,这里对应的是WEB服务器中存贮的结构,整合了数量信息 /// public ObservableCollection _children; public ObservableCollection children { get => _children; set => RaiseAndSetIfChanged(ref _children, value); } /// /// 子模组,这个属性反映了图纸真实的结构 /// public ObservableCollection _modules; public ObservableCollection modules { get => _modules; set => RaiseAndSetIfChanged(ref _modules, value); } public void Init() { InitParent(); BomIniterHolder.Instance.InitBom(this); InitFilePath(); } public void InitParent() { if (parent != null) { xcChild = parent.xc == true || parent.xcChild == true; } } /// /// 判断BOM是否需要下单 /// public bool needOrdered => produceWay == "原材料" && (xcChild == false || jgj != true); public DrawInfo _drawInfo; public DrawInfo drawInfo { get => _drawInfo; set { if (_drawInfo != null) { _drawInfo.PropertyChanged -= Value_PropertyChanged; } value.PropertyChanged += Value_PropertyChanged; RaiseAndSetIfChanged(ref _drawInfo, value); } } private void Value_PropertyChanged(object sender, global::System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "checkRuleResult") { RaisePropertyChanged("checkRuleResult"); RaisePropertyChanged("localDocChanged"); } else if (e.PropertyName == "HistoryData") { RaisePropertyChanged("IsHistoryData"); } } public string d3Md5 => _drawInfo == null ? null : _drawInfo.d3Md5; public string d2Md5 => _drawInfo == null ? null : _drawInfo.d2Md5; public string pdfMd5 => _drawInfo == null ? null : _drawInfo.pdfMd5; public string d3FileId => _drawInfo == null ? null : _drawInfo.d3FileId; public string d2FileId => _drawInfo == null ? null : _drawInfo.d2FileId; public string pdfFileId => _drawInfo == null ? null : _drawInfo.pdfFileId; public string d2FilePath { get; set; } public string pdfFilePath { get; set; } public string localD3Md5 { get; set; } public string localD2Md5 { get; set; } public string localPdfMd5 { get; set; } public bool checkBoxEnabled => !(xcChild || (lost == true) || produceWay == "标准件" || (produceWay == "模组" && drawingType == (int)swDocumentTypes_e.swDocPART) || (ExcludeFromBOM && drawingType == (int)swDocumentTypes_e.swDocPART) // BomInfo.jgj == "标准件" //|| component?.IsVirtual == true ); public bool d3Changed => localD3Md5 != _drawInfo?.d3Md5; public int order { get; set; } /// /// 填充生产方式 /// public void InitFilePath() { if (string.IsNullOrEmpty(d3FilePath)) { return; } if ("自制" == produceWay) { localD3Md5 = MD5Util.Get(d3FilePath); return; } if (jgj == true) { d2FilePath = d3FilePath.Substring(0, d3FilePath.Length - 3) + "DRW"; pdfFilePath = Path.GetFileNameWithoutExtension(d3FilePath) + ".PDF"; } else { d2FilePath = d3FilePath.Substring(0, d3FilePath.Length - 3) + "DRW"; pdfFilePath = Path.GetFileNameWithoutExtension(d3FilePath) + ".PDF"; } localD3Md5 = MD5Util.Get(d3FilePath); localD2Md5 = MD5Util.Get(d2FilePath); localPdfMd5 = MD5Util.Get(pdfFilePath); } /// /// 浅拷贝 /// /// public PdmBom ShallowCopy() { return (PdmBom)MemberwiseClone(); } public object Clone() { return ShallowCopy(); } } }