프로젝트

일반

사용자정보

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

markus / FinalService / FinalServiceBase / FinalPDFClient / MainWindow.xaml.cs @ 42d49521

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

1 42d49521 taeseongkim
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
            catch (Exception ex)
95
            {
96
                txtOutput.Text = ex.ToString();
97
            }
98
        }
99
100
        private void Button_Click(object sender, RoutedEventArgs e)
101
        {
102
             MergedPDF();
103
        }
104
105
        private void btXamlToString_Click(object sender, RoutedEventArgs e)
106
        {
107
            OpenFileDialog openFileDialog = new OpenFileDialog();
108
109
            openFileDialog.InitialDirectory = "c:\\";
110
            openFileDialog.Filter = "xaml files (*.xaml)|*.txt|All files (*.*)|*.*";
111
            openFileDialog.FilterIndex = 2;
112
            openFileDialog.RestoreDirectory = true;
113
114
            if (openFileDialog.ShowDialog() == true)
115
            {
116
                //Read the contents of the file into a stream
117
                var fileStream = openFileDialog.OpenFile();
118
119
                using (StreamReader reader = new StreamReader(fileStream))
120
                {
121
                    string fileContent = reader.ReadToEnd();
122
123
                    MarkupToPDF.MarkupToPDF markupToPDF = new MarkupToPDF.MarkupToPDF();
124
125
                    markupToPDF.AddStamp(fileContent);
126
                }
127
            }
128
129
        }
130
    }
131
}
클립보드 이미지 추가 (최대 크기: 500 MB)