프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / ConverterForm.cs @ 12b7a2a8

이력 | 보기 | 이력해설 | 다운로드 (32.2 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 23eb98bf gaqhf
        private void btnID2Project_ButtonClick(object sender, ButtonPressedEventArgs e)
147
        {
148 fab4f207 gaqhf
            xtraFolderBrowserDialog.SelectedPath = btnID2Project.Text;
149
150 23eb98bf gaqhf
            if (xtraFolderBrowserDialog.ShowDialog() == DialogResult.OK)
151
            {
152 fab4f207 gaqhf
                if (xtraFolderBrowserDialog.SelectedPath[xtraFolderBrowserDialog.SelectedPath.Length - 1] == '\\')
153
                    xtraFolderBrowserDialog.SelectedPath = xtraFolderBrowserDialog.SelectedPath.Remove(xtraFolderBrowserDialog.SelectedPath.Length - 1);
154
                Settings.Default.LatestProjectPath = xtraFolderBrowserDialog.SelectedPath;
155
                Settings.Default.Save();
156
                if (InitID2Project())
157 635a8747 gaqhf
                {
158 fab4f207 gaqhf
                    MessageBox.Show(Msg.SuccessProjectSelect, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
159 635a8747 gaqhf
                }
160 fab4f207 gaqhf
                else
161 23eb98bf gaqhf
                    MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
162
            }
163
        }
164
165 fab4f207 gaqhf
        private bool InitID2Project()
166 23eb98bf gaqhf
        {
167 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
168 fab4f207 gaqhf
            _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath;
169
            if (Project_DB.ConnTestAndCreateTable())
170 23eb98bf gaqhf
            {
171 fab4f207 gaqhf
                _ProjectInfo.Enable = true;
172 171142c5 gaqhf
                btnID2Project.Text = _ProjectInfo.DefaultPath;
173 23eb98bf gaqhf
                labelID2ProjectName.Text = _ProjectInfo.Name;
174
                labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue;
175
                labelID2ProjectStatus.Text = Msg.ConnectionSuccessful;
176
                labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue;
177 fab4f207 gaqhf
                layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
178
                layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
179 23eb98bf gaqhf
            }
180
            else
181
            {
182 fab4f207 gaqhf
                _ProjectInfo.Enable = false;
183 23eb98bf gaqhf
                btnID2Project.Text = "";
184
                labelID2ProjectName.Text = " ";
185
                labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red;
186
                labelID2ProjectStatus.Text = Msg.ConnectionFail;
187
                labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red;
188 fab4f207 gaqhf
                layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
189
                layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
190 bca86986 gaqhf
            }
191 fab4f207 gaqhf
192 bca86986 gaqhf
            InitMapping();
193
            InitSPPIDDB();
194
195
            return _ProjectInfo.Enable;
196
        }
197
198
        private void InitMapping()
199
        {
200
            Project_Info _ProjectInfo = Project_Info.GetInstance();
201
            if (_ProjectInfo.Enable)
202
            {
203 4d2571ab gaqhf
                if (_ID2SymbolTable != null)
204
                {
205
                    _ID2SymbolTable.Dispose();
206
                    _ID2SymbolTable = null;
207
                }
208
                _ID2SymbolTable = Project_DB.SelectID2SymbolTable();
209 bca86986 gaqhf
                InitID2Symbol();
210
                InitID2Line();
211
                InitID2LineNumber();
212 1efc25a3 gaqhf
                InitID2Attribute();
213 e00e891d gaqhf
214
                InitETCSetting();
215
            }
216
        }
217 fbdb9f2a gaqhf
218 e00e891d gaqhf
        private void InitETCSetting()
219
        {
220
            Project_Info _ProjectInfo = Project_Info.GetInstance();
221
            if (_ProjectInfo.Enable)
222
            {
223 7cbb1038 gaqhf
                DataTable dt = Project_DB.SelectSetting();
224
                foreach (DataRow item in dt.Rows)
225
                {
226
                    string settingType = item["SettingType"].ToString();
227
                    if (settingType == "ETCSetting")
228
                        SPPIDUtil.ConvertToETCSetting(item["JsonString"].ToString());
229
                    else if (settingType == "GridSetting")
230
                        SPPIDUtil.ConvertToGridSetting(item["JsonString"].ToString());
231
                }
232 bca86986 gaqhf
            }
233
        }
234
235
        private void InitID2Symbol()
236
        {
237
            using (DataTable symbolDT = Project_DB.SelectProjectSymbol())
238
            {
239
                symbolMappings.Clear();
240
                _ID2SymbolDT = symbolDT;
241
                _ID2SymbolDT.Columns.Add("Clear");
242
                _ID2SymbolDT.Columns["Clear"].Caption = "";
243
                foreach (DataRow row in symbolDT.Rows)
244
                {
245
                    symbolMappings.Add(new SymbolMapping()
246
                    {
247
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
248
                        SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(),
249
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
250 cf924377 gaqhf
                        LEADERLINE = DBNull.Value.Equals(row["LEADERLINE"]) ? false : (bool)row["LEADERLINE"]
251 bca86986 gaqhf
                    });
252
                }
253 4b4dbca9 gaqhf
254
                MergeID2ChildSymbol();
255
            }
256
        }
257
258
        private void MergeID2ChildSymbol()
259
        {
260
            using (DataTable childSymbolDT = Project_DB.SelectProjectChildSymbol())
261
            {
262
                childSymbolMappings.Clear();
263
                _ID2ChildSymbolDT = childSymbolDT;
264
                _ID2ChildSymbolDT.Columns.Add("Clear");
265
                _ID2ChildSymbolDT.Columns["Clear"].Caption = "";
266
                foreach (DataRow row in childSymbolDT.Rows)
267
                {
268
                    childSymbolMappings.Add(new ChildSymbolMapping()
269
                    {
270
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
271
                        SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(),
272
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
273
                    });
274
                }
275
276
                _ID2SymbolDT.Merge(_ID2ChildSymbolDT);
277 bca86986 gaqhf
            }
278
        }
279
280
        private void InitID2Line()
281
        {
282
            using (DataTable lineTypes = Project_DB.SelectProjectLine())
283
            {
284
                lineMappings.Clear();
285
                _ID2LineDT.Rows.Clear();
286
                foreach (DataRow row in lineTypes.Rows)
287
                {
288
                    DataRow newRow = _ID2LineDT.NewRow();
289
                    newRow["UID"] = row["UID"] == null ? "" : row["UID"].ToString();
290
                    newRow["Name"] = row["Name"] == null ? "" : row["Name"].ToString();
291
                    newRow["Type"] = "Line";
292
                    newRow["SPPID_SYMBOL_PATH"] = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString();
293
                    _ID2LineDT.Rows.Add(newRow);
294
295
                    lineMappings.Add(new LineMapping()
296
                    {
297
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
298
                        LINENAME = row["Name"] == null ? "" : row["Name"].ToString(),
299
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
300
                    });
301
                }
302
            }
303
        }
304
305
        private void InitID2LineNumber()
306
        {
307
            using (DataTable linePropertiesDT = Project_DB.SelectProjectLineProperties())
308
            {
309
                lineNumberMappings.Clear();
310
                _ID2LinePropertyDT = linePropertiesDT;
311
                _ID2LinePropertyDT.Columns.Add("Type");
312
                foreach (DataRow row in linePropertiesDT.Rows)
313
                {
314
                    row["Type"] = "Line Property";
315
                    lineNumberMappings.Add(new LineNumberMapping()
316
                    {
317
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
318
                        DisplayName = row["DisplayName"] == null ? "" : row["DisplayName"].ToString(),
319
                        SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(),
320
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString()
321
                    });
322
                }
323
            }
324
        }
325
326 1efc25a3 gaqhf
        private void InitID2Attribute()
327 bca86986 gaqhf
        {
328 1efc25a3 gaqhf
            using (DataTable attributeDT = Project_DB.SelectProjectAttribute())
329 bca86986 gaqhf
            {
330 1efc25a3 gaqhf
                attributeMappings.Clear();
331
                _ID2AttributeDT = attributeDT;
332
                _ID2AttributeDT.Columns.Add("Clear");
333
                _ID2AttributeDT.Columns["Clear"].Caption = "";
334
                foreach (DataRow row in attributeDT.Rows)
335 bca86986 gaqhf
                {
336 1efc25a3 gaqhf
                    attributeMappings.Add(new AttributeMapping()
337 bca86986 gaqhf
                    {
338
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
339
                        DisplayAttribute = row["DisplayAttribute"] == null ? "" : row["DisplayAttribute"].ToString(),
340
                        Type = row["Type"] == null ? "" : row["Type"].ToString(),
341
                        SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(),
342 1a3a74a8 gaqhf
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
343 1ba9c671 gaqhf
                        Location = DBNull.Value.Equals(row["LOCATION"]) ? Model.Location.None : (Location)row["LOCATION"],
344
                        LeaderLine = DBNull.Value.Equals(row["LEADERLINE"]) ? false : (bool)row["LEADERLINE"]
345 bca86986 gaqhf
                    });
346
                }
347 23eb98bf gaqhf
            }
348
        }
349
350 fab4f207 gaqhf
        private void InitSPPIDDB()
351 23eb98bf gaqhf
        {
352 12b7a2a8 gaqhf
            buttonEditDefaultUnit.TextChanged -= new EventHandler(buttonEditDefaultUnit_TextChanged);
353
            comboBoxEditDefaultTemplate.SelectedIndexChanged -= new EventHandler(comboBoxEditDefaultTemplate_SelectedIndexChanged);
354
355 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
356 fab4f207 gaqhf
            if (_ProjectInfo.Enable)
357
            {
358
                DataTable dt = Project_DB.SelectSPPID_DB_INFO();
359 ec0c7045 gaqhf
                if (dt.Columns.Count > 0 && dt.Rows.Count > 0)
360
                    SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString());
361
                else
362
                    SPPID_DBInfo.Clear();
363 fab4f207 gaqhf
            }
364 ec0c7045 gaqhf
365 635a8747 gaqhf
            templateComboBox.Items.Clear();
366 d73c791c gaqhf
            comboBoxEditDefaultTemplate.SelectedIndex = -1;
367
            comboBoxEditDefaultTemplate.Properties.Items.Clear();
368
            buttonEditDefaultUnit.Text = "";
369
370 ec0c7045 gaqhf
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
371 23eb98bf gaqhf
            if (_SPPIDInfo.Enable)
372
            {
373
                labelSPPIDPlantName.Text = _SPPIDInfo.SelectedPlant;
374
                labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Blue;
375
                labelSPPIDDBStatus.Text = Msg.ConnectionSuccessful;
376
                labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Blue;
377 635a8747 gaqhf
378
                string TemplatePath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("PID Template Path");
379
                if (!string.IsNullOrEmpty(TemplatePath))
380 d73c791c gaqhf
                {
381
                    List<string> templateFiles = Directory.GetFiles(TemplatePath, "*.pid").ToList().Select(filePath => Path.GetFileName(filePath)).ToList();
382
                    templateComboBox.Items.AddRange(templateFiles);
383
                    comboBoxEditDefaultTemplate.Properties.Items.AddRange(templateFiles);
384
                }
385
                    
386 635a8747 gaqhf
387 e88aae98 gaqhf
                if (_SPPIDUnitDT != null)
388
                {
389
                    _SPPIDUnitDT.Dispose();
390
                    _SPPIDUnitDT = null;
391
                }
392
                if (_SPPIDAttributeDT != null)
393
                {
394
                    _SPPIDAttributeDT.Dispose();
395
                    _SPPIDAttributeDT = null;
396
                }
397
398 635a8747 gaqhf
                _SPPIDUnitDT = SPPID_DB.GetUnitTree();
399 e88aae98 gaqhf
                _SPPIDAttributeDT = SPPID_DB.GetSPPIDAttribute();
400
                if (_SPPIDAttributeDT != null)
401
                {
402
                    _SPPIDAttributeDT.Columns["DISPLAYNAME"].ColumnName = "DISPLAY NAME";
403
                }
404 12b7a2a8 gaqhf
405
                if (!string.IsNullOrEmpty(Settings.Default.DefaultTemplate) && comboBoxEditDefaultTemplate.Properties.Items.Contains(Settings.Default.DefaultTemplate))
406
                    comboBoxEditDefaultTemplate.SelectedItem = Settings.Default.DefaultTemplate;
407
408
                // Unit 있는지 없는지 검사 필요
409
                if (!string.IsNullOrEmpty(Settings.Default.DefaultUnit))
410
                    buttonEditDefaultUnit.Text = Settings.Default.DefaultUnit;
411 23eb98bf gaqhf
            }
412
            else
413
            {
414
                labelSPPIDPlantName.Text = " ";
415
                labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Red;
416
                labelSPPIDDBStatus.Text = Msg.ConnectionFail;
417
                labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Red;
418
            }
419 bca86986 gaqhf
420 635a8747 gaqhf
            _DicDocuments.Clear();
421
            _ConverterDT.Rows.Clear();
422 bca86986 gaqhf
            InitSPPIDSymbolTreeTable();
423 12b7a2a8 gaqhf
424
            buttonEditDefaultUnit.TextChanged += new EventHandler(buttonEditDefaultUnit_TextChanged);
425
            comboBoxEditDefaultTemplate.SelectedIndexChanged += new EventHandler(comboBoxEditDefaultTemplate_SelectedIndexChanged);
426 23eb98bf gaqhf
        }
427
428 bca86986 gaqhf
        private void InitSPPIDSymbolTreeTable()
429 23eb98bf gaqhf
        {
430 bca86986 gaqhf
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
431
432 26c6f818 gaqhf
            try
433
            {
434
                _SPPIDSymbolPathDT = new DataTable();
435
                _SPPIDSymbolPathDT.Columns.Add("ID");
436
                _SPPIDSymbolPathDT.Columns.Add("Parent");
437
                _SPPIDSymbolPathDT.Columns.Add("Name");
438
                _SPPIDSymbolPathDT.Columns.Add("FullPath");
439 bca86986 gaqhf
440 26c6f818 gaqhf
                if (_SPPIDInfo.Enable)
441
                {
442
                    string symbolPath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("Catalog Explorer root path");
443
                    DirectoryInfo info = new DirectoryInfo(symbolPath);
444
                    _SPPIDSymbolPathDT.Rows.Add(new object[] { "0", "-1", info.Name });
445
                    loop(info, "0", symbolPath);
446
                }
447
            }
448
            catch (Exception ex)
449 23eb98bf gaqhf
            {
450 26c6f818 gaqhf
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
451 23eb98bf gaqhf
            }
452 bca86986 gaqhf
        }
453 23eb98bf gaqhf
454 bca86986 gaqhf
        private void loop(DirectoryInfo parentInfo, string parentUID, string defaultPath)
455
        {
456
            DirectoryInfo[] infos = parentInfo.GetDirectories();
457
            foreach (DirectoryInfo info in infos)
458
            {
459
                string uid = Guid.NewGuid().ToString();
460
                _SPPIDSymbolPathDT.Rows.Add(new object[] { uid, parentUID, info.Name });
461
                loop(info, uid, defaultPath);
462
463
                FileInfo[] files = info.GetFiles("*.sym");
464
                foreach (FileInfo fileInfo in files)
465
                {
466
                    _SPPIDSymbolPathDT.Rows.Add(new object[] { Guid.NewGuid().ToString(), uid, fileInfo.Name, fileInfo.FullName.Replace(defaultPath, "") });
467
                }
468
            }
469 23eb98bf gaqhf
        }
470
471 1278ba59 gaqhf
        private void btnLoadFile_Click(object sender, EventArgs e)
472
        {
473 0a111e7d gaqhf
            List< BaseModel.Document> validationFailDocs = new List<BaseModel.Document>();
474 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
475 d73c791c gaqhf
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
476
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
477 23eb98bf gaqhf
            {
478 d73c791c gaqhf
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
479 23eb98bf gaqhf
                return;
480
            }
481 1278ba59 gaqhf
482 171142c5 gaqhf
            xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath;
483 23eb98bf gaqhf
            if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK)
484 1278ba59 gaqhf
            {
485 23eb98bf gaqhf
                foreach (string fileName in xtraOpenFileDialog.FileNames)
486 1278ba59 gaqhf
                {
487 bca86986 gaqhf
                    SPPID_Document document = new SPPID_Document(fileName);
488 4314b3f3 gaqhf
489 68e9394a gaqhf
                    document.SymbolTable = _ID2SymbolTable;
490
                    document.SymbolMappings = symbolMappings;
491
                    document.ChildSymbolMappings = childSymbolMappings;
492
                    document.LineMappings = lineMappings;
493
                    document.LineNumberMappings = lineNumberMappings;
494
                    document.AttributeMappings = attributeMappings;
495
                    document.ETCSetting = ETCSetting.GetInstance();
496
                    document.SetSPPIDInfo();
497
498
499
                    if (!document.SetSPPIDMapping())
500
                    {
501
                        document.Enable = false;
502
                        document.MappingValidation = false;
503
                    }
504
505 bca86986 gaqhf
                    DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName));
506 0d8062b2 gaqhf
                    if (rows.Length == 0)
507
                    {
508 f9cc5190 gaqhf
                        DataRow row = _ConverterDT.NewRow();
509 0d8062b2 gaqhf
                        row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName);
510
                        row["colDrawingFilePath"] = fileName;
511
                        row["colDrawingNumber"] = document.DWGNAME;
512
                        row["colDrawingName"] = document.DWGNAME;
513
                        if (document.Enable)
514
                            row["colStatus"] = "Ready";
515
                        else
516
                            row["colStatus"] = "Error";
517
                        row["colUID"] = "";
518 d73c791c gaqhf
                        if (comboBoxEditDefaultTemplate.SelectedIndex > -1)
519 12b7a2a8 gaqhf
                            row["colTemplate"] = comboBoxEditDefaultTemplate.SelectedItem;
520 d73c791c gaqhf
                        if (!string.IsNullOrEmpty(buttonEditDefaultUnit.Text))
521
                            row["colUnit"] = buttonEditDefaultUnit.Text;
522
523 bca86986 gaqhf
                        _ConverterDT.Rows.Add(row);
524 0d8062b2 gaqhf
                    }
