Save a correct xml-file from extract

This commit is contained in:
Tommy Öman
2019-01-08 22:32:19 +01:00
parent e98a3bf3f5
commit 7558df9d62
4 changed files with 51 additions and 2 deletions

View File

@ -31,6 +31,8 @@
this.txtFileShower = new System.Windows.Forms.TextBox();
this.lblShowerFileName = new System.Windows.Forms.Label();
this.btnClose = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button();
this.saveXMLfileDialog = new System.Windows.Forms.SaveFileDialog();
this.SuspendLayout();
//
// txtFileShower
@ -67,11 +69,22 @@
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(626, 513);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(75, 23);
this.btnSave.TabIndex = 3;
this.btnSave.Text = "Spara fil";
this.btnSave.UseVisualStyleBackColor = true;
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// frmFileShower
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(813, 551);
this.Controls.Add(this.btnSave);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.lblShowerFileName);
this.Controls.Add(this.txtFileShower);
@ -87,5 +100,7 @@
private System.Windows.Forms.TextBox txtFileShower;
private System.Windows.Forms.Label lblShowerFileName;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.SaveFileDialog saveXMLfileDialog;
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -12,8 +13,11 @@ namespace tomcatAnalys
{
public partial class frmFileShower : Form
{
public string FileShowerFileName {
set { lblShowerFileName.Text = value; } }
public bool SparaMoejlighet { get; set; }
public string FileShowerFileName
{
set { lblShowerFileName.Text = value; }
}
public TextBox FileShowerBox { get; set; }
public frmFileShower()
{
@ -25,5 +29,30 @@ namespace tomcatAnalys
{
this.Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
string extraLine = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>";
string saveFilePath = "";
List<string> extract = new List<string>();
extract.Add(extraLine);
saveXMLfileDialog.Title = "Spara XML-filen";
if (saveXMLfileDialog.ShowDialog() == DialogResult.OK)
{
saveFilePath = saveXMLfileDialog.FileName;
foreach (var row in txtFileShower.Lines)
{
extract.Add(row);
}
File.WriteAllLines(saveFilePath, extract.ToArray());
txtFileShower.Text = "";
}
}
protected override void OnShown(EventArgs e)
{
btnSave.Visible = SparaMoejlighet;
base.OnShown(e);
}
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="saveXMLfileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -115,7 +115,9 @@ namespace tomcatAnalys
ListItem aktRad = (ListItem)lbInstances.Items[lbInstances.SelectedIndex];
fileWindow.FileShowerFileName = aktRad.GarantiNr + "-" + aktRad.GarantiJob;
fileWindow.FileShowerBox.Lines = aktRad.xmlRader;
fileWindow.SparaMoejlighet = true;
fileWindow.ShowDialog();
fileWindow.SparaMoejlighet = false;
}
private void lbInstances_Click(object sender, EventArgs e)