public static UInt32?Book(Core.IDatabase database, string name, float amount) { UInt32?entry = null; if (database != null) { database.Connect(); database.Connection.Open(); using (var transaction = database.Connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted)) { database.Command.TransactionText(transaction, BookSQL); database.Command.Parameters.Add(new Parameter() { Name = "@book", Value = name }); database.Command.Parameters.Add(new Parameter() { Name = "@amount", Value = amount }); entry = (UInt32?)(int?)database.Command.ExecuteScalar(); database.Connection.Commit(); } } database.Connection.Close(); return(entry); }
public static List <Balance> BookBalance(Core.IDatabase database, string name, float amount) { List <Balance> result = new List <Balance>(); if (database != null) { database.Connect(); database.Connection.Open(); using (var transaction = database.Connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted)) { database.Command.TransactionText(transaction, BookBalanceSQL); database.Command.Parameters.Add(new Parameter() { Name = "@book", Value = name }); database.Command.Parameters.Add(new Parameter() { Name = "@amount", Value = amount }); var reader = database.Command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { result.Add(Balance.LoadFromReader(reader)); } } reader.Dispose(); database.Connection.Commit(); } } database.Connection.Close(); return(result); }
// Book single amounts into double entry Journal public static UInt32?SQLiteBook(Core.IDatabase database, string name, float amount, Boolean close = true) { UInt32?entry = null; database.Connect(); database.Connection.Open(); using (var transaction = database.Connection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted)) { UInt32?book = null; // Get Id of Book database.Command.TransactionText(transaction, GetBookIdSQL); database.Command.Parameters.Add(new Parameter() { Name = "@book", Value = name }); book = System.Convert.ToUInt32( database.Command.ExecuteScalar() ); // Create new Entry // Insert Entry record database.Command.TransactionText(transaction, GetEntryIdSQL); database.Command.Parameters.Clear(); database.Command.Parameters.Add(new Parameter() { Name = "@assemblyApplicationRelease", Value = null }); database.Command.Parameters.Add(new Parameter() { Name = "@credential", Value = null }); database.Command.ExecuteNonQuery(); // Get Entry Id database.Command.TransactionText(transaction, GetIdentitySQL); entry = System.Convert.ToUInt32( database.Command.ExecuteScalar() ); // Make Journal Inserts database.Command.TransactionText(transaction, InsertJournalEntriesSQL); database.Command.Parameters.Add(new Parameter() { Name = "@clientCulture", Value = 1033 }); database.Command.Parameters.Add(new Parameter() { Name = "@entry", Value = entry }); database.Command.Parameters.Add(new Parameter() { Name = "@book", Value = book }); database.Command.Parameters.Add(new Parameter() { Name = "@amount", Value = amount }); database.Command.ExecuteNonQuery(); database.Connection.Commit(); } if (close) { database.Connection.Close(); } return(entry); }