프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / ConverterForm.cs @ 0760d1ad

이력 | 보기 | 이력해설 | 다운로드 (34.6 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10
using Microsoft.VisualBasic;
11
using DevExpress.XtraEditors.Repository;
12
using DevExpress.XtraEditors.Controls;
13
using DevExpress.XtraEditors;
14
using System.Globalization;
15
using System.Threading;
16
using System.IO;
17
using Ingr.RAD2D;
18
using Converter.BaseModel;
19
using Converter.SPPID.Properties;
20
using Converter.SPPID.DB;
21
using Converter.SPPID.Util;
22
using Converter.SPPID.Form;
23
using Converter.SPPID.Model;
24
using Plaice;
25
using Llama;
26

    
27

    
28
namespace Converter.SPPID
29
{
30
    public partial class ConverterForm : DevExpress.XtraBars.Ribbon.RibbonForm
31
    {
32
        private Dictionary<string, SPPID_Document> _DicDocuments = new Dictionary<string, SPPID_Document>();
33
        private List<SPPID_Document> _Documents = new List<SPPID_Document>();
34
        public List<SPPID_Document> Documents { get { return _Documents; } }
35
        private DataTable _ConverterDT = new DataTable();
36
        private DataTable _SPPIDSymbolPathDT = new DataTable();
37
        private DataTable _SPPIDUnitDT = new DataTable();
38
        private DataTable _SPPIDAttributeDT = new DataTable();
39
        private RepositoryItemComboBox templateComboBox;
40

    
41

    
42
        private DataTable _ID2SymbolDT = new DataTable();
43
        private DataTable _ID2ChildSymbolDT = new DataTable();
44
        private DataTable _ID2LineDT = new DataTable();
45
        private DataTable _ID2AttributeDT = new DataTable();
46
        private DataTable _ID2DrawingAttributeDT = new DataTable();
47
        private DataTable _ID2LinePropertyDT = new DataTable();
48
        private DataTable _ID2SymbolTypeDT = new DataTable();
49
        private DataTable _ID2SymbolTable = new DataTable();
50

    
51

    
52
        private List<SymbolMapping> symbolMappings = new List<SymbolMapping>();
53
        private List<ChildSymbolMapping> childSymbolMappings = new List<ChildSymbolMapping>();
54
        private List<LineMapping> lineMappings = new List<LineMapping>();
55
        private List<LineNumberMapping> lineNumberMappings = new List<LineNumberMapping>();
56
        private List<AttributeMapping> attributeMappings = new List<AttributeMapping>();
57

    
58
        string TemplatePath;
59

    
60
        public ConverterForm()
61
        {
62
            InitializeComponent();
63

    
64
            CultureInfo culture = CultureInfo.GetCultureInfo("ko");
65
            Msg.Culture = culture;
66

    
67
            this._SPPIDUnitDT = SPPIDUtil.GetUnitInfo();
68
            TemplatePath = SPPIDUtil.T_OPTIONSETTING_Value("PID Template Path");
69

    
70
            InitUsedDataTable();
71
            InitGridControl();
72
            InitID2Project();
73

    
74
            //
75
            //labelID2ProjectName.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
76
            //labelDBType.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
77
            //labelID2ProjectStatus.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
78
            //labelSPPIDPlantName.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
79
            //labelSPPIDDBStatus.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
80
            //labelItemMappingStatus.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
81
        }
82

    
83
        private void InitUsedDataTable()
84
        {
85
            // Converter Table
86
            DataColumn col = _ConverterDT.Columns.Add("colDrawingFileName");
87
            col.Caption = "Drawing File Name";
88
            col = _ConverterDT.Columns.Add("colDrawingFilePath");
89
            col.Caption = "DrawingFilePath";
90
            col = _ConverterDT.Columns.Add("colUnit");
91
            col.Caption = "Unit";
92
            col = _ConverterDT.Columns.Add("colTemplate");
93
            col.Caption = "Template";
94
            col = _ConverterDT.Columns.Add("colDrawingNumber");
95
            col.Caption = "Drawing Number";
96
            col = _ConverterDT.Columns.Add("colDrawingName");
97
            col.Caption = "Drawing Name";
98
            col = _ConverterDT.Columns.Add("colStatus");
99
            col.Caption = "Status";
100
            col = _ConverterDT.Columns.Add("colUID");
101

    
102
            col = _ID2LineDT.Columns.Add("UID");
103
            col = _ID2LineDT.Columns.Add("Name");
104
            col.Caption = "Name";
105
            col = _ID2LineDT.Columns.Add("Type");
106
            col.Caption = "Type";
107
            col = _ID2LineDT.Columns.Add("SPPID_SYMBOL_PATH");
108
            col.Caption = "SPPID Symbol Path";
109
            col = _ID2LineDT.Columns.Add("Clear");
110
            col.Caption = "";
111
        }
112

    
113
        private void InitGridControl()
114
        {
115
            #region Converter Page
116
            gridViewConverter.OptionsSelection.MultiSelect = true;
117
            gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
118
            
119
            gridControlConverter.DataSource = _ConverterDT;
120

    
121
            templateComboBox = new RepositoryItemComboBox();
122
            templateComboBox.TextEditStyle = TextEditStyles.DisableTextEditor;
123
            templateComboBox.EditValueChanged += templateComboBox_EditValueChanged;
124
            gridControlConverter.RepositoryItems.Add(templateComboBox);
125
            gridViewConverter.Columns["colTemplate"].ColumnEdit = templateComboBox;
126

    
127
            gridViewConverter.Columns["colUnit"].OptionsColumn.AllowEdit = false;
128
            gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false;
129
            gridViewConverter.Columns["colUnit"].OptionsColumn.ReadOnly = true;
130
            gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false;
131
            gridViewConverter.Columns["colDrawingFilePath"].Visible = false;
132
            gridViewConverter.Columns["colUID"].Visible = false;
133

    
134
            gridViewConverter.BestFitColumns();
135
            #endregion
136
        }
137

    
138
        private void templateComboBox_EditValueChanged(object sender, EventArgs e)
139
        {
140
            gridViewConverter.CloseEditor();
141
            gridViewConverter.UpdateCurrentRow();
142
        }
143

    
144
        private void gridViewConverter_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
145
        {
146
            if (e.Column.Name == "colcolTemplate")
147
            {
148
                gridViewConverter.ShowEditor();
149
                (gridViewConverter.ActiveEditor as ComboBoxEdit).ShowPopup();
150
            }
151
            else if (e.Column.Name == "colcolUnit")
152
            {
153
                UnitForm unitForm = new UnitForm(_SPPIDUnitDT);
154
                if (unitForm.ShowDialog() == DialogResult.OK)
155
                {
156
                    gridViewConverter.SetRowCellValue(e.RowHandle, e.Column, unitForm.SelectedUnit);
157
                    gridViewConverter.CloseEditor();
158
                    gridViewConverter.UpdateCurrentRow();
159
                }
160
            }
161
        }
162

    
163
        private void btnID2DB_Click(object sender, EventArgs e)
164
        {
165
            ID2DBSetting form = new ID2DBSetting();
166
            DialogResult dialogResult = form.ShowDialog();
167
            Project_Info _ProjectInfo = Project_Info.GetInstance();
168
            _ProjectInfo.DefaultPath = Settings.Default.ProjectPath;
169
            _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType;
170
            _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP;
171
            _ProjectInfo.Port = Settings.Default.ProjectPort;
172
            _ProjectInfo.DBUser = Settings.Default.ProjectDBUser;
173
            _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword;
174

    
175
            if (dialogResult == DialogResult.OK)
176
            {
177
                if (InitID2Project())
178
                    MessageBox.Show(Msg.SuccessProjectSelect, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
179
                else
180
                    MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
181
            }
182
        }
183

    
184
        private bool InitID2Project()
185
        {
186
            Project_Info _ProjectInfo = Project_Info.GetInstance();
187
            if (Project_DB.ConnTestAndCreateTable())
188
            {
189
                _ProjectInfo.Enable = true;
190
                labelDBType.Text = _ProjectInfo.DBType.ToString();
191
                labelDBType.AppearanceItemCaption.ForeColor = Color.Blue;
192
                labelID2ProjectName.Text = _ProjectInfo.Name;
193
                labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue;
194
                labelID2ProjectStatus.Text = Msg.ConnectionSuccessful;
195
                labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue;
196
                layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
197
                layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
198
            }
199
            else
200
            {
201
                _ProjectInfo.Enable = false;
202
                labelDBType.Text = " ";
203
                labelID2ProjectName.Text = " ";
204
                labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red;
205
                labelID2ProjectStatus.Text = Msg.ConnectionFail;
206
                labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red;
207
                layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
208
                layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
209
            }
210

    
211
            InitMapping();
212
            InitSPPIDDB();
213

    
214
            return _ProjectInfo.Enable;
215
        }
216

    
217
        private void InitMapping()
218
        {
219
            Project_Info _ProjectInfo = Project_Info.GetInstance();
220
            if (_ProjectInfo.Enable)
221
            {
222
                if (_ID2SymbolTable != null)
223
                {
224
                    _ID2SymbolTable.Dispose();
225
                    _ID2SymbolTable = null;
226
                }
227
                _ID2SymbolTable = Project_DB.SelectID2SymbolTable();
228

    
229
                if (_ID2SymbolTypeDT != null)
230
                {
231
                    _ID2SymbolTypeDT.Dispose();
232
                    _ID2SymbolTypeDT = null;
233
                }
234
                _ID2SymbolTypeDT = Project_DB.SelectSymbolType();
235
                InitID2Symbol();
236
                InitID2Line();
237
                InitID2LineNumber();
238
                InitID2Attribute();
239
                InitID2DrawingAttribute();
240

    
241
                InitETCSetting();
242
            }
243
        }
244

    
245
        private void InitETCSetting()
246
        {
247
            Project_Info _ProjectInfo = Project_Info.GetInstance();
248
            if (_ProjectInfo.Enable)
249
            {
250
                DataTable dt = Project_DB.SelectSetting();
251
                foreach (DataRow item in dt.Rows)
252
                {
253
                    string settingType = item["SettingType"].ToString();
254
                    if (settingType == "ETCSetting")
255
                        SPPIDUtil.ConvertToETCSetting(item["JsonString"].ToString());
256
                    else if (settingType == "GridSetting")
257
                        SPPIDUtil.ConvertToGridSetting(item["JsonString"].ToString());
258
                }
259
            }
260
        }
261

    
262
        private void InitID2Symbol()
263
        {
264
            using (DataTable symbolDT = Project_DB.SelectProjectSymbol())
265
            {
266
                symbolMappings.Clear();
267
                _ID2SymbolDT = symbolDT;
268
                _ID2SymbolDT.Columns.Add("Clear");
269
                _ID2SymbolDT.Columns["Clear"].Caption = "";
270
                foreach (DataRow row in symbolDT.Rows)
271
                {
272
                    symbolMappings.Add(new SymbolMapping()
273
                    {
274
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
275
                        SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(),
276
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
277
                        LEADERLINE = DBNull.Value.Equals(row["LEADERLINE"]) ? false : (bool)row["LEADERLINE"]
278
                    });
279
                }
280

    
281
                MergeID2ChildSymbol();
282
            }
283
        }
284

    
285
        private void MergeID2ChildSymbol()
286
        {
287
            using (DataTable childSymbolDT = Project_DB.SelectProjectChildSymbol())
288
            {
289
                childSymbolMappings.Clear();
290
                _ID2ChildSymbolDT = childSymbolDT;
291
                _ID2ChildSymbolDT.Columns.Add("Clear");
292
                _ID2ChildSymbolDT.Columns["Clear"].Caption = "";
293
                foreach (DataRow row in childSymbolDT.Rows)
294
                {
295
                    childSymbolMappings.Add(new ChildSymbolMapping()
296
                    {
297
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
298
                        SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(),
299
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
300
                    });
301
                }
302

    
303
                _ID2SymbolDT.Merge(_ID2ChildSymbolDT);
304
            }
305
        }
306

    
307
        private void InitID2Line()
308
        {
309
            using (DataTable lineTypes = Project_DB.SelectProjectLine())
310
            {
311
                lineMappings.Clear();
312
                _ID2LineDT.Rows.Clear();
313
                foreach (DataRow row in lineTypes.Rows)
314
                {
315
                    DataRow newRow = _ID2LineDT.NewRow();
316
                    newRow["UID"] = row["UID"] == null ? "" : row["UID"].ToString();
317
                    newRow["Name"] = row["Name"] == null ? "" : row["Name"].ToString();
318
                    newRow["Type"] = "Line";
319
                    newRow["SPPID_SYMBOL_PATH"] = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString();
320
                    _ID2LineDT.Rows.Add(newRow);
321

    
322
                    lineMappings.Add(new LineMapping()
323
                    {
324
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
325
                        LINENAME = row["Name"] == null ? "" : row["Name"].ToString(),
326
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
327
                    });
328
                }
329
            }
330
        }
331

    
332
        private void InitID2LineNumber()
333
        {
334
            using (DataTable linePropertiesDT = Project_DB.SelectProjectLineProperties())
335
            {
336
                lineNumberMappings.Clear();
337
                _ID2LinePropertyDT = linePropertiesDT;
338
                _ID2LinePropertyDT.Columns.Add("Type");
339
                foreach (DataRow row in linePropertiesDT.Rows)
340
                {
341
                    row["Type"] = "Line Property";
342
                    lineNumberMappings.Add(new LineNumberMapping()
343
                    {
344
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
345
                        DisplayName = row["DisplayName"] == null ? "" : row["DisplayName"].ToString(),
346
                        SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(),
347
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString()
348
                    });
349
                }
350
            }
351
        }
352

    
353
        private void InitID2Attribute()
354
        {
355
            using (DataTable attributeDT = Project_DB.SelectProjectAttribute())
356
            {
357
                attributeMappings.Clear();
358
                _ID2AttributeDT = attributeDT;
359
                _ID2AttributeDT.Columns.Add("Clear");
360
                _ID2AttributeDT.Columns["Clear"].Caption = "";
361
                foreach (DataRow row in attributeDT.Rows)
362
                {
363
                    attributeMappings.Add(new AttributeMapping()
364
                    {
365
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
366
                        DisplayAttribute = row["DisplayAttribute"] == null ? "" : row["DisplayAttribute"].ToString(),
367
                        Type = row["Type"] == null ? "" : row["Type"].ToString(),
368
                        SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(),
369
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
370
                        Location = DBNull.Value.Equals(row["LOCATION"]) ? Model.Location.None : (Location)row["LOCATION"],
371
                        LeaderLine = DBNull.Value.Equals(row["LEADERLINE"]) ? false : (bool)row["LEADERLINE"],
372
                        IsText = DBNull.Value.Equals(row["ISTEXT"]) ? false : (bool)row["ISTEXT"]
373
                    });
374
                }
375
            }
376
        }
377

    
378
        private void InitID2DrawingAttribute()
379
        {
380
            using (DataTable drawingAttributeDT = Project_DB.SelectDrawingProjectAttribute())
381
            {
382
                _ID2DrawingAttributeDT = drawingAttributeDT;
383
            }
384
        }
385

    
386
        private void InitSPPIDDB()
387
        {
388
            buttonEditDefaultUnit.TextChanged -= new EventHandler(buttonEditDefaultUnit_TextChanged);
389
            comboBoxEditDefaultTemplate.SelectedIndexChanged -= new EventHandler(comboBoxEditDefaultTemplate_SelectedIndexChanged);
390

    
391
            Project_Info _ProjectInfo = Project_Info.GetInstance();
392
            if (_ProjectInfo.Enable)
393
            {
394
                DataTable dt = Project_DB.SelectSPPID_DB_INFO();
395
                if (dt.Columns.Count > 0 && dt.Rows.Count > 0)
396
                    SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString());
397
                else
398
                    SPPID_DBInfo.Clear();
399
            }
400

    
401
            templateComboBox.Items.Clear();
402
            comboBoxEditDefaultTemplate.SelectedIndex = -1;
403
            comboBoxEditDefaultTemplate.Properties.Items.Clear();
404
            buttonEditDefaultUnit.Text = "";
405

    
406
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
407
            if (_SPPIDInfo.Enable)
408
            {
409
                labelSPPIDPlantName.Text = _SPPIDInfo.SelectedPlant;
410
                labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Blue;
411
                labelSPPIDDBStatus.Text = Msg.ConnectionSuccessful;
412
                labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Blue;
413

    
414
                if (!string.IsNullOrEmpty(TemplatePath))
415
                {
416
                    List<string> templateFiles = Directory.GetFiles(TemplatePath, "*.pid").ToList().Select(filePath => Path.GetFileName(filePath)).ToList();
417
                    templateComboBox.Items.AddRange(templateFiles);
418
                    comboBoxEditDefaultTemplate.Properties.Items.AddRange(templateFiles);
419
                }
420
                    
421
                if (_SPPIDAttributeDT != null)
422
                {
423
                    _SPPIDAttributeDT.Dispose();
424
                    _SPPIDAttributeDT = null;
425
                }
426

    
427
                _SPPIDAttributeDT = SPPID_DB.GetSPPIDAttribute();
428
                if (_SPPIDAttributeDT != null)
429
                {
430
                    _SPPIDAttributeDT.Columns["DISPLAYNAME"].ColumnName = "DISPLAY NAME";
431
                }
432

    
433
                if (!string.IsNullOrEmpty(Settings.Default.DefaultTemplate) && comboBoxEditDefaultTemplate.Properties.Items.Contains(Settings.Default.DefaultTemplate))
434
                    comboBoxEditDefaultTemplate.SelectedItem = Settings.Default.DefaultTemplate;
435

    
436
                // Unit 있는지 없는지 검사 필요
437
                if (!string.IsNullOrEmpty(Settings.Default.DefaultUnit))
438
                    buttonEditDefaultUnit.Text = Settings.Default.DefaultUnit;
439
            }
440
            else
441
            {
442
                labelSPPIDPlantName.Text = " ";
443
                labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Red;
444
                labelSPPIDDBStatus.Text = Msg.ConnectionFail;
445
                labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Red;
446
            }
447

    
448
            _DicDocuments.Clear();
449
            _ConverterDT.Rows.Clear();
450
            InitSPPIDSymbolTreeTable();
451

    
452
            buttonEditDefaultUnit.TextChanged += new EventHandler(buttonEditDefaultUnit_TextChanged);
453
            comboBoxEditDefaultTemplate.SelectedIndexChanged += new EventHandler(comboBoxEditDefaultTemplate_SelectedIndexChanged);
454
        }
455

    
456
        private void InitSPPIDSymbolTreeTable()
457
        {
458
            try
459
            {
460
                _SPPIDSymbolPathDT = new DataTable();
461
                _SPPIDSymbolPathDT.Columns.Add("ID");
462
                _SPPIDSymbolPathDT.Columns.Add("Parent");
463
                _SPPIDSymbolPathDT.Columns.Add("Name");
464
                _SPPIDSymbolPathDT.Columns.Add("FullPath");
465

    
466
                string symbolPath = SPPIDUtil.T_OPTIONSETTING_Value("Catalog Explorer root path");
467
                DirectoryInfo info = new DirectoryInfo(symbolPath);
468
                _SPPIDSymbolPathDT.Rows.Add(new object[] { "0", "-1", info.Name });
469
                loop(info, "0", symbolPath);
470
            }
471
            catch (Exception ex)
472
            {
473
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
474
            }
475
        }
476

    
477
        private void loop(DirectoryInfo parentInfo, string parentUID, string defaultPath)
478
        {
479
            DirectoryInfo[] infos = parentInfo.GetDirectories();
480
            foreach (DirectoryInfo info in infos)
481
            {
482
                string uid = Guid.NewGuid().ToString();
483
                _SPPIDSymbolPathDT.Rows.Add(new object[] { uid, parentUID, info.Name });
484
                loop(info, uid, defaultPath);
485

    
486
                FileInfo[] files = info.GetFiles("*.sym");
487
                foreach (FileInfo fileInfo in files)
488
                {
489
                    _SPPIDSymbolPathDT.Rows.Add(new object[] { Guid.NewGuid().ToString(), uid, fileInfo.Name, fileInfo.FullName.Replace(defaultPath, "") });
490
                }
491
            }
492
        }
493

    
494
        private void btnLoadFile_Click(object sender, EventArgs e)
495
        {
496
            List< BaseModel.Document> validationFailDocs = new List<BaseModel.Document>();
497
            Project_Info _ProjectInfo = Project_Info.GetInstance();
498
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
499
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
500
            {
501
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
502
                return;
503
            }
504

    
505
            xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath;
506
            if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK)
507
            {
508
                foreach (string fileName in xtraOpenFileDialog.FileNames)
509
                {
510
                    SPPID_Document document = new SPPID_Document(fileName, _ID2SymbolTypeDT);
511

    
512
                    document.SymbolTable = _ID2SymbolTable;
513
                    document.SymbolMappings = symbolMappings;
514
                    document.ChildSymbolMappings = childSymbolMappings;
515
                    document.LineMappings = lineMappings;
516
                    document.LineNumberMappings = lineNumberMappings;
517
                    document.AttributeMappings = attributeMappings;
518
                    document.ETCSetting = ETCSetting.GetInstance();
519
                    document.SetSPPIDInfo();
520

    
521

    
522
                    if (!document.SetSPPIDMapping())
523
                    {
524
                        document.Enable = false;
525
                        document.MappingValidation = false;
526
                    }
527

    
528
                    DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName));
529
                    if (rows.Length == 0)
530
                    {
531
                        DataRow row = _ConverterDT.NewRow();
532
                        row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName);
533
                        row["colDrawingFilePath"] = fileName;
534
                        row["colDrawingNumber"] = document.DWGNAME;
535
                        row["colDrawingName"] = document.DWGNAME;
536
                        if (document.Enable)
537
                            row["colStatus"] = "Ready";
538
                        else
539
                            row["colStatus"] = "Error";
540
                        row["colUID"] = "";
541
                        if (comboBoxEditDefaultTemplate.SelectedIndex > -1)
542
                            row["colTemplate"] = comboBoxEditDefaultTemplate.SelectedItem;
543
                        if (!string.IsNullOrEmpty(buttonEditDefaultUnit.Text))
544
                            row["colUnit"] = buttonEditDefaultUnit.Text;
545

    
546
                        _ConverterDT.Rows.Add(row);
547

    
548
                        if (document.Enable && document.Validation && document.MappingValidation)
549
                            gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
550
                    }
551
                    else
552
                    {
553
                        foreach (DataRow row in rows)
554
                        {
555
                            if (document.Enable)
556
                                row["colStatus"] = "Ready";
557
                            else
558
                                row["colStatus"] = "Error";
559

    
560
                            if (comboBoxEditDefaultTemplate.SelectedIndex > -1)
561
                                row["colTemplate"] = comboBoxEditDefaultTemplate.SelectedItem;
562
                            if (!string.IsNullOrEmpty(buttonEditDefaultUnit.Text))
563
                                row["colUnit"] = buttonEditDefaultUnit.Text;
564

    
565
                            if (document.Enable && document.Validation && document.MappingValidation)
566
                                gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
567
                        }
568
                    }
569
                    if (!_DicDocuments.ContainsKey(fileName))
570
                        _DicDocuments.Add(fileName, null);
571

    
572
                    if (!document.Validation || !document.MappingValidation)
573
                        validationFailDocs.Add(document);
574

    
575
                    _DicDocuments[fileName] = document;
576
                }
577
                if (validationFailDocs.Count > 0)
578
                {
579
                    MessageForm messageForm = new MessageForm(validationFailDocs);
580
                    messageForm.ShowDialog();
581
                }
582
            }
