프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / ConverterForm.cs @ aa3c9d74

이력 | 보기 | 이력해설 | 다운로드 (28 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 23eb98bf gaqhf
using Converter.BaseModel;
12 1278ba59 gaqhf
using DevExpress.XtraEditors.Repository;
13
using DevExpress.XtraEditors.Controls;
14
using DevExpress.XtraEditors;
15 23eb98bf gaqhf
using System.Globalization;
16
using System.Threading;
17
using System.IO;
18 b8e2644e gaqhf
using Converter.SPPID.Properties;
19
using Converter.SPPID.DB;
20
using Converter.SPPID.Util;
21
using Converter.SPPID.Form;
22
using Converter.SPPID.Model;
23 96a2080c gaqhf
24 b8e2644e gaqhf
namespace Converter.SPPID
25 96a2080c gaqhf
{
26
    public partial class ConverterForm : DevExpress.XtraBars.Ribbon.RibbonForm
27
    {
28 bca86986 gaqhf
        private Dictionary<string, SPPID_Document> _DicDocuments = new Dictionary<string, SPPID_Document>();
29 4314b3f3 gaqhf
        private List<SPPID_Document> _Documents = new List<SPPID_Document>();
30
        public List<SPPID_Document> Documents { get { return _Documents; } }
31 bca86986 gaqhf
        private DataTable _ConverterDT = new DataTable();
32
        private DataTable _SPPIDSymbolPathDT = new DataTable();
33 635a8747 gaqhf
        private DataTable _SPPIDUnitDT = new DataTable();
34 23eb98bf gaqhf
        private RepositoryItemComboBox templateComboBox;
35
36 bca86986 gaqhf
37
        private DataTable _ID2SymbolDT = new DataTable();
38 4b4dbca9 gaqhf
        private DataTable _ID2ChildSymbolDT = new DataTable();
39 bca86986 gaqhf
        private DataTable _ID2LineDT = new DataTable();
40 1efc25a3 gaqhf
        private DataTable _ID2AttributeDT = new DataTable();
41 bca86986 gaqhf
        private DataTable _ID2LinePropertyDT = new DataTable();
42 f1c9dbaa gaqhf
        private DataTable _ID2SymbolTypeDT = new DataTable();
43
44 bca86986 gaqhf
45
        private List<SymbolMapping> symbolMappings = new List<SymbolMapping>();
46 4b4dbca9 gaqhf
        private List<ChildSymbolMapping> childSymbolMappings = new List<ChildSymbolMapping>();
47 bca86986 gaqhf
        private List<LineMapping> lineMappings = new List<LineMapping>();
48
        private List<LineNumberMapping> lineNumberMappings = new List<LineNumberMapping>();
49 1efc25a3 gaqhf
        private List<AttributeMapping> attributeMappings = new List<AttributeMapping>();
50 bca86986 gaqhf
51 96a2080c gaqhf
        public ConverterForm()
52
        {
53
            InitializeComponent();
54 1278ba59 gaqhf
55 fab4f207 gaqhf
            CultureInfo culture = CultureInfo.GetCultureInfo("ko");
56 23eb98bf gaqhf
            Msg.Culture = culture;
57
58 bca86986 gaqhf
            InitUsedDataTable();
59 1278ba59 gaqhf
            InitGridControl();
60 fab4f207 gaqhf
            InitID2Project();
61 1278ba59 gaqhf
        }
62
63 f1232880 gaqhf
        #region
64
        /// <summary>
65
        /// The Activate Event is where the command should show its form
66
        /// if it should be displayed.
67
        /// </summary>
68
        /// <param name="sender">The sender of the event</param>
69
        /// <param name="e">Arguments passed during event</param>
70
        private void commandControl_Activate(object sender, EventArgs e)
71
        {
72 5e6ecf05 gaqhf
            Show();
73
            //if (ShowDialog() == DialogResult.OK)
74
            //{
75 f1232880 gaqhf
76 5e6ecf05 gaqhf
            //}
77 f1232880 gaqhf
78 5e6ecf05 gaqhf
            //foreach (var item in commandControl.Application.RADApplication.ActiveSelectSet)
79
            //{
80
            //    //MessageBox.Show(item.GetType());
81
            //    int count = ((Ingr.RAD2D.LineStringGeometry2d)((Ingr.RAD2D.DependencyObject)item).GetGeometry()).VertexCount;
82
            //    double[] iii = null;
83
            //    ((Ingr.RAD2D.LineStringGeometry2d)((Ingr.RAD2D.DependencyObject)item).GetGeometry()).GetVertices(ref count, ref iii);
84
            //    for (int i = 0; i < count; i++)
85
            //    {
86
            //        double x = 0;
87
            //        double y = 0;
88
            //        ((Ingr.RAD2D.LineStringGeometry2d)((Ingr.RAD2D.DependencyObject)item).GetGeometry()).GetVertex(i + 1, ref x, ref y);
89
90
            //    }
91
            //    Ingr.RAD2D.Symbol2d symbol2D;
92
            //    //symbol2D.Move
93
            //}
94 f1232880 gaqhf
95
            //commandControl.Application.RADApplication.Interactive = true;
96
            //Hide();
97
            //commandControl.Done = true;
98
        }
99
100
        /// <summary>
101
        /// The Deactivate event is where the command should hide its form if it
102
        /// was displayed.  The command should not unload the form here.
103
        /// The command's form should be unloaded in the Class Module Terminate event.
104
        /// </summary>
105
        /// <param name="sender">The sender of the event</param>
106
        /// <param name="e">Arguments passed during event</param>
107
        private void commandControl_Deactivate(object sender, EventArgs e)
108
        {
109
            Hide();
110
        }
111
112
        /// <summary>
113
        /// The Initialize event is where the command should perform 1 time 
114
        /// initialization, for example it might save a reference to the 
115
        /// active document in private global data.
116
        /// </summary>
117
        /// <param name="sender">The sender of the event</param>
118
        /// <param name="e">Arguments passed during event</param>
119
        private void commandControl_Initialize(object sender, EventArgs e)
120
        {
121
122
        }
123
124
        /// <summary>
125
        /// The Terminate event is where the command can clean up any command
126
        /// specific allocated resources.
127
        /// </summary>
128
        /// <param name="sender">The sender of the event</param>
129
        /// <param name="e">Arguments passed during event</param>
130
        public void commandControl_Terminate(object sender, EventArgs e)
131
        {
132
133
        }
134
135
        /// <summary>
136
        /// The primary form should not simply be unloaded. You should set the
137
        /// Intergraph Command Control Done property to True when you want the 
138
        /// form to be unloaded. Then unload the form in the dispose method.
139
        /// </summary>
140
        /// <param name="sender">The sender of the event</param>
141
        /// <param name="e">Arguments passed during event</param>
142
        private void ConverterForm_FormClosing(object sender, FormClosingEventArgs e)
143
        {
144
            Hide();
145
            commandControl.Done = true;
146
            e.Cancel = true; //Do not let C# close out the form ... Let RAD close it.
147
        }
148
        #endregion
149
150 bca86986 gaqhf
        private void InitUsedDataTable()
151 1278ba59 gaqhf
        {
152 bca86986 gaqhf
            // Converter Table
153
            DataColumn col = _ConverterDT.Columns.Add("colDrawingFileName");
154 1278ba59 gaqhf
            col.Caption = "Drawing File Name";
155 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colDrawingFilePath");
156 0d8062b2 gaqhf
            col.Caption = "DrawingFilePath";
157 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colUnit");
158 1278ba59 gaqhf
            col.Caption = "Unit";
159 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colTemplate");
160 1278ba59 gaqhf
            col.Caption = "Template";
161 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colDrawingNumber");
162 1278ba59 gaqhf
            col.Caption = "Drawing Number";
163 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colDrawingName");
164 1278ba59 gaqhf
            col.Caption = "Drawing Name";
165 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colStatus");
166 1278ba59 gaqhf
            col.Caption = "Status";
167 bca86986 gaqhf
            col = _ConverterDT.Columns.Add("colUID");
168
169
            col = _ID2LineDT.Columns.Add("UID");
170
            col = _ID2LineDT.Columns.Add("Name");
171
            col.Caption = "Name";
172
            col = _ID2LineDT.Columns.Add("Type");
173
            col.Caption = "Type";
174
            col = _ID2LineDT.Columns.Add("SPPID_SYMBOL_PATH");
175
            col.Caption = "SPPID Symbol Path";
176
            col = _ID2LineDT.Columns.Add("Clear");
177
            col.Caption = "";
178
        }
179
180
        private void InitGridControl()
181
        {
182
            #region Converter Page
183
            gridViewConverter.OptionsSelection.MultiSelect = true;
184
            gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
185
            
186
            gridControlConverter.DataSource = _ConverterDT;
187 1278ba59 gaqhf
188
            templateComboBox = new RepositoryItemComboBox();
189
            templateComboBox.TextEditStyle = TextEditStyles.DisableTextEditor;
190 635a8747 gaqhf
            templateComboBox.EditValueChanged += templateComboBox_EditValueChanged;
191 1278ba59 gaqhf
            gridControlConverter.RepositoryItems.Add(templateComboBox);
192
            gridViewConverter.Columns["colTemplate"].ColumnEdit = templateComboBox;
193
194 635a8747 gaqhf
            gridViewConverter.Columns["colUnit"].OptionsColumn.AllowEdit = false;
195 1278ba59 gaqhf
            gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false;
196
            gridViewConverter.Columns["colUnit"].OptionsColumn.ReadOnly = true;
197
            gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false;
198 0d8062b2 gaqhf
            gridViewConverter.Columns["colDrawingFilePath"].Visible = false;
199 1278ba59 gaqhf
            gridViewConverter.Columns["colUID"].Visible = false;
200
201
            gridViewConverter.BestFitColumns();
202
            #endregion
203
        }
204 f1c9dbaa gaqhf
205 635a8747 gaqhf
        private void templateComboBox_EditValueChanged(object sender, EventArgs e)
206
        {
207
            gridViewConverter.CloseEditor();
208
            gridViewConverter.UpdateCurrentRow();
209
        }
210
211
        private void gridViewConverter_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
212
        {
213
            if (e.Column.Name == "colcolTemplate")
214
            {
215
                gridViewConverter.ShowEditor();
216
                (gridViewConverter.ActiveEditor as ComboBoxEdit).ShowPopup();
217
            }
218
            else if (e.Column.Name == "colcolUnit")
219
            {
220
                UnitForm unitForm = new UnitForm(_SPPIDUnitDT);
221
                if (unitForm.ShowDialog() == DialogResult.OK)
222
                {
223
                    gridViewConverter.SetRowCellValue(e.RowHandle, e.Column, unitForm.SelectedUnit);
224
                    gridViewConverter.CloseEditor();
225
                    gridViewConverter.UpdateCurrentRow();
226
                }
227
            }
228
        }
229 1278ba59 gaqhf
230 23eb98bf gaqhf
        private void btnID2Project_ButtonClick(object sender, ButtonPressedEventArgs e)
231
        {
232 fab4f207 gaqhf
            xtraFolderBrowserDialog.SelectedPath = btnID2Project.Text;
233
234 23eb98bf gaqhf
            if (xtraFolderBrowserDialog.ShowDialog() == DialogResult.OK)
235
            {
236 fab4f207 gaqhf
                if (xtraFolderBrowserDialog.SelectedPath[xtraFolderBrowserDialog.SelectedPath.Length - 1] == '\\')
237
                    xtraFolderBrowserDialog.SelectedPath = xtraFolderBrowserDialog.SelectedPath.Remove(xtraFolderBrowserDialog.SelectedPath.Length - 1);
238
                Settings.Default.LatestProjectPath = xtraFolderBrowserDialog.SelectedPath;
239
                Settings.Default.Save();
240
                if (InitID2Project())
241 635a8747 gaqhf
                {
242 fab4f207 gaqhf
                    MessageBox.Show(Msg.SuccessProjectSelect, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
243 635a8747 gaqhf
                }
244 fab4f207 gaqhf
                else
245 23eb98bf gaqhf
                    MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
246
            }
247
        }
248
249 fab4f207 gaqhf
        private bool InitID2Project()
250 23eb98bf gaqhf
        {
251 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
252 fab4f207 gaqhf
            _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath;
253
            if (Project_DB.ConnTestAndCreateTable())
254 23eb98bf gaqhf
            {
255 fab4f207 gaqhf
                _ProjectInfo.Enable = true;
256 171142c5 gaqhf
                btnID2Project.Text = _ProjectInfo.DefaultPath;
257 23eb98bf gaqhf
                labelID2ProjectName.Text = _ProjectInfo.Name;
258
                labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue;
259
                labelID2ProjectStatus.Text = Msg.ConnectionSuccessful;
260
                labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue;
261 fab4f207 gaqhf
                layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
262
                layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
263 23eb98bf gaqhf
            }
264
            else
265
            {
266 fab4f207 gaqhf
                _ProjectInfo.Enable = false;
267 23eb98bf gaqhf
                btnID2Project.Text = "";
268
                labelID2ProjectName.Text = " ";
269
                labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red;
270
                labelID2ProjectStatus.Text = Msg.ConnectionFail;
271
                labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red;
272 fab4f207 gaqhf
                layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
273
                layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
274 bca86986 gaqhf
            }
275 fab4f207 gaqhf
276 bca86986 gaqhf
            InitMapping();
277
            InitSPPIDDB();
278
279
            return _ProjectInfo.Enable;
280
        }
281
282
        private void InitMapping()
283
        {
284
            Project_Info _ProjectInfo = Project_Info.GetInstance();
285
            if (_ProjectInfo.Enable)
286
            {
287
                InitID2Symbol();
288
                InitID2Line();
289
                InitID2LineNumber();
290 1efc25a3 gaqhf
                InitID2Attribute();
291 e00e891d gaqhf
292
                InitETCSetting();
293
            }
294
        }
295 fbdb9f2a gaqhf
296 e00e891d gaqhf
        private void InitETCSetting()
297
        {
298
            Project_Info _ProjectInfo = Project_Info.GetInstance();
299
            if (_ProjectInfo.Enable)
300
            {
301
                DataTable dt = Project_DB.SelectETCSetting();
302
                if (dt.Columns.Count > 0 && dt.Rows.Count > 0)
303
                    SPPIDUtil.ConvertToETCSetting(dt.Rows[0][0].ToString());
304
                else
305
                    SPPID_DBInfo.Clear();
306 bca86986 gaqhf
            }
307
        }
308
309
        private void InitID2Symbol()
310
        {
311
            using (DataTable symbolDT = Project_DB.SelectProjectSymbol())
312
            {
313
                symbolMappings.Clear();
314
                _ID2SymbolDT = symbolDT;
315
                _ID2SymbolDT.Columns.Add("Clear");
316
                _ID2SymbolDT.Columns["Clear"].Caption = "";
317
                foreach (DataRow row in symbolDT.Rows)
318
                {
319
                    symbolMappings.Add(new SymbolMapping()
320
                    {
321
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
322
                        SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(),
323
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
324
                    });
325
                }
326 4b4dbca9 gaqhf
327
                MergeID2ChildSymbol();
328
            }
329
        }
330
331
        private void MergeID2ChildSymbol()
332
        {
333
            using (DataTable childSymbolDT = Project_DB.SelectProjectChildSymbol())
334
            {
335
                childSymbolMappings.Clear();
336
                _ID2ChildSymbolDT = childSymbolDT;
337
                _ID2ChildSymbolDT.Columns.Add("Clear");
338
                _ID2ChildSymbolDT.Columns["Clear"].Caption = "";
339
                foreach (DataRow row in childSymbolDT.Rows)
340
                {
341
                    childSymbolMappings.Add(new ChildSymbolMapping()
342
                    {
343
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
344
                        SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(),
345
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
346
                    });
347
                }
348
349
                _ID2SymbolDT.Merge(_ID2ChildSymbolDT);
350 bca86986 gaqhf
            }
351
        }
352
353
        private void InitID2Line()
354
        {
355
            using (DataTable lineTypes = Project_DB.SelectProjectLine())
356
            {
357
                lineMappings.Clear();
358
                _ID2LineDT.Rows.Clear();
359
                foreach (DataRow row in lineTypes.Rows)
360
                {
361
                    DataRow newRow = _ID2LineDT.NewRow();
362
                    newRow["UID"] = row["UID"] == null ? "" : row["UID"].ToString();
363
                    newRow["Name"] = row["Name"] == null ? "" : row["Name"].ToString();
364
                    newRow["Type"] = "Line";
365
                    newRow["SPPID_SYMBOL_PATH"] = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString();
366
                    _ID2LineDT.Rows.Add(newRow);
367
368
                    lineMappings.Add(new LineMapping()
369
                    {
370
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
371
                        LINENAME = row["Name"] == null ? "" : row["Name"].ToString(),
372
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
373
                    });
374
                }
375
            }
376
        }
377
378
        private void InitID2LineNumber()
379
        {
380
            using (DataTable linePropertiesDT = Project_DB.SelectProjectLineProperties())
381
            {
382
                lineNumberMappings.Clear();
383
                _ID2LinePropertyDT = linePropertiesDT;
384
                _ID2LinePropertyDT.Columns.Add("Type");
385
                foreach (DataRow row in linePropertiesDT.Rows)
386
                {
387
                    row["Type"] = "Line Property";
388
                    lineNumberMappings.Add(new LineNumberMapping()
389
                    {
390
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
391
                        DisplayName = row["DisplayName"] == null ? "" : row["DisplayName"].ToString(),
392
                        SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(),
393
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString()
394
                    });
395
                }
396
            }
397
        }
398
399 1efc25a3 gaqhf
        private void InitID2Attribute()
400 bca86986 gaqhf
        {
401 1efc25a3 gaqhf
            using (DataTable attributeDT = Project_DB.SelectProjectAttribute())
402 bca86986 gaqhf
            {
403 1efc25a3 gaqhf
                attributeMappings.Clear();
404
                _ID2AttributeDT = attributeDT;
405
                _ID2AttributeDT.Columns.Add("Clear");
406
                _ID2AttributeDT.Columns["Clear"].Caption = "";
407
                foreach (DataRow row in attributeDT.Rows)
408 bca86986 gaqhf
                {
409 1efc25a3 gaqhf
                    attributeMappings.Add(new AttributeMapping()
410 bca86986 gaqhf
                    {
411
                        UID = row["UID"] == null ? "" : row["UID"].ToString(),
412
                        DisplayAttribute = row["DisplayAttribute"] == null ? "" : row["DisplayAttribute"].ToString(),
413
                        Type = row["Type"] == null ? "" : row["Type"].ToString(),
414
                        SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(),
415 1a3a74a8 gaqhf
                        SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(),
416
                        Location = DBNull.Value.Equals(row["LOCATION"]) ? Model.Location.None : (Location)row["LOCATION"]
417 bca86986 gaqhf
                    });
418
                }
419 23eb98bf gaqhf
            }
420
        }
421
422 fab4f207 gaqhf
        private void InitSPPIDDB()
423 23eb98bf gaqhf
        {
424 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
425 fab4f207 gaqhf
            if (_ProjectInfo.Enable)
426
            {
427
                DataTable dt = Project_DB.SelectSPPID_DB_INFO();
428 ec0c7045 gaqhf
                if (dt.Columns.Count > 0 && dt.Rows.Count > 0)
429
                    SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString());
430
                else
431
                    SPPID_DBInfo.Clear();
432 fab4f207 gaqhf
            }
433 ec0c7045 gaqhf
434 635a8747 gaqhf
            templateComboBox.Items.Clear();
435 ec0c7045 gaqhf
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
436 23eb98bf gaqhf
            if (_SPPIDInfo.Enable)
437
            {
438
                labelSPPIDPlantName.Text = _SPPIDInfo.SelectedPlant;
439
                labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Blue;
440
                labelSPPIDDBStatus.Text = Msg.ConnectionSuccessful;
441
                labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Blue;
442 635a8747 gaqhf
443
                string TemplatePath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("PID Template Path");
444
                if (!string.IsNullOrEmpty(TemplatePath))
445
                    templateComboBox.Items.AddRange(Directory.GetFiles(TemplatePath, "*.pid").ToList().Select(filePath => Path.GetFileName(filePath)).ToList());
446
447
                _SPPIDUnitDT = SPPID_DB.GetUnitTree();
448
449
                layoutControlGroupAutoConverter.Enabled = true;
450 23eb98bf gaqhf
            }
451
            else
452
            {
453
                labelSPPIDPlantName.Text = " ";
454
                labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Red;
455
                labelSPPIDDBStatus.Text = Msg.ConnectionFail;
456
                labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Red;
457 bca86986 gaqhf
458 635a8747 gaqhf
                layoutControlGroupAutoConverter.Enabled = false;
459 23eb98bf gaqhf
            }
460 bca86986 gaqhf
461 635a8747 gaqhf
            _DicDocuments.Clear();
462
            _ConverterDT.Rows.Clear();
463 bca86986 gaqhf
            InitSPPIDSymbolTreeTable();
464 23eb98bf gaqhf
        }
465
466 bca86986 gaqhf
        private void InitSPPIDSymbolTreeTable()
467 23eb98bf gaqhf
        {
468 bca86986 gaqhf
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
469
470 26c6f818 gaqhf
            try
471
            {
472
                _SPPIDSymbolPathDT = new DataTable();
473
                _SPPIDSymbolPathDT.Columns.Add("ID");
474
                _SPPIDSymbolPathDT.Columns.Add("Parent");
475
                _SPPIDSymbolPathDT.Columns.Add("Name");
476
                _SPPIDSymbolPathDT.Columns.Add("FullPath");
477 bca86986 gaqhf
478 26c6f818 gaqhf
                if (_SPPIDInfo.Enable)
479
                {
480
                    string symbolPath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("Catalog Explorer root path");
481
                    DirectoryInfo info = new DirectoryInfo(symbolPath);
482
                    _SPPIDSymbolPathDT.Rows.Add(new object[] { "0", "-1", info.Name });
483
                    loop(info, "0", symbolPath);
484
                }
485
            }
486
            catch (Exception ex)
487 23eb98bf gaqhf
            {
488 26c6f818 gaqhf
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
489 23eb98bf gaqhf
            }
490 bca86986 gaqhf
        }
491 23eb98bf gaqhf
492 bca86986 gaqhf
        private void loop(DirectoryInfo parentInfo, string parentUID, string defaultPath)
493
        {
494
            DirectoryInfo[] infos = parentInfo.GetDirectories();
495
            foreach (DirectoryInfo info in infos)
496
            {
497
                string uid = Guid.NewGuid().ToString();
498
                _SPPIDSymbolPathDT.Rows.Add(new object[] { uid, parentUID, info.Name });
499
                loop(info, uid, defaultPath);
500
501
                FileInfo[] files = info.GetFiles("*.sym");
502
                foreach (FileInfo fileInfo in files)
503
                {
504
                    _SPPIDSymbolPathDT.Rows.Add(new object[] { Guid.NewGuid().ToString(), uid, fileInfo.Name, fileInfo.FullName.Replace(defaultPath, "") });
505
                }
506
            }
507 23eb98bf gaqhf
        }
508
509 1278ba59 gaqhf
        private void btnLoadFile_Click(object sender, EventArgs e)
510
        {
511 65a1ed4b gaqhf
            modeling.Test();
512
            return;
513 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
514 23eb98bf gaqhf
            if (!_ProjectInfo.Enable)
515
            {
516
                MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
517
                return;
518
            }
519 1278ba59 gaqhf
520 171142c5 gaqhf
            xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath;
521 23eb98bf gaqhf
            if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK)
522 1278ba59 gaqhf
            {
523 23eb98bf gaqhf
                foreach (string fileName in xtraOpenFileDialog.FileNames)
524 1278ba59 gaqhf
                {
525 bca86986 gaqhf
                    SPPID_Document document = new SPPID_Document(fileName);
526 4314b3f3 gaqhf
527 bca86986 gaqhf
                    DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName));
528 0d8062b2 gaqhf
                    DataRow row;
529
                    if (rows.Length == 0)
530
                    {
531 bca86986 gaqhf
                        row = _ConverterDT.NewRow();
532 0d8062b2 gaqhf
                        row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName);
533
                        row["colDrawingFilePath"] = fileName;
534
                        row["colDrawingNumber"] = document.DWGNAME;
535
                        row["colDrawingName"] = document.DWGNAME;
536
                        if (document.Enable)
537
                            row["colStatus"] = "Ready";
538
                        else
539
                            row["colStatus"] = "Error";
540
                        row["colUID"] = "";
541 bca86986 gaqhf
                        _ConverterDT.Rows.Add(row);
542 0d8062b2 gaqhf
                    }
543
                    if (!_DicDocuments.ContainsKey(fileName))
544
                        _DicDocuments.Add(fileName, null);
545
546
                    _DicDocuments[fileName] = document;
547 1278ba59 gaqhf
                }
548
            }
