merges export functions, removed the option for users to add or delete rows
This commit is contained in:
28
Form1.Designer.cs
generated
28
Form1.Designer.cs
generated
@@ -39,6 +39,8 @@ namespace it_projekt
|
|||||||
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.Department_Short = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.Department = 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.jsonRBtn = new System.Windows.Forms.RadioButton();
|
||||||
@@ -100,18 +102,22 @@ namespace it_projekt
|
|||||||
//
|
//
|
||||||
// dataGrid
|
// dataGrid
|
||||||
//
|
//
|
||||||
|
this.dataGrid.AllowUserToAddRows = false;
|
||||||
|
this.dataGrid.AllowUserToDeleteRows = false;
|
||||||
this.dataGrid.AllowUserToOrderColumns = true;
|
this.dataGrid.AllowUserToOrderColumns = true;
|
||||||
this.dataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
this.dataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
this.dataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
this.dataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||||
this.Id,
|
this.Id,
|
||||||
this.firstname,
|
this.firstname,
|
||||||
this.lastname,
|
this.lastname,
|
||||||
|
this.Department_Short,
|
||||||
|
this.Department,
|
||||||
this.creationDate,
|
this.creationDate,
|
||||||
this.markItem});
|
this.markItem});
|
||||||
this.dataGrid.Location = new System.Drawing.Point(12, 109);
|
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(543, 225);
|
this.dataGrid.Size = new System.Drawing.Size(743, 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);
|
||||||
//
|
//
|
||||||
@@ -133,6 +139,18 @@ namespace it_projekt
|
|||||||
this.lastname.Name = "lastname";
|
this.lastname.Name = "lastname";
|
||||||
this.lastname.ReadOnly = true;
|
this.lastname.ReadOnly = true;
|
||||||
//
|
//
|
||||||
|
// Department_Short
|
||||||
|
//
|
||||||
|
this.Department_Short.HeaderText = "Abteilungs Kürzel";
|
||||||
|
this.Department_Short.Name = "Department_Short";
|
||||||
|
this.Department_Short.ReadOnly = true;
|
||||||
|
//
|
||||||
|
// Department
|
||||||
|
//
|
||||||
|
this.Department.HeaderText = "Abteilung";
|
||||||
|
this.Department.Name = "Department";
|
||||||
|
this.Department.ReadOnly = true;
|
||||||
|
//
|
||||||
// creationDate
|
// creationDate
|
||||||
//
|
//
|
||||||
this.creationDate.HeaderText = "Erstellungssdatum";
|
this.creationDate.HeaderText = "Erstellungssdatum";
|
||||||
@@ -172,7 +190,7 @@ namespace it_projekt
|
|||||||
//
|
//
|
||||||
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(559, 336);
|
this.ClientSize = new System.Drawing.Size(758, 336);
|
||||||
this.Controls.Add(this.xmlRBtn);
|
this.Controls.Add(this.xmlRBtn);
|
||||||
this.Controls.Add(this.jsonRBtn);
|
this.Controls.Add(this.jsonRBtn);
|
||||||
this.Controls.Add(this.dataGrid);
|
this.Controls.Add(this.dataGrid);
|
||||||
@@ -200,13 +218,15 @@ namespace it_projekt
|
|||||||
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.DataGridView dataGrid;
|
private System.Windows.Forms.DataGridView dataGrid;
|
||||||
|
private System.Windows.Forms.RadioButton jsonRBtn;
|
||||||
|
private System.Windows.Forms.RadioButton xmlRBtn;
|
||||||
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 Department_Short;
|
||||||
|
private System.Windows.Forms.DataGridViewTextBoxColumn Department;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
65
Form1.cs
65
Form1.cs
@@ -22,9 +22,9 @@ namespace it_projekt
|
|||||||
private void exportBtn_Click(object sender, EventArgs e)
|
private void exportBtn_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (jsonRBtn.Checked)
|
if (jsonRBtn.Checked)
|
||||||
exportJSON();
|
export("All files (*.*)|*.*|json files (*.json)|*.json", "benutzer.json");
|
||||||
else
|
else
|
||||||
exportXML();
|
export("All files (*.*)|*.*|xml files (*.xml)|*.xml", "benutzer.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loginBtn_Click(object sender, EventArgs e)
|
private void loginBtn_Click(object sender, EventArgs e)
|
||||||
@@ -52,19 +52,17 @@ namespace it_projekt
|
|||||||
|
|
||||||
private void dataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
private void dataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportJSON()
|
private void export(string Filter, string FileName)
|
||||||
{
|
{
|
||||||
Stream myStream;
|
Stream myStream;
|
||||||
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
|
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
|
||||||
|
saveFileDialog1.Filter = Filter;
|
||||||
saveFileDialog1.Filter = "All files (*.*)|*.*|json files (*.json)|*.json";
|
|
||||||
saveFileDialog1.FilterIndex = 2;
|
saveFileDialog1.FilterIndex = 2;
|
||||||
saveFileDialog1.RestoreDirectory = true;
|
saveFileDialog1.RestoreDirectory = true;
|
||||||
saveFileDialog1.FileName = "benutzer.json";
|
saveFileDialog1.FileName = FileName;
|
||||||
|
|
||||||
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if ((myStream = saveFileDialog1.OpenFile()) != null)
|
if ((myStream = saveFileDialog1.OpenFile()) != null)
|
||||||
@@ -72,59 +70,34 @@ namespace it_projekt
|
|||||||
List<Person> markedUsers = new List<Person>();
|
List<Person> markedUsers = new List<Person>();
|
||||||
foreach (DataGridViewRow row in dataGrid.Rows)
|
foreach (DataGridViewRow row in dataGrid.Rows)
|
||||||
{
|
{
|
||||||
if (row.Cells[4].Value != null)
|
if (row.Cells[6].Value != null)
|
||||||
{
|
{
|
||||||
if (row.Cells[4].Value.ToString() == "True")
|
if (row.Cells[6].Value.ToString() == "True")
|
||||||
{
|
{
|
||||||
markedUsers.Add(db.Persons.Find(person => person.Id == row.Cells[0].Value.ToString()));
|
markedUsers.Add(db.Persons.Find(person => person.Id == row.Cells[0].Value.ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string json = JsonSerializer.Serialize(markedUsers);
|
|
||||||
StreamWriter sw = new StreamWriter(myStream);
|
StreamWriter sw = new StreamWriter(myStream);
|
||||||
sw.Write(json);
|
if (FileName.Contains("xml"))
|
||||||
sw.Flush();
|
|
||||||
sw.Close();
|
|
||||||
myStream.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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<Person> markedUsers = new List<Person>();
|
|
||||||
foreach (DataGridViewRow row in dataGrid.Rows)
|
|
||||||
{
|
{
|
||||||
if (row.Cells[4].Value != null)
|
var writer = new System.Xml.Serialization.XmlSerializer(typeof(List<Person>));
|
||||||
{
|
writer.Serialize(sw, markedUsers);
|
||||||
if (row.Cells[4].Value.ToString() == "True")
|
}
|
||||||
{
|
else //If xml is not selected, json is the only other option
|
||||||
markedUsers.Add(db.Persons.Find(person => person.Id == row.Cells[0].Value.ToString()));
|
{
|
||||||
}
|
string json = JsonSerializer.Serialize(markedUsers);
|
||||||
}
|
sw.Write(json);
|
||||||
}
|
}
|
||||||
StreamWriter sw = new StreamWriter(myStream);
|
|
||||||
var writer = new System.Xml.Serialization.XmlSerializer(typeof(List<Person>));
|
|
||||||
writer.Serialize(sw, markedUsers);
|
|
||||||
sw.Flush();
|
sw.Flush();
|
||||||
sw.Close();
|
sw.Close();
|
||||||
myStream.Close();
|
myStream.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void Form1_Load(object sender, EventArgs e)
|
private void Form1_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -137,7 +110,7 @@ namespace it_projekt
|
|||||||
|
|
||||||
private void xmlRBtn_CheckedChanged(object sender, EventArgs e)
|
private void xmlRBtn_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,12 @@
|
|||||||
<metadata name="lastname.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="lastname.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<metadata name="Department_Short.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="Department.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">
|
<metadata name="creationDate.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|||||||
Reference in New Issue
Block a user