583
        }
584

    
585
        /// <summary>
586
        /// 선택한 도면의 정보를 로딩한다
587
        /// </summary>
588
        /// <param name="sender"></param>
589
        /// <param name="e"></param>
590
        private void btnRun_Click(object sender, EventArgs e)
591
        {
592
            Project_Info _ProjectInfo = Project_Info.GetInstance();
593
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
594
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
595
            {
596
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
597
                return;
598
            }
599

    
600
            if (gridViewConverter.GetSelectedRows().Length == 0)
601
            {
602
                MessageBox.Show(Msg.SelectDocument, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
603
                return;
604
            }
605
            DataTable tDrawing = Project_DB.SelectDrawings();
606
            this._Documents.Clear();
607
            foreach (int rowHandle in gridViewConverter.GetSelectedRows())
608
            {
609
                string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath");
610
                string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit");
611
                string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
612
                string _DrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber");
613
                string _DrawingName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingName");
614

    
615
                DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png"));
616
                if (rows.Length != 1)
617
                    continue;
618

    
619
                SPPID_Document document = _DicDocuments[_FilePath];
620
                document.Unit = _Unit;
621
                document.Template = _Template;
622
                document.DrawingNumber = _DrawingNumber;
623
                document.DrawingName = _DrawingName;
624
                document.UID = rows[0]["UID"].ToString();
625

    
626
                document.SymbolTable = _ID2SymbolTable;
627
                document.SymbolMappings = symbolMappings;
628
                document.ChildSymbolMappings = childSymbolMappings;
629
                document.LineMappings = lineMappings;
630
                document.LineNumberMappings = lineNumberMappings;
631
                document.AttributeMappings = attributeMappings;
632
                document.ETCSetting = ETCSetting.GetInstance();
633
                document.SetSPPIDInfo();
634

    
635
                if (document.SetSPPIDMapping() && document.Enable)
636
                    this._Documents.Add(document);
637
            }
638

    
639
            if (_Documents.Count > 50)
640
                checkEditCloseDocument.Checked = true;
641

    
642
            tDrawing.Dispose();
643
            DialogResult = DialogResult.OK;
644
        }
645

    
646
        private void btnSPPIDDB_Click(object sender, EventArgs e)
647
        {
648
            SPPID_DB_SettingForm form = new SPPID_DB_SettingForm();
649
            if (form.ShowDialog() == DialogResult.OK)
650
                InitSPPIDDB();
651
        }
652

    
653
        private void btnItemMapping_Click(object sender, EventArgs e)
654
        {
655
            Project_Info _ProjectInfo = Project_Info.GetInstance();
656
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
657
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
658
            {
659
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
660
                return;
661
            }
662

    
663
            MappingForm form = new MappingForm(_ID2SymbolDT,_SPPIDSymbolPathDT, _ID2LineDT, _ID2LinePropertyDT, _ID2AttributeDT, _SPPIDAttributeDT, _ID2DrawingAttributeDT);
664
            form.ShowDialog();
665
            InitMapping();
666
        }
667
        private List<int> prevSelectedList = new List<int>();
668

    
669
        private void gridViewConverter_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
670
        {
671
            if (e.Action == CollectionChangeAction.Add)
672
            {
673
                string _Unit = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colUnit");
674
                string _Template = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colTemplate");
675

    
676
                if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template))
677
                    gridViewConverter.UnselectRow(e.ControllerRow);
678
            }
