annotate FrmXmlExport.cs @ 211: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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
1 using System;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
2 using System.Collections.Generic;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
3 using System.ComponentModel;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
4 using System.Data;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
5 using System.Drawing;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
6 using System.Linq;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
7 using System.Text;
210
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
8 using System.IO;
209
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
9 using System.Windows.Forms;
211
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 210
diff changeset
10 using System.Xml.Xsl;
209
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
11 using IBBoard.WarFoundry.API.Objects;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
12 using IBBoard.WarFoundry.API.Exporters;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
13
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
14 namespace IBBoard.WarFoundry.GUI.WinForms
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
15 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
16 public partial class FrmXmlExport : Form
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
17 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
18 Army myArmy = null;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
19 public FrmXmlExport(Army army)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
20 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
21 InitializeComponent();
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
22 myArmy = army;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
23 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
24
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
25 private void FrmXmlExport_Load(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
26 {
210
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
27 tbXslPath.Text = Directory.GetCurrentDirectory() + "\\xsl\\default_html.xsl";
209
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
28 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
29
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
30 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
31 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
32
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
33 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
34
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
35 private void bttnOutputSelect_Click(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
36 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
37 SaveFileDialog sfd = new SaveFileDialog();
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
38 sfd.Filter = "XML File|*.xml|HTML File|*.html|XHTML File|*.xhtml";
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
39 sfd.Title = "Save XML output";
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
40 sfd.ShowDialog();
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
41
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
42 if (sfd.FileName != "")
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
43 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
44 tbOutputFile.Text = sfd.FileName;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
45 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
46 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
47
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
48 private void bttnCancel_Click(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
49 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
50 this.DialogResult = DialogResult.Cancel;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
51 this.Hide();
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
52 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
53
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
54 private void bttnExport_Click(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
55 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
56 if (cbApplyTransform.Checked)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
57 {
211
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 210
diff changeset
58 try
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 210
diff changeset
59 {
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 210
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: 210
diff changeset
61 }
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 210
diff changeset
62 catch (Exception ex)
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 210
diff changeset
63 {
a0df71b24972 Added basic exception handling (a one case fits all)
Dan.Kulinski@dank-laptop.Global.Local
parents: 210
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: 210
diff changeset
65 }
209
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
66 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
67 else
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
68 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
69 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(myArmy, tbOutputFile.Text);
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
70 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
71
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
72 this.DialogResult = DialogResult.OK;
210
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
73 this.Hide();
209
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
74 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
75
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
76 private void tbOutputFile_Change(object sender, EventArgs e)
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
77 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
78 if (tbOutputFile.Text != "")
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
79 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
80 bttnExport.Enabled = true;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
81 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
82 else
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
83 {
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
84 bttnExport.Enabled = false;
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
85 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
86 }
210
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
87
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
88 private void cbApplyTransform_CheckedChanged(object sender, EventArgs e)
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
89 {
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
90 if (cbApplyTransform.Checked)
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
91 {
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
92 tbXslPath.Enabled = true;
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
93 bttnXslSelect.Enabled = true;
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
94 }
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
95 else
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
96 {
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
97 tbXslPath.Enabled = false;
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
98 bttnXslSelect.Enabled = false;
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
99 }
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
100 }
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
101
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
102 private void bttnXslSelect_Click(object sender, EventArgs e)
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
103 {
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
104 OpenFileDialog ofd = new OpenFileDialog();
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
105
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
106 ofd.InitialDirectory = Directory.GetCurrentDirectory() + "\\xsl";
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
107 ofd.Filter = "XSL Files|*.xsl";
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
108 DialogResult result = ofd.ShowDialog();
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
109
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
110 if (result == DialogResult.OK)
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
111 {
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
112 tbXslPath.Text = ofd.FileName;
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
113 }
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
114
a6ce13e4ae89 Near Final XSL output
Dan.Kulinski@dank-laptop.Global.Local
parents: 209
diff changeset
115 }
209
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
116 }
f57957fe9009 UI Dialog for XML output
Dan.Kulinski@dank-laptop.Global.Local
parents:
diff changeset
117 }