프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / ConverterForm.cs @ 1ecaaba8

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

1 96a2080c gaqhf
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 1278ba59 gaqhf
using DevExpress.XtraEditors.Repository;
12
using DevExpress.XtraEditors.Controls;
13
using DevExpress.XtraEditors;
14 23eb98bf gaqhf
using System.Globalization;
15
using System.Threading;
16
using System.IO;
17 d19ae675 gaqhf
using Ingr.RAD2D;
18
using Converter.BaseModel;
19 b8e2644e gaqhf
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 96a2080c gaqhf
25 b8e2644e gaqhf
namespace Converter.SPPID
26 96a2080c gaqhf
{
27
    public partial class ConverterForm : DevExpress.XtraBars.Ribbon.RibbonForm
28
    {
29 bca86986 gaqhf
        private Dictionary<string, SPPID_Document> _DicDocuments = new Dictionary<string, SPPID_Document>();
30 4314b3f3 gaqhf
        private List<SPPID_Document> _Documents = new List<SPPID_Document>();
31
        public List<SPPID_Document> Documents { get { return _Documents; } }
32 bca86986 gaqhf
        private DataTable _ConverterDT = new DataTable();
33
        private DataTable _SPPIDSymbolPathDT = new DataTable();
34 635a8747 gaqhf
        private DataTable _SPPIDUnitDT = new DataTable();
35 e88aae98 gaqhf
        private DataTable _SPPIDAttributeDT = new DataTable();
36 23eb98bf gaqhf
        private RepositoryItemComboBox templateComboBox;
37
38 bca86986 gaqhf
39
        private DataTable _ID2SymbolDT = new DataTable();
40 4b4dbca9 gaqhf
        private DataTable _ID2ChildSymbolDT = new DataTable();
41 bca86986 gaqhf
        private DataTable _ID2LineDT = new DataTable();
42 1efc25a3 gaqhf
        private DataTable _ID2AttributeDT = new DataTable();
43 306a0af9 gaqhf
        private DataTable _ID2DrawingAttributeDT = new DataTable();
44 bca86986 gaqhf
        private DataTable _ID2LinePropertyDT = new DataTable();
45 f1c9dbaa gaqhf
        private DataTable _ID2SymbolTypeDT = new DataTable();
46 4d2571ab gaqhf
        private DataTable _ID2SymbolTable = new DataTable();
47 f1c9dbaa gaqhf
48 bca86986 gaqhf
49
        private List<SymbolMapping> symbolMappings = new List<SymbolMapping>();
50 4b4dbca9 gaqhf
        private List<ChildSymbolMapping> childSymbolMappings = new List<ChildSymbolMapping>();
51 bca86986 gaqhf
        private List<LineMapping> lineMappings = new List<LineMapping>();
52
        private List<LineNumberMapping> lineNumberMappings = new List<LineNumberMapping>();
53 1efc25a3 gaqhf
        private List<AttributeMapping> attributeMappings = new List<AttributeMapping>();
54 bca86986 gaqhf
55 96a2080c gaqhf
        public ConverterForm()
56
        {
57
            InitializeComponent();
58 1278ba59 gaqhf
59 b048c104 gaqhf
            CultureInfo culture = CultureInfo.GetCultureInfo("ko");
60
            Msg.Culture = culture;
61 23eb98bf gaqhf
62 bca86986 gaqhf
            InitUsedDataTable();
63 1278ba59 gaqhf
            InitGridControl();
64 fab4f207 gaqhf
            InitID2Project();
65 1278ba59 gaqhf
        }
66
67 bca86986 gaqhf
        private void InitUsedDataTable()
68 1278ba59 gaqhf
        {
69 bca86986 gaqhf
            // Converter Table
70
            DataColumn col = _ConverterDT.Columns.Add("colDrawingFileName");
71 1278ba59 gaqhf
            col.Caption = "Drawing File Name";
72 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colDrawingFilePath");
73 0d8062b2 gaqhf
            col.Caption = "DrawingFilePath";
74 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colUnit");
75 1278ba59 gaqhf
            col.Caption = "Unit";
76 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colTemplate");
77 1278ba59 gaqhf
            col.Caption = "Template";
78 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colDrawingNumber");
79 1278ba59 gaqhf
            col.Caption = "Drawing Number";
80 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colDrawingName");
81 1278ba59 gaqhf
            col.Caption = "Drawing Name";
82 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colStatus");
83 1278ba59 gaqhf
            col.Caption = "Status";
84 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colUID");
85
86
            col = _ID2LineDT.Columns.Add("UID");
87
            col = _ID2LineDT.Columns.Add("Name");
88
            col.Caption = "Name";
89
            col = _ID2LineDT.Columns.Add("Type");
90
            col.Caption = "Type";
91
            col = _ID2LineDT.Columns.Add("SPPID_SYMBOL_PATH");
92
            col.Caption = "SPPID Symbol Path";
93
            col = _ID2LineDT.Columns.Add("Clear");
94
            col.Caption = "";
95
        }
96
97
        private void InitGridControl()
98
        {
99
            #region Converter Page
100
            gridViewConverter.OptionsSelection.MultiSelect = true;
101
            gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
102
            
103
            gridControlConverter.DataSource = _ConverterDT;
104 1278ba59 gaqhf
105
            templateComboBox = new RepositoryItemComboBox();
106
            templateComboBox.TextEditStyle = TextEditStyles.DisableTextEditor;
107 635a8747 gaqhf
            templateComboBox.EditValueChanged += templateComboBox_EditValueChanged;
108 1278ba59 gaqhf
            gridControlConverter.RepositoryItems.Add(templateComboBox);
109
            gridViewConverter.Columns["colTemplate"].ColumnEdit = templateComboBox;
110
111 635a8747 gaqhf
            gridViewConverter.Columns["colUnit"].OptionsColumn.AllowEdit = false;
112 1278ba59 gaqhf
            gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false;
113
            gridViewConverter.Columns["colUnit"].OptionsColumn.ReadOnly = true;
114
            gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false;
115 0d8062b2 gaqhf
            gridViewConverter.Columns["colDrawingFilePath"].Visible = false;
116 1278ba59 gaqhf
            gridViewConverter.Columns["colUID"].Visible = false;
117
118
            gridViewConverter.BestFitColumns();
119
            #endregion
120
        }
121 f1c9dbaa gaqhf
122 635a8747 gaqhf
        private void templateComboBox_EditValueChanged(object sender, EventArgs e)
123
        {
124
            gridViewConverter.CloseEditor();
125
            gridViewConverter.UpdateCurrentRow();
126
        }
127
128
        private void gridViewConverter_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
129
        {
130
            if (e.Column.Name == "colcolTemplate")
131
            {
132
                gridViewConverter.ShowEditor();
133
                (gridViewConverter.ActiveEditor as ComboBoxEdit).ShowPopup();
134
            }
135
            else if (e.Column.Name == "colcolUnit")
136
            {
137
                UnitForm unitForm = new UnitForm(_SPPIDUnitDT);
138
                if (unitForm.ShowDialog() == DialogResult.OK)
139
                {
140
                    gridViewConverter.SetRowCellValue(e.RowHandle, e.Column, unitForm.SelectedUnit);
141
                    gridViewConverter.CloseEditor();
142
                    gridViewConverter.UpdateCurrentRow();
143
                }
144
            }
145
        }
146 1278ba59 gaqhf
147 8847ea67 gaqhf
        private void btnID2DB_Click(object sender, EventArgs e)
148 23eb98bf gaqhf
        {
149 8847ea67 gaqhf
            ID2DBSetting form = new ID2DBSetting();
150 e7427d3c gaqhf
            DialogResult dialogResult = form.ShowDialog();
151 8847ea67 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
152
            _ProjectInfo.DefaultPath = Settings.Default.ProjectPath;
153
            _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType;
154
            _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP;
155
            _ProjectInfo.Port = Settings.Default.ProjectPort;
156
            _ProjectInfo.DBUser = Settings.Default.ProjectDBUser;
157
            _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword;
158
159 e7427d3c gaqhf
            if (dialogResult == DialogResult.OK)
160 23eb98bf gaqhf
            {
161 fab4f207 gaqhf
                if (InitID2Project())
162
                    MessageBox.Show(Msg.SuccessProjectSelect, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
163
                else
164 23eb98bf gaqhf
                    MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
165
            }
166
        }
167
168 fab4f207 gaqhf
        private bool InitID2Project()
169 23eb98bf gaqhf
        {
170 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
171 fab4f207 gaqhf
            if (Project_DB.ConnTestAndCreateTable())
172 23eb98bf gaqhf
            {
173 fab4f207 gaqhf
                _ProjectInfo.Enable = true;
174 8847ea67 gaqhf
                labelDBType.Text = _ProjectInfo.DBType.ToString();
175
                labelDBType.AppearanceItemCaption.ForeColor = Color.Blue;
176 23eb98bf gaqhf
                labelID2ProjectName.Text = _ProjectInfo.Name;
177
                labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue;
178
                labelID2ProjectStatus.Text = Msg.ConnectionSuccessful;
179
                labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue;
180 fab4f207 gaqhf
                layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
181
                layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
182 23eb98bf gaqhf
            }
183
            else
184
            {
185 fab4f207 gaqhf
                _ProjectInfo.Enable = false;
186 da84b14b gaqhf
                labelDBType.Text = " ";
187 23eb98bf gaqhf
                labelID2ProjectName.Text = " ";
188
                labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red;
189
                labelID2ProjectStatus.Text = Msg.ConnectionFail;
190
                labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red;
191 fab4f207 gaqhf
                layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
192
                layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
193 bca86986 gaqhf
            }
194 fab4f207 gaqhf
195 bca86986 gaqhf
            InitMapping();
196
            InitSPPIDDB();
197
198
            return _ProjectInfo.Enable;
199
        }
200
201
        private void InitMapping()
202
        {
203
            Project_Info _ProjectInfo = Project_Info.GetInstance();
204
            if (_ProjectInfo.Enable)
205
            {
206 4d2571ab gaqhf
                if (_ID2SymbolTable != null)
207
                {
208
                    _ID2SymbolTable.Dispose();
209
                    _ID2SymbolTable = null;
210
                }
211
                _ID2SymbolTable = Project_DB.SelectID2SymbolTable();
212 7e680366 gaqhf
213
                if (_ID2SymbolTypeDT != null)
214
                {
215
                    _ID2SymbolTypeDT.Dispose();
216
                    _ID2SymbolTypeDT = null;
217
                }
218
                _ID2SymbolTypeDT = Project_DB.SelectSymbolType();
219 bca86986 gaqhf
                InitID2Symbol();
220
                InitID2Line();
221
                InitID2LineNumber();
222 1efc25a3 gaqhf
                InitID2Attribute();
223 306a0af9 gaqhf
                InitID2DrawingAttribute();
224 e00e891d gaqhf
225
                InitETCSetting();
226
            }
227
        }
228 fbdb9f2a gaqhf
229 e00e891d gaqhf
        private void InitETCSetting()
230
        {
231
            Project_Info _ProjectInfo = Project_Info.GetInstance();
232
            if (_ProjectInfo.Enable)
233
            {
234 7cbb1038 gaqhf
                DataTable dt = Project_DB.SelectSetting();
235
                foreach (DataRow item in dt.Rows)
236
                {
237
                    string settingType = item["SettingType"].ToString();
238
                    if (settingType == "ETCSetting")
239
                        SPPIDUtil.ConvertToETCSetting(item["JsonString"].ToString());
240
                    else if (settingType == "GridSetting")
241
                        SPPIDUtil.ConvertToGridSetting(item["JsonString"].ToString());
242
                }
243 bca86986 gaqhf
            }
244
        }
245
246
        private void InitID2Symbol()
247
        {
248
            using (DataTable symbolDT = Project_DB.SelectProjectSymbol())
249
            {
250
                symbolMappings.Clear();
251
                _ID2SymbolDT = symbolDT;
252
                _ID2SymbolDT.Columns.Add("Clear");
253
                _ID2SymbolDT.Columns["Clear"].Caption = "";
254
                foreach (DataRow row in symbolDT.Rows)
255
                {
256
                    symbolMappings.Add(new SymbolMapping()
257
                    {
258
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
259
                        SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(),
260
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
261 cf924377 gaqhf
                        LEADERLINE = DBNull.Value.Equals(row["LEADERLINE"]) ? false : (bool)row["LEADERLINE"]
262 bca86986 gaqhf
                    });
263
                }
264 4b4dbca9 gaqhf
265
                MergeID2ChildSymbol();
266
            }
267
        }
268
269
        private void MergeID2ChildSymbol()
270
        {
271
            using (DataTable childSymbolDT = Project_DB.SelectProjectChildSymbol())
272
            {
273
                childSymbolMappings.Clear();
274
                _ID2ChildSymbolDT = childSymbolDT;
275
                _ID2ChildSymbolDT.Columns.Add("Clear");
276
                _ID2ChildSymbolDT.Columns["Clear"].Caption = "";
277
                foreach (DataRow row in childSymbolDT.Rows)
278
                {
279
                    childSymbolMappings.Add(new ChildSymbolMapping()
280
                    {
281
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
282
                        SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(),
283
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
284
                    });
285
                }
286
287
                _ID2SymbolDT.Merge(_ID2ChildSymbolDT);
288 bca86986 gaqhf
            }
289
        }
290
291
        private void InitID2Line()
292
        {
293
            using (DataTable lineTypes = Project_DB.SelectProjectLine())
294
            {
295
                lineMappings.Clear();
296
                _ID2LineDT.Rows.Clear();
297
                foreach (DataRow row in lineTypes.Rows)
298
                {
299
                    DataRow newRow = _ID2LineDT.NewRow();
300
                    newRow["UID"] = row["UID"] == null ? "" : row["UID"].ToString();
301
                    newRow["Name"] = row["Name"] == null ? "" : row["Name"].ToString();
302
                    newRow["Type"] = "Line";
303
                    newRow["SPPID_SYMBOL_PATH"] = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString();
304
                    _ID2LineDT.Rows.Add(newRow);
305
306
                    lineMappings.Add(new LineMapping()
307
                    {
308
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
309
                        LINENAME = row["Name"] == null ? "" : row["Name"].ToString(),
310
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
311
                    });
312
                }
313
            }
314
        }
315
316
        private void InitID2LineNumber()
317
        {
318
            using (DataTable linePropertiesDT = Project_DB.SelectProjectLineProperties())
319
            {
320
                lineNumberMappings.Clear();
321
                _ID2LinePropertyDT = linePropertiesDT;
322
                _ID2LinePropertyDT.Columns.Add("Type");
323
                foreach (DataRow row in linePropertiesDT.Rows)
324
                {
325
                    row["Type"] = "Line Property";
326
                    lineNumberMappings.Add(new LineNumberMapping()
327
                    {
328
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
329
                        DisplayName = row["DisplayName"] == null ? "" : row["DisplayName"].ToString(),
330
                        SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(),
331
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString()
332
                    });
333
                }
334
            }
335
        }
336
337 1efc25a3 gaqhf
        private void InitID2Attribute()
338 bca86986 gaqhf
        {
339 1efc25a3 gaqhf
            using (DataTable attributeDT = Project_DB.SelectProjectAttribute())
340 bca86986 gaqhf
            {
341 1efc25a3 gaqhf
                attributeMappings.Clear();
342
                _ID2AttributeDT = attributeDT;
343
                _ID2AttributeDT.Columns.Add("Clear");
344
                _ID2AttributeDT.Columns["Clear"].Caption = "";
345
                foreach (DataRow row in attributeDT.Rows)
346 bca86986 gaqhf
                {
347 1efc25a3 gaqhf
                    attributeMappings.Add(new AttributeMapping()
348 bca86986 gaqhf
                    {
349
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
350
                        DisplayAttribute = row["DisplayAttribute"] == null ? "" : row["DisplayAttribute"].ToString(),
351
                        Type = row["Type"] == null ? "" : row["Type"].ToString(),
352
                        SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(),
353 1a3a74a8 gaqhf
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
354 1ba9c671 gaqhf
                        Location = DBNull.Value.Equals(row["LOCATION"]) ? Model.Location.None : (Location)row["LOCATION"],
355 1ecaaba8 gaqhf
                        LeaderLine = DBNull.Value.Equals(row["LEADERLINE"]) ? false : (bool)row["LEADERLINE"],
356
                        IsText = DBNull.Value.Equals(row["ISTEXT"]) ? false : (bool)row["ISTEXT"]
357 bca86986 gaqhf
                    });
358
                }
359 23eb98bf gaqhf
            }
360
        }
361
362 306a0af9 gaqhf
        private void InitID2DrawingAttribute()
363
        {
364
            using (DataTable drawingAttributeDT = Project_DB.SelectDrawingProjectAttribute())
365
            {
366
                _ID2DrawingAttributeDT = drawingAttributeDT;
367
            }
368
        }
369
370 fab4f207 gaqhf
        private void InitSPPIDDB()
371 23eb98bf gaqhf
        {
372 12b7a2a8 gaqhf
            buttonEditDefaultUnit.TextChanged -= new EventHandler(buttonEditDefaultUnit_TextChanged);
373
            comboBoxEditDefaultTemplate.SelectedIndexChanged -= new EventHandler(comboBoxEditDefaultTemplate_SelectedIndexChanged);
374
375 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
376 fab4f207 gaqhf
            if (_ProjectInfo.Enable)
377
            {
378
                DataTable dt = Project_DB.SelectSPPID_DB_INFO();
379 ec0c7045 gaqhf
                if (dt.Columns.Count > 0 && dt.Rows.Count > 0)
380
                    SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString());
381
                else
382
                    SPPID_DBInfo.Clear();
383 fab4f207 gaqhf
            }
384 ec0c7045 gaqhf
385 635a8747 gaqhf
            templateComboBox.Items.Clear();
386 d73c791c gaqhf
            comboBoxEditDefaultTemplate.SelectedIndex = -1;
387
            comboBoxEditDefaultTemplate.Properties.Items.Clear();
388
            buttonEditDefaultUnit.Text = "";
389
390 ec0c7045 gaqhf
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
391 23eb98bf gaqhf
            if (_SPPIDInfo.Enable)
392
            {
393
                labelSPPIDPlantName.Text = _SPPIDInfo.SelectedPlant;
394
                labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Blue;
395
                labelSPPIDDBStatus.Text = Msg.ConnectionSuccessful;
396
                labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Blue;
397 635a8747 gaqhf
398
                string TemplatePath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("PID Template Path");
399
                if (!string.IsNullOrEmpty(TemplatePath))
400 d73c791c gaqhf
                {
401
                    List<string> templateFiles = Directory.GetFiles(TemplatePath, "*.pid").ToList().Select(filePath => Path.GetFileName(filePath)).ToList();
402
                    templateComboBox.Items.AddRange(templateFiles);
403
                    comboBoxEditDefaultTemplate.Properties.Items.AddRange(templateFiles);
404
                }
405
                    
406 635a8747 gaqhf
407 e88aae98 gaqhf
                if (_SPPIDUnitDT != null)
408
                {
409
                    _SPPIDUnitDT.Dispose();
410
                    _SPPIDUnitDT = null;
411
                }
412
                if (_SPPIDAttributeDT != null)
413
                {
414
                    _SPPIDAttributeDT.Dispose();
415
                    _SPPIDAttributeDT = null;
416
                }
417
418 635a8747 gaqhf
                _SPPIDUnitDT = SPPID_DB.GetUnitTree();
419 e88aae98 gaqhf
                _SPPIDAttributeDT = SPPID_DB.GetSPPIDAttribute();
420
                if (_SPPIDAttributeDT != null)
421
                {
422
                    _SPPIDAttributeDT.Columns["DISPLAYNAME"].ColumnName = "DISPLAY NAME";
423
                }
424 12b7a2a8 gaqhf
425
                if (!string.IsNullOrEmpty(Settings.Default.DefaultTemplate) && comboBoxEditDefaultTemplate.Properties.Items.Contains(Settings.Default.DefaultTemplate))
426
                    comboBoxEditDefaultTemplate.SelectedItem = Settings.Default.DefaultTemplate;
427
428
                // Unit 있는지 없는지 검사 필요
429
                if (!string.IsNullOrEmpty(Settings.Default.DefaultUnit))
430
                    buttonEditDefaultUnit.Text = Settings.Default.DefaultUnit;
431 23eb98bf gaqhf
            }
432
            else
433
            {
434
                labelSPPIDPlantName.Text = " ";
435
                labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Red;
436
                labelSPPIDDBStatus.Text = Msg.ConnectionFail;
437
                labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Red;
438
            }
439 bca86986 gaqhf
440 635a8747 gaqhf
            _DicDocuments.Clear();
441
            _ConverterDT.Rows.Clear();
442 bca86986 gaqhf
            InitSPPIDSymbolTreeTable();
443 12b7a2a8 gaqhf
444
            buttonEditDefaultUnit.TextChanged += new EventHandler(buttonEditDefaultUnit_TextChanged);
445
            comboBoxEditDefaultTemplate.SelectedIndexChanged += new EventHandler(comboBoxEditDefaultTemplate_SelectedIndexChanged);
446 23eb98bf gaqhf
        }
447
448 bca86986 gaqhf
        private void InitSPPIDSymbolTreeTable()
449 23eb98bf gaqhf
        {
450 bca86986 gaqhf
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
451
452 26c6f818 gaqhf
            try
453
            {
454
                _SPPIDSymbolPathDT = new DataTable();
455
                _SPPIDSymbolPathDT.Columns.Add("ID");
456
                _SPPIDSymbolPathDT.Columns.Add("Parent");
457
                _SPPIDSymbolPathDT.Columns.Add("Name");
458
                _SPPIDSymbolPathDT.Columns.Add("FullPath");
459 bca86986 gaqhf
460 26c6f818 gaqhf
                if (_SPPIDInfo.Enable)
461
                {
462
                    string symbolPath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("Catalog Explorer root path");
463
                    DirectoryInfo info = new DirectoryInfo(symbolPath);
464
                    _SPPIDSymbolPathDT.Rows.Add(new object[] { "0", "-1", info.Name });
465
                    loop(info, "0", symbolPath);
466
                }
467
            }
468
            catch (Exception ex)
469 23eb98bf gaqhf
            {
470 26c6f818 gaqhf
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
471 23eb98bf gaqhf
            }
472 bca86986 gaqhf
        }
473 23eb98bf gaqhf
474 bca86986 gaqhf
        private void loop(DirectoryInfo parentInfo, string parentUID, string defaultPath)
475
        {
476
            DirectoryInfo[] infos = parentInfo.GetDirectories();
477
            foreach (DirectoryInfo info in infos)
478
            {
479
                string uid = Guid.NewGuid().ToString();
480
                _SPPIDSymbolPathDT.Rows.Add(new object[] { uid, parentUID, info.Name });
481
                loop(info, uid, defaultPath);
482
483
                FileInfo[] files = info.GetFiles("*.sym");
484
                foreach (FileInfo fileInfo in files)
485
                {
486
                    _SPPIDSymbolPathDT.Rows.Add(new object[] { Guid.NewGuid().ToString(), uid, fileInfo.Name, fileInfo.FullName.Replace(defaultPath, "") });
487
                }
488
            }
489 23eb98bf gaqhf
        }
490
491 1278ba59 gaqhf
        private void btnLoadFile_Click(object sender, EventArgs e)
492
        {
493 0a111e7d gaqhf
            List< BaseModel.Document> validationFailDocs = new List<BaseModel.Document>();
494 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
495 d73c791c gaqhf
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
496
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
497 23eb98bf gaqhf
            {
498 d73c791c gaqhf
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
499 23eb98bf gaqhf
                return;
500
            }
501 1278ba59 gaqhf
502 171142c5 gaqhf
            xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath;
503 23eb98bf gaqhf
            if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK)
504 1278ba59 gaqhf
            {
505 23eb98bf gaqhf
                foreach (string fileName in xtraOpenFileDialog.FileNames)
506 1278ba59 gaqhf
                {
507 7e680366 gaqhf
                    SPPID_Document document = new SPPID_Document(fileName, _ID2SymbolTypeDT);
508 4314b3f3 gaqhf
509 68e9394a gaqhf
                    document.SymbolTable = _ID2SymbolTable;
510
                    document.SymbolMappings = symbolMappings;
511
                    document.ChildSymbolMappings = childSymbolMappings;
512
                    document.LineMappings = lineMappings;
513
                    document.LineNumberMappings = lineNumberMappings;
514
                    document.AttributeMappings = attributeMappings;
515
                    document.ETCSetting = ETCSetting.GetInstance();
516
                    document.SetSPPIDInfo();
517
518
519
                    if (!document.SetSPPIDMapping())
520
                    {
521
                        document.Enable = false;
522
                        document.MappingValidation = false;
523
                    }
524
525 bca86986 gaqhf
                    DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName));
526 0d8062b2 gaqhf
                    if (rows.Length == 0)
527
                    {
528 f9cc5190 gaqhf
                        DataRow row = _ConverterDT.NewRow();
529 0d8062b2 gaqhf
                        row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName);
530
                        row["colDrawingFilePath"] = fileName;
531
                        row["colDrawingNumber"] = document.DWGNAME;
532
                        row["colDrawingName"] = document.DWGNAME;
533
                        if (document.Enable)
534
                            row["colStatus"] = "Ready";
535
                        else
536
                            row["colStatus"] = "Error";
537
                        row["colUID"] = "";
538 d73c791c gaqhf
                        if (comboBoxEditDefaultTemplate.SelectedIndex > -1)
539 12b7a2a8 gaqhf
                            row["colTemplate"] = comboBoxEditDefaultTemplate.SelectedItem;
540 d73c791c gaqhf
                        if (!string.IsNullOrEmpty(buttonEditDefaultUnit.Text))
541
                            row["colUnit"] = buttonEditDefaultUnit.Text;
542
543 bca86986 gaqhf
                        _ConverterDT.Rows.Add(row);
544 442bd51e gaqhf
545
                        if (document.Enable && document.Validation && document.MappingValidation)
546
                            gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
547 0d8062b2 gaqhf
                    }
548 f9cc5190 gaqhf
                    else
549
                    {
550
                        foreach (DataRow row in rows)
551
                        {
552
                            if (document.Enable)
553
                                row["colStatus"] = "Ready";
554
                            else
555
                                row["colStatus"] = "Error";
556 d73c791c gaqhf
557
                            if (comboBoxEditDefaultTemplate.SelectedIndex > -1)
558
                                row["colTemplate"] = comboBoxEditDefaultTemplate.SelectedItem;
559
                            if (!string.IsNullOrEmpty(buttonEditDefaultUnit.Text))
560
                                row["colUnit"] = buttonEditDefaultUnit.Text;
561 442bd51e gaqhf
562
                            if (document.Enable && document.Validation && document.MappingValidation)
563
                                gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
564 f9cc5190 gaqhf
                        }
565
                    }
566 0d8062b2 gaqhf
                    if (!_DicDocuments.ContainsKey(fileName))
567
                        _DicDocuments.Add(fileName, null);
568
569 68e9394a gaqhf
                    if (!document.Validation || !document.MappingValidation)
570 0a111e7d gaqhf
                        validationFailDocs.Add(document);
571 e613d0e8 gaqhf
572 0d8062b2 gaqhf
                    _DicDocuments[fileName] = document;
573 1278ba59 gaqhf
                }
