From 84ce1818a4058f4778032281ff011ec754619281 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 9 May 2022 15:59:05 +0200 Subject: [PATCH] working --- Form1.Designer.cs | 2 +- Form1.cs | 48 ++++++++++++++++++++++++++++++++++++++++------- Form1.resx | 15 --------------- Person.cs | 6 +++++- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 7919e90..7db3143 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -147,6 +147,7 @@ namespace it_projekt // jsonRBtn // this.jsonRBtn.AutoSize = true; + this.jsonRBtn.Checked = true; this.jsonRBtn.Location = new System.Drawing.Point(380, 54); this.jsonRBtn.Name = "jsonRBtn"; this.jsonRBtn.Size = new System.Drawing.Size(53, 19); @@ -163,7 +164,6 @@ namespace it_projekt this.xmlRBtn.Name = "xmlRBtn"; this.xmlRBtn.Size = new System.Drawing.Size(49, 19); this.xmlRBtn.TabIndex = 9; - this.xmlRBtn.TabStop = true; this.xmlRBtn.Text = "XML"; this.xmlRBtn.UseVisualStyleBackColor = true; this.xmlRBtn.CheckedChanged += new System.EventHandler(this.xmlRBtn_CheckedChanged); diff --git a/Form1.cs b/Form1.cs index b9b9da0..322d948 100644 --- a/Form1.cs +++ b/Form1.cs @@ -20,7 +20,10 @@ namespace it_projekt private void exportBtn_Click(object sender, EventArgs e) { - exportJSON(); + if (jsonRBtn.Checked) + exportJSON(); + else + exportXML(); } private void loginBtn_Click(object sender, EventArgs e) @@ -82,6 +85,41 @@ namespace it_projekt } } + private void exportXML() + { + Stream myStream; + SaveFileDialog saveFileDialog1 = new SaveFileDialog(); + + saveFileDialog1.Filter = "All files (*.*)|*.*|xml files (*.xml)|*.xml"; + saveFileDialog1.FilterIndex = 2; + saveFileDialog1.RestoreDirectory = true; + saveFileDialog1.FileName = "benutzer.xml"; + + if (saveFileDialog1.ShowDialog() == DialogResult.OK) + { + if ((myStream = saveFileDialog1.OpenFile()) != null) + { + List markedUsers = new List(); + foreach (DataGridViewRow row in dataGrid.Rows) + { + if (row.Cells[4].Value != null) + { + if (row.Cells[4].Value.ToString() == "True") + { + markedUsers.Add(db.Persons.Find(person => person.Id == row.Cells[0].Value.ToString())); + } + } + } + StreamWriter sw = new StreamWriter(myStream); + var writer = new System.Xml.Serialization.XmlSerializer(typeof(List)); + writer.Serialize(sw, markedUsers); + sw.Flush(); + sw.Close(); + myStream.Close(); + } + } + } + private void Form1_Load(object sender, EventArgs e) { @@ -89,16 +127,12 @@ namespace it_projekt private void jsonRBtn_CheckedChanged(object sender, EventArgs e) { - xmlRBtn.Checked = false; - if (!jsonRBtn.Checked) - jsonRBtn.Checked = true; + } private void xmlRBtn_CheckedChanged(object sender, EventArgs e) { - xmlRBtn.Checked = false; - if (!xmlRBtn.Checked) - xmlRBtn.Checked = true; + } } } diff --git a/Form1.resx b/Form1.resx index 34619f1..1294763 100644 --- a/Form1.resx +++ b/Form1.resx @@ -72,19 +72,4 @@ True - - True - - - True - - - True - - - True - - - True - \ No newline at end of file diff --git a/Person.cs b/Person.cs index 15bf913..c40df5d 100644 --- a/Person.cs +++ b/Person.cs @@ -6,13 +6,17 @@ using System.Threading.Tasks; namespace it_projekt { - class Person + public class Person { public string Id { get; set; } public string Lastname { get; set; } public string Firstname { get; set; } public DateTime CreationDate { get; set; } + public Person() + { + + } public Person(string Id, string Lastname, string Firstname, DateTime CreationDate) { this.Id = Id;