Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmXmlExport.cs @ 221:c47094612bac
Re #355: Add XML export format that can be transformed with an XSL
* Merge Clutch's WinForms code into main branch
* Fix targetting of project
* Add .hgignore
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 25 Aug 2011 20:43:51 +0100 |
parents | e10688b29092 |
children | 72beddaffb71 |
rev | line source |
---|---|
213 | 1 using System; |
2 using System.Collections.Generic; | |
3 using System.ComponentModel; | |
4 using System.Data; | |
5 using System.Drawing; | |
6 using System.Text; | |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
7 using System.IO; |
213 | 8 using System.Windows.Forms; |
215
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
9 using System.Xml.Xsl; |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
10 using IBBoard.Lang; |
213 | 11 using IBBoard.WarFoundry.API.Objects; |
12 using IBBoard.WarFoundry.API.Exporters; | |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
13 using System.Xml.Xsl; |
213 | 14 |
15 namespace IBBoard.WarFoundry.GUI.WinForms | |
16 { | |
17 public partial class FrmXmlExport : Form | |
18 { | |
19 Army myArmy = null; | |
20 public FrmXmlExport(Army army) | |
21 { | |
22 InitializeComponent(); | |
23 myArmy = army; | |
24 } | |
25 | |
26 private void FrmXmlExport_Load(object sender, EventArgs e) | |
27 { | |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
28 tbXslPath.Text = Directory.GetCurrentDirectory() + "\\xsl\\default_html.xsl"; |
213 | 29 } |
30 | |
31 private void bttnOutputSelect_Click(object sender, EventArgs e) | |
32 { | |
33 SaveFileDialog sfd = new SaveFileDialog(); | |
34 sfd.Filter = "XML File|*.xml|HTML File|*.html|XHTML File|*.xhtml"; | |
35 sfd.Title = "Save XML output"; | |
36 sfd.ShowDialog(); | |
37 | |
38 if (sfd.FileName != "") | |
39 { | |
40 tbOutputFile.Text = sfd.FileName; | |
41 } | |
42 } | |
43 | |
44 private void bttnCancel_Click(object sender, EventArgs e) | |
45 { | |
46 this.DialogResult = DialogResult.Cancel; | |
47 this.Hide(); | |
48 } | |
49 | |
50 private void bttnExport_Click(object sender, EventArgs e) | |
51 { | |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
52 string errorMessage = ""; |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
53 // Catch potential errors with the file export or XSL compiliation |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
54 try |
213 | 55 { |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
56 if (cbApplyTransform.Checked) |
215
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
57 { |
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
58 WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(myArmy, tbOutputFile.Text, tbXslPath.Text); |
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
59 } |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
60 else |
215
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
61 { |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
62 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(myArmy, tbOutputFile.Text); |
215
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
63 } |
213 | 64 } |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
65 catch (XsltCompileException ex) |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
66 { |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
67 errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") + |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
68 ":\n" + ex.Message; |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
69 } |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
70 catch (XsltException ex) |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
71 { |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
72 |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
73 errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") + |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
74 ":\n" + ex.Message; |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
75 } |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
76 catch (FileNotFoundException ex) |
213 | 77 { |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
78 errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") + |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
79 ":\n" + ex.Message; |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
80 } |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
81 catch (IOException ex) |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
82 { |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
83 errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") + |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
84 ":\n" + ex.Message; |
213 | 85 } |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
86 catch (Exception ex) |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
87 { |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
88 errorMessage = Translation.GetTranslation("mbErrorFailed", "") + |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
89 ":\n" + ex.Message; |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
90 } |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
91 if (errorMessage != "") |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
92 { |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
93 MessageBox.Show(errorMessage, "Error During Export", MessageBoxButtons.OK, MessageBoxIcon.Error); |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
94 } |
213 | 95 this.DialogResult = DialogResult.OK; |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
96 this.Hide(); |
213 | 97 } |
98 | |
99 private void tbOutputFile_Change(object sender, EventArgs e) | |
100 { | |
101 if (tbOutputFile.Text != "") | |
102 { | |
103 bttnExport.Enabled = true; | |
104 } | |
105 else | |
106 { | |
107 bttnExport.Enabled = false; | |
108 } | |
109 } | |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
110 |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
111 private void cbApplyTransform_CheckedChanged(object sender, EventArgs e) |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
112 { |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
113 if (cbApplyTransform.Checked) |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
114 { |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
115 tbXslPath.Enabled = true; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
116 bttnXslSelect.Enabled = true; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
117 } |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
118 else |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
119 { |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
120 tbXslPath.Enabled = false; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
121 bttnXslSelect.Enabled = false; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
122 } |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
123 } |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
124 |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
125 private void bttnXslSelect_Click(object sender, EventArgs e) |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
126 { |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
127 OpenFileDialog ofd = new OpenFileDialog(); |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
128 |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
129 ofd.InitialDirectory = Directory.GetCurrentDirectory() + "\\xsl"; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
130 ofd.Filter = "XSL Files|*.xsl"; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
131 DialogResult result = ofd.ShowDialog(); |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
132 |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
133 if (result == DialogResult.OK) |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
134 { |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
135 tbXslPath.Text = ofd.FileName; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
136 } |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
137 |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
138 } |
213 | 139 } |
140 } |