Refactoring
This commit is contained in:
parent
3ffde5cf4b
commit
10cea5f42c
|
@ -0,0 +1,31 @@
|
||||||
|
using Dapper;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.SQLite;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CryptoCalc
|
||||||
|
{
|
||||||
|
class DBInteraction
|
||||||
|
{
|
||||||
|
public static List<Transaction> LoadTransactions()
|
||||||
|
{
|
||||||
|
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString());
|
||||||
|
var output = _connection.Query<Transaction>("select * from RawData", new DynamicParameters());
|
||||||
|
Debug.WriteLine("Loaded DB data");
|
||||||
|
return output.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SaveTransaction(Transaction transaction)
|
||||||
|
{
|
||||||
|
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString());
|
||||||
|
cnn.Execute("insert into RawData (Date_Year, Date_Month, Date_Day, Time_Hour, Time_Minute, Time_Second, DateTimeString, CryptoCurrency, Amount, TransactionType, Service, Comment) values (@Date_Year, @Date_Month, @Date_Day, @Time_Hour, @Time_Minute, @Time_Second, @DateTimeString, @CryptoCurrency, @Amount, @TransactionType, @Service, @Comment)", transaction);
|
||||||
|
Debug.WriteLine("Saved DB data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,8 +7,8 @@
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="MainWindow" Height="450" Width="800">
|
Title="MainWindow" Height="450" Width="800">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Button x:Name="saveButton" Content="Save" HorizontalAlignment="Left" Margin="536,0,0,309" VerticalAlignment="Bottom" Height="80" Width="180" Click="saveButton_Click" FontSize="20"/>
|
<Button x:Name="saveButton" Content="Save" HorizontalAlignment="Left" Margin="518,0,0,289" VerticalAlignment="Bottom" Height="100" Width="239" Click="saveButton_Click" FontSize="20"/>
|
||||||
<Button x:Name="readButton" Content="Read" Margin="536,0,84,0" Click="readButton_click" FontSize="20" Height="80" Width="180" VerticalAlignment="Center"/>
|
<Button x:Name="readButton" Content="Read" HorizontalAlignment="Left" Margin="518,0,0,156" VerticalAlignment="Bottom" Height="100" Width="239" Click="readButton_click" FontSize="20"/>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|
|
@ -34,12 +34,12 @@ namespace CryptoCalc
|
||||||
|
|
||||||
private void saveButton_Click(object sender, RoutedEventArgs e)
|
private void saveButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
SqliteDataAccess.SaveTransaction(dummyTransaction());
|
DBInteraction.SaveTransaction(dummyTransaction());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readButton_click(object sender, RoutedEventArgs e)
|
private void readButton_click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
transactions = SqliteDataAccess.LoadTransactions();
|
transactions = DBInteraction.LoadTransactions();
|
||||||
foreach (var x in transactions)
|
foreach (var x in transactions)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"{x.DateTimeString} *** {x.CryptoCurrency} - {x.Amount}");
|
Debug.WriteLine($"{x.DateTimeString} *** {x.CryptoCurrency} - {x.Amount}");
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
using Dapper;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Configuration;
|
|
||||||
using System.Data;
|
|
||||||
using System.Data.SQLite;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace CryptoCalc
|
|
||||||
{
|
|
||||||
class SqliteDataAccess
|
|
||||||
{
|
|
||||||
public static List<Transaction> LoadTransactions()
|
|
||||||
{
|
|
||||||
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
|
|
||||||
{
|
|
||||||
var output = cnn.Query<Transaction>("select * from RawData", new DynamicParameters());
|
|
||||||
Debug.WriteLine("Loaded DB data");
|
|
||||||
return output.ToList();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SaveTransaction(Transaction transaction)
|
|
||||||
{
|
|
||||||
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
|
|
||||||
{
|
|
||||||
cnn.Execute("insert into RawData (Date_Year, Date_Month, Date_Day, Time_Hour, Time_Minute, Time_Second, DateTimeString, CryptoCurrency, Amount, TransactionType, Service, Comment) values (@Date_Year, @Date_Month, @Date_Day, @Time_Hour, @Time_Minute, @Time_Second, @DateTimeString, @CryptoCurrency, @Amount, @TransactionType, @Service, @Comment)", transaction);
|
|
||||||
Debug.WriteLine("Saved DB data");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string LoadConnectionString(string id = "Default")
|
|
||||||
{
|
|
||||||
return ConfigurationManager.ConnectionStrings[id].ConnectionString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace CryptoCalc
|
namespace CryptoCalc
|
||||||
{
|
{
|
||||||
class Transaction
|
public class Transaction
|
||||||
{
|
{
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
public int Date_Year { get; set; }
|
public int Date_Year { get; set; }
|
||||||
|
@ -21,7 +21,5 @@ namespace CryptoCalc
|
||||||
public string TransactionType { get; set; }
|
public string TransactionType { get; set; }
|
||||||
public string Service{ get; set; }
|
public string Service{ get; set; }
|
||||||
public string Comment { get; set; }
|
public string Comment { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace CryptoCalc
|
||||||
|
{
|
||||||
|
public static class Util
|
||||||
|
{
|
||||||
|
public static string GetConnectionString(string name = "Default")
|
||||||
|
{
|
||||||
|
return ConfigurationManager.ConnectionStrings[name].ConnectionString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue