[성현모] TRA DB목록 불러오기, 정의 자동추가
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,15 +1,16 @@
|
|||||||
{
|
{
|
||||||
|
"ApplicationName": "KIP Web Tools",
|
||||||
"Server": {
|
"Server": {
|
||||||
"Address": "https://*",
|
"Address": "https://*",
|
||||||
"Port": 11000,
|
"Port": 11000,
|
||||||
"IIS": false
|
"IIS": false
|
||||||
},
|
},
|
||||||
"DataBase": [
|
"DataBase": [
|
||||||
{
|
{
|
||||||
"IP": "127.0.0.1",
|
"IP": "127.0.0.1",
|
||||||
"Port": 1433,
|
"Port": 1433,
|
||||||
"DBName": "CPXV2",
|
"DBName": "CPXV2",
|
||||||
"DBID": 1,
|
"DBID": 1,
|
||||||
"UserID": "Alis",
|
"UserID": "Alis",
|
||||||
"Password": "Kefico!@34"
|
"Password": "Kefico!@34"
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
56
Projects/SystemX.Core/SystemX.Core/DB/DBStoredProcedure.cs
Normal file
56
Projects/SystemX.Core/SystemX.Core/DB/DBStoredProcedure.cs
Normal file
@ -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<IEnumerable<TResult>>? ExecuteStoredProcedureAsync<TEntity, TResult>(this DbContext dbContext, string storedProcedure) where TEntity : class where TResult : class
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = new List<TResult>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,11 +1,15 @@
|
|||||||
@inherits LayoutComponentBase
|
@using SystemX.Core.Services
|
||||||
|
@using WebClient.Library.Config
|
||||||
|
|
||||||
|
@inherits LayoutComponentBase
|
||||||
|
@inject ConfigService<WebClientConfig> configService
|
||||||
|
|
||||||
<RadzenComponents @rendermode="InteractiveServer" />
|
<RadzenComponents @rendermode="InteractiveServer" />
|
||||||
<RadzenLayout>
|
<RadzenLayout>
|
||||||
<RadzenHeader>
|
<RadzenHeader>
|
||||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" Gap="0">
|
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" Gap="0">
|
||||||
<RadzenSidebarToggle Click="@(() => sidebarExpanded = !sidebarExpanded)" />
|
<RadzenSidebarToggle Click="@(() => sidebarExpanded = !sidebarExpanded)" />
|
||||||
<RadzenLabel Text="Header" />
|
<RadzenLabel Text="@configService?.GetConfig()?.ApplicationName" />
|
||||||
</RadzenStack>
|
</RadzenStack>
|
||||||
</RadzenHeader>
|
</RadzenHeader>
|
||||||
<RadzenSidebar @bind-Expanded="@sidebarExpanded">
|
<RadzenSidebar @bind-Expanded="@sidebarExpanded">
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
using Radzen;
|
using Radzen;
|
||||||
|
using SystemX.Core.Config.Model;
|
||||||
|
using SystemX.Core.DB;
|
||||||
using SystemX.Core.Services;
|
using SystemX.Core.Services;
|
||||||
using Web.Tra.Components;
|
using Web.Tra.Components;
|
||||||
using WebClient.Library.Config;
|
using WebClient.Library.Config;
|
||||||
|
using WebClient.Library.Model;
|
||||||
|
|
||||||
string configDir = @"../../Config";
|
string configDir = @"../../Config";
|
||||||
string configFileName = "WebClient.Tra.Config.json";
|
string configFileName = "WebClient.Tra.Config.json";
|
||||||
@ -63,6 +67,28 @@ if (configService?.OpenConfig($@"{configDir}/{configFileName}") == true)
|
|||||||
{
|
{
|
||||||
var dbProvider = scoped.ServiceProvider.GetRequiredService<DbContextProvider>();
|
var dbProvider = scoped.ServiceProvider.GetRequiredService<DbContextProvider>();
|
||||||
dbProvider?.SetDBList(apiConfig?.DataBase);
|
dbProvider?.SetDBList(apiConfig?.DataBase);
|
||||||
|
|
||||||
|
//log db list
|
||||||
|
var dbcontext = dbProvider.GetDBContext<CPXV2>("CPXV2");
|
||||||
|
var getDbList = await dbcontext.ExecuteStoredProcedureAsync<CPXV2, DBList>("spGetDBList");
|
||||||
|
var longTermDB = getDbList.Where(x => x.Name.ToLower().Contains("longterm")).ToList();
|
||||||
|
|
||||||
|
List<DataBase> logDb = new List<DataBase>();
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,5 +13,8 @@ namespace WebClient.Library.Config
|
|||||||
{
|
{
|
||||||
[JsonPropertyName("DataBase")]
|
[JsonPropertyName("DataBase")]
|
||||||
public List<DataBase>? DataBase { get; set; }
|
public List<DataBase>? DataBase { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("ApplicationName")]
|
||||||
|
public string? ApplicationName { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
Projects/WebClient/WebClient.Library/Model/DBList.cs
Normal file
13
Projects/WebClient/WebClient.Library/Model/DBList.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user