markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / ConvertExcelDialogViewModel.cs @ 037ab674
이력 | 보기 | 이력해설 | 다운로드 (6.9 KB)
1 | 037ab674 | semi | using Markus.Service.StationController.Data; |
---|---|---|---|
2 | using Markus.Service.StationController.Extensions; |
||
3 | using System.Collections.Generic; |
||
4 | using Microsoft.Win32; |
||
5 | using Telerik.Windows.Controls; |
||
6 | using System.Collections.ObjectModel; |
||
7 | |||
8 | namespace Markus.Service.StationController.ViewModel |
||
9 | { |
||
10 | class ConvertExcelDialogViewModel : Mvvm.ToolKit.ViewModelBase |
||
11 | { |
||
12 | #region Construrtor |
||
13 | |||
14 | public ConvertExcelDialogViewModel() |
||
15 | { |
||
16 | ALL_SelectedCommand = new DelegateCommand(ALL_Selected); |
||
17 | ALL_DeletedCommand = new DelegateCommand(ALL_Deleted); |
||
18 | SaveCommand = new DelegateCommand(Save); |
||
19 | } |
||
20 | |||
21 | #endregion |
||
22 | |||
23 | #region Propertise |
||
24 | |||
25 | public ObservableCollection<CheckBoxItem> _ItemsSource; |
||
26 | public ObservableCollection<CheckBoxItem> ItemsSource |
||
27 | { |
||
28 | get |
||
29 | { |
||
30 | if (_ItemsSource == null) |
||
31 | { |
||
32 | ItemsSource = new ObservableCollection<CheckBoxItem> |
||
33 | { |
||
34 | new CheckBoxItem { IsChecked=true, Name="ServiceID"}, |
||
35 | new CheckBoxItem { IsChecked=true, Name="ConvertID"}, |
||
36 | new CheckBoxItem { IsChecked=true, Name="ProjectNumber"}, |
||
37 | new CheckBoxItem { IsChecked=true, Name="ConvertState"}, |
||
38 | new CheckBoxItem { IsChecked=true, Name="CurrentPageNo"}, |
||
39 | new CheckBoxItem { IsChecked=true, Name="TotalPage"}, |
||
40 | new CheckBoxItem { IsChecked=true, Name="OriginfilePath"}, |
||
41 | new CheckBoxItem { IsChecked=true, Name="ConvertPath"}, |
||
42 | new CheckBoxItem { IsChecked=true, Name="CreateTime"}, |
||
43 | new CheckBoxItem { IsChecked=true, Name="StartTime"}, |
||
44 | new CheckBoxItem { IsChecked=true, Name="EndTime"}, |
||
45 | new CheckBoxItem { IsChecked=true, Name="Exception"}, |
||
46 | new CheckBoxItem { IsChecked=true, Name="ReConverter"}, |
||
47 | new CheckBoxItem { IsChecked=true, Name="Revision"}, |
||
48 | new CheckBoxItem { IsChecked=true, Name="UniqueKey"}, |
||
49 | new CheckBoxItem { IsChecked=true, Name="Group_NO"}, |
||
50 | new CheckBoxItem { IsChecked=true, Name="Document_NO"}, |
||
51 | new CheckBoxItem { IsChecked=true, Name="Document_Name"} |
||
52 | }; |
||
53 | } |
||
54 | |||
55 | return _ItemsSource; |
||
56 | } |
||
57 | set |
||
58 | { |
||
59 | _ItemsSource = value; |
||
60 | OnPropertyChanged(() => ExcelSource); |
||
61 | } |
||
62 | } |
||
63 | private System.Collections.ObjectModel.ObservableCollection<ConvertPDF> _ExcelSource; |
||
64 | public System.Collections.ObjectModel.ObservableCollection<ConvertPDF> ExcelSource |
||
65 | { |
||
66 | get |
||
67 | { |
||
68 | if (_ExcelSource == null) |
||
69 | { |
||
70 | _ExcelSource = new System.Collections.ObjectModel.ObservableCollection<ConvertPDF>(); |
||
71 | _ExcelSource = DataBaseItemsModel.Return_FilterConvertSource(); |
||
72 | } |
||
73 | return _ExcelSource; |
||
74 | } |
||
75 | set |
||
76 | { |
||
77 | _ExcelSource = value; |
||
78 | OnPropertyChanged(() => ExcelSource); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | #endregion |
||
83 | |||
84 | #region Command |
||
85 | |||
86 | public DelegateCommand ALL_SelectedCommand { get; private set; } |
||
87 | public DelegateCommand ALL_DeletedCommand { get; private set; } |
||
88 | public DelegateCommand SaveCommand { get; private set; } |
||
89 | |||
90 | #endregion |
||
91 | |||
92 | #region Fuction |
||
93 | |||
94 | #region ALL_Selected |
||
95 | |||
96 | public void ALL_Selected(object obj) |
||
97 | { |
||
98 | foreach(var ItemsSource in ItemsSource) |
||
99 | { |
||
100 | ItemsSource.IsChecked = true; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | #endregion |
||
105 | |||
106 | #region ALL_Deleted |
||
107 | |||
108 | public void ALL_Deleted(object obj) |
||
109 | { |
||
110 | foreach (var ItemsSource in ItemsSource) |
||
111 | { |
||
112 | ItemsSource.IsChecked = false; |
||
113 | } |
||
114 | } |
||
115 | |||
116 | #endregion |
||
117 | |||
118 | #region Save |
||
119 | |||
120 | public void Save(object obj) |
||
121 | { |
||
122 | SaveFileDialog saveFileDialog = new SaveFileDialog(); |
||
123 | |||
124 | saveFileDialog.FileName = "Document"; // Default file name |
||
125 | saveFileDialog.DefaultExt = ".txt"; // Default file extension |
||
126 | saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension |
||
127 | |||
128 | if (saveFileDialog.ShowDialog() == true) |
||
129 | { |
||
130 | if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName)) |
||
131 | { |
||
132 | var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension; |
||
133 | |||
134 | if (extension == ".xlsx" || extension == ".csv") |
||
135 | { |
||
136 | List<HeaderMember> headers = new List<HeaderMember>(); |
||
137 | foreach(var ItemsSource in ItemsSource) |
||
138 | { |
||
139 | if (ItemsSource.IsChecked == true) |
||
140 | { |
||
141 | headers.Add(new HeaderMember { HeaderName = ItemsSource.Name, Property = ItemsSource.Name }); |
||
142 | } |
||
143 | } |
||
144 | |||
145 | // var headers = new List<HeaderMember> |
||
146 | //{ |
||
147 | |||
148 | //new HeaderMember{HeaderName = "ServiceID", Property = "ServiceID" }, |
||
149 | //new HeaderMember{HeaderName = "ConvertID", Property = "ConvertID" }, |
||
150 | //new HeaderMember{HeaderName = "ProjectNumber", Property = "ProjectNumber" }, |
||
151 | //new HeaderMember{HeaderName = "ConvertState", Property = "ConvertState" }, |
||
152 | //new HeaderMember{HeaderName = "CurrentPageNo", Property = "CurrentPageNo" }, |
||
153 | //new HeaderMember{HeaderName = "TotalPage", Property = "TotalPage" }, |
||
154 | //new HeaderMember{HeaderName = "OriginfilePath", Property = "OriginfilePath" }, |
||
155 | //new HeaderMember{HeaderName = "ConvertPath", Property = "ConvertPath" }, |
||
156 | //new HeaderMember{HeaderName = "CreateTime", Property = "CreateTime" }, |
||
157 | //new HeaderMember{HeaderName = "Exception", Property = "Exception" }, |
||
158 | //new HeaderMember{HeaderName = "ReConverter", Property = "ReConverter" }, |
||
159 | //new HeaderMember{HeaderName = "UniqueKey", Property = "UniqueKey" } |
||
160 | //}; |
||
161 | // new HeaderMember{HeaderName = "ProcessorAffinity", Property = "ProcessorAffinity" }, |
||
162 | |||
163 | DataExport dataExport = new DataExport(); |
||
164 | dataExport.DataExportExcel(saveFileDialog.FileName, "Convert PDF", ExcelSource, headers); |
||
165 | } |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | |||
170 | #endregion |
||
171 | |||
172 | #endregion |
||
173 | |||
174 | } |
||
175 | } |