hytos / DTI_PID / SPPIDConverter / ConverterForm.cs @ ef90c19c
이력 | 보기 | 이력해설 | 다운로드 (37.8 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel; |
4 |
using System.Data; |
5 |
using System.Drawing; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Windows.Forms; |
10 |
using Microsoft.VisualBasic; |
11 |
using DevExpress.XtraEditors.Repository; |
12 |
using DevExpress.XtraEditors.Controls; |
13 |
using DevExpress.XtraEditors; |
14 |
using System.Globalization; |
15 |
using System.Threading; |
16 |
using System.IO; |
17 |
using Ingr.RAD2D; |
18 |
using Converter.BaseModel; |
19 |
using Converter.SPPID.Properties; |
20 |
using Converter.SPPID.DB; |
21 |
using Converter.SPPID.Util; |
22 |
using Converter.SPPID.Form; |
23 |
using Converter.SPPID.Model; |
24 |
using Plaice; |
25 |
using Llama; |
26 |
|
27 |
|
28 |
namespace Converter.SPPID |
29 |
{ |
30 |
public partial class ConverterForm : DevExpress.XtraBars.Ribbon.RibbonForm |
31 |
{ |
32 |
private Dictionary<string, SPPID_Document> _DicDocuments = new Dictionary<string, SPPID_Document>(); |
33 |
private List<SPPID_Document> _Documents = new List<SPPID_Document>(); |
34 |
public List<SPPID_Document> Documents { get { return _Documents; } } |
35 |
private DataTable _ConverterDT = new DataTable(); |
36 |
private DataTable _SPPIDSymbolPathDT = new DataTable(); |
37 |
private DataTable _SPPIDUnitDT = new DataTable(); |
38 |
private DataTable _SPPIDAttributeDT = new DataTable(); |
39 |
private RepositoryItemComboBox templateComboBox; |
40 |
private RepositoryItemComboBox bulkRuleComboBox; |
41 |
|
42 |
|
43 |
private DataTable _ID2SymbolDT = new DataTable(); |
44 |
private DataTable _ID2ChildSymbolDT = new DataTable(); |
45 |
private DataTable _ID2LineDT = new DataTable(); |
46 |
private DataTable _ID2AttributeDT = new DataTable(); |
47 |
private DataTable _ID2DrawingAttributeDT = new DataTable(); |
48 |
private DataTable _ID2LinePropertyDT = new DataTable(); |
49 |
private DataTable _ID2SymbolTypeDT = new DataTable(); |
50 |
private DataTable _ID2SymbolTable = new DataTable(); |
51 |
|
52 |
|
53 |
private List<SymbolMapping> symbolMappings = new List<SymbolMapping>(); |
54 |
private List<ChildSymbolMapping> childSymbolMappings = new List<ChildSymbolMapping>(); |
55 |
private List<LineMapping> lineMappings = new List<LineMapping>(); |
56 |
private List<LineNumberMapping> lineNumberMappings = new List<LineNumberMapping>(); |
57 |
private List<AttributeMapping> attributeMappings = new List<AttributeMapping>(); |
58 |
|
59 |
string TemplatePath; |
60 |
|
61 |
public ConverterForm() |
62 |
{ |
63 |
InitializeComponent(); |
64 |
|
65 |
CultureInfo culture = CultureInfo.GetCultureInfo("en"); |
66 |
Msg.Culture = culture; |
67 |
|
68 |
this._SPPIDUnitDT = SPPIDUtil.GetUnitInfo(); |
69 |
TemplatePath = SPPIDUtil.T_OPTIONSETTING_Value("PID Template Path"); |
70 |
|
71 |
InitUsedDataTable(); |
72 |
InitGridControl(); |
73 |
InitID2Project(); |
74 |
|
75 |
// |
76 |
//labelID2ProjectName.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
77 |
//labelDBType.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
78 |
//labelID2ProjectStatus.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
79 |
//labelSPPIDPlantName.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
80 |
//labelSPPIDDBStatus.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
81 |
//labelItemMappingStatus.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
82 |
} |
83 |
|
84 |
private void InitUsedDataTable() |
85 |
{ |
86 |
// Converter Table |
87 |
DataColumn col = _ConverterDT.Columns.Add("colDrawingFileName"); |
88 |
col.Caption = "Drawing File Name"; |
89 |
col = _ConverterDT.Columns.Add("colDrawingFilePath"); |
90 |
col.Caption = "DrawingFilePath"; |
91 |
col = _ConverterDT.Columns.Add("colUnit"); |
92 |
col.Caption = "Unit"; |
93 |
col = _ConverterDT.Columns.Add("colTemplate"); |
94 |
col.Caption = "Template"; |
95 |
col = _ConverterDT.Columns.Add("colDrawingNumber"); |
96 |
col.Caption = "Drawing Number"; |
97 |
col = _ConverterDT.Columns.Add("colDrawingName"); |
98 |
col.Caption = "Drawing Name"; |
99 |
col = _ConverterDT.Columns.Add("colRuleName"); |
100 |
col.Caption = "Bulk Rule Name"; |
101 |
col = _ConverterDT.Columns.Add("colStatus"); |
102 |
col.Caption = "Status"; |
103 |
col = _ConverterDT.Columns.Add("colUID"); |
104 |
|
105 |
col = _ID2LineDT.Columns.Add("UID"); |
106 |
col = _ID2LineDT.Columns.Add("Name"); |
107 |
col.Caption = "Name"; |
108 |
col = _ID2LineDT.Columns.Add("Type"); |
109 |
col.Caption = "Type"; |
110 |
col = _ID2LineDT.Columns.Add("SPPID_SYMBOL_PATH"); |
111 |
col.Caption = "SPPID Symbol Path"; |
112 |
col = _ID2LineDT.Columns.Add("Clear"); |
113 |
col.Caption = ""; |
114 |
} |
115 |
|
116 |
private void InitGridControl() |
117 |
{ |
118 |
#region Converter Page |
119 |
gridViewConverter.OptionsSelection.MultiSelect = true; |
120 |
gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; |
121 |
|
122 |
gridControlConverter.DataSource = _ConverterDT; |
123 |
|
124 |
templateComboBox = new RepositoryItemComboBox(); |
125 |
templateComboBox.TextEditStyle = TextEditStyles.DisableTextEditor; |
126 |
templateComboBox.EditValueChanged += templateComboBox_EditValueChanged; |
127 |
gridControlConverter.RepositoryItems.Add(templateComboBox); |
128 |
gridViewConverter.Columns["colTemplate"].ColumnEdit = templateComboBox; |
129 |
|
130 |
bulkRuleComboBox = new RepositoryItemComboBox(); |
131 |
bulkRuleComboBox.TextEditStyle = TextEditStyles.DisableTextEditor; |
132 |
bulkRuleComboBox.EditValueChanged += templateComboBox_EditValueChanged; |
133 |
gridControlConverter.RepositoryItems.Add(bulkRuleComboBox); |
134 |
gridViewConverter.Columns["colRuleName"].ColumnEdit = bulkRuleComboBox; |
135 |
|
136 |
gridViewConverter.Columns["colUnit"].OptionsColumn.AllowEdit = false; |
137 |
gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false; |
138 |
gridViewConverter.Columns["colUnit"].OptionsColumn.ReadOnly = true; |
139 |
gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false; |
140 |
gridViewConverter.Columns["colDrawingFilePath"].Visible = false; |
141 |
gridViewConverter.Columns["colUID"].Visible = false; |
142 |
|
143 |
gridViewConverter.BestFitColumns(); |
144 |
#endregion |
145 |
} |
146 |
|
147 |
private void templateComboBox_EditValueChanged(object sender, EventArgs e) |
148 |
{ |
149 |
gridViewConverter.CloseEditor(); |
150 |
gridViewConverter.UpdateCurrentRow(); |
151 |
} |
152 |
|
153 |
private void gridViewConverter_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) |
154 |
{ |
155 |
if (e.Column.Name == "colcolTemplate" || e.Column.Name == "colcolRuleName") |
156 |
{ |
157 |
gridViewConverter.ShowEditor(); |
158 |
(gridViewConverter.ActiveEditor as ComboBoxEdit).ShowPopup(); |
159 |
} |
160 |
else if (e.Column.Name == "colcolUnit") |
161 |
{ |
162 |
UnitForm unitForm = new UnitForm(_SPPIDUnitDT); |
163 |
if (unitForm.ShowDialog() == DialogResult.OK) |
164 |
{ |
165 |
gridViewConverter.SetRowCellValue(e.RowHandle, e.Column, unitForm.SelectedUnit); |
166 |
gridViewConverter.CloseEditor(); |
167 |
gridViewConverter.UpdateCurrentRow(); |
168 |
} |
169 |
} |
170 |
} |
171 |
|
172 |
private void btnID2DB_Click(object sender, EventArgs e) |
173 |
{ |
174 |
ID2DBSetting form = new ID2DBSetting(); |
175 |
DialogResult dialogResult = form.ShowDialog(); |
176 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
177 |
_ProjectInfo.DefaultPath = Settings.Default.ProjectPath; |
178 |
_ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType; |
179 |
_ProjectInfo.ServerIP = Settings.Default.ProjectServerIP; |
180 |
_ProjectInfo.Port = Settings.Default.ProjectPort; |
181 |
_ProjectInfo.DBUser = Settings.Default.ProjectDBUser; |
182 |
_ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword; |
183 |
|
184 |
if (dialogResult == DialogResult.OK) |
185 |
{ |
186 |
if (InitID2Project()) |
187 |
MessageBox.Show(Msg.SuccessProjectSelect, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
188 |
else |
189 |
MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
190 |
} |
191 |
} |
192 |
|
193 |
private bool InitID2Project() |
194 |
{ |
195 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
196 |
if (Project_DB.ConnTestAndCreateTable()) |
197 |
{ |
198 |
_ProjectInfo.Enable = true; |
199 |
labelDBType.Text = _ProjectInfo.DBType.ToString(); |
200 |
labelDBType.AppearanceItemCaption.ForeColor = Color.Blue; |
201 |
labelID2ProjectName.Text = _ProjectInfo.Name; |
202 |
labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue; |
203 |
labelID2ProjectStatus.Text = Msg.ConnectionSuccessful; |
204 |
labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
205 |
layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
206 |
layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
207 |
} |
208 |
else |
209 |
{ |
210 |
_ProjectInfo.Enable = false; |
211 |
labelDBType.Text = " "; |
212 |
labelID2ProjectName.Text = " "; |
213 |
labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red; |
214 |
labelID2ProjectStatus.Text = Msg.ConnectionFail; |
215 |
labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red; |
216 |
layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
217 |
layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
218 |
} |
219 |
|
220 |
InitMapping(); |
221 |
InitSPPIDDB(); |
222 |
|
223 |
return _ProjectInfo.Enable; |
224 |
} |
225 |
|
226 |
private void InitMapping() |
227 |
{ |
228 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
229 |
if (_ProjectInfo.Enable) |
230 |
{ |
231 |
if (_ID2SymbolTable != null) |
232 |
{ |
233 |
_ID2SymbolTable.Dispose(); |
234 |
_ID2SymbolTable = null; |
235 |
} |
236 |
_ID2SymbolTable = Project_DB.SelectID2SymbolTable(); |
237 |
|
238 |
if (_ID2SymbolTypeDT != null) |
239 |
{ |
240 |
_ID2SymbolTypeDT.Dispose(); |
241 |
_ID2SymbolTypeDT = null; |
242 |
} |
243 |
_ID2SymbolTypeDT = Project_DB.SelectSymbolType(); |
244 |
InitID2Symbol(); |
245 |
InitID2Line(); |
246 |
InitID2LineNumber(); |
247 |
InitID2Attribute(); |
248 |
InitID2DrawingAttribute(); |
249 |
|
250 |
InitETCSetting(); |
251 |
} |
252 |
} |
253 |
|
254 |
private void InitETCSetting() |
255 |
{ |
256 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
257 |
if (_ProjectInfo.Enable) |
258 |
{ |
259 |
DataTable dt = Project_DB.SelectSetting(); |
260 |
foreach (DataRow item in dt.Rows) |
261 |
{ |
262 |
string settingType = item["SettingType"].ToString(); |
263 |
if (settingType == "ETCSetting") |
264 |
SPPIDUtil.ConvertToETCSetting(item["JsonString"].ToString()); |
265 |
else if (settingType == "GridSetting") |
266 |
SPPIDUtil.ConvertToGridSetting(item["JsonString"].ToString()); |
267 |
} |
268 |
} |
269 |
} |
270 |
|
271 |
private void InitID2Symbol() |
272 |
{ |
273 |
using (DataTable symbolDT = Project_DB.SelectProjectSymbol()) |
274 |
{ |
275 |
symbolMappings.Clear(); |
276 |
_ID2SymbolDT = symbolDT; |
277 |
_ID2SymbolDT.Columns.Add("Clear"); |
278 |
_ID2SymbolDT.Columns["Clear"].Caption = ""; |
279 |
foreach (DataRow row in symbolDT.Rows) |
280 |
{ |
281 |
symbolMappings.Add(new SymbolMapping() |
282 |
{ |
283 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
284 |
SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(), |
285 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
286 |
LEADERLINE = DBNull.Value.Equals(row["LEADERLINE"]) ? false : (bool)row["LEADERLINE"] |
287 |
}); |
288 |
} |
289 |
|
290 |
MergeID2ChildSymbol(); |
291 |
} |
292 |
} |
293 |
|
294 |
private void MergeID2ChildSymbol() |
295 |
{ |
296 |
using (DataTable childSymbolDT = Project_DB.SelectProjectChildSymbol()) |
297 |
{ |
298 |
childSymbolMappings.Clear(); |
299 |
_ID2ChildSymbolDT = childSymbolDT; |
300 |
_ID2ChildSymbolDT.Columns.Add("Clear"); |
301 |
_ID2ChildSymbolDT.Columns["Clear"].Caption = ""; |
302 |
foreach (DataRow row in childSymbolDT.Rows) |
303 |
{ |
304 |
childSymbolMappings.Add(new ChildSymbolMapping() |
305 |
{ |
306 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
307 |
SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(), |
308 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
309 |
}); |
310 |
} |
311 |
|
312 |
_ID2SymbolDT.Merge(_ID2ChildSymbolDT); |
313 |
} |
314 |
} |
315 |
|
316 |
private void InitID2Line() |
317 |
{ |
318 |
using (DataTable lineTypes = Project_DB.SelectProjectLine()) |
319 |
{ |
320 |
lineMappings.Clear(); |
321 |
_ID2LineDT.Rows.Clear(); |
322 |
foreach (DataRow row in lineTypes.Rows) |
323 |
{ |
324 |
DataRow newRow = _ID2LineDT.NewRow(); |
325 |
newRow["UID"] = row["UID"] == null ? "" : row["UID"].ToString(); |
326 |
newRow["Name"] = row["Name"] == null ? "" : row["Name"].ToString(); |
327 |
newRow["Type"] = "Line"; |
328 |
newRow["SPPID_SYMBOL_PATH"] = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(); |
329 |
_ID2LineDT.Rows.Add(newRow); |
330 |
|
331 |
lineMappings.Add(new LineMapping() |
332 |
{ |
333 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
334 |
LINENAME = row["Name"] == null ? "" : row["Name"].ToString(), |
335 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
336 |
}); |
337 |
} |
338 |
} |
339 |
} |
340 |
|
341 |
private void InitID2LineNumber() |
342 |
{ |
343 |
using (DataTable linePropertiesDT = Project_DB.SelectProjectLineProperties()) |
344 |
{ |
345 |
lineNumberMappings.Clear(); |
346 |
_ID2LinePropertyDT = linePropertiesDT; |
347 |
_ID2LinePropertyDT.Columns.Add("Type"); |
348 |
foreach (DataRow row in linePropertiesDT.Rows) |
349 |
{ |
350 |
row["Type"] = "Line Property"; |
351 |
lineNumberMappings.Add(new LineNumberMapping() |
352 |
{ |
353 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
354 |
DisplayName = row["DisplayName"] == null ? "" : row["DisplayName"].ToString(), |
355 |
SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(), |
356 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString() |
357 |
}); |
358 |
} |
359 |
} |
360 |
} |
361 |
|
362 |
private void InitID2Attribute() |
363 |
{ |
364 |
using (DataTable attributeDT = Project_DB.SelectProjectAttribute()) |
365 |
{ |
366 |
attributeMappings.Clear(); |
367 |
_ID2AttributeDT = attributeDT; |
368 |
_ID2AttributeDT.Columns.Add("Clear"); |
369 |
_ID2AttributeDT.Columns["Clear"].Caption = ""; |
370 |
foreach (DataRow row in attributeDT.Rows) |
371 |
{ |
372 |
attributeMappings.Add(new AttributeMapping() |
373 |
{ |
374 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
375 |
DisplayAttribute = row["DisplayAttribute"] == null ? "" : row["DisplayAttribute"].ToString(), |
376 |
Type = row["Type"] == null ? "" : row["Type"].ToString(), |
377 |
SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(), |
378 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
379 |
Location = DBNull.Value.Equals(row["LOCATION"]) ? Model.Location.None : (Location)row["LOCATION"], |
380 |
LeaderLine = DBNull.Value.Equals(row["LEADERLINE"]) ? false : (bool)row["LEADERLINE"], |
381 |
IsText = DBNull.Value.Equals(row["ISTEXT"]) ? false : (bool)row["ISTEXT"] |
382 |
}); |
383 |
} |
384 |
} |
385 |
} |
386 |
|
387 |
private void InitID2DrawingAttribute() |
388 |
{ |
389 |
using (DataTable drawingAttributeDT = Project_DB.SelectDrawingProjectAttribute()) |
390 |
{ |
391 |
_ID2DrawingAttributeDT = drawingAttributeDT; |
392 |
} |
393 |
} |
394 |
|
395 |
private void InitSPPIDDB() |
396 |
{ |
397 |
buttonEditDefaultUnit.TextChanged -= new EventHandler(buttonEditDefaultUnit_TextChanged); |
398 |
comboBoxEditDefaultTemplate.SelectedIndexChanged -= new EventHandler(comboBoxEditDefaultTemplate_SelectedIndexChanged); |
399 |
comboBoxEditBulk.SelectedIndexChanged -= new System.EventHandler(this.comboBoxEditBulk_SelectedIndexChanged); |
400 |
|
401 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
402 |
if (_ProjectInfo.Enable) |
403 |
{ |
404 |
DataTable dt = Project_DB.SelectSPPID_DB_INFO(); |
405 |
if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
406 |
SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString()); |
407 |
else |
408 |
SPPID_DBInfo.Clear(); |
409 |
} |
410 |
|
411 |
templateComboBox.Items.Clear(); |
412 |
comboBoxEditDefaultTemplate.SelectedIndex = -1; |
413 |
comboBoxEditDefaultTemplate.Properties.Items.Clear(); |
414 |
buttonEditDefaultUnit.Text = ""; |
415 |
|
416 |
|
417 |
// Bulk Attribute |
418 |
RefreshBulkRule(); |
419 |
|
420 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
421 |
if (_SPPIDInfo.Enable) |
422 |
{ |
423 |
labelSPPIDPlantName.Text = _SPPIDInfo.SelectedPlant; |
424 |
labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Blue; |
425 |
labelSPPIDDBStatus.Text = Msg.ConnectionSuccessful; |
426 |
labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
427 |
|
428 |
if (!string.IsNullOrEmpty(TemplatePath)) |
429 |
{ |
430 |
List<string> templateFiles = Directory.GetFiles(TemplatePath, "*.pid").ToList().Select(filePath => Path.GetFileName(filePath)).ToList(); |
431 |
templateComboBox.Items.AddRange(templateFiles); |
432 |
comboBoxEditDefaultTemplate.Properties.Items.AddRange(templateFiles); |
433 |
} |
434 |
|
435 |
if (_SPPIDAttributeDT != null) |
436 |
{ |
437 |
_SPPIDAttributeDT.Dispose(); |
438 |
_SPPIDAttributeDT = null; |
439 |
} |
440 |
|
441 |
_SPPIDAttributeDT = SPPID_DB.GetSPPIDAttribute(); |
442 |
if (_SPPIDAttributeDT != null) |
443 |
{ |
444 |
_SPPIDAttributeDT.Columns["DISPLAYNAME"].ColumnName = "DISPLAY NAME"; |
445 |
} |
446 |
|
447 |
if (!string.IsNullOrEmpty(Settings.Default.DefaultTemplate) && comboBoxEditDefaultTemplate.Properties.Items.Contains(Settings.Default.DefaultTemplate)) |
448 |
comboBoxEditDefaultTemplate.SelectedItem = Settings.Default.DefaultTemplate; |
449 |
|
450 |
if (!string.IsNullOrEmpty(Settings.Default.DefaultBulkRule) && comboBoxEditBulk.Properties.Items.Contains(Settings.Default.DefaultBulkRule)) |
451 |
comboBoxEditBulk.SelectedItem = Settings.Default.DefaultBulkRule; |
452 |
|
453 |
// Unit 있는지 없는지 검사 필요 |
454 |
if (!string.IsNullOrEmpty(Settings.Default.DefaultUnit)) |
455 |
buttonEditDefaultUnit.Text = Settings.Default.DefaultUnit; |
456 |
} |
457 |
else |
458 |
{ |
459 |
labelSPPIDPlantName.Text = " "; |
460 |
labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Red; |
461 |
labelSPPIDDBStatus.Text = Msg.ConnectionFail; |
462 |
labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Red; |
463 |
} |
464 |
|
465 |
_DicDocuments.Clear(); |
466 |
_ConverterDT.Rows.Clear(); |
467 |
InitSPPIDSymbolTreeTable(); |
468 |
|
469 |
buttonEditDefaultUnit.TextChanged += new EventHandler(buttonEditDefaultUnit_TextChanged); |
470 |
comboBoxEditDefaultTemplate.SelectedIndexChanged += new EventHandler(comboBoxEditDefaultTemplate_SelectedIndexChanged); |
471 |
comboBoxEditBulk.SelectedIndexChanged += new System.EventHandler(this.comboBoxEditBulk_SelectedIndexChanged); |
472 |
} |
473 |
|
474 |
private void InitSPPIDSymbolTreeTable() |
475 |
{ |
476 |
try |
477 |
{ |
478 |
_SPPIDSymbolPathDT = new DataTable(); |
479 |
_SPPIDSymbolPathDT.Columns.Add("ID"); |
480 |
_SPPIDSymbolPathDT.Columns.Add("Parent"); |
481 |
_SPPIDSymbolPathDT.Columns.Add("Name"); |
482 |
_SPPIDSymbolPathDT.Columns.Add("FullPath"); |
483 |
|
484 |
string symbolPath = SPPIDUtil.T_OPTIONSETTING_Value("Catalog Explorer root path"); |
485 |
DirectoryInfo info = new DirectoryInfo(symbolPath); |
486 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { "0", "-1", info.Name }); |
487 |
loop(info, "0", symbolPath); |
488 |
} |
489 |
catch (Exception ex) |
490 |
{ |
491 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
492 |
} |
493 |
} |
494 |
|
495 |
private void loop(DirectoryInfo parentInfo, string parentUID, string defaultPath) |
496 |
{ |
497 |
DirectoryInfo[] infos = parentInfo.GetDirectories(); |
498 |
foreach (DirectoryInfo info in infos) |
499 |
{ |
500 |
string uid = Guid.NewGuid().ToString(); |
501 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { uid, parentUID, info.Name }); |
502 |
loop(info, uid, defaultPath); |
503 |
|
504 |
FileInfo[] files = info.GetFiles("*.sym"); |
505 |
foreach (FileInfo fileInfo in files) |
506 |
{ |
507 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { Guid.NewGuid().ToString(), uid, fileInfo.Name, fileInfo.FullName.Replace(defaultPath, "") }); |
508 |
} |
509 |
} |
510 |
} |
511 |
|
512 |
private void btnLoadFile_Click(object sender, EventArgs e) |
513 |
{ |
514 |
List< BaseModel.Document> validationFailDocs = new List<BaseModel.Document>(); |
515 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
516 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
517 |
if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable) |
518 |
{ |
519 |
MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
520 |
return; |
521 |
} |
522 |
|
523 |
xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath; |
524 |
if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK) |
525 |
{ |
526 |
foreach (string fileName in xtraOpenFileDialog.FileNames) |
527 |
{ |
528 |
SPPID_Document document = new SPPID_Document(fileName, _ID2SymbolTypeDT); |
529 |
|
530 |
document.SymbolTable = _ID2SymbolTable; |
531 |
document.SymbolMappings = symbolMappings; |
532 |
document.ChildSymbolMappings = childSymbolMappings; |
533 |
document.LineMappings = lineMappings; |
534 |
document.LineNumberMappings = lineNumberMappings; |
535 |
document.AttributeMappings = attributeMappings; |
536 |
document.ETCSetting = ETCSetting.GetInstance(); |
537 |
document.SetSPPIDInfo(); |
538 |
|
539 |
|
540 |
if (!document.SetSPPIDMapping()) |
541 |
{ |
542 |
document.Enable = false; |
543 |
document.MappingValidation = false; |
544 |
} |
545 |
|
546 |
DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName)); |
547 |
if (rows.Length == 0) |
548 |
{ |
549 |
DataRow row = _ConverterDT.NewRow(); |
550 |
row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName); |
551 |
row["colDrawingFilePath"] = fileName; |
552 |
row["colDrawingNumber"] = document.DWGNAME; |
553 |
row["colDrawingName"] = document.DWGNAME; |
554 |
if (document.Enable) |
555 |
row["colStatus"] = "Ready"; |
556 |
else |
557 |
row["colStatus"] = "Error"; |
558 |
row["colUID"] = ""; |
559 |
if (comboBoxEditDefaultTemplate.SelectedIndex > -1) |
560 |
row["colTemplate"] = comboBoxEditDefaultTemplate.SelectedItem; |
561 |
if (comboBoxEditBulk.SelectedIndex > -1) |
562 |
row["colRuleName"] = comboBoxEditBulk.SelectedItem; |
563 |
if (!string.IsNullOrEmpty(buttonEditDefaultUnit.Text)) |
564 |
row["colUnit"] = buttonEditDefaultUnit.Text; |
565 |
|
566 |
_ConverterDT.Rows.Add(row); |
567 |
|
568 |
if (document.Enable && document.Validation && document.MappingValidation) |
569 |
gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
570 |
} |
571 |
else |
572 |
{ |
573 |
foreach (DataRow row in rows) |
574 |
{ |
575 |
if (document.Enable) |
576 |
row["colStatus"] = "Ready"; |
577 |
else |
578 |
row["colStatus"] = "Error"; |
579 |
|
580 |
if (comboBoxEditDefaultTemplate.SelectedIndex > -1) |
581 |
row["colTemplate"] = comboBoxEditDefaultTemplate.SelectedItem; |
582 |
if (comboBoxEditBulk.SelectedIndex > -1) |
583 |
row["colRuleName"] = comboBoxEditBulk.SelectedItem; |
584 |
if (!string.IsNullOrEmpty(buttonEditDefaultUnit.Text)) |
585 |
row["colUnit"] = buttonEditDefaultUnit.Text; |
586 |
|
587 |
if (document.Enable && document.Validation && document.MappingValidation) |
588 |
gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
589 |
} |
590 |
} |
591 |
if (!_DicDocuments.ContainsKey(fileName)) |
592 |
_DicDocuments.Add(fileName, null); |
593 |
|
594 |
if (!document.Validation || !document.MappingValidation) |
595 |
validationFailDocs.Add(document); |
596 |
|
597 |
_DicDocuments[fileName] = document; |
598 |
} |
599 |
if (validationFailDocs.Count > 0) |
600 |
{ |
601 |
MessageForm messageForm = new MessageForm(validationFailDocs); |
602 |
messageForm.ShowDialog(); |
603 |
} |
604 |
} |
605 |
} |
606 |
|
607 |
/// <summary> |
608 |
/// 선택한 도면의 정보를 로딩한다 |
609 |
/// </summary> |
610 |
/// <param name="sender"></param> |
611 |
/// <param name="e"></param> |
612 |
private void btnRun_Click(object sender, EventArgs e) |
613 |
{ |
614 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
615 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
616 |
if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable) |
617 |
{ |
618 |
MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
619 |
return; |
620 |
} |
621 |
|
622 |
if (gridViewConverter.GetSelectedRows().Length == 0) |
623 |
{ |
624 |
MessageBox.Show(Msg.SelectDocument, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
625 |
return; |
626 |
} |
627 |
DataTable tDrawing = Project_DB.SelectDrawings(); |
628 |
this._Documents.Clear(); |
629 |
foreach (int rowHandle in gridViewConverter.GetSelectedRows()) |
630 |
{ |
631 |
string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath"); |
632 |
string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit"); |
633 |
string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate"); |
634 |
string _DrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber"); |
635 |
string _DrawingName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingName"); |
636 |
string _RuleName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colRuleName"); |
637 |
DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png")); |
638 |
if (rows.Length != 1) |
639 |
continue; |
640 |
|
641 |
SPPID_Document document = _DicDocuments[_FilePath]; |
642 |
document.Unit = _Unit; |
643 |
document.Template = _Template; |
644 |
document.DrawingNumber = _DrawingNumber; |
645 |
document.DrawingName = _DrawingName; |
646 |
document.UID = rows[0]["UID"].ToString(); |
647 |
document.BulkAttributeName = _RuleName; |
648 |
|
649 |
document.SymbolTable = _ID2SymbolTable; |
650 |
document.SymbolMappings = symbolMappings; |
651 |
document.ChildSymbolMappings = childSymbolMappings; |
652 |
document.LineMappings = lineMappings; |
653 |
document.LineNumberMappings = lineNumberMappings; |
654 |
document.AttributeMappings = attributeMappings; |
655 |
document.ETCSetting = ETCSetting.GetInstance(); |
656 |
document.SetSPPIDInfo(); |
657 |
|
658 |
if (document.SetSPPIDMapping() && document.Enable) |
659 |
this._Documents.Add(document); |
660 |
} |
661 |
|
662 |
if (_Documents.Count > 50) |
663 |
checkEditCloseDocument.Checked = true; |
664 |
|
665 |
tDrawing.Dispose(); |
666 |
DialogResult = DialogResult.OK; |
667 |
} |
668 |
|
669 |
private void btnSPPIDDB_Click(object sender, EventArgs e) |
670 |
{ |
671 |
SPPID_DB_SettingForm form = new SPPID_DB_SettingForm(); |
672 |
if (form.ShowDialog() == DialogResult.OK) |
673 |
InitSPPIDDB(); |
674 |
} |
675 |
|
676 |
private void btnItemMapping_Click(object sender, EventArgs e) |
677 |
{ |
678 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
679 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
680 |
if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable) |
681 |
{ |
682 |
MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
683 |
return; |
684 |
} |
685 |
|
686 |
MappingForm form = new MappingForm(_ID2SymbolDT,_SPPIDSymbolPathDT, _ID2LineDT, _ID2LinePropertyDT, _ID2AttributeDT, _SPPIDAttributeDT, _ID2DrawingAttributeDT); |
687 |
form.ShowDialog(); |
688 |
InitMapping(); |
689 |
RefreshBulkRule(); |
690 |
} |
691 |
private List<int> prevSelectedList = new List<int>(); |
692 |
|
693 |
private void gridViewConverter_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) |
694 |
{ |
695 |
if (e.Action == CollectionChangeAction.Add) |
696 |
{ |
697 |
string _Unit = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colUnit"); |
698 |
string _Template = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colTemplate"); |
699 |
|
700 |
if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template)) |
701 |
gridViewConverter.UnselectRow(e.ControllerRow); |
702 |
} |
703 |
else if (e.Action == CollectionChangeAction.Refresh) |
704 |
{ |
705 |
foreach (int rowHandle in gridViewConverter.GetSelectedRows()) |
706 |
{ |
707 |
string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit"); |
708 |
string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate"); |
709 |
|
710 |
if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template)) |
711 |
gridViewConverter.UnselectRow(rowHandle); |
712 |
} |
713 |
|
714 |
List<int> selectedRowHandleList = gridViewConverter.GetSelectedRows().ToList(); |
715 |
var firstNotSecond = prevSelectedList.Except(selectedRowHandleList).ToList(); |
716 |
var secondNotFirst = selectedRowHandleList.Except(prevSelectedList).ToList(); |
717 |
|
718 |
if (!firstNotSecond.Any() && !secondNotFirst.Any()) |
719 |
{ |
720 |
this.gridViewConverter.SelectionChanged -= new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged); |
721 |
gridViewConverter.ClearSelection(); |
722 |
this.gridViewConverter.SelectionChanged += new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged); |
723 |
} |
724 |
} |
725 |
|
726 |
prevSelectedList = gridViewConverter.GetSelectedRows().ToList(); |
727 |
} |
728 |
|
729 |
private void buttonEditDefaulUnit_ButtonClick(object sender, ButtonPressedEventArgs e) |
730 |
{ |
731 |
UnitForm unitForm = new UnitForm(_SPPIDUnitDT); |
732 |
if (unitForm.ShowDialog() == DialogResult.OK) |
733 |
{ |
734 |
buttonEditDefaultUnit.Text = unitForm.SelectedUnit; |
735 |
} |
736 |
} |
737 |
|
738 |
private void btnRefresh_Click(object sender, EventArgs e) |
739 |
{ |
740 |
List<BaseModel.Document> validationFailDocs = new List<BaseModel.Document>(); |
741 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
742 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
743 |
if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable) |
744 |
{ |
745 |
MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
746 |
return; |
747 |
} |
748 |
|
749 |
foreach (DataRow row in _ConverterDT.Rows) |
750 |
{ |
751 |
string fileName = row["colDrawingFilePath"].ToString(); |
752 |
SPPID_Document document = new SPPID_Document(fileName, _ID2SymbolTypeDT); |
753 |
document.SymbolTable = _ID2SymbolTable; |
754 |
document.SymbolMappings = symbolMappings; |
755 |
document.ChildSymbolMappings = childSymbolMappings; |
756 |
document.LineMappings = lineMappings; |
757 |
document.LineNumberMappings = lineNumberMappings; |
758 |
document.AttributeMappings = attributeMappings; |
759 |
document.ETCSetting = ETCSetting.GetInstance(); |
760 |
document.SetSPPIDInfo(); |
761 |
|
762 |
|
763 |
if (!document.SetSPPIDMapping()) |
764 |
{ |
765 |
document.Enable = false; |
766 |
document.MappingValidation = false; |
767 |
} |
768 |
|
769 |
row["colDrawingNumber"] = document.DWGNAME; |
770 |
row["colDrawingName"] = document.DWGNAME; |
771 |
if (document.Enable) |
772 |
row["colStatus"] = "Ready"; |
773 |
else |
774 |
row["colStatus"] = "Error"; |
775 |
|
776 |
if (!_DicDocuments.ContainsKey(fileName)) |
777 |
_DicDocuments.Add(fileName, null); |
778 |
|
779 |
if (!document.Validation || !document.MappingValidation) |
780 |
validationFailDocs.Add(document); |
781 |
|
782 |
_DicDocuments[fileName] = document; |
783 |
|
784 |
if (document.Enable && document.Validation && document.MappingValidation) |
785 |
gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
786 |
} |
787 |
|
788 |
|
789 |
if (validationFailDocs.Count > 0) |
790 |
{ |
791 |
MessageForm messageForm = new MessageForm(validationFailDocs); |
792 |
messageForm.ShowDialog(); |
793 |
} |
794 |
} |
795 |
|
796 |
private void buttonEditDefaultUnit_TextChanged(object sender, EventArgs e) |
797 |
{ |
798 |
Settings.Default.DefaultUnit = buttonEditDefaultUnit.Text; |
799 |
Settings.Default.Save(); |
800 |
} |
801 |
|
802 |
private void comboBoxEditDefaultTemplate_SelectedIndexChanged(object sender, EventArgs e) |
803 |
{ |
804 |
Settings.Default.DefaultTemplate = comboBoxEditDefaultTemplate.SelectedItem.ToString(); |
805 |
Settings.Default.Save(); |
806 |
} |
807 |
|
808 |
private void comboBoxEditBulk_SelectedIndexChanged(object sender, EventArgs e) |
809 |
{ |
810 |
Settings.Default.DefaultBulkRule = comboBoxEditBulk.SelectedItem.ToString(); |
811 |
Settings.Default.Save(); |
812 |
} |
813 |
|
814 |
private void RefreshBulkRule() |
815 |
{ |
816 |
ETCSetting eTCSetting = ETCSetting.GetInstance(); |
817 |
bulkRuleComboBox.Items.Clear(); |
818 |
bulkRuleComboBox.Items.Add(""); |
819 |
foreach (var item in eTCSetting.BulkAttributes) |
820 |
if (!bulkRuleComboBox.Items.Contains(item.RuleName)) |
821 |
bulkRuleComboBox.Items.Add(item.RuleName); |
822 |
|
823 |
for (int i = 0; i < gridViewConverter.DataRowCount; i++) |
824 |
{ |
825 |
DataRow row = gridViewConverter.GetDataRow(i); |
826 |
object data = row["colRuleName"]; |
827 |
if (data != null && !DBNull.Value.Equals(data)) |
828 |
{ |
829 |
string sData = data.ToString(); |
830 |
if (eTCSetting.BulkAttributes.Find(x => x.RuleName.Equals(sData)) == null) |
831 |
row["colRuleName"] = string.Empty; |
832 |
} |
833 |
} |
834 |
|
835 |
comboBoxEditBulk.Properties.Items.Clear(); |
836 |
comboBoxEditBulk.Properties.Items.Add(""); |
837 |
foreach (var item in eTCSetting.BulkAttributes) |
838 |
if (!comboBoxEditBulk.Properties.Items.Contains(item.RuleName)) |
839 |
comboBoxEditBulk.Properties.Items.Add(item.RuleName); |
840 |
if (eTCSetting.BulkAttributes.Find(x => x.RuleName.Equals(comboBoxEditBulk.Text)) == null) |
841 |
comboBoxEditBulk.SelectedIndex = 0; |
842 |
} |
843 |
|
844 |
|
845 |
} |
846 |
} |