using connor_zwcadm.util; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace connor_zwcadm.model { public class CADAttr { public string Name { get; } public string Value { get; } public bool UseRealValue { get; } public CADAttr(string name, string value, bool useRealValue) { Name = name; Value = value; UseRealValue = useRealValue; } public override string ToString() { return Value; } public override bool Equals(object obj) { if (obj == null || obj.GetType() != typeof(CADAttr)) { return false; } CADAttr other = (CADAttr)obj; return Value == null ? string.IsNullOrEmpty(other.Value) : Value.Equals(other.Value); } } public class TCData { public const string ITEMTYPE_UNASSIGNED = "未指定类型"; public Dictionary ItemProps { get; } public Dictionary RevProps { get; } public Dictionary ItemMasterProps { get; } public Dictionary RevMasterProps { get; } public Dictionary BomProps { get; } public string ItemTypeName { get; } public Teamcenter.Soa.Client.Model.Strong.ItemRevision Rev { get; set; } public bool NonBomPropertiesModified { get; set; } public List BomLineDatas { get; set; } public string DocFileName { get; set; } public string Item_id { get; } private TCData(string itemId, string itemTypeName, Dictionary itemProps, Dictionary revProps, Dictionary itemMasterProps, Dictionary revMasterProps, Dictionary bomProps) { this.Item_id = itemId; this.ItemTypeName = itemTypeName; this.ItemProps = itemProps; this.RevProps = revProps; this.ItemMasterProps = itemMasterProps; this.RevMasterProps = revMasterProps; this.BomProps = bomProps; this.NonBomPropertiesModified = true; } public override string ToString() { return DocFileName; } public override bool Equals(object obj) { if (obj == null || obj.GetType() != typeof(TCData)) { return false; } TCData other = (TCData)obj; return KUtil.CompareDictionary(ItemProps, other.ItemProps) && KUtil.CompareDictionary(RevProps, other.RevProps) && KUtil.CompareDictionary(ItemMasterProps, other.ItemMasterProps) && KUtil.CompareDictionary(RevMasterProps, other.RevMasterProps) && KUtil.CompareDictionary(BomProps, other.BomProps); } public static TCData Parse(List propertyInfos) { int len = propertyInfos == null ? 0 : propertyInfos.Count; if (len == 0) { return null; } Dictionary itemProps = new Dictionary(); Dictionary revProps = new Dictionary(); Dictionary itemMasterProps = new Dictionary(); Dictionary revMasterProps = new Dictionary(); Dictionary bomProps = new Dictionary(); for (int i = 0; i < len; i++) { PropertyInfo info = propertyInfos[i]; if (info == null) { continue; } if ("object_type".Equals(info.TcPropName)) { continue; } CADAttr propValue = new CADAttr(info.CadPropName, "", info.UseRealValue); switch (info.Location) { case PropertyInfo.PropLocation.Item: KUtil.Put(itemProps, info.TcPropName, propValue); break; case PropertyInfo.PropLocation.Rev: KUtil.Put(revProps, info.TcPropName, propValue); break; case PropertyInfo.PropLocation.ItemMaster: KUtil.Put(itemMasterProps, info.TcPropName, propValue); break; case PropertyInfo.PropLocation.RevMaster: KUtil.Put(revMasterProps, info.TcPropName, propValue); break; case PropertyInfo.PropLocation.BOMLine: KUtil.Put(bomProps, info.TcPropName, propValue); break; default: break; } } if (itemProps.Count + revProps.Count + itemMasterProps.Count + revMasterProps.Count + bomProps.Count == 0) { return null; } return new TCData("", "", itemProps, revProps, itemMasterProps, revMasterProps, bomProps); } public static TCData Parse(List propertyInfos, Dictionary cadValueMap) { int len = propertyInfos == null ? 0 : propertyInfos.Count; if (len == 0) { return null; } string itemTypeName=null; Dictionary itemProps = new Dictionary(); Dictionary revProps = new Dictionary(); Dictionary itemMasterProps = new Dictionary(); Dictionary revMasterProps = new Dictionary(); Dictionary bomProps = new Dictionary(); for (int i = 0; i < len; i++) { PropertyInfo info = propertyInfos[i]; if(info == null) { continue; } if("object_type".Equals(info.TcPropName)&&info.Location == PropertyInfo.PropLocation.Item) { itemTypeName = info.CadPropName; } if (!cadValueMap.ContainsKey(info.CadPropName)) { continue; } CADAttr propValue = new CADAttr(info.CadPropName, cadValueMap[info.CadPropName], info.UseRealValue); //CADAttr propValue = new CADAttr(info.CadPropName, cadValueMap[info.CadPropName]); switch (info.Location) { case PropertyInfo.PropLocation.Item: if ("item_id".Equals(info.TcPropName) && string.IsNullOrWhiteSpace(propValue.Value)) { break ; } KUtil.Put(itemProps, info.TcPropName, propValue); break; case PropertyInfo.PropLocation.Rev: KUtil.Put(revProps, info.TcPropName, propValue); break; case PropertyInfo.PropLocation.ItemMaster: KUtil.Put(itemMasterProps, info.TcPropName, propValue); break; case PropertyInfo.PropLocation.RevMaster: KUtil.Put(revMasterProps, info.TcPropName, propValue); break; case PropertyInfo.PropLocation.BOMLine: KUtil.Put(bomProps, info.TcPropName, propValue); break; default: break; } } string itemId = KUtil.GetCADValue(itemProps, "item_id"); return new TCData(itemId, itemTypeName, itemProps, revProps, itemMasterProps, revMasterProps, bomProps); } } }