프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / FinalPDFExcelDialogViewModel.cs @ 037ab674

이력 | 보기 | 이력해설 | 다운로드 (5.63 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="ServiceID"},
39
                        //new CheckBoxItem { IsChecked=true, Name="ConvertID"},
40
                        //new CheckBoxItem { IsChecked=true, Name="ProjectNumber"},
41
                        //new CheckBoxItem { IsChecked=true, Name="ConvertState"},
42
                        //new CheckBoxItem { IsChecked=true, Name="CurrentPageNo"},
43
                        //new CheckBoxItem { IsChecked=true, Name="TotalPage"},
44
                        //new CheckBoxItem { IsChecked=true, Name="OriginfilePath"},
45
                        //new CheckBoxItem { IsChecked=true, Name="ConvertPath"},
46
                        //new CheckBoxItem { IsChecked=true, Name="CreateTime"},
47
                        //new CheckBoxItem { IsChecked=true, Name="StartTime"},
48
                        //new CheckBoxItem { IsChecked=true, Name="EndTime"},
49
                        //new CheckBoxItem { IsChecked=true, Name="Exception"},
50
                        //new CheckBoxItem { IsChecked=true, Name="ReConverter"},
51
                        //new CheckBoxItem { IsChecked=true, Name="Revision"},
52
                        //new CheckBoxItem { IsChecked=true, Name="UniqueKey"},
53
                        //new CheckBoxItem { IsChecked=true, Name="Group_NO"},
54
                        //new CheckBoxItem { IsChecked=true, Name="Document_NO"},
55
                        //new CheckBoxItem { IsChecked=true, Name="Document_Name"}
56
                    };
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
        public void Save(object obj)
125
        {
126
            SaveFileDialog saveFileDialog = new SaveFileDialog();
127

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

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

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

    
149
                        DataExport dataExport = new DataExport();
150
                        dataExport.DataExportExcel(saveFileDialog.FileName, "Convert PDF", ExcelSource, headers);
151
                    }
152
                }
153
            }
154
        }
155

    
156
        #endregion
157

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