180 lines
5.0 KiB
C#
180 lines
5.0 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace CryptoCalc
|
|
{
|
|
|
|
public interface IDBClasses
|
|
{
|
|
string DBVariables { get; set; }
|
|
|
|
string DBTableName { get; }
|
|
string DBSaveDataString { get; }
|
|
}
|
|
|
|
public class DBClasses : IDBClasses
|
|
{
|
|
#region Publics
|
|
public virtual string DBVariables { get; set; }
|
|
public virtual string DBTableName => throw new NotImplementedException();
|
|
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.ToString() } { 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(int _year, int _month, int _day, string _platform, string _name, string _currency, float _balance, int _default, string _note)
|
|
{
|
|
SaveUnixTimeNow();
|
|
UnixTimeCreated = GetUnixTime(new DateTime(_year, _month, _day));
|
|
Platform = _platform;
|
|
Name = _name;
|
|
Currency = _currency;
|
|
Balance = _balance;
|
|
DefaultWallet = _default;
|
|
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
|
|
}
|
|
|
|
}
|