using Eplan.EplApi.Base; using KPlan.Util; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using Teamcenter.Services.Strong.Cad._2007_01.StructureManagement; namespace KPlan.Forms.Bean { public class CheckTableRowData { public const string INDEX = "INDEX"; public const string CHECK = "CHECK"; public const string COUNT = "P_ARTICLEREF_COUNT"; public const string ITEMID = "P_ARTICLE_ERPNR"; public const string ORDERNR = "P_ARTICLE_ORDERNR"; public const string DEVICETAG = "P_FUNC_IDENTDEVICETAG"; private string title = ""; private XmlNode node2; public bool checkOK = false; public object[] rowData; public string itemId; public string orderNo; public string itemUid; public string deviceTag; private List nodeToCombine = new List(); private bool itemExist; public CheckTableRowData(string itemId,string orderNo, XmlNode node, bool itemExist, string itemUid) { this.node2 = node; if (!string.IsNullOrWhiteSpace(itemId)) { this.itemId = itemId; } else { this.itemId = GetPropValue(ITEMID, -1)?.ToString(); } if (!string.IsNullOrWhiteSpace(orderNo)) { this.orderNo = orderNo; } else { this.orderNo = GetPropValue(ORDERNR, -1)?.ToString(); } this.deviceTag = GetPropValue(DEVICETAG, -1)?.ToString(); this.itemExist = itemExist; this.itemUid = itemUid; } public void addCombineNode(CheckTableRowData bean) { if (bean.node2 != null) { nodeToCombine.Add(bean.node2); } } public bool CheckOK() { return checkOK; } public override bool Equals(object obj) { CheckTableRowData bean = obj as CheckTableRowData; if (bean == null) { return false; } if (!this.itemId.Equals(bean.itemId)){ return false; } if (this.deviceTag == null) { return bean.deviceTag == null; } else { return this.deviceTag.Equals(bean.deviceTag); } } public object[] GetRowData(int index, List config) { int len = config.Count; object[] res = new object[len]; /*if (len > 0) { title = GetPropValue(config[0], index); res[0] = this; }*/ for (int i = 0; i < len; i++) { res[i] = GetPropValue(config[i], index); // KUtil.DispatcherShow(kCheckProject_Ex, "i:" + i + "config[i]:"+ config[i] + " res[i]:" + res[i]); } rowData = res; return res; } public AttributesInfo[] GetBomProp(Dictionary saveConfig) { if (saveConfig == null) { return null; } List res = new List(); foreach (string tc in saveConfig.Keys) { string eplan = saveConfig[tc]; string val = GetPropValue(eplan,-1)?.ToString(); AttributesInfo info = new AttributesInfo(); info.Name = tc; info.Value = val == null ? "" : val; res.Add(info); } return res.ToArray(); } private object GetPropValue(string config, int index) { if (INDEX.Equals(config)) { return index; } if (CHECK.Equals(config)) { return Check(); } if (COUNT.Equals(config)) { return Count(); } if (ITEMID.Equals(config)) { return itemId; } if (ORDERNR.Equals(config)) { return orderNo; } int ind = config.IndexOf('@'); string language = null; if (ind > 0) { language = config.Substring(ind + 1); config = config.Substring(0, ind); } string val = null; if (node2 != null) { val = node2.Attributes[config]?.InnerText; if (!KUtil.IsEmpty(val) && !KUtil.IsEmpty(language)) { MultiLangString multiLangString = new MultiLangString(); multiLangString.SetAsString(val); val = multiLangString.GetString((ISOCode.Language)Enum.Parse(typeof(ISOCode.Language), language)); } } //XmlAttribute attr = node.Attributes[config]; return val == null ? "" : val; } private string Count() { if (node2 == null) { return ""; } double total = 0; string refCount = node2.Attributes["P_ARTICLEREF_COUNT"]?.InnerText; string lenth = node2.Attributes["P_ARTICLE_PARTIAL_LENGTH_VALUE"]?.InnerText; if (KUtil.IsEmpty(lenth)) { lenth = "1"; } if (!KUtil.IsEmpty(refCount) && !KUtil.IsEmpty(lenth)) { double dwire_length = Convert.ToDouble(lenth); if (dwire_length != 0.0) { double drecord_num = Convert.ToDouble(refCount); drecord_num = dwire_length * drecord_num; total += drecord_num; } } foreach(XmlNode node in nodeToCombine) { refCount = node.Attributes["P_ARTICLEREF_COUNT"]?.InnerText; lenth = node.Attributes["P_ARTICLE_PARTIAL_LENGTH_VALUE"]?.InnerText; if (KUtil.IsEmpty(lenth)) { lenth = "1"; } if (!KUtil.IsEmpty(refCount) && !KUtil.IsEmpty(lenth)) { double dwire_length = Convert.ToDouble(lenth); if (dwire_length != 0.0) { double drecord_num = Convert.ToDouble(refCount); drecord_num = dwire_length * drecord_num; total += drecord_num; } } } return total.ToString(); } private string Check() { if (node2 != null) { XmlAttribute discontinue = node2.Attributes["P_ARTICLE_DISCONTINUED"];//?.InnerText; if (discontinue != null && !"0".Equals(discontinue.InnerText)) { return "停产部件"; } } //string itemId = node.Attributes["P_ARTICLE_ERPNR"]?.InnerText; //string itemId = erpAttr == null ? "" : erpAttr.Value; if (itemExist) { //if (TCUtil.ItemExist(itemId)) { checkOK = true; return "TC存在"; } return "TC不存在"; } public override string ToString() { return title; } } }