forked from chnyksl/basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormMain.cs
110 lines (93 loc) · 3.46 KB
/
FormMain.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
namespace EFaturaGoruntuleyici
{
public partial class FormMain : Form
{
Encoding en;
string strXLST = "";
private OpenFileDialog openFileDialog1;
public FormMain()
{
InitializeComponent();
openFileDialog1 = new OpenFileDialog();
en = Encoding.UTF8;
string startup_path = Application.StartupPath;
string xlst_path = startup_path + "\\general.xslt";
if (!File.Exists(xlst_path))
{
MessageBox.Show(xlst_path + " dosyası bulunamadı");
return;
}
else
{
strXLST = File.ReadAllText(xlst_path, en);
}
}
private void btnSelectFile_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if (!openFileDialog1.FileName.ToLower().EndsWith(".xml"))
{
MessageBox.Show("sadece xml uzantılı dosyalar desteklenmektedir");
return;
}
var sr = new StreamReader(openFileDialog1.FileName);
txtFilePath.Text = openFileDialog1.FileName;
string strFaturaXML = sr.ReadToEnd();
string ErrMsg = "";
string strResult = Transform(strFaturaXML, strXLST, out ErrMsg);
if (ErrMsg != "")
MessageBox.Show(ErrMsg);
else
{
webBrowser1.DocumentText = strResult;
}
}
catch (Exception ex)
{
MessageBox.Show("Error message: " + ex.Message + Environment.NewLine + "Details:" + ex.StackTrace);
}
}
}
private void btnYazdir_Click(object sender, EventArgs e)
{
webBrowser1.ShowPrintDialog();
}
private string Transform(string XMLPage, string XSLStylesheet, out string ErrorMessage)
{
string result = "";
ErrorMessage = "";
try
{
// Reading XML
TextReader textReader1 = new StringReader(XMLPage);
XmlTextReader xmlTextReader1 = new XmlTextReader(textReader1);
XPathDocument xPathDocument = new XPathDocument(xmlTextReader1);
//Reading XSLT
TextReader textReader2 = new StringReader(XSLStylesheet);
XmlTextReader xmlTextReader2 = new XmlTextReader(textReader2);
//Define XslCompiledTransform
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(xmlTextReader2);
StringBuilder sb = new StringBuilder();
TextWriter tw = new StringWriter(sb);
xslt.Transform(xPathDocument, null, tw);
result = sb.ToString();
}
catch (Exception ex)
{
ErrorMessage = ex.Message;
}
return result;
}
}
}