182 lines
5.0 KiB
C#
182 lines
5.0 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace CryptoCalc
|
|
{
|
|
|
|
public interface IDBClasses
|
|
{
|
|
string DBName { get; }
|
|
string DBTableName { get; }
|
|
string DBVariables { get; set; }
|
|
string DBSaveDataString { get; }
|
|
}
|
|
|
|
public class DBClasses : IDBClasses
|
|
{
|
|
#region Publics
|
|
public string DBName => "CryptoCalc";
|
|
public virtual string DBTableName { get; }
|
|
public virtual string DBVariables { get; set; }
|
|
public string DBSaveDataString => $"({Regex.Replace(DBVariables, "@", "")}) values ({DBVariables})";
|
|
|
|
public int Index { get; set; }
|
|
public long UnixTime { get; set; }
|
|
|
|
|
|
#endregion
|
|
|
|
#region Functions
|
|
|
|
public void SaveUnixTimeNow()
|
|
{
|
|
UnixTime = (long)DateTime.UtcNow.Subtract(DateTime.UnixEpoch).TotalSeconds;
|
|
}
|
|
|
|
public long GetUnixTime(DateTime dateTime)
|
|
{
|
|
return (long)dateTime.Subtract(DateTime.UnixEpoch).TotalSeconds;
|
|
}
|
|
|
|
public DateTime GetUTCTimeFromUnixTime(long unix)
|
|
{
|
|
return DateTime.UnixEpoch.AddSeconds(unix).ToUniversalTime();
|
|
}
|
|
public DateTime GetLocalTimeFromUnixTime(long unix)
|
|
{
|
|
return DateTime.UnixEpoch.AddSeconds(unix).ToLocalTime();
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
public class Transaction : DBClasses
|
|
{
|
|
|
|
#region Publics
|
|
public override string DBVariables { get => base.DBVariables; set => base.DBVariables = value; }
|
|
public override string DBTableName => "Transactions";
|
|
|
|
public string Currency { get; set; }
|
|
public float Amount { get; set; }
|
|
public string TransactionType { get; set; }
|
|
public string FeeCurrency { get; set; }
|
|
public float FeeAmount { get; set; }
|
|
public string Platform { get; set; }
|
|
public string Note { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public Transaction() { SetDBStrings(); }
|
|
|
|
public Transaction(string _currency, float _amount, string _type)
|
|
{
|
|
SaveUnixTimeNow();
|
|
Currency = _currency;
|
|
Amount = _amount;
|
|
TransactionType = _type;
|
|
|
|
Platform = "";
|
|
Note = "";
|
|
|
|
SetDBStrings();
|
|
}
|
|
|
|
public Transaction(string currency, float amount, string type, string feeCurrency, float feeAmount)
|
|
{
|
|
SaveUnixTimeNow();
|
|
Currency = currency;
|
|
Amount = amount;
|
|
TransactionType = type;
|
|
FeeCurrency = feeCurrency;
|
|
FeeAmount = feeAmount;
|
|
Platform = "";
|
|
Note = "";
|
|
|
|
SetDBStrings();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Functions
|
|
|
|
private void SetDBStrings()
|
|
{
|
|
DBVariables =
|
|
$"@{nameof(UnixTime)},"
|
|
+ $"@{nameof(Currency)},"
|
|
+ $"@{nameof(Amount)},"
|
|
+ $"@{nameof(TransactionType)},"
|
|
+ $"@{nameof(FeeCurrency)},"
|
|
+ $"@{nameof(FeeAmount)},"
|
|
+ $"@{nameof(Platform)},"
|
|
+ $"@{nameof(Note)}";
|
|
}
|
|
|
|
public string FullInfo => $"{ Index } { GetLocalTimeFromUnixTime(UnixTime) } { Currency } { Amount } { TransactionType }";
|
|
|
|
#endregion
|
|
}
|
|
|
|
|
|
public class Wallet : DBClasses
|
|
{
|
|
#region Publics
|
|
public override string DBVariables { get => base.DBVariables; set => base.DBVariables = value; }
|
|
public override string DBTableName => "Wallets";
|
|
|
|
public long UnixTimeCreated { get; set; }
|
|
public string Platform { get; set; }
|
|
public string Name { get; set; }
|
|
public string Currency { get; set; }
|
|
public float Balance { get; set; }
|
|
public int DefaultWallet { get; set; }
|
|
public string Note { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public Wallet() { SetDBStrings(); }
|
|
|
|
public Wallet(DateTime dateTime, string platform, string name, string currency, float balance, int defaultWallet, string note)
|
|
{
|
|
SaveUnixTimeNow();
|
|
UnixTimeCreated = GetUnixTime(dateTime);
|
|
Platform = platform;
|
|
Name = name;
|
|
Currency = currency;
|
|
Balance = balance;
|
|
DefaultWallet = defaultWallet;
|
|
Note = note;
|
|
|
|
SetDBStrings();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Functions
|
|
|
|
private void SetDBStrings()
|
|
{
|
|
DBVariables =
|
|
$"@{nameof(UnixTime)},"
|
|
+ $"@{nameof(UnixTimeCreated)},"
|
|
+ $"@{nameof(Platform)},"
|
|
+ $"@{nameof(Name)},"
|
|
+ $"@{nameof(Currency)},"
|
|
+ $"@{nameof(Balance)},"
|
|
+ $"@{nameof(DefaultWallet)},"
|
|
+ $"@{nameof(Note)}";
|
|
}
|
|
|
|
//public string FullInfo => $"{ Index.ToString() } { DateTimeString } { Currency } { Amount } { TransactionType }";
|
|
|
|
#endregion
|
|
}
|
|
|
|
}
|