프로젝트

일반

사용자정보

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

hytos / ID2.Manager / ID2.Manager.Compare / Main.cs @ 2810b131

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

1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10

    
11
using System.IO;
12
using System.Reflection;
13
using System.Diagnostics;
14

    
15
using ID2.Manager.Controls;
16
using ID2.Manager.Classes;
17

    
18
using Telerik.WinControls;
19
using Telerik.WinControls.UI;
20

    
21
namespace ID2.Manager
22
{
23
    public partial class Main : RadRibbonForm
24
    {
25
        protected override CreateParams CreateParams
26
        {
27
            get
28
            {
29
                CreateParams cp = base.CreateParams;
30
                cp.ExStyle |= 0x02000000;
31
                return cp;
32
            }
33
        }
34

    
35
        private string dockLayoutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Application.ProductName,
36
         "dock.xml");
37

    
38
//#if DEBUG
39
//        Telerik.WinControls.RadControlSpy.RadControlSpyForm radControlSpyForm = new Telerik.WinControls.RadControlSpy.RadControlSpyForm();
40
//#endif
41
        private readonly Color _SummaryColor = Color.FromArgb(255, 108, 55);
42

    
43
        public Main()
44
        {
45
            InitializeComponent();
46
            var verification = new Controls.Verification(this.radProgressBarElement) { Dock = DockStyle.Fill };
47
            this.LayoutValidation.Controls.Add(verification);
48
            this.DockMainTabStrip.Select();
49

    
50
            var appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Application.ProductName);
51

    
52
            if (!Directory.Exists(appDataPath))
53
            {
54
                Directory.CreateDirectory(appDataPath);
55
            }
56

    
57
            #region 테마 설정
58
            this.radMenuItemControlDefault.Click += RadMenuItemTheme_Click;
59
            this.radMenuItemOffice2013Dark.Click += RadMenuItemTheme_Click;
60
            this.radMenuItemTelerikMetro.Click += RadMenuItemTheme_Click;
61
            this.radMenuItemVisualStudio2012Dark.Click += RadMenuItemTheme_Click;
62
            this.radMenuItemVisualStudio2012Light.Click += RadMenuItemTheme_Click;
63
            this.radMenuItemWindows8.Click += RadMenuItemTheme_Click;
64
            #endregion
65

    
66
            this.Initialize();
67
        }
68

    
69
        /// <summary>
70
        /// 사용자가 선택한 테마를 적용한다.
71
        /// </summary>
72
        /// <param name="sender"></param>
73
        /// <param name="e"></param>
74
        private void RadMenuItemTheme_Click(object sender, EventArgs e)
75
        {
76
            string theme = (sender as RadMenuItem).Text;
77
            if(theme != this.radDropDownButtonElementTheme.Text)
78
            {
79
                this.radDropDownButtonElementTheme.Text = theme;
80
                Classes.ID2Helper.IniWriteValue(Program.IniFilePath, "App", "Theme", theme);
81
                if (!string.IsNullOrEmpty(theme))
82
                {
83
                    Telerik.WinControls.ThemeResolutionService.ApplicationThemeName = theme;
84
                    Program.ThemeName = theme;
85
                }
86
            }
87
        }
88

    
89
        #region Init, Load
90
        private void Initialize()
91
        {
92
            this.ID2ManagerRadRibbonBar.Expanded = false;
93
        }
94

    
95
        protected override void OnLoad(EventArgs e)
