프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Compare / Main.cs @ 4b369ce1

이력 | 보기 | 이력해설 | 다운로드 (20.9 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
//#if DEBUG
36
//        Telerik.WinControls.RadControlSpy.RadControlSpyForm radControlSpyForm = new Telerik.WinControls.RadControlSpy.RadControlSpyForm();
37
//#endif
38
        private readonly Color _SummaryColor = Color.FromArgb(255, 108, 55);
39

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

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

    
49
            if (!Directory.Exists(appDataPath))
50
            {
51
                Directory.CreateDirectory(appDataPath);
52
            }
53

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

    
63
            this.Initialize();
64
        }
65

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

    
86
        #region Init, Load
87
        private void Initialize()
88
        {
89
            this.ID2ManagerRadRibbonBar.Expanded = false;
90
        }
91

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

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

    
114
                this.radButtonElementRefreshCommand.Click += RadButtonElementRefreshCommand_Click;
115

    
116
                Program.AutoCADFolder = Classes.ID2Helper.IniReadValue(Program.IniFilePath, "Path", "AutoCAD Folder");
117
                if (!string.IsNullOrEmpty(Program.AutoCADFolder)) this.radBrowseEditorAutoCADFolder.Value = Program.AutoCADFolder;
118

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

    
128
            base.OnLoad(e);
129
        }
130

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

    
142
                var AutoCADFiles = Directory.GetFiles(Program.AutoCADFolder, "*.dwg");
143
                var AVEVAFiles = Directory.GetFiles(Program.AVEVAPIDFolder, "*.dwg");
144

    
145
                MakeDocumentList(AutoCADFiles, AVEVAFiles);
146
            }
147
            finally
148
            {
149
                this.Cursor = Cursors.Default;
150
            }
151
        }
152

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

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

    
173
        private void RadButtonElementCompare_Click(object sender, EventArgs e)
174
        {
175
            try
176
            {
177
                this.Cursor = Cursors.WaitCursor;
178

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

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

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

    
235
        private void RadGridViewDocument_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
236
        {
237
            radGridViewDocument.BestFitColumns();
238
        }
239

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

    
247
                var AVEVAFiles = Directory.GetFiles(Program.AVEVAPIDFolder, "*.dwg");
248

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

    
255
                MakeDocumentList(AutoCADFiles, AVEVAFiles);
256
            }
257
        }
258

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

    
266
                var AutoCADFiles = Directory.GetFiles(Program.AutoCADFolder, "*.dwg");
267

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

    
274
                MakeDocumentList(AutoCADFiles, AVEVAFiles);
275
            }
276
        }
277

    
278
        private void MakeDocumentList(IList<string> AutoCADFiles, IList<string> AVEVAFiles)
279
        {
280
            radGridViewDocument.DataSource = null;
281

    
282
            Program.Documents.Clear();
283
            AutoCADFiles.ForAll(x => Program.Documents.Add(new Document(Path.GetFileNameWithoutExtension(x).ToUpper()) { AutoCADFileName = Path.GetFileNameWithoutExtension(x).ToUpper()}));
284

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

    
300
            addings.ForAll(x => Program.Documents.Add(x));
301

    
302
            radGridViewDocument.DataSource = Program.Documents;
303
        }
304
        #endregion
