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.
484 lines
22 KiB
484 lines
22 KiB
using System;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Collections;
|
|
|
|
using ZwSoft.ZwCAD.DatabaseServices;
|
|
using ZwSoft.ZwCAD.Runtime;
|
|
using ZwSoft.ZwCAD.Geometry;
|
|
using ZwSoft.ZwCAD.ApplicationServices;
|
|
using ZwSoft.ZwCAD.EditorInput;
|
|
|
|
|
|
|
|
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.Services.Strong.Core._2006_03.Reservation;
|
|
|
|
using Teamcenter.Services.Strong.Core._2006_03.FileManagement;
|
|
|
|
using Teamcenter.Soa.Internal.Client.Model;
|
|
using Teamcenter.Soa.Internal.Client;
|
|
|
|
using HelloTeamcenter.hello;
|
|
|
|
|
|
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;
|
|
using ImanFile = Teamcenter.Soa.Client.Model.Strong.ImanFile;
|
|
|
|
|
|
|
|
namespace HelloTeamcenter.form
|
|
{
|
|
public partial class Search : Form
|
|
{
|
|
public Search()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public List<ALLOBJECT> folderlist = new List<ALLOBJECT>();
|
|
public List<ALLOBJECT> itemlist = new List<ALLOBJECT>();
|
|
public List<ALLOBJECT> itemvisionlist = new List<ALLOBJECT>();
|
|
public List<ALLOBJECT> datasetlist = new List<ALLOBJECT>();
|
|
|
|
public Document appdoc;
|
|
public User user;
|
|
public Editor ed;
|
|
public bool hasRight = true;
|
|
|
|
public Hashtable itemtypetable;
|
|
|
|
public string xmlpath = "";
|
|
|
|
private void Search_Load(object sender, EventArgs e)
|
|
{
|
|
this.textBox1.Text = "";
|
|
this.textBox2.Text = "";
|
|
//读取Item类型.xml信息
|
|
OriginItemType originitemtype = new OriginItemType();
|
|
originitemtype.getType(this.xmlpath);
|
|
this.itemtypetable = originitemtype.Itemtypetable;
|
|
|
|
foreach (DictionaryEntry de in itemtypetable)
|
|
{
|
|
this.comboBox1.Items.Add(de.Key.ToString());
|
|
}
|
|
}
|
|
|
|
private void comboBox2_Click(object sender, EventArgs e)
|
|
{
|
|
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
|
|
this.comboBox2.Items.Clear();
|
|
OriginTool tool = new OriginTool();
|
|
SavedQueryResults found = tool.getSearchUser();
|
|
if (found != null && found.NumOfObjects > 0)
|
|
{
|
|
for (int i = 0; i < found.NumOfObjects; i++)
|
|
{
|
|
User userobj = found.Objects[i] as User;
|
|
ModelObject[] objects = { userobj };
|
|
String[] attributes = { "User ID", "Name" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
string userid = userobj.User_id;
|
|
string username = userobj.User_name;
|
|
string tempname = userid + "(" + username + ")";
|
|
if (this.comboBox2.Items.Contains(tempname))
|
|
continue;
|
|
else
|
|
this.comboBox2.Items.Add(tempname);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
string name = textBox1.Text;
|
|
string item_id = textBox2.Text;
|
|
string type = comboBox1.Text;
|
|
//ed.WriteMessage("选择类型:"+ type +"\n");
|
|
string owner = comboBox2.Text;
|
|
//ed.WriteMessage("选择用户:" + owner + "\n");
|
|
if (name == "")
|
|
{
|
|
name = "*";
|
|
}
|
|
if (item_id == "")
|
|
{
|
|
item_id = "*";
|
|
}
|
|
if (type == "")
|
|
{
|
|
type = "*";
|
|
}
|
|
if (owner == "")
|
|
{
|
|
owner = "*";
|
|
}
|
|
else
|
|
{
|
|
int pos = owner.IndexOf('(');
|
|
owner = owner.Substring(0, pos);
|
|
//ed.WriteMessage("用户" + owner+"\n");
|
|
}
|
|
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
|
|
OriginTool tool = new OriginTool();
|
|
SavedQueryResults found = tool.getSearchItem(item_id, name, type, owner);
|
|
if (found != null && found.NumOfObjects > 0)
|
|
{
|
|
this.treeView1.Nodes.Clear();
|
|
for (int i = 0; i < found.NumOfObjects; i++)
|
|
{
|
|
Item item = found.Objects[i] as Item;
|
|
ModelObject[] objects = { item };
|
|
String[] attributes = { "object_string"};
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
string inname = item.Object_string;
|
|
TreeNode childnode = new TreeNode(inname, 3, 3);
|
|
this.treeView1.Nodes.Add(childnode);
|
|
ALLOBJECT perobject = new ALLOBJECT();
|
|
perobject.workobject = item;
|
|
perobject.treenode = childnode;
|
|
itemlist.Add(perobject);
|
|
}
|
|
foreach (TreeNode ch in treeView1.Nodes)
|
|
{
|
|
ch.EnsureVisible();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
|
|
{
|
|
TreeNode nownode = this.treeView1.SelectedNode;
|
|
getChild(nownode);
|
|
foreach (TreeNode ch in nownode.Nodes)
|
|
{
|
|
ch.EnsureVisible();
|
|
}
|
|
}
|
|
|
|
private void getChild(TreeNode nownode)
|
|
{
|
|
nownode.Nodes.Clear();
|
|
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
|
|
WorkspaceObject[] contents = null;
|
|
string nodetext = nownode.Text;
|
|
int imageindex = nownode.SelectedImageIndex;
|
|
if (imageindex == 3)
|
|
{
|
|
foreach (ALLOBJECT perobject in itemlist)
|
|
{
|
|
if (perobject.treenode.Equals(nownode))
|
|
{
|
|
Item item = perobject.workobject as Item;
|
|
ModelObject[] itemrevisionlist = null;
|
|
ModelObject[] objects = { item };
|
|
String[] attributes = { "revision_list" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
itemrevisionlist = item.Revision_list;
|
|
for (int i = 0; i < itemrevisionlist.Length; i++)
|
|
{
|
|
ItemRevision itemrevision = itemrevisionlist[i] as ItemRevision;
|
|
ModelObject[] objects1 = { itemrevision };
|
|
String[] attributes1 = { "object_string", "object_type" };
|
|
dmService.RefreshObjects(objects1);
|
|
dmService.GetProperties(objects1, attributes1);
|
|
string name = itemrevision.Object_string;
|
|
string type = itemrevision.Object_type;
|
|
|
|
ALLOBJECT inperobject = new ALLOBJECT();
|
|
inperobject.workobject = itemrevision;
|
|
TreeNode childnode = new TreeNode(name, 4, 4);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
itemvisionlist.Add(inperobject);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else if (imageindex == 4)
|
|
{
|
|
foreach (ALLOBJECT perobject in itemvisionlist)
|
|
{
|
|
if (perobject.treenode.Equals(nownode))
|
|
{
|
|
ItemRevision itemrevision = perobject.workobject as ItemRevision;
|
|
ExpandGRMRelationsPref myPref = new ExpandGRMRelationsPref();
|
|
RelationAndTypesFilter2 myFilter = new RelationAndTypesFilter2();
|
|
myFilter.RelationName = "IMAN_specification";
|
|
String[] typeVec = { "D5DWG", "Folder" };
|
|
myFilter.ObjectTypeNames = typeVec;
|
|
myPref.ExpItemRev = false;
|
|
RelationAndTypesFilter2[] myfilter = { myFilter };
|
|
myPref.Info = myfilter;
|
|
ModelObject[] objects1 = { itemrevision };
|
|
|
|
ExpandGRMRelationsResponse myResp = dmService.ExpandGRMRelationsForPrimary(objects1, myPref);
|
|
ExpandGRMRelationsOutput[] myoutput = myResp.Output;
|
|
for (int i = 0; i < myoutput.Length; i++)
|
|
{
|
|
ExpandGRMRelationsOutput one_out = myoutput[i];
|
|
for (int j = 0; j < one_out.OtherSideObjData.Length; j++)
|
|
{
|
|
ExpandGRMRelationsData otherSideData = one_out.OtherSideObjData[j];
|
|
for (int k = 0; k < otherSideData.OtherSideObjects.Length; k++)
|
|
{
|
|
Type typeinfo = otherSideData.OtherSideObjects[k].GetType();
|
|
string typename = typeinfo.Name;
|
|
if (typename == "Folder")
|
|
{
|
|
Folder infold = otherSideData.OtherSideObjects[k] as Folder;
|
|
|
|
ModelObject[] objects = { infold };
|
|
String[] attributes = { "object_string", "object_type" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
string name = infold.Object_string;
|
|
string type = infold.Object_type;
|
|
|
|
ALLOBJECT inperobject = new ALLOBJECT();
|
|
inperobject.workobject = infold;
|
|
TreeNode childnode = new TreeNode(name, 1, 1);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
folderlist.Add(inperobject);
|
|
}
|
|
else
|
|
{
|
|
DataSet dateset = otherSideData.OtherSideObjects[k] as DataSet;
|
|
ModelObject[] objects = { dateset };
|
|
String[] attributes = { "object_string" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
string name = dateset.Object_string;
|
|
|
|
ALLOBJECT inperobject = new ALLOBJECT();
|
|
inperobject.workobject = dateset;
|
|
inperobject.name = name;
|
|
TreeNode childnode = new TreeNode(name, 0, 0);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
datasetlist.Add(inperobject);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else if (imageindex == 1)
|
|
{
|
|
foreach (ALLOBJECT perobject in folderlist)
|
|
{
|
|
if (perobject.treenode.Equals(nownode))
|
|
{
|
|
Folder fl = perobject.workobject as Folder;
|
|
ModelObject[] objects = { fl };
|
|
String[] attributes = { "contents" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
contents = fl.Contents;
|
|
for (int i = 0; i < contents.Length; i++)
|
|
{
|
|
WorkspaceObject childobj = contents[i];
|
|
ModelObject[] objects1 = { childobj };
|
|
String[] attributes1 = { "object_string", "object_type" };
|
|
dmService.RefreshObjects(objects1);
|
|
dmService.GetProperties(objects1, attributes1);
|
|
string name = childobj.Object_string;
|
|
string type = childobj.Object_type;
|
|
if (type == "Folder" || type == "Newstuff Folder" || type == "Mail Folder")
|
|
{
|
|
ALLOBJECT inperobject = new ALLOBJECT();
|
|
inperobject.workobject = childobj;
|
|
Folder infl = childobj as Folder;
|
|
|
|
if (type == "Folder")
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 1, 1);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
}
|
|
else if (type == "Newstuff Folder")
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 6, 6);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
}
|
|
else if (type == "Mail Folder")
|
|
{
|
|
TreeNode childnode = new TreeNode(name, 5, 5);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
}
|
|
folderlist.Add(inperobject);
|
|
}
|
|
else if (type == "Item" || this.itemtypetable.ContainsValue(type))
|
|
{
|
|
ALLOBJECT inperobject = new ALLOBJECT();
|
|
inperobject.workobject = childobj;
|
|
Item item = childobj as Item;
|
|
TreeNode childnode = new TreeNode(name, 3, 3);
|
|
inperobject.treenode = childnode;
|
|
nownode.Nodes.Add(childnode);
|
|
itemlist.Add(inperobject);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
|
|
Reservation res = ReservationService.getService(Session.getConnection());
|
|
TreeNode nownode = this.treeView1.SelectedNode;
|
|
if (nownode.SelectedImageIndex == 0)
|
|
{
|
|
foreach (ALLOBJECT perobject in this.datasetlist)
|
|
{
|
|
if (perobject.treenode.Equals(nownode))
|
|
{
|
|
DialogResult isopen = MessageBox.Show("您是否确定打开该图纸?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (isopen == DialogResult.None || isopen == DialogResult.No)
|
|
{
|
|
return;
|
|
}
|
|
DataSet mydateset = perobject.workobject as DataSet;
|
|
ModelObject[] objects = { mydateset };
|
|
String[] attributes = { "is_modifiable", "checked_out", "ref_list" };
|
|
dmService.RefreshObjects(objects);
|
|
dmService.GetProperties(objects, attributes);
|
|
if (mydateset.Is_modifiable == false)
|
|
{
|
|
DialogResult result = MessageBox.Show("您没有修改权限,是否以只读方式打开?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
hasRight = false;
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
if (mydateset.Is_modifiable)
|
|
{
|
|
DialogResult result = MessageBox.Show("是否签出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
if (mydateset.Checked_out == "Y")
|
|
{
|
|
MessageBox.Show("对不起,文件已签出!请确认文件签入后执行此操作");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
ModelObject[] dataobj = { mydateset };
|
|
res.Checkout(dataobj, "", "");
|
|
//ed.WriteMessage("文件已签出");
|
|
//ed.WriteMessage("\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
ModelObject[] dsfilevec = mydateset.Ref_list;
|
|
//ed.WriteMessage("长度:" + dsfilevec.Length);
|
|
//ed.WriteMessage(dsfilevec[0].GetType().ToString());
|
|
ImanFile dsfile = dsfilevec[0] as ImanFile;
|
|
|
|
ModelObject[] objects1 = { dsfile };
|
|
String[] attributes1 = { "relative_directory_path", "original_file_name" };
|
|
dmService.RefreshObjects(objects1);
|
|
dmService.GetProperties(objects1, attributes1);
|
|
|
|
//ed.WriteMessage("路径:" + dsfile.Relative_directory_path + "\n");
|
|
//ed.WriteMessage("文件名:" + dsfile.Original_file_name + "\n");
|
|
string newfilename = dsfile.Original_file_name;
|
|
|
|
string tempdir = System.Environment.GetEnvironmentVariable("TEMP").ToString();
|
|
//ed.WriteMessage("TEMP:" + tempdir.ToString() + "\n");
|
|
|
|
FileManagementService fmService = FileManagementService.getService(Teamcenter.ClientX.Session.getConnection());
|
|
ImanFile[] objects2 = { dsfile };
|
|
FileTicketsResponse tickets = fmService.GetFileReadTickets(objects2);
|
|
//ed.WriteMessage("tickets : " + tickets.Tickets.Count + "\n");
|
|
|
|
//foreach (System.Collections.DictionaryEntry ticket in tickets.Tickets)
|
|
//{
|
|
// ed.WriteMessage("键:" + ticket.Key + "\n" + "值:" + ticket.Value + "\n");
|
|
//}
|
|
Teamcenter.Soa.Client.FileManagementUtility fmu = new Teamcenter.Soa.Client.FileManagementUtility(Teamcenter.ClientX.Session.getConnection());
|
|
Teamcenter.Soa.Client.GetFileResponse getFileResponse = fmu.GetFiles(dsfilevec);
|
|
FileInfo[] fileinfovec = getFileResponse.GetFiles();
|
|
|
|
//ed.WriteMessage("文件个数:" + fileinfovec.Length + "\n");
|
|
FileInfo file = fileinfovec[0];
|
|
|
|
string newtempfile = tempdir + "\\" + newfilename;
|
|
System.IO.File.Copy(file.FullName, newtempfile, true);
|
|
System.IO.File.SetAttributes(newtempfile, FileAttributes.Normal);
|
|
DocumentCollection acdocmgr = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager;
|
|
if (File.Exists(newtempfile))
|
|
{
|
|
acdocmgr.Open(newtempfile,false);
|
|
//Object pdata = newtempfile;
|
|
//acdocmgr.ExecuteInApplicationContext(c_back, pdata);
|
|
//acdocmgr.Add(newtempfile);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("对不起,用户临时目录下不存在此文件\n");
|
|
}
|
|
this.Hide();
|
|
this.Dispose();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//ed.WriteMessage("请选择正确的数据集类型\n");
|
|
MessageBox.Show("请选择正确的数据集类型");
|
|
return;
|
|
}
|
|
}
|
|
|
|
//private void c_back(Object data)
|
|
//{
|
|
// DocumentCollection acdocmgr = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager;
|
|
// if (acdocmgr.IsApplicationContext)
|
|
// {
|
|
// acdocmgr.Open(Convert.ToString(data));
|
|
// }
|
|
//}
|
|
|
|
}
|
|
}
|