프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / SPPIDConverter_AutoModeling / MainControl2.cs @ d7341835

이력 | 보기 | 이력해설 | 다운로드 (29.4 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
                needSymbolMapping.Add(SPPID.Model.Text.pipingCompSize);
296
                needSymbolMapping.Add(SPPID.Model.Text.instrumentSize);
297
                foreach (string item in needSymbolMapping)
298
                {
299
                    if (!symbolMapping.ContainsKey(item))
300
                        symbolDT.Rows.Add(item, "");
301
                }
302
                needAttributeMapping = needAttributeMapping.Distinct().ToList();
303
                foreach (string item in needAttributeMapping)
304
                {
305
                    if (!attributeMapping.ContainsKey(item))
306
                        attributeDT.Rows.Add(item, "");
307
                }
308

    
309
                gridViewSymbol.EndUpdate();
310
                gridViewAttribute.EndUpdate();
311
            }
312
        }
313

    
314

    
315
        #region Converter Page
316

    
317
        private void RefreshGridViewDrawingList()
318
        {
319
            if (gridControlConverter.InvokeRequired)
320
            {
321
                gridControlConverter.BeginInvoke(new Action(() => gridControlConverter.Refresh()));
322
                Thread.Sleep(1);
323
            }
324
            else
325
            {
326
                gridControlConverter.Refresh();
327
            }
328
        }
329

    
330
        private void btnLoadFiles_Click(object sender, EventArgs e)
331
        {
332
            OpenFileDialog dia = new OpenFileDialog();
333
            dia.Multiselect = true;
334
            dia.Filter = "Xml Files(*.xml)|*.xml";
335
            if (dia.ShowDialog() == DialogResult.OK)
336
            {
337
                foreach (string fileName in dia.FileNames)
338
                {
339
                    try
340
                    {
341
                        DataRow row = converterDT.NewRow();
342
                        Document document = Document.Load(fileName, symbolMapping, attributeMapping);
343

    
344
                        if (document == null)
345
                        {
346
                            row[""] = fileName;
347
                            row["colDrawingFileName"] = fileName;
348
                            row["colStatus"] = _LoadFail;
349
                        }
350
                        else
351
                        {
352
                            row["colDrawingFileName"] = document.DWGNAME;
353
                            row["colDrawingNumber"] = document.DWGNAME;
354
                            row["colDrawingName"] = document.DWGNAME;
355
                        }
356
                        string sUID = Guid.NewGuid().ToString();
357
                        row["colUID"] = sUID;
358
                        dicDocument.Add(sUID, document);
359
                        converterDT.Rows.Add(row);
360
                        gridViewConverter.BestFitColumns();
361
                    }
362
                    catch (Exception ex)
363
                    {
364

    
365
                    }
366
                }
367
            }
368
        }
369

    
370
        private void btnRun_Click(object sender, EventArgs e)
