Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmXmlExport.cs @ 253:7243e6646926 default tip
Re #427: Resizable equipment dialog
* Make equipment dialog resizable
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Apr 2013 16:10:08 +0100 |
parents | 4d25c42bbe7b |
children |
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; | |
13 | |
14 namespace IBBoard.WarFoundry.GUI.WinForms | |
15 { | |
16 public partial class FrmXmlExport : Form | |
17 { | |
18 Army myArmy = null; | |
19 public FrmXmlExport(Army army) | |
20 { | |
21 InitializeComponent(); | |
22 myArmy = army; | |
252
4d25c42bbe7b
Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
23 cbTransforms.DataSource = WarFoundryXmlWithXslExporter.GetDefault().GetXsltStreams(); |
4d25c42bbe7b
Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
24 cbTransforms.DisplayMember = "Name"; |
213 | 25 } |
26 | |
27 private void bttnOutputSelect_Click(object sender, EventArgs e) | |
28 { | |
29 SaveFileDialog sfd = new SaveFileDialog(); | |
30 sfd.Filter = "XML File|*.xml|HTML File|*.html|XHTML File|*.xhtml"; | |
31 sfd.Title = "Save XML output"; | |
32 sfd.ShowDialog(); | |
33 | |
34 if (sfd.FileName != "") | |
35 { | |
36 tbOutputFile.Text = sfd.FileName; | |
37 } | |
38 } | |
39 | |
40 private void bttnCancel_Click(object sender, EventArgs e) | |
41 { | |
42 this.DialogResult = DialogResult.Cancel; | |
43 this.Hide(); | |
44 } | |
45 | |
46 private void bttnExport_Click(object sender, EventArgs e) | |
47 { | |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
48 string errorMessage = ""; |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
49 // 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
|
50 try |
213 | 51 { |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
52 if (cbApplyTransform.Checked) |
215
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
53 { |
252
4d25c42bbe7b
Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
54 using (Stream xsltStream = (Stream)cbTransforms.SelectedItem) |
4d25c42bbe7b
Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
55 { |
4d25c42bbe7b
Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
56 WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(myArmy, tbOutputFile.Text, xsltStream); |
4d25c42bbe7b
Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
57 } |
215
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
58 } |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
59 else |
215
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
60 { |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
61 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
|
62 } |
213 | 63 } |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
64 catch (XsltCompileException ex) |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
65 { |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
66 errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") + |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
67 ":\n" + ex.Message; |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
68 } |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
69 catch (XsltException ex) |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
70 { |
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 errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") + |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
73 ":\n" + ex.Message; |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
74 } |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
75 catch (FileNotFoundException ex) |
213 | 76 { |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
77 errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") + |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
78 ":\n" + ex.Message; |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
79 } |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
80 catch (IOException ex) |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
81 { |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
82 errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") + |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
83 ":\n" + ex.Message; |
213 | 84 } |
219
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
85 catch (Exception ex) |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
86 { |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
87 errorMessage = Translation.GetTranslation("mbErrorFailed", "") + |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
88 ":\n" + ex.Message; |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
89 } |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
90 if (errorMessage != "") |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
91 { |
a3e62a2c267f
Added translation support for exceptional cases
Dan.Kulinski@dank-laptop.Global.Local
parents:
215
diff
changeset
|
92 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
|
93 } |
213 | 94 this.DialogResult = DialogResult.OK; |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
95 this.Hide(); |
213 | 96 } |
97 | |
98 private void tbOutputFile_Change(object sender, EventArgs e) | |
99 { | |
100 if (tbOutputFile.Text != "") | |
101 { | |
102 bttnExport.Enabled = true; | |
103 } | |
104 else | |
105 { | |
106 bttnExport.Enabled = false; | |
107 } | |
108 } | |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
109 |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
110 private void cbApplyTransform_CheckedChanged(object sender, EventArgs e) |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
111 { |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
112 if (cbApplyTransform.Checked) |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
113 { |
252
4d25c42bbe7b
Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
114 cbTransforms.Enabled = true; |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
115 } |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
116 else |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
117 { |
252
4d25c42bbe7b
Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
118 cbTransforms.Enabled = false; |
214
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 } |
213 | 121 } |
122 } |