You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using connor_zwcadm.dialog;
using connor_zwcadm.model;
using connor_zwcadm.util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZwSoft.ZwCAD.ApplicationServices;
namespace connor_zwcadm.commands {
public class SyncBomCommand : AbstractCADCommand {
private KBackgroundWorker bgWorker { get; }
public TCUtil TCUtil { get; }
public SyncBomCommand(string file_path):base(file_path) {
bgWorker = new KBackgroundWorker();
bgWorker.backgroundWorker.DoWork += DoSync;
TCUtil = new TCUtil(bgWorker);
}
public void DoSync(object sender, DoWorkEventArgs e) {
bgWorker.Progress("初始化", "", 0);
InitCommand();
//读取图纸数据
bgWorker.Progress("读取对象数据", 40);
FrameInfo frameInfo = KCADUtil.ReadFrame();
TCData titleData = KCADUtil.ReadDocData(false, TCUtil);
List<PropertyInfo> saveBomConfig = KCADUtil.GetSaveConfig(frameInfo.Bom_Name, TCUtil);
TCData bomConfig = TCData.Parse(saveBomConfig);
if (bomConfig == null) {
throw new System.Exception("首选项配置错误:" + KMain.PREF_PROP_CONFIG_PREFIX + frameInfo.Bom_Name);
}
Dictionary<string, string> cadProps = TCUtil.ReadTCData(titleData);
bgWorker.Progress("读取BOM数据", 80);
List<Dictionary<string, string>> cadBomProps = TCUtil.ReadBomData(bomConfig, titleData.Rev);
KUtil.Log("BOM数量"+(cadBomProps==null?0:cadBomProps.Count));
if (cadBomProps == null || cadBomProps.Count == 0) {
throw new Exception("零组件无BOM结构取消更新");
}
//更新图纸数据
bgWorker.Progress("更新图纸", 90);
bgWorker.pbDialog.Dispatcher.Invoke(new Action(delegate {
KCADUtil.WriteBom(cadBomProps);
//using (DocumentLock docLoc = doc.LockDocument()) {
// doc.Editor.Regen();
//}
}));
bgWorker.Progress("更新完成", "", 100);
System.Threading.Thread.Sleep(800);
}
protected override void InitCommand() {
}
protected override void ExecuteCommand() {
bgWorker.Start(null);
}
}
}