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 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 cadProps = TCUtil.ReadTCData(titleData); bgWorker.Progress("读取BOM数据", 80); List> 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); } } }