You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
5.9 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using BWPMModels;
using BlazorApp.Helper;
using Newtonsoft.Json;
using System.Data;
using Microsoft.AspNetCore.Mvc;
using System.Net.NetworkInformation;
namespace BlazorApp.Controller
{
public class ZuteilungController : ControllerBase
{
public static List<Zuteilung> GetAllData()
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata("Select * from Zuteilung", false, true);
return dbh.ConvertDataTable<Zuteilung>(dbh.dsdaten.Tables[0]);
}
public static List<Zuteilung> GetByID(int ID)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata("Select * from Zuteilung where id=" + ID.ToString(), false, true);
return dbh.ConvertDataTable<Zuteilung>(dbh.dsdaten.Tables[0]);
}
public static List<ZuteilungView> GetZuteilungBySchuelerID(int ID)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata("Select * from View_Schuelerzuteilung where schuelerid=" + ID.ToString() + " order by prioritaet", false, true);
return dbh.ConvertDataTable<ZuteilungView>(dbh.dsdaten.Tables[0]);
}
public static List<View_Zuteilung> GetZuteilungen(string SchuelerNr, string BerufID)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata("Select * from View_Zugeteilt where BerufID=" + BerufID + " and id<>" + SchuelerNr, false, true);
return dbh.ConvertDataTable<View_Zuteilung>(dbh.dsdaten.Tables[0]);
}
public static List<Zuteilung> GetLast()
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata("Select top 1 * from Zuteilung order by mutiert_am desc", false, true);
return dbh.ConvertDataTable<Zuteilung>(dbh.dsdaten.Tables[0]);
}
public static List<Zuteilung> GetLastByMutierer(string Mutierer)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata("Select top 1 * from Zuteilung where mutierer='" + Mutierer + "' order by mutiert_am desc", false, true);
return dbh.ConvertDataTable<Zuteilung>(dbh.dsdaten.Tables[0]);
}
public static List<Zuteilung> GetbyUserSQL(string SQL)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata(SQL, false, true);
return dbh.ConvertDataTable<Zuteilung>(dbh.dsdaten.Tables[0]);
}
public static int POST(Zuteilung Zuteilungdata)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabeldata_for_Update("Select top 1 * from [Zuteilung] where id=-1", false, true);
DataRow dr = dbh.dsdaten.Tables[0].NewRow();
Zuteilungdata.GetType().GetProperties().ToList().ForEach(f =>
{
try
{
if (f.PropertyType == typeof(DateTime))
{
dr[f.Name] = (DateTime)f.GetValue(Zuteilungdata, null);
}
else
{
dr[f.Name] = f.GetValue(Zuteilungdata, null);
}
}
catch (Exception ex)
{
string s = ex.Message;
}
});
dbh.dsdaten.Tables[0].Rows.Add(dr);
dbh.Update_Tabeldata();
List<Zuteilung> tmplst = GetLastByMutierer(Zuteilungdata.mutierer);
return tmplst.First<Zuteilung>().ID;
}
public static void PUT(Zuteilung Zuteilungdata)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabeldata_for_Update("Select top 1 * from [Zuteilung] where id=" + Zuteilungdata.ID.ToString(), false, true);
DataRow dr = dbh.dsdaten.Tables[0].Rows[0];
Zuteilungdata.GetType().GetProperties().ToList().ForEach(f =>
{
try
{
if (f.PropertyType == typeof(DateTime))
{
dr[f.Name] = (DateTime)f.GetValue(Zuteilungdata, null);
}
else
{
dr[f.Name] = f.GetValue(Zuteilungdata, null);
}
}
catch (Exception ex)
{
string s = ex.Message;
}
});
dbh.Update_Tabeldata();
}
public static void DELETE(Zuteilung Zuteilungdata)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabeldata_for_Update("delete from [Zuteilung] where id=" + Zuteilungdata.ID.ToString(), false, true);
}
public static void Inaktivate(int ZuteilungID, string mutierer)
{
dbhelper dbh = new dbhelper();
dbh.Exec_SQL("update zuteilung set aktiv=0, mutierer='" + mutierer + "', mutiert_am=getdate() where ID=" + ZuteilungID.ToString());
}
public static List<View_Offene_Plaetze> GetOffenePlaetze(int Berufid, int KlasseTypID)
{
dbhelper dbh = new dbhelper();
dbh.add_sp_param("berufnr", Berufid.ToString());
dbh.add_sp_param("klassentyp", KlasseTypID.ToString());
dbh.Get_Tabledata("get_offene_plaetze", true, false);
return dbh.ConvertDataTable<View_Offene_Plaetze>(dbh.dsdaten.Tables[0]);
}
public static void insert_zuteilung(int schuelerid, int berufid)
{
dbhelper dbh = new dbhelper();
dbh.add_sp_param("schuelerid", schuelerid.ToString());
dbh.add_sp_param("berufid", berufid.ToString());
dbh.Get_Tabledata("Zuteilung_Manuell", true, false);
}
//public static Zuteilen(int firmaberufid, int schuelerid)
//{
//}
}
}