|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Data;
|
|
|
using System.Windows.Documents;
|
|
|
using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Navigation;
|
|
|
using System.Windows.Shapes;
|
|
|
using KPlan.Util;
|
|
|
using Teamcenter.Soa.Client.Model;
|
|
|
using KPlan.Forms.Bean;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Windows.Forms;
|
|
|
using System.ComponentModel;
|
|
|
using Eplan.EplApi.DataModel;
|
|
|
using Eplan.EplApi.MasterData;
|
|
|
using Eplan.EplApi.Base;
|
|
|
|
|
|
namespace KPlan.Forms {
|
|
|
/// <summary>
|
|
|
/// Interaction logic for CreateProject.xaml
|
|
|
/// </summary>
|
|
|
public partial class CreateProject : Window {
|
|
|
|
|
|
public const double W_NO_TEMPLATE = 400;
|
|
|
public const double W_TEMPLATE = 640;
|
|
|
private ModelObject[] templates;
|
|
|
private ObservableCollection<ModelObjectBean> templatesListData = new ObservableCollection<ModelObjectBean>();
|
|
|
private ModelObjectBean selectedTemplateBean;
|
|
|
string projCode = "";
|
|
|
string projName = "";
|
|
|
string savePosition = "";
|
|
|
string templateName = "";
|
|
|
DateTime? creation_date = null;
|
|
|
string creator = "";
|
|
|
public bool create = false;
|
|
|
|
|
|
public CreateProject() {
|
|
|
InitializeComponent();
|
|
|
KUtil.SetOwnerWindow(this);
|
|
|
list_TCTemplate.ItemsSource = templatesListData;
|
|
|
try {
|
|
|
loadTCTemplate();
|
|
|
}
|
|
|
catch (System.Exception ex) {
|
|
|
KUtil.LogErr(ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void CreateProj_Button_Click(object sender, RoutedEventArgs e) {
|
|
|
create = true;
|
|
|
projCode = tb_ProjCode.Text;
|
|
|
projName = tb_ProjName.Text;
|
|
|
savePosition = tb_SavePosition.Text;
|
|
|
templateName = tb_Template.Text;
|
|
|
if (cb_CreationDate.IsChecked.Value) {
|
|
|
creation_date = dp_CreationDate.Value;
|
|
|
}
|
|
|
if (cb_Creator.IsChecked.Value) {
|
|
|
creator = tb_Creator.Text;
|
|
|
}
|
|
|
if (KUtil.IsEmpty(projCode) || KUtil.IsEmpty(projName) || KUtil.IsEmpty(savePosition) || KUtil.IsEmpty(templateName)) {
|
|
|
KUtil.DispatcherShow(this, "请填写项目信息");
|
|
|
return;
|
|
|
}
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
public void DoCreateProject() {
|
|
|
System.IO.FileInfo fileInfo;
|
|
|
if (selectedTemplateBean != null && templateName.Equals(selectedTemplateBean.objectString)) {
|
|
|
List<Teamcenter.Soa.Client.Model.Strong.ImanFile> imanFiles = TCUtil.GetDatasetFile(selectedTemplateBean.mo, null);
|
|
|
if (imanFiles == null || imanFiles.Count == 0) {
|
|
|
throw new Exception("数据集<" + templateName + ">不存在文件引用");
|
|
|
}
|
|
|
if (imanFiles.Count > 1) {
|
|
|
throw new Exception("数据集<" + templateName + ">存在多个文件引用");
|
|
|
}
|
|
|
fileInfo = TCUtil.GetFileInfo(imanFiles[0]);
|
|
|
if (fileInfo == null) {
|
|
|
throw new Exception("从数据集<" + templateName + ">下载文件引用失败");
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
fileInfo = new System.IO.FileInfo(templateName);
|
|
|
}
|
|
|
if (fileInfo == null || !fileInfo.Exists) {
|
|
|
throw new Exception("获取模板异常,文件不存在:" + templateName);
|
|
|
}
|
|
|
KUtil.Log("项目模板:" + fileInfo.FullName);
|
|
|
if (!System.IO.Directory.Exists(savePosition)) {
|
|
|
System.IO.Directory.CreateDirectory(savePosition);
|
|
|
}
|
|
|
KUtil.Log(savePosition + "\\" + projName + ".elk|" + fileInfo.FullName);
|
|
|
Progress progress = new Progress("SimpleProgress");
|
|
|
progress.BeginPart(100.0, "");
|
|
|
progress.ShowImmediately();
|
|
|
progress.SetAllowCancel(true);
|
|
|
try {
|
|
|
string projPath = savePosition + "\\" + projName + ".elk";
|
|
|
string tempPath = fileInfo.FullName;
|
|
|
KUtil.Log("创建项目:" + projPath);
|
|
|
KUtil.Log("使用模板:" + tempPath);
|
|
|
Project proj = EplanUtil.Create(projPath, tempPath, true);
|
|
|
proj.Properties.PROJ_DRAWINGNUMBER = projCode;
|
|
|
proj.Properties.PROJ_CUSTOM_SUPPLEMENTARYFIELD100 = projCode;//item_id
|
|
|
if (!KUtil.IsEmpty(creator)) {
|
|
|
KUtil.Log("设置创建者:" + creator);
|
|
|
proj.Properties.PROJ_CREATOR = creator;
|
|
|
}
|
|
|
if (creation_date != null) {
|
|
|
KUtil.Log("设置创建时间:" + creation_date.Value);
|
|
|
proj.Properties.PROJ_CREATIONDATE = creation_date.Value;
|
|
|
}
|
|
|
//去掉感叹号
|
|
|
proj.Close();
|
|
|
proj = EplanUtil.OpenProject(projPath);
|
|
|
KUtil.Log("创建完成");
|
|
|
}
|
|
|
finally {
|
|
|
progress.EndPart(true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void loadTCTemplate() {
|
|
|
string itemId = KUtil.GetConfigValue(KConfigure.EPLAN_DATA_SECTION, KConfigure.EPLAN_TEMPLATE_ITEM_ID);
|
|
|
string dsType = KUtil.GetConfigValue(KConfigure.EPLAN_DATA_SECTION, KConfigure.EPLAN_TEMPLATE_DATASET_TYPE);
|
|
|
if (TCUtil.user == null || KUtil.IsEmpty(itemId) || KUtil.IsEmpty(dsType)) {
|
|
|
colDef_TCTemplate.Width = new GridLength(0);
|
|
|
this.Width = W_NO_TEMPLATE;
|
|
|
this.MinWidth = W_NO_TEMPLATE;
|
|
|
return;
|
|
|
}
|
|
|
this.Width = W_TEMPLATE;
|
|
|
this.MinWidth = W_TEMPLATE;
|
|
|
KUtil.Log("加载TC中项目模板:" + itemId);
|
|
|
Teamcenter.Soa.Client.Model.Strong.ItemRevision rev = TCUtil.Query_LatestRev(itemId);
|
|
|
if (rev == null) {
|
|
|
KUtil.Log("配置对象不存在:" + itemId);
|
|
|
return;
|
|
|
}
|
|
|
templates = TCUtil.GetChild(rev, TCUtil.REL_REV_EPLAN, dsType);
|
|
|
int len = templates == null ? 0 : templates.Length;
|
|
|
if (len > 0) {
|
|
|
TCUtil.dmService.RefreshObjects(templates);
|
|
|
TCUtil.GetProperties(false, templates, "object_string");
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
Teamcenter.Soa.Client.Model.Strong.Dataset ds = (Teamcenter.Soa.Client.Model.Strong.Dataset)templates[i];
|
|
|
templatesListData.Add(new ModelObjectBean(ds, ds.Object_string));
|
|
|
}
|
|
|
}
|
|
|
KUtil.Log("加载完成");
|
|
|
}
|
|
|
|
|
|
private void CreationDate_CheckBox_SelectionChanged(object sender, RoutedEventArgs e) {
|
|
|
dp_CreationDate.IsEnabled = cb_CreationDate.IsChecked.Value;
|
|
|
if (cb_CreationDate.IsChecked.Value) {
|
|
|
dp_CreationDate.Text = DateTime.Now.ToString(dp_CreationDate.FormatString);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void Cb_Creator_SelectionChanged(object sender, RoutedEventArgs e) {
|
|
|
tb_Creator.IsEnabled = cb_Creator.IsChecked.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
private void Close_Button_Click(object sender, RoutedEventArgs e) {
|
|
|
Close();
|
|
|
}
|
|
|
|
|
|
private void SavePosition_Button_Click(object sender, RoutedEventArgs e) {
|
|
|
FolderBrowserDialog fb = new FolderBrowserDialog();
|
|
|
fb.RootFolder = Environment.SpecialFolder.Desktop;
|
|
|
fb.Description = "选择项目保存位置";
|
|
|
if (fb.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
|
|
|
tb_SavePosition.Text = fb.SelectedPath;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void Template_Button_Click(object sender, RoutedEventArgs e) {
|
|
|
OpenFileDialog fd = new OpenFileDialog();
|
|
|
fd.Title = "选择项目模板";
|
|
|
fd.Filter = "模板文件|*.ept";
|
|
|
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
|
|
|
tb_Template.Text = fd.FileName;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void List_TCTemplate_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
|
|
selectedTemplateBean = list_TCTemplate.SelectedItem as ModelObjectBean;
|
|
|
if (selectedTemplateBean == null) {
|
|
|
return;
|
|
|
}
|
|
|
tb_Template.Text = selectedTemplateBean.objectString;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|