프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / ConverterForm.cs @ fbea6028

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