markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / ConvertExcelDialogViewModel.cs @ 8acc4862
이력 | 보기 | 이력해설 | 다운로드 (6.81 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 | cbf28e29 | semi | using System; |
8 | using System.Windows; |
||
9 | 037ab674 | semi | |
10 | namespace Markus.Service.StationController.ViewModel |
||
11 | { |
||
12 | class ConvertExcelDialogViewModel : Mvvm.ToolKit.ViewModelBase |
||
13 | { |
||
14 | #region Construrtor |
||
15 | |||
16 | public ConvertExcelDialogViewModel() |
||
17 | { |
||
18 | ALL_SelectedCommand = new DelegateCommand(ALL_Selected); |
||
19 | ALL_DeletedCommand = new DelegateCommand(ALL_Deleted); |
||
20 | SaveCommand = new DelegateCommand(Save); |
||
21 | } |
||
22 | |||
23 | #endregion |
||
24 | |||
25 | #region Propertise |
||
26 | |||
27 | public ObservableCollection<CheckBoxItem> _ItemsSource; |
||
28 | public ObservableCollection<CheckBoxItem> ItemsSource |
||
29 | { |
||
30 | get |
||
31 | { |
||
32 | if (_ItemsSource == null) |
||
33 | { |
||
34 | ItemsSource = new ObservableCollection<CheckBoxItem> |
||
35 | { |
||
36 | new CheckBoxItem { IsChecked=true, Name="ServiceID"}, |
||
37 | new CheckBoxItem { IsChecked=true, Name="ConvertID"}, |
||
38 | new CheckBoxItem { IsChecked=true, Name="ProjectNumber"}, |
||
39 | new CheckBoxItem { IsChecked=true, Name="ConvertState"}, |
||
40 | new CheckBoxItem { IsChecked=true, Name="CurrentPageNo"}, |
||
41 | new CheckBoxItem { IsChecked=true, Name="TotalPage"}, |
||
42 | new CheckBoxItem { IsChecked=true, Name="OriginfilePath"}, |
||
43 | new CheckBoxItem { IsChecked=true, Name="ConvertPath"}, |
||
44 | new CheckBoxItem { IsChecked=true, Name="CreateTime"}, |
||
45 | new CheckBoxItem { IsChecked=true, Name="StartTime"}, |
||
46 | new CheckBoxItem { IsChecked=true, Name="EndTime"}, |
||
47 | new CheckBoxItem { IsChecked=true, Name="Exception"}, |
||
48 | new CheckBoxItem { IsChecked=true, Name="ReConverter"}, |
||
49 | new CheckBoxItem { IsChecked=true, Name="Revision"}, |
||
50 | new CheckBoxItem { IsChecked=true, Name="UniqueKey"}, |
||
51 | 19d6b221 | semi | new CheckBoxItem { IsChecked=true, Name="GroupNo"}, |
52 | new CheckBoxItem { IsChecked=true, Name="DocumentNo"}, |
||
53 | new CheckBoxItem { IsChecked=true, Name="DocumentName"}, |
||
54 | new CheckBoxItem { IsChecked=true, Name="DocumnetURL"}, |
||
55 | new CheckBoxItem { IsChecked=true, Name="MarkusLink"} |
||
56 | 037ab674 | semi | }; |
57 | } |
||
58 | |||
59 | return _ItemsSource; |
||
60 | } |
||
61 | set |
||
62 | { |
||
63 | _ItemsSource = value; |
||
64 | OnPropertyChanged(() => ExcelSource); |
||
65 | } |
||
66 | } |
||
67 | private System.Collections.ObjectModel.ObservableCollection<ConvertPDF> _ExcelSource; |
||
68 | public System.Collections.ObjectModel.ObservableCollection<ConvertPDF> ExcelSource |
||
69 | { |
||
70 | get |
||
71 | { |
||
72 | if (_ExcelSource == null) |
||
73 | { |
||
74 | _ExcelSource = new System.Collections.ObjectModel.ObservableCollection<ConvertPDF>(); |
||
75 | _ExcelSource = DataBaseItemsModel.Return_FilterConvertSource(); |
||
76 | } |
||
77 | return _ExcelSource; |
||
78 | } |
||
79 | set |
||
80 | { |
||
81 | _ExcelSource = value; |
||
82 | OnPropertyChanged(() => ExcelSource); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | #endregion |
||
87 | |||
88 | #region Command |
||
89 | |||
90 | public DelegateCommand ALL_SelectedCommand { get; private set; } |
||
91 | public DelegateCommand ALL_DeletedCommand { get; private set; } |
||
92 | public DelegateCommand SaveCommand { get; private set; } |
||
93 | |||
94 | #endregion |
||
95 | |||
96 | #region Fuction |
||
97 | |||
98 | #region ALL_Selected |
||
99 | |||
100 | public void ALL_Selected(object obj) |
||
101 | { |
||
102 | foreach(var ItemsSource in ItemsSource) |
||
103 | { |
||
104 | ItemsSource.IsChecked = true; |
||
105 | } |
||
106 | } |
||
107 | |||
108 | #endregion |
||
109 | |||
110 | #region ALL_Deleted |
||
111 | |||
112 | public void ALL_Deleted(object obj) |
||
113 | { |
||
114 | foreach (var ItemsSource in ItemsSource) |
||
115 | { |
||
116 | ItemsSource.IsChecked = false; |
||
117 | } |
||
118 | } |
||
119 | |||
120 | #endregion |
||
121 | |||
122 | #region Save |
||
123 | |||
124 | cbf28e29 | semi | public void Save(object obj)//파일이름 경로 저장 및 파일 저장 하면 바로 저장되게! |
125 | 037ab674 | semi | { |
126 | cbf28e29 | semi | try |
127 | { |
||
128 | 037ab674 | semi | |
129 | cbf28e29 | semi | SaveFileDialog saveFileDialog = new SaveFileDialog(); |
130 | 037ab674 | semi | |
131 | cbf28e29 | semi | var today = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); |
132 | |||
133 | saveFileDialog.FileName = "Convert_" + today; |
||
134 | saveFileDialog.Title = "Convert_" + today; |
||
135 | saveFileDialog.DefaultExt = ".txt"; |
||
136 | saveFileDialog.CreatePrompt = true; |
||
137 | saveFileDialog.OverwritePrompt = false; |
||
138 | saveFileDialog.CheckFileExists = false; |
||
139 | saveFileDialog.CheckPathExists = false; |
||
140 | saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; |
||
141 | saveFileDialog.FilterIndex = 2; |
||
142 | saveFileDialog.RestoreDirectory = true; |
||
143 | |||
144 | if (saveFileDialog.ShowDialog() == true) |
||
145 | 037ab674 | semi | { |
146 | cbf28e29 | semi | string filename = saveFileDialog.FileName; |
147 | |||
148 | if (saveFileDialog.FileName.Contains("\\")) |
||
149 | { |
||
150 | filename = saveFileDialog.FileName.Substring(saveFileDialog.FileName.LastIndexOf("\\") + 1); |
||
151 | } |
||
152 | |||
153 | filename = saveFileDialog.FileName.Replace(filename, "Convert_" + today); |
||
154 | 037ab674 | semi | |
155 | cbf28e29 | semi | if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName)) |
156 | 037ab674 | semi | { |
157 | cbf28e29 | semi | var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension; |
158 | |||
159 | if (extension == ".xlsx" || extension == ".csv") |
||
160 | 037ab674 | semi | { |
161 | cbf28e29 | semi | List<HeaderMember> headers = new List<HeaderMember>(); |
162 | foreach (var ItemsSource in ItemsSource) |
||
163 | 037ab674 | semi | { |
164 | cbf28e29 | semi | if (ItemsSource.IsChecked == true) |
165 | { |
||
166 | headers.Add(new HeaderMember { HeaderName = ItemsSource.Name, Property = ItemsSource.Name }); |
||
167 | } |
||
168 | 037ab674 | semi | } |
169 | |||
170 | cbf28e29 | semi | DataExport dataExport = new DataExport(); |
171 | dataExport.DataExportExcel(filename + extension, "Convert PDF", ExcelSource, headers); |
||
172 | } |
||
173 | 037ab674 | semi | } |
174 | } |
||
175 | } |
||
176 | cbf28e29 | semi | catch (Exception ex) |
177 | { |
||
178 | System.Windows.MessageBox.Show(ex.ToString()); |
||
179 | } |
||
180 | 037ab674 | semi | } |
181 | |||
182 | cbf28e29 | semi | |
183 | 037ab674 | semi | #endregion |
184 | |||
185 | #endregion |
||
186 | |||
187 | } |
||
188 | } |