Merged DBs to one BD
This commit is contained in:
parent
19b6012717
commit
8e777e9330
|
@ -1,8 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<connectionStrings>
|
<connectionStrings>
|
||||||
<add name="RawData" connectionString="Data Source = ./data.db;version=3" providerName="System.Data.SqlClient"/>
|
<add name="CryptoCalc" connectionString="Data Source = ./CryptoCalc.db;version=3" providerName="System.Data.SqlClient"/>
|
||||||
<add name="Transactions" connectionString="Data Source = ./transactions.db;version=3" providerName="System.Data.SqlClient"/>
|
|
||||||
<add name="Wallets" connectionString="Data Source = ./wallets.db;version=3" providerName="System.Data.SqlClient"/>
|
|
||||||
</connectionStrings>
|
</connectionStrings>
|
||||||
</configuration>
|
</configuration>
|
|
@ -6,21 +6,24 @@ namespace CryptoCalc
|
||||||
|
|
||||||
public interface IDBClasses
|
public interface IDBClasses
|
||||||
{
|
{
|
||||||
string DBVariables { get; set; }
|
string DBName { get; }
|
||||||
string DBTableName { get; }
|
string DBTableName { get; }
|
||||||
|
string DBVariables { get; set; }
|
||||||
string DBSaveDataString { get; }
|
string DBSaveDataString { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DBClasses : IDBClasses
|
public class DBClasses : IDBClasses
|
||||||
{
|
{
|
||||||
#region Publics
|
#region Publics
|
||||||
public virtual string DBVariables { get; set; }
|
public string DBName => "CryptoCalc";
|
||||||
public virtual string DBTableName { get; }
|
public virtual string DBTableName { get; }
|
||||||
|
public virtual string DBVariables { get; set; }
|
||||||
public string DBSaveDataString => $"({Regex.Replace(DBVariables, "@", "")}) values ({DBVariables})";
|
public string DBSaveDataString => $"({Regex.Replace(DBVariables, "@", "")}) values ({DBVariables})";
|
||||||
|
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
public long UnixTime { get; set; }
|
public long UnixTime { get; set; }
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Functions
|
#region Functions
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace CryptoCalc
|
||||||
throw new ArgumentNullException(nameof(data));
|
throw new ArgumentNullException(nameof(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(data.DBTableName));
|
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(data.DBName));
|
||||||
cnn.Execute($"insert into {data.DBTableName} {data.DBSaveDataString}", data);
|
cnn.Execute($"insert into {data.DBTableName} {data.DBSaveDataString}", data);
|
||||||
Debug.WriteLine($"Saved {data.DBTableName} DB data");
|
Debug.WriteLine($"Saved {data.DBTableName} DB data");
|
||||||
}
|
}
|
||||||
|
@ -26,25 +26,25 @@ namespace CryptoCalc
|
||||||
public class GenericDB<T> where T : DBClasses
|
public class GenericDB<T> where T : DBClasses
|
||||||
{
|
{
|
||||||
|
|
||||||
public IEnumerable<T> LoadAllData(string tableName)
|
public IEnumerable<T> LoadAllData(T data)
|
||||||
{
|
{
|
||||||
if (tableName is null)
|
if (data.DBTableName is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(tableName));
|
throw new ArgumentNullException(nameof(data.DBTableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(tableName));
|
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(data.DBName));
|
||||||
return _connection.Query<T>($"select * from {tableName}", new DynamicParameters());
|
return _connection.Query<T>($"select * from {data.DBTableName}", new DynamicParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<T> QueryData(string tableName, string query)
|
public IEnumerable<T> QueryData(T data, string query)
|
||||||
{
|
{
|
||||||
if (tableName is null)
|
if (data.DBTableName is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(query));
|
throw new ArgumentNullException(nameof(data.DBTableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(tableName));
|
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(data.DBTableName));
|
||||||
return _connection.Query<T>($"{query}", new DynamicParameters());
|
return _connection.Query<T>($"{query}", new DynamicParameters());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace CryptoCalc
|
||||||
|
|
||||||
private void readButton_click(object sender, RoutedEventArgs e)
|
private void readButton_click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
IEnumerable <Transaction> transactions = transactionDB.LoadAllData(genericT.DBTableName);
|
IEnumerable <Transaction> transactions = transactionDB.LoadAllData(genericT);
|
||||||
foreach (Transaction t in transactions)
|
foreach (Transaction t in transactions)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"{t.GetLocalTimeFromUnixTime(t.UnixTime)} *** {t.Currency} - {t.Amount}");
|
Debug.WriteLine($"{t.GetLocalTimeFromUnixTime(t.UnixTime)} *** {t.Currency} - {t.Amount}");
|
||||||
|
@ -45,7 +45,7 @@ namespace CryptoCalc
|
||||||
private void searchButton_Click(object sender, RoutedEventArgs e)
|
private void searchButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
string query = $"SELECT * from {genericT.DBTableName} WHERE {nameof(genericT.Currency)}=\'{currencyText.Text}\'";
|
string query = $"SELECT * from {genericT.DBTableName} WHERE {nameof(genericT.Currency)}=\'{currencyText.Text}\'";
|
||||||
IEnumerable<Transaction> transactions = transactionDB.QueryData(genericT.DBTableName, query);
|
IEnumerable<Transaction> transactions = transactionDB.QueryData(genericT, query);
|
||||||
transactionsFoundListBox.Items.Clear();
|
transactionsFoundListBox.Items.Clear();
|
||||||
foreach (Transaction x in transactions)
|
foreach (Transaction x in transactions)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue