using Database;
using KlassenBIB;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SanSystem
{
///
///
///
public partial class frmNewProjekt : Form
{
///
///
///
public frmNewProjekt()
{
InitializeComponent();
}
private void btn_save_Click(object sender, EventArgs e)
{
using (var context = new SanVerwalterContext())
{
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();
}
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 == '\\')
{
e.Handled = true;
MessageBox.Show("Es sind keine Zeichen wie '/' oder '\\' erlaubt ");
txt_pro_nr.Focus();
}
}
}
}