679
            else if (e.Action == CollectionChangeAction.Refresh)
680
            {
681
                foreach (int rowHandle in gridViewConverter.GetSelectedRows())
682
                {
683
                    string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit");
684
                    string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
685

    
686
                    if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template))
687
                        gridViewConverter.UnselectRow(rowHandle);
688
                }
689

    
690
                List<int> selectedRowHandleList = gridViewConverter.GetSelectedRows().ToList();
691
                var firstNotSecond = prevSelectedList.Except(selectedRowHandleList).ToList();
692
                var secondNotFirst = selectedRowHandleList.Except(prevSelectedList).ToList();
693

    
694
                if (!firstNotSecond.Any() && !secondNotFirst.Any())
695
                {
696
                    this.gridViewConverter.SelectionChanged -= new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged);
697
                    gridViewConverter.ClearSelection();
698
                    this.gridViewConverter.SelectionChanged += new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged);
699
                }
700
            }
701

    
702
            prevSelectedList = gridViewConverter.GetSelectedRows().ToList();
703
        }
704

    
705
        private void buttonEditDefaulUnit_ButtonClick(object sender, ButtonPressedEventArgs e)
706
        {
707
            UnitForm unitForm = new UnitForm(_SPPIDUnitDT);
708
            if (unitForm.ShowDialog() == DialogResult.OK)
709
            {
710
                buttonEditDefaultUnit.Text = unitForm.SelectedUnit;
711
            }
712
        }
