view FrmXmlExport.cs @ 216:e10688b29092

Fixed .Net 4.0 dependency
author Dan.Kulinski@dank-laptop.Global.Local
date Thu, 25 Aug 2011 12:59:26 -0600
parents a3e62a2c267f
children 72beddaffb71
line source
1 ´╗┐using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.IO;
8 using System.Windows.Forms;
9 using System.Xml.Xsl;
10 using IBBoard.Lang;
11 using IBBoard.WarFoundry.API.Objects;
12 using IBBoard.WarFoundry.API.Exporters;
13 using System.Xml.Xsl;
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 }
26 private void FrmXmlExport_Load(object sender, EventArgs e)
27 {
28 tbXslPath.Text = Directory.GetCurrentDirectory() + "\\xsl\\default_html.xsl";
29 }
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();
38 if (sfd.FileName != "")
39 {
40 tbOutputFile.Text = sfd.FileName;
41 }
42 }
44 private void bttnCancel_Click(object sender, EventArgs e)
45 {
46 this.DialogResult = DialogResult.Cancel;
47 this.Hide();
48 }
50 private void bttnExport_Click(object sender, EventArgs e)
51 {
52 string errorMessage = "";
53 // Catch potential errors with the file export or XSL compiliation
54 try
55 {
56 if (cbApplyTransform.Checked)
57 {
58 WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(myArmy, tbOutputFile.Text, tbXslPath.Text);
59 }
60 else
61 {
62 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(myArmy, tbOutputFile.Text);
63 }
64 }
65 catch (XsltCompileException ex)
66 {
67 errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") +
68 ":\n" + ex.Message;
69 }
70 catch (XsltException ex)
71 {
73 errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") +
74 ":\n" + ex.Message;
75 }
76 catch (FileNotFoundException ex)
77 {
78 errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") +
79 ":\n" + ex.Message;
80 }
81 catch (IOException ex)
82 {
83 errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") +
84 ":\n" + ex.Message;
85 }
86 catch (Exception ex)
87 {
88 errorMessage = Translation.GetTranslation("mbErrorFailed", "") +
89 ":\n" + ex.Message;
90 }
91 if (errorMessage != "")
92 {
93 MessageBox.Show(errorMessage, "Error During Export", MessageBoxButtons.OK, MessageBoxIcon.Error);
94 }
95 this.DialogResult = DialogResult.OK;
96 this.Hide();
97 }
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 }
111 private void cbApplyTransform_CheckedChanged(object sender, EventArgs e)
112 {
113 if (cbApplyTransform.Checked)
114 {
115 tbXslPath.Enabled = true;
116 bttnXslSelect.Enabled = true;
117 }
118 else
119 {
120 tbXslPath.Enabled = false;
121 bttnXslSelect.Enabled = false;
122 }
123 }
125 private void bttnXslSelect_Click(object sender, EventArgs e)
126 {
127 OpenFileDialog ofd = new OpenFileDialog();
129 ofd.InitialDirectory = Directory.GetCurrentDirectory() + "\\xsl";
130 ofd.Filter = "XSL Files|*.xsl";
131 DialogResult result = ofd.ShowDialog();
133 if (result == DialogResult.OK)
134 {
135 tbXslPath.Text = ofd.FileName;
136 }
138 }
139 }
140 }