525 f9cc5190 gaqhf
                    else
526
                    {
527
                        foreach (DataRow row in rows)
528
                        {
529
                            if (document.Enable)
530
                                row["colStatus"] = "Ready";
531
                            else
532
                                row["colStatus"] = "Error";
533 d73c791c gaqhf
534
                            if (comboBoxEditDefaultTemplate.SelectedIndex > -1)
535
                                row["colTemplate"] = comboBoxEditDefaultTemplate.SelectedItem;
536
                            if (!string.IsNullOrEmpty(buttonEditDefaultUnit.Text))
537
                                row["colUnit"] = buttonEditDefaultUnit.Text;
538 f9cc5190 gaqhf
                        }
539
                    }
540 0d8062b2 gaqhf
                    if (!_DicDocuments.ContainsKey(fileName))
541
                        _DicDocuments.Add(fileName, null);
542
543 68e9394a gaqhf
                    if (!document.Validation || !document.MappingValidation)
544 0a111e7d gaqhf
                        validationFailDocs.Add(document);
545 e613d0e8 gaqhf
546 0d8062b2 gaqhf
                    _DicDocuments[fileName] = document;
547 1278ba59 gaqhf
                }
548 0a111e7d gaqhf
                if (validationFailDocs.Count > 0)
549
                {
550
                    MessageForm messageForm = new MessageForm(validationFailDocs);
551
                    messageForm.ShowDialog();
552
                }
