chr
6 天以前 43a0207d207390abdeeb3ab9155eebf03edd7b1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
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<string> allModels { get; set; }
 
        public Dictionary<string, DrawInfo> needCheckProperties { get; set; }
    }
 
    /// <summary>
    /// 跟随图纸的BomInfo,多个PdmBom之间可能公用
    /// </summary>
    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 isHidden { get; set; } = false;
        public bool suppressed { get; set; } = false;
        public bool lightWeight { get; set; } = false;
 
        private Dictionary<string, string> _properties;
        public Dictionary<string, string> 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 bool? _inKeeDeeDb;
 
        public bool? inKeeDeeDb
        {
            get => _inKeeDeeDb;
            set => RaiseAndSetIfChanged(ref _inKeeDeeDb, 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; }
    }
 
    /// <summary>
    /// 图纸信息
    /// 这些信息要根据web更新,单独抽出来管理
    /// </summary>
    public class DrawInfo : NotifyBase
    {
        /// <summary>
        /// true说明没有工程图
        /// </summary>
        public bool _noDrw = false;
 
        public bool noDrw
        {
            get => _noDrw;
            set => RaiseAndSetIfChanged(ref _noDrw, value);
        }
 
        public bool _inKeeDeeDb = false;
 
        private bool _isSpecial;
        public bool isSpecial
        {
            get => _isSpecial;
            set => RaiseAndSetIfChanged(ref _isSpecial, value);
        }
 
        /// <summary>
        /// 3Dmd5
        /// </summary>
        public string d3Md5 { get; set; }
 
        /// <summary>
        /// 2Dmd5
        /// </summary>
        public string d2Md5 { get; set; }
 
        /// <summary>
        /// pdfMd5
        /// </summary>
        public string pdfMd5 { get; set; }
 
        /// <summary>
        /// 3D图纸FileId
        /// </summary>
        public string d3FileId { get; set; }
 
        /// <summary>
        /// 2D图纸FileId
        /// </summary>
        public string d2FileId { get; set; }
 
        /// <summary>
        /// PDF图纸FileId
        /// </summary>
        public string pdfFileId { get; set; }
 
        private int? _checkRuleResult = 0;
 
        public bool isHidden;
 
        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<string> errMessages { get; set; }
 
        public Dictionary<string, string> allProperties { get; set; }
 
        /// <summary>
        /// 为True说明没有工程图
        /// </summary>
    }
 
    [Serializable]
    public class PdmBom : NotifyBase, ICloneable
    {
 
        public static event EventHandler<bool> InBomChanged;
 
        /// <summary>
        /// 是否级联选中
        /// </summary>
        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);
        }
 
        /// <summary>
        /// true说明没有工程图
        /// </summary>
        public bool noDrw => (_drawInfo?.noDrw == true);
 
        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<string, string> properties => BomInfo?.properties;
        public string d3FilePath => BomInfo?.d3FilePath;
        public string filePath => BomInfo?.filePath;
        public bool lost => BomInfo?.lost == true || isHidden;
 
        public bool isHidden = false;
 
        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 图纸审核相关字段
        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;
 
        /// <summary>
        /// 是否是历史图纸
        /// </summary>
        public bool IsHistoryData => _drawInfo?.HistoryData == true;
        /// <summary>
        /// 是否跳过规则检查
        /// </summary>
        public bool skipCheck => produceWay == "模组" || ExcludeFromBOM || component?.IsVirtual == true;
        /// <summary>
        /// 图纸是否发生变更 非历史图纸看2D图MD5 历史图纸看一致性检查没通过
        /// </summary>
        public bool localDocChanged
        {
            get
            {
                //if (!IsHistoryData) return localD2Md5 != _drawInfo?.d2Md5; //(!IsHistoryData && localD2Md5 != _drawInfo?.d2Md5)
                //return (IsHistoryData && _drawInfo?.checkRuleResult == 2);
                return false;
            }
        }
        /// <summary>
        /// 规则检查结果
        /// </summary>
        public int? checkRuleResult => (IsHistoryData || skipCheck) ? 3 : (isHidden ? 2 : _drawInfo?.checkRuleResult);
        /// <summary>
        /// 检查是否OK
        /// </summary>
        public bool checkRuleOk => _drawInfo != null && _drawInfo.checkRuleOk;
        /// <summary>
        /// 是否不在物料明细表中
        /// </summary>
        public bool ExcludeFromBOM
        {
            get => component == null ? false : component.ExcludeFromBOM;
            set
            {
                InBomChanged?.Invoke(this, value);
            }
        }
 
        public List<string> ErrorMsgs;
 
        /// <summary>
        /// 是否需要审核
        /// </summary>
        public bool NeedAudit
        {
            get
            {
                // 找不到文档的不审核
                if (lost) return false;
                // 跳过检查的不审
                if (skipCheck) return false;
                // 进入系统的不审核
                if (BomInfo.inKeeDeeDb == true) return false;
                // 不在BOM明细表中不提交
                if (component.ExcludeFromBOM) return false;
                //if (_drawInfo.isSpecial) return false;
                // 待审核的不重复提交
                if (drawStatus == "submitted" || drawStatus == "resubmitted") return false;
                return produceWay == "加工件" && (drawStatus != "submitted" && drawStatus != "resubmitted")
                            && (drawStatus != "completed");
 
                /// 以前还要分图纸变更,现在不弄了
                //if (IsHistoryData)
                //{
                //    // 历史图纸只审核一致性不通过的 和被驳回的
                //    return _drawInfo.checkRuleResult == 2 || drawStatus == "rejected";
                //}
                //else
                //{
                //    // 非历史图纸只审核 允许审核的加工件
                //    return produceWay == "加工件"
                //            && (drawStatus != "submitted" && drawStatus != "resubmitted")
                //            && (drawStatus != "completed" || localDocChanged);
                //}
            }
        }
 
        /// <summary>
        /// 是否需要终止检入/导入
        /// </summary>
        /// <returns></returns>
        public string NeedStopCheckIn()
        {
            if (skipCheck) return null;
            /// 2025-03-12 修改金蝶插件拦截问题
            if (produceWay == "标准件") return null;
            if (drawInfo.isSpecial) return null;
            /// 2025-03-12 修改金蝶插件拦截问题 END
 
            if (BomInfo.inKeeDeeDb == true) return null;
            if (IsHistoryData)
            {
                bool err = false;
                string msg = $"历史图纸【{partModel}】";
                if (localDocChanged && !noDrw)
                {
                    err = true;
                    msg += "变更后未重新审核;";
                }
                if ((drawStatus == "rejected" || drawStatus == "submitted" || drawStatus == "resubmitted") && BomInfo.inKeeDeeDb != true)
                {
                    err = true;
                    msg += "未通过审核";
                }
 
                if (isHidden)
                {
                    err = true;
                    msg += "被隐藏;";
                }
                if (noDrw)
                {
                    err = true;
                    msg += "未找到工程图";
                }
                return err ? msg : null;
            }
            if (!IsHistoryData)
            {
                bool error = false;
                string msg = $"【{partModel}】";
                if (!skipCheck && !checkRuleOk)
                {
                    error = true;
                    msg += "未通过规则检查;";
                }
                if (!skipCheck && isHidden)
                {
                    error = true;
                    msg += "被隐藏;";
                }
                if (produceWay == "加工件" && drawStatus != "completed" && BomInfo.inKeeDeeDb != true)
                {
                    error = true;
                    msg += "未通过审核;";
                }
                if (produceWay == "加工件" && drawStatus == "completed" && localDocChanged && !noDrw)
                {
                    error = true;
                    msg += "图纸变更后未重新审核";
                }
                if (noDrw)
                {
                    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;
        }
 
        /// <summary>
        /// 加工件
        /// </summary>
        public bool? _jgj;
        public bool? jgj
        {
            get => _jgj;
            set => RaiseAndSetIfChanged(ref _jgj, value);
        }
 
        /// <summary>
        /// 模拟件
        /// </summary>
        public bool? _mn;
        public bool? mn
        {
            get => _mn;
            set => RaiseAndSetIfChanged(ref _mn, value);
        }
 
        /// <summary>
        /// 是否是型材
        /// </summary>
        public bool? _xc;
        public bool? xc
        {
            get => _xc;
            set => RaiseAndSetIfChanged(ref _xc, value);
        }
 
        /// <summary>
        /// 是否是型材子料
        /// </summary>
        public bool _xcChild = false;
        public bool xcChild
        {
            get => _xcChild;
            set => RaiseAndSetIfChanged(ref _xcChild, value);
        }
 
        /// <summary>
        /// 是否建料
        /// </summary>
        public bool? _inDb;
        public bool? inDb
        {
            get => _inDb;
            set => RaiseAndSetIfChanged(ref _inDb, value);
        }
 
        /// <summary>
        /// 是否可检入
        /// </summary>
        public bool? _canCheckIn;
        public bool? canCheckIn
        {
            get => _canCheckIn;
            set => RaiseAndSetIfChanged(ref _canCheckIn, value);
        }
 
        /// <summary>
        /// 也是子模组,这里对应的是WEB服务器中存贮的结构,整合了数量信息
        /// </summary>
        public ObservableCollection<PdmBom> _children;
        public ObservableCollection<PdmBom> children
        {
            get => _children;
            set => RaiseAndSetIfChanged(ref _children, value);
        }
 
        /// <summary>
        /// 子模组,这个属性反映了图纸真实的结构
        /// </summary>
        public ObservableCollection<PdmBom> _modules;
        public ObservableCollection<PdmBom> 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;
            }
        }
 
        /// <summary>
        /// 判断BOM是否需要下单
        /// </summary>
        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; }
 
        /// <summary>
        /// 填充生产方式
        /// </summary>
        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);
        }
 
 
        /// <summary>
        /// 浅拷贝
        /// </summary>
        /// <returns></returns>
        public PdmBom ShallowCopy()
        {
            return (PdmBom)MemberwiseClone();
        }
 
        public object Clone()
        {
            return ShallowCopy();
        }
    }
}