96
        {
97
            try
98
            {
99
                #region 테마를 읽어 적용
100
                string theme = Classes.ID2Helper.IniReadValue(Program.IniFilePath, "App", "Theme");
101
                if (!string.IsNullOrEmpty(theme))
102
                {
103
                    Telerik.WinControls.ThemeResolutionService.ApplicationThemeName = theme;
104
                    Program.ThemeName = theme;
105
                }
106
                #endregion
107

    
108
                this.radDropDownButtonElementTheme.Text = Program.ThemeName;
109
                this.radBrowseEditorAutoCADFolder.ValueChanged += RadBrowseEditorAutoCADFolder_ValueChanged;
110
                this.radBrowseEditorAVEVAFolder.ValueChanged += RadBrowseEditorAVEVAFolder_ValueChanged;
111
                this.radGridViewDocument.DataBindingComplete += RadGridViewDocument_DataBindingComplete;
112
                this.radGridViewDocument.ViewRowFormatting += RadGridViewDocument_ViewRowFormatting;
113
                this.radGridViewDocument.CellClick += RadGridViewDocument_CellClick;
114
                this.radButtonElementCompare.Click += RadButtonElementCompare_Click;
115
                this.radButtonElementConfiguration.Click += RadButtonElementConfiguration_Click;
116

    
117
                this.radButtonElementRefreshCommand.Click += RadButtonElementRefreshCommand_Click;
118

    
119
                Program.AutoCADFolder = Classes.ID2Helper.IniReadValue(Program.IniFilePath, "Path", "AutoCAD Folder");
120
                if (!string.IsNullOrEmpty(Program.AutoCADFolder)) this.radBrowseEditorAutoCADFolder.Value = Program.AutoCADFolder;
121

    
122
                Program.AVEVAPIDFolder = Classes.ID2Helper.IniReadValue(Program.IniFilePath, "Path", "AVEVA P&ID Folder");
123
                if (!string.IsNullOrEmpty(Program.AVEVAPIDFolder)) this.radBrowseEditorAVEVAFolder.Value = Program.AVEVAPIDFolder;
124
            }
125
            catch (Exception ex)
126
            {
127
                Program.logger.Error($"An exception occurred from {MethodBase.GetCurrentMethod().Name}", ex);
128
                RadMessageBox.Show("Failed to load project.", Application.ProductName, MessageBoxButtons.OK, RadMessageIcon.Error);
129
            }
130

    
131
            base.OnLoad(e);
132
        }
133

    
134
        /// <summary>
135
        /// 도면 리스트를 갱신한다.
136
        /// </summary>
137
        /// <param name="sender"></param>
138
        /// <param name="e"></param>
139
        private void RadButtonElementRefreshCommand_Click(object sender, EventArgs e)
140
        {
141
            try
142
            {
143
                this.Cursor = Cursors.WaitCursor;
144

    
145
                var AutoCADFiles = Directory.GetFiles(Program.AutoCADFolder, "*.dwg");
146
                var AVEVAFiles = Directory.GetFiles(Program.AVEVAPIDFolder, "*.dwg");
147

    
148
                MakeDocumentList(AutoCADFiles, AVEVAFiles);
149
            }
150
            finally
151
            {
152
                this.Cursor = Cursors.Default;
153
            }
154
        }
155

    
156
        /// <summary>
157
        /// 환경 설정 창을 띄운다.
158
        /// </summary>
159
        /// <param name="sender"></param>
160
        /// <param name="e"></param>
161
        private void RadButtonElementConfiguration_Click(object sender, EventArgs e)
162
        {
163
            using (var frm = new Forms.ExceptLayer())
164
            {
165
                if (DialogResult.OK == frm.ShowDialog(this))
166
                {
167
                    string ExceptLayers = string.Join(",", Forms.ExceptLayer.ExceptLayers.Select(x => x.Name));
168
                    Classes.ID2Helper.IniWriteValue(Program.IniFilePath, "Verification", "Except Layers", ExceptLayers);
169

    
170
                    string ExceptLayersVisible = string.Join(",", Forms.ExceptLayer.ExceptLayers.Select(x => x.Visible));
171
                    Classes.ID2Helper.IniWriteValue(Program.IniFilePath, "Verification", "Except Layers Visible", ExceptLayersVisible);
172
                }
173
            }
174
        }
175

    
176
        private void RadButtonElementCompare_Click(object sender, EventArgs e)
177
        {
178
            try
179
            {
180
                this.Cursor = Cursors.WaitCursor;
181

    
182
                var docs = this.radGridViewDocument.Rows.Where(x => (x.DataBoundItem is Document doc) && doc.Checked).
183
                    Select(x => (x.DataBoundItem as Document)).ToList();
184
                var verification = this.LayoutValidation.Controls[0] as Controls.Verification;
185
                verification.CompareDrawings(docs, true);
186
            }
187
            finally
188
            {
189
                this.Cursor = Cursors.Default;
190
            }
191
        }