553 1278ba59 gaqhf
            }
554 65a1ed4b gaqhf
        }
555 17f2a3a7 gaqhf
556 1278ba59 gaqhf
        private void btnRun_Click(object sender, EventArgs e)
557
        {
558 d73c791c gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
559
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
560
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
561
            {
562
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
563
                return;
564
            }
565
566 6924abc6 gaqhf
            if (gridViewConverter.GetSelectedRows().Length == 0)
567 e0bb889b gaqhf
            {
568
                MessageBox.Show(Msg.SelectDocument, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
569 6924abc6 gaqhf
                return;
570 e0bb889b gaqhf
            }
571 4ee5c4bf gaqhf
             
572 17f2a3a7 gaqhf
            _Documents.Clear();
573
            foreach (int rowHandle in gridViewConverter.GetSelectedRows())
574
            {
575
                string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath");
576
                string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit");
577
                string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
578
                string _DrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber");
579
                string _DrawingName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingName");
580
                SPPID_Document document = _DicDocuments[_FilePath];
581
                document.Unit = _Unit;
582
                document.Template = _Template;
583
                document.DrawingNumber = _DrawingNumber;
584
                document.DrawingName = _DrawingName;
585 712860bb gaqhf
586 4d2571ab gaqhf
                document.SymbolTable = _ID2SymbolTable;
587 712860bb gaqhf
                document.SymbolMappings = symbolMappings;
588
                document.ChildSymbolMappings = childSymbolMappings;
589
                document.LineMappings = lineMappings;
590
                document.LineNumberMappings = lineNumberMappings;
591
                document.AttributeMappings = attributeMappings;
592
                document.ETCSetting = ETCSetting.GetInstance();
593
                document.SetSPPIDInfo();
594
595 e3e2d41f gaqhf
                if (document.SetSPPIDMapping() && document.Enable)
596
                    _Documents.Add(document);
597 17f2a3a7 gaqhf
            }
598 5dfb8a24 gaqhf
599 d19ae675 gaqhf
            DialogResult = DialogResult.OK;
600 96a2080c gaqhf
        }
601 23eb98bf gaqhf
602
        private void btnSPPIDDB_Click(object sender, EventArgs e)
603
        {
604
            SPPID_DB_SettingForm form = new SPPID_DB_SettingForm();
605
            if (form.ShowDialog() == DialogResult.OK)
606 fab4f207 gaqhf
                InitSPPIDDB();
607 23eb98bf gaqhf
        }
608 df4559fc gaqhf
609
        private void btnItemMapping_Click(object sender, EventArgs e)
610
        {
611 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
612 d73c791c gaqhf
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
613
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
614 df4559fc gaqhf
            {
615 d73c791c gaqhf
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
616 df4559fc gaqhf
                return;
617
            }
618
619 e88aae98 gaqhf
            MappingForm form = new MappingForm(_ID2SymbolDT,_SPPIDSymbolPathDT, _ID2LineDT, _ID2LinePropertyDT, _ID2AttributeDT, _SPPIDAttributeDT);
620 df4559fc gaqhf
            form.ShowDialog();
621 bca86986 gaqhf
            InitMapping();
622 df4559fc gaqhf
        }
623 4314b3f3 gaqhf
        private List<int> prevSelectedList = new List<int>();
624
625
        private void gridViewConverter_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
626
        {
627
            if (e.Action == CollectionChangeAction.Add)
628
            {
629
                string _Unit = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colUnit");
630
                string _Template = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colTemplate");
631
632
                if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template))
633
                    gridViewConverter.UnselectRow(e.ControllerRow);
634
            }
