From 7558df9d62e6847c979a8e307aaf8b9ef1843198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Tue, 8 Jan 2019 22:32:19 +0100 Subject: [PATCH] Save a correct xml-file from extract --- tomcatAnalys/frmFileShower.Designer.cs | 15 ++++++++++++ tomcatAnalys/frmFileShower.cs | 33 ++++++++++++++++++++++++-- tomcatAnalys/frmFileShower.resx | 3 +++ tomcatAnalys/frmStart.cs | 2 ++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/tomcatAnalys/frmFileShower.Designer.cs b/tomcatAnalys/frmFileShower.Designer.cs index df4086f..45da48f 100644 --- a/tomcatAnalys/frmFileShower.Designer.cs +++ b/tomcatAnalys/frmFileShower.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/tomcatAnalys/frmFileShower.cs b/tomcatAnalys/frmFileShower.cs index b297050..1b0c17d 100644 --- a/tomcatAnalys/frmFileShower.cs +++ b/tomcatAnalys/frmFileShower.cs @@ -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 = ""; + string saveFilePath = ""; + List extract = new List(); + 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); + } } } diff --git a/tomcatAnalys/frmFileShower.resx b/tomcatAnalys/frmFileShower.resx index 1af7de1..1ef8879 100644 --- a/tomcatAnalys/frmFileShower.resx +++ b/tomcatAnalys/frmFileShower.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/tomcatAnalys/frmStart.cs b/tomcatAnalys/frmStart.cs index f9bce01..16656a8 100644 --- a/tomcatAnalys/frmStart.cs +++ b/tomcatAnalys/frmStart.cs @@ -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)