192

    
193
        private void RadGridViewDocument_CellClick(object sender, GridViewCellEventArgs e)
194
        {
195
            if (e.ColumnIndex == 1 || e.ColumnIndex == 2) 
196
            {
197
                if (this.radGridViewDocument.SelectedRows.Any() && this.radGridViewDocument.SelectedRows[0].DataBoundItem is Document doc)
198
                {
199
                    this.Cursor = Cursors.WaitCursor;
200
                    try
201
                    {
202
                        var verification = this.LayoutValidation.Controls[0] as Controls.Verification;
203
                        verification.CompareDrawings(new List<Document>() { doc });
204
                    }
205
                    finally
206
                    {
207
                        this.Cursor = Cursors.Default;
208
                    }
209
                }
210
            }
211
        }
212

    
213
        private void RadGridViewDocument_ViewRowFormatting(object sender, RowFormattingEventArgs e)
214
        {
215
            if(e.RowElement is GridRowElement)
216
            {
217
                if (e.RowElement.RowInfo.DataBoundItem is Document doc)
218
                {
219
                    if (!doc.IsValid)
220
                    {
221
                        e.RowElement.ForeColor = Color.Gray;
222
                        e.RowElement.Font = Program.UnmatchedFont;
223
                    }
224
                    else
225
                    {
226
                        e.RowElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
227
                        e.RowElement.Font = Program.MatchedFont;
228
                    }
229
                }
230
            }
231
            else
232
            {
233
                e.RowElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
234
                e.RowElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local);
235
            }
236
        }
237

    
238
        private void RadGridViewDocument_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
239
        {
240
            radGridViewDocument.BestFitColumns();
241
        }
242

    
243
        private void RadBrowseEditorAVEVAFolder_ValueChanged(object sender, EventArgs e)
244
        {
245
            if(Directory.Exists(this.radBrowseEditorAVEVAFolder.Value))
246
            {
247
                Program.AVEVAPIDFolder = this.radBrowseEditorAVEVAFolder.Value;
248
                Classes.ID2Helper.IniWriteValue(Program.IniFilePath, "Path", "AVEVA P&ID Folder", Program.AVEVAPIDFolder);
249

    
250
                var AVEVAFiles = Directory.GetFiles(Program.AVEVAPIDFolder, "*.dwg");
251

    
252
                var AutoCADFiles = new List<string>();
253
                if (Directory.Exists(this.radBrowseEditorAutoCADFolder.Value))
254
                {
255
                    AutoCADFiles.AddRange(Directory.GetFiles(this.radBrowseEditorAutoCADFolder.Value, "*.dwg"));
256
                }
257

    
258
                MakeDocumentList(AutoCADFiles, AVEVAFiles);
259
            }
260
        }
261

    
262
        private void RadBrowseEditorAutoCADFolder_ValueChanged(object sender, EventArgs e)
263
        {
264
            if (Directory.Exists(this.radBrowseEditorAutoCADFolder.Value))
265
            {
266
                Program.AutoCADFolder = this.radBrowseEditorAutoCADFolder.Value;
267
                Classes.ID2Helper.IniWriteValue(Program.IniFilePath, "Path", "AutoCAD Folder", Program.AutoCADFolder);
268

    
269
                var AutoCADFiles = Directory.GetFiles(Program.AutoCADFolder, "*.dwg");
270

    
271
                var AVEVAFiles = new List<string>();
272
                if (Directory.Exists(this.radBrowseEditorAVEVAFolder.Value))
273
                {
274
                    AVEVAFiles.AddRange(Directory.GetFiles(this.radBrowseEditorAVEVAFolder.Value, "*.dwg"));
275
                }
276

    
277
                MakeDocumentList(AutoCADFiles, AVEVAFiles);
278
            }
279
        }
280

    
281
        private void MakeDocumentList(IList<string> AutoCADFiles, IList<string> AVEVAFiles)
