프로젝트

일반

사용자정보

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

hytos / ID2.Manager / ID2.Manager / Main.cs @ 3dc5cbb3

이력 | 보기 | 이력해설 | 다운로드 (40.2 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

    
14
using ID2.Manager.Common;
15
using ID2.Manager.Classes;
16
using ID2.Manager.Data.Models;
17
using ID2.Manager.Controller.Controllers;
18
using static ID2.Manager.Data.Models.Documents;
19

    
20
using Telerik.WinControls;
21
using Telerik.WinControls.UI;
22
using Telerik.WinControls.Data;
23

    
24
using GemBox.Spreadsheet;
25

    
26
using Newtonsoft.Json;
27

    
28
namespace ID2.Manager
29
{
30
    public partial class Main : RadRibbonForm
31
    {
32
        readonly Informations informations = Informations.Instance;
33

    
34
        List<Documents> documents = new List<Documents>();
35
        List<Documents> orgDocuments = null;
36

    
37
        private readonly Color _SummaryColor = Color.FromArgb(255, 108, 55);
38

    
39
        public Main()
40
        {
41
            InitializeComponent();
42

    
43
            this.Initialize();
44

    
45
            SpreadsheetInfo.SetLicense(Properties.Settings.Default.GemBoxLicense);
46

    
47
            this.Load += Main_Load;
48
            this.radButtonElementSave.Click += RadButtonElementSave_Click;
49
            this.radButtonElementExcelImport.Click += RadButtonElementExcelImport_Click;
50
            this.radButtonElementExcelExport.Click += RadButtonElementExcelExport_Click;
51

    
52
            this.radCheckBox1.CheckStateChanged += RadCheckBox_CheckStateChanged;
53
            this.radCheckBox2.CheckStateChanged += RadCheckBox_CheckStateChanged;
54
            this.radCheckBox3.CheckStateChanged += RadCheckBox_CheckStateChanged;
55
            this.radCheckBox4.CheckStateChanged += RadCheckBox_CheckStateChanged;
56

    
57
            this.radButtonSearch.Click += RadButtonSearch_Click;
58
            this.radButtonMapping.Click += RadButtonMapping_Click;
59

    
60
            this.radGridViewDocuments.ViewCellFormatting += RadGridViewDocuments_ViewCellFormatting;
61
            this.radGridViewDocuments.CellBeginEdit += RadGridViewDocuments_CellBeginEdit;
62
            this.radGridViewDocuments.CommandCellClick += RadGridViewDocuments_CommandCellClick;
63

    
64
            this.radGridViewDocuments.MasterView.TableHeaderRow.MinHeight = 36;
65
            this.radGridViewDocuments.TableElement.RowHeaderColumnWidth = 36;
66

    
67
            this.InitColumnGroupsViewDefinition(this.radGridViewDocuments);
68
        }
69

    
70
        #region Init, Load
71
        private void Initialize()
72
        {
73
            IEnumerable<UserInfo> allUserList = new UserController().GetAllUserInfo();
74
            allUserList.ToList().ForEach(x => informations.UserList.Add(x));
75
        }
76

    
77
        private void Main_Load(object sender, EventArgs e)
78
        {
79
            this.radGridViewDocuments.DataSource = this.documents;
80
        }
81
        #endregion
82

    
83
        #region Document List 조회
84
        public void GetDocList()
85
        {
86
            this.documents = new DocumentController().GetAllDocuments().ToList();
87
            this.orgDocuments = JsonConvert.DeserializeObject<List<Documents>>(JsonConvert.SerializeObject(this.documents));
88

    
89
            GridViewComboBoxColumn ColUserList = this.radGridViewDocuments.Columns["PersonInCharge"] as GridViewComboBoxColumn;
90
            ColUserList.DataSource = informations.UserList;
91
            ColUserList.DisplayMember = "Name";
92
            ColUserList.ValueMember = "ID";
93

    
94
            //Data
95
            if (this.radGridViewDocuments.DataSource != null)
96
                this.radGridViewDocuments.DataSource = null;
97
            this.radGridViewDocuments.DataSource = this.documents;
98

    
99
            if (this.radGridViewDocuments.SummaryRowsTop != null)
100
                this.radGridViewDocuments.SummaryRowsTop.Clear();
101

    
102
            string totalCount = String.Format("{0:#,###}", this.documents.Count());
103

    
104
            //Summary
105
            GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem()
106
                {
107
                    new GridViewSummaryItem("DocumentNo", "{0:#,###} / " + totalCount, GridAggregateFunction.Count)
108
                };
109
            this.radGridViewDocuments.SummaryRowsTop.Add(summaryRowItem);
110
            this.radGridViewDocuments.MasterView.SummaryRows[0].PinPosition = PinnedRowPosition.Top;
111
            this.radGridViewDocuments.MasterTemplate.BottomPinnedRowsMode = GridViewBottomPinnedRowsMode.Fixed;
112
        }
113
        #endregion
114

    
115
        #region button, checkbox event
116
        private void RadCheckBox_CheckStateChanged(object sender, EventArgs e)
117
        {
118
            if (sender is RadCheckBox)
119
            {
120
                RadCheckBox checkBox = sender as RadCheckBox;
121

    
122
                if (checkBox.Tag != null)
123
                {
124
                    ColumnGroupsViewDefinition columnGroupsView =  this.radGridViewDocuments.MasterTemplate.ViewDefinition as ColumnGroupsViewDefinition;
125
                    GridViewColumnGroup colGroup = columnGroupsView.GetAllGroups().Where(x => x.Name.Equals(checkBox.Tag.ToString())).FirstOrDefault();
126
                    if (colGroup != null)
127
                        colGroup.IsVisible = checkBox.Checked;
128
                }
129
            }
130

    
131
            //ColumnGroupsViewDefinition columnGroupsView = this.radGridViewDocuments.MasterTemplate.ViewDefinition = columnGroupsView;
132
        }
133

    
134
        private void RadButtonSearch_Click(object sender, EventArgs e)
135
        {
136
            this.GetDocList();
137
        }
138

    
139
        private void RadButtonMapping_Click(object sender, EventArgs e)
140
        {
141
            
142
        }
143
        #endregion
144

    
145
        #region grid event
146
        private void RadGridViewDocuments_CommandCellClick(object sender, GridViewCellEventArgs e)
147
        {
148
            if (e.Row is GridViewNewRowInfo)
149
            {
150
                
151
            }
152
            else
153
            {
154
                switch (e.Column.Name)
155
                {
156
                    case "AutoCADLink":
157
                        Controls.AutoCADViewer viewer = null;
158
                        foreach (var control in this.tableLayoutPanelRight.Controls)
159
                        {
160
                            if (control is Controls.AutoCADViewer _viewer)
161
                            {
162
                                viewer = _viewer;
163
                                break;
164
                            }
165
                        }
166

    
167
                        if (viewer == null)
168
                        {
169
                            viewer = new Controls.AutoCADViewer() { Dock = DockStyle.Fill };
170
                            this.tableLayoutPanelRight.Controls.Add(viewer);
171
                        }
172
                        else
173
                        {
174
                            viewer.Visible = true;
175
                        }
176
                        break;
177
                    case "PDFLink":
178
                        MessageBox.Show($"{e.Column.Name} 실행");
179
                        break;
180
                    case "MarkupLink":
181
                        MessageBox.Show($"{e.Column.Name} 실행");
182
                        break;
183
                    case "AVEVALink":
184
                    case "AVEVAConnection":
185
                        MessageBox.Show($"{e.Column.Name} 실행");
186
                        break;
187
                    case "ReviewFileName"://일단주석
188
                        MessageBox.Show($"{e.Column.Name} 실행");
189
                        break;
190
                    case "SystemLink":
191
                        MessageBox.Show($"{e.Column.Name} 실행");
192
                        break;
193
                    case "ToCapturePath":
194
                    case "FrCapturePath":
195
                        break;
196
                    case "ID2Connection":
197
                        MessageBox.Show($"{e.Column.Name} 실행");
198
                        break;
199
                }
200
            }
201
        }
202

    
203
        private void RadGridViewDocuments_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
204
        {
205
            if (e.ActiveEditor is RadDropDownListEditor)
206
            {
207
                switch (e.Column.Name)
208
                {
209
                    case "JobLevel":
210
                        GridViewComboBoxColumn ColJobLevel = this.radGridViewDocuments.Columns[e.Column.Name] as GridViewComboBoxColumn;
211
                        ColJobLevel.DataSource = informations.JobLevel;
212
                        break;
213
                    case "IsTypical":
214
                    case "ToIsDiscussion":
215
                    case "ToIsMarkup":
216
                    case "FrIsMarkup":
217
                    case "IsID2Work":
218
                    case "DTIsGateWay":
219
                    case "DTIsImport":
220
                    case "DTIsRegSystem":
221
                        GridViewComboBoxColumn ColYesNo = this.radGridViewDocuments.Columns[e.Column.Name] as GridViewComboBoxColumn;
222
                        ColYesNo.DataSource = (new string[] { string.Empty }).Union<string>(informations.IsYesNo);
223
                        break;
224
                    case "ID2Status":
225
                    case "AVEVAStatus":
226
                        GridViewComboBoxColumn ColJobStatus = this.radGridViewDocuments.Columns[e.Column.Name] as GridViewComboBoxColumn;
227
                        ColJobStatus.DataSource = (new string[] { string.Empty }).Union<string>(informations.JobStatus);
228
                        break;
229
                    case "FrReviewStatus"://삼성의견status
230
                        GridViewComboBoxColumn ColClientStatus = this.radGridViewDocuments.Columns[e.Column.Name] as GridViewComboBoxColumn;
231
                        ColClientStatus.DataSource = (new string[] { string.Empty }).Union<string>(informations.ClientStatus);
232
                        break;
233
                    case "ProdIsResult":
234
                    case "ClientIsResult":
235
                        GridViewComboBoxColumn ColResult = this.radGridViewDocuments.Columns[e.Column.Name] as GridViewComboBoxColumn;
236
                        ColResult.DataSource = (new string[] { string.Empty }).Union<string>(informations.ValidationResult);
237
                        break;
238
                }
239
            }
240
        }
241

    
242
        private void RadGridViewDocuments_ViewCellFormatting(object sender, CellFormattingEventArgs e)
243
        {
244
            if (e.Row is GridViewDataRowInfo)
245
            {
246
                if (e.CellElement is GridRowHeaderCellElement)
247
                {
248
                    if (e.CellElement.RowIndex > -1)
249
                        e.CellElement.Text = (e.CellElement.RowIndex + 1).ToString();
250
                }
251
                else
252
                {
253
                    var result = e.Row.DataBoundItem as Documents;
254
                    if (result != null || e.Row is GridViewNewRowInfo)
255
                    {
256
                        switch (e.CellElement.ColumnInfo.Name)
257
                        {
258
                            case "AutoCADLink":
259
                            case "PDFLink":
260
                            case "MarkupLink":
261
                            case "AVEVALink":
262
                            case "AVEVAConnection":
263
                            case "ReviewFileName"://일단주석
264
                            case "SystemLink":
265
                            case "ToCapturePath":
266
                            case "FrCapturePath":
267
                            case "ID2Connection":
268
                                this.GetCommandColBtnElement(e.CellElement.Children[0], e.CellElement.ColumnInfo.Name);
269
                                break;
270
                        }
271
                    }
272
                    else
273
                    {
274

    
275
                    }
276
                }
277
            }
278
            else if (e.Row is GridViewSummaryRowInfo)
279
            {
280
                if (e.CellElement is GridRowHeaderCellElement)
281
                {
282
                    e.CellElement.Text = "Count";
283
                }
284
                else if (e.CellElement is GridSummaryCellElement)
285
                {
286
                    e.CellElement.ForeColor = this._SummaryColor;
287
                    e.CellElement.TextAlignment = ContentAlignment.BottomRight;
288
                    e.CellElement.Font = new Font(e.CellElement.Font, FontStyle.Bold);
289
                }
290
                else
291
                {
292

    
293
                }
294
            }
295
            else
296
            {
297

    
298
            }
299
        }
300

    
301
        private RadButtonElement GetCommandColBtnElement(RadElement elem, string colName)
302
        {
303
            RadButtonElement btnElem = null;
304
            Bitmap bitmap = null; ;
305

    
306
            switch (colName)
307
            {
308
                case "AutoCADLink":
309
                    bitmap = new Bitmap(Properties.Resources.cad18);
310
                    break;
311
                case "PDFLink":
312
                    bitmap = new Bitmap(Properties.Resources.pdf18);
313
                    break;
314
                case "MarkupLink":
315
                    bitmap = new Bitmap(Properties.Resources.link18_green);
316
                    break;
317
                case "AVEVALink":
318
                case "AVEVAConnection":
319
                    bitmap = new Bitmap(Properties.Resources.link18_blue);
320
                    break;
321
                case "ReviewFileName"://일단주석
322
                    bitmap = new Bitmap(Properties.Resources.pdf18);
323
                    break;
324
                case "SystemLink":
325
                    bitmap = new Bitmap(Properties.Resources.link18_yellow);
326
                    break;
327
                case "ToCapturePath":
328
                case "FrCapturePath":
329
                    bitmap = new Bitmap(Properties.Resources.files18);
330
                    break;
331
                case "ID2Connection":
332
                    bitmap = new Bitmap(Properties.Resources.link18_purple);
333
                    break;
334
            }
335

    
336
            switch (colName)
337
            {
338
                case "AutoCADLink":
339
                case "PDFLink":
340
                case "MarkupLink":
341
                case "AVEVALink":
342
                case "AVEVAConnection":
343
                case "ReviewFileName"://일단주석
344
                case "SystemLink":
345
                case "ToCapturePath":
346
                case "FrCapturePath":
347
                case "ID2Connection":
348
                    btnElem = (RadButtonElement)elem;
349
                    btnElem.Margin = new Padding(0);
350
                    btnElem.Padding = new Padding(0);
351
                    btnElem.BorderElement.Opacity = 0;
352
                    btnElem.Alignment = ContentAlignment.MiddleCenter;
353
                    btnElem.DisplayStyle = DisplayStyle.Image;
354
                    btnElem.Image = bitmap;
355
                    btnElem.ImageAlignment = ContentAlignment.MiddleCenter;
356
                    btnElem.MaxSize = bitmap.Size;
357
                    break;
358
            }
359

    
360
            return btnElem;
361
        }
362
        #endregion
363

    
364
        #region Excel
365
        private void RadButtonElementExcelImport_Click(object sender, EventArgs e)
366
        {
367
            using (OpenFileDialog ofd = new OpenFileDialog()
368
            {
369
                Filter = "Excel files (*.xlsx)|*.xlsx",
370
                Title = "Open an Excel File",
371
                RestoreDirectory = true
372
            })
373
            {
374
                if (ofd.ShowDialog() == DialogResult.OK)
375
                {
376
                    //Error Message
377
                    StringBuilder sbErrMsg = new StringBuilder();
378

    
379
                    var exFile = ExcelFile.Load(ofd.FileName);
380
                    var ws = exFile.Worksheets[0];
381

    
382
                    int rowCount = ws.Rows.Count;
383
                    int columnCount = ws.CalculateMaxUsedColumns();
384
                    int exRow = 8;
385

    
386
                    #region Excel 유효성검사
387

    
388
                    //Excel 포멧체크
389
                    if (rowCount <= 10 || columnCount != 45)
390
                    {
391
                        RadMessageBox.Show("Please, check the excel.\n", "Information", MessageBoxButtons.OK, RadMessageIcon.Info);
392
                        return;
393
                    }
394

    
395
                    #region 엑셀 필수값 체크(도면 : 이름,담당자, 난이도, Typical)
396
                    ws.Rows.SelectMany(row => row.AllocatedCells)
397
                           .Where(col => col.Column.Index > 5 && col.Column.Index < 10 && col.Row.Index > exRow && col.Value == null)
398
                           .ToList()
399
                           .ForEach(p => sbErrMsg.Append(", " + p.Column.Name + p.Row.Name));
400

    
401
                    if (sbErrMsg.Length > 0)
402
                    {
403
                        string errMsg = sbErrMsg.ToString().Substring(2);
404
                        if (errMsg.Length > 100)
405
                        {
406
                            errMsg = $"{errMsg.Substring(0, 100)}...";
407
                        }
408

    
409
                        RadMessageBox.Show($"Please, check null value in excel.\n{errMsg}", "Information", MessageBoxButtons.OK, RadMessageIcon.Info);
410
                        return;
411
                    }
412
                    #endregion
413

    
414
                    #region 엑셀 도명명 중복 값 체크
415
                    ws.Rows.SelectMany(row => row.AllocatedCells)
416
                                                 .Where(col => col.Column.Index == 6 && col.Row.Index > exRow)
417
                                                 .GroupBy(g => g.Row.Index)
418
                                                 .Select(p => new {
419
                                                     rowIndex = p.Key,
420
                                                     docNo = p.Select(x => x.Value.ToString()).FirstOrDefault()
421
                                                 })
422
                                                 .GroupBy(g => g.docNo)
423
                                                 .Where(p => p.Count() > 1)
424
                                                 .Select(p => p.Select(x => (x.rowIndex + 1).ToString())
425
                                                                                            .Aggregate((x, y) => x.ToString() + "," + y.ToString())
426
                                                                                            .ToString())
427
                                                 .ToList().ForEach(p => sbErrMsg.Append("\n" + p.ToString()));
428
                    if (sbErrMsg.Length > 0)
429
                    {
430
                        sbErrMsg.Insert(0, "\n중복 된 도면명 Excel row : ");
431
                        string errMsg = sbErrMsg.ToString();
432
                        if (errMsg.Length > 100)
433
                        {
434
                            errMsg = $"{errMsg.Substring(0, 100)}...";
435
                        }
436

    
437
                        RadMessageBox.Show($"Please, check the duplicate value in excel.\n{errMsg}", "Information", MessageBoxButtons.OK, RadMessageIcon.Info);
438
                        return;
439
                    }
440
                    #endregion
441

    
442
                    #endregion
443

    
444
                    List<Documents> appendDocuments = new List<Documents>();
445

    
446
                    ws.Rows.Where(row => row.Index > exRow)
447
                           .ToList()
448
                           .ForEach(p => appendDocuments.Add(new Documents()
449
                           {
450
                               //UID = string.Empty,
451
                               //Type = this.radTextBoxInsulationType.Text,
452
                               //TempFrom = ws.Rows[exRow].Cells[p.Column.Index].Value == null ? 0 : Convert.ToSingle(ws.Rows[exRow].Cells[p.Column.Index].Value),
453
                               //TempTo = ws.Rows[exRow + 2].Cells[p.Column.Index].Value == null ? 0 : Convert.ToSingle(ws.Rows[exRow + 2].Cells[p.Column.Index].Value),
454
                               //NPS = ws.Rows[p.Row.Index].Cells[0].Value == null ? 0 : Convert.ToSingle(ws.Rows[p.Row.Index].Cells[0].Value),
455
                               //Thickness = p.Value == null ? 0 : Convert.ToSingle(p.Value)
456

    
457
                               Place = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
458
                               DocumentNo = ws.Rows[p.Index].Cells[6].Value == null ? string.Empty : ws.Rows[p.Index].Cells[6].Value.ToString(),
459
                               PersonInCharge = ws.Rows[p.Index].Cells[7].Value == null ? string.Empty : ws.Rows[p.Index].Cells[7].Value.ToString(),
460
                               JobLevel = ws.Rows[p.Index].Cells[8].Value == null ? string.Empty : ws.Rows[p.Index].Cells[8].Value.ToString(),
461
                               IsTypical = ws.Rows[p.Index].Cells[9].Value == null ? string.Empty : ws.Rows[p.Index].Cells[9].Value.ToString(),
462
                               RevisonNo = ws.Rows[p.Index].Cells[10].Value == null ? string.Empty : ws.Rows[p.Index].Cells[10].Value.ToString(),
463
                               ToIsDiscussion = ws.Rows[p.Index].Cells[11].Value == null ? string.Empty : ws.Rows[p.Index].Cells[11].Value.ToString(),
464
                               ToRemarks = ws.Rows[p.Index].Cells[12].Value == null ? string.Empty : ws.Rows[p.Index].Cells[12].Value.ToString(),
465
                               ToCreator = ws.Rows[p.Index].Cells[13].Value == null ? string.Empty : ws.Rows[p.Index].Cells[13].Value.ToString(),
466
                               //ToCapturePath = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
467
                               //ToIsMarkup = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
468
                               FrReviewStatus = ws.Rows[p.Index].Cells[16].Value == null ? string.Empty : ws.Rows[p.Index].Cells[16].Value.ToString(),
469
                               FrRemarks = ws.Rows[p.Index].Cells[17].Value == null ? string.Empty : ws.Rows[p.Index].Cells[17].Value.ToString(),
470
                               FrCreator = ws.Rows[p.Index].Cells[18].Value == null ? string.Empty : ws.Rows[p.Index].Cells[18].Value.ToString(),
471
                               //FrCapturePath = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
472
                               //FrIsMarkup = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
473
                               IsID2Work = ws.Rows[p.Index].Cells[21].Value == null ? string.Empty : ws.Rows[p.Index].Cells[21].Value.ToString(),
474
                               //ID2Connection = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
475
                               //ID2StartDate = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
476
                               //ID2EndDate = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
477
                               //ID2JobTime = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
478
                               ID2Status = ws.Rows[p.Index].Cells[26].Value == null ? string.Empty : ws.Rows[p.Index].Cells[26].Value.ToString(),
479
                               ID2Issues = ws.Rows[p.Index].Cells[27].Value == null ? string.Empty : ws.Rows[p.Index].Cells[27].Value.ToString(),
480
                               //AVEVAConnection = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
481
                               //AVEVAConvertDate = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
482
                               //AVEVAReviewDate = ws.Rows[p.Index].Cells[5].Value == null ? string.Empty : ws.Rows[p.Index].Cells[5].Value.ToString(),
483
                               AVEVAStatus = ws.Rows[p.Index].Cells[31].Value == null ? string.Empty : ws.Rows[p.Index].Cells[31].Value.ToString(),
484
                               AVEVAIssues = ws.Rows[p.Index].Cells[32].Value == null ? string.Empty : ws.Rows[p.Index].Cells[32].Value.ToString(),
485
                               ProdReviewer = ws.Rows[p.Index].Cells[35].Value == null ? string.Empty : ws.Rows[p.Index].Cells[35].Value.ToString(),
486
                               ProdIsResult = ws.Rows[p.Index].Cells[36].Value == null ? string.Empty : ws.Rows[p.Index].Cells[36].Value.ToString(),
487
                               ProdRemarks = ws.Rows[p.Index].Cells[37].Value == null ? string.Empty : ws.Rows[p.Index].Cells[37].Value.ToString(),
488
                               ClientReviewer = ws.Rows[p.Index].Cells[38].Value == null ? string.Empty : ws.Rows[p.Index].Cells[38].Value.ToString(),
489
                               ClientIsResult = ws.Rows[p.Index].Cells[39].Value == null ? string.Empty : ws.Rows[p.Index].Cells[39].Value.ToString(),
490
                               ClientRemarks = ws.Rows[p.Index].Cells[40].Value == null ? string.Empty : ws.Rows[p.Index].Cells[40].Value.ToString(),
491
                               DTIsGateWay = ws.Rows[p.Index].Cells[41].Value == null ? string.Empty : ws.Rows[p.Index].Cells[41].Value.ToString(),
492
                               DTIsImport = ws.Rows[p.Index].Cells[42].Value == null ? string.Empty : ws.Rows[p.Index].Cells[42].Value.ToString(),
493
                               DTIsRegSystem = ws.Rows[p.Index].Cells[43].Value == null ? string.Empty : ws.Rows[p.Index].Cells[43].Value.ToString(),
494
                               DTRemarks = ws.Rows[p.Index].Cells[44].Value == null ? string.Empty : ws.Rows[p.Index].Cells[44].Value.ToString()
495
                           }));
496

    
497
                    this.documents.AddRange(appendDocuments);
498
                    this.radGridViewDocuments.DataSource = this.documents;
499

    
500
                    //foreach (Documents appDoc in appendDocuments)
501
                    //{
502
                    //    GridViewRowInfo rowInfo = this.radGridViewDocuments.Rows.AddNew();
503

    
504
                    //    foreach (FieldInfo fieldInfo in appDoc.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
505
                    //    {
506
                    //        if (fieldInfo.GetValue(appDoc) != null)
507
                    //        {
508
                    //            var cols = rowInfo.Cells.Where(x => fieldInfo.Name.Contains($"<{x.ColumnInfo.Name}>"));
509

    
510
                    //            if (cols.Any())
511
                    //            {
512
                    //                cols.FirstOrDefault().Value = fieldInfo.GetValue(appDoc);
513
                    //            }
514
                    //        }
515
                    //    }
516
                    //}
517
                }
518
            }
519
        }
520

    
521
        private void RadButtonElementExcelExport_Click(object sender, EventArgs e)
522
        {
523
            string sPrefixName = "Samsung Elec Task Management";
524
            string extension = ".xlsx";
525

    
526
            using (SaveFileDialog sfd = new SaveFileDialog()
527
            {
528
                FileName = $"{sPrefixName}_{DateTime.Now:yyyyMMddhhmmss}{extension}",
529
                Filter = "Excel|*.xlsx",
530
                Title = "Save an Excel File",
531
                CheckFileExists = false,
532
                CheckPathExists = true,
533
                OverwritePrompt = true
534
            })
535
            {
536
                if (sfd.ShowDialog() == DialogResult.OK)
537
                {
538
                    string fileName = $"{sPrefixName}{extension}";
539
                    string templateFolder = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Template");
540
                    string templateFilePath = Path.Combine(templateFolder, fileName);
541
                    if (!File.Exists(templateFilePath))
542
                    {
543
                        RadMessageBox.Show(this, $"There is no {fileName} in {templateFolder}", "Error", MessageBoxButtons.OK, RadMessageIcon.Error);
544
                        return;
545
                    }
546

    
547
                    if (this.radGridViewDocuments.Rows.Count > 0)
548
                    {
549
                        var templateExcelFile = ExcelFile.Load(templateFilePath);
550
                        var templateWorksheets = templateExcelFile.Worksheets;
551
                        var templateWorksheet = templateWorksheets[0];
552

    
553
                        int rowIndex = 9;
554
                        //int colIndex = 1;
555

    
556
                        foreach (var row in this.radGridViewDocuments.Rows)
557
                        {
558
                            var doc = row.DataBoundItem as Documents;
559

    
560
                            templateWorksheet.Cells[rowIndex, 0].Value = doc.Seq;
561
                            //templateWorksheet.Cells[rowIndex, 1].Value = doc.DocumentNo;
562
                            //templateWorksheet.Cells[rowIndex, 2].Value = doc.DocumentNo;
563
                            //templateWorksheet.Cells[rowIndex, 3].Value = doc.DocumentNo;
564
                            //templateWorksheet.Cells[rowIndex, 4].Value = doc.DocumentNo;
565
                            templateWorksheet.Cells[rowIndex, 5].Value = doc.Place;
566
                            templateWorksheet.Cells[rowIndex, 6].Value = doc.DocumentNo;
567
                            templateWorksheet.Cells[rowIndex, 7].Value = doc.PersonInCharge;
568
                            templateWorksheet.Cells[rowIndex, 8].Value = doc.JobLevel;
569
                            templateWorksheet.Cells[rowIndex, 9].Value = doc.IsTypical;
570
                            templateWorksheet.Cells[rowIndex, 10].Value = doc.RevisonNo;
571
                            templateWorksheet.Cells[rowIndex, 11].Value = doc.ToIsDiscussion;
572
                            templateWorksheet.Cells[rowIndex, 12].Value = doc.ToRemarks;
573
                            templateWorksheet.Cells[rowIndex, 13].Value = doc.ToCreator;
574
                            templateWorksheet.Cells[rowIndex, 14].Value = doc.ToCapturePath;
575
                            templateWorksheet.Cells[rowIndex, 15].Value = doc.ToIsMarkup;
576
                            templateWorksheet.Cells[rowIndex, 16].Value = doc.FrReviewStatus;
577
                            templateWorksheet.Cells[rowIndex, 17].Value = doc.FrRemarks;
578
                            templateWorksheet.Cells[rowIndex, 18].Value = doc.FrCreator;
579
                            templateWorksheet.Cells[rowIndex, 19].Value = doc.FrCapturePath;
580
                            templateWorksheet.Cells[rowIndex, 20].Value = doc.FrIsMarkup;
581
                            templateWorksheet.Cells[rowIndex, 21].Value = doc.IsID2Work;
582
                            templateWorksheet.Cells[rowIndex, 22].Value = doc.ID2Connection;
583
                            templateWorksheet.Cells[rowIndex, 23].Value = doc.ID2StartDate;
584
                            templateWorksheet.Cells[rowIndex, 24].Value = doc.ID2EndDate;
585
                            templateWorksheet.Cells[rowIndex, 25].Value = doc.ID2JobTime;
586
                            templateWorksheet.Cells[rowIndex, 26].Value = doc.ID2Status;
587
                            templateWorksheet.Cells[rowIndex, 27].Value = doc.ID2Issues;
588
                            templateWorksheet.Cells[rowIndex, 28].Value = doc.AVEVAConnection;
589
                            templateWorksheet.Cells[rowIndex, 29].Value = doc.AVEVAConvertDate;
590
                            templateWorksheet.Cells[rowIndex, 30].Value = doc.AVEVAReviewDate;
591
                            templateWorksheet.Cells[rowIndex, 31].Value = doc.AVEVAStatus;
592
                            templateWorksheet.Cells[rowIndex, 32].Value = doc.AVEVAIssues;
593
                            //templateWorksheet.Cells[rowIndex, 33].Value = doc.DocumentNo;
594
                            //templateWorksheet.Cells[rowIndex, 34].Value = doc.DocumentNo;
595
                            templateWorksheet.Cells[rowIndex, 35].Value = doc.ProdReviewer;
596
                            templateWorksheet.Cells[rowIndex, 36].Value = doc.ProdIsResult;
597
                            templateWorksheet.Cells[rowIndex, 37].Value = doc.ProdRemarks;
598
                            templateWorksheet.Cells[rowIndex, 38].Value = doc.ClientReviewer;
599
                            templateWorksheet.Cells[rowIndex, 39].Value = doc.ClientIsResult;
600
                            templateWorksheet.Cells[rowIndex, 40].Value = doc.ClientRemarks;
601
                            templateWorksheet.Cells[rowIndex, 41].Value = doc.DTIsGateWay;
602
                            templateWorksheet.Cells[rowIndex, 42].Value = doc.DTIsImport;
603
                            templateWorksheet.Cells[rowIndex, 43].Value = doc.DTIsRegSystem;
604
                            templateWorksheet.Cells[rowIndex, 44].Value = doc.DTRemarks;
605
                            rowIndex++;
606
                        }
607

    
608
                        templateExcelFile.Save(sfd.FileName);
609
                        RadMessageBox.Show("Exporting 'ID2 Document List' is complete", Globals.Name, MessageBoxButtons.OK, RadMessageIcon.Info);
610
                    }
611
                }
612
            }
613
        }
614
        #endregion
615

    
616
        #region save event
617
        private void RadButtonElementSave_Click(object sender, EventArgs e)
618
        {
619
            List <Documents> setDocuments = new List<Documents>();
620
            List<Documents> delDocuments = new List<Documents>();
621

    
622
            var worker = new DocumentsWorker(this.documents, this.orgDocuments, setDocuments, delDocuments, this.radGridViewDocuments);
623
            worker.OnWorkCompletedHandler += () =>
624
            {
625
                bool result = new DocumentController().SetDocumentData(setDocuments, delDocuments);
626
                if (result)
627
                {
628
                    RadMessageBox.Show("Save is complete", Globals.Name, MessageBoxButtons.OK, RadMessageIcon.Info);
629
                    this.GetDocList();
630
                }
631
                else
632
                {
633
                    RadMessageBox.Show("Save is not complete", Globals.Name, MessageBoxButtons.OK, RadMessageIcon.Error);
634
                }
635
            };
636
            worker.StartWork();
637
        }
638
        #endregion
639

    
640
        #region ColumnGroup
641
        private void InitColumnGroupsViewDefinition(RadGridView gridView)
642
        {
643
            ColumnGroupsViewDefinition columnGroupsView = new ColumnGroupsViewDefinition();
644

    
645
            List<string> docLinkColNames = new List<string>() { "AutoCADLink", "PDFLink", "MarkupLink", "AVEVALink" };
646
            List<string> docInfoColNames = new List<string>() { "Place", "DocumentNo", "PersonInCharge", "JobLevel", "IsTypical", "RevisonNo" };
647
            List<string> rvToColNames = new List<string>() { "ToIsDiscussion", "ToRemarks", "ToModifier", "ToCapturePath", "ToIsMarkup" };
648
            List<string> rvFrColNames = new List<string>() { "FrReviewStatus", "FrRemarks", "FrModifier", "FrCapturePath", "FrIsMarkup" };
649
            List<string> rvEtcColNames = new List<string>() { "IsID2Work" };
650
            List<string> wkID2ColNames = new List<string>() { "ID2Connection", "ID2StartDate", "ID2EndDate", "ID2JobTime", "ID2Status", "ID2Issues" };
651
            List<string> wkAVEVAColNames = new List<string>() { "AVEVAConnection", "AVEVAConvertDate", "AVEVAReviewDate", "AVEVAStatus", "AVEVAIssues" };
652
            List<string> valLinkColNames = new List<string>() { "ReviewFileName", "SystemLink" };
653
            List<string> valProdColNames = new List<string>() { "ProdReviewer", "ProdIsResult", "ProdRemarks" };
654
            List<string> valCntColNames = new List<string>() { "ClientReviewer", "ClientIsResult", "ClientRemarks" };
655
            List<string> dtColNames = new List<string>() { "DTIsGateWay", "DTIsImport", "DTIsRegSystem", "DTRemarks" };
656

    
657
            //도면
658
            GridViewColumnGroup docColGrp = new GridViewColumnGroup("도면 ");
659
            GridViewColumnGroup docLinkColGrp = new GridViewColumnGroup("파일링크");
660
            GridViewColumnGroup docInfoColGrp = new GridViewColumnGroup("도면정보");
661

    
662
            GridViewColumnGroupRow docLinkColGrpRow = new GridViewColumnGroupRow();
663
            docLinkColGrpRow.ColumnNames.AddRange(docLinkColNames);
664

    
665
            GridViewColumnGroupRow docInfoColGrpRow = new GridViewColumnGroupRow();
666
            docInfoColGrpRow.ColumnNames.AddRange(docInfoColNames);
667

    
668
            docLinkColGrp.Rows.Add(docLinkColGrpRow);
669
            docColGrp.Groups.Add(docLinkColGrp);
670
            docInfoColGrp.Rows.Add(docInfoColGrpRow);
671
            docColGrp.Groups.Add(docInfoColGrp);
672

    
673
            //검토
674
            GridViewColumnGroup rvColGrp = new GridViewColumnGroup("검토", "review");
675
            GridViewColumnGroup rvToColGrp = new GridViewColumnGroup("도프텍");
676
            GridViewColumnGroup rvFrColGrp = new GridViewColumnGroup("삼성");
677
            GridViewColumnGroup rvEtcColGrp = new GridViewColumnGroup("기타");
678

    
679
            GridViewColumnGroupRow rvToColGrpRow = new GridViewColumnGroupRow();
680
            rvToColGrpRow.ColumnNames.AddRange(rvToColNames);
681

    
682
            GridViewColumnGroupRow rvFrColGrpRow = new GridViewColumnGroupRow();
683
            rvFrColGrpRow.ColumnNames.AddRange(rvFrColNames);
684

    
685
            GridViewColumnGroupRow rvEtcColGrpRow = new GridViewColumnGroupRow();
686
            rvEtcColGrpRow.ColumnNames.AddRange(rvEtcColNames);
687

    
688
            rvToColGrp.Rows.Add(rvToColGrpRow);
689
            rvFrColGrp.Rows.Add(rvFrColGrpRow);
690
            rvEtcColGrp.Rows.Add(rvEtcColGrpRow);
691

    
692

    
693
            rvColGrp.Groups.Add(rvToColGrp);
694
            rvColGrp.Groups.Add(rvFrColGrp);
695
            rvColGrp.Groups.Add(rvEtcColGrp);
696

    
697

    
698
            //작업
699
            GridViewColumnGroup wkColGrp = new GridViewColumnGroup("작업", "work");
700
            GridViewColumnGroup wkID2ColGrp = new GridViewColumnGroup("ID2");
701
            GridViewColumnGroup wkAVEVAColGrp = new GridViewColumnGroup("AVEVA");
702

    
703
            GridViewColumnGroupRow wkID2ColGrpRow = new GridViewColumnGroupRow();
704
            wkID2ColGrpRow.ColumnNames.AddRange(wkID2ColNames);
705

    
706
            GridViewColumnGroupRow wkAVEVAColGrpRow = new GridViewColumnGroupRow();
707
            wkAVEVAColGrpRow.ColumnNames.AddRange(wkAVEVAColNames);
708

    
709
            wkID2ColGrp.Rows.Add(wkID2ColGrpRow);
710
            wkAVEVAColGrp.Rows.Add(wkAVEVAColGrpRow);
711

    
712
            wkColGrp.Groups.Add(wkID2ColGrp);
713
            wkColGrp.Groups.Add(wkAVEVAColGrp);
714

    
715

    
716
            //Validation
717
            GridViewColumnGroup valColGrp = new GridViewColumnGroup("Validation", "validation");
718
            GridViewColumnGroup valLinkColGrp = new GridViewColumnGroup("파일링크");
719
            GridViewColumnGroup valProdColGrp = new GridViewColumnGroup("도프텍");
720
            GridViewColumnGroup valCntColGrp = new GridViewColumnGroup("삼성전자");
721

    
722
            GridViewColumnGroupRow valLinkColGrpRow = new GridViewColumnGroupRow();
723
            valLinkColGrpRow.ColumnNames.AddRange(valLinkColNames);
724

    
725
            GridViewColumnGroupRow valProdColGrpRow = new GridViewColumnGroupRow();
726
            valProdColGrpRow.ColumnNames.AddRange(valProdColNames);
727

    
728
            GridViewColumnGroupRow valCntColGrpRow = new GridViewColumnGroupRow();
729
            valCntColGrpRow.ColumnNames.AddRange(valCntColNames);
730

    
731
            valLinkColGrp.Rows.Add(valLinkColGrpRow);
732
            valProdColGrp.Rows.Add(valProdColGrpRow);
733
            valCntColGrp.Rows.Add(valCntColGrpRow);
734

    
735
            valColGrp.Groups.Add(valLinkColGrp);
736
            valColGrp.Groups.Add(valProdColGrp);
737
            valColGrp.Groups.Add(valCntColGrp);
738

    
739
            //AVEVA Net
740
            GridViewColumnGroup dtColGrp = new GridViewColumnGroup("AVEVA Net\n(Digital Twin)", "avevanet");
741

    
742
            GridViewColumnGroupRow dtColGrpRow = new GridViewColumnGroupRow();
743
            dtColGrpRow.ColumnNames.AddRange(dtColNames);
744

    
745
            dtColGrp.Rows.Add(dtColGrpRow);
746

    
747
            //Group 추가
748
            columnGroupsView.ColumnGroups.Add(docColGrp);
749
            columnGroupsView.ColumnGroups.Add(rvColGrp);
750
            columnGroupsView.ColumnGroups.Add(wkColGrp);
751
            columnGroupsView.ColumnGroups.Add(valColGrp);
752
            columnGroupsView.ColumnGroups.Add(dtColGrp);
753

    
754
            gridView.MasterTemplate.ViewDefinition = columnGroupsView;
755
        }
756
        #endregion
757

    
758
        class DocumentsWorker : BaseWorker
759
        {
760
            public delegate void OnWorkCompleted();
761
            public OnWorkCompleted OnWorkCompletedHandler;
762

    
763
            List<Documents> docList { get; set; }
764
            List<Documents> orgList { get; set; }
765
            List<Documents> setList { get; set; }
766
            List<Documents> delList { get; set; }
767

    
768
            public DocumentsWorker(List<Documents> docList, List<Documents> orgDocList, List<Documents> setDocList, List<Documents> delDocList, Control parent = null) : base(parent)
769
            {
770
                this.docList = docList;
771
                this.orgList = orgDocList;
772
                this.setList = setDocList;
773
                this.delList = delDocList;
774
            }
775
            protected override void DoWork(BackgroundWorker worker)
776
            {
777
                //수정리스트
778
                this.docList.Where(x => !this.orgList.Any(y => y.Equals(x)))
779
                              .ToList().ForEach(x => this.setList.Add(x));
780
                //삭제리스트
781
                this.delList.AddRange(this.orgList.Except(this.docList, new DocumentsKeyComparer()));
782
            }
783

    
784
            protected override void WorkCompleted()
785
            {
786
                if (this.OnWorkCompletedHandler != null) this.OnWorkCompletedHandler();
787
            }
788
        }
789
    }
790
}
클립보드 이미지 추가 (최대 크기: 500 MB)