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.

64 lines
2.4 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 System.Windows.Forms;
using ZwmToolKitLib;
namespace connor_zwcadm.commands {
class SyncBomLineCommand : AbstractCADCommand {
private KBackgroundWorker bgWorker { get; }
public TCUtil TCUtil { get; }
public SyncBomLineCommand(string file_path) : base(file_path) {
bgWorker = new KBackgroundWorker();
bgWorker.backgroundWorker.DoWork += DoSync;
TCUtil = new TCUtil(bgWorker);
}
public void DoSync(object sender, DoWorkEventArgs e) {
String err = "";
bgWorker.Progress("初始化", "", 0);
InitCommand();
//读取图纸数据
bgWorker.Progress("读取图纸Bom", 30);
Dictionary<int, TCData> bomlineMap = KCADUtil.ReadCADBomLine(TCUtil);
KUtil.Log("BOM数量" + (bomlineMap == null ? 0 : bomlineMap.Count));
if (bomlineMap == null || bomlineMap.Count == 0) {
throw new Exception("图纸中无有效BOM信息取消更新");
}
bgWorker.Progress("读取BOM数据", 50);
Dictionary<int, Dictionary<string, string>> propMap = new Dictionary<int, Dictionary<string, string>>();
foreach (int row in bomlineMap.Keys) {
TCData data = bomlineMap[row];
Dictionary<string, string> props = TCUtil.ReadTCData(data);
propMap.Add(row, props);
}
//更新图纸数据
bgWorker.Progress("更新图纸", 90);
bgWorker.pbDialog.Dispatcher.Invoke(new Action(delegate {
err = KCADUtil.WriteBomLine(propMap);
}));
bgWorker.Progress("更新完成", "", 100);
System.Threading.Thread.Sleep(800);
if (!("".Equals(err.Trim())))
{
MessageBox.Show("明细栏更新成功,但第" + err + "行数据更新失败,在TC系统中未找到对应的对象!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
}
protected override void InitCommand() {
}
protected override void ExecuteCommand() {
bgWorker.Start(null);
}
}
}