add department sql join query, alter person model to fit department data

This commit is contained in:
2022-05-16 18:03:14 +02:00
parent 1a9e339119
commit 9b4980c204
4 changed files with 57 additions and 53 deletions

View File

@@ -16,13 +16,13 @@ namespace it_projekt
{
connection.Open();
string sql = "SELECT * FROM stammdaten";
string sql = "SELECT stammdaten.id, stammdaten.firstname, stammdaten.lastname, stammdaten.creationdate, abteilung.kuerzel, abteilung.name FROM `stammdaten` JOIN abteilung GROUP BY stammdaten.id; ";
MySqlCommand cmd = new MySqlCommand(sql, connection);
MySqlDataReader rdr = cmd.ExecuteReader();
Persons = new List<Person>();
while (rdr.Read())
{
Person p = new Person(rdr[0].ToString(), rdr[1].ToString(), rdr[2].ToString(), DateTime.Parse(rdr[3].ToString()));
Person p = new Person(rdr[0].ToString(), rdr[1].ToString(), rdr[2].ToString(), DateTime.Parse(rdr[3].ToString()), rdr[4].ToString(), rdr[5].ToString());
Persons.Add(p);
}

98
Form1.Designer.cs generated
View File

@@ -1,34 +1,34 @@

namespace it_projekt
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{

namespace it_projekt
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.loginBtn = new System.Windows.Forms.Button();
this.exportBtn = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
@@ -189,24 +189,24 @@ namespace it_projekt
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button loginBtn;
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.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;
}
#endregion
private System.Windows.Forms.Button loginBtn;
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.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.RadioButton jsonRBtn;
private System.Windows.Forms.RadioButton xmlRBtn;
}
}
}
}

View File

@@ -41,7 +41,7 @@ namespace it_projekt
}
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.department_short, person.department_long, person.CreationDate, false);
}
}

View File

@@ -12,17 +12,21 @@ namespace it_projekt
public string Lastname { get; set; }
public string Firstname { get; set; }
public DateTime CreationDate { get; set; }
public string department_short { get; set; }
public string department_long { get; set; }
public Person()
{
}
public Person(string Id, string Lastname, string Firstname, DateTime CreationDate)
public Person(string Id, string Lastname, string Firstname, DateTime CreationDate, string department_short, string department_long)
{
this.Id = Id;
this.Lastname = Lastname;
this.Firstname = Firstname;
this.CreationDate = CreationDate;
this.department_short = department_short;
this.department_long = department_long;
}
}
}