initial refactor commit

upgraded to net 6.0

minor changes to support .net upgrade
refactor
Don Oerkfitz 2 years ago
parent 1484b98d98
commit 9e62eb5c05

@ -10,7 +10,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/OSI-API/bin/Debug/net5.0/OSI-API.dll",
"program": "${workspaceFolder}/OSI-API/bin/Debug/net6.0/OSI-API.dll",
"args": [],
"cwd": "${workspaceFolder}/OSI-API",
"stopAtEntry": false,

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using OSI.API.Business.Database;
using OSI.API.Business.Objects;
using Common.Library.SQL.MySQL;
namespace OSI.API.Business.DAO
{

@ -1,100 +0,0 @@
using System;
using System.Text;
namespace OSI.API.Business.Database.Base
{
public abstract class SQLBase : IDisposable
{
protected DBConnectionInformation DBConnectionInfo;
public enum DBType
{
MSSQL,
MYSQL
}
public struct DBConnectionInformation
{
public string DBHost { get; set; }
public string DBName { get; set; }
public string DBUserName { get; set; }
public string DBPassword { get; set; }
public DBType DBType { get; set; }
public string GetConnectionString()
{
string rv = string.Empty;
switch (DBType)
{
case DBType.MSSQL:
break;
case DBType.MYSQL:
rv = string.Format("Server={0};Database={1};Uid={2};Pwd={3}", DBHost, DBName, DBUserName, DBPassword);
break;
}
return rv;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
// free managed resources
}
// free native resources if there are any.
}
protected string FormatNewLineForHTML(string input)
{
return input.Replace("\\r\\n", "<br/>");
}
protected string FormatNewLineForHTML(string input, int numberOfBreaksToAdd)
{
StringBuilder breaks = new();
for (int x = 0; x < numberOfBreaksToAdd; x++)
{
breaks.Append("<br/>");
}
return input.Replace("\\r\\n", breaks.ToString());
}
protected string FormatBoldForHTML(string input)
{
return input.Replace("[b]", "<strong>").Replace("[/b]", "</strong>");
}
protected abstract void InitConnection();
protected abstract void DisposeConnection();
protected abstract int GetOrdinal(string columnName);
protected abstract int? GetInt(int columnID);
protected abstract int? GetInt(string columnName);
protected abstract byte? GetByte(int columnID);
protected abstract byte? GetByte(string columnName);
protected abstract byte[] GetBytes(int columnID);
protected abstract byte[] GetBytes(string columnName);
protected abstract decimal? GetDecimal(int columnID);
protected abstract decimal? GetDecimal(string columnName);
protected abstract long? GetLong(int columnID);
protected abstract long? GetLong(string columnName);
protected abstract short? GetShort(int columnID);
protected abstract short? GetShort(string columnName);
protected abstract string GetString(int columnID);
protected abstract string GetString(string columnName);
protected abstract bool? GetBool(int columnID);
protected abstract bool? GetBool(string columnName);
protected abstract DateTime? GetDateTime(int columnID);
protected abstract DateTime? GetDateTime(string columnName);
}
}

@ -1,205 +0,0 @@
using System;
using System.Data;
using System.IO;
using OSI.API.Business.Database.Base;
using MySql.Data.MySqlClient;
namespace OSI.API.Business.Database
{
public class MySQL : SQLBase
{
protected MySqlConnection DBConnection { get; set; }
protected MySqlCommand DBCommand { get; set; }
protected MySqlDataReader DBReader { get; set; }
public MySQL(string server, string database, string username, string password)
{
DBConnectionInfo = new DBConnectionInformation()
{
DBHost = server,
DBUserName = username,
DBName = database,
DBPassword = password,
DBType = DBType.MYSQL
};
}
public MySQL(DBConnectionInformation connectionInformation)
{
DBConnectionInfo = connectionInformation;
}
protected override void InitConnection()
{
DBConnection = new MySqlConnection(DBConnectionInfo.GetConnectionString());
DBConnection.Open();
DBCommand = DBConnection.CreateCommand();
}
protected override void DisposeConnection()
{
if (DBConnection.State == ConnectionState.Open)
{
DBConnection.Close();
}
}
protected override int GetOrdinal(string columnName)
{
return DBReader.GetOrdinal(columnName);
}
protected override int? GetInt(int columnID)
{
int? rv = null;
if (!DBReader.IsDBNull(columnID))
{
rv = DBReader.GetInt32(columnID);
}
return rv;
}
protected override int? GetInt(string columnName)
{
return GetInt(GetOrdinal(columnName));
}
protected override byte? GetByte(int columnID)
{
byte? rv = null;
if (!DBReader.IsDBNull(columnID))
{
rv = DBReader.GetByte(columnID);
}
return rv;
}
protected override byte? GetByte(string columnName)
{
return GetByte(GetOrdinal(columnName));
}
protected override byte[] GetBytes(int columnID)
{
byte[] rv = null;
if (!DBReader.IsDBNull(columnID))
{
rv = (byte[])DBReader[columnID];
}
return rv;
}
protected override byte[] GetBytes(string columnName)
{
return GetBytes(GetOrdinal(columnName));
}
protected override decimal? GetDecimal(int columnID)
{
decimal? rv = null;
if (!DBReader.IsDBNull(columnID))
{
rv = DBReader.GetDecimal(columnID);
}
return rv;
}
protected override decimal? GetDecimal(string columnName)
{
return GetDecimal(GetOrdinal(columnName));
}
protected override long? GetLong(int columnID)
{
long? rv = null;
if (!DBReader.IsDBNull(columnID))
{
rv = DBReader.GetInt64(columnID);
}
return rv;
}
protected override long? GetLong(string columnName)
{
return GetLong(GetOrdinal(columnName));
}
protected override short? GetShort(int columnID)
{
short? rv = null;
if (!DBReader.IsDBNull(columnID))
{
rv = DBReader.GetInt16(columnID);
}
return rv;
}
protected override short? GetShort(string columnName)
{
return GetShort(GetOrdinal(columnName));
}
protected override string GetString(int columnID)
{
string rv = string.Empty;
if (!DBReader.IsDBNull(columnID))
{
rv = DBReader.GetString(columnID);
}
return rv;
}
protected override string GetString(string columnName)
{
return GetString(GetOrdinal(columnName));
}
protected override bool? GetBool(int columnID)
{
bool? rv = null;
if (!DBReader.IsDBNull(columnID))
{
rv = DBReader.GetBoolean(columnID);
}
return rv;
}
protected override bool? GetBool(string columnName)
{
return GetBool(GetOrdinal(columnName));
}
protected override DateTime? GetDateTime(int columnID)
{
DateTime? rv = null;
if (!DBReader.IsDBNull(columnID))
{
rv = GetDateTime(columnID);
}
return rv;
}
protected override DateTime? GetDateTime(string columnName)
{
return GetDateTime(GetOrdinal(columnName));
}
}
}

@ -21,13 +21,13 @@ namespace OSI.API.Controllers
public override IActionResult Get()
{
//> get all invoices as a list of InvoiceObjects
using InvoiceDAO dao = new(new Business.Database.Base.SQLBase.DBConnectionInformation());
using InvoiceDAO dao = new(new Common.Library.SQL.Base.SQLBase.DBConnectionInformation());
return new JsonResult(dao.GetAll());
}
public override IActionResult Get(int id)
{
using InvoiceDAO dao = new(new Business.Database.Base.SQLBase.DBConnectionInformation());
using InvoiceDAO dao = new(new Common.Library.SQL.Base.SQLBase.DBConnectionInformation());
return new JsonResult(dao.Get(id));
}

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>OSI_API</RootNamespace>
</PropertyGroup>
@ -14,4 +14,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Library.System\Common.Library\Common.Library.csproj" />
</ItemGroup>
</Project>

Loading…
Cancel
Save