diff --git a/DBPatch/sqlScripts/dacpac/SystemX.DB.AccountDB.dacpac b/DBPatch/sqlScripts/dacpac/SystemX.DB.AccountDB.dacpac index 71f0e72..1fe1660 100644 Binary files a/DBPatch/sqlScripts/dacpac/SystemX.DB.AccountDB.dacpac and b/DBPatch/sqlScripts/dacpac/SystemX.DB.AccountDB.dacpac differ diff --git a/DBPatch/sqlScripts/dacpac/SystemX.DB.CPXV2.dacpac b/DBPatch/sqlScripts/dacpac/SystemX.DB.CPXV2.dacpac index ed99e7d..023540b 100644 Binary files a/DBPatch/sqlScripts/dacpac/SystemX.DB.CPXV2.dacpac and b/DBPatch/sqlScripts/dacpac/SystemX.DB.CPXV2.dacpac differ diff --git a/DBPatch/sqlScripts/dacpac/SystemX.DB.CPXV2Log.dacpac b/DBPatch/sqlScripts/dacpac/SystemX.DB.CPXV2Log.dacpac index 09f24c2..b979d21 100644 Binary files a/DBPatch/sqlScripts/dacpac/SystemX.DB.CPXV2Log.dacpac and b/DBPatch/sqlScripts/dacpac/SystemX.DB.CPXV2Log.dacpac differ diff --git a/DBPatch/sqlScripts/dacpac/SystemX.DB.UniqueKeyDB.dacpac b/DBPatch/sqlScripts/dacpac/SystemX.DB.UniqueKeyDB.dacpac index 88ac311..d30f09d 100644 Binary files a/DBPatch/sqlScripts/dacpac/SystemX.DB.UniqueKeyDB.dacpac and b/DBPatch/sqlScripts/dacpac/SystemX.DB.UniqueKeyDB.dacpac differ diff --git a/DBPatch/sqlScripts/dacpac/SystemX.DB.VPKI_DataDB.dacpac b/DBPatch/sqlScripts/dacpac/SystemX.DB.VPKI_DataDB.dacpac index e8d4516..bc0514f 100644 Binary files a/DBPatch/sqlScripts/dacpac/SystemX.DB.VPKI_DataDB.dacpac and b/DBPatch/sqlScripts/dacpac/SystemX.DB.VPKI_DataDB.dacpac differ diff --git a/Projects/Config/WebClient.Tra.Config.json b/Projects/Config/WebClient.Tra.Config.json index 60aba7e..03acb75 100644 --- a/Projects/Config/WebClient.Tra.Config.json +++ b/Projects/Config/WebClient.Tra.Config.json @@ -1,15 +1,16 @@ { + "ApplicationName": "KIP Web Tools", "Server": { "Address": "https://*", "Port": 11000, "IIS": false - }, + }, "DataBase": [ { "IP": "127.0.0.1", "Port": 1433, "DBName": "CPXV2", - "DBID": 1, + "DBID": 1, "UserID": "Alis", "Password": "Kefico!@34" } diff --git a/Projects/DLL/SystemX.Core.DB.dll b/Projects/DLL/SystemX.Core.DB.dll index e4b80f6..74eb067 100644 Binary files a/Projects/DLL/SystemX.Core.DB.dll and b/Projects/DLL/SystemX.Core.DB.dll differ diff --git a/Projects/DLL/SystemX.Core.dll b/Projects/DLL/SystemX.Core.dll index 6c77ffe..12d2465 100644 Binary files a/Projects/DLL/SystemX.Core.dll and b/Projects/DLL/SystemX.Core.dll differ diff --git a/Projects/SystemX.Core/SystemX.Core/DB/DBStoredProcedure.cs b/Projects/SystemX.Core/SystemX.Core/DB/DBStoredProcedure.cs new file mode 100644 index 0000000..c399cc2 --- /dev/null +++ b/Projects/SystemX.Core/SystemX.Core/DB/DBStoredProcedure.cs @@ -0,0 +1,56 @@ +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal; +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SystemX.Core.DB +{ + public static class DBStoredProcedure + { + public static async Task>? ExecuteStoredProcedureAsync(this DbContext dbContext, string storedProcedure) where TEntity : class where TResult : class + { + try + { + var result = new List(); + var type = typeof(TResult); + + using var command = dbContext.Database.GetDbConnection().CreateCommand(); + command.CommandText = storedProcedure; + command.CommandType = CommandType.StoredProcedure; + + if (command.Connection.State != ConnectionState.Open) + await command.Connection.OpenAsync(); + + using var reader = await command.ExecuteReaderAsync(); + while (await reader.ReadAsync()) + { + TResult row = (TResult)Activator.CreateInstance(typeof(TResult)); + + foreach (var prop in type.GetProperties()) + { + string propertyName = $"{prop.Name}"; + var value = reader.GetValue(propertyName); + prop.SetValue(row, value); + } + + result.Add(row); + } + + return result; + } + catch(Exception e) + { + LogXnet.WriteLine($"StoredProcedure {storedProcedure} Error", LogXLabel.Exception); + LogXnet.WriteLine(e); + } + + return null; + } + } +} diff --git a/Projects/WebClient/Web.Tra/Components/Layout/MainLayout.razor b/Projects/WebClient/Web.Tra/Components/Layout/MainLayout.razor index 8c32590..47b7964 100644 --- a/Projects/WebClient/Web.Tra/Components/Layout/MainLayout.razor +++ b/Projects/WebClient/Web.Tra/Components/Layout/MainLayout.razor @@ -1,11 +1,15 @@ -@inherits LayoutComponentBase +@using SystemX.Core.Services +@using WebClient.Library.Config + +@inherits LayoutComponentBase +@inject ConfigService configService - + diff --git a/Projects/WebClient/Web.Tra/Program.cs b/Projects/WebClient/Web.Tra/Program.cs index e63b545..b33edf1 100644 --- a/Projects/WebClient/Web.Tra/Program.cs +++ b/Projects/WebClient/Web.Tra/Program.cs @@ -1,7 +1,11 @@ +using Microsoft.EntityFrameworkCore.Storage; using Radzen; +using SystemX.Core.Config.Model; +using SystemX.Core.DB; using SystemX.Core.Services; using Web.Tra.Components; using WebClient.Library.Config; +using WebClient.Library.Model; string configDir = @"../../Config"; string configFileName = "WebClient.Tra.Config.json"; @@ -63,6 +67,28 @@ if (configService?.OpenConfig($@"{configDir}/{configFileName}") == true) { var dbProvider = scoped.ServiceProvider.GetRequiredService(); dbProvider?.SetDBList(apiConfig?.DataBase); + + //log db list + var dbcontext = dbProvider.GetDBContext("CPXV2"); + var getDbList = await dbcontext.ExecuteStoredProcedureAsync("spGetDBList"); + var longTermDB = getDbList.Where(x => x.Name.ToLower().Contains("longterm")).ToList(); + + List logDb = new List(); + foreach (var db in longTermDB.Select((value,index) => (value, index))) + { + logDb.Add(new DataBase + { + DBID = db.index, + DBName = db.value.Name, + IP = "127.0.0.1", + Port = 1433, + UserID = "Alis", + Password = "Kefico!@34", + DBContext = "" + }); + } + + dbProvider.SetDBList(logDb); } } } diff --git a/Projects/WebClient/WebClient.Library/Config/WebClientConfig.cs b/Projects/WebClient/WebClient.Library/Config/WebClientConfig.cs index 788e885..2708b4b 100644 --- a/Projects/WebClient/WebClient.Library/Config/WebClientConfig.cs +++ b/Projects/WebClient/WebClient.Library/Config/WebClientConfig.cs @@ -13,5 +13,8 @@ namespace WebClient.Library.Config { [JsonPropertyName("DataBase")] public List? DataBase { get; set; } + + [JsonPropertyName("ApplicationName")] + public string? ApplicationName { get; set; } } } diff --git a/Projects/WebClient/WebClient.Library/Model/DBList.cs b/Projects/WebClient/WebClient.Library/Model/DBList.cs new file mode 100644 index 0000000..c026ab4 --- /dev/null +++ b/Projects/WebClient/WebClient.Library/Model/DBList.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WebClient.Library.Model +{ + public class DBList + { + public string Name { get; set; } + } +}