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.

766 lines
33 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.

using Eplan.EplApi.Base;
using Eplan.EplApi.DataModel;
using KPlan.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using Teamcenter.Soa.Client.Model.Strong;
namespace KPlan.RefActions {
public partial class SaveForm : System.Windows.Forms.Form {
public string projectCode = "";
public Eplan.EplApi.DataModel.Project currentProject = null;
public string xmlFilePath = "";
public Dictionary<string, string> nameToPaths;
private List<string> childItem_id = new List<string>();
private List<string> childItem_num = new List<string>();
//private List<string> childItem_installpos1 = new List<string>();
//private List<string> childItem_Manufacturer = new List<string>();//制造商
private Dictionary<string, List<string>> customPropMap = new Dictionary<string, List<string>>();
private int idIdx = -1;
private int numIdx = -1;
private int installposIdx = -1;
private int devidIdx = -1;
private int errorPartNum = 0;
public SaveForm() {
InitializeComponent();
}
private void SaveForm_Load(object sender, EventArgs e) {
tbProjectCode.Text = projectCode;
tbProjectName.Text = currentProject.ProjectName;
if (0 == TCTool.checkItem(projectCode)) {
SaveButton.Enabled = false;
//btnEPlanItem.Show();
}
else {
tbEPlanItem.Text = projectCode;
}
int titleNum = TCTool.BomTitleName.Count;
this.ComListView.Columns.Add("检查结果", 80, HorizontalAlignment.Left); //一步添加表头信息
for (int i = 0; i < TCTool.BomTitleName.Count; i++) {
this.ComListView.Columns.Add(TCTool.BomTitleName[i].ToString(), 120, HorizontalAlignment.Left); //一步添加表头信息
if (TCTool.BomPropertyKey[i].ToString().Equals("P_ARTICLE_ERPNR", StringComparison.OrdinalIgnoreCase)) {
idIdx = i + 1;
}
else if (TCTool.BomPropertyKey[i].ToString().Equals("P_ARTICLEREF_COUNT", StringComparison.OrdinalIgnoreCase)) {
numIdx = i + 1;
}
else if (TCTool.BomPropertyKey[i].ToString().Equals("P_DESIGNATION_LOCATION_DESCR", StringComparison.OrdinalIgnoreCase)) {
installposIdx = i + 1;
}
else if (TCTool.BomPropertyKey[i].ToString().Equals("P_FUNC_DEVICETAG_FULLNAME", StringComparison.OrdinalIgnoreCase)) {
devidIdx = i + 1;
}
}
this.PageListView.Columns.Add("名称", 580, HorizontalAlignment.Left);
Dictionary<string, string>.KeyCollection kc = nameToPaths.Keys;
foreach (string name in kc) {
ListViewItem lvi = new ListViewItem();
lvi.Text = nameToPaths[name];
this.PageListView.Items.Add(lvi);
}
Progress progress = new Progress("EnhancedProgress");
progress.SetActionText("正在加载表单...");
progress.SetTitle("加载表单");
progress.BeginPart(100.0, "进度");
progress.ShowImmediately();
progress.SetAllowCancel(true);
ReadXMLFile();
if (errorPartNum > 0) {
generateListButton.Enabled = true;
}
else {
generateListButton.Enabled = false;
}
progress.EndPart(true);
}
/**
*
* 功能解析partslist XML文件
* 过滤掉不需要的部件,
* 得到需要的部件列表的信息
*
* 入参partslist XML 文件地址
*
*/
public void ReadXMLFile() {
errorPartNum = 0;
childItem_id.Clear();
childItem_num.Clear();
customPropMap.Clear();
//childItem_installpos1.Clear();
//childItem_Manufacturer.Clear();
//MessageBox.Show("xmlFilePath------" + xmlFilePath);
XmlTextReader xtr = new XmlTextReader(xmlFilePath);
string name_f = "@@";
bool is_dos = false;
bool is_device = false;
string device_name = "";
int record_code_idx = -1;
int record_num_idx = -1;
int PropertyNoum = TCTool.BomPropertyKey.Count;
for (int step = 0; step < PropertyNoum; step++) {
// MessageBox.Show("ReadXMLFile------1" );
if (TCTool.BomPropertyKey[step].Equals("P_ARTICLE_ERPNR")) {
record_code_idx = step;
}
if (TCTool.BomPropertyKey[step].Equals("P_ARTICLEREF_COUNT")) {
record_num_idx = step;
}
}
try {
// MessageBox.Show("ReadXMLFile------2");
this.ComListView.BeginUpdate(); //数据更新UI暂时挂起直到EndUpdate绘制控件可以有效避免闪烁并大大提高加载速度
while (xtr.Read()) {
bool is_other = true;
if (is_device) {
if (xtr.NodeType == XmlNodeType.EndElement) {
is_device = false;
}
else {
continue;
}
}
if (xtr.NodeType != XmlNodeType.Element) {
continue;
}
if (!xtr.HasAttributes) {
continue;
}
string element_name = xtr.Name;
bool is_P_ARTICLE_DISCONTINUED = false;
bool is_wire = false;
string wire_length = "";
string record_code = "";
string record_num = "";
string record_type = "";
Dictionary<string, string> customValMap = new Dictionary<string, string>();
string record_installpos1 = "";
//string record_manufacturer = "";
string record_devid = "";
string[] propertyValue = new string[PropertyNoum];
//MessageBox.Show("ReadXMLFile------3");
while (xtr.MoveToNextAttribute()) {
//MessageBox.Show("ReadXMLFile------xtr.Name" + xtr.Name);
//MessageBox.Show("ReadXMLFile------ xtr.Value" + xtr.Value);
if (xtr.Name == "P_ARTICLEREF_IDENTNAME")
//if (xtr.Value == "P_ARTICLEREF_IDENTNAME")
{
device_name = xtr.Value;
}
//if (xtr.Name == "P_ARTICLEREF_IDENTNAME" && xtr.Value.Equals("=+"))
//{
// xtr.MoveToElement();
// is_device = true;
// break;
//}
if (xtr.Name == "P_ARTICLE_DISCONTINUED") //停用
//if (xtr.Value == "P_ARTICLE_DISCONTINUED") //停用
{
if (!xtr.Value.Equals("0")) {
is_P_ARTICLE_DISCONTINUED = true;
}
}
if (xtr.Name == "P_ARTICLE_PARTIAL_LENGTH_VALUE") //此处标识出连接线的部件
// if (xtr.Value == "P_ARTICLE_PARTIAL_LENGTH_VALUE") //此处标识出连接线的部件
{
if (!string.IsNullOrEmpty(xtr.Value) && !xtr.Value.Equals("0")) {
is_wire = true;
wire_length = xtr.Value;
}
}
else if (xtr.Name == "P_ARTICLE_ERPNR")
// else if (xtr.Value == "P_ARTICLE_ERPNR")
{
is_other = false;
record_code = xtr.Value;
}
else if (xtr.Name == "P_ARTICLEREF_COUNT")
//else if (xtr.Value == "P_ARTICLEREF_COUNT")
{
record_num = xtr.Value;
}
else if (xtr.Name == "P_ARTICLE_TYPENR")
// else if (xtr.Value == "P_ARTICLE_TYPENR")
{
record_type = xtr.Value;
}
else if (xtr.Name == "P_DESIGNATION_LOCATION_DESCR")
// else if (xtr.Value == "P_DESIGNATION_LOCATION_DESCR")
{
//MessageBox.Show(xtr.Value);
record_installpos1 = TCTool.getCNString(xtr.Value);
// MessageBox.Show(record_installpos);
}
/*else if(xtr.Name == "P_ARTICLE_MANUFACTURER") {
record_manufacturer = xtr.Value;
}*/
else if (xtr.Name == "P_FUNC_DEVICETAG_FULLNAME")
// else if (xtr.Value == "P_FUNC_DEVICETAG_FULLNAME")
{
record_devid = TCTool.getCNString(xtr.Value);
}
else {
string eName = xtr.Name;
if (TCTool.customBomPropConfig.ContainsKey(eName)) {
//KUtil.Log("读取xml属性"+eName +" = "+xtr.Value);
string tName = TCTool.customBomPropConfig[eName];
if (customValMap.ContainsKey(tName)) {
customValMap.Remove(tName);
}
customValMap.Add(tName, TCTool.getCNString(xtr.Value));
}
}
for (int step = 0; step < PropertyNoum; step++) {
if (xtr.Name == TCTool.BomPropertyKey[step].ToString()) {
//if (xtr.Name.Equals("P_ARTICLE_ERPNR") && record_code_idx == -1)
//{
// record_code_idx = step;
//}
is_other = false;
if (xtr.Value.Contains("@") && xtr.Value.Contains(";")) {
string[] arrStr = xtr.Value.Split(';');
int arrLen = arrStr.Length;
for (int cnt = 0; cnt < arrLen; cnt++) {
if (arrStr[cnt].StartsWith("zh_CN") || arrStr[cnt].StartsWith("??")) {
propertyValue[step] = arrStr[cnt].Split('@')[1];
break;
}
}
}
else {
propertyValue[step] = xtr.Value;
}
break;
}
}
}
if (element_name == "device") //此处过滤掉一些组合设备的部件
{
if (device_name.IndexOf(name_f) != -1) {
is_dos = true;
}
else {
is_dos = false;
}
}
else if (element_name == "part") {
if (is_dos) {
continue;
}
if (TCTool.lineCount != "TRUE") {
if (is_wire) {
continue;
}
}
else {
if (is_wire) {
if (!string.IsNullOrEmpty(wire_length) && !string.IsNullOrEmpty(record_num)) {
double dwire_length = Convert.ToDouble(wire_length);
double drecord_num = Convert.ToDouble(record_num);
drecord_num = dwire_length * drecord_num;
record_num = drecord_num.ToString();
}
}
}
if (record_num.Equals("0")) {
continue;
}
if (is_other) {
name_f = device_name;
}
bool findsame = false;
for (int i = 0; i < ComListView.Items.Count; i++) {
string id = ComListView.Items[i].SubItems[idIdx].Text.ToString();
string installpos = ComListView.Items[i].SubItems[installposIdx].Text.ToString();
if (!id.Equals("") && !installpos.Equals("") && id.Equals(record_code) && installpos.Equals(record_installpos1)) {
string num = ComListView.Items[i].SubItems[numIdx].Text.ToString();
num = (double.Parse(num) + double.Parse(record_num)).ToString();
ComListView.Items[i].SubItems[numIdx].Text = num;
childItem_num[i] = num;
string devid = ComListView.Items[i].SubItems[devidIdx].Text.ToString();
devid += ";" + record_devid;
ComListView.Items[i].SubItems[devidIdx].Text = devid;
findsame = true;
}
}
if (findsame) {
continue;
}
ListViewItem lvi = new ListViewItem();
lvi.UseItemStyleForSubItems = false;
if (record_code.Equals("")) {
for (int i = 0; i < TCTool.P_ARTICLE_TYPENRs.Count; i++) {
if (record_type.Equals(TCTool.P_ARTICLE_TYPENRs[i].ToString(), StringComparison.OrdinalIgnoreCase)) {
record_code = TCTool.P_ARTICLE_ERPNRs[i].ToString();
propertyValue[record_code_idx] = record_code;
break;
}
}
}
if (is_P_ARTICLE_DISCONTINUED) {
lvi.ForeColor = Color.Red;
SaveButton.Enabled = false;
errorPartNum++;
lvi.Text = "停产部件";
}
else {
if (record_code.Equals("")) {
lvi.ForeColor = Color.Red;
SaveButton.Enabled = false;
errorPartNum++;
lvi.Text = "TC不存在";
}
else {
int findItem = TCTool.checkItem(record_code);
if (findItem == 0) {
lvi.ForeColor = Color.Red;
SaveButton.Enabled = false;
errorPartNum++;
lvi.Text = "TC不存在";
}
else {
lvi.Text = "TC存在";
}
}
}
record_code = record_code.Replace("\r", "");
record_code = record_code.Replace("\n", "");
childItem_id.Add(record_code);
record_num = record_num.Replace("\r", "");
record_num = record_num.Replace("\n", "");
childItem_num.Add(record_num);
//添加未获取值
foreach (string key in TCTool.customBomPropConfig.Keys) {
string tName = TCTool.customBomPropConfig[key];
if (!customValMap.ContainsKey(tName)) {
//KUtil.Log("补充xml属性" + key);
customValMap.Add(tName, "");
}
}
foreach (string key in customValMap.Keys) {
string val = customValMap[key];
val = val.Replace("\r", "").Replace("\n", "");
//KUtil.Log("添加属性映射:"+key+" = "+val);
if (customPropMap.ContainsKey(key)) {
customPropMap[key].Add(val);
}
else {
List<string> l = new List<string>();
l.Add(val);
customPropMap.Add(key, l);
}
}
/*record_installpos1 = record_installpos1.Replace("\r", "");
record_installpos1 = record_installpos1.Replace("\n", "");
childItem_installpos1.Add(record_installpos1);
record_manufacturer = record_manufacturer.Replace("\r", "");
record_manufacturer = record_manufacturer.Replace("\n", "");
childItem_Manufacturer.Add(record_manufacturer);*/
for (int step = 0; step < PropertyNoum; step++) {
if (record_num_idx == step) {
lvi.SubItems.Add(record_num).ForeColor = Color.Black;
}
else {
if (propertyValue[step] == null) {
lvi.SubItems.Add("");
}
else {
lvi.SubItems.Add(propertyValue[step]).ForeColor = Color.Black;
}
}
}
this.ComListView.Items.Add(lvi);
}
}
xtr.Close();
this.ComListView.EndUpdate(); //结束数据处理UI界面一次性绘制。
}
catch (XmlException ex) {
MessageBox.Show(ex.Message);
}
}
private void assignButton_Click(object sender, EventArgs e) {
//if (cbxType.SelectedItem == null || cbxType.SelectedItem.ToString().Equals(""))
//{
// MessageBox.Show("请选择零组件类型再指派Item_ID和版本");
// return;
//}
//string outputstr = "";
//string[] arrStr = new string[3];
//arrStr[0] = "project";
//arrStr[1] = cbxType.SelectedItem.ToString();
//arrStr[2] = "1";
//TCTool.invokeTC("assignNewIdAndRev", null, arrStr, out outputstr);
//string[] itemidAndRev = outputstr.Split('$');
//tbItemId.Text = itemidAndRev[0];
//tbRevId.Text = itemidAndRev[1];
////if (projectIdTextBox.Text.Trim().Equals(""))
////{
//// projectIdTextBox.Text = itemidAndRev[2];
////}
//TCTool.ProjectString = itemidAndRev[2];
//btnItemID.Enabled = false;
//if (errorPartNum == 0)
//{
// SaveButton.Enabled = true;
//}
}
private void btnEPlanItem_Click(object sender, EventArgs e) {
//SelectElecPartsForm form = new SelectElecPartsForm();
//if (DialogResult.OK == form.ShowDialog())
//{
// tbProjectCode.Text = form.selectItem_id;
// tbRevId.Text = form.selectItem_revision_id;
//}
}
private void SaveButton_Click(object sender, EventArgs e) {
// MessageBox.Show("保存前操作----------");
ItemRevision projItemRevision = TCUtil.Query_LatestRev(projectCode);
TCUtil.GetProperties(false, new Teamcenter.Soa.Client.Model.ModelObject[] { projItemRevision }, "item_revision_id");
string ver = projItemRevision.Item_revision_id;
ProjectPropertyList projectProperties = currentProject.Properties;
projectProperties.PROJ_CUSTOM_SUPPLEMENTARYFIELD100.Set(projectCode);
projectProperties.PROJ_CUSTOM_SUPPLEMENTARYFIELD99.Set(ver);
/////////////////////////////////////////////////////////
List<string> saveFileItemData = new List<string>();
foreach (ListViewItem lvi in PageListView.Items) {
saveFileItemData.Add(lvi.Text);
}
SaveProjectBean saveProjBean = new SaveProjectBean() { projectCode = projectCode,childItem_id=childItem_id,childItem_num = childItem_num,custPropMap=customPropMap,saveFileItemData=saveFileItemData };
/////////////////////////////////////////////////////////
/*string fmsHome = Environment.GetEnvironmentVariable("FMS_HOME");
string dataFile = fmsHome + "\\EPlan\\" + "data";
try {
FileStream aFile = new FileStream(@dataFile, FileMode.Create);
StreamWriter sw = new StreamWriter(aFile);
sw.WriteLine(projectCode);
sw.WriteLine(string.Join("@@", childItem_id.ToArray()));
sw.WriteLine(string.Join("@@", childItem_num.ToArray()));
//MessageBox.Show("childItem_installpos----------" + childItem_installpos);
sw.WriteLine(string.Join("@@", childItem_installpos1.ToArray()));
sw.WriteLine(string.Join("@@", childItem_Manufacturer.ToArray()));
sw.WriteLine(string.Join("@@", saveFileItemData.ToArray()));
sw.Close();
}
catch (IOException ex) {
MessageBox.Show("写入数据文件失败:\r\n" + ex.ToString(), "提示");
return;
}
short nRes = SaveProject(dataFile);*/
short nRes = SaveProject(saveProjBean);
// string para = String.Format("\"{0}||{1}||{2}||{3}\"", TCTool.LoginUser, TCTool.PWD, "saveProject", dataFile);
//short nRes = TCTool.execTools(para);
if (nRes == 0) {
MessageBox.Show("保存项目完毕!", "提示");
this.DialogResult = DialogResult.OK;
}
}
public class SaveProjectBean {
public string projectCode { get; set; }
public List<string> childItem_id { get; set; }
public List<string> childItem_num { get; set; }
public Dictionary<string,List<string>> custPropMap { get; set; }
public List<string> saveFileItemData { get; set; }
}
private void ComListView_ColumnClick(object sender, ColumnClickEventArgs e) {
ComListView.ListViewItemSorter = new ListViewItemComparer(e.Column);
ComListView.Sort();
}
private short SaveProject(string filename) {
{
//Console.WriteLine("filename------------------" + filename);
string projectCode = "";
string[] childItem_id = null;
string[] childItem_num = null;
string[] childItem_installpos1 = null;
string[] childItem_manufacturer = null;
string[] saveFileItemData = null;
try {
FileStream aFile = new FileStream(@filename, FileMode.Open);
StreamReader sr = new StreamReader(aFile);
projectCode = sr.ReadLine();
//Console.WriteLine("projectCode------------------" + projectCode);
string childItem_idLine = sr.ReadLine();
// Console.WriteLine("childItem_idLine------------------" + childItem_idLine);
if (!String.IsNullOrEmpty(childItem_idLine)) {
// Console.WriteLine("1------------------" + childItem_idLine);
childItem_id = Regex.Split(childItem_idLine, "@@", RegexOptions.IgnoreCase);
}
string childItem_numLine = sr.ReadLine();
if (!String.IsNullOrEmpty(childItem_numLine)) {
// Console.WriteLine("2------------------" + childItem_numLine);
childItem_num = Regex.Split(childItem_numLine, "@@", RegexOptions.IgnoreCase);
}
string childItem_installposLine = sr.ReadLine();
if (!String.IsNullOrEmpty(childItem_installposLine)) {
// Console.WriteLine("3------------------" + childItem_installposLine);
childItem_installpos1 = Regex.Split(childItem_installposLine, "@@", RegexOptions.IgnoreCase);
}
string childItem_manufacturerLine = sr.ReadLine();
if (!String.IsNullOrEmpty(childItem_manufacturerLine)) {
// Console.WriteLine("3------------------" + childItem_installposLine);
childItem_manufacturer = Regex.Split(childItem_manufacturerLine, "@@", RegexOptions.IgnoreCase);
}
// Console.WriteLine("4------------------");
saveFileItemData = Regex.Split(sr.ReadLine(), "@@", RegexOptions.IgnoreCase);
//Console.WriteLine("5------------------");
sr.Close();
}
catch (IOException ex) {
MessageBox.Show("读取数据文件失败:\r\n" + ex.ToString(), "提示");
return 2001;
}
//Console.WriteLine("6------------------");
//Console.WriteLine("9------------------" + projectCode);
Teamcenter.Soa.Client.Model.Strong.ItemRevision projItemRevision = TCUtil.Query_LatestRev(projectCode);
////////////////////////////////////////////////////////////
//Console.WriteLine("10------------------");
short nRes = 0;
if (childItem_id != null) {
// Console.WriteLine("11------------------");
//Console.WriteLine("childItem_id------------------" + childItem_id.Length);
//Console.WriteLine("childItem_num------------------" + childItem_num.Length);
//Console.WriteLine("childItem_installpos------------------" + childItem_installpos.Length);
/* if (childItem_id.ToList()==null)
{
Console.WriteLine("childItem_id.ToList()==null");
}
if (childItem_num.ToList() == null)
{
Console.WriteLine("childItem_num.ToList()");
}*/
/* if (childItem_installpos.ToList() == null)
{
Console.WriteLine("childItem_installpos.ToList()==null");
}*/
// nRes = TCTool.CreateOrUpdateBom(projItemRevision, childItem_id.ToList(), childItem_num.ToList(), childItem_installpos.ToList());
// nRes = TCTool.CreateOrUpdateBom(projItemRevision, childItem_id.ToList(), childItem_num.ToList(), childItem_installpos1,childItem_manufacturer);
nRes = TCTool.CreateOrUpdateBom(projItemRevision, childItem_id.ToList(), childItem_num.ToList(), customPropMap);
// Console.WriteLine("12------------------");
if (0 > nRes) {
//Console.WriteLine("13------------------");
MessageBox.Show("保存BOM失败!", "提示");
return 2011;
}
else if (0 < nRes) {
return 2012;
}
// kk 同步项目属性
try {
KUtil.Sync_ProjProperty_to_TC(projItemRevision, currentProject);
}
catch (Exception ex) {
KUtil.LogErr(ex);
MessageBox.Show("同步项目属性出错:"+ex.Message);
return 2013;
}
}
////////////////////////////////////////////////////////////
// Console.WriteLine("14------------------");
nRes = createProjctDataset(projectCode, projItemRevision, saveFileItemData.ToList());
if (0 > nRes) {
MessageBox.Show("保存文件失败!", "提示");
return 2021;
}
else if (0 < nRes) {
return 2022;
}
}
return 0;
}
private short SaveProject(SaveProjectBean bean) {
{
//Console.WriteLine("6------------------");
//Console.WriteLine("9------------------" + projectCode);
Teamcenter.Soa.Client.Model.Strong.ItemRevision projItemRevision = TCUtil.Query_LatestRev(projectCode);
////////////////////////////////////////////////////////////
//Console.WriteLine("10------------------");
short nRes = 0;
if (childItem_id != null) {
// Console.WriteLine("11------------------");
//Console.WriteLine("childItem_id------------------" + childItem_id.Length);
//Console.WriteLine("childItem_num------------------" + childItem_num.Length);
//Console.WriteLine("childItem_installpos------------------" + childItem_installpos.Length);
/* if (childItem_id.ToList()==null)
{
Console.WriteLine("childItem_id.ToList()==null");
}
if (childItem_num.ToList() == null)
{
Console.WriteLine("childItem_num.ToList()");
}*/
/* if (childItem_installpos.ToList() == null)
{
Console.WriteLine("childItem_installpos.ToList()==null");
}*/
// nRes = TCTool.CreateOrUpdateBom(projItemRevision, childItem_id.ToList(), childItem_num.ToList(), childItem_installpos.ToList());
nRes = TCTool.CreateOrUpdateBom(projItemRevision, bean.childItem_id, bean.childItem_num, bean.custPropMap);
// Console.WriteLine("12------------------");
if (0 > nRes) {
//Console.WriteLine("13------------------");
MessageBox.Show("保存BOM失败!", "提示");
return 2011;
}
else if (0 < nRes) {
return 2012;
}
// kk 同步项目属性
try {
KUtil.Sync_ProjProperty_to_TC(projItemRevision, currentProject);
}
catch (Exception ex) {
KUtil.LogErr(ex);
MessageBox.Show("同步项目属性出错:" + ex.Message);
return 2013;
}
}
////////////////////////////////////////////////////////////
// Console.WriteLine("14------------------");
nRes = createProjctDataset(projectCode, projItemRevision, bean.saveFileItemData);
if (0 > nRes) {
MessageBox.Show("保存文件失败!", "提示");
return 2021;
}
else if (0 < nRes) {
return 2022;
}
}
return 0;
}
static private short createProjctDataset(string projectCode, Teamcenter.Soa.Client.Model.Strong.ItemRevision projItemRevision, List<String> saveFileItemData) {
string ZW1DSType = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_ZW_DSTYPE);
string ZW1DSRef = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_ZW_DSREF);
string PDFDSType = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_PDF_DSTYPE);
string PDFDSRef = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_PDF_DSREF);
// Console.WriteLine("开始获取cad数据集--------------");
Teamcenter.Soa.Client.Model.Strong.Dataset dataset_zw1 = TCTool.getDataset(projItemRevision, ZW1DSType, projectCode + TCTool.ZW1Name);
if (dataset_zw1 != null) {
// Console.WriteLine("检查cad是否签出--------------");
if (0 != TCTool.checkDatasetCheckout(dataset_zw1)) {
return 1;
}
//if (0 != TCTool.deleteDataset(projItemRevision, dataset_zw1))
//{
// return 2;
//}
}
else {
dataset_zw1 = TCTool.createDataset(projItemRevision, ZW1DSType, projectCode + TCTool.ZW1Name);
if (dataset_zw1 == null) {
return 3;
}
}
// Console.WriteLine("开始获取pdf数据集--------------");
//Console.WriteLine("projectCode + TCTool.PDFName--------------" + projectCode + TCTool.PDFName);
Teamcenter.Soa.Client.Model.Strong.Dataset dataset_pdf = TCTool.getDataset(projItemRevision, PDFDSType, projectCode + TCTool.PDFName);
if (dataset_pdf != null) {
// Console.WriteLine("pdf数据集不为空--------------");
if (0 != TCTool.checkDatasetCheckout(dataset_pdf)) {
// Console.WriteLine("检查pdf数据集签出故障--------------");
return 11;
}
//if (0 != TCTool.deleteDataset(projItemRevision, dataset_pdf))
//{
// return 12;
//}
}
else {
//Console.WriteLine("pdf数据集为空开始创建pdf数据集--------------");
dataset_pdf = TCTool.createDataset(projItemRevision, PDFDSType, projectCode + TCTool.PDFName);
if (dataset_pdf == null) {
return 13;
}
}
foreach (string filename in saveFileItemData) {
//Console.WriteLine("filename--------------" + filename);
FileInfo fi = new FileInfo(filename);
string extension = System.IO.Path.GetExtension(filename);
if (extension.Equals(".zw1", StringComparison.OrdinalIgnoreCase)) {
//Console.WriteLine("添加.zw1--------------");
// MessageBox.Show("添加.zw1-------------", "提示");
//TCTool.addNameRef(dataset_zw1, TCTool.ZW1NameRef, filename);
TCUtil.UploadFile(dataset_zw1, filename, ZW1DSRef);
}
else if (extension.Equals(".pdf", StringComparison.OrdinalIgnoreCase)) {
// Console.WriteLine("添加.pdf--------------");
//MessageBox.Show("添加.pdf-------------", "提示");
//TCTool.addNameRef(dataset_pdf, TCTool.PDFNameRef, filename);
TCUtil.UploadFile(dataset_pdf, filename, PDFDSRef);
}
}
return 0;
}
}
}