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.

171 lines
7.3 KiB

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<string, CADAttr> ItemProps { get; }
public Dictionary<string, CADAttr> RevProps { get; }
public Dictionary<string, CADAttr> ItemMasterProps { get; }
public Dictionary<string, CADAttr> RevMasterProps { get; }
public Dictionary<string, CADAttr> BomProps { get; }
public string ItemTypeName { get; }
public Teamcenter.Soa.Client.Model.Strong.ItemRevision Rev { get; set; }
public bool NonBomPropertiesModified { get; set; }
public List<TCData> BomLineDatas { get; set; }
public string DocFileName { get; set; }
public string Item_id { get; }
private TCData(string itemId, string itemTypeName, Dictionary<string, CADAttr> itemProps, Dictionary<string, CADAttr> revProps, Dictionary<string, CADAttr> itemMasterProps, Dictionary<string, CADAttr> revMasterProps, Dictionary<string, CADAttr> 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<PropertyInfo> propertyInfos) {
int len = propertyInfos == null ? 0 : propertyInfos.Count;
if (len == 0) {
return null;
}
Dictionary<string, CADAttr> itemProps = new Dictionary<string, CADAttr>();
Dictionary<string, CADAttr> revProps = new Dictionary<string, CADAttr>();
Dictionary<string, CADAttr> itemMasterProps = new Dictionary<string, CADAttr>();
Dictionary<string, CADAttr> revMasterProps = new Dictionary<string, CADAttr>();
Dictionary<string, CADAttr> bomProps = new Dictionary<string, CADAttr>();
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<PropertyInfo> propertyInfos, Dictionary<string, string> cadValueMap) {
int len = propertyInfos == null ? 0 : propertyInfos.Count;
if (len == 0) {
return null;
}
string itemTypeName=null;
Dictionary<string, CADAttr> itemProps = new Dictionary<string, CADAttr>();
Dictionary<string, CADAttr> revProps = new Dictionary<string, CADAttr>();
Dictionary<string, CADAttr> itemMasterProps = new Dictionary<string, CADAttr>();
Dictionary<string, CADAttr> revMasterProps = new Dictionary<string, CADAttr>();
Dictionary<string, CADAttr> bomProps = new Dictionary<string, CADAttr>();
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);
}
}
}