hytos / DTI_PID / SPPIDConverter_AutoModeling / MainControl2.cs @ aac983d3
이력 | 보기 | 이력해설 | 다운로드 (29.1 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel; |
4 |
using System.Drawing; |
5 |
using System.Data; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Windows.Forms; |
10 |
using Microsoft.Win32; |
11 |
using System.IO; |
12 |
using System.Threading; |
13 |
using SPPID.Modeling; |
14 |
using SPPID.Model; |
15 |
using SPPID.Utill; |
16 |
using SPPID.DB; |
17 |
using Microsoft.VisualBasic; |
18 |
using Newtonsoft.Json; |
19 |
using DevExpress.XtraEditors.Repository; |
20 |
using DevExpress.XtraEditors.Controls; |
21 |
using DevExpress.XtraEditors; |
22 | |
23 |
namespace SPPIDConverter_AutoModeling |
24 |
{ |
25 |
public partial class MainControl2 : UserControl |
26 |
{ |
27 |
const string _Ready = "Ready"; |
28 |
const string _LoadFail = "Can't Load"; |
29 |
const string _NeedMapping = "Need Mapping"; |
30 |
const string _NeedUnit = "Select Unit"; |
31 |
const string _NeedTemplate = "Select Template"; |
32 |
const string _Error = "Error"; |
33 |
const string _EndProcess = "End Process"; |
34 |
const string _Processing = "Processing"; |
35 | |
36 |
Thread autoModelingThread; |
37 |
Dictionary<string, Document> dicDocument = new Dictionary<string, Document>(); |
38 |
private Dictionary<string, string> symbolMapping = new Dictionary<string, string>(); |
39 |
private Dictionary<string, string> attributeMapping = new Dictionary<string, string>(); |
40 |
List<string> needSymbolMapping = new List<string>(); |
41 |
List<string> needAttributeMapping = new List<string>(); |
42 |
private DataTable dUnit = new DataTable(); |
43 |
private string TemplatePath; |
44 |
private string SymbolPath; |
45 | |
46 |
DataTable converterDT = new DataTable(); |
47 |
DataTable symbolDT = new DataTable(); |
48 |
DataTable attributeDT = new DataTable(); |
49 |
DataTable symbolPathDT = new DataTable(); |
50 |
RepositoryItemComboBox templateComboBox; |
51 |
RepositoryItemComboBox attributeComboBox; |
52 | |
53 |
public MainControl2() |
54 |
{ |
55 |
InitializeComponent(); |
56 | |
57 |
if (InitPath()) |
58 |
{ |
59 |
InitDBSettingPage(); |
60 |
if (SPPIDUtill.LoadDB()) |
61 |
{ |
62 |
InitGridControl(); |
63 |
InitDBInformation(); |
64 |
} |
65 |
else |
66 |
MessageBox.Show("Please Check DB Setting", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
67 |
} |
68 |
else |
69 |
{ |
70 | |
71 |
} |
72 |
} |
73 | |
74 |
private void InitGridControl() |
75 |
{ |
76 |
#region Converter Page |
77 |
gridViewConverter.OptionsSelection.MultiSelect = true; |
78 |
gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; |
79 | |
80 |
DataColumn col = converterDT.Columns.Add("colDrawingFileName"); |
81 |
col.Caption = "Drawing File Name"; |
82 |
col = converterDT.Columns.Add("colUnit"); |
83 |
col.Caption = "Unit"; |
84 |
col = converterDT.Columns.Add("colTemplate"); |
85 |
col.Caption = "Template"; |
86 |
col = converterDT.Columns.Add("colDrawingNumber"); |
87 |
col.Caption = "Drawing Number"; |
88 |
col = converterDT.Columns.Add("colDrawingName"); |
89 |
col.Caption = "Drawing Name"; |
90 |
col = converterDT.Columns.Add("colStatus"); |
91 |
col.Caption = "Status"; |
92 |
col = converterDT.Columns.Add("colUID"); |
93 |
gridControlConverter.DataSource = converterDT; |
94 | |
95 |
templateComboBox = new RepositoryItemComboBox(); |
96 |
templateComboBox.TextEditStyle = TextEditStyles.DisableTextEditor; |
97 |
gridControlConverter.RepositoryItems.Add(templateComboBox); |
98 |
gridViewConverter.Columns["colTemplate"].ColumnEdit = templateComboBox; |
99 | |
100 |
RepositoryItemButtonEdit unitButton = new RepositoryItemButtonEdit(); |
101 |
unitButton.ButtonClick += UnitButton_ButtonClick; |
102 |
unitButton.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
103 |
gridControlConverter.RepositoryItems.Add(unitButton); |
104 |
gridViewConverter.Columns["colUnit"].ColumnEdit = unitButton; |
105 | |
106 |
gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false; |
107 |
gridViewConverter.Columns["colUnit"].OptionsColumn.ReadOnly = true; |
108 |
gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false; |
109 |
gridViewConverter.Columns["colUID"].Visible = false; |
110 | |
111 |
gridViewConverter.BestFitColumns(); |
112 |
#endregion |
113 | |
114 |
#region Mapping Page |
115 |
col = symbolDT.Columns.Add("colItemName"); |
116 |
col.Caption = "Item Name"; |
117 |
col = symbolDT.Columns.Add("colSPPIDName"); |
118 |
col.Caption = "SPPID Name"; |
119 |
gridControlSymbol.DataSource = symbolDT; |
120 |
RepositoryItemButtonEdit symbolButton = new RepositoryItemButtonEdit(); |
121 |
symbolButton.ButtonClick += SymbolButton_ButtonClick; |
122 |
symbolButton.TextEditStyle = TextEditStyles.DisableTextEditor; |
123 |
gridControlSymbol.RepositoryItems.Add(symbolButton); |
124 |
gridViewSymbol.Columns["colSPPIDName"].ColumnEdit = symbolButton; |
125 |
gridViewSymbol.Columns["colItemName"].OptionsColumn.AllowEdit = false; |
126 | |
127 |
col = attributeDT.Columns.Add("colAttribute"); |
128 |
col.Caption = "Attribute Name"; |
129 |
col = attributeDT.Columns.Add("colSPPIDAttribute"); |
130 |
col.Caption = "SPPID Attribute Name"; |
131 |
gridControlAttribute.DataSource = attributeDT; |
132 |
attributeComboBox = new RepositoryItemComboBox(); |
133 |
attributeComboBox.TextEditStyle = TextEditStyles.DisableTextEditor; |
134 |
gridControlAttribute.RepositoryItems.Add(attributeComboBox); |
135 |
gridViewAttribute.Columns["colSPPIDAttribute"].ColumnEdit = attributeComboBox; |
136 |
gridViewAttribute.Columns["colAttribute"].OptionsColumn.AllowEdit = false; |
137 |
#endregion |
138 |
} |
139 | |
140 |
private bool InitPath() |
141 |
{ |
142 |
try |
143 |
{ |
144 |
RegistryKey key = Registry.LocalMachine; |
145 |
RegistryKey software = key.OpenSubKey("SOFTWARE"); |
146 |
RegistryKey DOFTECH = software.OpenSubKey("DOFTECH"); |
147 |
if (DOFTECH != null) |
148 |
{ |
149 |
RegistryKey ID2 = DOFTECH.OpenSubKey("ID2"); |
150 |
if (ID2 != null) |
151 |
{ |
152 |
SPPIDUtill.defaultPath = ID2.GetValue("Path").ToString(); |
153 |
Log.logPath = SPPIDUtill.defaultPath + @"Converter\SPPID Converter.log"; |
154 |
SPPIDUtill.mappingFilePath = SPPIDUtill.defaultPath + @"Converter\mapping.xml"; |
155 |
SPPIDUtill.dbFilePath = SPPIDUtill.defaultPath + @"Converter\DB.config"; |
156 | |
157 |
return true; |
158 |
} |
159 |
} |
160 |
} |
161 |
catch (Exception ex) |
162 |
{ |
163 | |
164 |
} |
165 | |
166 |
return false; |
167 |
} |
168 | |
169 |
public void InitDBInformation() |
170 |
{ |
171 |
try |
172 |
{ |
173 |
DBInformation dbInfo = DBInformation.GetInstance(); |
174 |
if (dbInfo.Status) |
175 |
{ |
176 |
tbDBType.Text = dbInfo.DBType; |
177 |
tbServiceName.Text = dbInfo.Service; |
178 |
tbSiteName.Text = dbInfo.Site; |
179 |
tbServerIP.Text = dbInfo.ServerIP; |
180 |
tbPort.Text = dbInfo.Port; |
181 |
tbDBUser.Text = dbInfo.DBUser; |
182 |
tbDBPassword.Text = dbInfo.DBPassword; |
183 |
comboBoxPlantList.Properties.Items.AddRange(dbInfo.PlantList); |
184 |
comboBoxPlantList.SelectedIndex = dbInfo.PlantList.FindIndex(x => x == dbInfo.Plant); |
185 |
} |
186 | |
187 |
// Unit DataTable |
188 |
dUnit = DB.GetUnitTree(); |
189 | |
190 |
// Template List |
191 |
TemplatePath = DB.GetPlantPID_T_OPTIONSETTING_Value("PID Template Path"); |
192 |
if (!string.IsNullOrEmpty(TemplatePath)) |
193 |
{ |
194 |
templateComboBox.Items.Clear(); |
195 |
templateComboBox.Items.AddRange(Directory.GetFiles(TemplatePath, "*.pid").ToList().Select(filePath => Path.GetFileName(filePath)).ToList()); |
196 |
} |
197 | |
198 |
// Symbol Path |
199 |
SymbolPath = DB.GetPlantPID_T_OPTIONSETTING_Value("Catalog Explorer root path"); |
200 |
SetPathDataTable(); |
201 | |
202 |
// Load Mapping |
203 |
SPPIDUtill.LoadMapping(symbolMapping, attributeMapping); |
204 |
foreach (var item in symbolMapping) |
205 |
symbolDT.Rows.Add(item.Key, item.Value); |
206 |
gridViewSymbol.BestFitColumns(); |
207 | |
208 |
// Attribute |
209 |
attributeComboBox.Items.Clear(); |
210 |
attributeComboBox.Items.AddRange(DB.GetSPPIDAttribute()); |
211 | |
212 |
// Load Attribute |
213 |
foreach (var item in attributeMapping) |
214 |
attributeDT.Rows.Add(new object[] { item.Key, item.Value }); |
215 |
} |
216 |
catch (Exception ex) |
217 |
{ |
218 | |
219 |
} |
220 |
} |
221 | |
222 |
private void SetPathDataTable() |
223 |
{ |
224 |
symbolPathDT = new DataTable(); |
225 |
symbolPathDT.Columns.Add("ID"); |
226 |
symbolPathDT.Columns.Add("Parent"); |
227 |
symbolPathDT.Columns.Add("Name"); |
228 |
symbolPathDT.Columns.Add("FullPath"); |
229 | |
230 |
DirectoryInfo info = new DirectoryInfo(SymbolPath); |
231 |
symbolPathDT.Rows.Add(new object[] { "0", "-1", info.Name }); |
232 |
loop(info, "0"); |
233 |
} |
234 | |
235 |
private void loop(DirectoryInfo parentInfo, string parentUID) |
236 |
{ |
237 |
DirectoryInfo[] infos = parentInfo.GetDirectories(); |
238 |
foreach (DirectoryInfo info in infos) |
239 |
{ |
240 |
string uid = Guid.NewGuid().ToString(); |
241 |
symbolPathDT.Rows.Add(new object[] { uid, parentUID, info.Name }); |
242 |
loop(info, uid); |
243 | |
244 |
FileInfo[] files = info.GetFiles("*.sym"); |
245 |
foreach (FileInfo fileInfo in files) |
246 |
{ |
247 |
symbolPathDT.Rows.Add(new object[] { Guid.NewGuid().ToString(), uid, fileInfo.Name, fileInfo.FullName.Replace(SymbolPath, "") }); |
248 |
} |
249 |
} |
250 |
} |
251 | |
252 |
public void InitDBSettingPage() |
253 |
{ |
254 |
comboBoxPlantList.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
255 |
textBoxFittingSymbolPath.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
256 |
} |
257 | |
258 |
private void tabControl_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e) |
259 |
{ |
260 |
if (e.Page.Name == "pageItemMapping") |
261 |
{ |
262 |
gridViewSymbol.BeginUpdate(); |
263 |
gridViewAttribute.BeginUpdate(); |
264 | |
265 |
symbolDT.Rows.Clear(); |
266 |
attributeDT.Rows.Clear(); |
267 | |
268 |
foreach (var item in symbolMapping) |
269 |
{ |
270 |
if (item.Key == "FittingSymbolPath") |
271 |
{ |
272 |
textBoxFittingSymbolPath.EditValue = item.Value; |
273 |
} |
274 |
else |
275 |
{ |
276 |
symbolDT.Rows.Add(item.Key, item.Value); |
277 |
} |
278 |
} |
279 |
foreach (var item in attributeMapping) |
280 |
{ |
281 |
if (item.Key == "LargeSize") |
282 |
{ |
283 |
if (radioGroupReducer.Properties.Items[0].Tag.ToString() == item.Value) |
284 |
radioGroupReducer.SelectedIndex = 0; |
285 |
else |
286 |
radioGroupReducer.SelectedIndex = 1; |
287 |
} |
288 |
else if (item.Key != "SmallSize") |
289 |
{ |
290 |
attributeDT.Rows.Add(new object[] { item.Key, item.Value }); |
291 |
} |
292 |
} |
293 | |
294 |
needSymbolMapping = needSymbolMapping.Distinct().ToList(); |
295 |
foreach (string item in needSymbolMapping) |
296 |
{ |
297 |
if (!symbolMapping.ContainsKey(item)) |
298 |
symbolDT.Rows.Add(item, ""); |
299 |
} |
300 |
needAttributeMapping = needAttributeMapping.Distinct().ToList(); |
301 |
foreach (string item in needAttributeMapping) |
302 |
{ |
303 |
if (!attributeMapping.ContainsKey(item)) |
304 |
attributeDT.Rows.Add(item, ""); |
305 |
} |
306 | |
307 |
gridViewSymbol.EndUpdate(); |
308 |
gridViewAttribute.EndUpdate(); |
309 |
} |
310 |
} |
311 | |
312 | |
313 |
#region Converter Page |
314 | |
315 |
private void RefreshGridViewDrawingList() |
316 |
{ |
317 |
if (gridControlConverter.InvokeRequired) |
318 |
{ |
319 |
gridControlConverter.BeginInvoke(new Action(() => gridControlConverter.Refresh())); |
320 |
Thread.Sleep(1); |
321 |
} |
322 |
else |
323 |
{ |
324 |
gridControlConverter.Refresh(); |
325 |
} |
326 |
} |
327 | |
328 |
private void btnLoadFiles_Click(object sender, EventArgs e) |
329 |
{ |
330 |
OpenFileDialog dia = new OpenFileDialog(); |
331 |
dia.Multiselect = true; |
332 |
dia.Filter = "Xml Files(*.xml)|*.xml"; |
333 |
if (dia.ShowDialog() == DialogResult.OK) |
334 |
{ |
335 |
foreach (string fileName in dia.FileNames) |
336 |
{ |
337 |
try |
338 |
{ |
339 |
DataRow row = converterDT.NewRow(); |
340 |
Document document = Document.Load(fileName, symbolMapping, attributeMapping); |
341 | |
342 |
if (document == null) |
343 |
{ |
344 |
row[""] = fileName; |
345 |
row["colDrawingFileName"] = fileName; |
346 |
row["colStatus"] = _LoadFail; |
347 |
} |
348 |
else |
349 |
{ |
350 |
row["colDrawingFileName"] = document.DWGNAME; |
351 |
row["colDrawingNumber"] = document.DWGNAME; |
352 |
row["colDrawingName"] = document.DWGNAME; |
353 |
} |
354 |
string sUID = Guid.NewGuid().ToString(); |
355 |
row["colUID"] = sUID; |
356 |
dicDocument.Add(sUID, document); |
357 |
converterDT.Rows.Add(row); |
358 |
gridViewConverter.BestFitColumns(); |
359 |
} |
360 |
catch (Exception ex) |
361 |
{ |
362 | |
363 |
} |
364 |
} |
365 |
} |
366 |
} |
367 | |
368 |
private void btnRun_Click(object sender, EventArgs e) |
369 |
{ |
370 |
if (!CheckDB()) |
371 |
{ |
372 |
MessageBox.Show("Please Check DB Setting", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
373 |
return; |
374 |
} |
375 | |
376 |
if (gridViewConverter.SelectedRowsCount > 0) |
377 |
{ |
378 |
if (DialogResult.OK == MessageBox.Show("SPPID Converter를 실행하시겠습니까?", "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)) |
379 |
{ |
380 |
try |
381 |
{ |
382 |
ProgressForm.stop = false; |
383 |
foreach (int rowHandle in gridViewConverter.GetSelectedRows()) |
384 |
{ |
385 |
try |
386 |
{ |
387 |
|
388 | |
389 |
string sStatus = gridViewConverter.GetRowCellDisplayText(rowHandle, "colStatus"); |
390 | |
391 |
if (sStatus == _Ready && !ProgressForm.stop) |
392 |
{ |
393 |
gridViewConverter.SetRowCellValue(rowHandle, "colStatus", _Processing); |
394 |
RefreshGridViewDrawingList(); |
395 | |
396 |
string sUnit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit"); |
397 |
string sTemplate = TemplatePath + @"\" + gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate"); |
398 |
string sDrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber"); |
399 |
string sDrawingName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingName"); |
400 | |
401 |
// |
402 |
dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
403 |
dynamic newDrawing = application.Drawings.Add(sUnit, sTemplate, sDrawingNumber, sDrawingName); |
404 |
application.ActiveWindow.Fit(); |
405 |
Thread.Sleep(100); |
406 |
application.ActiveWindow.Zoom = 2000; |
407 |
Thread.Sleep(100); |
408 |
// |
409 | |
410 |
Document document = dicDocument[gridViewConverter.GetRowCellDisplayText(rowHandle, "colUID")]; |
411 |
autoModelingThread = new Thread(Func => |
412 |
{ |
413 |
try |
414 |
{ |
415 |
Thread.Sleep(500); |
416 |
ProgressForm.UpdateDocument(document.DWGNAME); |
417 |
AutoModeling auto = new AutoModeling(document); |
418 |
auto.Run(); |
419 |
ProgressForm.End(); |
420 |
} |
421 |
catch (Exception ex) |
422 |
{ |
423 |
Log.WriteLine(ex); |
424 |
} |
425 |
}); |
426 |
ProgressForm.Start(autoModelingThread); |
427 | |
428 |
gridViewConverter.SetRowCellValue(rowHandle, "colStatus", _EndProcess); |
429 |
RefreshGridViewDrawingList(); |
430 |
application.ActiveWindow.Fit(); |
431 |
Thread.Sleep(100); |
432 |
newDrawing.CloseDrawing(true); |
433 |
Thread.Sleep(100); |
434 |
} |
435 |
} |
436 |
catch (Exception ex) |
437 |
{ |
438 |
gridViewConverter.SetRowCellValue(rowHandle, "colStatus", _Error); |
439 |
} |
440 |
} |
441 |
} |
442 |
catch (Exception ex) |
443 |
{ |
444 |
MessageBox.Show(ex.Message); |
445 |
} |
446 |
} |
447 |
} |
448 |
else |
449 |
{ |
450 |
MessageBox.Show("도면을 선택해주세요!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
451 |
} |
452 |
} |
453 | |
454 |
private void UnitButton_ButtonClick(object sender, ButtonPressedEventArgs e) |
455 |
{ |
456 |
UnitForm unitForm = new UnitForm(dUnit); |
457 |
if (unitForm.ShowDialog() == DialogResult.OK) |
458 |
{ |
459 |
ButtonEdit button = sender as ButtonEdit; |
460 |
button.EditValue = unitForm.SelectedUnit; |
461 |
gridViewConverter.CloseEditor(); |
462 |
gridViewConverter.UpdateCurrentRow(); |
463 |
gridViewConverter.BestFitColumns(); |
464 |
} |
465 |
} |
466 | |
467 |
private void gridViewConverter_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) |
468 |
{ |
469 |
if (e.Column.FieldName == "colUnit" || e.Column.FieldName == "colTemplate") |
470 |
{ |
471 |
CheckStatus(e.RowHandle); |
472 |
} |
473 |
} |
474 | |
475 |
private void CheckStatus(int rowHandle) |
476 |
{ |
477 |
bool result = true; |
478 | |
479 |
string sUnit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit"); |
480 |
string sTemplate = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate"); |
481 |
string sUID = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUID"); |
482 | |
483 |
Document document = dicDocument[sUID]; |
484 |
if (!document.ReMapping(needSymbolMapping, needAttributeMapping)) |
485 |
{ |
486 |
needSymbolMapping = needSymbolMapping.Distinct().ToList(); |
487 |
needAttributeMapping = needAttributeMapping.Distinct().ToList(); |
488 |
result = false; |
489 |
} |
490 | |
491 |
if (string.IsNullOrEmpty(sUnit) || string.IsNullOrEmpty(sTemplate)) |
492 |
result = false; |
493 | |
494 |
if (result) |
495 |
gridViewConverter.SetRowCellValue(rowHandle, "colStatus", "Ready"); |
496 |
else |
497 |
gridViewConverter.SetRowCellValue(rowHandle, "colStatus", ""); |
498 |
} |
499 | |
500 |
#endregion |
501 | |
502 | |
503 | |
504 | |
505 | |
506 | |
507 |
#region DB Setting Page |
508 | |
509 |
private void LoadPlantiniFile_Click(object sender, EventArgs e) |
510 |
{ |
511 |
try |
512 |
{ |
513 |
OpenFileDialog dialog = new OpenFileDialog(); |
514 |
dialog.Multiselect = false; |
515 |
dialog.Filter = "ini File(*.ini)|*.ini"; |
516 |
if (dialog.ShowDialog() == DialogResult.OK) |
517 |
{ |
518 |
string sDBTYPE = string.Empty; |
519 |
string sSERVICENAME = string.Empty; |
520 |
string sUID = string.Empty; |
521 | |
522 |
string[] texts = File.ReadAllLines(dialog.FileName); |
523 | |
524 |
bool find = false; |
525 |
for (int i = 0; i < texts.Length; i++) |
526 |
{ |
527 |
string text = texts[i]; |
528 | |
529 |
if (text.Trim() == "[SITESCHEMA]") |
530 |
find = true; |
531 | |
532 |
if (find) |
533 |
{ |
534 |
if (text.StartsWith("DBTYPE=") && string.IsNullOrEmpty(sDBTYPE)) |
535 |
sDBTYPE = text.Remove(0, "DBTYPE=".Length); |
536 |
else if (text.StartsWith("DBSERVER=") && string.IsNullOrEmpty(sSERVICENAME)) |
537 |
sSERVICENAME = text.Remove(0, "DBSERVER=".Length); |
538 |
else if (text.StartsWith("UID=") && string.IsNullOrEmpty(sUID)) |
539 |
sUID = text.Remove(0, "UID=".Length); |
540 |
} |
541 |
} |
542 | |
543 |
if (string.IsNullOrEmpty(sDBTYPE) || string.IsNullOrEmpty(sSERVICENAME) || string.IsNullOrEmpty(sUID)) |
544 |
MessageBox.Show("Unavailable ini file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
545 |
else |
546 |
{ |
547 |
tbDBType.Text = sDBTYPE; |
548 |
tbServiceName.Text = sSERVICENAME; |
549 |
tbSiteName.Text = sUID; |
550 |
} |
551 |
} |
552 |
} |
553 |
catch (Exception ex) |
554 |
{ |
555 |
MessageBox.Show("Unavailable ini file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
556 |
} |
557 |
} |
558 | |
559 |
private void btnDBTest_Click(object sender, EventArgs e) |
560 |
{ |
561 |
try |
562 |
{ |
563 |
SetDBInformation(); |
564 |
comboBoxPlantList.Properties.Items.Clear(); |
565 |
comboBoxPlantList.SelectedIndex = -1; |
566 |
List<string> plantList = DB.GetPlantList(); |
567 |
if (plantList.Count > 0) |
568 |
{ |
569 |
comboBoxPlantList.Properties.Items.AddRange(plantList); |
570 |
comboBoxPlantList.SelectedIndex = 0; |
571 | |
572 |
MessageBox.Show("Success.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); |
573 |
} |
574 |
|
575 |
} |
576 |
catch (Exception ex) |
577 |
{ |
578 | |
579 |
} |
580 |
} |
581 | |
582 |
private void SetDBInformation() |
583 |
{ |
584 |
DBInformation dbInfo = DBInformation.GetInstance(); |
585 |
dbInfo.Status = false; |
586 |
dbInfo.DBType = tbDBType.Text; |
587 |
dbInfo.Service = tbServiceName.Text; |
588 |
dbInfo.Site = tbSiteName.Text; |
589 |
dbInfo.ServerIP = tbServerIP.Text; |
590 |
dbInfo.Port = tbPort.Text; |
591 |
dbInfo.DBUser = tbDBUser.Text; |
592 |
dbInfo.DBPassword = tbDBPassword.Text; |
593 |
} |
594 | |
595 |
private bool CheckDB() |
596 |
{ |
597 |
bool result = false; |
598 | |
599 |
List<string> plantList = DB.GetPlantList(); |
600 |
string selectedPlant = comboBoxPlantList.Properties.Items[comboBoxPlantList.SelectedIndex].ToString(); |
601 |
if (plantList.Contains(selectedPlant)) |
602 |
result = true; |
603 | |
604 |
return result; |
605 |
} |
606 | |
607 |
private void btnSave_Click(object sender, EventArgs e) |
608 |
{ |
609 |
try |
610 |
{ |
611 |
if (comboBoxPlantList.SelectedIndex == -1) |
612 |
{ |
613 |
MessageBox.Show("Plant를 선택해주세요.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
614 |
return; |
615 |
} |
616 |
DBInformation dbInfo = DBInformation.GetInstance(); |
617 |
SetDBInformation(); |
618 |
List<string> plantList = DB.GetPlantList(); |
619 |
string selectedPlant = comboBoxPlantList.Properties.Items[comboBoxPlantList.SelectedIndex].ToString(); |
620 |
if (plantList.Contains(selectedPlant) && DB.SetPlantDBSetting()) |
621 |
{ |
622 |
dbInfo.Plant = selectedPlant; |
623 |
dbInfo.PlantList = plantList; |
624 |
dbInfo.Status = true; |
625 |
string sJson = JsonConvert.SerializeObject(dbInfo); |
626 |
SPPIDUtill.SaveDB(sJson); |
627 | |
628 |
MessageBox.Show("DB 정보를 저장하였습니다.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); |
629 |
} |
630 |
else |
631 |
{ |
632 |
MessageBox.Show("저장에 실패하였습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
633 |
} |
634 |
} |
635 |
catch (Exception ex) |
636 |
{ |
637 |
MessageBox.Show("저장에 실패하였습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
638 |
} |
639 |
} |
640 | |
641 |
#endregion |
642 | |
643 | |
644 | |
645 |
#region Mapping Page |
646 | |
647 |
private void SymbolButton_ButtonClick(object sender, ButtonPressedEventArgs e) |
648 |
{ |
649 |
SymbolPathForm symbolPathForm = new SymbolPathForm(symbolPathDT); |
650 |
if (symbolPathForm.ShowDialog() == DialogResult.OK) |
651 |
{ |
652 |
ButtonEdit button = sender as ButtonEdit; |
653 |
button.EditValue = symbolPathForm.FullPath; |
654 |
gridViewSymbol.CloseEditor(); |
655 |
gridViewSymbol.UpdateCurrentRow(); |
656 |
gridViewSymbol.BestFitColumns(); |
657 |
} |
658 |
} |
659 | |
660 |
private void btnMappingSave_Click(object sender, EventArgs e) |
661 |
{ |
662 |
symbolMapping.Clear(); |
663 |
foreach (DataRow row in symbolDT.Rows) |
664 |
{ |
665 |
if (row["colItemName"] != null && row["colSPPIDName"] != null) |
666 |
{ |
667 |
string key = row["colItemName"].ToString(); |
668 |
string value = row["colSPPIDName"].ToString(); |
669 | |
670 |
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) |
671 |
{ |
672 |
if (symbolMapping.ContainsKey(key)) |
673 |
symbolMapping[key] = value; |
674 |
else |
675 |
symbolMapping.Add(key, value); |
676 |
} |
677 | |
678 |
} |
679 |
} |
680 | |
681 |
attributeMapping.Clear(); |
682 |
foreach (DataRow row in attributeDT.Rows) |
683 |
{ |
684 |
if (row["colAttribute"] != null && row["colSPPIDAttribute"] != null) |
685 |
{ |
686 |
string key = row["colAttribute"].ToString(); |
687 |
string value = row["colSPPIDAttribute"].ToString(); |
688 | |
689 |
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) |
690 |
{ |
691 |
if (attributeMapping.ContainsKey(key)) |
692 |
attributeMapping[key] = value; |
693 |
else |
694 |
attributeMapping.Add(key, value); |
695 |
} |
696 | |
697 |
} |
698 |
} |
699 | |
700 |
// Custom |
701 |
if (radioGroupReducer.SelectedIndex == 0) |
702 |
{ |
703 |
attributeMapping.Add("LargeSize", radioGroupReducer.Properties.Items[0].Tag.ToString()); |
704 |
attributeMapping.Add("SmallSize", radioGroupReducer.Properties.Items[1].Tag.ToString()); |
705 |
} |
706 |
else |
707 |
{ |
708 |
attributeMapping.Add("LargeSize", radioGroupReducer.Properties.Items[1].Tag.ToString()); |
709 |
attributeMapping.Add("SmallSize", radioGroupReducer.Properties.Items[0].Tag.ToString()); |
710 |
} |
711 | |
712 |
symbolMapping.Add("FittingSymbolPath", textBoxFittingSymbolPath.EditValue.ToString()); |
713 |
|
714 |
SPPIDUtill.SaveMapping(symbolMapping, attributeMapping); |
715 | |
716 |
for (int i = 0; i < converterDT.Rows.Count; i++) |
717 |
{ |
718 |
CheckStatus(gridViewConverter.GetRowHandle(i)); |
719 |
} |
720 | |
721 |
MessageBox.Show("Save success!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); |
722 |
} |
723 | |
724 |
private void textBoxSymbolPath_ButtonClick(object sender, ButtonPressedEventArgs e) |
725 |
{ |
726 |
SymbolPathForm symbolPathForm = new SymbolPathForm(symbolPathDT); |
727 |
if (symbolPathForm.ShowDialog() == DialogResult.OK) |
728 |
{ |
729 |
ButtonEdit button = sender as ButtonEdit; |
730 |
button.EditValue = symbolPathForm.FullPath; |
731 |
} |
732 |
} |
733 | |
734 |
#endregion |
735 | |
736 | |
737 |
} |
738 |
} |