EF core added

This commit is contained in:
Damian Wessels
2023-01-14 12:20:47 +01:00
parent 12fa97bc28
commit 1c4f581f28
24 changed files with 719 additions and 53 deletions

View File

@@ -25,26 +25,30 @@ namespace SanSystem
InitializeComponent();
}
private bool project_already_excist(string projektnummer)
{
return Datenbank.Instance.TeufelDB.Projekte.FindAll(x => x.Nummer.Equals(projektnummer)).Count > 0;
}
private void btn_save_Click(object sender, EventArgs e)
{
if(project_already_excist(txt_pro_nr.Text))
using (var context = new SanVerwalterContext())
{
MessageBox.Show(string.Format("Projekt mit den nummer {0} excistiert bereits. Projekt wird nicht angelegt", txt_pro_nr.Text));
return;
if (project_already_exist(context, txt_pro_nr.Text))
{
MessageBox.Show(string.Format("Projekt mit den nummer {0} excistiert bereits. Projekt wird nicht angelegt", txt_pro_nr.Text));
return;
}
Projekt projekt = new Projekt();
projekt.Nummer = txt_pro_nr.Text;
projekt.Ort = txt_ort.Text;
context.Projekte.Add(projekt);
context.SaveChanges();
}
Projekt projekt = new Projekt();
projekt.Nummer = txt_pro_nr.Text;
projekt.Ort = txt_ort.Text;
Global.Instance.SetProjekt(projekt);
this.Close();
//Global.Instance.ChangeProjekt(txt_pro_nr.Text);
}
private bool project_already_exist(SanVerwalterContext context, string text)
{
return context.Projekte.Count(x => x.Nummer.Equals(text)) > 0;
}
private void txt_pro_nr_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == '/' || e.KeyChar == '\\')