574 0a111e7d gaqhf
                if (validationFailDocs.Count > 0)
575
                {
576
                    MessageForm messageForm = new MessageForm(validationFailDocs);
577
                    messageForm.ShowDialog();
578
                }
579 1278ba59 gaqhf
            }
580 65a1ed4b gaqhf
        }
581 17f2a3a7 gaqhf
582 5a9396ae humkyung
        /// <summary>
583
        /// 선택한 도면의 정보를 로딩한다
584
        /// </summary>
585
        /// <param name="sender"></param>
586
        /// <param name="e"></param>
587 1278ba59 gaqhf
        private void btnRun_Click(object sender, EventArgs e)
588
        {
589 d73c791c gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
590
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
591
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
592
            {
593
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
594
                return;
595
            }
596
597 6924abc6 gaqhf
            if (gridViewConverter.GetSelectedRows().Length == 0)
598 e0bb889b gaqhf
            {
599
                MessageBox.Show(Msg.SelectDocument, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
600 6924abc6 gaqhf
                return;
601 e0bb889b gaqhf
            }
602 154d8f43 gaqhf
            DataTable tDrawing = Project_DB.SelectDrawings();
603 5a9396ae humkyung
            this._Documents.Clear();
604 17f2a3a7 gaqhf
            foreach (int rowHandle in gridViewConverter.GetSelectedRows())
605
            {
606
                string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath");
607
                string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit");
608
                string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
609
                string _DrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber");
610
                string _DrawingName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingName");
611 154d8f43 gaqhf
612
                DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png"));
613
                if (rows.Length != 1)
614
                    continue;
615
616 17f2a3a7 gaqhf
                SPPID_Document document = _DicDocuments[_FilePath];
617
                document.Unit = _Unit;
618
                document.Template = _Template;
619
                document.DrawingNumber = _DrawingNumber;
620
                document.DrawingName = _DrawingName;
621 154d8f43 gaqhf
                document.UID = rows[0]["UID"].ToString();
622 712860bb gaqhf
623 4d2571ab gaqhf
                document.SymbolTable = _ID2SymbolTable;
624 712860bb gaqhf
                document.SymbolMappings = symbolMappings;
625
                document.ChildSymbolMappings = childSymbolMappings;
626
                document.LineMappings = lineMappings;
627
                document.LineNumberMappings = lineNumberMappings;
628
                document.AttributeMappings = attributeMappings;
629
                document.ETCSetting = ETCSetting.GetInstance();
630
                document.SetSPPIDInfo();
631
632 e3e2d41f gaqhf
                if (document.SetSPPIDMapping() && document.Enable)
633 5a9396ae humkyung
                    this._Documents.Add(document);
634 17f2a3a7 gaqhf
            }
635 5dfb8a24 gaqhf
636 154d8f43 gaqhf
            if (_Documents.Count > 50)
637
                checkEditCloseDocument.Checked = true;
638
639
            tDrawing.Dispose();
640 d19ae675 gaqhf
            DialogResult = DialogResult.OK;
641 96a2080c gaqhf
        }
642 23eb98bf gaqhf
643
        private void btnSPPIDDB_Click(object sender, EventArgs e)
644
        {
645
            SPPID_DB_SettingForm form = new SPPID_DB_SettingForm();
646
            if (form.ShowDialog() == DialogResult.OK)
647 fab4f207 gaqhf
                InitSPPIDDB();
648 23eb98bf gaqhf
        }
649 df4559fc gaqhf
650
        private void btnItemMapping_Click(object sender, EventArgs e)
651
        {
652 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
653 d73c791c gaqhf
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
654
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
655 df4559fc gaqhf
            {
656 d73c791c gaqhf
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
657 df4559fc gaqhf
                return;
658
            }
659
660 306a0af9 gaqhf
            MappingForm form = new MappingForm(_ID2SymbolDT,_SPPIDSymbolPathDT, _ID2LineDT, _ID2LinePropertyDT, _ID2AttributeDT, _SPPIDAttributeDT, _ID2DrawingAttributeDT);
661 df4559fc gaqhf
            form.ShowDialog();
662 bca86986 gaqhf
            InitMapping();
663 df4559fc gaqhf
        }
664 4314b3f3 gaqhf
        private List<int> prevSelectedList = new List<int>();
665
666
        private void gridViewConverter_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
667
        {
668
            if (e.Action == CollectionChangeAction.Add)
669
            {
670
                string _Unit = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colUnit");
671
                string _Template = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colTemplate");
672
673
                if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template))
674
                    gridViewConverter.UnselectRow(e.ControllerRow);
675
            }
