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.
339 lines
13 KiB
339 lines
13 KiB
using System;
|
|
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 KPlan.Forms.Bean;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace KPlan.Forms {
|
|
/// <summary>
|
|
/// Interaction logic for Config_ProjSync.xaml
|
|
/// </summary>
|
|
public partial class Config_ProjSync : Grid {
|
|
private string loadedType;
|
|
private List<EPlanPropBean> ePlanPropBeanList = new List<EPlanPropBean>();
|
|
private ObservableCollection<EPlanPropBean> ePlanPropBeanData = new ObservableCollection<EPlanPropBean>();
|
|
private ObservableCollection<TCPropBean> tcPropBeanData = new ObservableCollection<TCPropBean>();
|
|
private ObservableCollection<PartSyncConfigBean> eplan_to_tc_config = new ObservableCollection<PartSyncConfigBean>();
|
|
private Dictionary<string, List<TCPropBean>> tcPropMap = new Dictionary<string, List<TCPropBean>>();
|
|
public ObservableCollection<string> language_list = new ObservableCollection<string>();
|
|
|
|
public Config_ProjSync() {
|
|
InitializeComponent();
|
|
ReadEplanProperty();
|
|
table_Eplan_Prop.ItemsSource = ePlanPropBeanData;
|
|
table_TC_Prop.ItemsSource = tcPropBeanData;
|
|
table_EPLAN_TO_TC.ItemsSource = eplan_to_tc_config;
|
|
string[] ENUM_LANGUAGES = Enum.GetNames(typeof(Eplan.EplApi.Base.ISOCode.Language));
|
|
Array.Sort(ENUM_LANGUAGES);
|
|
foreach (string l in ENUM_LANGUAGES) {
|
|
language_list.Add(l);
|
|
}
|
|
col_language.ItemsSource = language_list;
|
|
try {
|
|
string itemTypeName = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_TC_ITEM_TYPE);
|
|
TCUtil.GetDefinedProperties(itemTypeName);
|
|
ReadTcProperty(itemTypeName);
|
|
}
|
|
catch (System.Exception ex) {
|
|
KUtil.LogErr(ex);
|
|
//MessageBox.Show("加载数据出错:" + ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
private void ChangeType() {
|
|
string newType = tb_ObjectType.Text;
|
|
if (KUtil.IsEmpty(newType)) {
|
|
MessageBox.Show("请输入对象类型");
|
|
return;
|
|
}
|
|
if (newType.Equals(loadedType)) {
|
|
return;
|
|
}
|
|
MessageBoxResult res = MessageBox.Show("重新加载对象类型将清空当前映射配置,是否继续?", "", MessageBoxButton.YesNo);
|
|
if (res != MessageBoxResult.Yes) {
|
|
return;
|
|
}
|
|
//清空
|
|
ClearPropConfig();
|
|
//加载TC属性
|
|
ReadTcProperty(newType);
|
|
loadedType = newType;
|
|
}
|
|
|
|
private void ReadTcProperty(string itemTypeName) {
|
|
tcPropBeanData.Clear();
|
|
cb_Location.Items.Clear();
|
|
cb_Location.Items.Add("");
|
|
this.tcPropMap = TCUtil.GetDefinedProperties(itemTypeName);
|
|
foreach (string key in tcPropMap.Keys) {
|
|
cb_Location.Items.Add(key);
|
|
List<TCPropBean> list = tcPropMap[key];
|
|
foreach (TCPropBean b in list) {
|
|
tcPropBeanData.Add(b);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ReadEplanProperty() {
|
|
ePlanPropBeanList.Clear();
|
|
ePlanPropBeanData.Clear();
|
|
Eplan.EplApi.DataModel.AnyPropertyId[] props = Eplan.EplApi.DataModel.Properties.AllProjectPropIDs;
|
|
for (int i = 0; i < props.Length; i++) {
|
|
Eplan.EplApi.DataModel.AnyPropertyId prop = props[i];
|
|
if (prop.Definition.IsReadOnly) {
|
|
continue;
|
|
}
|
|
EPlanPropBean bean = new EPlanPropBean(prop.Definition.Type.ToString()) { realName = prop.AsProject.ToString(), disName = prop.Definition.Name, type = prop.Definition.Type.ToString() };
|
|
ePlanPropBeanList.Add(bean);
|
|
ePlanPropBeanData.Add(bean);
|
|
}
|
|
}
|
|
|
|
private void ClearPropConfig() {
|
|
eplan_to_tc_config.Clear();
|
|
}
|
|
|
|
private void Remove_Config(DataGrid dataGrid, ObservableCollection<PartSyncConfigBean> data) {
|
|
try {
|
|
System.Collections.IList selectedItems = dataGrid.SelectedItems;
|
|
if (selectedItems == null || selectedItems.Count == 0) {
|
|
return;
|
|
}
|
|
while (selectedItems.Count > 0) {
|
|
data.Remove((PartSyncConfigBean)selectedItems[0]);
|
|
dataGrid.Items.Refresh();
|
|
}
|
|
dataGrid.Items.Refresh();
|
|
}
|
|
catch (System.Exception ex) {
|
|
KUtil.LogErr(ex);
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void Modify_Config(DataGrid dataGrid, ObservableCollection<PartSyncConfigBean> data, string from, string to) {
|
|
if (KUtil.IsEmpty(from) || KUtil.IsEmpty(to)) {
|
|
return;
|
|
}
|
|
PartSyncConfigBean selectedBean = dataGrid.SelectedItem as PartSyncConfigBean;
|
|
if (selectedBean == null) {
|
|
return;
|
|
}
|
|
int existInd = data.IndexOf(new PartSyncConfigBean() { from = from, to = to });
|
|
if (existInd >= 0 && !to.Equals(selectedBean.to)) {
|
|
MessageBox.Show("已存在属性映射到" + to);
|
|
return;
|
|
}
|
|
//PartSyncConfigBean bean = (PartSyncConfigBean)dataGrid.Items[ind];
|
|
selectedBean.from = from;
|
|
selectedBean.to = to;
|
|
dataGrid.Items.Refresh();
|
|
dataGrid.SelectedItem = selectedBean;
|
|
|
|
}
|
|
|
|
private void Add_Config(DataGrid dataGrid, ObservableCollection<PartSyncConfigBean> data, string from, string to) {
|
|
if (KUtil.IsEmpty(from) || KUtil.IsEmpty(to)) {
|
|
return;
|
|
}
|
|
PartSyncConfigBean bean = new PartSyncConfigBean() { from = from, to = to };
|
|
if (!data.Contains(bean)) {
|
|
data.Add(bean);
|
|
}
|
|
dataGrid.SelectedItem = bean;
|
|
dataGrid.ScrollIntoView(bean);
|
|
}
|
|
|
|
private void Read_Prop_Refection_to_Textbox() {
|
|
EPlanPropBean eplanBean = table_Eplan_Prop.SelectedItem as EPlanPropBean;
|
|
TCPropBean tcBean = table_TC_Prop.SelectedItem as TCPropBean;
|
|
string eplanConfig = "";
|
|
string tcConfig = "";
|
|
if (eplanBean != null) {
|
|
eplanConfig = eplanBean.getConfigValue();
|
|
}
|
|
if (tcBean != null) {
|
|
tcConfig = tcBean.location + "." + tcBean.realName;
|
|
}
|
|
tb_EPLAN_TO_TC_eplan.Text = eplanConfig;
|
|
tb_EPLAN_TO_TC_tc.Text = tcConfig;
|
|
}
|
|
|
|
private void Find_TC_Props() {
|
|
string text = tb_TCProp.Text;
|
|
string type = cb_Location.SelectedItem as string;
|
|
tcPropBeanData.Clear();
|
|
if (KUtil.IsEmpty(type) && KUtil.IsEmpty(text)) {
|
|
foreach (List<TCPropBean> list in tcPropMap.Values) {
|
|
foreach (TCPropBean b in list) {
|
|
tcPropBeanData.Add(b);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
text = text.ToLower();
|
|
foreach (List<TCPropBean> list in tcPropMap.Values) {
|
|
foreach (TCPropBean b in list) {
|
|
if (KUtil.RegexMatch(b.disName.ToLower(),text) || KUtil.RegexMatch(b.realName.ToLower(), text)) {
|
|
//if (b.disName.ToLower().Contains(text) || b.realName.ToLower().Contains(text)) {
|
|
if (KUtil.IsEmpty(type) || b.typeName.Equals(type)) {
|
|
tcPropBeanData.Add(b);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Find_EPlan_Props() {
|
|
string text = tb_EPlanProp.Text;
|
|
ePlanPropBeanData.Clear();
|
|
if (KUtil.IsEmpty(text)) {
|
|
foreach (EPlanPropBean bean in ePlanPropBeanList) {
|
|
ePlanPropBeanData.Add(bean);
|
|
}
|
|
}
|
|
else {
|
|
text = text.ToLower();
|
|
foreach (EPlanPropBean bean in ePlanPropBeanList) {
|
|
if (KUtil.RegexMatch(bean.disName.ToLower(),text) || KUtil.RegexMatch(bean.realName.ToLower(), text)){
|
|
//if (bean.disName.ToLower().Contains(text) || bean.realName.ToLower().Contains(text)) {
|
|
ePlanPropBeanData.Add(bean);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void SaveConfiguration() {
|
|
Dictionary<string, string> syncConfig = new Dictionary<string, string>();
|
|
syncConfig.Add(KConfigure.PROJ_SYNC_TC_ITEM_TYPE, tb_ObjectType.Text);
|
|
// syncConfig.Add(KConfigure.PROJ_SYNC_TEMPLATE_ID, tb_templateid.Text);
|
|
syncConfig.Add(KConfigure.PROJ_SYNC_PDF_DSTYPE, tb_pdftype.Text);
|
|
syncConfig.Add(KConfigure.PROJ_SYNC_PDF_DSREF, tb_pdfref.Text);
|
|
syncConfig.Add(KConfigure.PROJ_SYNC_ZW_DSTYPE, tb_zwtype.Text);
|
|
syncConfig.Add(KConfigure.PROJ_SYNC_ZW_DSREF, tb_zwref.Text);
|
|
//syncConfig.Add(KConfigure.PROJ_SYNC_ItemID_EPlan, tb_ItemID_Prop.Text);
|
|
KUtil.SetConfigValue(KConfigure.PROJ_SYNC_SECTION, syncConfig);
|
|
KUtil.ClearConfigSection(KConfigure.PROJ_SYNC_EPLAN_TO_TC_SECTION);
|
|
//eplan to tc
|
|
Dictionary<string, string> eplan_to_tc = new Dictionary<string, string>();
|
|
for (int i = 0; i < eplan_to_tc_config.Count; i++) {
|
|
PartSyncConfigBean bean = eplan_to_tc_config[i];
|
|
eplan_to_tc.Add(bean.to, bean.from);
|
|
}
|
|
KUtil.SetConfigValue(KConfigure.PROJ_SYNC_EPLAN_TO_TC_SECTION, eplan_to_tc);
|
|
}
|
|
|
|
public void LoadConfiguration() {
|
|
this.loadedType = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_TC_ITEM_TYPE);
|
|
tb_ObjectType.Text = this.loadedType;
|
|
//tb_templateid.Text = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_TEMPLATE_ID);
|
|
tb_pdftype.Text = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_PDF_DSTYPE);
|
|
tb_pdfref.Text = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_PDF_DSREF);
|
|
tb_zwtype.Text = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_ZW_DSTYPE);
|
|
tb_zwref.Text = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_ZW_DSREF);
|
|
//tb_ItemID_Prop.Text = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_SECTION, KConfigure.PROJ_SYNC_ItemID_EPlan);
|
|
//eplan to tc
|
|
Dictionary<string, string> eplan_to_tc = KUtil.GetConfigValue(KConfigure.PROJ_SYNC_EPLAN_TO_TC_SECTION);
|
|
foreach (string key in eplan_to_tc.Keys) {
|
|
PartSyncConfigBean bean = new PartSyncConfigBean() { from = eplan_to_tc[key], to = key };
|
|
eplan_to_tc_config.Add(bean);
|
|
}
|
|
}
|
|
|
|
private void Find_EPlan_Prop_Button_Click(object sender, RoutedEventArgs e) {
|
|
Find_EPlan_Props();
|
|
}
|
|
|
|
private void Tb_EPlanProp_KeyDown(object sender, KeyEventArgs e) {
|
|
if (e.Key == Key.Return) {
|
|
Find_EPlan_Props();
|
|
}
|
|
}
|
|
|
|
private void Find_TC_PropButton_Click(object sender, RoutedEventArgs e) {
|
|
Find_TC_Props();
|
|
}
|
|
|
|
private void Tb_TCProp_KeyDown(object sender, KeyEventArgs e) {
|
|
if (e.Key == Key.Return) {
|
|
Find_TC_Props();
|
|
}
|
|
}
|
|
|
|
private void ChangeType_Button_Click(object sender, RoutedEventArgs e) {
|
|
try {
|
|
ChangeType();
|
|
}
|
|
catch (System.Exception ex) {
|
|
KUtil.LogErr(ex);
|
|
MessageBox.Show("加载数据出错:" + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void Tb_ObjectType_KeyDown(object sender, KeyEventArgs e) {
|
|
if (e.Key == Key.Return) {
|
|
try {
|
|
ChangeType();
|
|
}
|
|
catch (System.Exception ex) {
|
|
KUtil.LogErr(ex);
|
|
MessageBox.Show("加载数据出错:" + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Cb_Location_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
|
Find_TC_Props();
|
|
}
|
|
|
|
private void PropTable_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
|
Read_Prop_Refection_to_Textbox();
|
|
}
|
|
|
|
private void EPLAN_TO_TC_ADD_Button_Click(object sender, RoutedEventArgs e) {
|
|
Add_Config(table_EPLAN_TO_TC, eplan_to_tc_config, tb_EPLAN_TO_TC_eplan.Text, tb_EPLAN_TO_TC_tc.Text);
|
|
}
|
|
|
|
private void EPLAN_TO_TC_REMOVE_Button_Click(object sender, RoutedEventArgs e) {
|
|
Remove_Config(table_EPLAN_TO_TC, eplan_to_tc_config);
|
|
}
|
|
|
|
private void EPLAN_TO_TC_MODIFY_Button_Click(object sender, RoutedEventArgs e) {
|
|
Modify_Config(table_EPLAN_TO_TC, eplan_to_tc_config, tb_EPLAN_TO_TC_eplan.Text, tb_EPLAN_TO_TC_tc.Text);
|
|
}
|
|
|
|
private void Clear_All_Button_Click(object sender, RoutedEventArgs e) {
|
|
MessageBoxResult res = MessageBox.Show("确认清空?", "", MessageBoxButton.YesNo);
|
|
if (res != MessageBoxResult.Yes) {
|
|
return;
|
|
}
|
|
ClearPropConfig();
|
|
}
|
|
|
|
private void COL_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
|
EPlanPropBean eplanBean = table_Eplan_Prop.SelectedItem as EPlanPropBean;
|
|
ComboBox cb = e.Source as ComboBox;
|
|
if (eplanBean == null || cb == null) {
|
|
return;
|
|
}
|
|
eplanBean.language = cb.SelectedItem as string;
|
|
}
|
|
}
|
|
}
|