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.

299 lines
12 KiB

@page "/Admin/Teacher/Teacher"
@inject Blazored.SessionStorage.ISessionStorageService sessionStorage
@inherits ListBase
@using Syncfusion.Blazor.Grids;
@using Syncfusion.Blazor.Buttons;
@using Syncfusion.Blazor.Spinner;
@using Syncfusion.Blazor.Notifications;
@using BlazorApp.Helper
@using BWPMModels;
@using BlazorApp.Controller;
<h1>Lehrer</h1>
<div class="col-lg-12 control-section">
<div class="content-wrapper">
<div class="row">
<SfGrid ID="Grid" DataSource="@GridData" @ref="Grid" AllowPaging="true" AllowSorting="true" >
<GridPageSettings PageCount="5" PageSizes="true"></GridPageSettings>
<GridEditSettings AllowAdding="false" AllowDeleting="false" AllowEditing="false" Mode="EditMode.Dialog" Dialog="DialogParams"></GridEditSettings>
<GridEvents OnActionBegin="OnBeginHandler" OnActionComplete="OnCompletedHandler" TValue="Lehrer" OnDataBound="RowDataBoundHandler" CommandClicked="CommandClickHandler"></GridEvents>
<GridColumns>
@* <GridColumn Type="ColumnType.CheckBox" AllowFiltering="false" AllowSorting="false" Width="60"></GridColumn>*@
<GridColumn Field=@nameof(Lehrer.ID) HeaderText="Id" IsPrimaryKey="true" AllowAdding="false" Width="60" Visible="true"></GridColumn>
<GridColumn Field=@nameof(Lehrer.anredeID) HeaderText="Anredeid" Width="100" Visible="false"></GridColumn>
<GridColumn Field=@nameof(Lehrer.name) HeaderText="Name" Width="100" Visible="true"></GridColumn>
<GridColumn Field=@nameof(Lehrer.vorname) HeaderText="Vorname" Width="100" Visible="true"></GridColumn>
<GridColumn Field=@nameof(Lehrer.tel) HeaderText="Tel" Width="100" Visible="true"></GridColumn>
<GridColumn Field=@nameof(Lehrer.handy) HeaderText="Handy" Width="100" Visible="true"></GridColumn>
<GridColumn Field=@nameof(Lehrer.email) HeaderText="Email" Width="100" Visible="true"></GridColumn>
@*<GridColumn Field=@nameof(Lehrer.schulhausID) HeaderText="Schulhaus" Width="100" Visible="true">*@
<GridForeignColumn Field=@nameof(Lehrer.schulhausID) HeaderText="Schulhaus" ForeignKeyValue=@nameof(BWPMModels.Schulhaus.bezeichnung) ForeignKeyField=@nameof(BWPMModels.Schulhaus.ID) ForeignDataSource="@Schulhaus" Width="100"></GridForeignColumn>
@*</GridColumn>
*@
@*<GridColumn Field=@nameof(Lehrer.briefanrede) HeaderText="Briefanrede" Width="100" Visible="true"></GridColumn>
<GridColumn Field=@nameof(Lehrer.mandantnr) HeaderText="Mandantnr" Width="100" Visible="true"></GridColumn>
<GridColumn Field=@nameof(Lehrer.aktiv) HeaderText="Aktiv" Width="100" Visible="true" DisplayAsCheckBox="true"></GridColumn>
<GridColumn Field=@nameof(Lehrer.erstellt_am) HeaderText="Erstellt_am" Width="100" Visible="true" Format="d" Type="ColumnType.Date"></GridColumn>
<GridColumn Field=@nameof(Lehrer.mutiert_am) HeaderText="Mutiert_am" Width="100" Visible="true" Format="d" Type="ColumnType.Date"></GridColumn>
<GridColumn Field=@nameof(Lehrer.mutierer) HeaderText="Mutierer" Width="100" Visible="true"></GridColumn>*@
<GridColumn Field=@nameof(Lehrer.userid) HeaderText="Userid" Width="100" Visible="false"></GridColumn>
<GridColumn HeaderText="Funktionen" Width="150">
<GridCommandColumns>
<GridCommandColumn Title="Lehrer-Daten" Type="CommandButtonType.None" ButtonOption="@(new CommandButtonOptions() {IconCss="fas fa-pen", CssClass="e-flat" })"></GridCommandColumn>
<GridCommandColumn Title="Schüler-Daten" Type="CommandButtonType.None" ButtonOption="@(new CommandButtonOptions() {IconCss="fas fa-user", CssClass="e-flat" })"></GridCommandColumn>
<GridCommandColumn Title="Löschen" Type="CommandButtonType.None" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-delete", CssClass="e-flat" })"></GridCommandColumn>
<GridCommandColumn Title="EMail" Type="CommandButtonType.None" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-mail", CssClass="e-flat" })"></GridCommandColumn>
</GridCommandColumns>
</GridColumn>
</GridColumns>
</SfGrid>
</div>
</div>
</div>
<div class="col-lg-12 control-section toast-default-section">
<SfToast ID="toast_default" @ref="ToastObj" Content="@ToastContent" Timeout="5000" Icon="e-meeting">
<ToastPosition X="Right" Y="Bottom"></ToastPosition>
<ToastAnimationSettings>
<ToastShowAnimationSettings Effect="@ShowAnimation"></ToastShowAnimationSettings>
<ToastHideAnimationSettings Effect="@HideAnimation"></ToastHideAnimationSettings>
</ToastAnimationSettings>
</SfToast>
</div>
<style>
.bootstrap4 #toast_default .e-meeting::before {
content: "\e763";
font-size: 20px;
}
.e-toast-container .e-toast {
background-color: lightgreen;
}
</style>
<style>
div#Grid_dialogEdit_wrapper {
max-height: none !important;
}
</style>
@code {
SfToast ToastObj;
private string ToastPosition = "Right";
private string ToastContent = "Daten erfolgreich gespeichert";
private ToastEffect ShowAnimation = ToastEffect.FadeIn;
private ToastEffect HideAnimation = ToastEffect.FadeOut;
}
@code{
private DialogSettings DialogParams = new DialogSettings { Width = "450px", Height = "750px" };
SfGrid<Lehrer> Grid { get; set; }
public List<BWPMModels.Lehrer> GridData { get; set; }
public List<BWPMModels.Lehrer> Lehrers { get; set; }
public List<BWPMModels.Lehrer> TmpLehrer { get; set; }
public List<BWPMModels.AspNetUsers> Users { get; set; }
public List<BWPMModels.Schulhaus> Schulhaus { get; set; }
string userid = "";
public static int? pkey { get; set; }
public bool Initial { get; set; } = true;
public bool ContinuePaging = true;
public bool InitialRender { get; set; }
public int Value = 0; // consider that value your querystring contains
public int foundrow = 0;
protected override void OnInitialized()
{
/// GridData = OrdersDetails.GetAllRecords();
GridData = BlazorApp.Controller.LehrerController.GetAllData();
Schulhaus = BlazorApp.Controller.SchulhausController.GetAllData();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
userid = await sessionStorage.GetItemAsync<string>("UserID");
if (userid == null)
{
var authState = await authenticationStateTask;
var userId = authState.User.Claims.FirstOrDefault().Value;
var user = authState.User;
if (user.Identity.IsAuthenticated)
{
await sessionStorage.SetItemAsync("UserID", userId);
}
else
{
await sessionStorage.SetItemAsync("UserID", userId);
}
}
}
private async Task OnBeginHandler(ActionEventArgs<BWPMModels.Lehrer> Args)
{
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
{
if (Args.Action == "Add")
{
Users = BlazorApp.Controller.AspNetUsersController.GetByUserName(Args.Data.email);
if (Users.Count !=0)
{
Args.Cancel = true;
ToastObj.CssClass = "e-toast-danger";
ToastContent = "Ein Benutzer mit der gleichen E-Mailadresse ist bereits vorhanden.";
StateHasChanged();
ToastObj.ShowAsync();
// Grid.Refresh();
return;
}
else {
Args.Data.erstellt_am = DateTime.Now;
Args.Data.mutierer = userid;
Args.Data.mutiert_am = DateTime.Now;
Args.Data.aktiv = true;
Args.Data.ID = BlazorApp.Controller.LehrerController.POST(Args.Data);
Value = Args.Data.ID;
}
}
else
{
TmpLehrer = BlazorApp.Controller.LehrerController.GetByEMail(Args.Data.email);
if (TmpLehrer.Count > 1)
{
Args.Cancel = true;
ToastObj.CssClass = "e-toast-danger";
ToastContent = "Die eingegebene Mail-Aadresse wird bereits verwendet.";
StateHasChanged();
ToastObj.ShowAsync();
// Grid.Refresh();
return;
}
Args.Data.mutierer = userid.ToString();
Args.Data.mutiert_am = DateTime.Now;
BlazorApp.Controller.LehrerController.PUT(Args.Data);
ToastObj.CssClass = "e-toast-success";
ToastContent = "Daten erfolgreich gespeichert";
StateHasChanged();
ToastObj.ShowAsync();
}
}
}
public async Task OnCompletedHandler(ActionEventArgs<BWPMModels.Lehrer> Args)
{
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
{
await Grid.SetRowData(Args.Data.ID, Args.Data);
double xx = 0;
Value = Args.Data.ID;
xx = await DataHandler();
await Grid.SelectRow(xx);
}
}
public async void RowDataBoundHandler(BeforeDataBoundArgs<BWPMModels.Lehrer> args)
{
if (!Initial)
{
//await Task.Delay(100);
//var Idx = await this.Grid.GetRowIndexByPrimaryKey(Convert.ToDouble(Value)); //get index value
//this.Grid.SelectRow(Convert.ToDouble(Idx));
}
Initial = false;
}
public async Task<double> DataHandler()
{
var PageCount = (GridData.Count / Grid.PageSettings.PageSize) + 1;
ContinuePaging = true;
var CurrentPage = 1;
Grid.Refresh();
await Grid.GoToPage(1);
for (int i = 1; i <= PageCount; i++)
{
List<Lehrer> Rows = await Grid.GetCurrentViewRecords(); // returns the current view data
for (int j = 0; j < Grid.PageSettings.PageSize; j++)
{
if (j < Rows.Count && Rows[j].ID == Value)
{
foundrow = j;
ContinuePaging = false; // prevent the default navigation
break;
}
}
if (ContinuePaging)
{
if (i >= PageCount)
{
i = 0;
}
await Grid.GoToPage(i + 1);
}
else
{
return foundrow;
}
}
return foundrow;
}
public void CommandClickHandler(CommandClickEventArgs<Lehrer> args)
{
if (args.CommandColumn.Title == "Lehrer-Daten")
{
NavigationManager.NavigateTo("/Teacher/TeacherContact/" + args.RowData.ID.ToString());
}
if (args.CommandColumn.Title == "Schüler-Daten")
{
NavigationManager.NavigateTo("/Teacher/TeacherStudent/" + args.RowData.ID.ToString());
}
if (args.CommandColumn.Title=="Berufsangebot"){
NavigationManager.NavigateTo("/Company/Berufsangebot/" + args.RowData.ID.ToString());
}
if (args.CommandColumn.Title=="Ansprechperson"){
NavigationManager.NavigateTo("/Company/CompanyContact/" + args.RowData.ID.ToString());
}
//Perform your custom command button click operation here. And also with the value in “args” you can differentiate the buttons, if having multiple custom command buttons.
}
}