371
        {
372
            if (!CheckDB())
373
            {
374
                MessageBox.Show("Please Check DB Setting", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
375
                return;
376
            }
377

    
378
            if (gridViewConverter.SelectedRowsCount > 0)
379
            {
380
                if (DialogResult.OK == MessageBox.Show("SPPID Converter를 실행하시겠습니까?", "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
381
                {
382
                    try
383
                    {
384
                        ProgressForm.stop = false;
385
                        foreach (int rowHandle in gridViewConverter.GetSelectedRows())
386
                        {
387
                            try
388
                            {
389
                                
390

    
391
                                string sStatus = gridViewConverter.GetRowCellDisplayText(rowHandle, "colStatus");
392

    
393
                                if (sStatus == _Ready && !ProgressForm.stop)
394
                                {
395
                                    gridViewConverter.SetRowCellValue(rowHandle, "colStatus", _Processing);
396
                                    RefreshGridViewDrawingList();
397

    
398
                                    string sUnit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit");
399
                                    string sTemplate = TemplatePath + @"\" + gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
400
                                    string sDrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber");
401
                                    string sDrawingName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingName");
402

    
403
                                    //
404
                                    dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
405
                                    dynamic newDrawing = application.Drawings.Add(sUnit, sTemplate, sDrawingNumber, sDrawingName);
406
                                    application.ActiveWindow.Fit();
407
                                    Thread.Sleep(100);
408
                                    application.ActiveWindow.Zoom = 60;
409
                                    Thread.Sleep(100);
410
                                    //
411
                                    
412
                                    Document document = dicDocument[gridViewConverter.GetRowCellDisplayText(rowHandle, "colUID")];
413
                                    autoModelingThread = new Thread(Func =>
414
                                    {
415
                                        try
416
                                        {
417
                                            Thread.Sleep(500);
418
                                            ProgressForm.UpdateDocument(document.DWGNAME);
419
                                            AutoModeling auto = new AutoModeling(document);
420
                                            auto.Run();
421
                                            ProgressForm.End();
422
                                        }
423
                                        catch (Exception ex)
424
                                        {
425
                                            Log.WriteLine(ex);
426
                                        }
427
                                    });
428
                                    ProgressForm.Start(autoModelingThread);
429

    
430
                                    gridViewConverter.SetRowCellValue(rowHandle, "colStatus", _EndProcess);
431
                                    RefreshGridViewDrawingList();
432
                                    application.ActiveWindow.Fit();
433
                                    //Thread.Sleep(100);
434
                                    //newDrawing.CloseDrawing(true);
435
                                    //Thread.Sleep(100);
436
                                }
437
                            }
438
                            catch (Exception ex)
439
                            {
440
                                gridViewConverter.SetRowCellValue(rowHandle, "colStatus", _Error);
441
                            }
442
                        }
443
                    }
444
                    catch (Exception ex)
445
                    {
446
                        MessageBox.Show(ex.Message);
447
                    }
448
                }
449
            }
450
            else
451
            {
452
                MessageBox.Show("도면을 선택해주세요!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
453
            }
454
        }
455

    
456
        private void UnitButton_ButtonClick(object sender, ButtonPressedEventArgs e)
457
        {
458
            UnitForm unitForm = new UnitForm(dUnit);
459
            if (unitForm.ShowDialog() == DialogResult.OK)
460
            {
461
                ButtonEdit button = sender as ButtonEdit;
462
                button.EditValue = unitForm.SelectedUnit;
463
                gridViewConverter.CloseEditor();
464
                gridViewConverter.UpdateCurrentRow();
465
                gridViewConverter.BestFitColumns();
466
            }
467
        }
468

    
469
        private void gridViewConverter_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
470
        {
471
            if (e.Column.FieldName == "colUnit" || e.Column.FieldName == "colTemplate")
472
            {
473
                CheckStatus(e.RowHandle);
474
            }
475
        }
476

    
477
        private void CheckStatus(int rowHandle)
478
        {
479
            bool result = true;
480

    
481
            string sUnit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit");
482
            string sTemplate = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
483
            string sUID = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUID");
484

    
485
            Document document = dicDocument[sUID];
486
            if (!document.ReMapping(needSymbolMapping, needAttributeMapping))
487
            {
488
                needSymbolMapping = needSymbolMapping.Distinct().ToList();
489
                needAttributeMapping = needAttributeMapping.Distinct().ToList();
490
                result = false;
491
            }
492

    
493
            if (string.IsNullOrEmpty(sUnit) || string.IsNullOrEmpty(sTemplate))
494
                result = false;
495

    
496
            if (result)
497
                gridViewConverter.SetRowCellValue(rowHandle, "colStatus", "Ready");
498
            else
499
                gridViewConverter.SetRowCellValue(rowHandle, "colStatus", "");
500
        }
501

    
502
        #endregion
503

    
504

    
505

    
506

    
507

    
508

    
509
        #region DB Setting Page
510

    
511
        private void LoadPlantiniFile_Click(object sender, EventArgs e)
512
        {
513
            try
514
            {
515
                OpenFileDialog dialog = new OpenFileDialog();
516
                dialog.Multiselect = false;
517
                dialog.Filter = "ini File(*.ini)|*.ini";
518
                if (dialog.ShowDialog() == DialogResult.OK)
519
                {
520
                    string sDBTYPE = string.Empty;
521
                    string sSERVICENAME = string.Empty;
522
                    string sUID = string.Empty;
523

    
524
                    string[] texts = File.ReadAllLines(dialog.FileName);
525

    
526
                    bool find = false;
527
                    for (int i = 0; i < texts.Length; i++)
528
                    {
529
                        string text = texts[i];
530

    
531
                        if (text.Trim() == "[SITESCHEMA]")
532
                            find = true;
533

    
534
                        if (find)
535
                        {
536
                            if (text.StartsWith("DBTYPE=") && string.IsNullOrEmpty(sDBTYPE))
537
                                sDBTYPE = text.Remove(0, "DBTYPE=".Length);
538
                            else if (text.StartsWith("DBSERVER=") && string.IsNullOrEmpty(sSERVICENAME))
539
                                sSERVICENAME = text.Remove(0, "DBSERVER=".Length);
540
                            else if (text.StartsWith("UID=") && string.IsNullOrEmpty(sUID))
541
                                sUID = text.Remove(0, "UID=".Length);
542
                        }
543
                    }
544

    
545
                    if (string.IsNullOrEmpty(sDBTYPE) || string.IsNullOrEmpty(sSERVICENAME) || string.IsNullOrEmpty(sUID))
546
                        MessageBox.Show("Unavailable ini file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
547
                    else
548
                    {
549
                        tbDBType.Text = sDBTYPE;
550
                        tbServiceName.Text = sSERVICENAME;
551
                        tbSiteName.Text = sUID;
552
                    }
553
                }
554
            }
555
            catch (Exception ex)
556
            {
557
                MessageBox.Show("Unavailable ini file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
558
            }
559
        }
560

    
561
        private void btnDBTest_Click(object sender, EventArgs e)
562
        {
563
            try
564
            {
565
                SetDBInformation();
566
                comboBoxPlantList.Properties.Items.Clear();
567
                comboBoxPlantList.SelectedIndex = -1;
568
                List<string> plantList = DB.GetPlantList();
569
                if (plantList.Count > 0)
570
                {
571
                    comboBoxPlantList.Properties.Items.AddRange(plantList);
572
                    comboBoxPlantList.SelectedIndex = 0;
573

    
574
                    MessageBox.Show("Success.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
575
                }
576
                    
577
            }
578
            catch (Exception ex)
579
            {
580

    
581
            }
582
        }
583

    
584
        private void SetDBInformation()
585
        {
586
            DBInformation dbInfo = DBInformation.GetInstance();
587
            dbInfo.Status = false;
588
            dbInfo.DBType = tbDBType.Text;
589
            dbInfo.Service = tbServiceName.Text;
590
            dbInfo.Site = tbSiteName.Text;
591
            dbInfo.ServerIP = tbServerIP.Text;
592
            dbInfo.Port = tbPort.Text;
593
            dbInfo.DBUser = tbDBUser.Text;
594
            dbInfo.DBPassword = tbDBPassword.Text;
595
        }
596

    
597
        private bool CheckDB()
598
        {
599
            bool result = false;
600

    
601
            List<string> plantList = DB.GetPlantList();
602
            string selectedPlant = comboBoxPlantList.Properties.Items[comboBoxPlantList.SelectedIndex].ToString();
603
            if (plantList.Contains(selectedPlant))
604
                result = true;
605

    
606
            return result;
607
        }
608

    
609
        private void btnSave_Click(object sender, EventArgs e)
610
        {
611
            try
612
            {
613
                if (comboBoxPlantList.SelectedIndex == -1)
614
                {
615
                    MessageBox.Show("Plant를 선택해주세요.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
616
                    return;
617
                }
618
                DBInformation dbInfo = DBInformation.GetInstance();
619
                SetDBInformation();
620
                List<string> plantList = DB.GetPlantList();
621
                string selectedPlant = comboBoxPlantList.Properties.Items[comboBoxPlantList.SelectedIndex].ToString();
622
                if (plantList.Contains(selectedPlant) && DB.SetPlantDBSetting())
623
                {
624
                    dbInfo.Plant = selectedPlant;
625
                    dbInfo.PlantList = plantList;
626
                    dbInfo.Status = true;
627
                    string sJson = JsonConvert.SerializeObject(dbInfo);
628
                    SPPIDUtill.SaveDB(sJson);
629

    
630
                    MessageBox.Show("DB 정보를 저장하였습니다.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
631
                }
632
                else
633
                {
634
                    MessageBox.Show("저장에 실패하였습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
635
                }
636
            }
637
            catch (Exception ex)
638
            {
639
                MessageBox.Show("저장에 실패하였습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
640
            }
641
        }
642

    
643
        #endregion
644

    
645

    
646

    
647
        #region Mapping Page
648

    
649
        private void SymbolButton_ButtonClick(object sender, ButtonPressedEventArgs e)
650
        {
651
            SymbolPathForm symbolPathForm = new SymbolPathForm(symbolPathDT);
652
            if (symbolPathForm.ShowDialog() == DialogResult.OK)
653
            {
654
                ButtonEdit button = sender as ButtonEdit;
655
                button.EditValue = symbolPathForm.FullPath;
656
                gridViewSymbol.CloseEditor();
657
                gridViewSymbol.UpdateCurrentRow();
658
                gridViewSymbol.BestFitColumns();
659
            }
660
        }
661

    
662
        private void btnMappingSave_Click(object sender, EventArgs e)
663
        {
664
            symbolMapping.Clear();
665
            foreach (DataRow row in symbolDT.Rows)
666
            {
667
                if (row["colItemName"] != null && row["colSPPIDName"] != null)
668
                {
669
                    string key = row["colItemName"].ToString();
670
                    string value = row["colSPPIDName"].ToString();
671

    
672
                    if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
673
                    {
674
                        if (symbolMapping.ContainsKey(key))
675
                            symbolMapping[key] = value;
676
                        else
677
                            symbolMapping.Add(key, value);
678
                    }
679

    
680
                }
681
            }
682

    
683
            attributeMapping.Clear();
684
            foreach (DataRow row in attributeDT.Rows)
685
            {
686
                if (row["colAttribute"] != null && row["colSPPIDAttribute"] != null)
687
                {
688
                    string key = row["colAttribute"].ToString();
689
                    string value = row["colSPPIDAttribute"].ToString();
690

    
691
                    if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
692
                    {
693
                        if (attributeMapping.ContainsKey(key))
694
                            attributeMapping[key] = value;
695
                        else
696
                            attributeMapping.Add(key, value);
697
                    }
698

    
699
                }
700
            }
701

    
702
            // Custom
703
            if (radioGroupReducer.SelectedIndex == 0)
704
            {
705
                attributeMapping.Add("LargeSize", radioGroupReducer.Properties.Items[0].Tag.ToString());
706
                attributeMapping.Add("SmallSize", radioGroupReducer.Properties.Items[1].Tag.ToString());
707
            }
708
            else
709
            {
710
                attributeMapping.Add("LargeSize", radioGroupReducer.Properties.Items[1].Tag.ToString());
711
                attributeMapping.Add("SmallSize", radioGroupReducer.Properties.Items[0].Tag.ToString());
712
            }
713

    
714
            if (textBoxFittingSymbolPath.EditValue != null)
715
                symbolMapping.Add("FittingSymbolPath", textBoxFittingSymbolPath.EditValue.ToString());
716
            
717
            
718
            SPPIDUtill.SaveMapping(symbolMapping, attributeMapping);
719

    
720
            for (int i = 0; i < converterDT.Rows.Count; i++)
721
            {
722
                CheckStatus(gridViewConverter.GetRowHandle(i));
723
            }
724

    
725
            MessageBox.Show("Save success!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
726
        }
727

    
728
        private void textBoxSymbolPath_ButtonClick(object sender, ButtonPressedEventArgs e)
729
        {
730
            SymbolPathForm symbolPathForm = new SymbolPathForm(symbolPathDT);
731
            if (symbolPathForm.ShowDialog() == DialogResult.OK)
732
            {
733
                ButtonEdit button = sender as ButtonEdit;
734
                button.EditValue = symbolPathForm.FullPath;
735
            }
736
        }
737

    
738
        #endregion
739

    
740

    
741
    }
742
}
클립보드 이미지 추가 (최대 크기: 500 MB)