From 0b97eb8780cedab3d9f91e8fa6cde4000a49de27 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 9 May 2022 15:49:30 +0200 Subject: [PATCH] merged --- Form1.Designer.cs | 308 ++++++++++++++++++++++++---------------------- Form1.cs | 166 +++++++++++++++---------- Form1.resx | 163 +++++++++++++----------- 3 files changed, 357 insertions(+), 280 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 6a8ec5c..7919e90 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -29,164 +29,184 @@ namespace it_projekt /// private void InitializeComponent() { - this.loginBtn = new System.Windows.Forms.Button(); - this.searchBtn = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.userTxt = new System.Windows.Forms.TextBox(); - this.passTxt = new System.Windows.Forms.TextBox(); - this.sqlTxt = new System.Windows.Forms.TextBox(); - this.dataGrid = new System.Windows.Forms.DataGridView(); - this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.firstname = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.lastname = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.creationDate = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.markItem = new System.Windows.Forms.DataGridViewCheckBoxColumn(); - ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).BeginInit(); - this.SuspendLayout(); - // - // loginBtn - // - this.loginBtn.Location = new System.Drawing.Point(265, 184); - this.loginBtn.Name = "loginBtn"; - this.loginBtn.Size = new System.Drawing.Size(75, 23); - this.loginBtn.TabIndex = 0; - this.loginBtn.Text = "Login"; - this.loginBtn.UseVisualStyleBackColor = true; - this.loginBtn.Click += new System.EventHandler(this.loginBtn_Click); - // - // searchBtn - // - this.searchBtn.Location = new System.Drawing.Point(708, 184); - this.searchBtn.Name = "searchBtn"; - this.searchBtn.Size = new System.Drawing.Size(75, 23); - this.searchBtn.TabIndex = 1; - this.searchBtn.Text = "Suchen!"; - this.searchBtn.UseVisualStyleBackColor = true; - this.searchBtn.Click += new System.EventHandler(this.searchBtn_Click); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(31, 58); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(83, 15); - this.label1.TabIndex = 2; - this.label1.Text = "Benutzername"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(31, 84); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(54, 15); - this.label2.TabIndex = 3; - this.label2.Text = "Passwort"; - // - // userTxt - // - this.userTxt.Location = new System.Drawing.Point(120, 55); - this.userTxt.Name = "userTxt"; - this.userTxt.Size = new System.Drawing.Size(100, 23); - this.userTxt.TabIndex = 4; - // - // passTxt - // - this.passTxt.Location = new System.Drawing.Point(120, 80); - this.passTxt.Name = "passTxt"; - this.passTxt.Size = new System.Drawing.Size(100, 23); - this.passTxt.TabIndex = 5; - // - // sqlTxt - // - this.sqlTxt.Location = new System.Drawing.Point(358, 12); - this.sqlTxt.Multiline = true; - this.sqlTxt.Name = "sqlTxt"; - this.sqlTxt.Size = new System.Drawing.Size(335, 195); - this.sqlTxt.TabIndex = 6; - // - // dataGrid - // - this.dataGrid.AllowUserToOrderColumns = true; - this.dataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.Id, - this.firstname, - this.lastname, - this.creationDate, - this.markItem}); - this.dataGrid.Location = new System.Drawing.Point(12, 213); - this.dataGrid.Name = "dataGrid"; - this.dataGrid.RowTemplate.Height = 25; - this.dataGrid.Size = new System.Drawing.Size(771, 225); - this.dataGrid.TabIndex = 7; - this.dataGrid.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGrid_CellContentClick); - // - // Id - // - this.Id.HeaderText = "NutzerId"; - this.Id.Name = "Id"; - this.Id.ReadOnly = true; - // - // firstname - // - this.firstname.HeaderText = "Vorname"; - this.firstname.Name = "firstname"; - this.firstname.ReadOnly = true; - // - // lastname - // - this.lastname.HeaderText = "Nachname"; - this.lastname.Name = "lastname"; - this.lastname.ReadOnly = true; - // - // creationDate - // - this.creationDate.HeaderText = "Erstellungssdatum"; - this.creationDate.Name = "creationDate"; - this.creationDate.ReadOnly = true; - // - // markItem - // - this.markItem.HeaderText = "User Auswählen"; - this.markItem.Name = "markItem"; - // - // Form1 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.dataGrid); - this.Controls.Add(this.sqlTxt); - this.Controls.Add(this.passTxt); - this.Controls.Add(this.userTxt); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); - this.Controls.Add(this.searchBtn); - this.Controls.Add(this.loginBtn); - this.Name = "Form1"; - this.Text = "Form1"; - ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - + this.loginBtn = new System.Windows.Forms.Button(); + this.exportBtn = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.userTxt = new System.Windows.Forms.TextBox(); + this.passTxt = new System.Windows.Forms.TextBox(); + this.dataGrid = new System.Windows.Forms.DataGridView(); + this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.firstname = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.lastname = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.creationDate = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.markItem = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.jsonRBtn = new System.Windows.Forms.RadioButton(); + this.xmlRBtn = new System.Windows.Forms.RadioButton(); + ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).BeginInit(); + this.SuspendLayout(); + // + // loginBtn + // + this.loginBtn.Location = new System.Drawing.Point(271, 80); + this.loginBtn.Name = "loginBtn"; + this.loginBtn.Size = new System.Drawing.Size(75, 23); + this.loginBtn.TabIndex = 0; + this.loginBtn.Text = "Login"; + this.loginBtn.UseVisualStyleBackColor = true; + this.loginBtn.Click += new System.EventHandler(this.loginBtn_Click); + // + // exportBtn + // + this.exportBtn.Location = new System.Drawing.Point(480, 80); + this.exportBtn.Name = "exportBtn"; + this.exportBtn.Size = new System.Drawing.Size(75, 23); + this.exportBtn.TabIndex = 1; + this.exportBtn.Text = "Exportieren!"; + this.exportBtn.UseVisualStyleBackColor = true; + this.exportBtn.Click += new System.EventHandler(this.exportBtn_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(31, 58); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(83, 15); + this.label1.TabIndex = 2; + this.label1.Text = "Benutzername"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(31, 84); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(54, 15); + this.label2.TabIndex = 3; + this.label2.Text = "Passwort"; + // + // userTxt + // + this.userTxt.Location = new System.Drawing.Point(120, 55); + this.userTxt.Name = "userTxt"; + this.userTxt.Size = new System.Drawing.Size(100, 23); + this.userTxt.TabIndex = 4; + // + // passTxt + // + this.passTxt.Location = new System.Drawing.Point(120, 80); + this.passTxt.Name = "passTxt"; + this.passTxt.Size = new System.Drawing.Size(100, 23); + this.passTxt.TabIndex = 5; + // + // dataGrid + // + this.dataGrid.AllowUserToOrderColumns = true; + this.dataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Id, + this.firstname, + this.lastname, + this.creationDate, + this.markItem}); + this.dataGrid.Location = new System.Drawing.Point(12, 109); + this.dataGrid.Name = "dataGrid"; + this.dataGrid.RowTemplate.Height = 25; + this.dataGrid.Size = new System.Drawing.Size(543, 225); + this.dataGrid.TabIndex = 7; + this.dataGrid.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGrid_CellContentClick); + // + // Id + // + this.Id.HeaderText = "NutzerId"; + this.Id.Name = "Id"; + this.Id.ReadOnly = true; + // + // firstname + // + this.firstname.HeaderText = "Vorname"; + this.firstname.Name = "firstname"; + this.firstname.ReadOnly = true; + // + // lastname + // + this.lastname.HeaderText = "Nachname"; + this.lastname.Name = "lastname"; + this.lastname.ReadOnly = true; + // + // creationDate + // + this.creationDate.HeaderText = "Erstellungssdatum"; + this.creationDate.Name = "creationDate"; + this.creationDate.ReadOnly = true; + // + // markItem + // + this.markItem.HeaderText = "User Auswählen"; + this.markItem.Name = "markItem"; + // + // jsonRBtn + // + this.jsonRBtn.AutoSize = true; + this.jsonRBtn.Location = new System.Drawing.Point(380, 54); + this.jsonRBtn.Name = "jsonRBtn"; + this.jsonRBtn.Size = new System.Drawing.Size(53, 19); + this.jsonRBtn.TabIndex = 8; + this.jsonRBtn.TabStop = true; + this.jsonRBtn.Text = "JSON"; + this.jsonRBtn.UseVisualStyleBackColor = true; + this.jsonRBtn.CheckedChanged += new System.EventHandler(this.jsonRBtn_CheckedChanged); + // + // xmlRBtn + // + this.xmlRBtn.AutoSize = true; + this.xmlRBtn.Location = new System.Drawing.Point(380, 80); + 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); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(559, 336); + this.Controls.Add(this.xmlRBtn); + this.Controls.Add(this.jsonRBtn); + this.Controls.Add(this.dataGrid); + this.Controls.Add(this.passTxt); + this.Controls.Add(this.userTxt); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.exportBtn); + this.Controls.Add(this.loginBtn); + this.Name = "Form1"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Form1_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion private System.Windows.Forms.Button loginBtn; - private System.Windows.Forms.Button searchBtn; + private System.Windows.Forms.Button exportBtn; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox userTxt; private System.Windows.Forms.TextBox passTxt; - private System.Windows.Forms.TextBox sqlTxt; private System.Windows.Forms.DataGridView dataGrid; private System.Windows.Forms.DataGridViewTextBoxColumn Id; private System.Windows.Forms.DataGridViewTextBoxColumn firstname; private System.Windows.Forms.DataGridViewTextBoxColumn lastname; private System.Windows.Forms.DataGridViewTextBoxColumn creationDate; - private System.Windows.Forms.DataGridViewCheckBoxColumn markItem; + private System.Windows.Forms.DataGridViewCheckBoxColumn markItem; + private System.Windows.Forms.RadioButton jsonRBtn; + private System.Windows.Forms.RadioButton xmlRBtn; } } diff --git a/Form1.cs b/Form1.cs index 911afb1..b9b9da0 100644 --- a/Form1.cs +++ b/Form1.cs @@ -1,62 +1,104 @@ -using MySql.Data.MySqlClient; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - - -namespace it_projekt -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - - - private void searchBtn_Click(object sender, EventArgs e) - { - foreach(DataGridViewRow row in dataGrid.Rows) - { - List markedUsers = new List(); - if (row.Cells[4].Value != null) - { - if (row.Cells[4].Value.ToString() == "True") - { - MessageBox.Show("geht"); - } - } - - - } - - } - - private void loginBtn_Click(object sender, EventArgs e) - { - LoadUsersFromTable(userTxt.Text,passTxt.Text); - } - - - - public void LoadUsersFromTable(string user, string password) - { - Database db = new Database(user, password); - foreach (Person person in db.Persons) - { - this.dataGrid.Rows.Add(person.Id, person.Firstname, person.Lastname, person.CreationDate, false); - } - } - - private void dataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e) - { - - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Text.Json; +using System.Windows.Forms; + + +namespace it_projekt +{ + public partial class Form1 : Form + { + + private Database db = null; + public Form1() + { + InitializeComponent(); + } + + + private void exportBtn_Click(object sender, EventArgs e) + { + exportJSON(); + } + + private void loginBtn_Click(object sender, EventArgs e) + { + LoadUsersFromTable(this.userTxt.Text, this.passTxt.Text); + } + + + + public void LoadUsersFromTable(string user, string password) + { + if (db == null) + { + db = new Database(user, password); + } + foreach (Person person in db.Persons) + { + this.dataGrid.Rows.Add(person.Id, person.Firstname, person.Lastname, person.CreationDate, false); + } + } + + private void dataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + + private void exportJSON() + { + Stream myStream; + SaveFileDialog saveFileDialog1 = new SaveFileDialog(); + + saveFileDialog1.Filter = "All files (*.*)|*.*|json files (*.json)|*.json"; + saveFileDialog1.FilterIndex = 2; + saveFileDialog1.RestoreDirectory = true; + saveFileDialog1.FileName = "benutzer.json"; + + 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())); + } + } + } + string json = JsonSerializer.Serialize(markedUsers); + StreamWriter sw = new StreamWriter(myStream); + sw.Write(json); + sw.Flush(); + sw.Close(); + myStream.Close(); + } + } + } + + private void Form1_Load(object sender, EventArgs e) + { + + } + + 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 11cd2a1..34619f1 100644 --- a/Form1.resx +++ b/Form1.resx @@ -1,75 +1,90 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - True - - - True - - - True - - - True - - - True - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + \ No newline at end of file