549 65a1ed4b gaqhf
        }
550
        static AutoModeling modeling;
551 1278ba59 gaqhf
        private void btnRun_Click(object sender, EventArgs e)
552
        {
553 5dfb8a24 gaqhf
#if DEBUG
554 402ef5b1 gaqhf
            this.Visible = false;
555
556 5a4b8f32 gaqhf
            SPPID_Document document = new SPPID_Document(@"Z:\HanKyouHo\temp\Isocynates\Temp\11111.xml");
557
            //SPPID_Document document = new SPPID_Document(@"Z:\HanKyouHo\temp\Isocynates\Temp\Isocynates-325_Page50.xml");
558 1a3a74a8 gaqhf
            //SPPID_Document document = new SPPID_Document(@"Z:\HanKyouHo\temp\Isocynates\Temp\Isocynates-325_Page49.xml");
559 5dfb8a24 gaqhf
            document.SymbolMappings = symbolMappings;
560 4b4dbca9 gaqhf
            document.ChildSymbolMappings = childSymbolMappings;
561 5dfb8a24 gaqhf
            document.LineMappings = lineMappings;
562
            document.LineNumberMappings = lineNumberMappings;
563 1efc25a3 gaqhf
            document.AttributeMappings = attributeMappings;
564 5dfb8a24 gaqhf
            document.ETCSetting = ETCSetting.GetInstance();
565 f1c9dbaa gaqhf
566 5dfb8a24 gaqhf
            document.SetSPPIDInfo();
567 4314b3f3 gaqhf
568 8aa6f2db gaqhf
            if (document.SetSPPIDMapping() && document.Enable)
569 4314b3f3 gaqhf
            {
570 65a1ed4b gaqhf
                modeling = new AutoModeling(document, commandControl.Application.RADApplication);
571 5dfb8a24 gaqhf
                modeling.Run();
572 4314b3f3 gaqhf
            }
573
574 402ef5b1 gaqhf
            this.Visible = true;
575 5dfb8a24 gaqhf
            return;
576
#endif
577
578
            //_Documents.Clear();
579
580
            //foreach (int rowHandle in gridViewConverter.GetSelectedRows())
581
            //{
582
            //    string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath");
583
            //    string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit");
584
            //    string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
585
            //    string _DrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber");
586
            //    string _DrawingName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingName");
587
            //    SPPID_Document document = _DicDocuments[_FilePath];
588
            //    document.Unit = _Unit;
589
            //    document.Template = _Template;
590
            //    document.DrawingNumber = _DrawingNumber;
591
            //    document.DrawingName = _DrawingName;
592
            //    _Documents.Add(document);
593
            //}
594
595 1278ba59 gaqhf
            DialogResult = DialogResult.OK;
596 96a2080c gaqhf
        }
