add inital idea, not working! entityframeworkgit add ./git add ./ ahaaaaaha
This commit is contained in:
27
Database.cs
Normal file
27
Database.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Data.Entity;
|
||||||
|
|
||||||
|
namespace it_projekt
|
||||||
|
{
|
||||||
|
class Database : DbContext
|
||||||
|
{
|
||||||
|
public DbSet<Person> persons { get; set; }
|
||||||
|
|
||||||
|
public Database()
|
||||||
|
: base()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public Database(DbConnection existingConnection, bool contextOwnsConnection)
|
||||||
|
: base(existingConnection, contextOwnsConnection)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
107
Form1.Designer.cs
generated
107
Form1.Designer.cs
generated
@@ -29,13 +29,118 @@ namespace it_projekt
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.components = new System.ComponentModel.Container();
|
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();
|
||||||
|
((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.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;
|
||||||
|
//
|
||||||
|
// Form1
|
||||||
|
//
|
||||||
|
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(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";
|
this.Text = "Form1";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Button loginBtn;
|
||||||
|
private System.Windows.Forms.Button searchBtn;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
61
Form1.cs
61
Form1.cs
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using MySql.Data.MySqlClient;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@@ -8,6 +9,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
|
||||||
namespace it_projekt
|
namespace it_projekt
|
||||||
{
|
{
|
||||||
public partial class Form1 : Form
|
public partial class Form1 : Form
|
||||||
@@ -17,5 +19,62 @@ namespace it_projekt
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void searchBtn_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loginBtn_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadUsersFromTable("","");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void LoadUsersFromTable(string user, string password)
|
||||||
|
{
|
||||||
|
string connectionString = "server=localhost;port=3306;database=stammdaten;User Id=" + user + ";Password=" + password + ";";
|
||||||
|
|
||||||
|
using (MySqlConnection connection = new MySqlConnection(connectionString))
|
||||||
|
{
|
||||||
|
// Create database if not exists
|
||||||
|
using (Database contextDB = new Database(connection, false))
|
||||||
|
{
|
||||||
|
contextDB.Database.CreateIfNotExists();
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.Open();
|
||||||
|
MySqlTransaction transaction = connection.BeginTransaction();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// DbConnection that is already opened
|
||||||
|
using (Database context = new Database(connection, false))
|
||||||
|
{
|
||||||
|
|
||||||
|
// Interception/SQL logging
|
||||||
|
context.Database.Log = (string message) => { Console.WriteLine(message); };
|
||||||
|
|
||||||
|
// Passing an existing transaction to the context
|
||||||
|
context.Database.UseTransaction(transaction);
|
||||||
|
|
||||||
|
// DbSet.AddRange
|
||||||
|
List<Person> persons = new List<Person>();
|
||||||
|
persons = context.persons.ToList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
Form1.resx
62
Form1.resx
@@ -1,64 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<root>
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
|||||||
16
Person.cs
Normal file
16
Person.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace it_projekt
|
||||||
|
{
|
||||||
|
class Person
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Lastname { get; set; }
|
||||||
|
public string Firstname { get; set; }
|
||||||
|
public DateTime CreationDate { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
# it-projekt
|
# it-projekt
|
||||||
|
|
||||||
SUPER PROJEKT, ICH SAGS EUCH
|
SUPER PROJEKT, ICH SAGS EUCH, schw<68>re!
|
||||||
@@ -7,4 +7,9 @@
|
|||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="EntityFramework" Version="6.4.4" />
|
||||||
|
<PackageReference Include="MySql.Data" Version="8.0.29" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user