713

    
714
        private void btnRefresh_Click(object sender, EventArgs e)
715
        {
716
            List<BaseModel.Document> validationFailDocs = new List<BaseModel.Document>();
717
            Project_Info _ProjectInfo = Project_Info.GetInstance();
718
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
719
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
720
            {
721
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
722
                return;
723
            }
724

    
725
            foreach (DataRow row in _ConverterDT.Rows)
726
            {
727
                string fileName = row["colDrawingFilePath"].ToString();
728
                SPPID_Document document = new SPPID_Document(fileName, _ID2SymbolTypeDT);
729
                document.SymbolTable = _ID2SymbolTable;
730
                document.SymbolMappings = symbolMappings;
731
                document.ChildSymbolMappings = childSymbolMappings;
732
                document.LineMappings = lineMappings;
733
                document.LineNumberMappings = lineNumberMappings;
734
                document.AttributeMappings = attributeMappings;
735
                document.ETCSetting = ETCSetting.GetInstance();
736
                document.SetSPPIDInfo();
737

    
738

    
739
                if (!document.SetSPPIDMapping())
740
                {
741
                    document.Enable = false;
742
                    document.MappingValidation = false;
743
                }
744

    
745
                row["colDrawingNumber"] = document.DWGNAME;
746
                row["colDrawingName"] = document.DWGNAME;
747
                if (document.Enable)
748
                    row["colStatus"] = "Ready";
749
                else
750
                    row["colStatus"] = "Error";
751

    
752
                if (!_DicDocuments.ContainsKey(fileName))
753
                    _DicDocuments.Add(fileName, null);
754

    
755
                if (!document.Validation || !document.MappingValidation)
756
                    validationFailDocs.Add(document);
757

    
758
                _DicDocuments[fileName] = document;
759

    
760
                if (document.Enable && document.Validation && document.MappingValidation)
761
                    gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
762
            }
763

    
764

    
765
            if (validationFailDocs.Count > 0)
766
            {
767
                MessageForm messageForm = new MessageForm(validationFailDocs);
768
                messageForm.ShowDialog();
769
            }
770
        }
771

    
772
        private void buttonEditDefaultUnit_TextChanged(object sender, EventArgs e)
773
        {
774
            Settings.Default.DefaultUnit = buttonEditDefaultUnit.Text;
775
            Settings.Default.Save();
776
        }
777

    
778
        private void comboBoxEditDefaultTemplate_SelectedIndexChanged(object sender, EventArgs e)
779
        {
780
            Settings.Default.DefaultTemplate = comboBoxEditDefaultTemplate.SelectedItem.ToString();
781
            Settings.Default.Save();
782
        }
783

    
784
        
785
    }
786
}
클립보드 이미지 추가 (최대 크기: 500 MB)