markus / FinalService / KCOM_FinalService / FinalPDFClient / MainWindow.xaml.cs @ 1f112f94
이력 | 보기 | 이력해설 | 다운로드 (4.26 KB)
1 | 077fb153 | taeseongkim | using KCOMDataModel.DataModel; |
---|---|---|---|
2 | using MarkupToPDF; |
||
3 | c206d293 | taeseongkim | using Microsoft.Win32; |
4 | 077fb153 | taeseongkim | using System; |
5 | 8e6884a5 | taeseongkim | using System.Collections.Generic; |
6 | c206d293 | taeseongkim | using System.IO; |
7 | 8e6884a5 | taeseongkim | 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 | 077fb153 | taeseongkim | |
32 | c206d293 | taeseongkim | public void MergedPDF() |
33 | 077fb153 | taeseongkim | { |
34 | c206d293 | taeseongkim | |
35 | System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); |
||
36 | stopwatch.Start(); |
||
37 | |||
38 | 077fb153 | taeseongkim | MarkupToPDF.MarkupToPDF markupToPDF = new MarkupToPDF.MarkupToPDF(); |
39 | |||
40 | EventHandler<MakeFinalErrorArgs> errorEventHandler = null; |
||
41 | EventHandler<EndFinalEventArgs> endFinalEventHandler = null; |
||
42 | ab590000 | taeseongkim | EventHandler<StatusChangedEventArgs> StatusChangedEventHandler = null; |
43 | 077fb153 | taeseongkim | |
44 | c206d293 | taeseongkim | errorEventHandler = async (snd, evt) => |
45 | 077fb153 | taeseongkim | { |
46 | c206d293 | taeseongkim | await this.Dispatcher.InvokeAsync(() => |
47 | { |
||
48 | txtOutput.Text += evt.Message; |
||
49 | 077fb153 | taeseongkim | |
50 | c206d293 | taeseongkim | markupToPDF.FinalMakeError -= errorEventHandler; |
51 | markupToPDF.EndFinal -= endFinalEventHandler; |
||
52 | markupToPDF.StatusChanged -= StatusChangedEventHandler; |
||
53 | }); |
||
54 | 077fb153 | taeseongkim | }; |
55 | |||
56 | c206d293 | taeseongkim | endFinalEventHandler = async (snd, evt) => |
57 | 077fb153 | taeseongkim | { |
58 | c206d293 | taeseongkim | await this.Dispatcher.InvokeAsync(() => |
59 | { |
||
60 | txtOutput.Text += evt.FinalPDFPath + " " + evt.Error; |
||
61 | System.Diagnostics.Debug.WriteLine(evt.Message); |
||
62 | 077fb153 | taeseongkim | |
63 | c206d293 | taeseongkim | 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 | ab590000 | taeseongkim | }; |
73 | |||
74 | c206d293 | taeseongkim | StatusChangedEventHandler = async (snd, evt) => |
75 | ab590000 | taeseongkim | { |
76 | c206d293 | taeseongkim | await this.Dispatcher.InvokeAsync(() => { |
77 | ab590000 | taeseongkim | txtOutput.Text += evt.Message + " " + evt.CurrentPage + " " + evt.Error; |
78 | }); |
||
79 | 077fb153 | taeseongkim | }; |
80 | |||
81 | markupToPDF.FinalMakeError += errorEventHandler; |
||
82 | markupToPDF.EndFinal += endFinalEventHandler; |
||
83 | ab590000 | taeseongkim | markupToPDF.StatusChanged += StatusChangedEventHandler; |
84 | try |
||
85 | { |
||
86 | var addResult = markupToPDF.AddFinalPDF(txtProject.Text, txtDocId.Text, txtUserId.Text); |
||
87 | 077fb153 | taeseongkim | |
88 | ab590000 | taeseongkim | if (addResult.Success) |
89 | { |
||
90 | markupToPDF.MakeFinalPDF((object)addResult.FinalPDF); |
||
91 | c206d293 | taeseongkim | |
92 | ab590000 | taeseongkim | } |
93 | } |
||
94 | catch (Exception ex) |
||
95 | 077fb153 | taeseongkim | { |
96 | ab590000 | taeseongkim | txtOutput.Text = ex.ToString(); |
97 | 077fb153 | taeseongkim | } |
98 | } |
||
99 | |||
100 | private void Button_Click(object sender, RoutedEventArgs e) |
||
101 | { |
||
102 | c206d293 | taeseongkim | MergedPDF(); |
103 | 077fb153 | taeseongkim | } |
104 | |||
105 | c206d293 | taeseongkim | 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 | 8e6884a5 | taeseongkim | } |
131 | } |