using System; using System.Text; namespace Common.Library.SQL.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};SslMode=none", 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", "
"); } protected string FormatNewLineForHTML(string input, int numberOfBreaksToAdd) { StringBuilder breaks = new(); for (int x = 0; x < numberOfBreaksToAdd; x++) { breaks.Append("
"); } return input.Replace("\\r\\n", breaks.ToString()); } protected string FormatBoldForHTML(string input) { return input.Replace("[b]", "").Replace("[/b]", ""); } 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); } }