hytos / DTI_PID / SPPIDConverter_AutoModeling / ConverterForm.cs @ 635a8747
이력 | 보기 | 이력해설 | 다운로드 (19.3 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 Converter.BaseModel; |
12 |
using DevExpress.XtraEditors.Repository; |
13 |
using DevExpress.XtraEditors.Controls; |
14 |
using DevExpress.XtraEditors; |
15 |
using System.Globalization; |
16 |
using System.Threading; |
17 |
using System.IO; |
18 |
using Converter.AutoModeling.SPPID.Properties; |
19 |
using Converter.AutoModeling.SPPID.DB; |
20 |
using Converter.AutoModeling.SPPID.Util; |
21 |
using Converter.AutoModeling.SPPID.Form; |
22 |
using Converter.AutoModeling.SPPID.Model; |
23 |
|
24 |
namespace Converter.AutoModeling.SPPID |
25 |
{ |
26 |
public partial class ConverterForm : DevExpress.XtraBars.Ribbon.RibbonForm |
27 |
{ |
28 |
private Dictionary<string, SPPID_Document> _DicDocuments = new Dictionary<string, SPPID_Document>(); |
29 |
private DataTable _ConverterDT = new DataTable(); |
30 |
private DataTable _SPPIDSymbolPathDT = new DataTable(); |
31 |
private DataTable _SPPIDUnitDT = new DataTable(); |
32 |
private RepositoryItemComboBox templateComboBox; |
33 |
|
34 |
|
35 |
private DataTable _ID2SymbolDT = new DataTable(); |
36 |
private DataTable _ID2LineDT = new DataTable(); |
37 |
private DataTable _ID2AssociationDT = new DataTable(); |
38 |
private DataTable _ID2LinePropertyDT = new DataTable(); |
39 |
|
40 |
private List<SymbolMapping> symbolMappings = new List<SymbolMapping>(); |
41 |
private List<LineMapping> lineMappings = new List<LineMapping>(); |
42 |
private List<LineNumberMapping> lineNumberMappings = new List<LineNumberMapping>(); |
43 |
private List<AssociationMapping> associationMappings = new List<AssociationMapping>(); |
44 |
|
45 |
public ConverterForm() |
46 |
{ |
47 |
InitializeComponent(); |
48 |
|
49 |
CultureInfo culture = CultureInfo.GetCultureInfo("ko"); |
50 |
Msg.Culture = culture; |
51 |
|
52 |
InitUsedDataTable(); |
53 |
InitGridControl(); |
54 |
InitID2Project(); |
55 |
} |
56 |
|
57 |
private void InitUsedDataTable() |
58 |
{ |
59 |
// Converter Table |
60 |
DataColumn col = _ConverterDT.Columns.Add("colDrawingFileName"); |
61 |
col.Caption = "Drawing File Name"; |
62 |
col = _ConverterDT.Columns.Add("colDrawingFilePath"); |
63 |
col.Caption = "DrawingFilePath"; |
64 |
col = _ConverterDT.Columns.Add("colUnit"); |
65 |
col.Caption = "Unit"; |
66 |
col = _ConverterDT.Columns.Add("colTemplate"); |
67 |
col.Caption = "Template"; |
68 |
col = _ConverterDT.Columns.Add("colDrawingNumber"); |
69 |
col.Caption = "Drawing Number"; |
70 |
col = _ConverterDT.Columns.Add("colDrawingName"); |
71 |
col.Caption = "Drawing Name"; |
72 |
col = _ConverterDT.Columns.Add("colStatus"); |
73 |
col.Caption = "Status"; |
74 |
col = _ConverterDT.Columns.Add("colUID"); |
75 |
|
76 |
col = _ID2LineDT.Columns.Add("UID"); |
77 |
col = _ID2LineDT.Columns.Add("Name"); |
78 |
col.Caption = "Name"; |
79 |
col = _ID2LineDT.Columns.Add("Type"); |
80 |
col.Caption = "Type"; |
81 |
col = _ID2LineDT.Columns.Add("SPPID_SYMBOL_PATH"); |
82 |
col.Caption = "SPPID Symbol Path"; |
83 |
col = _ID2LineDT.Columns.Add("Clear"); |
84 |
col.Caption = ""; |
85 |
} |
86 |
|
87 |
private void InitGridControl() |
88 |
{ |
89 |
#region Converter Page |
90 |
gridViewConverter.OptionsSelection.MultiSelect = true; |
91 |
gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; |
92 |
|
93 |
gridControlConverter.DataSource = _ConverterDT; |
94 |
|
95 |
templateComboBox = new RepositoryItemComboBox(); |
96 |
templateComboBox.TextEditStyle = TextEditStyles.DisableTextEditor; |
97 |
templateComboBox.EditValueChanged += templateComboBox_EditValueChanged; |
98 |
gridControlConverter.RepositoryItems.Add(templateComboBox); |
99 |
gridViewConverter.Columns["colTemplate"].ColumnEdit = templateComboBox; |
100 |
|
101 |
//RepositoryItemButtonEdit unitButton = new RepositoryItemButtonEdit(); |
102 |
//unitButton.ButtonClick += UnitButton_ButtonClick; |
103 |
//unitButton.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
104 |
//gridControlConverter.RepositoryItems.Add(unitButton); |
105 |
//gridViewConverter.Columns["colUnit"].ColumnEdit = unitButton; |
106 |
|
107 |
gridViewConverter.Columns["colUnit"].OptionsColumn.AllowEdit = false; |
108 |
gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false; |
109 |
gridViewConverter.Columns["colUnit"].OptionsColumn.ReadOnly = true; |
110 |
gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false; |
111 |
gridViewConverter.Columns["colDrawingFilePath"].Visible = false; |
112 |
gridViewConverter.Columns["colUID"].Visible = false; |
113 |
|
114 |
gridViewConverter.BestFitColumns(); |
115 |
#endregion |
116 |
} |
117 |
private void templateComboBox_EditValueChanged(object sender, EventArgs e) |
118 |
{ |
119 |
gridViewConverter.CloseEditor(); |
120 |
gridViewConverter.UpdateCurrentRow(); |
121 |
} |
122 |
|
123 |
private void gridViewConverter_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) |
124 |
{ |
125 |
if (e.Column.Name == "colcolTemplate") |
126 |
{ |
127 |
gridViewConverter.ShowEditor(); |
128 |
(gridViewConverter.ActiveEditor as ComboBoxEdit).ShowPopup(); |
129 |
} |
130 |
else if (e.Column.Name == "colcolUnit") |
131 |
{ |
132 |
UnitForm unitForm = new UnitForm(_SPPIDUnitDT); |
133 |
if (unitForm.ShowDialog() == DialogResult.OK) |
134 |
{ |
135 |
gridViewConverter.SetRowCellValue(e.RowHandle, e.Column, unitForm.SelectedUnit); |
136 |
gridViewConverter.CloseEditor(); |
137 |
gridViewConverter.UpdateCurrentRow(); |
138 |
} |
139 |
} |
140 |
} |
141 |
|
142 |
private void btnID2Project_ButtonClick(object sender, ButtonPressedEventArgs e) |
143 |
{ |
144 |
xtraFolderBrowserDialog.SelectedPath = btnID2Project.Text; |
145 |
|
146 |
if (xtraFolderBrowserDialog.ShowDialog() == DialogResult.OK) |
147 |
{ |
148 |
if (xtraFolderBrowserDialog.SelectedPath[xtraFolderBrowserDialog.SelectedPath.Length - 1] == '\\') |
149 |
xtraFolderBrowserDialog.SelectedPath = xtraFolderBrowserDialog.SelectedPath.Remove(xtraFolderBrowserDialog.SelectedPath.Length - 1); |
150 |
Settings.Default.LatestProjectPath = xtraFolderBrowserDialog.SelectedPath; |
151 |
Settings.Default.Save(); |
152 |
if (InitID2Project()) |
153 |
{ |
154 |
MessageBox.Show(Msg.SuccessProjectSelect, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
155 |
} |
156 |
else |
157 |
MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
158 |
} |
159 |
} |
160 |
|
161 |
private bool InitID2Project() |
162 |
{ |
163 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
164 |
_ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath; |
165 |
if (Project_DB.ConnTestAndCreateTable()) |
166 |
{ |
167 |
_ProjectInfo.Enable = true; |
168 |
btnID2Project.Text = _ProjectInfo.DefaultPath; |
169 |
labelID2ProjectName.Text = _ProjectInfo.Name; |
170 |
labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue; |
171 |
labelID2ProjectStatus.Text = Msg.ConnectionSuccessful; |
172 |
labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
173 |
layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
174 |
layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
175 |
} |
176 |
else |
177 |
{ |
178 |
_ProjectInfo.Enable = false; |
179 |
btnID2Project.Text = ""; |
180 |
labelID2ProjectName.Text = " "; |
181 |
labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red; |
182 |
labelID2ProjectStatus.Text = Msg.ConnectionFail; |
183 |
labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red; |
184 |
layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
185 |
layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
186 |
} |
187 |
|
188 |
InitMapping(); |
189 |
InitSPPIDDB(); |
190 |
|
191 |
return _ProjectInfo.Enable; |
192 |
} |
193 |
|
194 |
private void InitMapping() |
195 |
{ |
196 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
197 |
if (_ProjectInfo.Enable) |
198 |
{ |
199 |
InitID2Symbol(); |
200 |
InitID2Line(); |
201 |
InitID2LineNumber(); |
202 |
InitID2Association(); |
203 |
|
204 |
InitETCSetting(); |
205 |
} |
206 |
} |
207 |
private void InitETCSetting() |
208 |
{ |
209 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
210 |
if (_ProjectInfo.Enable) |
211 |
{ |
212 |
DataTable dt = Project_DB.SelectETCSetting(); |
213 |
if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
214 |
SPPIDUtil.ConvertToETCSetting(dt.Rows[0][0].ToString()); |
215 |
else |
216 |
SPPID_DBInfo.Clear(); |
217 |
} |
218 |
} |
219 |
|
220 |
private void InitID2Symbol() |
221 |
{ |
222 |
using (DataTable symbolDT = Project_DB.SelectProjectSymbol()) |
223 |
{ |
224 |
symbolMappings.Clear(); |
225 |
_ID2SymbolDT = symbolDT; |
226 |
_ID2SymbolDT.Columns.Add("Clear"); |
227 |
_ID2SymbolDT.Columns["Clear"].Caption = ""; |
228 |
foreach (DataRow row in symbolDT.Rows) |
229 |
{ |
230 |
symbolMappings.Add(new SymbolMapping() |
231 |
{ |
232 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
233 |
SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(), |
234 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
235 |
}); |
236 |
} |
237 |
} |
238 |
} |
239 |
|
240 |
private void InitID2Line() |
241 |
{ |
242 |
using (DataTable lineTypes = Project_DB.SelectProjectLine()) |
243 |
{ |
244 |
lineMappings.Clear(); |
245 |
_ID2LineDT.Rows.Clear(); |
246 |
foreach (DataRow row in lineTypes.Rows) |
247 |
{ |
248 |
DataRow newRow = _ID2LineDT.NewRow(); |
249 |
newRow["UID"] = row["UID"] == null ? "" : row["UID"].ToString(); |
250 |
newRow["Name"] = row["Name"] == null ? "" : row["Name"].ToString(); |
251 |
newRow["Type"] = "Line"; |
252 |
newRow["SPPID_SYMBOL_PATH"] = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(); |
253 |
_ID2LineDT.Rows.Add(newRow); |
254 |
|
255 |
lineMappings.Add(new LineMapping() |
256 |
{ |
257 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
258 |
LINENAME = row["Name"] == null ? "" : row["Name"].ToString(), |
259 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
260 |
}); |
261 |
} |
262 |
} |
263 |
} |
264 |
|
265 |
private void InitID2LineNumber() |
266 |
{ |
267 |
using (DataTable linePropertiesDT = Project_DB.SelectProjectLineProperties()) |
268 |
{ |
269 |
lineNumberMappings.Clear(); |
270 |
_ID2LinePropertyDT = linePropertiesDT; |
271 |
_ID2LinePropertyDT.Columns.Add("Type"); |
272 |
foreach (DataRow row in linePropertiesDT.Rows) |
273 |
{ |
274 |
row["Type"] = "Line Property"; |
275 |
lineNumberMappings.Add(new LineNumberMapping() |
276 |
{ |
277 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
278 |
DisplayName = row["DisplayName"] == null ? "" : row["DisplayName"].ToString(), |
279 |
SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(), |
280 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString() |
281 |
}); |
282 |
} |
283 |
} |
284 |
} |
285 |
|
286 |
private void InitID2Association() |
287 |
{ |
288 |
using (DataTable associationDT = Project_DB.SelectProjectAssociation()) |
289 |
{ |
290 |
associationMappings.Clear(); |
291 |
_ID2AssociationDT = associationDT; |
292 |
_ID2AssociationDT.Columns.Add("Clear"); |
293 |
_ID2AssociationDT.Columns["Clear"].Caption = ""; |
294 |
foreach (DataRow row in associationDT.Rows) |
295 |
{ |
296 |
associationMappings.Add(new AssociationMapping() |
297 |
{ |
298 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
299 |
DisplayAttribute = row["DisplayAttribute"] == null ? "" : row["DisplayAttribute"].ToString(), |
300 |
Type = row["Type"] == null ? "" : row["Type"].ToString(), |
301 |
SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(), |
302 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString() |
303 |
}); |
304 |
} |
305 |
} |
306 |
} |
307 |
|
308 |
private void InitSPPIDDB() |
309 |
{ |
310 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
311 |
if (_ProjectInfo.Enable) |
312 |
{ |
313 |
DataTable dt = Project_DB.SelectSPPID_DB_INFO(); |
314 |
if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
315 |
SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString()); |
316 |
else |
317 |
SPPID_DBInfo.Clear(); |
318 |
} |
319 |
|
320 |
templateComboBox.Items.Clear(); |
321 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
322 |
if (_SPPIDInfo.Enable) |
323 |
{ |
324 |
labelSPPIDPlantName.Text = _SPPIDInfo.SelectedPlant; |
325 |
labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Blue; |
326 |
labelSPPIDDBStatus.Text = Msg.ConnectionSuccessful; |
327 |
labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
328 |
|
329 |
string TemplatePath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("PID Template Path"); |
330 |
if (!string.IsNullOrEmpty(TemplatePath)) |
331 |
templateComboBox.Items.AddRange(Directory.GetFiles(TemplatePath, "*.pid").ToList().Select(filePath => Path.GetFileName(filePath)).ToList()); |
332 |
|
333 |
_SPPIDUnitDT = SPPID_DB.GetUnitTree(); |
334 |
|
335 |
layoutControlGroupAutoConverter.Enabled = true; |
336 |
} |
337 |
else |
338 |
{ |
339 |
labelSPPIDPlantName.Text = " "; |
340 |
labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Red; |
341 |
labelSPPIDDBStatus.Text = Msg.ConnectionFail; |
342 |
labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Red; |
343 |
|
344 |
layoutControlGroupAutoConverter.Enabled = false; |
345 |
} |
346 |
|
347 |
_DicDocuments.Clear(); |
348 |
_ConverterDT.Rows.Clear(); |
349 |
InitSPPIDSymbolTreeTable(); |
350 |
} |
351 |
|
352 |
private void InitSPPIDSymbolTreeTable() |
353 |
{ |
354 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
355 |
|
356 |
_SPPIDSymbolPathDT = new DataTable(); |
357 |
_SPPIDSymbolPathDT.Columns.Add("ID"); |
358 |
_SPPIDSymbolPathDT.Columns.Add("Parent"); |
359 |
_SPPIDSymbolPathDT.Columns.Add("Name"); |
360 |
_SPPIDSymbolPathDT.Columns.Add("FullPath"); |
361 |
|
362 |
if (_SPPIDInfo.Enable) |
363 |
{ |
364 |
string symbolPath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("Catalog Explorer root path"); |
365 |
DirectoryInfo info = new DirectoryInfo(symbolPath); |
366 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { "0", "-1", info.Name }); |
367 |
loop(info, "0", symbolPath); |
368 |
} |
369 |
} |
370 |
|
371 |
private void loop(DirectoryInfo parentInfo, string parentUID, string defaultPath) |
372 |
{ |
373 |
DirectoryInfo[] infos = parentInfo.GetDirectories(); |
374 |
foreach (DirectoryInfo info in infos) |
375 |
{ |
376 |
string uid = Guid.NewGuid().ToString(); |
377 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { uid, parentUID, info.Name }); |
378 |
loop(info, uid, defaultPath); |
379 |
|
380 |
FileInfo[] files = info.GetFiles("*.sym"); |
381 |
foreach (FileInfo fileInfo in files) |
382 |
{ |
383 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { Guid.NewGuid().ToString(), uid, fileInfo.Name, fileInfo.FullName.Replace(defaultPath, "") }); |
384 |
} |
385 |
} |
386 |
} |
387 |
|
388 |
private void btnLoadFile_Click(object sender, EventArgs e) |
389 |
{ |
390 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
391 |
if (!_ProjectInfo.Enable) |
392 |
{ |
393 |
MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
394 |
return; |
395 |
} |
396 |
|
397 |
xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath; |
398 |
if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK) |
399 |
{ |
400 |
foreach (string fileName in xtraOpenFileDialog.FileNames) |
401 |
{ |
402 |
SPPID_Document document = new SPPID_Document(fileName); |
403 |
document.SymbolMappings = symbolMappings; |
404 |
DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName)); |
405 |
DataRow row; |
406 |
if (rows.Length == 0) |
407 |
{ |
408 |
row = _ConverterDT.NewRow(); |
409 |
row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName); |
410 |
row["colDrawingFilePath"] = fileName; |
411 |
row["colDrawingNumber"] = document.DWGNAME; |
412 |
row["colDrawingName"] = document.DWGNAME; |
413 |
if (document.Enable) |
414 |
row["colStatus"] = "Ready"; |
415 |
else |
416 |
row["colStatus"] = "Error"; |
417 |
row["colUID"] = ""; |
418 |
_ConverterDT.Rows.Add(row); |
419 |
} |
420 |
if (!_DicDocuments.ContainsKey(fileName)) |
421 |
_DicDocuments.Add(fileName, null); |
422 |
|
423 |
_DicDocuments[fileName] = document; |
424 |
} |
425 |
} |
426 |
} |
427 |
|
428 |
private void btnRun_Click(object sender, EventArgs e) |
429 |
{ |
430 |
DialogResult = DialogResult.OK; |
431 |
} |
432 |
|
433 |
private void btnSPPIDDB_Click(object sender, EventArgs e) |
434 |
{ |
435 |
SPPID_DB_SettingForm form = new SPPID_DB_SettingForm(); |
436 |
if (form.ShowDialog() == DialogResult.OK) |
437 |
InitSPPIDDB(); |
438 |
} |
439 |
|
440 |
private void btnItemMapping_Click(object sender, EventArgs e) |
441 |
{ |
442 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
443 |
if (!_ProjectInfo.Enable) |
444 |
{ |
445 |
MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
446 |
return; |
447 |
} |
448 |
|
449 |
MappingForm form = new MappingForm(_ID2SymbolDT,_SPPIDSymbolPathDT, _ID2LineDT, _ID2LinePropertyDT, _ID2AssociationDT); |
450 |
form.ShowDialog(); |
451 |
InitMapping(); |
452 |
} |
453 |
|
454 |
} |
455 |
} |