676
            else if (e.Action == CollectionChangeAction.Refresh)
677
            {
678
                foreach (int rowHandle in gridViewConverter.GetSelectedRows())
679
                {
680
                    string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit");
681
                    string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
682
683
                    if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template))
684
                        gridViewConverter.UnselectRow(rowHandle);
685
                }
686
687
                List<int> selectedRowHandleList = gridViewConverter.GetSelectedRows().ToList();
688
                var firstNotSecond = prevSelectedList.Except(selectedRowHandleList).ToList();
689
                var secondNotFirst = selectedRowHandleList.Except(prevSelectedList).ToList();
690 635a8747 gaqhf
691 4314b3f3 gaqhf
                if (!firstNotSecond.Any() && !secondNotFirst.Any())
692
                {
693
                    this.gridViewConverter.SelectionChanged -= new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged);
694
                    gridViewConverter.ClearSelection();
695
                    this.gridViewConverter.SelectionChanged += new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged);
696
                }
697
            }
698
699
            prevSelectedList = gridViewConverter.GetSelectedRows().ToList();
700
        }
701 d73c791c gaqhf
702
        private void buttonEditDefaulUnit_ButtonClick(object sender, ButtonPressedEventArgs e)
703
        {
704
            UnitForm unitForm = new UnitForm(_SPPIDUnitDT);
705
            if (unitForm.ShowDialog() == DialogResult.OK)
706
            {
707
                buttonEditDefaultUnit.Text = unitForm.SelectedUnit;
708
            }
709
        }
