markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / FinalPDFExcelDialogViewModel.cs @ cbf28e29
이력 | 보기 | 이력해설 | 다운로드 (6.46 KB)
1 | 037ab674 | semi | 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 | 19d6b221 | semi | 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 | 037ab674 | semi | }; |
59 | } |
||
60 | |||
61 | return _ItemsSource; |
||
62 | } |
||
63 | set |
||
64 | { |
||
65 | _ItemsSource = value; |
||
66 | OnPropertyChanged(() => ExcelSource); |
||
67 | } |
||
68 | } |
||
69 | 19d6b221 | semi | private System.Collections.ObjectModel.ObservableCollection<FinalPDF> _ExcelSource; |
70 | public System.Collections.ObjectModel.ObservableCollection<FinalPDF> ExcelSource |
||
71 | 037ab674 | semi | { |
72 | get |
||
73 | { |
||
74 | if (_ExcelSource == null) |
||
75 | { |
||
76 | 19d6b221 | semi | _ExcelSource = new System.Collections.ObjectModel.ObservableCollection<FinalPDF>(); |
77 | _ExcelSource = FinalPDFViewModel.Return_FilterConvertSource(); |
||
78 | 037ab674 | semi | } |
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 | cbf28e29 | semi | var today = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); |
131 | |||
132 | saveFileDialog.FileName = "Final_" + today; |
||
133 | saveFileDialog.Title = "Final_" + today; |
||
134 | saveFileDialog.DefaultExt = ".txt"; |
||
135 | saveFileDialog.CreatePrompt = true; |
||
136 | saveFileDialog.OverwritePrompt = false; |
||
137 | saveFileDialog.CheckFileExists = false; |
||
138 | saveFileDialog.CheckPathExists = false; |
||
139 | saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; |
||
140 | saveFileDialog.FilterIndex = 2; |
||
141 | saveFileDialog.RestoreDirectory = true; |
||
142 | 037ab674 | semi | |
143 | if (saveFileDialog.ShowDialog() == true) |
||
144 | { |
||
145 | cbf28e29 | semi | string filename = saveFileDialog.FileName; |
146 | |||
147 | if (saveFileDialog.FileName.Contains("\\")) |
||
148 | { |
||
149 | filename = saveFileDialog.FileName.Substring(saveFileDialog.FileName.LastIndexOf("\\") + 1); |
||
150 | } |
||
151 | |||
152 | filename = saveFileDialog.FileName.Replace(filename, "Final_" + today); |
||
153 | |||
154 | 037ab674 | semi | if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName)) |
155 | { |
||
156 | cbf28e29 | semi | |
157 | 037ab674 | semi | var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension; |
158 | |||
159 | if (extension == ".xlsx" || extension == ".csv") |
||
160 | { |
||
161 | List<HeaderMember> headers = new List<HeaderMember>(); |
||
162 | foreach (var ItemsSource in ItemsSource) |
||
163 | { |
||
164 | if (ItemsSource.IsChecked == true) |
||
165 | { |
||
166 | headers.Add(new HeaderMember { HeaderName = ItemsSource.Name, Property = ItemsSource.Name }); |
||
167 | } |
||
168 | } |
||
169 | |||
170 | DataExport dataExport = new DataExport(); |
||
171 | cbf28e29 | semi | dataExport.DataExportExcel(filename + extension, "Final PDF", ExcelSource, headers);//saveFileDialog.FileName |
172 | 037ab674 | semi | } |
173 | } |
||
174 | } |
||
175 | } |
||
176 | |||
177 | #endregion |
||
178 | |||
179 | #endregion |
||
180 | } |
||
181 | } |