프로젝트

일반

사용자정보

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

markus / FinalService / KCOM_FinalService / FinalPDFClient / MainWindow.xaml.cs @ c206d293

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

1
using KCOMDataModel.DataModel;
2
using MarkupToPDF;
3
using Microsoft.Win32;
4
using System;
5
using System.Collections.Generic;
6
using System.IO;
7
using System.Linq;
8
using System.Text;
9
using System.Threading.Tasks;
10
using System.Windows;
11
using System.Windows.Controls;
12
using System.Windows.Data;
13
using System.Windows.Documents;
14
using System.Windows.Input;
15
using System.Windows.Media;
16
using System.Windows.Media.Imaging;
17
using System.Windows.Navigation;
18
using System.Windows.Shapes;
19

    
20
namespace FinalPDFClient
21
{
22
    /// <summary>
23
    /// MainWindow.xaml에 대한 상호 작용 논리
24
    /// </summary>
25
    public partial class MainWindow : Window
26
    {
27
        public MainWindow()
28
        {
29
            InitializeComponent();
30
        }
31

    
32
        public  void MergedPDF()
33
        {
34

    
35
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
36
            stopwatch.Start();
37

    
38
            MarkupToPDF.MarkupToPDF markupToPDF = new MarkupToPDF.MarkupToPDF();
39

    
40
            EventHandler<MakeFinalErrorArgs> errorEventHandler = null;
41
            EventHandler<EndFinalEventArgs> endFinalEventHandler = null;
42
            EventHandler<StatusChangedEventArgs> StatusChangedEventHandler = null;
43

    
44
            errorEventHandler = async (snd, evt) =>
45
            {
46
                await this.Dispatcher.InvokeAsync(() =>
47
                {
48
                    txtOutput.Text += evt.Message;
49

    
50
                    markupToPDF.FinalMakeError -= errorEventHandler;
51
                    markupToPDF.EndFinal -= endFinalEventHandler;
52
                    markupToPDF.StatusChanged -= StatusChangedEventHandler;
53
                });
54
            };
55

    
56
            endFinalEventHandler = async (snd, evt) =>
57
            {
58
                await this.Dispatcher.InvokeAsync(() =>
59
                {
60
                    txtOutput.Text += evt.FinalPDFPath + "     " + evt.Error;
61
                    System.Diagnostics.Debug.WriteLine(evt.Message);
62

    
63
                    var sb = new StringBuilder();
64
                    sb.AppendLine(txtOutput.Text);
65
                    sb.AppendLine(new TimeSpan(stopwatch.ElapsedMilliseconds).ToString());
66
                    txtOutput.Text = sb.ToString();
67

    
68
                    markupToPDF.FinalMakeError -= errorEventHandler;
69
                    markupToPDF.EndFinal -= endFinalEventHandler;
70
                    markupToPDF.StatusChanged -= StatusChangedEventHandler;
71
                });
72
            };
73

    
74
            StatusChangedEventHandler = async (snd, evt) =>
75
            {
76
                await this.Dispatcher.InvokeAsync(() => {
77
                    txtOutput.Text += evt.Message + " " + evt.CurrentPage + "  " + evt.Error;
78
                });
79
            };
80

    
81
            markupToPDF.FinalMakeError += errorEventHandler;
82
            markupToPDF.EndFinal += endFinalEventHandler;
83
            markupToPDF.StatusChanged += StatusChangedEventHandler;
84
            try
85
            {
86
                var addResult = markupToPDF.AddFinalPDF(txtProject.Text, txtDocId.Text, txtUserId.Text);
87

    
88
                if (addResult.Success)
89
                {
90
                    markupToPDF.MakeFinalPDF((object)addResult.FinalPDF);
91
                  
92

    
93
                }
94
            }
95
            catch (Exception ex)
96
            {
97
                txtOutput.Text = ex.ToString();
98
            }
99
        }
100

    
101
        private void Button_Click(object sender, RoutedEventArgs e)
102
        {
103
             MergedPDF();
104
        }
105

    
106
        private void btXamlToString_Click(object sender, RoutedEventArgs e)
107
        {
108
            OpenFileDialog openFileDialog = new OpenFileDialog();
109

    
110
            openFileDialog.InitialDirectory = "c:\\";
111
            openFileDialog.Filter = "xaml files (*.xaml)|*.txt|All files (*.*)|*.*";
112
            openFileDialog.FilterIndex = 2;
113
            openFileDialog.RestoreDirectory = true;
114

    
115
            if (openFileDialog.ShowDialog() == true)
116
            {
117
                //Read the contents of the file into a stream
118
                var fileStream = openFileDialog.OpenFile();
119

    
120
                using (StreamReader reader = new StreamReader(fileStream))
121
                {
122
                    string fileContent = reader.ReadToEnd();
123

    
124
                    MarkupToPDF.MarkupToPDF markupToPDF = new MarkupToPDF.MarkupToPDF();
125

    
126
                    markupToPDF.AddStamp(fileContent);
127
                }
128
            }
129

    
130
        }
131
    }
132
}
클립보드 이미지 추가 (최대 크기: 500 MB)