This commit is contained in:
2022-05-09 15:49:30 +02:00
parent c9f53a5d84
commit 0b97eb8780
3 changed files with 357 additions and 280 deletions

72
Form1.Designer.cs generated
View File

@@ -30,24 +30,25 @@ namespace it_projekt
private void InitializeComponent() private void InitializeComponent()
{ {
this.loginBtn = new System.Windows.Forms.Button(); this.loginBtn = new System.Windows.Forms.Button();
this.searchBtn = new System.Windows.Forms.Button(); this.exportBtn = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.userTxt = new System.Windows.Forms.TextBox(); this.userTxt = new System.Windows.Forms.TextBox();
this.passTxt = 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.dataGrid = new System.Windows.Forms.DataGridView();
this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.firstname = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.firstname = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.lastname = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.lastname = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.creationDate = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.creationDate = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.markItem = new System.Windows.Forms.DataGridViewCheckBoxColumn(); 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(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// loginBtn // loginBtn
// //
this.loginBtn.Location = new System.Drawing.Point(265, 184); this.loginBtn.Location = new System.Drawing.Point(271, 80);
this.loginBtn.Name = "loginBtn"; this.loginBtn.Name = "loginBtn";
this.loginBtn.Size = new System.Drawing.Size(75, 23); this.loginBtn.Size = new System.Drawing.Size(75, 23);
this.loginBtn.TabIndex = 0; this.loginBtn.TabIndex = 0;
@@ -55,15 +56,15 @@ namespace it_projekt
this.loginBtn.UseVisualStyleBackColor = true; this.loginBtn.UseVisualStyleBackColor = true;
this.loginBtn.Click += new System.EventHandler(this.loginBtn_Click); this.loginBtn.Click += new System.EventHandler(this.loginBtn_Click);
// //
// searchBtn // exportBtn
// //
this.searchBtn.Location = new System.Drawing.Point(708, 184); this.exportBtn.Location = new System.Drawing.Point(480, 80);
this.searchBtn.Name = "searchBtn"; this.exportBtn.Name = "exportBtn";
this.searchBtn.Size = new System.Drawing.Size(75, 23); this.exportBtn.Size = new System.Drawing.Size(75, 23);
this.searchBtn.TabIndex = 1; this.exportBtn.TabIndex = 1;
this.searchBtn.Text = "Suchen!"; this.exportBtn.Text = "Exportieren!";
this.searchBtn.UseVisualStyleBackColor = true; this.exportBtn.UseVisualStyleBackColor = true;
this.searchBtn.Click += new System.EventHandler(this.searchBtn_Click); this.exportBtn.Click += new System.EventHandler(this.exportBtn_Click);
// //
// label1 // label1
// //
@@ -97,14 +98,6 @@ namespace it_projekt
this.passTxt.Size = new System.Drawing.Size(100, 23); this.passTxt.Size = new System.Drawing.Size(100, 23);
this.passTxt.TabIndex = 5; 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 // dataGrid
// //
this.dataGrid.AllowUserToOrderColumns = true; this.dataGrid.AllowUserToOrderColumns = true;
@@ -115,10 +108,10 @@ namespace it_projekt
this.lastname, this.lastname,
this.creationDate, this.creationDate,
this.markItem}); this.markItem});
this.dataGrid.Location = new System.Drawing.Point(12, 213); this.dataGrid.Location = new System.Drawing.Point(12, 109);
this.dataGrid.Name = "dataGrid"; this.dataGrid.Name = "dataGrid";
this.dataGrid.RowTemplate.Height = 25; this.dataGrid.RowTemplate.Height = 25;
this.dataGrid.Size = new System.Drawing.Size(771, 225); this.dataGrid.Size = new System.Drawing.Size(543, 225);
this.dataGrid.TabIndex = 7; this.dataGrid.TabIndex = 7;
this.dataGrid.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGrid_CellContentClick); this.dataGrid.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGrid_CellContentClick);
// //
@@ -151,21 +144,47 @@ namespace it_projekt
this.markItem.HeaderText = "User Auswählen"; this.markItem.HeaderText = "User Auswählen";
this.markItem.Name = "markItem"; 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 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); 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.dataGrid);
this.Controls.Add(this.sqlTxt);
this.Controls.Add(this.passTxt); this.Controls.Add(this.passTxt);
this.Controls.Add(this.userTxt); this.Controls.Add(this.userTxt);
this.Controls.Add(this.label2); this.Controls.Add(this.label2);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Controls.Add(this.searchBtn); this.Controls.Add(this.exportBtn);
this.Controls.Add(this.loginBtn); this.Controls.Add(this.loginBtn);
this.Name = "Form1"; this.Name = "Form1";
this.Text = "Form1"; this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@@ -175,18 +194,19 @@ namespace it_projekt
#endregion #endregion
private System.Windows.Forms.Button loginBtn; 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 label1;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox userTxt; private System.Windows.Forms.TextBox userTxt;
private System.Windows.Forms.TextBox passTxt; private System.Windows.Forms.TextBox passTxt;
private System.Windows.Forms.TextBox sqlTxt;
private System.Windows.Forms.DataGridView dataGrid; private System.Windows.Forms.DataGridView dataGrid;
private System.Windows.Forms.DataGridViewTextBoxColumn Id; private System.Windows.Forms.DataGridViewTextBoxColumn Id;
private System.Windows.Forms.DataGridViewTextBoxColumn firstname; private System.Windows.Forms.DataGridViewTextBoxColumn firstname;
private System.Windows.Forms.DataGridViewTextBoxColumn lastname; private System.Windows.Forms.DataGridViewTextBoxColumn lastname;
private System.Windows.Forms.DataGridViewTextBoxColumn creationDate; 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;
} }
} }

View File

@@ -1,12 +1,8 @@
using MySql.Data.MySqlClient; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.IO;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Text.Json;
using System.Windows.Forms; using System.Windows.Forms;
@@ -14,40 +10,32 @@ namespace it_projekt
{ {
public partial class Form1 : Form public partial class Form1 : Form
{ {
private Database db = null;
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
} }
private void searchBtn_Click(object sender, EventArgs e) private void exportBtn_Click(object sender, EventArgs e)
{ {
foreach(DataGridViewRow row in dataGrid.Rows) exportJSON();
{
List<int> markedUsers = new List<int>();
if (row.Cells[4].Value != null)
{
if (row.Cells[4].Value.ToString() == "True")
{
MessageBox.Show("geht");
}
}
}
} }
private void loginBtn_Click(object sender, EventArgs e) private void loginBtn_Click(object sender, EventArgs e)
{ {
LoadUsersFromTable(userTxt.Text,passTxt.Text); LoadUsersFromTable(this.userTxt.Text, this.passTxt.Text);
} }
public void LoadUsersFromTable(string user, string password) public void LoadUsersFromTable(string user, string password)
{ {
Database db = new Database(user, password); if (db == null)
{
db = new Database(user, password);
}
foreach (Person person in db.Persons) foreach (Person person in db.Persons)
{ {
this.dataGrid.Rows.Add(person.Id, person.Firstname, person.Lastname, person.CreationDate, false); this.dataGrid.Rows.Add(person.Id, person.Firstname, person.Lastname, person.CreationDate, false);
@@ -58,5 +46,59 @@ namespace it_projekt
{ {
} }
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<Person> markedUsers = new List<Person>();
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;
}
} }
} }

View File

@@ -72,4 +72,19 @@
<metadata name="markItem.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="markItem.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="firstname.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="lastname.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="creationDate.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="markItem.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root> </root>