|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections;
|
|
|
using System.Text;
|
|
|
using Autodesk.AutoCAD.DatabaseServices;
|
|
|
using Autodesk.AutoCAD.Runtime;
|
|
|
using Autodesk.AutoCAD.Geometry;
|
|
|
using Autodesk.AutoCAD.ApplicationServices;
|
|
|
using Autodesk.AutoCAD.EditorInput;
|
|
|
|
|
|
using Teamcenter.Services.Strong.Query._2007_06.SavedQuery;
|
|
|
using Teamcenter.Hello;
|
|
|
using Teamcenter.Soa.Client;
|
|
|
using Teamcenter.ClientX;
|
|
|
using Teamcenter.Services.Strong.Core;
|
|
|
using Teamcenter.Soa.Client.Model;
|
|
|
using Teamcenter.Soa.Exceptions;
|
|
|
using Teamcenter.Services.Strong.Query;
|
|
|
|
|
|
using Teamcenter.Services.Strong.Core._2007_06.DataManagement;
|
|
|
using Teamcenter.Schemas.Soa._2006_03.Exceptions;
|
|
|
using Teamcenter.Services.Strong.Query._2006_03.SavedQuery;
|
|
|
|
|
|
using User = Teamcenter.Soa.Client.Model.Strong.User;
|
|
|
using Folder = Teamcenter.Soa.Client.Model.Strong.Folder;
|
|
|
using WorkspaceObject = Teamcenter.Soa.Client.Model.Strong.WorkspaceObject;
|
|
|
using Item = Teamcenter.Soa.Client.Model.Strong.Item;
|
|
|
using ItemRevision = Teamcenter.Soa.Client.Model.Strong.ItemRevision;
|
|
|
using ImanQuery = Teamcenter.Soa.Client.Model.Strong.ImanQuery;
|
|
|
using DataSet = Teamcenter.Soa.Client.Model.Strong.Dataset;
|
|
|
|
|
|
using SavedQueryResults = Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryResults;
|
|
|
|
|
|
namespace HelloTeamcenter.hello
|
|
|
{
|
|
|
public class SortMXL:IComparer<MXLClass>
|
|
|
{
|
|
|
public int Compare(MXLClass one, MXLClass two)
|
|
|
{
|
|
|
return one.Index_num.CompareTo(two.Index_num);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class Tool
|
|
|
{
|
|
|
private BTLClass btlinfo;
|
|
|
private List<MXLClass> bomlist = new List<MXLClass>();
|
|
|
private static User loginuser;
|
|
|
|
|
|
public static User Loginuser
|
|
|
{
|
|
|
get { return Tool.loginuser; }
|
|
|
set { Tool.loginuser = value; }
|
|
|
}
|
|
|
|
|
|
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
|
|
|
|
|
|
public BTLClass getBTL(string btlname)
|
|
|
{
|
|
|
btlinfo = new BTLClass();
|
|
|
Database db = HostApplicationServices.WorkingDatabase;
|
|
|
using (Transaction tran = db.TransactionManager.StartTransaction())
|
|
|
{
|
|
|
BlockTable blt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
|
|
|
//ed.WriteMessage("名称"+blt.GetType().Name);
|
|
|
|
|
|
if (blt.Has(btlname))
|
|
|
{
|
|
|
BlockTableRecord bltr = tran.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
|
|
|
foreach (ObjectId item in bltr)
|
|
|
{
|
|
|
Entity ent = tran.GetObject(item, OpenMode.ForRead) as Entity;
|
|
|
//ed.WriteMessage(ent.GetType().Name + "\n");
|
|
|
if (ent.GetType().Name == "BlockReference")
|
|
|
{
|
|
|
BlockReference bref = (BlockReference)ent;
|
|
|
//ed.WriteMessage(bref.GetType().Name + "====\n");
|
|
|
//ed.WriteMessage(bref.Name + "====\n");
|
|
|
if (bref.Name == btlname)
|
|
|
{
|
|
|
ed.WriteMessage("块名称:" + bref.Name + "\n");
|
|
|
if (bref.AttributeCollection.Count != 0)
|
|
|
{
|
|
|
System.Collections.IEnumerator bRefEnum = bref.AttributeCollection.GetEnumerator();
|
|
|
|
|
|
while (bRefEnum.MoveNext())
|
|
|
{
|
|
|
ObjectId aId = (ObjectId)bRefEnum.Current;//这一句极其关键
|
|
|
|
|
|
AttributeReference aRef = (AttributeReference)tran.GetObject(aId, OpenMode.ForRead);
|
|
|
//ed.WriteMessage("属性:" + aRef.Tag + "属性值:" + aRef.TextString + "\n");
|
|
|
if(aRef.Tag == "图号")
|
|
|
{
|
|
|
btlinfo.Item_id = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "零/部件名称")
|
|
|
{
|
|
|
btlinfo.Item_name = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "项目-产品名称")
|
|
|
{
|
|
|
btlinfo.Projectname = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "代号")
|
|
|
{
|
|
|
btlinfo.Partnumber = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "比例")
|
|
|
{
|
|
|
btlinfo.Proportion = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "图幅")
|
|
|
{
|
|
|
btlinfo.Mapsheet = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "版本")
|
|
|
{
|
|
|
btlinfo.Item_revision_id = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "重量")
|
|
|
{
|
|
|
btlinfo.Weight = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "材料牌号")
|
|
|
{
|
|
|
btlinfo.Materialgrade = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "共几页")
|
|
|
{
|
|
|
btlinfo.Allpage = aRef.TextString;
|
|
|
if (btlinfo.Allpage == "")
|
|
|
btlinfo.Allpage = "1";
|
|
|
}
|
|
|
else if (aRef.Tag == "第几页")
|
|
|
{
|
|
|
btlinfo.Pagenumber = aRef.TextString;
|
|
|
if (btlinfo.Pagenumber == "")
|
|
|
btlinfo.Pagenumber = "1";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
return btlinfo;
|
|
|
}
|
|
|
|
|
|
public string getQZL(string qzlname)
|
|
|
{
|
|
|
string hedao = "";
|
|
|
Database db = HostApplicationServices.WorkingDatabase;
|
|
|
using (Transaction tran = db.TransactionManager.StartTransaction())
|
|
|
{
|
|
|
BlockTable blt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
|
|
|
//ed.WriteMessage("名称"+blt.GetType().Name);
|
|
|
|
|
|
if (blt.Has(qzlname))
|
|
|
{
|
|
|
BlockTableRecord bltr = tran.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
|
|
|
foreach (ObjectId item in bltr)
|
|
|
{
|
|
|
Entity ent = tran.GetObject(item, OpenMode.ForRead) as Entity;
|
|
|
//ed.WriteMessage(ent.GetType().Name + "\n");
|
|
|
if (ent.GetType().Name == "BlockReference")
|
|
|
{
|
|
|
BlockReference bref = (BlockReference)ent;
|
|
|
//ed.WriteMessage(bref.GetType().Name + "====\n");
|
|
|
//ed.WriteMessage(bref.Name + "====\n");
|
|
|
if (bref.Name == qzlname)
|
|
|
{
|
|
|
ed.WriteMessage("块名称:" + bref.Name + "\n");
|
|
|
if (bref.AttributeCollection.Count != 0)
|
|
|
{
|
|
|
System.Collections.IEnumerator bRefEnum = bref.AttributeCollection.GetEnumerator();
|
|
|
|
|
|
while (bRefEnum.MoveNext())
|
|
|
{
|
|
|
ObjectId aId = (ObjectId)bRefEnum.Current;//这一句极其关键
|
|
|
|
|
|
AttributeReference aRef = (AttributeReference)tran.GetObject(aId, OpenMode.ForRead);
|
|
|
//ed.WriteMessage("属性:" + aRef.Tag + "属性值:" + aRef.TextString + "\n");
|
|
|
if (aRef.Tag == "校核")
|
|
|
{
|
|
|
hedao = "非核岛";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
return hedao;
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<MXLClass> getMXL(string mxlname)
|
|
|
{
|
|
|
bomlist.Clear();
|
|
|
|
|
|
Database db = HostApplicationServices.WorkingDatabase;
|
|
|
using (Transaction tran = db.TransactionManager.StartTransaction())
|
|
|
{
|
|
|
BlockTable blt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
|
|
|
//ed.WriteMessage("名称"+blt.GetType().Name);
|
|
|
|
|
|
if (blt.Has(mxlname))
|
|
|
{
|
|
|
BlockTableRecord bltr = tran.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
|
|
|
foreach (ObjectId item in bltr)
|
|
|
{
|
|
|
Entity ent = tran.GetObject(item, OpenMode.ForRead) as Entity;
|
|
|
//ed.WriteMessage(ent.GetType().Name + "\n");
|
|
|
if (ent.GetType().Name == "BlockReference")
|
|
|
{
|
|
|
BlockReference bref = (BlockReference)ent;
|
|
|
//ed.WriteMessage(bref.GetType().Name + "====\n");
|
|
|
//ed.WriteMessage(bref.Name + "====\n");
|
|
|
if (bref.Name == mxlname)
|
|
|
{
|
|
|
ed.WriteMessage("块名称:" + bref.Name + "\n");
|
|
|
if (bref.AttributeCollection.Count != 0)
|
|
|
{
|
|
|
System.Collections.IEnumerator bRefEnum = bref.AttributeCollection.GetEnumerator();
|
|
|
MXLClass mxlinfo = new MXLClass();
|
|
|
while (bRefEnum.MoveNext())
|
|
|
{
|
|
|
ObjectId aId = (ObjectId)bRefEnum.Current;//这一句极其关键
|
|
|
|
|
|
AttributeReference aRef = (AttributeReference)tran.GetObject(aId, OpenMode.ForRead);
|
|
|
//ed.WriteMessage("属性:" + aRef.Tag + "属性值:" + aRef.TextString + "\n");
|
|
|
if (aRef.Tag == "序号")
|
|
|
{
|
|
|
mxlinfo.Index = aRef.TextString;
|
|
|
mxlinfo.Index_num = Convert.ToInt32(mxlinfo.Index);
|
|
|
}
|
|
|
else if (aRef.Tag == "图号")
|
|
|
{
|
|
|
mxlinfo.Item_id = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "代号")
|
|
|
{
|
|
|
mxlinfo.Partnumber = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "名称")
|
|
|
{
|
|
|
mxlinfo.Name = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "DESCRIPTION")
|
|
|
{
|
|
|
mxlinfo.Object_desc = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "数量")
|
|
|
{
|
|
|
mxlinfo.Count = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "材料")
|
|
|
{
|
|
|
mxlinfo.Material = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "单重")
|
|
|
{
|
|
|
mxlinfo.Perweight = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "总重")
|
|
|
{
|
|
|
mxlinfo.Tolweight = aRef.TextString;
|
|
|
}
|
|
|
else if (aRef.Tag == "备注")
|
|
|
{
|
|
|
mxlinfo.Memo = aRef.TextString;
|
|
|
}
|
|
|
}
|
|
|
bomlist.Add(mxlinfo);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
return bomlist;
|
|
|
}
|
|
|
|
|
|
public List<MXLClass> sortbomlist(List<MXLClass> sortbomlist)
|
|
|
{
|
|
|
for (int i = 0; i < sortbomlist.Count; i++)
|
|
|
{
|
|
|
sortbomlist[i].Itemtype = initItemType(sortbomlist[i].Item_id, sortbomlist[i].Material);
|
|
|
}
|
|
|
sortbomlist.Sort(new SortMXL());
|
|
|
return sortbomlist;
|
|
|
}
|
|
|
|
|
|
public string initItemType(string item_id, string material)
|
|
|
{
|
|
|
string type = "";
|
|
|
int pos = item_id.IndexOf("DR");
|
|
|
ed.WriteMessage("pos: " + pos + "\n");
|
|
|
if (pos >= 0)
|
|
|
{
|
|
|
string sub = item_id.Substring(pos + 2);
|
|
|
ed.WriteMessage("sub :" + sub + "\n");
|
|
|
char[] subchar = sub.ToCharArray();
|
|
|
int i = 0;
|
|
|
if (subchar[i].ToString() == "8")
|
|
|
{
|
|
|
ed.WriteMessage("是否含有CG-:" + item_id.Contains("CG-").ToString());
|
|
|
if (item_id.Contains("CG-"))
|
|
|
{
|
|
|
type = "D5PruchasePart";
|
|
|
return type;
|
|
|
}
|
|
|
}
|
|
|
for (; i < subchar.Length; i++)
|
|
|
{
|
|
|
if (subchar[i].ToString() == "0")
|
|
|
continue;
|
|
|
else
|
|
|
{
|
|
|
if (material == "装配件")
|
|
|
{
|
|
|
type = "D5AsmPart";
|
|
|
return type;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
type = "D5Part";
|
|
|
return type;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (material == "装配件" && i == subchar.Length)
|
|
|
{
|
|
|
type = "D5Product";
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if(item_id.StartsWith("104") || item_id.StartsWith("105"))
|
|
|
type = "D5StdFasteners";
|
|
|
else if(item_id.StartsWith("TC"))
|
|
|
type = "D5CommonParts";
|
|
|
else
|
|
|
type = "D5Part";
|
|
|
}
|
|
|
|
|
|
return type;
|
|
|
}
|
|
|
|
|
|
|
|
|
public string getLOVProductType(string item_id,string itemtype,string hedao)
|
|
|
{
|
|
|
string productTypes = "";
|
|
|
if (itemtype == "D5Product")
|
|
|
{
|
|
|
if (hedao == "非核岛")
|
|
|
productTypes = "117";
|
|
|
else
|
|
|
productTypes = "116";
|
|
|
}
|
|
|
else if (itemtype == "D5AsmPart")
|
|
|
{
|
|
|
if (hedao == "非核岛")
|
|
|
productTypes = "115";
|
|
|
else
|
|
|
productTypes = "114";
|
|
|
}
|
|
|
else if (itemtype == "D5Part")
|
|
|
{
|
|
|
if (hedao == "非核岛")
|
|
|
productTypes = "113";
|
|
|
else
|
|
|
productTypes = "112";
|
|
|
}
|
|
|
else if (itemtype == "D5StdFasteners")
|
|
|
{
|
|
|
if(item_id.StartsWith("104"))
|
|
|
productTypes = "104";
|
|
|
else
|
|
|
productTypes = "105";
|
|
|
}
|
|
|
else if (itemtype == "D5CommonPartss")
|
|
|
{
|
|
|
if (item_id.StartsWith("120"))
|
|
|
productTypes = "120";
|
|
|
else
|
|
|
productTypes = "121";
|
|
|
}//此处需要增加D5PruchasePart类型的核岛判断
|
|
|
return productTypes;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SavedQueryResults getSearchItem(string item_id)
|
|
|
{
|
|
|
ImanQuery query = null;
|
|
|
SavedQueryService queryService = SavedQueryService.getService(Session.getConnection());
|
|
|
try
|
|
|
{
|
|
|
GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();
|
|
|
if (savedQueries.Queries.Length == 0)
|
|
|
{
|
|
|
ed.WriteMessage("There are no saved queries in the system.\n");
|
|
|
}
|
|
|
for (int i = 0; i < savedQueries.Queries.Length; i++)
|
|
|
{
|
|
|
|
|
|
if (savedQueries.Queries[i].Name.Equals("D5Item ID"))
|
|
|
{
|
|
|
query = savedQueries.Queries[i].Query;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("GetSavedQueries service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if (query == null)
|
|
|
{
|
|
|
ed.WriteMessage("There is not an 'D5Item ID' query.\n");
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
// Search for all Items, returning a maximum of 25 objects
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[] savedQueryInput = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[1];
|
|
|
savedQueryInput[0] = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput();
|
|
|
savedQueryInput[0].Query = query;
|
|
|
//savedQueryInput[0].Entries = new String[] { "Item ID" };
|
|
|
savedQueryInput[0].Entries = new String[] { "零组件 ID" };
|
|
|
savedQueryInput[0].Values = new String[1];
|
|
|
savedQueryInput[0].Values[0] = item_id;
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.ExecuteSavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryResults found = savedQueryResult.ArrayOfResults[0];
|
|
|
|
|
|
ed.WriteMessage("Found Items:"+ found.NumOfObjects +"\n");
|
|
|
return found;
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("ExecuteSavedQuery service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SavedQueryResults getSearchItem(string item_id,string name,string type,string owner)
|
|
|
{
|
|
|
ImanQuery query = null;
|
|
|
SavedQueryService queryService = SavedQueryService.getService(Session.getConnection());
|
|
|
try
|
|
|
{
|
|
|
GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();
|
|
|
if (savedQueries.Queries.Length == 0)
|
|
|
{
|
|
|
ed.WriteMessage("There are no saved queries in the system.\n");
|
|
|
}
|
|
|
for (int i = 0; i < savedQueries.Queries.Length; i++)
|
|
|
{
|
|
|
|
|
|
if (savedQueries.Queries[i].Name.Equals("D5SearchForItem"))
|
|
|
{
|
|
|
query = savedQueries.Queries[i].Query;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("GetSavedQueries service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if (query == null)
|
|
|
{
|
|
|
ed.WriteMessage("There is not an 'D5SearchForItem' query.\n");
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[] savedQueryInput = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[1];
|
|
|
savedQueryInput[0] = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput();
|
|
|
savedQueryInput[0].Query = query;
|
|
|
//savedQueryInput[0].Entries = new String[] { "Name", "Item ID", "Type", "Owning User" };
|
|
|
savedQueryInput[0].Entries = new String[] { "名称", "零组件 ID", "类型", "所有权用户" };
|
|
|
savedQueryInput[0].Values = new String[4];
|
|
|
savedQueryInput[0].Values[0] = name;
|
|
|
savedQueryInput[0].Values[1] = item_id;
|
|
|
savedQueryInput[0].Values[2] = type;
|
|
|
savedQueryInput[0].Values[3] = owner;
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.ExecuteSavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryResults found = savedQueryResult.ArrayOfResults[0];
|
|
|
|
|
|
ed.WriteMessage("Found Items:" + found.NumOfObjects + "\n");
|
|
|
return found;
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("ExecuteSavedQuery service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SavedQueryResults getSearchUser()
|
|
|
{
|
|
|
ImanQuery query = null;
|
|
|
SavedQueryService queryService = SavedQueryService.getService(Session.getConnection());
|
|
|
try
|
|
|
{
|
|
|
GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();
|
|
|
if (savedQueries.Queries.Length == 0)
|
|
|
{
|
|
|
ed.WriteMessage("There are no saved queries in the system.\n");
|
|
|
}
|
|
|
for (int i = 0; i < savedQueries.Queries.Length; i++)
|
|
|
{
|
|
|
|
|
|
if (savedQueries.Queries[i].Name.Equals("D5SearchForUser"))
|
|
|
{
|
|
|
query = savedQueries.Queries[i].Query;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("GetSavedQueries service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if (query == null)
|
|
|
{
|
|
|
ed.WriteMessage("There is not an 'D5SearchForUser' query.\n");
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
// Search for all Items, returning a maximum of 25 objects
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[] savedQueryInput = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[1];
|
|
|
savedQueryInput[0] = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput();
|
|
|
savedQueryInput[0].Query = query;
|
|
|
//savedQueryInput[0].Entries = new String[] { "User Id" };
|
|
|
savedQueryInput[0].Entries = new String[] { "用户 ID" };
|
|
|
savedQueryInput[0].Values = new String[1];
|
|
|
savedQueryInput[0].Values[0] = "*";
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.ExecuteSavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryResults found = savedQueryResult.ArrayOfResults[0];
|
|
|
|
|
|
ed.WriteMessage("Found Users:" + found.NumOfObjects + "\n");
|
|
|
return found;
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("ExecuteSavedQuery service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public SavedQueryResults getSearchType(string d5MaterialGrades)
|
|
|
{
|
|
|
ImanQuery query = null;
|
|
|
SavedQueryService queryService = SavedQueryService.getService(Session.getConnection());
|
|
|
try
|
|
|
{
|
|
|
GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();
|
|
|
if (savedQueries.Queries.Length == 0)
|
|
|
{
|
|
|
ed.WriteMessage("There are no saved queries in the system.\n");
|
|
|
}
|
|
|
for (int i = 0; i < savedQueries.Queries.Length; i++)
|
|
|
{
|
|
|
|
|
|
if (savedQueries.Queries[i].Name.Equals("D5SearchForType"))
|
|
|
{
|
|
|
query = savedQueries.Queries[i].Query;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("GetSavedQueries service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
if (query == null)
|
|
|
{
|
|
|
ed.WriteMessage("There is not an 'D5SearchForType' query.\n");
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
// Search for all Items, returning a maximum of 25 objects
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[] savedQueryInput = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput[1];
|
|
|
savedQueryInput[0] = new Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryInput();
|
|
|
savedQueryInput[0].Query = query;
|
|
|
//savedQueryInput[0].Entries = new String[] { "Name", "Type" };
|
|
|
savedQueryInput[0].Entries = new String[] { "名称", "类型" };
|
|
|
savedQueryInput[0].Values = new String[2];
|
|
|
savedQueryInput[0].Values[0] = d5MaterialGrades;
|
|
|
savedQueryInput[0].Values[1] = "D5MaterialGrade";
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.ExecuteSavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
|
|
|
|
|
|
Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryResults found = savedQueryResult.ArrayOfResults[0];
|
|
|
|
|
|
ed.WriteMessage("Found Type:" + found.NumOfObjects + "\n");
|
|
|
return found;
|
|
|
}
|
|
|
catch (ServiceException e)
|
|
|
{
|
|
|
ed.WriteMessage("ExecuteSavedQuery service request failed.\n");
|
|
|
ed.WriteMessage(e.Message);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Hashtable getTCPreferences(string prefername)
|
|
|
{
|
|
|
Hashtable prefValues = new Hashtable();
|
|
|
SessionService sessionservice = SessionService.getService(Session.getConnection());
|
|
|
Teamcenter.Services.Strong.Core._2007_01.Session.ScopedPreferenceNames[] prefNames = new Teamcenter.Services.Strong.Core._2007_01.Session.ScopedPreferenceNames[1];
|
|
|
Teamcenter.Services.Strong.Core._2007_01.Session.ScopedPreferenceNames scopedPref = new Teamcenter.Services.Strong.Core._2007_01.Session.ScopedPreferenceNames();
|
|
|
scopedPref.Names = new String[]{ prefername };
|
|
|
scopedPref.Scope = "site";
|
|
|
prefNames[0] = scopedPref;
|
|
|
|
|
|
|
|
|
Teamcenter.Services.Strong.Core._2007_01.Session.MultiPreferencesResponse resp = sessionservice.GetPreferences(prefNames);
|
|
|
Teamcenter.Services.Strong.Core._2007_01.Session.ReturnedPreferences[] preferenceResp = resp.Preferences;
|
|
|
prefValues.Add(preferenceResp[0].Name, preferenceResp[0].Values);
|
|
|
//string temp = preferenceResp[0].Name.ToString();
|
|
|
//string[] value = (string[])prefValues[preferenceResp[0].Name.ToString()];
|
|
|
|
|
|
return prefValues;
|
|
|
}
|
|
|
|
|
|
//分割字符串,取出对应类型的Item的ID
|
|
|
public string getCorrespondItemID(string type,string[] tempprevalues)
|
|
|
{
|
|
|
string itemid = "";
|
|
|
Hashtable temptable = new Hashtable();
|
|
|
for (int i = 0; i < tempprevalues.Length; i++)
|
|
|
{
|
|
|
string tempvalueline = tempprevalues[i];
|
|
|
string[] tempvalue = tempvalueline.Split('=');
|
|
|
temptable.Add(tempvalue[0].ToString(), tempvalue[1].ToString());
|
|
|
}
|
|
|
|
|
|
if (temptable.Count <= 0)
|
|
|
itemid = "";
|
|
|
else
|
|
|
{
|
|
|
if (temptable.ContainsKey(type))
|
|
|
{
|
|
|
itemid = (string)temptable[type];
|
|
|
}
|
|
|
}
|
|
|
return itemid;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|