Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmXmlExport.cs @ 215:a0df71b24972 xml-export-ui
Added basic exception handling (a one case fits all)
author | Dan.Kulinski@dank-laptop.Global.Local |
---|---|
date | Thu, 18 Aug 2011 21:59:19 -0600 |
parents | a6ce13e4ae89 |
children | a3e62a2c267f |
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.Linq; | |
7 using System.Text; | |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
8 using System.IO; |
213 | 9 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
|
10 using System.Xml.Xsl; |
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; | |
23 } | |
24 | |
25 private void FrmXmlExport_Load(object sender, EventArgs e) | |
26 { | |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
27 tbXslPath.Text = Directory.GetCurrentDirectory() + "\\xsl\\default_html.xsl"; |
213 | 28 } |
29 | |
30 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) | |
31 { | |
32 | |
33 } | |
34 | |
35 private void bttnOutputSelect_Click(object sender, EventArgs e) | |
36 { | |
37 SaveFileDialog sfd = new SaveFileDialog(); | |
38 sfd.Filter = "XML File|*.xml|HTML File|*.html|XHTML File|*.xhtml"; | |
39 sfd.Title = "Save XML output"; | |
40 sfd.ShowDialog(); | |
41 | |
42 if (sfd.FileName != "") | |
43 { | |
44 tbOutputFile.Text = sfd.FileName; | |
45 } | |
46 } | |
47 | |
48 private void bttnCancel_Click(object sender, EventArgs e) | |
49 { | |
50 this.DialogResult = DialogResult.Cancel; | |
51 this.Hide(); | |
52 } | |
53 | |
54 private void bttnExport_Click(object sender, EventArgs e) | |
55 { | |
56 if (cbApplyTransform.Checked) | |
57 { | |
215
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
58 try |
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
59 { |
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
60 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
|
61 } |
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
62 catch (Exception ex) |
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
63 { |
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
64 MessageBox.Show(this, "Sorry, but an error occurred during export.", "Error on export", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); |
a0df71b24972
Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents:
214
diff
changeset
|
65 } |
213 | 66 } |
67 else | |
68 { | |
69 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(myArmy, tbOutputFile.Text); | |
70 } | |
71 | |
72 this.DialogResult = DialogResult.OK; | |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
73 this.Hide(); |
213 | 74 } |
75 | |
76 private void tbOutputFile_Change(object sender, EventArgs e) | |
77 { | |
78 if (tbOutputFile.Text != "") | |
79 { | |
80 bttnExport.Enabled = true; | |
81 } | |
82 else | |
83 { | |
84 bttnExport.Enabled = false; | |
85 } | |
86 } | |
214
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
87 |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
88 private void cbApplyTransform_CheckedChanged(object sender, EventArgs e) |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
89 { |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
90 if (cbApplyTransform.Checked) |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
91 { |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
92 tbXslPath.Enabled = true; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
93 bttnXslSelect.Enabled = true; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
94 } |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
95 else |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
96 { |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
97 tbXslPath.Enabled = false; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
98 bttnXslSelect.Enabled = false; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
99 } |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
100 } |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
101 |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
102 private void bttnXslSelect_Click(object sender, EventArgs e) |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
103 { |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
104 OpenFileDialog ofd = new OpenFileDialog(); |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
105 |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
106 ofd.InitialDirectory = Directory.GetCurrentDirectory() + "\\xsl"; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
107 ofd.Filter = "XSL Files|*.xsl"; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
108 DialogResult result = ofd.ShowDialog(); |
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 if (result == DialogResult.OK) |
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 tbXslPath.Text = ofd.FileName; |
a6ce13e4ae89
Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents:
213
diff
changeset
|
113 } |
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 } |
213 | 116 } |
117 } |