710 02a45794 gaqhf
711
        private void btnRefresh_Click(object sender, EventArgs e)
712
        {
713
            List<BaseModel.Document> validationFailDocs = new List<BaseModel.Document>();
714
            Project_Info _ProjectInfo = Project_Info.GetInstance();
715
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
716
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
717
            {
718
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
719
                return;
720
            }
721
722
            foreach (DataRow row in _ConverterDT.Rows)
723
            {
724
                string fileName = row["colDrawingFilePath"].ToString();
725 7e680366 gaqhf
                SPPID_Document document = new SPPID_Document(fileName, _ID2SymbolTypeDT);
726 68e9394a gaqhf
                document.SymbolTable = _ID2SymbolTable;
727
                document.SymbolMappings = symbolMappings;
728
                document.ChildSymbolMappings = childSymbolMappings;
729
                document.LineMappings = lineMappings;
730
                document.LineNumberMappings = lineNumberMappings;
731
                document.AttributeMappings = attributeMappings;
732
                document.ETCSetting = ETCSetting.GetInstance();
733
                document.SetSPPIDInfo();
734
735
736
                if (!document.SetSPPIDMapping())
737
                {
738
                    document.Enable = false;
739
                    document.MappingValidation = false;
740
                }
741
742 02a45794 gaqhf
                row["colDrawingNumber"] = document.DWGNAME;
743
                row["colDrawingName"] = document.DWGNAME;
744
                if (document.Enable)
745
                    row["colStatus"] = "Ready";
746
                else
747
                    row["colStatus"] = "Error";
748
749
                if (!_DicDocuments.ContainsKey(fileName))
750
                    _DicDocuments.Add(fileName, null);
751
752 68e9394a gaqhf
                if (!document.Validation || !document.MappingValidation)
753 02a45794 gaqhf
                    validationFailDocs.Add(document);
754
755
                _DicDocuments[fileName] = document;
756 442bd51e gaqhf
757
                if (document.Enable && document.Validation && document.MappingValidation)
758
                    gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
759 02a45794 gaqhf
            }
760
761
762
            if (validationFailDocs.Count > 0)
763
            {
764
                MessageForm messageForm = new MessageForm(validationFailDocs);
765
                messageForm.ShowDialog();
766
            }
767
        }
768 12b7a2a8 gaqhf
769
        private void buttonEditDefaultUnit_TextChanged(object sender, EventArgs e)
770
        {
771
            Settings.Default.DefaultUnit = buttonEditDefaultUnit.Text;
772
            Settings.Default.Save();
773
        }
774
775
        private void comboBoxEditDefaultTemplate_SelectedIndexChanged(object sender, EventArgs e)
776
        {
777
            Settings.Default.DefaultTemplate = comboBoxEditDefaultTemplate.SelectedItem.ToString();
778
            Settings.Default.Save();
779
        }
780 8847ea67 gaqhf
781
        
782 96a2080c gaqhf
    }
783
}
클립보드 이미지 추가 (최대 크기: 500 MB)