305

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

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

    
347
        /*
348
        private void GetCheckedList()
349
        {
350
            RadGridView grid = this.radGridViewDocuments;
351

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

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

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

    
365
            var rows = new GridViewDataRowInfo[checkers.Count];
366
            checkers.CopyTo(rows, 0);
367

    
368
            if (rows.Length > 0)
369
            {
370
                grid.BeginUpdate();
371

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

    
379
                grid.EndUpdate();
380
            }
381

    
382

    
383
            //grid.Rows.re grid.Rows.ToList().Intersect(checkers)
384

    
385

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

    
392
        #region ColumnGroup
393
        private void InitColumnGroupsViewDefinition(RadGridView gridView)
394
        {
395
            ColumnGroupsViewDefinition columnGroupsView = new ColumnGroupsViewDefinition();
396

    
397
            List<string> chkColNames = new List<string>() { "Checked" };
398

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

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

    
415
            //도면
416
            GridViewColumnGroup docColGrp = new GridViewColumnGroup("도면 ");
417
            GridViewColumnGroup docLinkColGrp = new GridViewColumnGroup("프로그램 연동");
418
            GridViewColumnGroup docInfoColGrp = new GridViewColumnGroup("도면정보");
419

    
420
            GridViewColumnGroupRow docLinkColGrpRow = new GridViewColumnGroupRow();
421
            docLinkColGrpRow.ColumnNames.AddRange(docLinkColNames);
422

    
423
            GridViewColumnGroupRow docInfoColGrpRow = new GridViewColumnGroupRow();
424
            docInfoColGrpRow.ColumnNames.AddRange(docInfoColNames);
425

    
426
            docLinkColGrp.Rows.Add(docLinkColGrpRow);
427
            docColGrp.Groups.Add(docLinkColGrp);
428
            docInfoColGrp.Rows.Add(docInfoColGrpRow);
429
            docColGrp.Groups.Add(docInfoColGrp);
430

    
431
            //검토
432
            GridViewColumnGroup rvColGrp = new GridViewColumnGroup("검토", "review");
433
            GridViewColumnGroup rvToColGrp = new GridViewColumnGroup("도프텍");
434
            GridViewColumnGroup rvFrColGrp = new GridViewColumnGroup("삼성");
435

    
436
            GridViewColumnGroupRow rvToColGrpRow = new GridViewColumnGroupRow();
437
            rvToColGrpRow.ColumnNames.AddRange(rvToColNames);
438

    
439
            GridViewColumnGroupRow rvFrColGrpRow = new GridViewColumnGroupRow();
440
            rvFrColGrpRow.ColumnNames.AddRange(rvFrColNames);
441

    
442
            rvToColGrp.Rows.Add(rvToColGrpRow);
443
            rvFrColGrp.Rows.Add(rvFrColGrpRow);
444

    
445
            rvColGrp.Groups.Add(rvToColGrp);
446
            rvColGrp.Groups.Add(rvFrColGrp);
447

    
448
            //작업
449
            GridViewColumnGroup wkColGrp = new GridViewColumnGroup("작업", "work");
450
            GridViewColumnGroup wkID2ColGrp = new GridViewColumnGroup("ID2");
451
            GridViewColumnGroup wkAVEVAColGrp = new GridViewColumnGroup("AVEVA");
452

    
453
            GridViewColumnGroupRow wkID2ColGrpRow = new GridViewColumnGroupRow();
454
            wkID2ColGrpRow.ColumnNames.AddRange(wkID2ColNames);
455

    
456
            GridViewColumnGroupRow wkAVEVAColGrpRow = new GridViewColumnGroupRow();
457
            wkAVEVAColGrpRow.ColumnNames.AddRange(wkAVEVAColNames);
458

    
459
            wkID2ColGrp.Rows.Add(wkID2ColGrpRow);
460
            wkAVEVAColGrp.Rows.Add(wkAVEVAColGrpRow);
461

    
462
            wkColGrp.Groups.Add(wkID2ColGrp);
463
            wkColGrp.Groups.Add(wkAVEVAColGrp);
464

    
465
            //Validation
466
            GridViewColumnGroup valColGrp = new GridViewColumnGroup("Validation", "validation");
467
            GridViewColumnGroup valProdColGrp = new GridViewColumnGroup("도프텍");
468
            GridViewColumnGroup valCntColGrp = new GridViewColumnGroup("삼성전자");
469

    
470
            GridViewColumnGroupRow valProdColGrpRow = new GridViewColumnGroupRow();
471
            valProdColGrpRow.ColumnNames.AddRange(valProdColNames);
472

    
473
            GridViewColumnGroupRow valCntColGrpRow = new GridViewColumnGroupRow();
474
            valCntColGrpRow.ColumnNames.AddRange(valCntColNames);
475

    
476
            valProdColGrp.Rows.Add(valProdColGrpRow);
477
            valCntColGrp.Rows.Add(valCntColGrpRow);
478

    
479
            valColGrp.Groups.Add(valProdColGrp);
480
            valColGrp.Groups.Add(valCntColGrp);
481

    
482
            //AVEVA Net
483
            GridViewColumnGroup dtColGrp = new GridViewColumnGroup("AVEVA Net\n(Digital Twin)", "avevanet");
484

    
485
            GridViewColumnGroupRow dtColGrpRow = new GridViewColumnGroupRow();
486
            dtColGrpRow.ColumnNames.AddRange(dtColNames);
487

    
488
            dtColGrp.Rows.Add(dtColGrpRow);
489

    
490
            //Group 추가
491
            columnGroupsView.ColumnGroups.Add(chkColGrp);
492
            columnGroupsView.ColumnGroups.Add(docColGrp);
493
            columnGroupsView.ColumnGroups.Add(wkColGrp);
494
            columnGroupsView.ColumnGroups.Add(rvColGrp);
495
            columnGroupsView.ColumnGroups.Add(valColGrp);
496
            columnGroupsView.ColumnGroups.Add(dtColGrp);
497

    
498
            gridView.MasterTemplate.ViewDefinition = columnGroupsView;
499
        }
500
        #endregion
501
    }
502
}
503

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