635
            else if (e.Action == CollectionChangeAction.Refresh)
636
            {
637
                foreach (int rowHandle in gridViewConverter.GetSelectedRows())
638
                {
639
                    string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit");
640
                    string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
641
642
                    if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template))
643
                        gridViewConverter.UnselectRow(rowHandle);
644
                }
645
646
                List<int> selectedRowHandleList = gridViewConverter.GetSelectedRows().ToList();
647
                var firstNotSecond = prevSelectedList.Except(selectedRowHandleList).ToList();
648
                var secondNotFirst = selectedRowHandleList.Except(prevSelectedList).ToList();
649 635a8747 gaqhf
650 4314b3f3 gaqhf
                if (!firstNotSecond.Any() && !secondNotFirst.Any())
651
                {
652
                    this.gridViewConverter.SelectionChanged -= new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged);
653
                    gridViewConverter.ClearSelection();
654
                    this.gridViewConverter.SelectionChanged += new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged);
655
                }
656
            }
657
658
            prevSelectedList = gridViewConverter.GetSelectedRows().ToList();
659
        }
660 d73c791c gaqhf
661
        private void buttonEditDefaulUnit_ButtonClick(object sender, ButtonPressedEventArgs e)
662
        {
663
            UnitForm unitForm = new UnitForm(_SPPIDUnitDT);
664
            if (unitForm.ShowDialog() == DialogResult.OK)
665
            {
666
                buttonEditDefaultUnit.Text = unitForm.SelectedUnit;
667
            }
668
        }