597 23eb98bf gaqhf
598
        private void btnSPPIDDB_Click(object sender, EventArgs e)
599
        {
600
            SPPID_DB_SettingForm form = new SPPID_DB_SettingForm();
601
            if (form.ShowDialog() == DialogResult.OK)
602 fab4f207 gaqhf
                InitSPPIDDB();
603 23eb98bf gaqhf
        }
604 df4559fc gaqhf
605
        private void btnItemMapping_Click(object sender, EventArgs e)
606
        {
607 ec0c7045 gaqhf
            Project_Info _ProjectInfo = Project_Info.GetInstance();
608 df4559fc gaqhf
            if (!_ProjectInfo.Enable)
609
            {
610
                MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
611
                return;
612
            }
613
614 1efc25a3 gaqhf
            MappingForm form = new MappingForm(_ID2SymbolDT,_SPPIDSymbolPathDT, _ID2LineDT, _ID2LinePropertyDT, _ID2AttributeDT);
615 df4559fc gaqhf
            form.ShowDialog();
616 bca86986 gaqhf
            InitMapping();
617 df4559fc gaqhf
        }
618 4314b3f3 gaqhf
        private List<int> prevSelectedList = new List<int>();
619
620
        private void gridViewConverter_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
621
        {
622
            if (e.Action == CollectionChangeAction.Add)
623
            {
624
                string _Unit = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colUnit");
625
                string _Template = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colTemplate");
626
627
                if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template))