282
        {
283
            radGridViewDocument.DataSource = null;
284

    
285
            Program.Documents.Clear();
286
            AutoCADFiles.ForAll(x => Program.Documents.Add(new Document(Path.GetFileNameWithoutExtension(x).ToUpper()) { AutoCADFileName = Path.GetFileNameWithoutExtension(x).ToUpper()}));
287

    
288
            var addings = new List<Document>();
289
            foreach(var file in AVEVAFiles)
290
            {
291
                string FileName = Path.GetFileNameWithoutExtension(file).ToUpper();
292
                var doc = Program.Documents.Find(x => x.AutoCADFileName == FileName);
293
                if(doc != null)
294
                {
295
                    doc.AVEVAFileName = FileName;
296
                }
297
                else
298
                {
299
                    addings.Add(new Document(FileName) { AVEVAFileName = FileName });
300
                }
301
            }
302

    
303
            addings.ForAll(x => Program.Documents.Add(x));
304

    
305
            radGridViewDocument.DataSource = Program.Documents;
306
        }
307
        #endregion
308

    
309
        private void RadDropDownList_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
310
        {
311
            if (sender is RadDropDownList ddl)
312
            {
313
                if (ddl.SelectedValue != null)
314
                {
315
                    if (string.IsNullOrEmpty(ddl.SelectedValue.ToString()))
316
                    {
317
                        ddl.BackColor = Color.White;
318
                        ddl.ForeColor = Color.Black;
319
                        ddl.Font = new Font("Segoe UI", 8.25F, FontStyle.Regular);
320
                    }
321
                    else
322
                    {
323
                        ddl.BackColor = Color.DarkSlateBlue;
324
                        ddl.ForeColor = Color.Yellow;
325
                        ddl.Font = new Font("Segoe UI", 8.25F, FontStyle.Bold);
326
                    }
327
                }
328
            }
329
        }
330

    
331
        private void RadTextBoxDocumentNo_KeyUp(object sender, KeyEventArgs e)
332
        {
333
            if (sender is RadTextBox txtBox)
334
            {
335
                if (txtBox.Text.Length > 0)
336
                {
337
                    txtBox.BackColor = Color.DarkSlateBlue;
338
                    txtBox.ForeColor = Color.Yellow;
339
                    txtBox.Font = new Font("Segoe UI", 8.25F, FontStyle.Bold);
340
                }
341
                else
342
                {
343
                    txtBox.BackColor = Color.White;
344
                    txtBox.ForeColor = Color.Black;
345
                    txtBox.Font = new Font("Segoe UI", 8.25F, FontStyle.Regular);
346
                }
347
            }
348
        }
349

    
350
        /*
351
        private void GetCheckedList()
352
        {
353
            RadGridView grid = this.radGridViewDocuments;
354

    
355
            //var checkers = grid.Rows.Where(x =>
356
            //{
357
            //    return x.Cells["Checked"].Value != null && Convert.ToBoolean(x.Cells["Checked"].Value);
358
            //}).Select(x => x.DataBoundItem as Documents).ToList();
359

    
360
            //var viewRows = new Queue<GridViewRowInfo>(this.radGridViewDocuments.MasterTemplate.DataView.Where(x => x.Cells["spq");
361
            var viewRows = grid.MasterTemplate.DataView;
362

    
363
            var checkers = viewRows.Where(x =>
364
            {
365
                return x.Cells["Checked"].Value != null && Convert.ToBoolean(x.Cells["Checked"].Value);
366
            }).ToList();
367

    
368
            var rows = new GridViewDataRowInfo[checkers.Count];
369
            checkers.CopyTo(rows, 0);
370

    
371
            if (rows.Length > 0)
372
            {
373
                grid.BeginUpdate();
374

    
375
                int nLoop = 0;
376
                rows.ForAll(x =>
377
                {
378
                    grid.Rows.Remove(rows[nLoop]);
379
                    nLoop++;
380
                });
381

    
382
                grid.EndUpdate();
383
            }
384

    
385

    
386
            //grid.Rows.re grid.Rows.ToList().Intersect(checkers)
387

    
388

    
389
            //RadMessageBox.Show($"{checkers.Count()}", Globals.Name, MessageBoxButtons.OK, RadMessageIcon.Info);
390
            //RadMessageBox.Show($"{this.documents.Count}", Globals.Name, MessageBoxButtons.OK, RadMessageIcon.Info);
391
            this.lbSelectAndTotal.Text = $"{grid.MasterTemplate.DataView.Count} / {this.TotalCount} (Selected / Total)";
392
        }
393
        */
