hytos / DTI_PID / SPPIDConverter_AutoModeling / MainControl2.cs @ c7a0bb20
이력 | 보기 | 이력해설 | 다운로드 (29.7 KB)
1 | aac983d3 | gaqhf | 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 | 5e67ad61 | gaqhf | else if (item.Key == "DrainSize") |
289 | { |
||
290 | radTextBoxDrainSize.Text = item.Value; |
||
291 | } |
||
292 | aac983d3 | gaqhf | else if (item.Key != "SmallSize") |
293 | { |
||
294 | attributeDT.Rows.Add(new object[] { item.Key, item.Value }); |
||
295 | } |
||
296 | } |
||
297 | |||
298 | needSymbolMapping = needSymbolMapping.Distinct().ToList(); |
||
299 | d7341835 | gaqhf | needSymbolMapping.Add(SPPID.Model.Text.pipingCompSize); |
300 | needSymbolMapping.Add(SPPID.Model.Text.instrumentSize); |
||
301 | 5e67ad61 | gaqhf | needSymbolMapping.Add("End Break"); |
302 | aac983d3 | gaqhf | foreach (string item in needSymbolMapping) |
303 | { |
||
304 | if (!symbolMapping.ContainsKey(item)) |
||
305 | symbolDT.Rows.Add(item, ""); |
||
306 | } |
||
307 | needAttributeMapping = needAttributeMapping.Distinct().ToList(); |
||
308 | foreach (string item in needAttributeMapping) |
||
309 | { |
||
310 | if (!attributeMapping.ContainsKey(item)) |
||
311 | attributeDT.Rows.Add(item, ""); |
||
312 | } |
||
313 | |||
314 | gridViewSymbol.EndUpdate(); |
||
315 | gridViewAttribute.EndUpdate(); |
||
316 | } |
||
317 | } |
||
318 | |||
319 | |||
320 | #region Converter Page |
||
321 | |||
322 | private void RefreshGridViewDrawingList() |
||
323 | { |
||
324 | if (gridControlConverter.InvokeRequired) |
||
325 | { |
||
326 | gridControlConverter.BeginInvoke(new Action(() => gridControlConverter.Refresh())); |
||
327 | Thread.Sleep(1); |
||
328 | } |
||
329 | else |
||
330 | { |
||
331 | gridControlConverter.Refresh(); |
||
332 | } |
||
333 | } |
||
334 | |||
335 | private void btnLoadFiles_Click(object sender, EventArgs e) |
||
336 | { |
||
337 | OpenFileDialog dia = new OpenFileDialog(); |
||
338 | dia.Multiselect = true; |
||
339 | dia.Filter = "Xml Files(*.xml)|*.xml"; |
||
340 | if (dia.ShowDialog() == DialogResult.OK) |
||
341 | { |
||
342 | foreach (string fileName in dia.FileNames) |
||
343 | { |
||
344 | try |
||
345 | { |
||
346 | DataRow row = converterDT.NewRow(); |
||
347 | Document document = Document.Load(fileName, symbolMapping, attributeMapping); |
||
348 | |||
349 | if (document == null) |
||
350 | { |
||
351 | row[""] = fileName; |
||
352 | row["colDrawingFileName"] = fileName; |
||
353 | row["colStatus"] = _LoadFail; |
||
354 | } |
||
355 | else |
||
356 | { |
||
357 | row["colDrawingFileName"] = document.DWGNAME; |
||
358 | row["colDrawingNumber"] = document.DWGNAME; |
||
359 | row["colDrawingName"] = document.DWGNAME; |
||
360 | } |
||
361 | string sUID = Guid.NewGuid().ToString(); |
||
362 | row["colUID"] = sUID; |
||
363 | dicDocument.Add(sUID, document); |
||
364 | converterDT.Rows.Add(row); |
||
365 | gridViewConverter.BestFitColumns(); |
||
366 | } |
||
367 | catch (Exception ex) |
||
368 | { |
||
369 | |||
370 | } |
||
371 | } |
||
372 | } |
||
373 | } |
||
374 | |||
375 | private void btnRun_Click(object sender, EventArgs e) |
||
376 | { |
||
377 | if (!CheckDB()) |
||
378 | { |
||
379 | MessageBox.Show("Please Check DB Setting", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
380 | return; |
||
381 | } |
||
382 | |||
383 | if (gridViewConverter.SelectedRowsCount > 0) |
||
384 | { |
||
385 | if (DialogResult.OK == MessageBox.Show("SPPID Converter를 실행하시겠습니까?", "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)) |
||
386 | { |
||
387 | try |
||
388 | { |
||
389 | ProgressForm.stop = false; |
||
390 | foreach (int rowHandle in gridViewConverter.GetSelectedRows()) |
||
391 | { |
||
392 | try |
||
393 | { |
||
394 | string sStatus = gridViewConverter.GetRowCellDisplayText(rowHandle, "colStatus"); |
||
395 | |||
396 | if (sStatus == _Ready && !ProgressForm.stop) |
||
397 | { |
||
398 | gridViewConverter.SetRowCellValue(rowHandle, "colStatus", _Processing); |
||
399 | RefreshGridViewDrawingList(); |
||
400 | |||
401 | string sUnit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit"); |
||
402 | string sTemplate = TemplatePath + @"\" + gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate"); |
||
403 | string sDrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber"); |
||
404 | string sDrawingName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingName"); |
||
405 | |||
406 | // |
||
407 | dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
||
408 | dynamic newDrawing = application.Drawings.Add(sUnit, sTemplate, sDrawingNumber, sDrawingName); |
||
409 | application.ActiveWindow.Fit(); |
||
410 | Thread.Sleep(100); |
||
411 | d7341835 | gaqhf | application.ActiveWindow.Zoom = 60; |
412 | aac983d3 | gaqhf | Thread.Sleep(100); |
413 | // |
||
414 | d7341835 | gaqhf | |
415 | 7a01d2c1 | gaqhf | |
416 | |||
417 | aac983d3 | gaqhf | Document document = dicDocument[gridViewConverter.GetRowCellDisplayText(rowHandle, "colUID")]; |
418 | autoModelingThread = new Thread(Func => |
||
419 | { |
||
420 | try |
||
421 | { |
||
422 | Thread.Sleep(500); |
||
423 | ProgressForm.UpdateDocument(document.DWGNAME); |
||
424 | AutoModeling auto = new AutoModeling(document); |
||
425 | auto.Run(); |
||
426 | ProgressForm.End(); |
||
427 | } |
||
428 | catch (Exception ex) |
||
429 | { |
||
430 | Log.WriteLine(ex); |
||
431 | } |
||
432 | }); |
||
433 | ProgressForm.Start(autoModelingThread); |
||
434 | |||
435 | gridViewConverter.SetRowCellValue(rowHandle, "colStatus", _EndProcess); |
||
436 | RefreshGridViewDrawingList(); |
||
437 | application.ActiveWindow.Fit(); |
||
438 | d7341835 | gaqhf | //Thread.Sleep(100); |
439 | //newDrawing.CloseDrawing(true); |
||
440 | //Thread.Sleep(100); |
||
441 | aac983d3 | gaqhf | } |
442 | } |
||
443 | catch (Exception ex) |
||
444 | { |
||
445 | gridViewConverter.SetRowCellValue(rowHandle, "colStatus", _Error); |
||
446 | } |
||
447 | } |
||
448 | } |
||
449 | catch (Exception ex) |
||
450 | { |
||
451 | MessageBox.Show(ex.Message); |
||
452 | } |
||
453 | } |
||
454 | } |
||
455 | else |
||
456 | { |
||
457 | MessageBox.Show("도면을 선택해주세요!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
458 | } |
||
459 | } |
||
460 | |||
461 | private void UnitButton_ButtonClick(object sender, ButtonPressedEventArgs e) |
||
462 | { |
||
463 | UnitForm unitForm = new UnitForm(dUnit); |
||
464 | if (unitForm.ShowDialog() == DialogResult.OK) |
||
465 | { |
||
466 | ButtonEdit button = sender as ButtonEdit; |
||
467 | button.EditValue = unitForm.SelectedUnit; |
||
468 | gridViewConverter.CloseEditor(); |
||
469 | gridViewConverter.UpdateCurrentRow(); |
||
470 | gridViewConverter.BestFitColumns(); |
||
471 | } |
||
472 | } |
||
473 | |||
474 | private void gridViewConverter_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) |
||
475 | { |
||
476 | if (e.Column.FieldName == "colUnit" || e.Column.FieldName == "colTemplate") |
||
477 | { |
||
478 | CheckStatus(e.RowHandle); |
||
479 | } |
||
480 | } |
||
481 | |||
482 | private void CheckStatus(int rowHandle) |
||
483 | { |
||
484 | bool result = true; |
||
485 | |||
486 | string sUnit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit"); |
||
487 | string sTemplate = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate"); |
||
488 | string sUID = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUID"); |
||
489 | |||
490 | Document document = dicDocument[sUID]; |
||
491 | if (!document.ReMapping(needSymbolMapping, needAttributeMapping)) |
||
492 | { |
||
493 | needSymbolMapping = needSymbolMapping.Distinct().ToList(); |
||
494 | needAttributeMapping = needAttributeMapping.Distinct().ToList(); |
||
495 | result = false; |
||
496 | } |
||
497 | |||
498 | if (string.IsNullOrEmpty(sUnit) || string.IsNullOrEmpty(sTemplate)) |
||
499 | result = false; |
||
500 | |||
501 | if (result) |
||
502 | gridViewConverter.SetRowCellValue(rowHandle, "colStatus", "Ready"); |
||
503 | else |
||
504 | gridViewConverter.SetRowCellValue(rowHandle, "colStatus", ""); |
||
505 | } |
||
506 | |||
507 | #endregion |
||
508 | |||
509 | |||
510 | |||
511 | |||
512 | |||
513 | |||
514 | #region DB Setting Page |
||
515 | |||
516 | private void LoadPlantiniFile_Click(object sender, EventArgs e) |
||
517 | { |
||
518 | try |
||
519 | { |
||
520 | OpenFileDialog dialog = new OpenFileDialog(); |
||
521 | dialog.Multiselect = false; |
||
522 | dialog.Filter = "ini File(*.ini)|*.ini"; |
||
523 | if (dialog.ShowDialog() == DialogResult.OK) |
||
524 | { |
||
525 | string sDBTYPE = string.Empty; |
||
526 | string sSERVICENAME = string.Empty; |
||
527 | string sUID = string.Empty; |
||
528 | |||
529 | string[] texts = File.ReadAllLines(dialog.FileName); |
||
530 | |||
531 | bool find = false; |
||
532 | for (int i = 0; i < texts.Length; i++) |
||
533 | { |
||
534 | string text = texts[i]; |
||
535 | |||
536 | if (text.Trim() == "[SITESCHEMA]") |
||
537 | find = true; |
||
538 | |||
539 | if (find) |
||
540 | { |
||
541 | if (text.StartsWith("DBTYPE=") && string.IsNullOrEmpty(sDBTYPE)) |
||
542 | sDBTYPE = text.Remove(0, "DBTYPE=".Length); |
||
543 | else if (text.StartsWith("DBSERVER=") && string.IsNullOrEmpty(sSERVICENAME)) |
||
544 | sSERVICENAME = text.Remove(0, "DBSERVER=".Length); |
||
545 | else if (text.StartsWith("UID=") && string.IsNullOrEmpty(sUID)) |
||
546 | sUID = text.Remove(0, "UID=".Length); |
||
547 | } |
||
548 | } |
||
549 | |||
550 | if (string.IsNullOrEmpty(sDBTYPE) || string.IsNullOrEmpty(sSERVICENAME) || string.IsNullOrEmpty(sUID)) |
||
551 | MessageBox.Show("Unavailable ini file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
552 | else |
||
553 | { |
||
554 | tbDBType.Text = sDBTYPE; |
||
555 | tbServiceName.Text = sSERVICENAME; |
||
556 | tbSiteName.Text = sUID; |
||
557 | } |
||
558 | } |
||
559 | } |
||
560 | catch (Exception ex) |
||
561 | { |
||
562 | MessageBox.Show("Unavailable ini file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
563 | } |
||
564 | } |
||
565 | |||
566 | private void btnDBTest_Click(object sender, EventArgs e) |
||
567 | { |
||
568 | try |
||
569 | { |
||
570 | SetDBInformation(); |
||
571 | comboBoxPlantList.Properties.Items.Clear(); |
||
572 | comboBoxPlantList.SelectedIndex = -1; |
||
573 | List<string> plantList = DB.GetPlantList(); |
||
574 | if (plantList.Count > 0) |
||
575 | { |
||
576 | comboBoxPlantList.Properties.Items.AddRange(plantList); |
||
577 | comboBoxPlantList.SelectedIndex = 0; |
||
578 | |||
579 | MessageBox.Show("Success.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
580 | } |
||
581 | |||
582 | } |
||
583 | catch (Exception ex) |
||
584 | { |
||
585 | |||
586 | } |
||
587 | } |
||
588 | |||
589 | private void SetDBInformation() |
||
590 | { |
||
591 | DBInformation dbInfo = DBInformation.GetInstance(); |
||
592 | dbInfo.Status = false; |
||
593 | dbInfo.DBType = tbDBType.Text; |
||
594 | dbInfo.Service = tbServiceName.Text; |
||
595 | dbInfo.Site = tbSiteName.Text; |
||
596 | dbInfo.ServerIP = tbServerIP.Text; |
||
597 | dbInfo.Port = tbPort.Text; |
||
598 | dbInfo.DBUser = tbDBUser.Text; |
||
599 | dbInfo.DBPassword = tbDBPassword.Text; |
||
600 | } |
||
601 | |||
602 | private bool CheckDB() |
||
603 | { |
||
604 | bool result = false; |
||
605 | |||
606 | List<string> plantList = DB.GetPlantList(); |
||
607 | string selectedPlant = comboBoxPlantList.Properties.Items[comboBoxPlantList.SelectedIndex].ToString(); |
||
608 | if (plantList.Contains(selectedPlant)) |
||
609 | result = true; |
||
610 | |||
611 | return result; |
||
612 | } |
||
613 | |||
614 | private void btnSave_Click(object sender, EventArgs e) |
||
615 | { |
||
616 | try |
||
617 | { |
||
618 | if (comboBoxPlantList.SelectedIndex == -1) |
||
619 | { |
||
620 | MessageBox.Show("Plant를 선택해주세요.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
621 | return; |
||
622 | } |
||
623 | DBInformation dbInfo = DBInformation.GetInstance(); |
||
624 | SetDBInformation(); |
||
625 | List<string> plantList = DB.GetPlantList(); |
||
626 | string selectedPlant = comboBoxPlantList.Properties.Items[comboBoxPlantList.SelectedIndex].ToString(); |
||
627 | if (plantList.Contains(selectedPlant) && DB.SetPlantDBSetting()) |
||
628 | { |
||
629 | 5e67ad61 | gaqhf | //dbInfo.Plant = selectedPlant; |
630 | aac983d3 | gaqhf | dbInfo.PlantList = plantList; |
631 | dbInfo.Status = true; |
||
632 | string sJson = JsonConvert.SerializeObject(dbInfo); |
||
633 | SPPIDUtill.SaveDB(sJson); |
||
634 | |||
635 | MessageBox.Show("DB 정보를 저장하였습니다.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
636 | } |
||
637 | else |
||
638 | { |
||
639 | MessageBox.Show("저장에 실패하였습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
||
640 | } |
||
641 | } |
||
642 | catch (Exception ex) |
||
643 | { |
||
644 | MessageBox.Show("저장에 실패하였습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
||
645 | } |
||
646 | } |
||
647 | |||
648 | #endregion |
||
649 | |||
650 | |||
651 | |||
652 | #region Mapping Page |
||
653 | |||
654 | private void SymbolButton_ButtonClick(object sender, ButtonPressedEventArgs e) |
||
655 | { |
||
656 | SymbolPathForm symbolPathForm = new SymbolPathForm(symbolPathDT); |
||
657 | if (symbolPathForm.ShowDialog() == DialogResult.OK) |
||
658 | { |
||
659 | ButtonEdit button = sender as ButtonEdit; |
||
660 | button.EditValue = symbolPathForm.FullPath; |
||
661 | gridViewSymbol.CloseEditor(); |
||
662 | gridViewSymbol.UpdateCurrentRow(); |
||
663 | gridViewSymbol.BestFitColumns(); |
||
664 | } |
||
665 | } |
||
666 | |||
667 | private void btnMappingSave_Click(object sender, EventArgs e) |
||
668 | { |
||
669 | symbolMapping.Clear(); |
||
670 | foreach (DataRow row in symbolDT.Rows) |
||
671 | { |
||
672 | if (row["colItemName"] != null && row["colSPPIDName"] != null) |
||
673 | { |
||
674 | string key = row["colItemName"].ToString(); |
||
675 | string value = row["colSPPIDName"].ToString(); |
||
676 | |||
677 | if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) |
||
678 | { |
||
679 | if (symbolMapping.ContainsKey(key)) |
||
680 | symbolMapping[key] = value; |
||
681 | else |
||
682 | symbolMapping.Add(key, value); |
||
683 | } |
||
684 | |||
685 | } |
||
686 | } |
||
687 | |||
688 | attributeMapping.Clear(); |
||
689 | foreach (DataRow row in attributeDT.Rows) |
||
690 | { |
||
691 | if (row["colAttribute"] != null && row["colSPPIDAttribute"] != null) |
||
692 | { |
||
693 | string key = row["colAttribute"].ToString(); |
||
694 | string value = row["colSPPIDAttribute"].ToString(); |
||
695 | |||
696 | if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) |
||
697 | { |
||
698 | if (attributeMapping.ContainsKey(key)) |
||
699 | attributeMapping[key] = value; |
||
700 | else |
||
701 | attributeMapping.Add(key, value); |
||
702 | } |
||
703 | |||
704 | } |
||
705 | } |
||
706 | |||
707 | // Custom |
||
708 | if (radioGroupReducer.SelectedIndex == 0) |
||
709 | { |
||
710 | attributeMapping.Add("LargeSize", radioGroupReducer.Properties.Items[0].Tag.ToString()); |
||
711 | attributeMapping.Add("SmallSize", radioGroupReducer.Properties.Items[1].Tag.ToString()); |
||
712 | } |
||
713 | else |
||
714 | { |
||
715 | attributeMapping.Add("LargeSize", radioGroupReducer.Properties.Items[1].Tag.ToString()); |
||
716 | attributeMapping.Add("SmallSize", radioGroupReducer.Properties.Items[0].Tag.ToString()); |
||
717 | } |
||
718 | |||
719 | 5e67ad61 | gaqhf | if (!string.IsNullOrEmpty(radTextBoxDrainSize.Text)) |
720 | attributeMapping.Add("DrainSize", radTextBoxDrainSize.Text); |
||
721 | |||
722 | |||
723 | d7341835 | gaqhf | if (textBoxFittingSymbolPath.EditValue != null) |
724 | symbolMapping.Add("FittingSymbolPath", textBoxFittingSymbolPath.EditValue.ToString()); |
||
725 | |||
726 | aac983d3 | gaqhf | |
727 | SPPIDUtill.SaveMapping(symbolMapping, attributeMapping); |
||
728 | |||
729 | for (int i = 0; i < converterDT.Rows.Count; i++) |
||
730 | { |
||
731 | CheckStatus(gridViewConverter.GetRowHandle(i)); |
||
732 | } |
||
733 | |||
734 | MessageBox.Show("Save success!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
735 | } |
||
736 | |||
737 | private void textBoxSymbolPath_ButtonClick(object sender, ButtonPressedEventArgs e) |
||
738 | { |
||
739 | SymbolPathForm symbolPathForm = new SymbolPathForm(symbolPathDT); |
||
740 | if (symbolPathForm.ShowDialog() == DialogResult.OK) |
||
741 | { |
||
742 | ButtonEdit button = sender as ButtonEdit; |
||
743 | button.EditValue = symbolPathForm.FullPath; |
||
744 | } |
||
745 | } |
||
746 | |||
747 | #endregion |
||
748 | |||
749 | |||
750 | } |
||
751 | } |