프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / FinalPDFExcelDialogViewModel.cs @ 19d6b221

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

1
using Markus.Service.StationController.Data;
2
using Markus.Service.StationController.Extensions;
3
using Microsoft.Win32;
4
using System;
5
using System.Collections.Generic;
6
using System.Collections.ObjectModel;
7
using System.Linq;
8
using System.Text;
9
using System.Threading.Tasks;
10
using Telerik.Windows.Controls;
11

    
12
namespace Markus.Service.StationController.ViewModel
13
{
14
    class FinalPDFExcelDialogViewModel : Mvvm.ToolKit.ViewModelBase
15
    {
16
        #region Construrtor
17

    
18
        public FinalPDFExcelDialogViewModel()
19
        {
20
            ALL_SelectedCommand = new DelegateCommand(ALL_Selected);
21
            ALL_DeletedCommand = new DelegateCommand(ALL_Deleted);
22
            SaveCommand = new DelegateCommand(Save);
23
        }
24

    
25
        #endregion
26

    
27
        #region Propertise
28

    
29
        public ObservableCollection<CheckBoxItem> _ItemsSource;
30
        public ObservableCollection<CheckBoxItem> ItemsSource
31
        {
32
            get
33
            {
34
                if (_ItemsSource == null)
35
                {
36
                    ItemsSource = new ObservableCollection<CheckBoxItem>
37
                    {
38
                        new CheckBoxItem { IsChecked=true, Name="ConvertID"},
39
                        new CheckBoxItem { IsChecked=true, Name="ProjectNumber"},
40
                        new CheckBoxItem { IsChecked=true, Name="ConvertState"},
41
                        new CheckBoxItem { IsChecked=true, Name="CurrentPageNo"},
42
                        new CheckBoxItem { IsChecked=true, Name="TotalPage"},
43
                        new CheckBoxItem { IsChecked=true, Name="OriginfilePath"},
44
                        new CheckBoxItem { IsChecked=true, Name="ConvertPath"},
45
                        new CheckBoxItem { IsChecked=true, Name="CreateTime"},
46
                        new CheckBoxItem { IsChecked=true, Name="StartTime"},
47
                        new CheckBoxItem { IsChecked=true, Name="EndTime"},
48
                        new CheckBoxItem { IsChecked=true, Name="Exception"},
49
                        new CheckBoxItem { IsChecked=true, Name="Revision"},
50
                        new CheckBoxItem { IsChecked=true, Name="GroupNo"},
51
                        new CheckBoxItem { IsChecked=true, Name="DocumentNo"},
52
                        new CheckBoxItem { IsChecked=true, Name="DocumentID"},
53
                        new CheckBoxItem { IsChecked=true, Name="DocumentName"},
54
                        new CheckBoxItem { IsChecked=true, Name="MarkupInfo_ID"},
55
                        new CheckBoxItem { IsChecked=true, Name="DocInfo_ID"},
56
                        new CheckBoxItem { IsChecked=true, Name="Create_User_ID"},
57
                        new CheckBoxItem { IsChecked=true, Name="MarkusLink"}
58
                    };
59
                }
60

    
61
                return _ItemsSource;
62
            }
63
            set
64
            {
65
                _ItemsSource = value;
66
                OnPropertyChanged(() => ExcelSource);
67
            }
68
        }
69
        private System.Collections.ObjectModel.ObservableCollection<FinalPDF> _ExcelSource;
70
        public System.Collections.ObjectModel.ObservableCollection<FinalPDF> ExcelSource
71
        {
72
            get
73
            {
74
                if (_ExcelSource == null)
75
                {
76
                    _ExcelSource = new System.Collections.ObjectModel.ObservableCollection<FinalPDF>();
77
                    _ExcelSource = FinalPDFViewModel.Return_FilterConvertSource();
78
                }
79
                return _ExcelSource;
80
            }
81
            set
82
            {
83
                _ExcelSource = value;
84
                OnPropertyChanged(() => ExcelSource);
85
            }
86
        }
87

    
88
        #endregion
89

    
90
        #region Command
91

    
92
        public DelegateCommand ALL_SelectedCommand { get; private set; }
93
        public DelegateCommand ALL_DeletedCommand { get; private set; }
94
        public DelegateCommand SaveCommand { get; private set; }
95

    
96
        #endregion
97

    
98
        #region Fuction
99

    
100
        #region ALL_Selected
101

    
102
        public void ALL_Selected(object obj)
103
        {
104
            foreach (var ItemsSource in ItemsSource)
105
            {
106
                ItemsSource.IsChecked = true;
107
            }
108
        }
109

    
110
        #endregion
111

    
112
        #region ALL_Deleted
113

    
114
        public void ALL_Deleted(object obj)
115
        {
116
            foreach (var ItemsSource in ItemsSource)
117
            {
118
                ItemsSource.IsChecked = false;
119
            }
120
        }
121

    
122
        #endregion
123

    
124
        #region Save
125

    
126
        public void Save(object obj)
127
        {
128
            SaveFileDialog saveFileDialog = new SaveFileDialog();
129

    
130
            saveFileDialog.FileName = "Document"; // Default file name
131
            saveFileDialog.DefaultExt = ".txt"; // Default file extension
132
            saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension
133

    
134
            if (saveFileDialog.ShowDialog() == true)
135
            {
136
                if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName))
137
                {
138
                    var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension;
139

    
140
                    if (extension == ".xlsx" || extension == ".csv")
141
                    {
142
                        List<HeaderMember> headers = new List<HeaderMember>();
143
                        foreach (var ItemsSource in ItemsSource)
144
                        {
145
                            if (ItemsSource.IsChecked == true)
146
                            {
147
                                headers.Add(new HeaderMember { HeaderName = ItemsSource.Name, Property = ItemsSource.Name });
148
                            }
149
                        }
150

    
151
                        DataExport dataExport = new DataExport();
152
                        dataExport.DataExportExcel(saveFileDialog.FileName, "Final PDF", ExcelSource, headers);
153
                    }
154
                }
155
            }
156
        }
157

    
158
        #endregion
159

    
160
        #endregion
161
    }
162
}
클립보드 이미지 추가 (최대 크기: 500 MB)