394

    
395
        #region ColumnGroup
396
        private void InitColumnGroupsViewDefinition(RadGridView gridView)
397
        {
398
            ColumnGroupsViewDefinition columnGroupsView = new ColumnGroupsViewDefinition();
399

    
400
            List<string> chkColNames = new List<string>() { "Checked" };
401

    
402
            List<string> docLinkColNames = new List<string>() { "AutoCADLink", "ID2Connection", "PDFLink", "MarkupLink", "AVEVALink", "Compare" };
403
            List<string> docInfoColNames = new List<string>() { "RefProjectCode", "System", "SubSystemCode", "DocumentNo", "PersonInCharge", "Worker", "AVEVAPersonInCharge", "AVEVAWorker", "JobLevel", "RevisonNo" };
404
            List<string> rvToColNames = new List<string>() { "ToIsDiscussion", "ToRemarks", "ToCreator", "ToCapture" };
405
            List<string> rvFrColNames = new List<string>() { "FrReviewStatus", "FrRemarks", "FrCreator", "FrCapture" };
406
            List<string> wkID2ColNames = new List<string>() { "ID2StartDate", "ID2EndDate", "ID2Status", "ID2Issues", "ID2Capture", "ReplyModifications", "ReplyRequester" };
407
            List<string> wkAVEVAColNames = new List<string>() { "IsConvert", "AVEVAConvertDate", "AVEVAWorkDate", "AVEVAStatus", "AVEVAIssues" };
408
            List<string> valProdColNames = new List<string>() { "AVEVAReviewDate", "ProdReviewer", "ProdIsResult", "ProdRemarks" };
409
            List<string> valCntColNames = new List<string>() { "ClientReviewer", "ClientIsResult", "ClientRemarks" };
410
            List<string> dtColNames = new List<string>() { "DTIsGateWay", "DTIsImport", "DTIsRegSystem", "DTRemarks" };
411

    
412
            //체크
413
            GridViewColumnGroup chkColGrp = new GridViewColumnGroup("√") { IsPinned = true };
414
            GridViewColumnGroupRow chkColGrpRow = new GridViewColumnGroupRow();
415
            chkColGrpRow.ColumnNames.AddRange(chkColNames);
416
            chkColGrp.Rows.Add(chkColGrpRow);
417

    
418
            //도면
419
            GridViewColumnGroup docColGrp = new GridViewColumnGroup("도면 ");
420
            GridViewColumnGroup docLinkColGrp = new GridViewColumnGroup("프로그램 연동");
421
            GridViewColumnGroup docInfoColGrp = new GridViewColumnGroup("도면정보");
422

    
423
            GridViewColumnGroupRow docLinkColGrpRow = new GridViewColumnGroupRow();
424
            docLinkColGrpRow.ColumnNames.AddRange(docLinkColNames);
425

    
426
            GridViewColumnGroupRow docInfoColGrpRow = new GridViewColumnGroupRow();
427
            docInfoColGrpRow.ColumnNames.AddRange(docInfoColNames);
428

    
429
            docLinkColGrp.Rows.Add(docLinkColGrpRow);
430
            docColGrp.Groups.Add(docLinkColGrp);
431
            docInfoColGrp.Rows.Add(docInfoColGrpRow);
432
            docColGrp.Groups.Add(docInfoColGrp);
433

    
434
            //검토
435
            GridViewColumnGroup rvColGrp = new GridViewColumnGroup("검토", "review");
436
            GridViewColumnGroup rvToColGrp = new GridViewColumnGroup("도프텍");
437
            GridViewColumnGroup rvFrColGrp = new GridViewColumnGroup("삼성");
438

    
439
            GridViewColumnGroupRow rvToColGrpRow = new GridViewColumnGroupRow();
440
            rvToColGrpRow.ColumnNames.AddRange(rvToColNames);
441

    
442
            GridViewColumnGroupRow rvFrColGrpRow = new GridViewColumnGroupRow();
443
            rvFrColGrpRow.ColumnNames.AddRange(rvFrColNames);
444

    
445
            rvToColGrp.Rows.Add(rvToColGrpRow);
446
            rvFrColGrp.Rows.Add(rvFrColGrpRow);
447

    
448
            rvColGrp.Groups.Add(rvToColGrp);
449
            rvColGrp.Groups.Add(rvFrColGrp);
450

    
451
            //작업
452
            GridViewColumnGroup wkColGrp = new GridViewColumnGroup("작업", "work");
453
            GridViewColumnGroup wkID2ColGrp = new GridViewColumnGroup("ID2");
454
            GridViewColumnGroup wkAVEVAColGrp = new GridViewColumnGroup("AVEVA");
455

    
456
            GridViewColumnGroupRow wkID2ColGrpRow = new GridViewColumnGroupRow();
457
            wkID2ColGrpRow.ColumnNames.AddRange(wkID2ColNames);
458

    
459
            GridViewColumnGroupRow wkAVEVAColGrpRow = new GridViewColumnGroupRow();
460
            wkAVEVAColGrpRow.ColumnNames.AddRange(wkAVEVAColNames);
461

    
462
            wkID2ColGrp.Rows.Add(wkID2ColGrpRow);
463
            wkAVEVAColGrp.Rows.Add(wkAVEVAColGrpRow);
464

    
465
            wkColGrp.Groups.Add(wkID2ColGrp);
466
            wkColGrp.Groups.Add(wkAVEVAColGrp);
467

    
468
            //Validation
469
            GridViewColumnGroup valColGrp = new GridViewColumnGroup("Validation", "validation");
470
            GridViewColumnGroup valProdColGrp = new GridViewColumnGroup("도프텍");
471
            GridViewColumnGroup valCntColGrp = new GridViewColumnGroup("삼성전자");
472

    
473
            GridViewColumnGroupRow valProdColGrpRow = new GridViewColumnGroupRow();
474
            valProdColGrpRow.ColumnNames.AddRange(valProdColNames);
475

    
476
            GridViewColumnGroupRow valCntColGrpRow = new GridViewColumnGroupRow();
477
            valCntColGrpRow.ColumnNames.AddRange(valCntColNames);
478

    
479
            valProdColGrp.Rows.Add(valProdColGrpRow);
480
            valCntColGrp.Rows.Add(valCntColGrpRow);
481

    
482
            valColGrp.Groups.Add(valProdColGrp);
483
            valColGrp.Groups.Add(valCntColGrp);
484

    
485
            //AVEVA Net
486
            GridViewColumnGroup dtColGrp = new GridViewColumnGroup("AVEVA Net\n(Digital Twin)", "avevanet");
487

    
488
            GridViewColumnGroupRow dtColGrpRow = new GridViewColumnGroupRow();
489
            dtColGrpRow.ColumnNames.AddRange(dtColNames);
490

    
491
            dtColGrp.Rows.Add(dtColGrpRow);
492

    
493
            //Group 추가
494
            columnGroupsView.ColumnGroups.Add(chkColGrp);
495
            columnGroupsView.ColumnGroups.Add(docColGrp);
496
            columnGroupsView.ColumnGroups.Add(wkColGrp);
497
            columnGroupsView.ColumnGroups.Add(rvColGrp);
498
            columnGroupsView.ColumnGroups.Add(valColGrp);
499
            columnGroupsView.ColumnGroups.Add(dtColGrp);
500

    
501
            gridView.MasterTemplate.ViewDefinition = columnGroupsView;
502
        }
503
        #endregion
504
    }
505
}
506

    
507
public class FilterColumn
508
{
509
    public string Name { get; set; }
510
    public string FieldName { get; set; }
511
    public bool IsSelect { get; set; }
512
}
클립보드 이미지 추가 (최대 크기: 500 MB)