669 02a45794 gaqhf
670
        private void btnRefresh_Click(object sender, EventArgs e)
671
        {
672
            List<BaseModel.Document> validationFailDocs = new List<BaseModel.Document>();
673
            Project_Info _ProjectInfo = Project_Info.GetInstance();
674
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
675
            if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable)
676
            {
677
                MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
678
                return;
679
            }
680
681
            foreach (DataRow row in _ConverterDT.Rows)
682
            {
683
                string fileName = row["colDrawingFilePath"].ToString();
684
                SPPID_Document document = new SPPID_Document(fileName);
685 68e9394a gaqhf
                document.SymbolTable = _ID2SymbolTable;
686
                document.SymbolMappings = symbolMappings;
687
                document.ChildSymbolMappings = childSymbolMappings;
688
                document.LineMappings = lineMappings;
689
                document.LineNumberMappings = lineNumberMappings;
690
                document.AttributeMappings = attributeMappings;
691
                document.ETCSetting = ETCSetting.GetInstance();
692
                document.SetSPPIDInfo();
693
694
695
                if (!document.SetSPPIDMapping())
696
                {
697
                    document.Enable = false;
698
                    document.MappingValidation = false;
699
                }
700
701 02a45794 gaqhf
                row["colDrawingNumber"] = document.DWGNAME;
702
                row["colDrawingName"] = document.DWGNAME;
703
                if (document.Enable)
704
                    row["colStatus"] = "Ready";
705
                else
706
                    row["colStatus"] = "Error";
707
708
                if (!_DicDocuments.ContainsKey(fileName))
709
                    _DicDocuments.Add(fileName, null);
710
711 68e9394a gaqhf
                if (!document.Validation || !document.MappingValidation)
712 02a45794 gaqhf
                    validationFailDocs.Add(document);
713
714
                _DicDocuments[fileName] = document;
715
            }
716
717
718
            if (validationFailDocs.Count > 0)
719
            {
720
                MessageForm messageForm = new MessageForm(validationFailDocs);
721
                messageForm.ShowDialog();
722
            }
723
        }
724 12b7a2a8 gaqhf
725
        private void buttonEditDefaultUnit_TextChanged(object sender, EventArgs e)
726
        {
727
            Settings.Default.DefaultUnit = buttonEditDefaultUnit.Text;
728
            Settings.Default.Save();
729
        }
730
731
        private void comboBoxEditDefaultTemplate_SelectedIndexChanged(object sender, EventArgs e)
732
        {
733
            Settings.Default.DefaultTemplate = comboBoxEditDefaultTemplate.SelectedItem.ToString();
734
            Settings.Default.Save();
735
        }
736 96a2080c gaqhf
    }
737
}
클립보드 이미지 추가 (최대 크기: 500 MB)