628
                    gridViewConverter.UnselectRow(e.ControllerRow);
629
            }
630
            else if (e.Action == CollectionChangeAction.Refresh)
631
            {
632
                foreach (int rowHandle in gridViewConverter.GetSelectedRows())
633
                {
634
                    string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit");
635
                    string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
636
637
                    if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template))
638
                        gridViewConverter.UnselectRow(rowHandle);
639
                }
640
641
                List<int> selectedRowHandleList = gridViewConverter.GetSelectedRows().ToList();
642
                var firstNotSecond = prevSelectedList.Except(selectedRowHandleList).ToList();
643
                var secondNotFirst = selectedRowHandleList.Except(prevSelectedList).ToList();
644 635a8747 gaqhf
645 4314b3f3 gaqhf
                if (!firstNotSecond.Any() && !secondNotFirst.Any())
646
                {
647
                    this.gridViewConverter.SelectionChanged -= new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged);
648
                    gridViewConverter.ClearSelection();
649
                    this.gridViewConverter.SelectionChanged += new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged);
650
                }
651
            }
652
653
            prevSelectedList = gridViewConverter.GetSelectedRows().ToList();
654
        }
655 96a2080c gaqhf
    }
656
}
클립보드 이미지 추가 (최대 크기: 500 MB)