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.

2612 lines
144 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//==================================================
//
// @<COPYRIGHT>@
//
//==================================================
using System;
using System.Collections;
using Teamcenter.ClientX;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
using HelloTeamcenter.hello;
using HelloTeamcenter.form;
using System.Windows.Forms;
using System.IO;
using System.Collections.Generic;
using Teamcenter.Services.Strong.Core;
using Teamcenter.Soa.Client.Model;
using Teamcenter.Services.Strong.Core._2006_03.Reservation;
using Teamcenter.Services.Strong.Core._2006_03.FileManagement;
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.Soa.Internal.Client.Model;
using Teamcenter.Soa.Internal.Client;
using Teamcenter.Soa.Client;
using Teamcenter.Services.Strong.Query;
//using Teamcenter.FMS.FCCProxy.ClientCache;
using Teamcenter.Schemas.Soa._2006_03.Exceptions;
using Teamcenter.Soa.Exceptions;
using User = Teamcenter.Soa.Client.Model.Strong.User;
using DataSet = Teamcenter.Soa.Client.Model.Strong.Dataset;
using ImanFile = Teamcenter.Soa.Client.Model.Strong.ImanFile;
using SavedQueryResults = Teamcenter.Services.Strong.Query._2007_06.SavedQuery.SavedQueryResults;
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 ReleaseStatus = Teamcenter.Soa.Client.Model.Strong.ReleaseStatus;
using Form = Teamcenter.Soa.Client.Model.Strong.Form;
using Dataset = Teamcenter.Soa.Client.Model.Strong.Dataset;
using Folder = Teamcenter.Soa.Client.Model.Strong.Folder;
using WorkspaceObject = Teamcenter.Soa.Client.Model.Strong.WorkspaceObject;
[assembly: ExtensionApplication(typeof(Teamcenter.Hello.Hello))]
[assembly: CommandClass(typeof(Teamcenter.Hello.Hello))]
namespace Teamcenter.Hello
{
/**
* This sample client application demonstrates some of the basic features of the
* Teamcenter Services framework and a few of the services.
*
* An instance of the Connection object is created with implementations of the
* ExceptionHandler, PartialErrorListener, ChangeListener, and DeleteListeners
* intefaces. This client application performs the following functions:
* 1. Establishes a session with the Teamcenter server
* 2. Display the contents of the Home Folder
* 3. Performs a simple query of the database
* 4. Create, revise, and delete an Item
*
*/
public class Hello : Autodesk.AutoCAD.Runtime.IExtensionApplication
{
static User loginuser;
Login loginfrom;
OpenFromTC openfrom;
Search searchfrom;
SaveToTC savefrom;
static Autodesk.AutoCAD.EditorInput.Editor ed;
static Autodesk.AutoCAD.ApplicationServices.Document appodc;
static DocumentCollection acdocmgr;
static Teamcenter.ClientX.Session session;
//
bool islogin = false;
bool hasRight = true;
string serveraddress;
string username;
string password;
string usergroup;
string userrole;
//<2F><><EFBFBD>ڼ<EFBFBD>¼Item<65><6D><EFBFBD><EFBFBD>.xml<6D>ļ<EFBFBD><C4BC>ж<EFBFBD>Ӧ<EFBFBD><D3A6>Item<65><6D><EFBFBD><EFBFBD>
static OriginItemType originitemtype;
static string xmlpath = "";
public void Initialize()
{
//addComtextMenu();
}
public void Terminate()
{
}
[CommandMethod("LOGIN")]
public void login()
{
appodc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
acdocmgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
//acdocmgr.DocumentToBeDestroyed+=new DocumentCollectionEventHandler(acdocmgr_DocumentToBeDestroyed);
appodc.Database.SaveAs(appodc.Name, true, DwgVersion.Current, appodc.Database.SecurityParameters);
//appodc.Database.Save();
ed = appodc.Editor;
ed.WriteMessage("==========login==========\n");
//Tool tool = new Tool();
//BTLClass titleinfo = tool.getBTL("DFHM_BTL",appodc);
//ed.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ:\n" + "ͼ<>ţ<EFBFBD>" + titleinfo.Item_id.ToString());
//<2F><>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
//OriginTool origintool = new OriginTool();
//xmlpath = System.Environment.CurrentDirectory;
xmlpath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
ed.WriteMessage("<22><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>·<EFBFBD><C2B7>:" + xmlpath + "\n");
//origintool.checkxml(xmlpath);
loginfrom = new Login();
loginfrom.appodc = appodc;
loginfrom.button1.Click += new System.EventHandler(this.loginbutton1_Click);
loginfrom.button2.Click += new System.EventHandler(this.loginbutton2_Click);
loginfrom.Activate();
loginfrom.Show();
}
private void loginbutton1_Click(object sender, EventArgs e)
{
loginfrom.m_WebAddress = loginfrom.textBox1.Text.ToString();
loginfrom.username = loginfrom.textBox2.Text.ToString();
loginfrom.password = loginfrom.textBox3.Text.ToString();
loginfrom.usergroup = loginfrom.textBox4.Text.ToString();
loginfrom.userrole = loginfrom.textBox5.Text.ToString();
session = new Teamcenter.ClientX.Session(loginfrom.m_WebAddress);
loginuser = session.mylogin(loginfrom.username, loginfrom.password, loginfrom.usergroup, loginfrom.userrole);
if (loginuser != null)
{
serveraddress = loginfrom.m_WebAddress;
username = loginfrom.username;
password = loginfrom.password;
usergroup = loginfrom.usergroup;
userrole = loginfrom.userrole;
OriginTool.Loginuser = loginuser;
ed.WriteMessage("<22><>¼<EFBFBD>ɹ<EFBFBD>\n");
islogin = true;
string tempdir = System.Environment.GetEnvironmentVariable("TEMP").ToString();
string loginfile = tempdir + "\\login.ini";
loginfrom.Hide();
//loginfrom.Dispose();
if (File.Exists(loginfile))
{
StreamWriter sw = new StreamWriter(loginfile, false);
sw.WriteLine(loginfrom.m_WebAddress + "|" + loginfrom.username + "|" + loginfrom.password
+ "|" + loginfrom.usergroup + "|" + loginfrom.userrole + "||");
sw.Close();
}
else
{
FileStream fs = new FileStream(loginfile, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(loginfrom.m_WebAddress + "|" + loginfrom.username + "|" + loginfrom.password
+ "|" + loginfrom.usergroup + "|" + loginfrom.userrole + "||");
sw.Close();
fs.Close();
}
//<2F>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˻<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>xml<6D>ļ<EFBFBD>
OriginTool origintool = new OriginTool();
bool hasxmlfile = origintool.checkxml(xmlpath);
if (hasxmlfile)
{
DialogResult hasresult = MessageBox.Show("<22><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Ŀ¼<C4BF>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>XML<4D><4C><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>", "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (hasresult == DialogResult.No || hasresult == DialogResult.None)
{
ed.WriteMessage("<22><><EFBFBD><EFBFBD>XML<4D><4C><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ͬ<EFBFBD><CDAC>\n");
}
if (hasresult == DialogResult.Yes)
{
Hashtable prevalues = origintool.getTCPreferences("OriginXMLFile");
if (prevalues != null && prevalues.Count > 0)
{
foreach (DictionaryEntry de in prevalues)
{
List<string> itemidlist = origintool.getCorrespondItemID((string[])de.Value);
for (int m = 0; m < itemidlist.Count; m++)
{
string item_id = itemidlist[m];
SavedQueryResults found = origintool.getSearchItem(item_id);
if (found.NumOfObjects == 0)
{
ed.WriteMessage("TCϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>\n");
return;
}
else
{
Item dmtitem = found.Objects[0] as Item;
if (!origintool.downloadfile(dmtitem, xmlpath))
{
ed.WriteMessage("<22><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
return;
}
}
}
}
}
}
}
}
else
{
MessageBox.Show("<22>Բ<EFBFBD><D4B2>𣬵<EFBFBD>¼ʧ<C2BC>ܣ<EFBFBD><DCA3><EFBFBD>ȷ<EFBFBD><C8B7>");
loginfrom.Dispose();
}
ed.WriteMessage("\n");
}
private void loginbutton2_Click(object sender, EventArgs e)
{
loginfrom.Hide();
loginfrom.Dispose();
}
bool hadlogin = false;
[CommandMethod("OPEN_FROM_TC")]
public void openformtc()
{
if (loginuser != null)
{
hadlogin = true;
}
else
login();
//if (hadlogin == false)
//{
// string tempdir = System.Environment.GetEnvironmentVariable("TEMP").ToString();
// string loginfile = tempdir + "\\login.ini";
// if (File.Exists(loginfile))
// {
// StreamReader sr = new StreamReader(loginfile);
// string line;
// if ((line = sr.ReadLine()) != null)
// {
// string[] ans = line.Split('|');
// for (int i = 0; i < ans.Length; i++)
// {
// if (i == 0)
// serveraddress = ans[i].ToString();
// if (i == 1)
// username = ans[i].ToString();
// if (i == 2)
// password = ans[i].ToString();
// if (i == 3)
// usergroup = ans[i].ToString();
// if (i == 4)
// userrole = ans[i].ToString();
// }
// if ((line = sr.ReadLine()) != null)
// {
// if (line == "#")
// {
// Teamcenter.ClientX.Session session = new Teamcenter.ClientX.Session(serveraddress);
// try
// {
// loginuser = session.mylogin(username, password, usergroup, userrole);
// }
// catch (InvalidCredentialsException e)
// {
// ed.WriteMessage("<22>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>¼");
// return;
// }
// if (loginuser != null)
// hadlogin = true;
// }
// }
// }
// sr.Close();
// }
// else
// {
// login();
// }
//}
if (hadlogin == true)
{
openfrom = new OpenFromTC();
openfrom.appodc = appodc;
openfrom.user = loginuser;
openfrom.button1.Click += new System.EventHandler(this.openbutton1_Click);
openfrom.button2.Click += new System.EventHandler(this.openbutton2_Click);
openfrom.Activate();
openfrom.Show();
}
}
private void openbutton1_Click(object sender, EventArgs e)
{
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
Reservation res = ReservationService.getService(Session.getConnection());
Editor ed1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
TreeNode nownode = this.openfrom.treeView1.SelectedNode;
if (nownode.SelectedImageIndex == 0)
{
List<ALLOBJECT> datasetlist = this.openfrom.datasetlist;
foreach (ALLOBJECT perobject in datasetlist)
{
if (perobject.treenode.Equals(nownode))
{
this.openfrom.textBox1.Text = perobject.name;
DialogResult isopen = MessageBox.Show("<22><><EFBFBD>Ƿ<EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>򿪸<EFBFBD>ͼֽ<CDBC><D6BD>", "<22><>ʾ", 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 moresult = MessageBox.Show("<22><>û<EFBFBD><C3BB><EFBFBD>޸<EFBFBD>Ȩ<EFBFBD>ޣ<EFBFBD><DEA3>Ƿ<EFBFBD><C7B7><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>ʽ<EFBFBD>򿪣<EFBFBD>", "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (moresult == DialogResult.Yes)
{
hasRight = false;
}
else
{
return;
}
}
if (mydateset.Is_modifiable)
{
DialogResult moresult = MessageBox.Show("<22>Ƿ<EFBFBD>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD>", "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (moresult == DialogResult.Yes)
{
if (mydateset.Checked_out == "Y")
{
MessageBox.Show("<22>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>ļ<EFBFBD>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD>ִ<EFBFBD>д˲<D0B4><CBB2><EFBFBD>");
return;
}
else
{
ModelObject[] dataobj = { mydateset };
res.Checkout(dataobj, "", "");
ed1.WriteMessage("<22>ļ<EFBFBD><C4BC><EFBFBD>ǩ<EFBFBD><C7A9>");
ed1.WriteMessage("\n");
}
}
}
ModelObject[] dsfilevec = mydateset.Ref_list;
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>:" + dsfilevec.Length);
ed1.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);
ed1.WriteMessage(<><C2B7>:" + dsfile.Relative_directory_path + "\n");
ed1.WriteMessage("<22>ļ<EFBFBD><C4BC><EFBFBD>:" + dsfile.Original_file_name + "\n");
string newfilename = dsfile.Original_file_name;
ed1.WriteMessage("Original_file_name : "+newfilename+"\n");
string tempdir = System.Environment.GetEnvironmentVariable("TEMP").ToString();
ed1.WriteMessage("TEMP:" + tempdir.ToString() + "\n");
FileManagementService fmService = FileManagementService.getService(Teamcenter.ClientX.Session.getConnection());
ImanFile[] objects2 = { dsfile };
FileTicketsResponse tickets = fmService.GetFileReadTickets(objects2);
ed1.WriteMessage("tickets : " + tickets.Tickets.Count + "\n");
foreach (System.Collections.DictionaryEntry ticket in tickets.Tickets)
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>" + ticket.Key + "\n" + <><D6B5>" + 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();
ed1.WriteMessage("<22>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + fileinfovec.Length + "\n");
FileInfo file = fileinfovec[0];
//ed.WriteMessage("file.DirectoryName:" + file.DirectoryName + "\n");
//ed.WriteMessage("file.FullName" + file.FullName + "\n");
//string datestring = "";
//datestring = DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");//19
string newtempfile = tempdir + "\\" + newfilename;
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>" + newtempfile + "\n");
System.IO.File.Copy(file.FullName, newtempfile, true);
System.IO.File.SetAttributes(newtempfile, FileAttributes.Normal);
this.openfrom.Hide();
this.openfrom.Dispose();
if (File.Exists(newtempfile))
{
DocumentCollection acdocmgr1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
acdocmgr1.Open(newtempfile, false);
//Object pdata = newtempfile;
//acdocmgr.ExecuteInApplicationContext(c_back,pdata);
//Teamcenter.ClientX.Session session = new Teamcenter.ClientX.Session(serveraddress);
//loginuser = session.mylogin(username, password, usergroup, userrole);
}
else
{
ed1.WriteMessage("<22>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ʱĿ¼<C4BF>²<EFBFBD><C2B2><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>ļ<EFBFBD>\n");
}
break;
}
}
}
else
{
ed1.WriteMessage("<22><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>\n");
MessageBox.Show("<22><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>");
return;
}
}
private void openbutton2_Click(object sender, EventArgs e)
{
this.openfrom.Hide();
this.searchfrom = new Search();
this.searchfrom.appdoc = appodc;
this.searchfrom.user = loginuser;
this.searchfrom.xmlpath = xmlpath;
this.searchfrom.Activate();
this.searchfrom.Show();
this.openfrom.Dispose();
}
private void c_back(Object data)
{
DocumentCollection acdocmgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
if (acdocmgr.IsApplicationContext)
{
acdocmgr.Open(Convert.ToString(data));
}
}
[CommandMethod("SAVE_AS")]
public void saveas()
{
savetotc();
}
[CommandMethod("SAVE_TO_TC")]
public void savetotc()
{
//Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute(string.Format("{0}", "QSAVE"), true, false, true);
if (loginuser != null)
{
hadlogin = true;
}
else
login();
if (hadlogin)
{
string filename = "";
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
Editor ed1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
OriginTool origintool = new OriginTool();
ed1.WriteMessage("\n<><6E>ʼ<EFBFBD><CABC>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ...\n");
/************************************************************************/
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݵĴ<DDB5><C4B4><EFBFBD> */
/************************************************************************/
ArrayList btllist = new ArrayList();
OriginReadXml readxml = new OriginReadXml();
btllist = readxml.OriginReadBTLXML(xmlpath);
for (int i = 0; i < btllist.Count; i++)
{
OriginBTL onebtlinfo = (OriginBTL)btllist[i];
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>" + onebtlinfo.Btlname + "\n");
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ:" + "\n");
foreach (DictionaryEntry de in onebtlinfo.Btldatatable)
{
ed1.WriteMessage("CAD<41><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"+de.Key + "\tCAD<41><44><EFBFBD><EFBFBD>ֵ:"+de.Value+
"\tTC<54><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" + onebtlinfo.Btltctable[de.Key] +
"\tTCϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>:" + onebtlinfo.Btltypetable[de.Key] +
"\t<><74>д<EFBFBD><D0B4>" + onebtlinfo.Btlwritetable[de.Key] + "\n");
}
}
ed1.WriteMessage("<22><>ʼ<EFBFBD><CABC>ȡ<EFBFBD><C8A1>ϸ<EFBFBD><CFB8><EFBFBD><EFBFBD>Ϣ...\n");
List<OriginMXL> mxllist = new List<OriginMXL>();
mxllist = readxml.OriginReadMXLXML(xmlpath);
for (int i = 0; i < mxllist.Count;i++ )
{
OriginMXL mxlinfo = mxllist[i];
ed1.WriteMessage("<22><>ϸ<EFBFBD><CFB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>" + mxlinfo.Mxlname + "\n");
ed1.WriteMessage("<22><>ϸ<EFBFBD><CFB8>"+i+"<22><>ϸ<EFBFBD><CFB8>Ϣ:" + "\n");
foreach (DictionaryEntry de in mxlinfo.Mxldatatable)
{
ed1.WriteMessage("CAD<41><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + de.Key + "\tCAD<41><44><EFBFBD><EFBFBD>ֵ:"+de.Value+
"\tTC<54><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:"+mxlinfo.Mxltctable[de.Key]+
"\tis_bomline:"+mxlinfo.Mxlisbomtable[de.Key]+
"\twritable:"+mxlinfo.Mxlupdatetable[de.Key]+"\n");
}
}
ed1.WriteMessage("<22><>ϸ<EFBFBD><CFB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ:" + mxllist.Count);
ed1.WriteMessage("<22><>ʼΪbom<6F><EFBFBD><E1B9B9><EFBFBD><EFBFBD>\n");
mxllist = origintool.sortbomlist(mxllist);
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>...\n");
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int btli = 0; btli < btllist.Count; btli++)
{
OriginBTL btlinfo = (OriginBTL)btllist[btli];
//<2F><><EFBFBD><EFBFBD>item_id<69><64><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>cadͼֽ<CDBC><D6BD>Ϣ
object key = origintool.getKeyFromValue(btlinfo.Btltctable, "item_id");
if (key == null)
{
ed1.WriteMessage("ϵͳû<CDB3><C3BB><EFBFBD>ҵ<EFBFBD>item_id<69><64><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ͼֽ<CDBC><D6BD>Ϣ<EFBFBD><CFA2>ϵͳ<CFB5>ж<EFBFBD>\n");
return;
}
SavedQueryResults found = origintool.getSearchItem(btlinfo.Btldatatable[key].ToString());
if (found != null && found.NumOfObjects > 0)
{
DialogResult upresult = MessageBox.Show("<22>ҵ<EFBFBD><D2B5><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Item<65><6D><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>£<EFBFBD>", "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (upresult == DialogResult.No || upresult == DialogResult.None)
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
return;
}
if (upresult == DialogResult.Yes)
{
for (int i = 0; i < found.NumOfObjects; i++)
{
Item item = found.Objects[i] as Item;
ModelObject[] objects = { item };
String[] attributes = { "item_id", "object_name", "object_string" };
dmService.RefreshObjects(objects);
dmService.GetProperties(objects, attributes);
string item_id = item.Item_id;
string object_name = item.Object_name;
Dataset dataset = null;
GetItemFromIdInfo tempitem = new GetItemFromIdInfo();
tempitem.ItemId = item_id;
GetItemFromIdInfo[] infos = new GetItemFromIdInfo[1];
infos[0] = tempitem;
GetItemFromIdPref pref = new GetItemFromIdPref();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>µķ<C2B5>ʽ
GetItemFromIdResponse infoResp = dmService.GetItemFromId(infos, 1, pref);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3BCB6><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>Ӷ<EFBFBD>Item<65><6D><EFBFBD>Եĸ<D4B5><C4B8><EFBFBD>
if (btlinfo.Btltypetable.ContainsValue("Item"))
{
ed1.WriteMessage("<22><><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD>Item<65><6D><EFBFBD><EFBFBD>\n");
Hashtable itemattrs = new Hashtable();
foreach (DictionaryEntry de in btlinfo.Btltypetable)
{
if (de.Value.ToString() == "Item" && btlinfo.Btlwritetable[de.Key].ToString() == "1" &&
btlinfo.Btlupdatetable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = btlinfo.Btldatatable[cadstring].ToString();
string tcstring = btlinfo.Btltctable[cadstring].ToString();
itemattrs.Add(tcstring, cadvalue);
}
}
if (itemattrs.Count > 0)
{
ServiceData itemupdateresponse = dmService.SetDisplayProperties(objects, itemattrs);
if (itemupdateresponse.sizeOfPartialErrors() <= 0)
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>Item<65><6D><EFBFBD>Գɹ<D4B3>\n");
}
}
}
for (int j = 0; j < infoResp.Output.Length; j++)
{
ModelObject[] objects1 = { infoResp.Output[j].Item };
String[] attributes1 = { "revision_list", "is_modifiable" };
dmService.RefreshObjects(objects1);
dmService.GetProperties(objects1, attributes1);
ModelObject[] revlist = infoResp.Output[j].Item.Revision_list;
dmService.RefreshObjects(revlist);
ItemRevision itemRev = null;
string rev_id = "";
for (int k = 0; k < revlist.Length; k++)
{
itemRev = revlist[k] as ItemRevision;
ModelObject[] objects2 = { itemRev };
String[] attributes2 = { "item_revision_id", "is_modifiable" ,
"checked_out","item_id","release_status_list",
"IMAN_master_form_rev"};
dmService.RefreshObjects(objects2);
dmService.GetProperties(objects2, attributes2);
//<2F>ж<EFBFBD>ͼֽ<CDBC><D6BD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˰汾<CBB0><E6B1BE>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˰汾<CBB0><E6B1BE>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>İ汾<C4B0><E6B1BE><EFBFBD><EFBFBD><EFBFBD>򣬴<EFBFBD><F2A3ACB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>°汾
if (btlinfo.Btltctable.ContainsValue("item_revision_id"))
{
if (itemRev.Item_revision_id == btlinfo.Btldatatable[origintool.getKeyFromValue(btlinfo.Btltctable, "item_revision_id")].ToString())
{
break;
}
}
}
if (itemRev == null)
{
ed1.WriteMessage("Itemû<6D>ж<EFBFBD>Ӧ<EFBFBD>汾\n");
return;
}
rev_id = itemRev.Item_revision_id;
ReleaseStatus[] releaselist = itemRev.Release_status_list;
if (!itemRev.Is_modifiable)
{
MessageBox.Show("ItemRevisionΪֻ<CEAA><D6BB>,<2C><>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD>Ȩ<EFBFBD><C8A8>!");
return;
}
if (releaselist.Length > 0)
{
string message = "Item IDΪ" + itemRev.Item_id + "<22><><EFBFBD><EFBFBD><EFBFBD>°汾<C2B0>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD>";
MessageBox.Show(message);
return;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3BCB6>Ҫ<EFBFBD><D2AA><EFBFBD>Ӷ԰汾<D4B0><E6B1BE><EFBFBD>Եĸ<D4B5><C4B8><EFBFBD>
if (btlinfo.Btltypetable.ContainsValue("ItemRevision"))
{
ed1.WriteMessage("<22><><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD>ItemRevision<6F><6E><EFBFBD><EFBFBD>\n");
Hashtable itemRevattrs = new Hashtable();
ModelObject[] olditemRev = new ModelObject[1];
olditemRev[0] = itemRev;
foreach (DictionaryEntry de in btlinfo.Btltypetable)
{
if (de.Value.ToString() == "ItemRevision" && btlinfo.Btlwritetable[de.Key].ToString() == "1" &&
btlinfo.Btlupdatetable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = btlinfo.Btldatatable[cadstring].ToString();
string tcstring = btlinfo.Btltctable[cadstring].ToString();
itemRevattrs.Add(tcstring, cadvalue);
}
}
if (itemRevattrs.Count > 0)
{
ServiceData itemupdateresponse = dmService.SetDisplayProperties(olditemRev, itemRevattrs);
if (itemupdateresponse.sizeOfPartialErrors() <= 0)
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>ItemRevision<6F><6E><EFBFBD>Գɹ<D4B3>\n");
}
}
}
//<2F><><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>Ϣ
FormInfo forminfo = new FormInfo();
FormInfo[] forminfo_vec = new FormInfo[1];
ModelObject[] form_vec;
form_vec = itemRev.IMAN_master_form_rev;
for (int k = 0; k < form_vec.Length; k++)
{
//Type myType = form_vec[k].GetType();
//string fType = myType.Name;
Form form = form_vec[k] as Form;
bool frash = false;
string[] props = new string[1];
Hashtable formAttrs = new Hashtable();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Form<72><6D><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD>
if (btlinfo.Btltypetable.ContainsValue("Form"))
{
foreach (DictionaryEntry de in btlinfo.Btltypetable)
{
if (de.Value.ToString() == "Form" && btlinfo.Btlwritetable[de.Key].ToString() == "1" &&
btlinfo.Btlupdatetable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = btlinfo.Btldatatable[cadstring].ToString();
string tcstring = btlinfo.Btltctable[cadstring].ToString();
string writestring = btlinfo.Btlwritetable[cadstring].ToString();
ed1.WriteMessage(<><C8A1><EFBFBD><EFBFBD>" + tcstring + "\n");
props[0] = tcstring;
ServiceData serviceData = dmService.GetProperties(form_vec, props);
if (serviceData.sizeOfPartialErrors() > 0)
{
continue;
}
Property my_prop = form_vec[k].GetProperty(tcstring);
if (cadvalue != my_prop.StringValue)
{
if (my_prop.StringValue == "")
frash = true;
else
{
string message = "<22><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼֽ:" + cadstring + "<22><><EFBFBD><EFBFBD>ֵ" + cadvalue + "<22><>ϵͳ<CFB5><CDB3>:" + tcstring + "<22><><EFBFBD><EFBFBD>ֵ" + my_prop.StringValue + "<22><>һ<EFBFBD><D2BB>,<2C>Ƿ񸲸<C7B7>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?";
DialogResult updateresult = MessageBox.Show(message, "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (updateresult == DialogResult.Yes)
{
frash = true;
}
}
string[] formAttrValue = new string[1];
formAttrValue[0] = "";
if (frash)
formAttrValue[0] = cadvalue;
else
formAttrValue[0] = my_prop.StringValue;
ed1.WriteMessage(tcstring + ":" + formAttrValue[0] + "\n");
formAttrs.Add(tcstring, formAttrValue);
props[0] = "";
}
}
}
}
ed1.WriteMessage("formAttrs:" + formAttrs.Count + "\n");
foreach (DictionaryEntry hash in formAttrs)
{
ed1.WriteMessage(hash.Key + ":" + Convert.ToString(hash.Value) + "\n");
}
forminfo.AttributesMap = formAttrs;
forminfo.ClientId = "1";
forminfo.Description = "";
forminfo.FormObject = (Form)form;
forminfo.Name = item_id + "/" + rev_id;
forminfo.ParentObject = null;
forminfo.RelationName = "IMAN_master_form";
forminfo.SaveDB = true;
forminfo.FormType = "ItemRevision Master";
forminfo_vec[0] = forminfo;
try
{
ed1.WriteMessage("<22><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>\n");
Teamcenter.Services.Strong.Core._2007_01.DataManagement.CreateOrUpdateFormsResponse formResp =
dmService.CreateOrUpdateForms(forminfo_vec);
ModelObject[] respon = { formResp.ServiceData.GetUpdatedObject(0) };
dmService.RefreshObjects(respon);
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
}
catch (ServiceException ex)
{
ed1.WriteMessage(ex.Message);
}
}
ed1.WriteMessage("=======<3D><><EFBFBD>ݼ<EFBFBD>=========\n");
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>,<2C><><EFBFBD><EFBFBD>type refname separator
OriginReadXml originreadxml = new OriginReadXml();
OriginDataSet datasetinfo = originreadxml.OriginReadDataSetXML(xmlpath);
datasetinfo = origintool.GetDataSetInfo(datasetinfo, btlinfo);
ed1.WriteMessage(<><D7BC><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
bool findDateset = false;
bool neworupdate = false;
Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsPref
myPref = new Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsPref();
Teamcenter.Services.Strong.Core._2007_06.DataManagement.RelationAndTypesFilter2
myFilter = new Teamcenter.Services.Strong.Core._2007_06.DataManagement.RelationAndTypesFilter2();
myFilter.RelationName = "IMAN_specification";
string[] typeVec = new string[1];
typeVec[0] = datasetinfo.Datatype;
myFilter.ObjectTypeNames = typeVec;
myPref.ExpItemRev = false;
Teamcenter.Services.Strong.Core._2007_06.DataManagement.RelationAndTypesFilter2[] myFilterVec = { myFilter };
myPref.Info = myFilterVec;
ModelObject[] primaryObjects = { itemRev };
Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsResponse
myResp = dmService.ExpandGRMRelationsForPrimary(primaryObjects, myPref);
if (myResp.Output.Length > 0)
{
for (int k = 0; k < myResp.Output.Length; k++)
{
Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsOutput
grmOutput = myResp.Output[k];
for (int l = 0; l < grmOutput.OtherSideObjData.Length; l++)
{
ExpandGRMRelationsData otherSideData = grmOutput.OtherSideObjData[l];
if (otherSideData.OtherSideObjects.Length > 0)
{
for (int m = 0; m < otherSideData.OtherSideObjects.Length; m++)
{
Dataset tempDataset;
//Teamcenter.Soa.Client.Model.ServiceData sData;
tempDataset = otherSideData.OtherSideObjects[m] as Dataset;
string ds_name = tempDataset.Object_string;
if (ds_name == datasetinfo.Ds_name)
{
findDateset = true;
dataset = otherSideData.OtherSideObjects[m] as Dataset;
ed1.WriteMessage("<22>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>ݼ<EFBFBD>!\n");
break;
}
}
//if (!findDateset)
//{
// DialogResult updateornewdialog = MessageBox.Show("<22><>Item<65>Ѵ<EFBFBD><D1B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
// if (updateornewdialog == DialogResult.Yes)
// {
// }
//}
}
}
}
}
//<2F>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>
if (findDateset)
{
bool ischeckout = false;
try
{
ModelObject[] objects2 = { dataset };
String[] attributes2 = { "is_modifiable", "checked_out", "checked_out_user" };
dmService.RefreshObjects(objects2);
dmService.GetProperties(objects2, attributes2);
if (!dataset.Is_modifiable)
{
MessageBox.Show("<22><><EFBFBD>򿪵<EFBFBD>ͼֽ״̬Ϊֻ<CEAA><D6BB>,<2C><><EFBFBD>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><E6B5BD>ϵͳ!");
return;
}
User checkuserinfo = dataset.Checked_out_user as User;
if (checkuserinfo != null)
{
if (checkuserinfo.Uid != loginuser.Uid)
{
MessageBox.Show("<22><>ͼֽ<CDBC>ѱ<EFBFBD><D1B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ǩ<EFBFBD><C7A9>,<2C>޷<EFBFBD><DEB7><EFBFBD><EFBFBD>浽ϵͳ!");
return;
}
}
if (dataset.Checked_out == "Y")
ischeckout = true;
}
catch (NotLoadedException ex)
{
ed1.WriteMessage(ex.Message);
}
Reservation res = ReservationService.getService(Session.getConnection());
//string comment = "", changeId = "";
//ModelObject[] ds_object = new ModelObject[1];
//ds_object[0] = dataset;
ModelObject[] dsFileVec = null;
//ed1.WriteMessage("=======22<32><32><EFBFBD>ݼ<EFBFBD>22=========");
try
{
ModelObject[] objects2 = { dataset };
String[] attributes2 = { "ref_list" };
dmService.RefreshObjects(objects2);
dmService.GetProperties(objects2, attributes2);
dsFileVec = dataset.Ref_list;
}
catch (NotLoadedException ex)
{
ed1.WriteMessage(ex.Message);
}
ImanFile dsfile = dsFileVec[0] as ImanFile;
ModelObject[] objects3 = { dsfile };
String[] attributes3 = { "relative_directory_path", "original_file_name" };
dmService.RefreshObjects(objects3);
dmService.GetProperties(objects3, attributes3);
filename = dsfile.Original_file_name;
//ed1.WriteMessage("=======33<33><33><EFBFBD>ݼ<EFBFBD>33=========\n");
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();
DocumentCollection inacdocmgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
ed1.WriteMessage("<22><>ǰ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>" + inacdocmgr.MdiActiveDocument.Name + "\n");
//inacdocmgr.MdiActiveDocument.Database.SaveAs(inacdocmgr.MdiActiveDocument.Name, DwgVersion.Current);
//inacdocmgr.MdiActiveDocument.SendStringToExecute("QSAVE", true, false, true);
//string tempdir = System.Environment.GetEnvironmentVariable("TEMP").ToString();
//string tempfilename = "";
//if (inacdocmgr.MdiActiveDocument.Name.IndexOf("temp") == 0)
//{
// tempfilename = inacdocmgr.MdiActiveDocument.Name.Substring(23);
//}
//else
//{
// tempfilename = inacdocmgr.MdiActiveDocument.Name;
//}
Document acdoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
acdoc.Database.SaveAs(acdoc.Name, true, DwgVersion.Current, acdoc.Database.SecurityParameters);
string mdiactivefile = acdoc.Name;
fileInfo.FileName = mdiactivefile;
fileInfo.AllowReplace = true;
fileInfo.IsText = false;
fileInfo.NamedReferencedName = datasetinfo.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;
//ed1.WriteMessage("=======44<34><34><EFBFBD>ݼ<EFBFBD>44=========");
Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData[] inputs = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData[1];
inputs[0] = inputData;
FileManagementUtility fMSFileManagement = new FileManagementUtility(Session.getConnection());
ServiceData response = fMSFileManagement.PutFiles(inputs);
if (response.sizeOfPartialErrors() > 0)
ed1.WriteMessage("FileManagementService upload returned partial errors:" + response.sizeOfPartialErrors());
ModelObject[] datasets = new ModelObject[1];
datasets[0] = dataset;
if (ischeckout)
res.Checkin(datasets);
dmService.RefreshObjects(datasets);
//datasets[0] = inputs[0].Dataset;
//dmService.DeleteObjects(datasets);
//fMSFileManagement.Term();
ed1.WriteMessage("DateSet check in successful\n");
}
else
{
Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties
oneDatasetProp = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties();
Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties[]
dataset_vec = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties[1];
oneDatasetProp.ClientId = "datasetWriteTixTestClientId";
oneDatasetProp.Type = datasetinfo.Datatype;
oneDatasetProp.Name = datasetinfo.Ds_name;
oneDatasetProp.Description = "";
oneDatasetProp.Container = null;
dataset_vec[0] = oneDatasetProp;
Teamcenter.Services.Strong.Core._2006_03.DataManagement.CreateDatasetsResponse
dsResp = dmService.CreateDatasets(dataset_vec);
Dataset createdataset = dsResp.Output[0].Dataset;
//create relationship
Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship[]
rela_vec = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship[1];
Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship
one_rela = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship();
one_rela.ClientId = "";
one_rela.PrimaryObject = itemRev;
one_rela.SecondaryObject = createdataset;
one_rela.RelationType = "IMAN_specification";
one_rela.UserData = null;
rela_vec[0] = one_rela;
Teamcenter.Services.Strong.Core._2006_03.DataManagement.CreateRelationsResponse
reResp = dmService.CreateRelations(rela_vec);
ed1.WriteMessage("<22><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!\n");
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();
DocumentCollection inacdocmgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
//inacdocmgr.MdiActiveDocument.Database.SaveAs(inacdocmgr.MdiActiveDocument.Name, DwgVersion.Current);
//inacdocmgr.MdiActiveDocument.SendStringToExecute("QSAVE", true, false, true);
ed1.WriteMessage("<22><>ǰ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>" + inacdocmgr.MdiActiveDocument.Name + "\n");
Document acdoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
acdoc.Database.SaveAs(acdoc.Name, true, DwgVersion.Current, acdoc.Database.SecurityParameters);
string mdiactivefile = acdoc.Name;
fileInfo.FileName = mdiactivefile;
fileInfo.AllowReplace = true;
fileInfo.IsText = false;
fileInfo.NamedReferencedName = datasetinfo.Refname;
fileInfos[0] = fileInfo;
Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData inputData = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData();
inputData.Dataset = createdataset;
inputData.CreateNewVersion = false;
inputData.DatasetFileInfos = fileInfos;
Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData[] inputs = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData[1];
inputs[0] = inputData;
FileManagementUtility fMSFileManagement = new FileManagementUtility(Session.getConnection());
ServiceData response = fMSFileManagement.PutFiles(inputs);
if (response.sizeOfPartialErrors() > 0)
ed1.WriteMessage("FileManagementService upload returned partial errors:" + response.sizeOfPartialErrors());
ed1.WriteMessage("DateSet check in successful\n");
ModelObject[] datasets = new ModelObject[1];
datasets[0] = createdataset;
dmService.RefreshObjects(datasets);
dataset = createdataset;
}
//<2F><><EFBFBD><EFBFBD>BOM
if (mxllist.Count > 0)
{
DialogResult flushbomresult = MessageBox.Show("<22>Ƿ<EFBFBD>ˢ<EFBFBD><CBA2>BOM", "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (flushbomresult == DialogResult.Yes)
{
Folder aimFolder = null;
WorkspaceObject[] object_vec = new WorkspaceObject[1];
object_vec[0] = item;
Teamcenter.Services.Strong.Core._2007_01.DataManagement.WhereReferencedResponse
refResp = dmService.WhereReferenced(object_vec, 1);
Teamcenter.Services.Strong.Core._2007_01.DataManagement.WhereReferencedOutput[]
refOutput = refResp.Output;
for (int u = 0; u < refOutput.Length; u++)
{
Teamcenter.Services.Strong.Core._2007_01.DataManagement.WhereReferencedInfo[]
info = refOutput[u].Info;
for (int p = 0; p < info.Length; p++)
{
Teamcenter.Services.Strong.Core._2007_01.DataManagement.WhereReferencedInfo
it_info = info[p];
string type = it_info.Referencer.Object_type;
if (type.Contains("Folder"))
{
aimFolder = it_info.Referencer as Folder;
ed1.WriteMessage("<22>ҵ<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>\n");
break;
}
}
}
if (aimFolder == null)
CreateBomStructure(itemRev, dataset, mxllist, null);
else
CreateBomStructure(itemRev, dataset, mxllist, aimFolder);
}
}
}//for
}
}
}
else
{
this.savefrom = new SaveToTC();
this.savefrom.appdoc = appodc;
this.savefrom.user = loginuser;
this.savefrom.btlinfo = btlinfo;
this.savefrom.bomlist = mxllist;
this.savefrom.xmlpath = xmlpath;
this.savefrom.button1.Click += new EventHandler(savebutton1_Click);
this.savefrom.Activate();
this.savefrom.Show();
}
}
}
}
/************************************************************************
* 2012-7-3 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* add by raywei
* function used by savetotc
* <20><><EFBFBD>߼<EFBFBD><DFBC><EFBFBD>
* <20><><EFBFBD><EFBFBD>ITEMʱ<4D><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>Դ<EFBFBD><D4B4>ϵͳ<CFB5>ж<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>item<65>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
* 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1> <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><><C4A3>ID <20>ָ<EFBFBD><D6B8>ַ<EFBFBD><D6B7><EFBFBD>
* 2<><32><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>item<65><6D><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>ö<EFBFBD>Ӧģ<D3A6><C4A3>ID<49><44><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>ID<49>ҵ<EFBFBD>ϵͳITEM
* 3<><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Item<65><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>
* 4<><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC>ļ<EFBFBD>
* 5<><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ITEM
* 6<><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>ݼ<EFBFBD>
* 7<><37><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
************************************************************************/
public void updateItemDataSet( Editor ed1, BTLClass btlinfo,
ItemRevision itemrevision, DataManagementService dmService, string rev_id)
{
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
Tool tool = new Tool();
Hashtable pre = tool.getTCPreferences("DFHM_dstype");
string[] prevalues = (string[])pre["DFHM_dstype"];
if (prevalues.Length <= 0)
{
ed1.WriteMessage("<22><>ѡ<EFBFBD><D1A1>DFHM_dstype<70><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
}
for (int i = 0; i < prevalues.Length; i++)
{
ed1.WriteMessage(prevalues[i].ToString() + "\n");
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>WORD<52><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>Item<65>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>WORD<52><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>\n");
bool hasWordDS = checkHasWord(itemrevision, dmService);
if (hasWordDS)
{
ed1.WriteMessage("Item<65>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>WORD<52><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>\n");
}
else
{
ed1.WriteMessage("Item<65><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WORD<52><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>\n");
//<2F><>ȡ<EFBFBD><C8A1>Ӧģ<D3A6><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
ed1.WriteMessage("<22><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD>Ӧģ<D3A6><C4A3>ID\n");
string DMTitemid = tool.getCorrespondItemID(tool.initItemType(btlinfo.Item_id, btlinfo.Materialgrade).Trim(), prevalues);
string DMTFilepath = "";
if (DMTitemid != null && DMTitemid != "")
{
SavedQueryResults found = tool.getSearchItem(DMTitemid);
//<2F>ҵ<EFBFBD>ģ<EFBFBD><C4A3>item
ed1.WriteMessage("<22>ҵ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
if (found.NumOfObjects > 0 && found != null)
{
Item DMTItem = found.Objects[0] as Item;
DMTFilepath = downloadfile(DMTItem);
ed1.WriteMessage(<><C4A3><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>·<EFBFBD><C2B7>" + DMTFilepath + "\n");
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
if (DMTFilepath != "")
{
bool uploadresult = uploadfile(DMTFilepath, btlinfo.Item_id + "/" + rev_id, itemrevision);
if (uploadresult)
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>ɹ<EFBFBD>\n");
}
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>MSWORD<52><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>
public bool checkHasWord(ItemRevision itemrevision,DataManagementService dmService)
{
bool hasWordDS = false;
Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsPref
myPref = new Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsPref();
Teamcenter.Services.Strong.Core._2007_06.DataManagement.RelationAndTypesFilter2
myFilter = new Teamcenter.Services.Strong.Core._2007_06.DataManagement.RelationAndTypesFilter2();
myFilter.RelationName = "IMAN_specification";
string[] typeVec = new string[1];
typeVec[0] = "MSWord";
myFilter.ObjectTypeNames = typeVec;
myPref.ExpItemRev = false;
Teamcenter.Services.Strong.Core._2007_06.DataManagement.RelationAndTypesFilter2[] myFilterVec = { myFilter };
myPref.Info = myFilterVec;
ModelObject[] primaryObjects = { itemrevision };
Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsResponse
myResp = dmService.ExpandGRMRelationsForPrimary(primaryObjects, 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 == "MSWord")
{
hasWordDS = true;
}
}
}
}
return hasWordDS;
}
/************************************************************************
* 2012-2-13
* add by raywei
* function used by savebutton1_Click
* <20><><EFBFBD>߼<EFBFBD><DFBC><EFBFBD>
* <20><><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD>ITEMʱ<4D><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>Դ<EFBFBD><D4B4>ϵͳ<CFB5>ж<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>item<65>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>
* 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1> <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><><C4A3>ID <20>ָ<EFBFBD><D6B8>ַ<EFBFBD><D6B7><EFBFBD>
* 2<><32><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>item<65><6D><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>ö<EFBFBD>Ӧģ<D3A6><C4A3>ID<49><44><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>ID<49>ҵ<EFBFBD>ϵͳITEM
* 3<><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Item<65><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>
* 4<><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC>ļ<EFBFBD>
* 5<><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ITEM
* 6<><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>ݼ<EFBFBD>
* 7<><37><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
************************************************************************/
/************************************************************************
* 2012-2-13
* add by raywei
* <20><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>·<EFBFBD><C2B7>
************************************************************************/
public string downloadfile(Item DMTItem)
{
string DMTFilepath = "";
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
Editor ed1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
ModelObject[] itemrevisionlist = null;
ModelObject[] objects = { DMTItem };
String[] attributes = { "revision_list" };
dmService.RefreshObjects(objects);
dmService.GetProperties(objects, attributes);
itemrevisionlist = DMTItem.Revision_list;
ItemRevision itemrevision = itemrevisionlist[itemrevisionlist.Length-1] as ItemRevision;
ExpandGRMRelationsPref myPref = new ExpandGRMRelationsPref();
RelationAndTypesFilter2 myFilter = new RelationAndTypesFilter2();
myFilter.RelationName = "IMAN_specification";
String[] typeVec = { "MSWord" };
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 == "MSWord")
{
DataSet dateset = otherSideData.OtherSideObjects[k] as DataSet;
ModelObject[] objects2 = { dateset };
String[] attributes2 = { "is_modifiable", "checked_out", "ref_list" };
dmService.RefreshObjects(objects2);
dmService.GetProperties(objects2, attributes2);
ModelObject[] dsfilevec = dateset.Ref_list;
ImanFile dsfile = dsfilevec[0] as ImanFile;
ModelObject[] objects3 = { dsfile };
String[] attributes3 = { "relative_directory_path", "original_file_name" };
dmService.RefreshObjects(objects3);
dmService.GetProperties(objects3, attributes3);
string newfilename = dsfile.Original_file_name;
ed1.WriteMessage("Original_file_name : " + newfilename + "\n");
string tempdir = System.Environment.GetEnvironmentVariable("TEMP").ToString();
ed1.WriteMessage("TEMP:" + tempdir.ToString() + "\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();
FileInfo file = fileinfovec[0];
DMTFilepath = tempdir + "\\" + newfilename;
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>" + DMTFilepath + "\n");
System.IO.File.Copy(file.FullName, DMTFilepath, true);
System.IO.File.SetAttributes(DMTFilepath, FileAttributes.Normal);
}
}
}
}
return DMTFilepath;
}
//<2F>½<EFBFBD><C2BD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4>ļ<EFBFBD>
public bool uploadfile(string DMTFilepath, string ds_name, ItemRevision rev)
{
bool result = false;
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
Editor ed1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties
oneDatasetProp = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties();
Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties[]
dataset_vec = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties[1];
oneDatasetProp.ClientId = "datasetWriteTixTestClientId";
oneDatasetProp.Type = "MSWord";
oneDatasetProp.Name = ds_name;
ed1.WriteMessage("ds_name===="+ds_name+"\n");
oneDatasetProp.Description = "";
oneDatasetProp.Container = null;
dataset_vec[0] = oneDatasetProp;
Teamcenter.Services.Strong.Core._2006_03.DataManagement.CreateDatasetsResponse
dsResp = dmService.CreateDatasets(dataset_vec);
Dataset createdataset = dsResp.Output[0].Dataset;
//create relationship
Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship[]
rela_vec = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship[1];
Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship
one_rela = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship();
one_rela.ClientId = "AppX-myTest";
one_rela.PrimaryObject = rev;
one_rela.SecondaryObject = createdataset;
one_rela.RelationType = "IMAN_specification";
one_rela.UserData = null;
rela_vec[0] = one_rela;
Teamcenter.Services.Strong.Core._2006_03.DataManagement.CreateRelationsResponse
reResp = dmService.CreateRelations(rela_vec);
ed1.WriteMessage("<22><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!\n");
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 = DMTFilepath;
ed1.WriteMessage("fileInfo.FileName===" + fileInfo.FileName+"\n");
fileInfo.AllowReplace = true;
fileInfo.IsText = false;
fileInfo.NamedReferencedName = "word";
fileInfos[0] = fileInfo;
Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData inputData = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData();
inputData.Dataset = createdataset;
inputData.CreateNewVersion = false;
inputData.DatasetFileInfos = fileInfos;
Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData[] inputs = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData[1];
inputs[0] = inputData;
FileManagementUtility fMSFileManagement = new FileManagementUtility(Session.getConnection());
ServiceData response = fMSFileManagement.PutFiles(inputs);
if (response.sizeOfPartialErrors() > 0)
ed1.WriteMessage("FileManagementService upload returned partial errors:" + response.sizeOfPartialErrors());
if (response.sizeOfPartialErrors() <= 0)
{
ed1.WriteMessage("DateSet check in successful\n");
result = true;
}
ModelObject[] datasets = new ModelObject[1];
datasets[0] = createdataset;
dmService.RefreshObjects(datasets);
return result;
}
/************************************************************************
* savetotc<74><63><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><E6B0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
************************************************************************/
public void savebutton1_Click(object sender, EventArgs e)
{
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
Reservation res = ReservationService.getService(Session.getConnection());
Editor ed1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
ed1.WriteMessage("==============\n");
OriginTool origintool = new OriginTool();
OriginBTL btlinfo = this.savefrom.btlinfo;
List<OriginMXL> bomlist = this.savefrom.bomlist;
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ITEM<45><4D>" + btlinfo.Btldatatable[origintool.getKeyFromValue(btlinfo.Btltctable, "item_id")].ToString());
ed1.WriteMessage("<22><>ϸ<EFBFBD><CFB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:"+bomlist.Count+"\n");
TreeNode nownode = this.savefrom.treeView1.SelectedNode;
if(nownode.SelectedImageIndex == 1)
{
foreach (ALLOBJECT perobject in this.savefrom.folderlist)
{
if (perobject.treenode.Equals(nownode))
{
ed1.WriteMessage("<22>ҵ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>\n");
Folder folder = perobject.workobject as Folder;
ModelObject[] objects = { folder };
String[] attributes = { "is_modifiable"};
dmService.RefreshObjects(objects);
dmService.GetProperties(objects, attributes);
if (!folder.Is_modifiable)
{
MessageBox.Show("<22><><EFBFBD><EFBFBD>Ŀ¼û<C2BC><C3BB>дȨ<D0B4>ޣ<EFBFBD><DEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>");
return;
}
ItemProperties oneItemProp = new ItemProperties();
CreateItemsResponse itemResp = new CreateItemsResponse();
Teamcenter.Hello.DataManagement hellomanagement = new Teamcenter.Hello.DataManagement();
string itemtype = this.savefrom.comboBox1.Text;
ItemIdsAndInitialRevisionIds[] itemIds = hellomanagement.generateItemIds(1, itemtype);
GetItemCreationRelatedInfoResponse relatedResponse = dmService.GetItemCreationRelatedInfo(itemtype, null);
string[] formTypes = new string[relatedResponse.FormAttrs.Length];
for (int j = 0; j < relatedResponse.FormAttrs.Length; j++)
{
FormAttributesInfo attrInfo = relatedResponse.FormAttrs[j];
formTypes[j] = attrInfo.FormType;
}
ItemProperties[] itemProps = new ItemProperties[itemIds.Length];
ItemProperties itemProperty = new ItemProperties();
for (int j = 0; j < itemIds.Length; j++)
{
ed1.WriteMessage("start Create form in cache!\n");
ModelObject[] forms = hellomanagement.createForms(itemIds[j].NewItemId,
formTypes[0], itemIds[j].NewRevId, formTypes[1], null, false);
ed1.WriteMessage("Create form in cache sucessful!\n");
ed1.WriteMessage("set item properties!\n");
itemProperty.ClientId = "AppX-Test";
itemProperty.ItemId = btlinfo.Btldatatable[origintool.getKeyFromValue(btlinfo.Btltctable, "item_id")].ToString();
if (btlinfo.Btltctable.ContainsValue("item_revision_id"))
itemProperty.RevId = btlinfo.Btldatatable[origintool.getKeyFromValue(btlinfo.Btltctable, "item_revision_id")].ToString();
else
itemProperty.RevId = itemIds[j].NewRevId;
if (btlinfo.Btltctable.ContainsValue("object_name"))
itemProperty.Name = btlinfo.Btldatatable[origintool.getKeyFromValue(btlinfo.Btltctable, "object_name")].ToString();
else
itemProperty.Name = "";
itemProperty.Type = itemtype;
itemProperty.Description = "";
itemProperty.Uom = "EA";
itemProps[j] = itemProperty;
}
try
{
ed1.WriteMessage("start item create!\n");
itemResp = dmService.CreateItems(itemProps, folder, "");
ed1.WriteMessage("create Items: " + btlinfo.Btldatatable[origintool.getKeyFromValue(btlinfo.Btltctable, "item_id")].ToString() + "sucessful!\n");
ItemRevision rev = null;
Item newitem = null;
for (int j = 0; j < itemResp.Output.Length; j++)
{
rev = itemResp.Output[j].ItemRev;
newitem = itemResp.Output[j].Item;
}
//<2F><><EFBFBD>Ӷ<EFBFBD>Item<65><6D><EFBFBD>Եĸ<D4B5><C4B8><EFBFBD>
if (btlinfo.Btltypetable.ContainsValue("Item"))
{
ed1.WriteMessage("<22><><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD>Item<65><6D><EFBFBD><EFBFBD>\n");
Hashtable itemattrs = new Hashtable();
ModelObject[] newitemOBJ = new ModelObject[1];
newitemOBJ[0] = newitem;
foreach (DictionaryEntry de in btlinfo.Btltypetable)
{
if (de.Value.ToString() == "Item" && btlinfo.Btlwritetable[de.Key].ToString() == "1" &&
btlinfo.Btlupdatetable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = btlinfo.Btldatatable[cadstring].ToString();
string tcstring = btlinfo.Btltctable[cadstring].ToString();
itemattrs.Add(tcstring, cadvalue);
}
}
if (itemattrs.Count > 0)
{
ServiceData itemupdateresponse = dmService.SetDisplayProperties(newitemOBJ, itemattrs);
if (itemupdateresponse.sizeOfPartialErrors() <= 0)
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>Item<65><6D><EFBFBD>Գɹ<D4B3>\n");
}
}
}
//<2F><><EFBFBD>Ӷ԰汾<D4B0><E6B1BE><EFBFBD>Եĸ<D4B5><C4B8><EFBFBD>
if (btlinfo.Btltypetable.ContainsValue("ItemRevision"))
{
ed1.WriteMessage("<22><><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD>ItemRevision<6F><6E><EFBFBD><EFBFBD>\n");
Hashtable itemRevattrs = new Hashtable();
ModelObject[] newitemRev = new ModelObject[1];
newitemRev[0] = rev;
foreach (DictionaryEntry de in btlinfo.Btltypetable)
{
if (de.Value.ToString() == "ItemRevision" && btlinfo.Btlwritetable[de.Key].ToString() == "1" &&
btlinfo.Btlupdatetable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = btlinfo.Btldatatable[cadstring].ToString();
string tcstring = btlinfo.Btltctable[cadstring].ToString();
itemRevattrs.Add(tcstring, cadvalue);
}
}
if (itemRevattrs.Count > 0)
{
ServiceData itemupdateresponse = dmService.SetDisplayProperties(newitemRev, itemRevattrs);
if (itemupdateresponse.sizeOfPartialErrors() <= 0)
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>ItemRevision<6F><6E><EFBFBD>Գɹ<D4B3>\n");
}
}
}
//дform<72><6D><EFBFBD><EFBFBD>
FormInfo forminfo = new FormInfo();
FormInfo[] forminfo_vec;
ModelObject[] form_vec = null;
ModelObject[] objects1 = { rev };
String[] attributes1 = { "IMAN_master_form_rev",
"is_modifiable","item_revision_id","item_id"};
dmService.RefreshObjects(objects1);
dmService.GetProperties(objects1, attributes1);
try
{
form_vec = rev.IMAN_master_form_rev;
ed1.WriteMessage("get_IMAN_master_form_rev sucessful!\n");
}
catch (NotLoadedException ex)
{
ed1.WriteMessage(ex.Message);
}
forminfo_vec = new FormInfo[form_vec.Length];
for (int j = 0; j < form_vec.Length; j++)
{
Form form = form_vec[j] as Form;
Hashtable formAttrs = new Hashtable();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Form<72><6D><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD>
if (btlinfo.Btltypetable.ContainsValue("Form"))
{
foreach (DictionaryEntry de in btlinfo.Btltypetable)
{
if (de.Value.ToString() == "Form" && btlinfo.Btlwritetable[de.Key].ToString() == "1" &&
btlinfo.Btlupdatetable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = btlinfo.Btldatatable[cadstring].ToString();
string tcstring = btlinfo.Btltctable[cadstring].ToString();
string writestring = btlinfo.Btlwritetable[cadstring].ToString();
string[] formAttrValue = new string[1];
formAttrValue[0] = "";
formAttrValue[0] = cadvalue;
formAttrs.Add(tcstring, formAttrValue);
}
}
}
forminfo.AttributesMap = formAttrs;
forminfo.ClientId = "1";
forminfo.Description = "";
forminfo.FormObject = form;
forminfo.Name = rev.Item_id + "/" + rev.Item_revision_id;
forminfo.ParentObject = null;
forminfo.RelationName = "IMAN_master_form";
forminfo.SaveDB = true;
forminfo.FormType = "ItemRevision Master";
forminfo_vec[j] = forminfo;
try
{
CreateOrUpdateFormsResponse formResp
= dmService.CreateOrUpdateForms(forminfo_vec);
ed1.WriteMessage("update form attributes sucessful!\n");
}
catch (ServiceException ex)
{
ed1.WriteMessage(ex.Message);
}
}
//string ds_name;
string rev_id = rev.Item_revision_id;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>,<2C><><EFBFBD><EFBFBD>type refname separator
OriginReadXml originreadxml = new OriginReadXml();
OriginDataSet datasetinfo = originreadxml.OriginReadDataSetXML(xmlpath);
datasetinfo = origintool.GetDataSetInfo(datasetinfo, btlinfo);
ed1.WriteMessage(<><D7BC><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties
oneDatasetProp = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties();
Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties[]
dataset_vec = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.DatasetProperties[1];
oneDatasetProp.ClientId = "datasetWriteTixTestClientId";
oneDatasetProp.Type = datasetinfo.Datatype;
oneDatasetProp.Name = datasetinfo.Ds_name;
oneDatasetProp.Description = "";
oneDatasetProp.Container = null;
dataset_vec[0] = oneDatasetProp;
ed1.WriteMessage(<><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>\n");
Teamcenter.Services.Strong.Core._2006_03.DataManagement.CreateDatasetsResponse
dsResp = dmService.CreateDatasets(dataset_vec);
if (dsResp.Output.Length == 0)
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>.xml<6D>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ");
return;
}
Dataset createdataset = dsResp.Output[0].Dataset;
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD>\n");
//create relationship
Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship[]
rela_vec = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship[1];
Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship
one_rela = new Teamcenter.Services.Strong.Core._2006_03.DataManagement.Relationship();
one_rela.ClientId = "";
one_rela.PrimaryObject = rev;
one_rela.SecondaryObject = createdataset;
one_rela.RelationType = "IMAN_specification";
one_rela.UserData = null;
rela_vec[0] = one_rela;
Teamcenter.Services.Strong.Core._2006_03.DataManagement.CreateRelationsResponse
reResp = dmService.CreateRelations(rela_vec);
ed1.WriteMessage("<22><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!\n");
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();
DocumentCollection inacdocmgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
ed1.WriteMessage("<22><>ǰ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>" + inacdocmgr.MdiActiveDocument.Name + "\n");
Document acdoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
acdoc.Database.SaveAs(acdoc.Name, true, DwgVersion.Current, acdoc.Database.SecurityParameters);
string mdiactivefile = acdoc.Name;
fileInfo.FileName = mdiactivefile;
fileInfo.AllowReplace = true;
fileInfo.IsText = false;
fileInfo.NamedReferencedName = datasetinfo.Refname;
fileInfos[0] = fileInfo;
Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData inputData = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData();
inputData.Dataset = createdataset;
inputData.CreateNewVersion = false;
inputData.DatasetFileInfos = fileInfos;
Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData[] inputs = new Teamcenter.Services.Loose.Core._2006_03.FileManagement.GetDatasetWriteTicketsInputData[1];
inputs[0] = inputData;
FileManagementUtility fMSFileManagement = new FileManagementUtility(Session.getConnection());
ServiceData response = fMSFileManagement.PutFiles(inputs);
if (response.sizeOfPartialErrors() > 0)
ed1.WriteMessage("FileManagementService upload returned partial errors:" + response.sizeOfPartialErrors());
ed1.WriteMessage("DateSet check in successful\n");
ModelObject[] datasets = new ModelObject[1];
datasets[0] = createdataset;
dmService.RefreshObjects(datasets);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2>bom
if(bomlist.Count > 0)
{
DialogResult updateresult = MessageBox.Show("<22>Ƿ<EFBFBD>ˢ<EFBFBD><CBA2>BOM", "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (updateresult == DialogResult.No || updateresult == DialogResult.None)
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2>BOM\n");
}
else
{
CreateBomStructure(rev, createdataset, bomlist, folder);
}
}
this.savefrom.Hide();
this.savefrom.Dispose();
}
catch (ServiceException ex)
{
ed1.WriteMessage(ex.Message);
}
}
}
}
else
{
MessageBox.Show("<22><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>ļ<EFBFBD><C4BC>У<EFBFBD>");
return;
}
}
[CommandMethod("LOGOUT")]
public void layout()
{
DialogResult updateresult = MessageBox.Show("<22><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><E6A3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD>Ƿ񱣴棿", "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (updateresult == DialogResult.Yes)
{
savetotc();
}
else
{
loginuser = null;
hadlogin = false;
}
}
[CommandMethod("UPDATE_FROM_TC")]
public void updateFromTc()
{
if (loginuser != null)
{
hadlogin = true;
}
else
login();
if (hadlogin)
{
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
Editor ed1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
OriginTool origintool = new OriginTool();
ed1.WriteMessage("\n<><6E>ʼ<EFBFBD><CABC>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ...\n");
/************************************************************************/
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݵĴ<DDB5><C4B4><EFBFBD> */
/************************************************************************/
ArrayList btllist = new ArrayList();
OriginReadXml readxml = new OriginReadXml();
btllist = readxml.OriginReadBTLXML(xmlpath);
for (int i = 0; i < btllist.Count; i++)
{
OriginBTL onebtlinfo = (OriginBTL)btllist[i];
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>" + onebtlinfo.Btlname + "\n");
ed1.WriteMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8>Ϣ:" + "\n");
foreach (DictionaryEntry de in onebtlinfo.Btldatatable)
{
ed1.WriteMessage("CAD<41><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + de.Key + "\tCAD<41><44><EFBFBD><EFBFBD>ֵ:" + de.Value +
"\tTC<54><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" + onebtlinfo.Btltctable[de.Key] +
"\tTCϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>:" + onebtlinfo.Btltypetable[de.Key] +
"\t<><74>д<EFBFBD><D0B4>" + onebtlinfo.Btlwritetable[de.Key] +
"\t<><74>ͬ<EFBFBD><CDAC>:"+onebtlinfo.Btlfromtctable[de.Key] +"\n");
}
}
for (int btli = 0; btli < btllist.Count; btli++)
{
OriginBTL btlinfo = (OriginBTL)btllist[btli];
//<2F><><EFBFBD><EFBFBD>item_id<69><64><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>cadͼֽ<CDBC><D6BD>Ϣ
object key = origintool.getKeyFromValue(btlinfo.Btltctable, "item_id");
if (key == null)
{
ed1.WriteMessage("ϵͳû<CDB3><C3BB><EFBFBD>ҵ<EFBFBD>item_id<69><64><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ͼֽ<CDBC><D6BD>Ϣ<EFBFBD><CFA2>ϵͳ<CFB5>ж<EFBFBD>\n");
return;
}
SavedQueryResults found = origintool.getSearchItem(btlinfo.Btldatatable[key].ToString());
if (found != null && found.NumOfObjects > 0)
{
DialogResult upresult = MessageBox.Show("<22>ҵ<EFBFBD><D2B5><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Item<65><6D><EFBFBD>Ƿ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>", "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (upresult == DialogResult.No || upresult == DialogResult.None)
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>\n");
return;
}
if (upresult == DialogResult.Yes)
{
for (int i = 0; i < found.NumOfObjects; i++)
{
Item item = found.Objects[i] as Item;
ModelObject[] objects = { item };
String[] attributes = { "item_id", "object_name", "object_string" };
dmService.RefreshObjects(objects);
dmService.GetProperties(objects, attributes);
string item_id = item.Item_id;
GetItemFromIdInfo tempitem = new GetItemFromIdInfo();
tempitem.ItemId = item_id;
GetItemFromIdInfo[] infos = new GetItemFromIdInfo[1];
infos[0] = tempitem;
GetItemFromIdPref pref = new GetItemFromIdPref();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>µķ<C2B5>ʽ
GetItemFromIdResponse infoResp = dmService.GetItemFromId(infos, 1, pref);
//׼<><D7BC>д<EFBFBD><D0B4>CADͼֽ<CDBC>ϵ<EFBFBD><CFB5><EFBFBD>Ϣ
Hashtable tempvaluetable = new Hashtable();
//<2F><>ȡItem<65>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>
if (btlinfo.Btltypetable.ContainsValue("Item"))
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>Item<65><6D><EFBFBD><EFBFBD>\n");
foreach (DictionaryEntry de in btlinfo.Btltypetable)
{
if (de.Value.ToString() == "Item" && btlinfo.Btlfromtctable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = btlinfo.Btldatatable[cadstring].ToString();
string tcstring = btlinfo.Btltctable[cadstring].ToString();
ed1.WriteMessage(<><C8A1><EFBFBD><EFBFBD>" + tcstring + "\n");
string[] props = new string[1];
props[0] = tcstring;
ServiceData serviceData = dmService.GetProperties(objects, props);
if (serviceData.sizeOfPartialErrors() > 0)
{
continue;
}
Property my_prop = item.GetProperty(tcstring);
string tempcadvalue = my_prop.StringValue.ToString();
ed1.WriteMessage("TCϵͳ<CFB5>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>" + tcstring + "ֵΪ <20><>" + tempcadvalue + "\n");
if (cadvalue != tempcadvalue)
{
origintool.TableHasKey(tempvaluetable, cadstring, tempcadvalue);
}
}
}
}
//<2F><><EFBFBD>ð汾<C3B0>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>
for (int j = 0; j < infoResp.Output.Length; j++)
{
ModelObject[] objects1 = { infoResp.Output[j].Item };
String[] attributes1 = { "revision_list", "is_modifiable" };
dmService.RefreshObjects(objects1);
dmService.GetProperties(objects1, attributes1);
ModelObject[] revlist = infoResp.Output[j].Item.Revision_list;
dmService.RefreshObjects(revlist);
ItemRevision itemRev = null;
string rev_id = "";
for (int k = 0; k < revlist.Length; k++)
{
itemRev = revlist[k] as ItemRevision;
}
if (itemRev == null)
{
ed1.WriteMessage("Itemû<6D>ж<EFBFBD>Ӧ<EFBFBD>汾\n");
return;
}
ModelObject[] objects2 = { itemRev };
String[] attributes2 = { "item_revision_id", "is_modifiable" ,
"checked_out","item_id","release_status_list",
"IMAN_master_form_rev"};
dmService.RefreshObjects(objects2);
dmService.GetProperties(objects2, attributes2);
rev_id = itemRev.Item_revision_id;
ReleaseStatus[] releaselist = itemRev.Release_status_list;
if (!itemRev.Is_modifiable)
{
MessageBox.Show("ItemRevisionΪֻ<CEAA><D6BB>,<2C><>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD>Ȩ<EFBFBD><C8A8>!");
return;
}
if (releaselist.Length > 0)
{
string message = "Item IDΪ" + itemRev.Item_id + "<22><><EFBFBD><EFBFBD><EFBFBD>°汾<C2B0>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD>";
MessageBox.Show(message);
return;
}
if (btlinfo.Btltypetable.ContainsValue("ItemRevision"))
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>ItemRevision<6F><6E><EFBFBD><EFBFBD>\n");
foreach (DictionaryEntry de in btlinfo.Btltypetable)
{
if (de.Value.ToString() == "ItemRevision" && btlinfo.Btlfromtctable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = btlinfo.Btldatatable[cadstring].ToString();
string tcstring = btlinfo.Btltctable[cadstring].ToString();
ed1.WriteMessage(<><C8A1><EFBFBD><EFBFBD>" + tcstring + "\n");
string[] props = new string[1];
props[0] = tcstring;
ServiceData serviceData = dmService.GetProperties(objects2, props);
if (serviceData.sizeOfPartialErrors() > 0)
{
continue;
}
Property my_prop = itemRev.GetProperty(tcstring);
string tempcadvalue = my_prop.StringValue.ToString();
ed1.WriteMessage("TCϵͳ<CFB5>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>" + tcstring + "ֵΪ <20><>" + tempcadvalue+"\n");
if (cadvalue != tempcadvalue)
{
origintool.TableHasKey(tempvaluetable, cadstring, tempcadvalue);
}
}
}
}
//<2F><><EFBFBD>ð汾<C3B0><E6B1BE><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>
FormInfo forminfo = new FormInfo();
FormInfo[] forminfo_vec = new FormInfo[1];
ModelObject[] form_vec;
form_vec = itemRev.IMAN_master_form_rev;
dmService.RefreshObjects(form_vec);
for (int k = 0; k < form_vec.Length; k++)
{
Form form = form_vec[k] as Form;
if (btlinfo.Btltypetable.ContainsValue("Form"))
{
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>ItemRevision<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
foreach (DictionaryEntry de in btlinfo.Btltypetable)
{
if (de.Value.ToString() == "Form" && btlinfo.Btlfromtctable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = btlinfo.Btldatatable[cadstring].ToString();
string tcstring = btlinfo.Btltctable[cadstring].ToString();
ed1.WriteMessage(<><C8A1><EFBFBD><EFBFBD>" + tcstring + "\n");
string[] props = new string[1];
props[0] = tcstring;
ServiceData serviceData = dmService.GetProperties(form_vec, props);
if (serviceData.sizeOfPartialErrors() > 0)
{
continue;
}
Property my_prop = form.GetProperty(tcstring);
string tempcadvalue = my_prop.StringValue.ToString();
ed1.WriteMessage("TCϵͳ<CFB5>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>" + tcstring + "ֵΪ <20><>" + tempcadvalue + "\n");
if (cadvalue != tempcadvalue)
{
origintool.TableHasKey(tempvaluetable, cadstring, tempcadvalue);
}
}
}
}
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>Ҫͬ<D2AA><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
foreach (DictionaryEntry de in tempvaluetable)
{
ed1.WriteMessage("CAD<41><44><EFBFBD><EFBFBD>:"+de.Key.ToString()+"\tֵ:"+de.Value.ToString() +"\n");
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>CADͼֽ
origintool.SetTitleInfo(btlinfo.Btlname, tempvaluetable);
}
}
}
}
}
}
public bool CreateBomStructure(ItemRevision parentRev, Dataset parent_ds, List<OriginMXL> bom_Vec, Folder folder)
{
DataManagementService dmService = DataManagementService.getService(Session.getConnection());
Reservation res = ReservationService.getService(Session.getConnection());
Editor ed1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
ed1.WriteMessage("bom_Vec size:" + bom_Vec.Count.ToString() + "\n");
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͹<EFBFBD><CDB9><EFBFBD>
OriginReadXml originreadxml = new OriginReadXml();
OriginTypeRule origintyperule = originreadxml.OriginReadRuleXML(xmlpath);
ItemRevision[] revVec = new ItemRevision[bom_Vec.Count];
ed1.WriteMessage("revVec size:" + revVec.Length.ToString() + "\n");
for (int i = 0; i < bom_Vec.Count; i++)
{
OriginMXL it_bom = bom_Vec[i];
OriginTool origintool = new OriginTool();
if (origintool.getKeyFromValue(it_bom.Mxltctable, "item_id") == null)
{
ed1.WriteMessage("<22><>ϸ<EFBFBD><CFB8><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>item_id\n");
return false;
}
string item_id = it_bom.Mxldatatable[origintool.getKeyFromValue(it_bom.Mxltctable,"item_id")].ToString();
SavedQueryResults found = origintool.getSearchItem(item_id);
if (found.NumOfObjects == 0)
{
//ItemProperties[] item_vec;
//DatasetProperties[] dataset_vec;
ItemProperties oneItemProp = new ItemProperties();
CreateItemsResponse itemResp = new CreateItemsResponse();
Teamcenter.Hello.DataManagement hellomanagement = new Teamcenter.Hello.DataManagement();
//<2F><><EFBFBD><EFBFBD>Item<65><6D><EFBFBD><EFBFBD>
string tempitemtype = origintool.getItemType(it_bom, origintyperule);
ItemIdsAndInitialRevisionIds[] itemIds = hellomanagement.generateItemIds(1, tempitemtype);
GetItemCreationRelatedInfoResponse relatedResponse = dmService.GetItemCreationRelatedInfo(tempitemtype, null);
string[] formTypes = new string[relatedResponse.FormAttrs.Length];
for (int j = 0; j < relatedResponse.FormAttrs.Length; j++)
{
FormAttributesInfo attrInfo = relatedResponse.FormAttrs[j];
formTypes[j] = attrInfo.FormType;
}
ItemProperties[] itemProps = new ItemProperties[itemIds.Length];
ItemProperties itemProperty = new ItemProperties();
for (int j = 0; j < itemIds.Length; j++)
{
ed1.WriteMessage("start Create form in cache!\n");
ModelObject[] forms = hellomanagement.createForms(itemIds[j].NewItemId,
formTypes[0], itemIds[j].NewRevId, formTypes[1],null,false);
ed1.WriteMessage("Create form in cache sucessful!\n");
ed1.WriteMessage("set item properties!\n");
itemProperty.ClientId = "";
itemProperty.ItemId = item_id;
itemProperty.RevId = itemIds[j].NewRevId;
if (it_bom.Mxltctable.ContainsValue("object_name"))
itemProperty.Name = it_bom.Mxldatatable[origintool.getKeyFromValue(it_bom.Mxltctable, "object_name")].ToString();
else
itemProperty.Name = "";
itemProperty.Type = tempitemtype;
itemProperty.Description = "";
itemProperty.Uom = "EA";
itemProps[j] = itemProperty;
}
try
{
ed1.WriteMessage("start item create!\n");
if (folder == null)
itemResp = dmService.CreateItems(itemProps, null, "");
else
itemResp = dmService.CreateItems(itemProps, folder, "");
ed1.WriteMessage("create Items: " + item_id + "sucessful!\n");
ItemRevision rev = null;
Item newitem = null;
for (int j = 0; j < itemResp.Output.Length;j++ )
{
rev = itemResp.Output[j].ItemRev;
newitem = itemResp.Output[j].Item;
}
revVec[i] = rev;
//дform<72><6D><EFBFBD><EFBFBD>
FormInfo forminfo = new FormInfo();
FormInfo[] forminfo_vec;
ModelObject[] form_vec = null;
ModelObject[] objects = { rev };
String[] attributes = { "IMAN_master_form_rev",
"is_modifiable","item_revision_id"};
dmService.RefreshObjects(objects);
dmService.GetProperties(objects, attributes);
if (rev.Is_modifiable)
{
try
{
form_vec = rev.IMAN_master_form_rev;
ed1.WriteMessage("get_IMAN_master_form_rev sucessful!\n");
}
catch (NotLoadedException ex)
{
ed1.WriteMessage(ex.Message);
}
forminfo_vec = new FormInfo[form_vec.Length];
for (int j = 0; j < form_vec.Length; j++)
{
Form form = form_vec[j] as Form;
Hashtable formAttrs = new Hashtable();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Form<72><6D><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD>
if (it_bom.Mxltypetable.ContainsValue("Form"))
{
foreach (DictionaryEntry de in it_bom.Mxltypetable)
{
if (de.Value.ToString() == "Form" && it_bom.Mxlisbomtable[de.Key].ToString() == "0" &&
it_bom.Mxlupdatetable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = it_bom.Mxldatatable[cadstring].ToString();
string tcstring = it_bom.Mxltctable[cadstring].ToString();
string[] formAttrValue = new string[1];
formAttrValue[0] = "";
formAttrValue[0] = cadvalue;
formAttrs.Add(tcstring, formAttrValue);
}
}
}
forminfo.AttributesMap = formAttrs;
forminfo.ClientId = "1";
forminfo.Description = "";
forminfo.FormObject = form;
forminfo.Name = item_id + "/" +rev.Item_revision_id;
forminfo.ParentObject = null;
forminfo.RelationName = "IMAN_master_form";
forminfo.SaveDB = true;
forminfo.FormType = "ItemRevision Master";
forminfo_vec[j] = forminfo;
try
{
CreateOrUpdateFormsResponse formResp
=dmService.CreateOrUpdateForms(forminfo_vec);
ed1.WriteMessage("update form attributes sucessful!\n");
}
catch (ServiceException ex)
{
ed1.WriteMessage(ex.Message);
}
}
}
/*if (it_bom.Memo == "<22><>ͼ")
{
if (parent_ds != null)
{
ExpandGRMRelationsPref myPref = new ExpandGRMRelationsPref();
RelationAndTypesFilter2 myFilter = new RelationAndTypesFilter2();
myFilter.RelationName = "IMAN_reference";
string[] typeVec = new string[1];
typeVec[0] = "D5DWG";
myFilter.ObjectTypeNames = typeVec;
myPref.ExpItemRev = false;
RelationAndTypesFilter2[] myFilterVec = { myFilter };
myPref.Info = myFilterVec;
ModelObject[] primaryObjects = { rev };
Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsResponse
myResp = dmService.ExpandGRMRelationsForPrimary(primaryObjects, myPref);
if (myResp.Output.Length > 0)
{
for (int k = 0; k < myResp.Output.Length; k++)
{
Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsOutput
grmOutput = myResp.Output[k];
for (int l = 0; l < grmOutput.OtherSideObjData.Length; l++)
{
ExpandGRMRelationsData otherSideData = grmOutput.OtherSideObjData[l];
if (otherSideData.OtherSideObjects.Length == 0)
{
Relationship[] rela_vec = new Relationship[1];
Relationship one_rela = new Relationship();
one_rela.ClientId = "";
one_rela.PrimaryObject = rev;
one_rela.SecondaryObject = parent_ds;
one_rela.RelationType = "IMAN_reference";
one_rela.UserData = null;
rela_vec[0] = one_rela;
CreateRelationsResponse reResp =
dmService.CreateRelations(rela_vec);
ed1.WriteMessage("create IMAN_reference sucessful!\n");
}
}
}
}
}
}*/
}
catch (ServiceException ex)
{
ed1.WriteMessage(ex.Message);
}
}
else//found
{
ItemRevision itemRev = null;
for (int j = 0; j < found.NumOfObjects; j++)
{
GetItemFromIdInfo[] infos = new GetItemFromIdInfo[1];
GetItemFromIdInfo oneItem = new GetItemFromIdInfo();
oneItem.ItemId = item_id;
infos[0] = oneItem;
GetItemFromIdPref pref = new GetItemFromIdPref();
GetItemFromIdResponse infoResp =
dmService.GetItemFromId(infos, 1, pref);
for (int n = 0; n < infoResp.Output.Length; n++)
{
ModelObject[] objects = { infoResp.Output[n].Item };
String[] attributes = { "revision_list",
"object_name","item_revision"};
dmService.RefreshObjects(objects);
dmService.GetProperties(objects, attributes);
ModelObject[] revList = infoResp.Output[n].Item.Revision_list;
dmService.RefreshObjects(revList);
for (int l = 0; l < revList.Length; l++)
{
itemRev = revList[l] as ItemRevision;
}
}
}
revVec[i] = itemRev;
//дform<72><6D><EFBFBD><EFBFBD>
FormInfo forminfo = new FormInfo();
FormInfo[] forminfo_vec = new FormInfo[1];
ModelObject[] form_vec;
ModelObject[] objects1 = {itemRev };
String[] attributes1 = { "IMAN_master_form_rev",
"is_modifiable","item_revision_id",
"date_released","item_id",
"release_status_list"};
dmService.RefreshObjects(objects1);
dmService.GetProperties(objects1, attributes1);
ReleaseStatus[] releaselist = itemRev.Release_status_list;
if (releaselist.Length > 0)
{
MessageBox.Show("Item IDΪ" + itemRev.Item_id + "<22><><EFBFBD><EFBFBD><EFBFBD>°汾<C2B0>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD>");
continue;
}
if (!itemRev.Is_modifiable)
{
MessageBox.Show("<22><>ǰ<EFBFBD>û<EFBFBD><C3BB><EFBFBD>Item IDΪ" + itemRev.Item_id + "<22><>Ȩ<EFBFBD>޸Ļ<DEB8><C4BB><EFBFBD>Item<65><6D><EFBFBD>°汾<C2B0>ѷ<EFBFBD><D1B7><EFBFBD>");
continue;
}
else if (itemRev.Is_modifiable)
{
ed1.WriteMessage("is_modifiable!\n");
form_vec = itemRev.IMAN_master_form_rev;
ed1.WriteMessage("get_IMAN_master_form_rev sucessful!\n");
for (int j = 0; j < form_vec.Length; j++)
{
Form form = form_vec[j] as Form;
bool frash = false;
string[] props = new string[1];
string revId = itemRev.Object_string;
Hashtable formAttrs = new Hashtable();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Form<72><6D><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD>
if (it_bom.Mxltypetable.ContainsValue("Form"))
{
foreach (DictionaryEntry de in it_bom.Mxltypetable)
{
if (de.Value.ToString() == "Form" && it_bom.Mxlisbomtable[de.Key].ToString() == "0" &&
it_bom.Mxlupdatetable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = it_bom.Mxldatatable[cadstring].ToString();
string tcstring = it_bom.Mxltctable[cadstring].ToString();
ed1.WriteMessage(<><C8A1><EFBFBD><EFBFBD>" + tcstring + "\n");
props[0] = tcstring;
ServiceData serviceData = dmService.GetProperties(form_vec, props);
if (serviceData.sizeOfPartialErrors() > 0)
{
continue;
}
Property my_prop = form_vec[j].GetProperty(tcstring);
if (cadvalue != my_prop.StringValue)
{
if (my_prop.StringValue == "")
frash = true;
else
{
string message = "<22><>ǰ<EFBFBD><C7B0>ϸ<EFBFBD><CFB8>ͼֽ:" + cadstring + "<22><><EFBFBD><EFBFBD>ֵ" + cadvalue + "<22><>ϵͳ<CFB5><CDB3>:" + tcstring + "<22><><EFBFBD><EFBFBD>ֵ" + my_prop.StringValue + "<22><>һ<EFBFBD><D2BB>,<2C>Ƿ񸲸<C7B7>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?";
DialogResult updateresult = MessageBox.Show(message, "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (updateresult == DialogResult.Yes)
{
frash = true;
}
}
string[] formAttrValue = new string[1];
formAttrValue[0] = "";
if (frash)
formAttrValue[0] = cadvalue;
else
formAttrValue[0] = my_prop.StringValue;
ed1.WriteMessage(tcstring + ":" + formAttrValue[0] + "\n");
formAttrs.Add(tcstring, formAttrValue);
props[0] = "";
}
}
}
}
forminfo.AttributesMap = formAttrs;
forminfo.ClientId = "";
forminfo.Description = "";
forminfo.FormObject = form;
forminfo.Name = item_id + "/" + itemRev.Item_revision_id;
forminfo.ParentObject = null;
forminfo.RelationName = "IMAN_master_form";
forminfo.SaveDB = true;
forminfo.FormType = "ItemRevision Master";
forminfo_vec[0] = forminfo;
try
{
CreateOrUpdateFormsResponse formResp
= dmService.CreateOrUpdateForms(forminfo_vec);
}
catch (SoaException ex)
{
ed1.WriteMessage(ex.Message);
}
}
}
////if (it_bom.Memo == "<22><>ͼ")
////{
//// if (parent_ds != null)
//// {
//// ExpandGRMRelationsPref myPref = new ExpandGRMRelationsPref();
//// RelationAndTypesFilter2 myFilter = new RelationAndTypesFilter2();
//// myFilter.RelationName = "IMAN_reference";
//// string[] typeVec = new string[1];
//// typeVec[0] = "D5DWG";
//// myFilter.ObjectTypeNames = typeVec;
//// myPref.ExpItemRev = false;
//// RelationAndTypesFilter2[] myFilterVec = { myFilter };
//// myPref.Info = myFilterVec;
//// ModelObject[] primaryObjects = { itemRev };
//// Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsResponse
//// myResp = dmService.ExpandGRMRelationsForPrimary(primaryObjects, myPref);
//// if (myResp.Output.Length > 0)
//// {
//// for (int k = 0; k < myResp.Output.Length; k++)
//// {
//// Teamcenter.Services.Strong.Core._2007_06.DataManagement.ExpandGRMRelationsOutput
//// grmOutput = myResp.Output[k];
//// for (int l = 0; l < grmOutput.OtherSideObjData.Length; l++)
//// {
//// ExpandGRMRelationsData otherSideData = grmOutput.OtherSideObjData[l];
//// if (otherSideData.OtherSideObjects.Length == 0)
//// {
//// Relationship[] rela_vec = new Relationship[1];
//// Relationship one_rela = new Relationship();
//// one_rela.ClientId = "";
//// one_rela.PrimaryObject = itemRev;
//// one_rela.SecondaryObject = parent_ds;
//// one_rela.RelationType = "IMAN_reference";
//// one_rela.UserData = null;
//// rela_vec[0] = one_rela;
//// CreateRelationsResponse reResp =
//// dmService.CreateRelations(rela_vec);
//// ed1.WriteMessage("create IMAN_reference sucessful!\n");
//// }
//// }
//// }
//// }
//// }
////}
}
}//for
//<2F><><EFBFBD><EFBFBD>BOM
Teamcenter.Services.Strong.Cad.StructureManagementService ssService =
Teamcenter.Services.Strong.Cad.StructureManagementService.getService(Session.getConnection());
Teamcenter.Services.Strong.Cad._2007_12.StructureManagement.CreateOrUpdateRelativeStructureInfo2
structInfo = new Teamcenter.Services.Strong.Cad._2007_12.StructureManagement.CreateOrUpdateRelativeStructureInfo2();
Teamcenter.Services.Strong.Cad._2007_12.StructureManagement.CreateOrUpdateRelativeStructureInfo2[]
structInfoVec = new Teamcenter.Services.Strong.Cad._2007_12.StructureManagement.CreateOrUpdateRelativeStructureInfo2[1];
//Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.RelativeStructureChildInfo
// childInfo = new Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.RelativeStructureChildInfo();
Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.RelativeStructureChildInfo[]
childInfoVec;
//Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.RelOccInfo
// occInfo = new Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.RelOccInfo();
//Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.AttributesInfo
// attrsInfo = new Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.AttributesInfo();
Teamcenter.Services.Strong.Cad._2007_12.StructureManagement.CreateOrUpdateRelativeStructurePref2
sPref = new Teamcenter.Services.Strong.Cad._2007_12.StructureManagement.CreateOrUpdateRelativeStructurePref2();
//ItemRevision childRev;
ed1.WriteMessage("<22><>ʼ׼<CABC><D7BC>pse<73><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
childInfoVec = new Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.RelativeStructureChildInfo[revVec.Length];
ed1.WriteMessage("childInfoVec size:"+childInfoVec.Length+"\n");
Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.AttributesInfo[]
attrsToSet = new Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.AttributesInfo[4];
for (int i = 0; i < revVec.Length; i++)
{
OriginMXL bomv = bom_Vec[i];
OriginTool origintool = new OriginTool();
string item_id = bomv.Mxldatatable[origintool.getKeyFromValue(bomv.Mxltctable, "item_id")].ToString();
ed1.WriteMessage("<22><><EFBFBD><EFBFBD>" + item_id + "...\n");
int updatenum = 0;
if (bomv.Mxltypetable.ContainsValue("bomline"))
{
foreach (DictionaryEntry de in bomv.Mxltypetable)
{
if (de.Value.ToString() == "bomline" && bomv.Mxlisbomtable[de.Key].ToString() == "1" && bomv.Mxlupdatetable[de.Key].ToString() =="1")
{
updatenum = updatenum + 1;
}
}
}
Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.RelativeStructureChildInfo
childInfo = new Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.RelativeStructureChildInfo();
Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.RelOccInfo
occInfo = new Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.RelOccInfo();
attrsToSet = new Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.AttributesInfo[updatenum];
if (bomv.Mxltypetable.ContainsValue("bomline"))
{
int stepnum = 0;
foreach (DictionaryEntry de in bomv.Mxltypetable)
{
if (de.Value.ToString() == "bomline" && bomv.Mxlisbomtable[de.Key].ToString() == "1" &&
bomv.Mxlupdatetable[de.Key].ToString() == "1")
{
string cadstring = de.Key.ToString();
string cadvalue = bomv.Mxldatatable[cadstring].ToString();
string tcstring = bomv.Mxltctable[cadstring].ToString();
Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.AttributesInfo
attrsInfo = new Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.AttributesInfo();
attrsInfo.Name = tcstring;
attrsInfo.Value = cadvalue;
attrsToSet[stepnum] = attrsInfo;
stepnum = stepnum + 1;
}
}
}
occInfo.AttrsToSet = attrsToSet;
childInfo.Child = revVec[i];
childInfo.OccInfo = occInfo;
childInfoVec[i] = childInfo;
}
for (int j = 0; j < childInfoVec.Length; j++)
{
for(int k=0;k<childInfoVec[j].OccInfo.AttrsToSet.Length;k++)
{
ed1.WriteMessage("====" + childInfoVec[j].OccInfo.AttrsToSet[k].Name + ":" + childInfoVec[j].OccInfo.AttrsToSet[k].Value + "====\n");
}
}
structInfo.ChildInfo = childInfoVec;
structInfo.Parent = parentRev;
structInfo.Precise = false;
structInfoVec[0] = structInfo;
ServiceData sData;
ModelObject[] objects2 = { parentRev };
String[] attributes2 = { "structure_revisions"};
dmService.RefreshObjects(objects2);
sData = dmService.GetProperties(objects2, attributes2);
Teamcenter.Soa.Client.Model.Strong.PSBOMViewRevision bvr = null;
Teamcenter.Soa.Client.Model.Strong.PSBOMView bv = null;
try
{
for (int i = 0; i < parentRev.Structure_revisions.Length; i++)
{
ed1.WriteMessage("<22><>ʼǩ<CABC><C7A9>Bomview revision\n");
bvr = parentRev.Structure_revisions[i];
ModelObject[] objects3 = { bvr };
String[] attributes3 = { "is_modifiable",
"object_string","checkde_out"};
dmService.RefreshObjects(objects3);
dmService.GetProperties(objects3, attributes3);
if (!bvr.Is_modifiable)
{
MessageBox.Show("<22><>Ȩ<EFBFBD>޸<EFBFBD>BOM<4F><4D>");
return false;
}
if (bvr.Checked_out == "Y")
{
MessageBox.Show("BOM<4F>Ѿ<EFBFBD>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
return false;
}
string bvr_name = bvr.Object_string;
ed1.WriteMessage("bvr_name="+bvr_name+"\n");
ModelObject[] bvr_vec = new ModelObject[1];
bvr_vec[0] = bvr;
sData = res.Checkout(bvr_vec, "", "");
if (sData.sizeOfPartialErrors() > 0)
{
ed1.WriteMessage("checkout bom returned a partial error.");
return false;
}
}
}
catch (ServiceException ex)
{
ed1.WriteMessage(ex.Message);
}
ed1.WriteMessage("<22><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>Bom\n");
try
{
Teamcenter.Services.Strong.Cad._2007_01.StructureManagement.CreateOrUpdateRelativeStructureResponse
cursResp = ssService.CreateOrUpdateRelativeStructure(structInfoVec, "view", true, sPref);
ed1.WriteMessage("Bom<6F><6D><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>\n");
}
catch (System.Exception ex)
{
ed1.WriteMessage(ex.Message);
return false;
}
if (bvr != null)
{
ModelObject[] checkIn_vec = new ModelObject[1];
checkIn_vec[0] = bvr;
try
{
res.Checkin(checkIn_vec);
ed1.WriteMessage("Bomview ǩ<><C7A9><EFBFBD>ɹ<EFBFBD>!\n");
}
catch (ServiceException ex)
{
ed1.WriteMessage(ex.Message);
}
}
return true;
}
private void loginbuttonclick(object Sender,EventArgs e)
{
login();
}
private void openbuttonclick(object Sender, EventArgs e)
{
openformtc();
}
private void savebuttonclick(object Sender, EventArgs e)
{
savetotc();
}
private void logoutbuttonclick(object Sender, EventArgs e)
{
layout();
}
//private void addComtextMenu()
//{
// ContextMenuExtension m_contextmenu = new ContextMenuExtension();
// m_contextmenu.Title = "MyTeamCenter";
// Autodesk.AutoCAD.Windows.MenuItem mi = new Autodesk.AutoCAD.Windows.MenuItem("<22><>¼");
// Autodesk.AutoCAD.Windows.MenuItem mi1 = new Autodesk.AutoCAD.Windows.MenuItem("<22><><EFBFBD><EFBFBD>");
// Autodesk.AutoCAD.Windows.MenuItem mi2 = new Autodesk.AutoCAD.Windows.MenuItem("<22><><EFBFBD><EFBFBD>");
// Autodesk.AutoCAD.Windows.MenuItem mi3 = new Autodesk.AutoCAD.Windows.MenuItem("<22>˳<EFBFBD>");
// mi.Click += new EventHandler (loginbuttonclick);
// mi1.Click += new EventHandler(openbuttonclick);
// mi2.Click += new EventHandler(savebuttonclick);
// mi3.Click += new EventHandler(logoutbuttonclick);
// m_contextmenu.MenuItems.Add(mi);
// m_contextmenu.MenuItems.Add(mi1);
// m_contextmenu.MenuItems.Add(mi2);
// m_contextmenu.MenuItems.Add(mi3);
// Autodesk.AutoCAD.ApplicationServices.Application.AddDefaultContextMenuExtension(m_contextmenu);
//}
////<2F>˳<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
//public void acdocmgr_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e)
//{
// DialogResult updateresult = MessageBox.Show("<22><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><E6A3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD>Ƿ񱣴棿", "<22><>ʾ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
// if (updateresult == DialogResult.Yes)
// {
// savetotc();
// }
// else
// {
// loginuser = null;
// hadlogin = false;
// }
//}
}
}