diff --git a/Ministreliy/Components/App.razor b/Ministreliy/Components/App.razor index 543c8b7..47c51e4 100644 --- a/Ministreliy/Components/App.razor +++ b/Ministreliy/Components/App.razor @@ -5,7 +5,7 @@ - + @@ -14,6 +14,7 @@ + diff --git a/Ministreliy/Components/Pages/Database.razor b/Ministreliy/Components/Pages/Database.razor index 645fd31..5448148 100644 --- a/Ministreliy/Components/Pages/Database.razor +++ b/Ministreliy/Components/Pages/Database.razor @@ -1,23 +1,72 @@ @page "/database" +@using Ministreliy.Models +@using Newtonsoft.Json +@using System.Text +@inject IJSRuntime JS +@inject NavigationManager NavManager База данных - + +
+ @* + *@ +
+ +
+
+ + + + @if (listDeviceTypes.Count == 0 || listDeviceItems.Count == 0) + { +

@messageStatus

+ } @code { - private int currentCount = 0; + public static List? listDeviceTypes = new(); + public static List? listDeviceItems = new(); + public static HttpClient httpClient = new(); - private void IncrementCount() + string? messageStatus = "Получаю данные..."; + + protected override async Task OnInitializedAsync() { - currentCount++; + httpClient.BaseAddress = new Uri("http://localhost:5262/api/"); + var devicetype = await httpClient.GetAsync("Device/GetTypes"); + var deviceitem = await httpClient.GetAsync("Device/GetDevices"); + listDeviceTypes = JsonConvert.DeserializeObject>(await devicetype.Content.ReadAsStringAsync()); + listDeviceItems = JsonConvert.DeserializeObject>(await deviceitem.Content.ReadAsStringAsync()); + messageStatus = string.Empty; + if (listDeviceTypes.Count == 0) + { + messageStatus += $"нет типов устройств\r\n"; + } + if (listDeviceItems.Count == 0) + { + messageStatus += $"нет устройств\r\n"; + } + DataStore.ListDeviceTypesStore = listDeviceTypes; + DataStore.ListDeviceItemsStore = listDeviceItems; } } diff --git a/Ministreliy/Components/Pages/DatabaseDevice.razor b/Ministreliy/Components/Pages/DatabaseDevice.razor new file mode 100644 index 0000000..cf6bdbd --- /dev/null +++ b/Ministreliy/Components/Pages/DatabaseDevice.razor @@ -0,0 +1,201 @@ +@page "/database/device" +@using Ministreliy.Models +@using System.Text.Json +@using Newtonsoft.Json +@using System.Text +@inject IJSRuntime JS +@inject NavigationManager NavManager + +База данных + + + + + + +@if (listDT.Count == 0 || listDT == null) +{ +

@msg

+} +else +{ + @* *@ +
+ + + +
+
+ +
+ + + + + + + + + @foreach (var item in listDT) + { + + + + + } + +
#Название
@item.Id@item.Name
+
+
+
+ + + + + + + +} + + +@code { + //HttpClient http = new(); + + private DeviceType dt; + private List listDT = new(); + + private string msg = "-= ПОЛУЧАЮ ДАННЫЕ =-", name_type = ""; + private int id_type = 1, selected_type = 0; + + protected override async Task OnInitializedAsync() + { + HttpClient http = new(); + await Task.Delay(1000); + http.BaseAddress = new Uri("http://localhost:5262/api/"); + var t = await http.GetAsync("Device/GetTypes"); + if (t.StatusCode == System.Net.HttpStatusCode.NoContent) + { + msg = "-= ДАННЫХ НЕТ =-"; + } + else + { + listDT = JsonConvert.DeserializeObject>(await t.Content.ReadAsStringAsync()); + //id_type = listDT.Count + 1; + var a = listDT.Select(listDT => listDT.Id).ToList(); + id_type = Enumerable.Range(1, int.MaxValue).FirstOrDefault(i => !a.Contains(i)); + + } + } + private async Task SaveType() + { + HttpClient http = new(); + dt = new(); + dt.Id = id_type; + dt.Name = name_type; + http.BaseAddress = new Uri("http://localhost:5262/api/"); + using StringContent content = new StringContent( + JsonConvert.SerializeObject(dt), + Encoding.UTF8, + "application/json" + ); + var r = await http.PostAsync("Device/AddType", content); + if (r.IsSuccessStatusCode) + { + await JS.InvokeVoidAsync("eval", $"var myModal = bootstrap.Modal.getInstance(document.querySelector('.modal1')); myModal.hide();"); + await Task.Delay(150); + id_type = listDT.Count+1; + NavManager.NavigateTo(NavManager.Uri, forceLoad: true); + } + } + private async Task DelType() + { + HttpClient http = new(); + http.BaseAddress = new Uri("http://localhost:5262/api/"); + var r = await http.DeleteAsync($"Device/DelType?id={selected_type}"); + if (r.IsSuccessStatusCode) + { + await JS.InvokeVoidAsync("eval", $"var myModal = bootstrap.Modal.getInstance(document.querySelector('.modal2')); myModal.hide();"); + await Task.Delay(250); + id_type = listDT.Count + 1; + NavManager.NavigateTo(NavManager.Uri, forceLoad: true); + } + } +} + + diff --git a/Ministreliy/Components/Pages/DatabaseType.razor b/Ministreliy/Components/Pages/DatabaseType.razor index 633a739..e18b9fe 100644 --- a/Ministreliy/Components/Pages/DatabaseType.razor +++ b/Ministreliy/Components/Pages/DatabaseType.razor @@ -7,24 +7,65 @@ @inject NavigationManager NavManager База данных +
+ +
+ + +
+
+@if (listDT.Count == 0) +{ +

@msg

+} +else +{ +
+
+ +
+ + + + + + + + + @foreach (var item in Database.listDeviceTypes) + { + + + + + } + +
#Название
@item.Id@item.Name
+
+
+
- - -