|
|
using connor_zwcadm.model;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using Teamcenter.Services.Loose.Administration;
|
|
|
using Teamcenter.Services.Loose.Administration._2006_03.IRM;
|
|
|
using Teamcenter.Services.Loose.Cad._2007_01.StructureManagement;
|
|
|
using Teamcenter.Services.Loose.Cad._2007_12.StructureManagement;
|
|
|
using Teamcenter.Services.Loose.Cad._2013_05.StructureManagement;
|
|
|
using Teamcenter.Services.Strong.Core;
|
|
|
using Teamcenter.Services.Strong.Core._2006_03.DataManagement;
|
|
|
using Teamcenter.Services.Strong.Core._2007_01.DataManagement;
|
|
|
using Teamcenter.Services.Strong.Core._2007_06.DataManagement;
|
|
|
using Teamcenter.Services.Strong.Core._2008_06.DataManagement;
|
|
|
using Teamcenter.Services.Strong.Query;
|
|
|
using Teamcenter.Services.Strong.Query._2006_03.SavedQuery;
|
|
|
using Teamcenter.Soa.Client;
|
|
|
using Teamcenter.Soa.Client.Model;
|
|
|
using Teamcenter.Soa.Client.Model.Strong;
|
|
|
using DataManagement = Teamcenter.Services.Strong.Core._2008_06.DataManagement.DataManagement;
|
|
|
using RelOccInfo = Teamcenter.Services.Loose.Cad._2007_01.StructureManagement.RelOccInfo;
|
|
|
using Session = Teamcenter.ClientX.Session;
|
|
|
|
|
|
namespace connor_zwcadm.util {
|
|
|
public class TCUtil {
|
|
|
|
|
|
public PreferenceManagementService PrefService { get; }
|
|
|
public SessionService SessionService { get; }
|
|
|
public DataManagementService DataManagementService { get; }
|
|
|
public SavedQueryService SavedQueryService { get; }
|
|
|
public IRMService IRMService { get; }
|
|
|
public ReservationService ReservationService { get; }
|
|
|
public Teamcenter.Services.Loose.Cad.StructureManagementService StructureManagementService { get; }
|
|
|
public dialog.KBackgroundWorker BackgroundWorker { get; }
|
|
|
public ImanQuery Query_Item { get; }
|
|
|
public ImanQuery Query_ItemRevision { get; }
|
|
|
public ImanQuery Query_LatestItemRevision { get; }
|
|
|
public GroupMember CurrentMember { get; }
|
|
|
public Folder SelectedFolder { get; }
|
|
|
|
|
|
public TCUtil(dialog.KBackgroundWorker backgroundWorker) {
|
|
|
BackgroundWorker = backgroundWorker;
|
|
|
SessionService = SessionService.getService(Session.getConnection());
|
|
|
PrefService = PreferenceManagementService.getService(Session.getConnection());
|
|
|
SavedQueryService = SavedQueryService.getService(Session.getConnection());
|
|
|
IRMService = IRMService.getService(Session.getConnection());
|
|
|
DataManagementService = DataManagementService.getService(Session.getConnection());
|
|
|
ReservationService = ReservationService.getService(Session.getConnection());
|
|
|
StructureManagementService = Teamcenter.Services.Loose.Cad.StructureManagementService.getService(Session.getConnection());
|
|
|
Query_Item = GetSavedQuery("Item...");
|
|
|
Query_ItemRevision = GetSavedQuery("Item Revision...");
|
|
|
Query_LatestItemRevision = GetSavedQuery("Latest Item Revision...");
|
|
|
|
|
|
// 获取当前用户组成员,用于检查权限
|
|
|
User user = SessionService.GetTCSessionInfo().User;
|
|
|
Group group = SessionService.GetTCSessionInfo().Group;
|
|
|
GetProperties(user, "user_id");
|
|
|
GetProperties(group, "full_name");
|
|
|
string queryName = "__EINT_group_members";
|
|
|
string[] entries = new string[] { "User" };
|
|
|
string[] values = new string[] { user.User_id };
|
|
|
List<GroupMember> groupMembers = Query2<GroupMember>(queryName, entries, values);
|
|
|
foreach (GroupMember gm in groupMembers) {
|
|
|
GetProperties(gm, "user", "group");
|
|
|
if (gm.User == user && gm.Group == group) {
|
|
|
CurrentMember = gm;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (CurrentMember == null) {
|
|
|
throw new Exception("未找到当前用户组成员信息");
|
|
|
}
|
|
|
|
|
|
// 获取当前选择文件夹
|
|
|
string uid = SocketUtil.SendRequest("GETSELECTEDTARGET");
|
|
|
if (!string.IsNullOrEmpty(uid)) {
|
|
|
ServiceData sd = DataManagementService.LoadObjects(new string[] { uid });
|
|
|
if (sd.sizeOfPlainObjects() == 1) {
|
|
|
ModelObject obj = sd.GetPlainObject(0);
|
|
|
GetProperties(obj, "object_string");
|
|
|
KUtil.Log("当前选择对象:"+obj.GetPropertyDisplayableValue("object_string"));
|
|
|
if(obj is Folder) {
|
|
|
SelectedFolder = obj as Folder;
|
|
|
}
|
|
|
else {
|
|
|
KUtil.Log(">> 该对象不是文件夹类型");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void SetProgress(string message) {
|
|
|
if (BackgroundWorker == null) {
|
|
|
return;
|
|
|
}
|
|
|
BackgroundWorker.ProgressDetail(message);
|
|
|
}
|
|
|
|
|
|
public string[] GetPrefValues(string prefName)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(prefName))
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
PrefService.RefreshPreferences();
|
|
|
Teamcenter.Services.Loose.Administration._2012_09.PreferenceManagement.GetPreferencesResponse resp0 = PrefService.GetPreferences(new string[] { "TC_customization_libraries" }, false);
|
|
|
CheckPartialError(resp0.Data);
|
|
|
KUtil.Log(">> GetPrefValues: " + resp0.Response[0].Values);
|
|
|
Teamcenter.Services.Loose.Administration._2012_09.PreferenceManagement.GetPreferencesResponse resp = PrefService.GetPreferences(new string[] { prefName }, false);
|
|
|
//Teamcenter.Services.Strong.Administration._2012_09.PreferenceManagement.GetPreferencesResponse resp = prefService.GetPreferences(new string[] { prefName }, false);
|
|
|
CheckPartialError(resp.Data);
|
|
|
List<string> values = new List<string>();
|
|
|
int len = resp.Response == null ? 0 : resp.Response.Length;
|
|
|
for (int i = 0; i < len; i++)
|
|
|
{
|
|
|
Teamcenter.Services.Loose.Administration._2012_09.PreferenceManagement.PreferenceValue prefValues = resp.Response[i].Values;
|
|
|
if (prefValues == null)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
return prefValues.Values;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public Dictionary<string, string> GetPrefValues(string prefName, string splitter) {
|
|
|
string[] values = GetPrefValues(prefName);
|
|
|
if (values == null) {
|
|
|
return null;
|
|
|
}
|
|
|
Dictionary<string, string> res = new Dictionary<string, string>();
|
|
|
foreach (string value in values) {
|
|
|
int ind = value.IndexOf(splitter);
|
|
|
if (ind > 0) {
|
|
|
KUtil.Put(res, value.Substring(0, ind), value.Substring(ind + splitter.Length));
|
|
|
}
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
public static bool CheckLogin(bool showDialog = false) {
|
|
|
bool sessionOK = false;
|
|
|
string userName = "";
|
|
|
if (Session.getConnection() != null) {
|
|
|
try {
|
|
|
SessionService sessionService = SessionService.getService(Session.getConnection());
|
|
|
Teamcenter.Services.Strong.Core._2007_01.Session.GetTCSessionInfoResponse resp = sessionService.GetTCSessionInfo();
|
|
|
CheckPartialError(resp.ServiceData);
|
|
|
sessionOK = resp.User != null;
|
|
|
userName = resp.User == null ? null : resp.User.User_name;
|
|
|
}
|
|
|
catch (System.Exception e) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
if (sessionOK && !showDialog) {
|
|
|
return true;
|
|
|
}
|
|
|
dialog.Login loginDialog = new dialog.Login(userName, !showDialog);
|
|
|
loginDialog.ShowDialog();
|
|
|
return loginDialog.getLoginResult();
|
|
|
}
|
|
|
|
|
|
public static string Login(string host, string id, string password, string character) {
|
|
|
KUtil.Log("开始登录...");
|
|
|
KUtil.Log(host + " -> " + id);
|
|
|
if (KUtil.IsEmpty(id) || KUtil.IsEmpty(password)) {
|
|
|
throw new Exception("用户名和密码不能为空");
|
|
|
}
|
|
|
Session session = new Session(host);
|
|
|
Teamcenter.Soa.Client.Model.Strong.User user = session.login(id, password);
|
|
|
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
|
|
|
dmService.GetProperties(new ModelObject[] { user }, new string[] { "user_name" });
|
|
|
string userName = user.User_name;
|
|
|
KUtil.Log("登录成功,登录用户:" + userName);
|
|
|
ConfigUtil.SetValue(ConfigUtil.LAST_LOGIN_USER, id);
|
|
|
return userName;
|
|
|
}
|
|
|
|
|
|
public static void CheckPartialError(ServiceData data) {
|
|
|
if (data.sizeOfPartialErrors() > 0) {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
for (int i = 0; i < data.sizeOfPartialErrors(); i++) {
|
|
|
foreach (string msg in data.GetPartialError(i).Messages) {
|
|
|
sb.Append(msg + "\n");
|
|
|
}
|
|
|
}
|
|
|
if (sb.Length > 0) {
|
|
|
throw new System.Exception(sb.ToString());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void CheckPartialError(GetFileResponse data) {
|
|
|
if (data.SizeOfPartialErrors() > 0) {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
for (int i = 0; i < data.SizeOfPartialErrors(); i++) {
|
|
|
foreach (string msg in data.GetPartialError(i).Messages) {
|
|
|
sb.Append(msg + "\n");
|
|
|
}
|
|
|
}
|
|
|
if (sb.Length > 0) {
|
|
|
throw new System.Exception(sb.ToString());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void GetProperties(ModelObject mo, params string[] props) {
|
|
|
DataManagementService.RefreshObjects(new ModelObject[] { mo });
|
|
|
ServiceData sd = DataManagementService.GetProperties(new ModelObject[] { mo }, props);
|
|
|
CheckPartialError(sd);
|
|
|
}
|
|
|
|
|
|
public ItemRevision QueryItemRevsion(string itemId, string revId, string type) {
|
|
|
if (KUtil.IsEmpty(itemId) || KUtil.IsEmpty(revId)) {
|
|
|
return null;
|
|
|
}
|
|
|
if (KUtil.IsEmpty(type)) {
|
|
|
throw new Exception("查询“类型”字段不能为空值");
|
|
|
}
|
|
|
List<ItemRevision> revs = Query<ItemRevision>(Query_ItemRevision, new string[] { "零组件 ID", "版本", "类型" }, new string[] { itemId, revId, type });
|
|
|
int cnt = revs == null ? 0 : revs.Count;
|
|
|
if (cnt == 1) {
|
|
|
return revs[0];
|
|
|
}
|
|
|
if (cnt > 1) {
|
|
|
throw new Exception("查询到多个最新版本:" + itemId + "/" + revId);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public ItemRevision QueryLatestRevision(string itemId, string type, bool dynamicType = false) {
|
|
|
if (KUtil.IsEmpty(itemId)) {
|
|
|
return null;
|
|
|
}
|
|
|
if (KUtil.IsEmpty(type)) {
|
|
|
throw new Exception("查询“类型”字段不能为空值");
|
|
|
}
|
|
|
{
|
|
|
List<ItemRevision> revs = Query<ItemRevision>(Query_LatestItemRevision, new string[] { "零组件 ID", "类型" }, new string[] { itemId, type });
|
|
|
int cnt = revs == null ? 0 : revs.Count;
|
|
|
if (cnt == 1) {
|
|
|
return revs[0];
|
|
|
}
|
|
|
if (cnt > 1) {
|
|
|
throw new Exception("通过ID查询到多个最新版本:" + itemId);
|
|
|
}
|
|
|
}
|
|
|
if (dynamicType) {
|
|
|
KUtil.Log("查询动态类型:" + itemId + " -> " + type);
|
|
|
List<ItemRevision> revs = Query<ItemRevision>(Query_LatestItemRevision, new string[] { "零组件 ID" }, new string[] { itemId });
|
|
|
int cnt = revs == null ? 0 : revs.Count;
|
|
|
if (cnt == 1) {
|
|
|
return revs[0];
|
|
|
}
|
|
|
if (cnt > 1) {
|
|
|
throw new Exception("通过ID查询到多个最新版本(多类型):" + itemId);
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public Item QueryItem(string itemId, string type, bool dynamicType = false) {
|
|
|
if (KUtil.IsEmpty(itemId)) {
|
|
|
return null;
|
|
|
}
|
|
|
if (KUtil.IsEmpty(type)) {
|
|
|
throw new Exception("查询“类型”字段不能为空值");
|
|
|
}
|
|
|
{
|
|
|
List<Item> items = Query<Item>(Query_Item, new string[] { "零组件 ID", "类型" }, new string[] { itemId, type });
|
|
|
int cnt = items == null ? 0 : items.Count;
|
|
|
if (cnt == 1) {
|
|
|
return items[0];
|
|
|
}
|
|
|
if (cnt > 1) {
|
|
|
throw new Exception("通过ID查询到多个最新对象:" + itemId);
|
|
|
}
|
|
|
}
|
|
|
if (dynamicType) {
|
|
|
KUtil.Log("查询动态类型:"+itemId+" -> "+type);
|
|
|
List<Item> items = Query<Item>(Query_Item, new string[] { "零组件 ID" }, new string[] { itemId });
|
|
|
int cnt = items == null ? 0 : items.Count;
|
|
|
if (cnt == 1) {
|
|
|
return items[0];
|
|
|
}
|
|
|
if (cnt > 1) {
|
|
|
throw new Exception("通过ID查询到多个对象(多类型):" + itemId);
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
private Item QueryItem2(string item_id) {
|
|
|
if (KUtil.IsEmpty(item_id)) {
|
|
|
return null;
|
|
|
}
|
|
|
GetItemAndRelatedObjectsInfo info = new GetItemAndRelatedObjectsInfo();
|
|
|
AttrInfo attrInfo = new AttrInfo();
|
|
|
attrInfo.Name = "item_id";
|
|
|
attrInfo.Value = item_id;
|
|
|
ItemInfo itemInfo = new ItemInfo();
|
|
|
itemInfo.Ids = new AttrInfo[] { attrInfo };
|
|
|
itemInfo.UseIdFirst = true;
|
|
|
itemInfo.ClientId = "itemInfo1";
|
|
|
RevInfo revInfo = new RevInfo();
|
|
|
revInfo.Processing = "None";// "Ids";
|
|
|
revInfo.UseIdFirst = true;
|
|
|
revInfo.NRevs = 1;
|
|
|
revInfo.ClientId = "revInfo1";
|
|
|
DatasetInfo dsInfo = new DatasetInfo();
|
|
|
dsInfo.ClientId = "dsInfo1";
|
|
|
dsInfo.Filter = new DatasetFilter();
|
|
|
dsInfo.Filter.Processing = "None";
|
|
|
info.ItemInfo = itemInfo;
|
|
|
info.RevInfo = revInfo;
|
|
|
info.DatasetInfo = dsInfo;
|
|
|
GetItemAndRelatedObjectsResponse resp = DataManagementService.GetItemAndRelatedObjects(new GetItemAndRelatedObjectsInfo[] { info });
|
|
|
// CheckPartialError(resp.ServiceData);
|
|
|
return resp.Output.Length > 0 ? resp.Output[0].Item : null;
|
|
|
}
|
|
|
|
|
|
public ImanQuery GetSavedQuery(string queryName) {
|
|
|
if (string.IsNullOrWhiteSpace(queryName)) {
|
|
|
return null;
|
|
|
}
|
|
|
Teamcenter.Services.Strong.Query._2006_03.SavedQuery.GetSavedQueriesResponse resp = SavedQueryService.GetSavedQueries();
|
|
|
CheckPartialError(resp.ServiceData);
|
|
|
int len = resp.Queries == null ? 0 : resp.Queries.Length;
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
Teamcenter.Services.Strong.Query._2006_03.SavedQuery.SavedQueryObject queryObj = resp.Queries[i];
|
|
|
if (queryName.Equals(queryObj.Name)) {
|
|
|
return queryObj.Query;
|
|
|
}
|
|
|
}
|
|
|
throw new Exception("未找到保存的查询\"" + queryName + "\"");
|
|
|
}
|
|
|
|
|
|
public List<T> Query<T>(ImanQuery query, string[] entries, string[] values) {
|
|
|
//KUtil.Log(string.Format("执行查询[{0}]: [{1}] = [{2}]", query.Query_name, string.Join(", ", entries), string.Join(", ", values)));
|
|
|
List<T> resultList = new List<T>();
|
|
|
ExecuteSavedQueryResponse qryResp1 = SavedQueryService.ExecuteSavedQuery(query, entries, values, 0);
|
|
|
CheckPartialError(qryResp1.ServiceData);
|
|
|
foreach (ModelObject mObj in qryResp1.Objects) {
|
|
|
if (mObj is T ) {
|
|
|
resultList.Add((T)mObj);
|
|
|
}
|
|
|
}
|
|
|
//KUtil.Log("查询结果数量:" + resultList.Count);
|
|
|
return resultList;
|
|
|
}
|
|
|
|
|
|
public List<T> Query2<T>(string queryName, string[] entries, string[] values) {
|
|
|
// KUtil.Log(string.Format("执行查询[{0}]: [{1}] = [{2}]", queryName, string.Join(", ", entries), string.Join(", ", values)));
|
|
|
List<T> resultList = new List<T>();
|
|
|
ImanQuery query = GetSavedQuery(queryName);
|
|
|
return Query<T>(query, entries, values);
|
|
|
// 提示不支持的查询
|
|
|
//QueryInput queryInput = new QueryInput();
|
|
|
//queryInput.Query = query;
|
|
|
//queryInput.LimitList = new ModelObject[0];
|
|
|
//queryInput.MaxNumToReturn = 0;
|
|
|
//queryInput.ResultsType = 0;
|
|
|
//queryInput.Entries = entries;
|
|
|
//queryInput.Values = values;
|
|
|
//Teamcenter.Services.Strong.Query._2007_09.SavedQuery.SavedQueriesResponse qryResp = SavedQueryService.ExecuteSavedQueries(new QueryInput[] { queryInput });
|
|
|
//CheckPartialError(qryResp.ServiceData);
|
|
|
//string[][] uids = new string[qryResp.ArrayOfResults.Length][];
|
|
|
//for (int i = 0; i < qryResp.ArrayOfResults.Length; i++) {
|
|
|
// uids[i] = qryResp.ArrayOfResults[i].ObjectUIDS;
|
|
|
//}
|
|
|
//foreach (string[] grpUIDs in uids) {
|
|
|
// ServiceData sData = DataManagementService.LoadObjects(grpUIDs);
|
|
|
// CheckPartialError(sData);
|
|
|
// for (int i = 0; i < sData.sizeOfPlainObjects(); i++) {
|
|
|
// ModelObject mObj = sData.GetPlainObject(i);
|
|
|
// //KUtil.Log(mObj.Uid + " > " + mObj.GetType().Name);
|
|
|
// if (mObj is T t) {
|
|
|
// resultList.Add(t);
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
//KUtil.Log("查询结果数量:"+resultList.Count);
|
|
|
//return resultList;
|
|
|
}
|
|
|
|
|
|
public bool CheckCanWrite(ModelObject obj) {
|
|
|
if (obj == null) {
|
|
|
return false;
|
|
|
}
|
|
|
DataManagementService.RefreshObjects(new ModelObject[] { obj });
|
|
|
Teamcenter.Services.Loose.Administration._2006_03.IRM.CheckAccessorPrivilegesResponse resp = IRMService.CheckAccessorsPrivileges(CurrentMember, new ModelObject[] { obj }, new string[] { "WRITE" });
|
|
|
CheckPartialError(resp.ServiceData);
|
|
|
foreach (PrivilegeReport report in resp.PrivilegeReports) {
|
|
|
foreach (Privilege priv in report.PrivilegeInfos) {
|
|
|
if ("WRITE".Equals(priv.PrivilegeName) && priv.Verdict) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public bool CheckTypeName(string typeName) {
|
|
|
Teamcenter.Schemas.Soa._2011_06.Metamodel.TypeSchema typeResp = SessionService.GetTypeDescriptions(new string[] { typeName });
|
|
|
if (typeResp.Types == null || typeResp.Types.Length == 0) {
|
|
|
KUtil.Log("检查类型名称:[" + typeName + "] -> 不存在");
|
|
|
return false;
|
|
|
}
|
|
|
KUtil.Log("检查类型名称:[" + typeName + "] -> 存在");
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public string GetRevTypeName(string itemTypeName) {
|
|
|
if ("Part".Equals(itemTypeName)) {
|
|
|
return itemTypeName + " Revision";
|
|
|
}
|
|
|
else {
|
|
|
return itemTypeName + "Revision";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Dictionary<string, string> ReadTCData(TCData data) {
|
|
|
if (data == null) {
|
|
|
return null;
|
|
|
}
|
|
|
string itemTypeName = data.ItemTypeName;
|
|
|
// test
|
|
|
// KUtil.Put(data.ItemProps, "item_id", "");
|
|
|
string itemId = KUtil.GetCADValue(data.ItemProps, "item_id");
|
|
|
string revId = KUtil.GetCADValue(data.RevProps, "item_revision_id");
|
|
|
string name = KUtil.GetCADValue(data.ItemProps, "object_name");
|
|
|
if (string.IsNullOrWhiteSpace(name)) {
|
|
|
name = KUtil.GetCADValue(data.RevProps, "object_name");
|
|
|
}
|
|
|
KUtil.Log(string.Format("查询TC数据:类型[{0}] ID[{1}] 版本[{2}] 名称[{3}]", itemTypeName, itemId, revId, name));
|
|
|
SetProgress("查询对象 " + itemId);
|
|
|
ItemRevision rev = null;
|
|
|
if (string.IsNullOrWhiteSpace(itemId)) {
|
|
|
throw new Exception("参数异常:对象ID不可为空");
|
|
|
}
|
|
|
string revTypeName = GetRevTypeName(itemTypeName);
|
|
|
if (string.IsNullOrWhiteSpace(revId)) {
|
|
|
rev = QueryLatestRevision(itemId, revTypeName);
|
|
|
}
|
|
|
else {
|
|
|
rev = QueryItemRevsion(itemId, revId, revTypeName);
|
|
|
}
|
|
|
if (rev == null) {
|
|
|
return null;
|
|
|
// throw new Exception("未在TC中查询到图号是[" + itemId + (string.IsNullOrWhiteSpace(revId) ? "" : ("/" + revId)) + "]的零组件,更新未成功。");
|
|
|
// throw new Exception("未查询到对象:" + + (string.IsNullOrWhiteSpace(name) ? "" : ("-" + name)));
|
|
|
}
|
|
|
GetProperties(rev, "object_string");
|
|
|
KUtil.Log("找到已存在的版本:" + rev.Object_string);
|
|
|
SetProgress("读取属性 " + rev.Object_string);
|
|
|
//更新属性
|
|
|
data.Rev = rev;
|
|
|
return ReadProperties(data);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Dictionary<string, string> ReadTCData2(TCData data,string itemId,string revId)
|
|
|
{
|
|
|
if (data == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
string itemTypeName = "Lb5_Design";
|
|
|
// test
|
|
|
// KUtil.Put(data.ItemProps, "item_id", "");
|
|
|
// string itemId = KUtil.GetCADValue(data.ItemProps, "item_id");
|
|
|
//string revId = KUtil.GetCADValue(data.RevProps, "item_revision_id");
|
|
|
//string name = KUtil.GetCADValue(data.ItemProps, "object_name");
|
|
|
|
|
|
KUtil.Log(string.Format("查询TC数据:类型[{0}] ID[{1}] 版本[{2}] 名称[{3}]", itemTypeName, itemId, revId, ""));
|
|
|
|
|
|
ItemRevision rev = null;
|
|
|
if (string.IsNullOrWhiteSpace(itemId))
|
|
|
{
|
|
|
throw new Exception("参数异常:对象ID不可为空");
|
|
|
}
|
|
|
string revTypeName = GetRevTypeName(itemTypeName);
|
|
|
if (string.IsNullOrWhiteSpace(revId))
|
|
|
{
|
|
|
rev = QueryLatestRevision(itemId, revTypeName);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
rev = QueryItemRevsion(itemId, revId, revTypeName);
|
|
|
}
|
|
|
if (rev == null)
|
|
|
{
|
|
|
return null;
|
|
|
// throw new Exception("未在TC中查询到图号是[" + itemId + (string.IsNullOrWhiteSpace(revId) ? "" : ("/" + revId)) + "]的零组件,更新未成功。");
|
|
|
// throw new Exception("未查询到对象:" + + (string.IsNullOrWhiteSpace(name) ? "" : ("-" + name)));
|
|
|
}
|
|
|
|
|
|
|
|
|
WhereReferencedResponse referencedResponse = DataManagementService.WhereReferenced(new WorkspaceObject[] { rev }, 1);
|
|
|
int outputSize = referencedResponse.Output.Length;
|
|
|
KUtil.Log("outputSize:" + outputSize);
|
|
|
for (int i = 0; i < outputSize; i++)
|
|
|
{
|
|
|
// 何处引用输出
|
|
|
WhereReferencedOutput referencedOutput = referencedResponse.Output[i];
|
|
|
int infoSize = referencedOutput.Info.Length;
|
|
|
|
|
|
for (int j = 0; j < infoSize; j++)
|
|
|
{
|
|
|
// 何处引用信息
|
|
|
WhereReferencedInfo referencedInfo = referencedOutput.Info[j];
|
|
|
// 当前引用对象
|
|
|
WorkspaceObject referencedObject = referencedInfo.Referencer;
|
|
|
GetProperties(referencedObject,"object_type");
|
|
|
KUtil.Log("referencedObject.Object_type:" + referencedObject.Object_type);
|
|
|
if (referencedObject.Object_type.Equals("Lb5_ChangeNoticeRevision"))
|
|
|
{
|
|
|
rev = (ItemRevision)referencedObject;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
GetProperties(rev, "object_string");
|
|
|
KUtil.Log("找到已存在的版本:" + rev.Object_string);
|
|
|
|
|
|
//更新属性
|
|
|
data.Rev = rev;
|
|
|
return ReadProperties(data);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Dictionary<string, string>> ReadBomData(TCData bomConfig, ItemRevision topRev) {
|
|
|
if (topRev == null || bomConfig == null) {
|
|
|
return null;
|
|
|
}
|
|
|
KUtil.Log("开始读取BOM");
|
|
|
GetProperties(topRev, "object_string", "structure_revisions", "items_tag");
|
|
|
KUtil.Log("顶层:" + topRev.Object_string);
|
|
|
|
|
|
Item item = topRev.Items_tag;
|
|
|
if (item == null) {
|
|
|
throw new Exception("获取对象Item异常:"+topRev.Object_string);
|
|
|
}
|
|
|
GetProperties(item, "object_string", "bom_view_tags");
|
|
|
ModelObject[] bvs = item.Bom_view_tags;
|
|
|
int bvrCnt = KUtil.GetLen(bvs);
|
|
|
KUtil.Log("Find Bom Views: " + bvrCnt);
|
|
|
if (bvrCnt == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
//string revisionRuleName = "Latest Working";
|
|
|
//RevisionRule revisionRule = GetRevisionRule(revisionRuleName);
|
|
|
//if (revisionRule == null) {
|
|
|
// throw new Exception("读取BOM失败,未找到版本规则:"+revisionRuleName);
|
|
|
//}
|
|
|
PSBOMView bomView = bvs[0] as PSBOMView;
|
|
|
if (bomView == null) {
|
|
|
throw new Exception("获取BOM视图异常");
|
|
|
}
|
|
|
GetProperties(bomView, "object_string");
|
|
|
KUtil.Log("BOM视图:"+bomView.Object_string);
|
|
|
CreateWindowsInfo2 windowInfo = new CreateWindowsInfo2();
|
|
|
windowInfo.BomView = bomView;
|
|
|
windowInfo.Item = item;
|
|
|
windowInfo.ItemRev = topRev;
|
|
|
//windowInfo.ObjectsForConfigure = null;
|
|
|
//windowInfo.RevRuleConfigInfo.Props.Date = new DateTime();
|
|
|
//windowInfo.RevRuleConfigInfo.Props.EndItem = null;
|
|
|
//windowInfo.RevRuleConfigInfo.Props.EndItemRevision = null;
|
|
|
//OverrideInfo overrideInfo = new OverrideInfo();
|
|
|
//overrideInfo.Folder = null;
|
|
|
//overrideInfo.RuleEntry = null;
|
|
|
//windowInfo.RevRuleConfigInfo.Props.OverrideFolders = new OverrideInfo[] { overrideInfo };
|
|
|
//windowInfo.RevRuleConfigInfo.Props.Today = false;
|
|
|
//windowInfo.RevRuleConfigInfo.Props.UnitNo = 0;
|
|
|
//windowInfo.RevRuleConfigInfo.RevRule = revisionRule;
|
|
|
CreateBOMWindowsResponse resp = StructureManagementService.CreateBOMWindows2(new CreateWindowsInfo2[] { windowInfo });
|
|
|
try{
|
|
|
CheckPartialError(resp.ServiceData);
|
|
|
}catch(Exception e) {
|
|
|
KUtil.Log("创建BOMWindow包含异常:" + e.Message);
|
|
|
}
|
|
|
int bomWindowCnt = KUtil.GetLen(resp.Output);
|
|
|
KUtil.Log("创建BOMWindow完成:"+bomWindowCnt);
|
|
|
if (bomWindowCnt==0) {
|
|
|
throw new Exception("读取BOM异常");
|
|
|
}
|
|
|
BOMWindow window = (BOMWindow)resp.Output[0].BomWindow;
|
|
|
BOMLine topLine = (BOMLine)resp.Output[0].BomLine;
|
|
|
List<Dictionary<string, string>> bomDatas = new List<Dictionary<string, string>>();
|
|
|
try {
|
|
|
GetProperties(topLine, "bl_child_lines");
|
|
|
ModelObject[] cLines = topLine.Bl_child_lines;
|
|
|
int lineCnt = KUtil.GetLen(cLines);
|
|
|
KUtil.Log("子行数量:" + lineCnt);
|
|
|
for (int i = 0; i < lineCnt; i++) {
|
|
|
SetProgress("加载BOM行 ( " + (i + 1) + " / " + lineCnt + " )");
|
|
|
BOMLine cLine = (BOMLine)cLines[i];
|
|
|
Dictionary<string, string> propMap = ReadProperties(cLine, bomConfig);
|
|
|
if (propMap != null && propMap.Count > 0) {
|
|
|
bomDatas.Add(propMap);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
finally {
|
|
|
try {
|
|
|
CloseBOMWindowsResponse closeResp = StructureManagementService.CloseBOMWindows(new BOMWindow[] { window });
|
|
|
CheckPartialError(closeResp.ServiceData);
|
|
|
}
|
|
|
catch (Exception e) {
|
|
|
KUtil.Log("关闭BOM失败: "+e.Message);
|
|
|
}
|
|
|
}
|
|
|
return bomDatas;
|
|
|
}
|
|
|
|
|
|
public RevisionRule GetRevisionRule(string ruleName) {
|
|
|
if (string.IsNullOrWhiteSpace(ruleName)) {
|
|
|
return null;
|
|
|
}
|
|
|
GetRevisionRulesResponse resp = StructureManagementService.GetRevisionRules();
|
|
|
CheckPartialError(resp.ServiceData);
|
|
|
int len = KUtil.GetLen(resp.Output);
|
|
|
for(int i = 0; i < len; i++) {
|
|
|
RevisionRule rule = (RevisionRule)resp.Output[i].RevRule;
|
|
|
DataManagementService.GetProperties(new ModelObject[] { rule }, new string[] { "object_name"});
|
|
|
if (ruleName.Equals(rule.Object_name)) {
|
|
|
return rule;
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public Boolean CreateOrUpdateItem(TCData data) {
|
|
|
if (data == null) {
|
|
|
return false;
|
|
|
}
|
|
|
string itemTypeName = data.ItemTypeName;
|
|
|
// test
|
|
|
// KUtil.Put(data.ItemProps, "item_id", "");
|
|
|
string itemId = KUtil.GetCADValue(data.ItemProps, "item_id");
|
|
|
string revId = KUtil.GetCADValue(data.RevProps, "item_revision_id");
|
|
|
string name = KUtil.GetCADValue(data.ItemProps, "object_name");
|
|
|
if (string.IsNullOrWhiteSpace(name)) {
|
|
|
name = KUtil.GetCADValue(data.RevProps, "object_name");
|
|
|
}
|
|
|
KUtil.Log(string.Format("新建或更新对象:类型[{0}] ID[{1}] 版本[{2}] 名称[{3}]", itemTypeName, itemId, revId, name));
|
|
|
SetProgress("查询对象 " + itemId);
|
|
|
ItemRevision rev = null;
|
|
|
if (!string.IsNullOrWhiteSpace(itemId)) {
|
|
|
string revTypeName = GetRevTypeName(itemTypeName);
|
|
|
if (string.IsNullOrWhiteSpace(revId)) {
|
|
|
rev = QueryLatestRevision(itemId, revTypeName);
|
|
|
}
|
|
|
else {
|
|
|
rev = QueryItemRevsion(itemId, revId, revTypeName);
|
|
|
}
|
|
|
if (rev != null) {
|
|
|
GetProperties(rev, "object_string");
|
|
|
KUtil.Log("找到已存在的版本:" + rev.Object_string);
|
|
|
}
|
|
|
else if (!string.IsNullOrWhiteSpace(revId)) {
|
|
|
// 升版
|
|
|
ItemRevision existRev = QueryLatestRevision(itemId, revTypeName);
|
|
|
if (existRev != null) {
|
|
|
ReleaseStatus[] RS = existRev.Release_status_list;
|
|
|
KUtil.Log("发布状态个数:" + RS.Length);
|
|
|
if (RS.Length > 0)
|
|
|
{
|
|
|
GetProperties(rev, "items_tag");
|
|
|
Item item = existRev.Items_tag;
|
|
|
if(CheckCanWrite(item))
|
|
|
{
|
|
|
GetProperties(existRev, "object_string", "object_name");
|
|
|
SetProgress("修订 " + existRev.Object_string);
|
|
|
KUtil.Log("找到已存在的对象,开始修订:" + existRev.Object_string);
|
|
|
GetProperties(existRev, "object_string");
|
|
|
KUtil.Log("基于版本:" + existRev.Object_string);
|
|
|
ReviseInfo reviseInfo = new ReviseInfo();
|
|
|
reviseInfo.ClientId = "KRevise";
|
|
|
reviseInfo.BaseItemRevision = existRev;
|
|
|
reviseInfo.NewRevId = revId;
|
|
|
reviseInfo.Name = existRev.Object_name;
|
|
|
reviseInfo.DeepCopyInfo = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.DeepCopyData[0];
|
|
|
reviseInfo.NewItemRevisionMasterProperties = new MasterFormPropertiesInfo();
|
|
|
ReviseResponse2 reviseResp = DataManagementService.Revise2(new ReviseInfo[] { reviseInfo });
|
|
|
CheckPartialError(reviseResp.ServiceData);
|
|
|
Teamcenter.Services.Strong.Core._2008_06.DataManagement.ReviseOutput reviseOutput = (ReviseOutput)reviseResp.ReviseOutputMap[reviseInfo.ClientId];
|
|
|
rev = reviseOutput.NewItemRev;
|
|
|
if (rev == null)
|
|
|
{
|
|
|
throw new Exception("修订对象异常:" + existRev.Object_string);
|
|
|
}
|
|
|
GetProperties(rev, "object_string");
|
|
|
KUtil.Log("修订完成:" + rev.Object_string);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
//如果没发布就改版本号
|
|
|
rev = existRev;
|
|
|
data.Rev = rev;
|
|
|
if (CheckCanWrite(existRev))
|
|
|
{
|
|
|
SetProperties(existRev, data.RevProps);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (rev == null) {
|
|
|
SetProgress("新建对象 " + itemId);
|
|
|
rev = CreateItem(data);
|
|
|
}
|
|
|
else {
|
|
|
SetProgress("更新属性 " + rev.Object_string);
|
|
|
//更新属性
|
|
|
data.Rev = rev;
|
|
|
if (CheckCanWrite(rev))
|
|
|
{
|
|
|
UpdateProperties(data);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
data.Rev = rev;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public ItemRevision CreateItem(TCData data) {
|
|
|
ItemRevision rev = null;
|
|
|
string itemId = data.Item_id;
|
|
|
string itemTypeName = data.ItemTypeName;
|
|
|
KUtil.Log("开始新建对象");
|
|
|
KUtil.Log("对象属性:" + KUtil.PrintDictionary(data.ItemProps));
|
|
|
KUtil.Log("对象主属性表单属性:" + KUtil.PrintDictionary(data.ItemMasterProps));
|
|
|
KUtil.Log("版本属性:" + KUtil.PrintDictionary(data.RevProps));
|
|
|
KUtil.Log("版本主属性表单属性:" + KUtil.PrintDictionary(data.RevMasterProps));
|
|
|
//加载类型名
|
|
|
if (!CheckTypeName(itemTypeName)) {
|
|
|
throw new Exception("未定义对象类型:" + itemTypeName);
|
|
|
}
|
|
|
string revTypeName = itemTypeName + "Revision";
|
|
|
if (!CheckTypeName(revTypeName)) {
|
|
|
revTypeName = itemTypeName + " Revision";
|
|
|
if (!CheckTypeName(revTypeName)) {
|
|
|
throw new Exception("获取版本类型名称异常:" + itemTypeName);
|
|
|
}
|
|
|
}
|
|
|
string itemMasterTypeName = itemTypeName+ " Master";
|
|
|
if (!CheckTypeName(itemMasterTypeName)) {
|
|
|
itemMasterTypeName = itemTypeName + "Master";
|
|
|
if (!CheckTypeName(itemMasterTypeName)) {
|
|
|
throw new Exception("获取对象主属性表单类型名称异常:" + itemTypeName);
|
|
|
}
|
|
|
}
|
|
|
string revMasterTypeName = revTypeName + " Master";
|
|
|
if (!CheckTypeName(revMasterTypeName)) {
|
|
|
revMasterTypeName = revTypeName + "Master";
|
|
|
if (!CheckTypeName(revMasterTypeName)) {
|
|
|
throw new Exception("获取版本主属性表单类型名称异常:" + itemTypeName);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!(data.RevProps.ContainsKey("item_revision_id")))
|
|
|
{
|
|
|
CADAttr propValue = new CADAttr("版本", "S01", true);
|
|
|
KUtil.Put(data.RevProps, "item_revision_id", propValue);
|
|
|
}
|
|
|
// 新建对象
|
|
|
Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput itemInput = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput();
|
|
|
Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput revInput = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput();
|
|
|
Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput itemMasterInput = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput();
|
|
|
Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput revMasterInput = new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput();
|
|
|
itemInput.BoName = itemTypeName;
|
|
|
revInput.BoName = revTypeName;
|
|
|
itemMasterInput.BoName = itemMasterTypeName;
|
|
|
revMasterInput.BoName = revMasterTypeName;
|
|
|
itemInput.StringProps = GetStringPropHashTable(data.ItemProps);
|
|
|
revInput.StringProps = GetStringPropHashTable(data.RevProps);
|
|
|
itemMasterInput.StringProps = GetStringPropHashTable(data.ItemMasterProps);
|
|
|
revMasterInput.StringProps = GetStringPropHashTable(data.RevMasterProps);
|
|
|
itemInput.CompoundCreateInput = new System.Collections.Hashtable();
|
|
|
itemInput.CompoundCreateInput.Add("revision", new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput[] { revInput });
|
|
|
itemInput.CompoundCreateInput.Add("IMAN_master_form", new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput[] { itemMasterInput });
|
|
|
revInput.CompoundCreateInput = new System.Collections.Hashtable();
|
|
|
revInput.CompoundCreateInput.Add("IMAN_master_form_rev", new Teamcenter.Services.Strong.Core._2008_06.DataManagement.CreateInput[] { revMasterInput });
|
|
|
CreateIn ci = new CreateIn();
|
|
|
ci.Data = itemInput;
|
|
|
CreateResponse resp = DataManagementService.CreateObjects(new CreateIn[] { ci });
|
|
|
CheckPartialError(resp.ServiceData);
|
|
|
Item item = null;
|
|
|
for (int i = 0; i < resp.ServiceData.sizeOfCreatedObjects(); i++) {
|
|
|
ModelObject mo = resp.ServiceData.GetCreatedObject(i);
|
|
|
if (mo is ItemRevision) {
|
|
|
rev = (ItemRevision)mo;
|
|
|
}else if(mo is Item) {
|
|
|
item = (Item)mo;
|
|
|
}
|
|
|
}
|
|
|
if (rev == null) {
|
|
|
throw new Exception("新建对象异常");
|
|
|
}
|
|
|
AddToNewStuff(item);
|
|
|
GetProperties(rev, "object_string");
|
|
|
KUtil.Log("新建完成:" + rev.Object_string);
|
|
|
return rev;
|
|
|
}
|
|
|
|
|
|
public void AddToNewStuff(ModelObject obj) {
|
|
|
if (obj==null) {
|
|
|
return;
|
|
|
}
|
|
|
User user = SessionService.GetTCSessionInfo().User;
|
|
|
Folder folder;
|
|
|
if (SelectedFolder == null) {
|
|
|
GetProperties(user, "newstuff_folder");
|
|
|
folder = user.Newstuff_folder;
|
|
|
KUtil.Log("发送对象到 Newstuff");
|
|
|
}
|
|
|
else {
|
|
|
folder = SelectedFolder;
|
|
|
KUtil.Log("发生对象到当前选择文件夹");
|
|
|
}
|
|
|
DataManagementService.RefreshObjects(new ModelObject[] { folder });
|
|
|
Relationship rel = new Relationship();
|
|
|
rel.ClientId = "";
|
|
|
rel.PrimaryObject = folder;
|
|
|
rel.SecondaryObject = obj;
|
|
|
rel.RelationType = "contents";
|
|
|
rel.UserData = null;
|
|
|
CreateRelationsResponse resp = DataManagementService.CreateRelations(new Relationship[] { rel });
|
|
|
CheckPartialError(resp.ServiceData);
|
|
|
DataManagementService.RefreshObjects(new ModelObject[] { folder });
|
|
|
if (SelectedFolder != null) {
|
|
|
SocketUtil.SendRequest("REFRESH", SelectedFolder.Uid);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Dataset FindDatasetByName(ItemRevision rev, string relName, string dsName, string datasetType) {
|
|
|
if (rev == null || string.IsNullOrWhiteSpace(datasetType)) {
|
|
|
return null;
|
|
|
}
|
|
|
ExpandGRMRelationsPref pref = new ExpandGRMRelationsPref();
|
|
|
RelationAndTypesFilter2 filter = new RelationAndTypesFilter2();
|
|
|
filter.RelationName = relName;
|
|
|
filter.ObjectTypeNames = new string[] { datasetType };
|
|
|
pref.ExpItemRev = false;
|
|
|
pref.Info = new RelationAndTypesFilter2[] { filter };
|
|
|
ExpandGRMRelationsResponse resp = DataManagementService.ExpandGRMRelationsForPrimary(new ModelObject[] { rev }, pref);
|
|
|
CheckPartialError(resp.ServiceData);
|
|
|
int outputLen = KUtil.GetLen(resp.Output);
|
|
|
for (int k = 0; k < outputLen; k++) {
|
|
|
ExpandGRMRelationsOutput grmOutput2 = resp.Output[k];
|
|
|
int grmLen = KUtil.GetLen(grmOutput2.OtherSideObjData);
|
|
|
for (int l = 0; l < grmLen; l++) {
|
|
|
ExpandGRMRelationsData otherSideData = grmOutput2.OtherSideObjData[l];
|
|
|
if (otherSideData.OtherSideObjects.Length > 0) {
|
|
|
for (int m = 0; m < otherSideData.OtherSideObjects.Length; m++) {
|
|
|
Dataset dataset = otherSideData.OtherSideObjects[m] as Dataset;
|
|
|
if (dataset == null) {
|
|
|
continue;
|
|
|
}
|
|
|
GetProperties(dataset, "object_name");
|
|
|
if (dataset.Object_name.Equals(dsName)) {
|
|
|
return dataset;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public Dataset CreateDataset(ItemRevision rev, string relName, string dsName, string datasetType) {
|
|
|
DatasetProperties2 datasetProp = new DatasetProperties2();
|
|
|
datasetProp.ClientId = "KCreateDataset";
|
|
|
datasetProp.Type = datasetType;
|
|
|
datasetProp.Name = dsName;
|
|
|
datasetProp.Description = "";
|
|
|
datasetProp.Container = null;
|
|
|
CreateDatasetsResponse
|
|
|
dsResp = DataManagementService.CreateDatasets2(new DatasetProperties2[] { datasetProp });
|
|
|
CheckPartialError(dsResp.ServiceData);
|
|
|
if (dsResp.Output.Length == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
Dataset dataset = dsResp.Output[0].Dataset;
|
|
|
if (rev == null) {
|
|
|
return dataset;
|
|
|
}
|
|
|
Relationship[] rela_vec = new Relationship[1];
|
|
|
Relationship one_rela = new Relationship();
|
|
|
one_rela.ClientId = "";
|
|
|
one_rela.PrimaryObject = rev;
|
|
|
one_rela.SecondaryObject = dataset;
|
|
|
one_rela.RelationType = relName;
|
|
|
one_rela.UserData = null;
|
|
|
rela_vec[0] = one_rela;
|
|
|
CreateRelationsResponse reResp = DataManagementService.CreateRelations(rela_vec);
|
|
|
CheckPartialError(reResp.ServiceData);
|
|
|
return dataset;
|
|
|
}
|
|
|
|
|
|
public void UploadFileRef(Dataset dataset, string filePath, string refName, string fmsUrl = null) {
|
|
|
if (dataset == null) {
|
|
|
return;
|
|
|
}
|
|
|
GetProperties(dataset, "checked_out", "ref_list");
|
|
|
//if (dataset.Checked_out == "Y") {
|
|
|
//CheckIn(new ModelObject[] { dataset });
|
|
|
//}
|
|
|
Teamcenter.Services.Loose.Core._2006_03.FileManagement.DatasetFileInfo[] fileInfos = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.DatasetFileInfo[1];
|
|
|
Teamcenter.Services.Loose.Core._2006_03.FileManagement.DatasetFileInfo fileInfo = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.DatasetFileInfo();
|
|
|
fileInfo.FileName = filePath;
|
|
|
fileInfo.AllowReplace = true;
|
|
|
fileInfo.IsText = false;
|
|
|
fileInfo.NamedReferencedName = refName;
|
|
|
fileInfos[0] = fileInfo;
|
|
|
Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData inputData = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData();
|
|
|
inputData.Dataset = dataset;
|
|
|
inputData.CreateNewVersion = false;
|
|
|
inputData.DatasetFileInfos = fileInfos;
|
|
|
ModelObject[] datasets = new ModelObject[1];
|
|
|
datasets[0] = dataset;
|
|
|
// Teamcenter.Services.Strong.Core._2006_03.Reservation.Reservation res = ReservationService.getService(Session.getConnection());
|
|
|
ModelObject[] oldRefs = dataset.Ref_list;
|
|
|
int refCnt = oldRefs == null ? 0 : oldRefs.Length;
|
|
|
if (refCnt > 0) {
|
|
|
Teamcenter.Services.Strong.Core._2007_09.DataManagement.RemoveNamedReferenceFromDatasetInfo[] removeInfo = new Teamcenter.Services.Strong.Core._2007_09.DataManagement.RemoveNamedReferenceFromDatasetInfo[1];
|
|
|
removeInfo[0] = new Teamcenter.Services.Strong.Core._2007_09.DataManagement.RemoveNamedReferenceFromDatasetInfo();
|
|
|
removeInfo[0].Dataset = dataset;
|
|
|
Teamcenter.Services.Strong.Core._2007_09.DataManagement.NamedReferenceInfo[] nrInfo = new Teamcenter.Services.Strong.Core._2007_09.DataManagement.NamedReferenceInfo[refCnt];
|
|
|
for (int i = 0; i < refCnt; i++) {
|
|
|
nrInfo[i] = new Teamcenter.Services.Strong.Core._2007_09.DataManagement.NamedReferenceInfo();
|
|
|
nrInfo[i].DeleteTarget = true;
|
|
|
nrInfo[i].TargetObject = oldRefs[i];
|
|
|
nrInfo[i].Type = refName;
|
|
|
}
|
|
|
removeInfo[0].NrInfo = nrInfo;
|
|
|
ServiceData removeResp = DataManagementService.RemoveNamedReferenceFromDataset(removeInfo);
|
|
|
CheckPartialError(removeResp);
|
|
|
}
|
|
|
Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData[] inputs = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData[1];
|
|
|
inputs[0] = inputData;
|
|
|
FileManagementUtility fMSFileManagement = string.IsNullOrEmpty(fmsUrl) ? new FileManagementUtility(Session.getConnection()) : new FileManagementUtility(Session.getConnection(), null, null, new string[] { fmsUrl}, System.IO.Path.GetTempPath());
|
|
|
ServiceData response = fMSFileManagement.PutFiles(inputs);
|
|
|
CheckPartialError(response);
|
|
|
}
|
|
|
|
|
|
|
|
|
public void UploadFile(TCData data, string relation, string dsType, string dsRef, string dsName, List<string> tempFiles, string fmsUrl = null)
|
|
|
{
|
|
|
if (data == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
string oldPath = data.DocFileName;
|
|
|
KUtil.Log("oldPath:" + oldPath);
|
|
|
string itemId = data.Item_id;
|
|
|
GetProperties(data.Rev, "object_name");
|
|
|
GetProperties(data.Rev, "item_revision_id");
|
|
|
string fileName = itemId + "-" + data.Rev.Item_revision_id + "-" + data.Rev.Object_name;
|
|
|
|
|
|
/*
|
|
|
BackgroundWorker.pbDialog.Dispatcher.Invoke(new Action(delegate
|
|
|
{
|
|
|
if (KCADUtil.CheckOpendDoc(data))
|
|
|
{
|
|
|
tempFiles.Add(data.DocFileName);
|
|
|
}
|
|
|
}));*/
|
|
|
tempFiles.Add(oldPath);
|
|
|
|
|
|
ItemRevision rev = data.Rev;
|
|
|
if (rev == null)
|
|
|
{
|
|
|
throw new Exception("上传文件失败,获取顶层对象版本异常");
|
|
|
}
|
|
|
string docPath = data.DocFileName;
|
|
|
if (!System.IO.File.Exists(docPath))
|
|
|
{
|
|
|
throw new Exception("上传文件失败,文件不存在:" + docPath);
|
|
|
}
|
|
|
GetProperties(rev, "object_string");
|
|
|
if (dsName.Contains("/"))
|
|
|
{
|
|
|
dsName = dsName.Replace("/", "");
|
|
|
}
|
|
|
if (fileName.Contains("/"))
|
|
|
{
|
|
|
fileName = fileName.Replace("/", "");
|
|
|
}
|
|
|
KUtil.Log("上传文件:" + rev.Object_string + " -> " + docPath);
|
|
|
if (docPath.ToLower().EndsWith(".dwg"))
|
|
|
{
|
|
|
FileInfo f = new FileInfo(docPath);
|
|
|
//if (!f.Name.ToLower().Equals(fileName.ToLower() + ".dwg"))
|
|
|
// {
|
|
|
//string newPath = f.Directory.FullName + "\\" + fileName + ".dwg";
|
|
|
string newPath = System.IO.Path.GetTempPath() + "\\" + fileName + ".dwg";
|
|
|
KUtil.Log(">> 另存文件进行上传:" + newPath);
|
|
|
System.IO.File.Copy(docPath, newPath, true);
|
|
|
if (new FileInfo(newPath).Exists)
|
|
|
{
|
|
|
docPath = newPath;
|
|
|
tempFiles.Add(docPath);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
KUtil.Log("另存失败");
|
|
|
}
|
|
|
// }
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
SetProgress("查询数据集");
|
|
|
Dataset dataset = FindDatasetByName(rev, relation, dsName, dsType);
|
|
|
if (dataset == null)
|
|
|
{
|
|
|
SetProgress("新建数据集");
|
|
|
KUtil.Log("开始新建数据集");
|
|
|
dataset = CreateDataset(rev, relation, dsName, dsType);
|
|
|
if (dataset == null)
|
|
|
{
|
|
|
throw new Exception("上传文件失败,新建数据集异常");
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
KUtil.Log("更新已有数据集");
|
|
|
}
|
|
|
SetProgress("上传文件");
|
|
|
UploadFileRef(dataset, docPath, dsRef, fmsUrl);
|
|
|
KUtil.Log("上传文件完成");
|
|
|
data.DocFileName = oldPath;
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
KUtil.LogErr(e);
|
|
|
throw new Exception("上传图纸失败:" + docPath);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void CreateOrUpdateBom(TCData topData, bool isPack) {
|
|
|
if (topData == null) {
|
|
|
return;
|
|
|
}
|
|
|
List<TCData> bomlineDatas = topData.BomLineDatas;
|
|
|
int lineCnt = bomlineDatas == null ? 0 : bomlineDatas.Count;
|
|
|
if (lineCnt == 0) {
|
|
|
KUtil.Log("无BOM数据,取消更新BOM");
|
|
|
return;
|
|
|
}
|
|
|
KUtil.Log("开始更新BOM,BOM行数量:" + lineCnt);
|
|
|
ItemRevision topRev = topData.Rev;
|
|
|
if (!CheckCanWrite(topRev))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
if (topRev == null) {
|
|
|
throw new Exception("获取顶层对象版本异常");
|
|
|
}
|
|
|
GetProperties(topRev, "object_string", "structure_revisions");
|
|
|
KUtil.Log("顶层:" + topRev.Object_string);
|
|
|
ModelObject[] bvrs = topRev.Structure_revisions;
|
|
|
int bvrCnt = KUtil.GetLen(bvrs);
|
|
|
KUtil.Log("Find Structure Revisions: " + bvrCnt);
|
|
|
CheckOut(bvrs);
|
|
|
try {
|
|
|
CreateOrUpdateRelativeStructureInfo2
|
|
|
structInfo = new CreateOrUpdateRelativeStructureInfo2();
|
|
|
CreateOrUpdateRelativeStructureInfo2[]
|
|
|
structInfoVec = new CreateOrUpdateRelativeStructureInfo2[1];
|
|
|
List<RelativeStructureChildInfo> childInfoVec = new List<RelativeStructureChildInfo>();
|
|
|
CreateOrUpdateRelativeStructurePref2
|
|
|
sPref = new CreateOrUpdateRelativeStructurePref2() {
|
|
|
CadOccIdAttrName = null,
|
|
|
ItemTypes = new string[] { },
|
|
|
OverwriteForLastModDate = true
|
|
|
};
|
|
|
int seq = 1;
|
|
|
|
|
|
for (int i = 0; i < lineCnt; i++) {
|
|
|
SetProgress(string.Format("准备行数据 ( {0} / {1} )", i + 1, lineCnt));
|
|
|
TCData bomlineData = bomlineDatas[i];
|
|
|
if (bomlineData.Rev == null) {
|
|
|
string lineId = KUtil.GetCADValue(bomlineData.ItemProps, "item_id");
|
|
|
string revTypeName = GetRevTypeName(bomlineData.ItemTypeName);
|
|
|
bomlineData.Rev = QueryLatestRevision(lineId, revTypeName);
|
|
|
if (bomlineData.Rev == null) { // 批量保存检查时会存在bom行对象未创建的情况,需要重新查询
|
|
|
// throw new Exception("获取BOM行版本异常: "+lineId);
|
|
|
bomlineData.Rev = CreateItem(bomlineData);
|
|
|
}
|
|
|
}
|
|
|
GetProperties(bomlineData.Rev, "object_string");
|
|
|
KUtil.Log((i + 1) + ". " + bomlineData.Rev.Object_string + ": " + KUtil.PrintDictionary(bomlineData.BomProps));
|
|
|
//UpdateProperties(bomlineData);
|
|
|
RelativeStructureChildInfo childInfo = new RelativeStructureChildInfo();
|
|
|
RelOccInfo occInfo = new RelOccInfo();
|
|
|
Dictionary<string, AttributesInfo> attrsToSet = new Dictionary<string, AttributesInfo>();
|
|
|
int packCnt = 1;
|
|
|
foreach (string propName in bomlineData.BomProps.Keys) {
|
|
|
string propValue = KUtil.GetCADValue(bomlineData.BomProps, propName);
|
|
|
if (isPack && "bl_quantity".Equals(propName) && !string.IsNullOrWhiteSpace(propValue)) {
|
|
|
int num = -1;
|
|
|
int.TryParse(propValue, out num);
|
|
|
if (num > 0) {
|
|
|
packCnt = num;
|
|
|
propValue = "1";
|
|
|
}
|
|
|
}
|
|
|
AttributesInfo attrsInfo = new AttributesInfo();
|
|
|
attrsInfo.Name = propName;
|
|
|
attrsInfo.Value = propValue;
|
|
|
attrsToSet.Add(propName, attrsInfo);
|
|
|
}
|
|
|
if (!bomlineData.BomProps.ContainsKey("bl_sequence_no")) {
|
|
|
AttributesInfo seqNo = new AttributesInfo();
|
|
|
seqNo.Name = "bl_sequence_no";
|
|
|
seqNo.Value = seq * 10 + "";
|
|
|
seq++;
|
|
|
attrsToSet.Add("bl_sequence_no", seqNo);
|
|
|
}
|
|
|
occInfo.AttrsToSet = attrsToSet.Values.ToArray();
|
|
|
childInfo.Child = bomlineData.Rev;
|
|
|
childInfo.OccInfo = occInfo;
|
|
|
for (int x = 0; x < packCnt; x++) {
|
|
|
childInfoVec.Add(childInfo);
|
|
|
}
|
|
|
}
|
|
|
structInfo.ChildInfo = childInfoVec.ToArray();
|
|
|
//structInfo.LastModifiedOfBVR = DateTime.Now;
|
|
|
structInfo.Parent = topRev;
|
|
|
structInfo.Precise = false;
|
|
|
structInfoVec[0] = structInfo;
|
|
|
SetProgress("创建BOM");
|
|
|
|
|
|
CreateOrUpdateRelativeStructureResponse bomResp = StructureManagementService.CreateOrUpdateRelativeStructure(structInfoVec, "view", true, sPref);
|
|
|
|
|
|
CheckPartialError(bomResp.ServiceData);
|
|
|
|
|
|
}
|
|
|
finally {
|
|
|
CheckIn(bvrs);
|
|
|
}
|
|
|
|
|
|
KUtil.Log("更新BOM完成");
|
|
|
}
|
|
|
|
|
|
public void UpdateProperties(TCData data) {
|
|
|
if (data == null || !data.NonBomPropertiesModified) {
|
|
|
return;
|
|
|
}
|
|
|
ItemRevision rev = data.Rev;
|
|
|
GetProperties(rev, "items_tag", "object_string", "IMAN_master_form_rev");
|
|
|
KUtil.Log("开始更新属性: " + rev.Object_string);
|
|
|
Item item = rev.Items_tag;
|
|
|
if (item == null) {
|
|
|
throw new Exception("获取版本对应的Item失败:" + rev.Object_string);
|
|
|
}
|
|
|
GetProperties(item, "IMAN_master_form", "object_string", "object_type");
|
|
|
// 校验类型
|
|
|
if (!string.IsNullOrWhiteSpace(data.ItemTypeName)) {
|
|
|
if (!data.ItemTypeName.Equals(item.Object_type)) {
|
|
|
KUtil.Log(">> 类型校验失败,取消同步属性:"+data.ItemTypeName+" -> "+item.Object_type);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
//KUtil.Log("不更新对象id和版本号" );
|
|
|
|
|
|
if (data.ItemProps.Count > 0)
|
|
|
{
|
|
|
KUtil.Log("更新对象属性:" + KUtil.PrintDictionary(data.ItemProps));
|
|
|
SetProperties(item, data.ItemProps,"item_id");
|
|
|
}
|
|
|
if (data.RevProps.Count > 0)
|
|
|
{
|
|
|
KUtil.Log("更新版本属性:" + KUtil.PrintDictionary(data.RevProps));
|
|
|
SetProperties(rev, data.RevProps,"item_revision_id");
|
|
|
}
|
|
|
if (data.ItemMasterProps.Count > 0) {
|
|
|
KUtil.Log("更新对象主属性表单属性:" + KUtil.PrintDictionary(data.ItemMasterProps));
|
|
|
ModelObject[] itemMaster = item.IMAN_master_form;
|
|
|
if (itemMaster == null || itemMaster.Length == 0) {
|
|
|
throw new Exception("获取对象的主属性表单失败:" + item.Object_string);
|
|
|
}
|
|
|
SetProperties(itemMaster[0], data.ItemMasterProps);
|
|
|
}
|
|
|
if (data.RevMasterProps.Count > 0) {
|
|
|
KUtil.Log("更新版本主属性表单属性:" + KUtil.PrintDictionary(data.RevMasterProps));
|
|
|
ModelObject[] revMaster = rev.IMAN_master_form_rev;
|
|
|
if (revMaster == null || revMaster.Length == 0) {
|
|
|
throw new Exception("获取版本的主属性表单失败:" + rev.Object_string);
|
|
|
}
|
|
|
SetProperties(revMaster[0], data.RevMasterProps);
|
|
|
}
|
|
|
KUtil.Log("更新属性完成");
|
|
|
}
|
|
|
|
|
|
public Dictionary<string, string> ReadProperties(BOMLine bomLine, TCData data) {
|
|
|
if (bomLine == null||data==null) {
|
|
|
return null;
|
|
|
}
|
|
|
GetProperties(bomLine, "bl_item", "bl_revision", "object_string");
|
|
|
KUtil.Log("读取属性: " + bomLine.Object_string);
|
|
|
ItemRevision rev = (ItemRevision)bomLine.Bl_revision;
|
|
|
Item item = (Item)bomLine.Bl_item;
|
|
|
if (item == null) {
|
|
|
throw new Exception("获取BOMLine对应的Item失败:" + bomLine.Object_string);
|
|
|
}
|
|
|
if (rev == null) {
|
|
|
throw new Exception("获取BOMLine对应的Revision失败:" + bomLine.Object_string);
|
|
|
}
|
|
|
Dictionary<string, string> cadProps = new Dictionary<string, string>();
|
|
|
if (data.BomProps.Count > 0) {
|
|
|
Dictionary<string, string> defaultValueMap = new Dictionary<string, string>();
|
|
|
defaultValueMap.Add("bl_quantity", "1");
|
|
|
ReadProperties(bomLine, data.BomProps, cadProps, defaultValueMap);
|
|
|
}
|
|
|
if (data.ItemProps.Count > 0) {
|
|
|
ReadProperties(item, data.ItemProps, cadProps);
|
|
|
}
|
|
|
if (data.RevProps.Count > 0) {
|
|
|
ReadProperties(rev, data.RevProps, cadProps);
|
|
|
}
|
|
|
if (data.ItemMasterProps.Count > 0) {
|
|
|
GetProperties(item, "IMAN_master_form", "object_string");
|
|
|
ModelObject[] itemMaster = item.IMAN_master_form;
|
|
|
if (itemMaster == null || itemMaster.Length == 0) {
|
|
|
throw new Exception("获取对象的主属性表单失败:" + item.Object_string);
|
|
|
}
|
|
|
ReadProperties(itemMaster[0], data.ItemMasterProps, cadProps);
|
|
|
}
|
|
|
if (data.RevMasterProps.Count > 0) {
|
|
|
GetProperties(rev, "object_string", "IMAN_master_form_rev");
|
|
|
ModelObject[] revMaster = rev.IMAN_master_form_rev;
|
|
|
if (revMaster == null || revMaster.Length == 0) {
|
|
|
throw new Exception("获取版本的主属性表单失败:" + rev.Object_string);
|
|
|
}
|
|
|
ReadProperties(revMaster[0], data.RevMasterProps, cadProps);
|
|
|
}
|
|
|
KUtil.Log(KUtil.PrintDictionary(cadProps));
|
|
|
return cadProps;
|
|
|
}
|
|
|
|
|
|
public Dictionary<string, string> ReadProperties(TCData data) {
|
|
|
if (data == null || data.Rev == null) {
|
|
|
return null;
|
|
|
}
|
|
|
ItemRevision rev = data.Rev;
|
|
|
GetProperties(rev, "items_tag", "object_string", "IMAN_master_form_rev");
|
|
|
KUtil.Log("开始读取属性: " + rev.Object_string);
|
|
|
Item item = rev.Items_tag;
|
|
|
GetProperties(item, "IMAN_master_form", "object_string");
|
|
|
if (item == null) {
|
|
|
throw new Exception("获取版本对应的Item失败:" + rev.Object_string);
|
|
|
}
|
|
|
Dictionary<string, string> cadProps = new Dictionary<string, string>();
|
|
|
if (data.ItemProps.Count > 0) {
|
|
|
ReadProperties(item, data.ItemProps, cadProps);
|
|
|
}
|
|
|
if (data.RevProps.Count > 0) {
|
|
|
ReadProperties(rev, data.RevProps, cadProps);
|
|
|
}
|
|
|
if (data.ItemMasterProps.Count > 0) {
|
|
|
ModelObject[] itemMaster = item.IMAN_master_form;
|
|
|
if (itemMaster == null || itemMaster.Length == 0) {
|
|
|
throw new Exception("获取对象的主属性表单失败:" + item.Object_string);
|
|
|
}
|
|
|
ReadProperties(itemMaster[0], data.ItemMasterProps, cadProps);
|
|
|
}
|
|
|
if (data.RevMasterProps.Count > 0) {
|
|
|
ModelObject[] revMaster = rev.IMAN_master_form_rev;
|
|
|
if (revMaster == null || revMaster.Length == 0) {
|
|
|
throw new Exception("获取版本的主属性表单失败:" + rev.Object_string);
|
|
|
}
|
|
|
ReadProperties(revMaster[0], data.RevMasterProps, cadProps);
|
|
|
}
|
|
|
KUtil.Log(KUtil.PrintDictionary(cadProps));
|
|
|
return cadProps;
|
|
|
}
|
|
|
|
|
|
public List<string> ComparePropertiesInTC(TCData data) {
|
|
|
if (data == null) {
|
|
|
return null;
|
|
|
}
|
|
|
string itemId = KUtil.GetCADValue(data.ItemProps, "item_id");
|
|
|
string name = KUtil.GetCADValue(data.ItemProps, "object_name");
|
|
|
if (string.IsNullOrWhiteSpace(name)) {
|
|
|
name = KUtil.GetCADValue(data.RevProps, "object_name");
|
|
|
}
|
|
|
if (string.IsNullOrWhiteSpace(itemId)) {
|
|
|
return null;
|
|
|
}
|
|
|
string itemTypeName = data.ItemTypeName;
|
|
|
KUtil.Log(string.Format("检查属性是否需要更改:ID[{0}] 名称[{1}] 类型[{2}]", itemId, name, itemTypeName));
|
|
|
string revTypeName = GetRevTypeName(itemTypeName);
|
|
|
ItemRevision rev = QueryLatestRevision(itemId, revTypeName, true);
|
|
|
if (rev == null) {
|
|
|
throw new Exception("无法比较数据,查询最新版本异常:" + itemId);
|
|
|
}
|
|
|
data.Rev = rev;
|
|
|
GetProperties(rev, "object_string");
|
|
|
KUtil.Log("找到已存在的版本:" + rev.Object_string);
|
|
|
//更新属性
|
|
|
GetProperties(rev, "items_tag", "object_string", "IMAN_master_form_rev");
|
|
|
Item item = rev.Items_tag;
|
|
|
GetProperties(item, "IMAN_master_form", "object_string");
|
|
|
if (item == null) {
|
|
|
throw new Exception("获取版本对应的Item失败:" + rev.Object_string);
|
|
|
}
|
|
|
List<string> propNames = new List<string>();
|
|
|
if (data.ItemProps.Count > 0) {
|
|
|
CheckChangedProperties(item, data.ItemProps, propNames);
|
|
|
}
|
|
|
if (data.RevProps.Count > 0) {
|
|
|
CheckChangedProperties(rev, data.RevProps, propNames);
|
|
|
}
|
|
|
if (data.ItemMasterProps.Count > 0) {
|
|
|
ModelObject[] itemMaster = item.IMAN_master_form;
|
|
|
if (itemMaster == null || itemMaster.Length == 0) {
|
|
|
throw new Exception("获取对象的主属性表单失败:" + item.Object_string);
|
|
|
}
|
|
|
CheckChangedProperties(itemMaster[0], data.ItemMasterProps, propNames);
|
|
|
}
|
|
|
if (data.RevMasterProps.Count > 0) {
|
|
|
ModelObject[] revMaster = rev.IMAN_master_form_rev;
|
|
|
if (revMaster == null || revMaster.Length == 0) {
|
|
|
throw new Exception("获取版本的主属性表单失败:" + rev.Object_string);
|
|
|
}
|
|
|
CheckChangedProperties(revMaster[0], data.RevMasterProps, propNames);
|
|
|
}
|
|
|
data.NonBomPropertiesModified = propNames.Count > 0;
|
|
|
return propNames;
|
|
|
}
|
|
|
|
|
|
public void CheckChangedProperties(ModelObject mo, Dictionary<string, CADAttr> props, List<string> propNames) {
|
|
|
if (mo == null || props == null || props.Count == 0 || propNames == null) { return; }
|
|
|
GetProperties(mo, props.Keys.ToArray());
|
|
|
foreach (string propName in props.Keys) {
|
|
|
CADAttr cadAttr = KUtil.Get(props, propName);
|
|
|
if (cadAttr == null) { continue; }
|
|
|
string cadValue = cadAttr.Value;
|
|
|
string tcValue = cadAttr.UseRealValue ? mo.GetProperty(propName).StringValue : mo.GetPropertyDisplayableValue(propName);
|
|
|
bool changed = cadValue == null ? !string.IsNullOrEmpty(tcValue) : !cadValue.Equals(tcValue);
|
|
|
if (changed) {
|
|
|
string propDisName = mo.GetProperty(propName).PropertyDescription.UiName;
|
|
|
KUtil.Log(string.Format(">> [{0}({1})]:[{2}] -> [{3}]", propDisName, propName, cadValue, tcValue));
|
|
|
if (!propNames.Contains(propDisName)) {
|
|
|
propNames.Add(propDisName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void ReadProperties(ModelObject mo, Dictionary<string, CADAttr> props, Dictionary<string, string> cadPropMap, Dictionary<string, string> defaultValueMap = null) {
|
|
|
if (mo == null || props == null || props.Count == 0 || cadPropMap == null) { return; }
|
|
|
GetProperties(mo, props.Keys.ToArray());
|
|
|
foreach (string propName in props.Keys) {
|
|
|
CADAttr cadAttr = KUtil.Get(props, propName);
|
|
|
if (cadAttr == null) { continue; }
|
|
|
string cadName = cadAttr.Name;
|
|
|
string tcValue = cadAttr.UseRealValue ? mo.GetProperty(propName).StringValue : mo.GetPropertyDisplayableValue(propName);
|
|
|
if (string.IsNullOrWhiteSpace(tcValue) && defaultValueMap!=null && defaultValueMap.ContainsKey(propName)) {
|
|
|
tcValue = defaultValueMap[propName];
|
|
|
}
|
|
|
KUtil.Put(cadPropMap, cadName, tcValue);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetProperties(ModelObject mo, Dictionary<string, CADAttr> props, params string[] ignoreProps)
|
|
|
{
|
|
|
if (mo == null || props == null || props.Count == 0) { return; }
|
|
|
System.Collections.Hashtable tcProps = GetPropHashTable(props);
|
|
|
if (ignoreProps != null)
|
|
|
{
|
|
|
foreach (string propName in ignoreProps)
|
|
|
{
|
|
|
if (tcProps.ContainsKey(propName))
|
|
|
{
|
|
|
tcProps.Remove(propName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (tcProps.Count == 0)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
ServiceData sd = DataManagementService.SetProperties(new ModelObject[] { mo }, tcProps);
|
|
|
CheckPartialError(sd);
|
|
|
}
|
|
|
|
|
|
//public void SetProperties(ModelObject mo, Dictionary<string, CADAttr> props)
|
|
|
//{
|
|
|
// if (mo == null || props == null || props.Count == 0) { return; }
|
|
|
// System.Collections.Hashtable tcProps = GetPropHashTable(props);
|
|
|
|
|
|
// ServiceData sd = DataManagementService.SetProperties(new ModelObject[] { mo }, tcProps);
|
|
|
// CheckPartialError(sd);
|
|
|
//}
|
|
|
|
|
|
public void CheckOut(ModelObject[] modelObjects) {
|
|
|
if (KUtil.GetLen(modelObjects) == 0) {
|
|
|
return;
|
|
|
}
|
|
|
ServiceData sd = ReservationService.Checkout(modelObjects, "", "");
|
|
|
CheckPartialError(sd);
|
|
|
}
|
|
|
|
|
|
public void CheckIn(ModelObject[] modelObjects) {
|
|
|
if (KUtil.GetLen(modelObjects) == 0) {
|
|
|
return;
|
|
|
}
|
|
|
ServiceData sd = ReservationService.Checkin(modelObjects);
|
|
|
CheckPartialError(sd);
|
|
|
}
|
|
|
|
|
|
|
|
|
public static System.Collections.Hashtable GetPropHashTable(Dictionary<string, CADAttr> props) {
|
|
|
System.Collections.Hashtable tcProps = new System.Collections.Hashtable();
|
|
|
foreach (string key in props.Keys) {
|
|
|
string val = KUtil.GetCADValue(props, key);
|
|
|
VecStruct formVal = new VecStruct();
|
|
|
formVal.StringVec = new string[] { val };
|
|
|
tcProps.Add(key, formVal);
|
|
|
}
|
|
|
return tcProps;
|
|
|
}
|
|
|
|
|
|
public static System.Collections.Hashtable GetStringPropHashTable(Dictionary<string, CADAttr> props) {
|
|
|
System.Collections.Hashtable tcProps = new System.Collections.Hashtable();
|
|
|
foreach (string key in props.Keys) {
|
|
|
tcProps.Add(key, KUtil.GetCADValue(props, key));
|
|
|
}
|
|
|
return tcProps;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |