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.

66 lines
2.3 KiB

using Dapper;
using Microsoft.Data.SqlClient;
using Npgsql;
using Oracle.ManagedDataAccess.Client;
using Shentun.Utilities;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shentun.Peis.PlugIns
{
public class ColumnReferencePlugInsDbBase: ColumnReferencePlugInsBase
{
protected string InterfaceSql;
protected string InterfaceDbType;
protected string? InterfaceConnctionStr;
public ColumnReferencePlugInsDbBase(string parmValue):base(parmValue)
{
InterfaceSql = InterfaceConfig.GetSection("Interface").GetSection("Sql").Value;
InterfaceDbType = InterfaceConfig.GetSection("Interface").GetSection("DbType").Value;
InterfaceConnctionStr = InterfaceConfig.GetSection("Interface").GetSection("ConnectionStrings").Value;
}
protected DbConnection CreateInterfaceDbConnect()
{
DbConnection conn ;
if (string.IsNullOrWhiteSpace(InterfaceConnctionStr))
{
throw new ArgumentException("数据连接设置中的DbType不能为空");
}
InterfaceDbType = InterfaceDbType.ToLower();
if (InterfaceDbType == "sqlserver")
{
conn = new SqlConnection(InterfaceConnctionStr);
}
else if (InterfaceDbType == "postgres")
{
conn = new NpgsqlConnection(InterfaceConnctionStr);
}
else if (InterfaceDbType == "oracle")
{
conn = new OracleConnection(InterfaceConnctionStr);
}
else
{
throw new ArgumentException("数据连接设置中的DbType不支持");
}
return conn;
}
public override async Task<List<ColumnReferenceCodeValue>> GetInterfaceCodeValuesAsync()
{
using (DbConnection conn = CreateInterfaceDbConnect())
{
var list = (await conn.QueryAsync<ColumnReferenceCodeValue>(InterfaceSql)).ToList();
foreach (var item in list)
{
item.SimpleCode = LanguageConverter.GetPYSimpleCode(item.DisplayName);
}
return list;
}
}
}
}