Skip to content

Commit 5fcf7e9

Browse files
committed
- added capability to keep the table sorted (note: do not add elements while reversed!)
- minor documentation improvement
1 parent 0710ae7 commit 5fcf7e9

17 files changed

Lines changed: 379 additions & 169 deletions

File tree

TransactionTable/AccountTransactions/AccountTransactionsTable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public partial class AccountTransactionsTable : TransactionsTable
1919
{
2020
// Derived class specific properties, fields, and methods go here
2121

22-
public AccountTransactionsTable(FileInfo file, bool splitByMonths)
23-
: base(file, splitByMonths, AccountTableHeaders.ToStringArray())
22+
public AccountTransactionsTable(FileInfo file, bool splitByMonths, bool keepTimeSorted = true)
23+
: base(file, splitByMonths, AccountTableHeaders.ToStringArray(), keepTimeSorted)
2424
{
2525
// You can add more initialization here if necessary
2626
}

TransactionTable/AccountTransactions/TransactionPresets/AddDeposit.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,36 @@ public void AddDeposit(DateTime depositDate, DepositAccount cashAccount, double
3737
public void AddDeposit(DateTime depositDate, DepositAccount cashAccount, decimal amount, string? note = null)
3838
{
3939
Table table = GetTable(depositDate);
40-
int index = table.AppendEmptyRecord();
40+
// insert record at specified position
41+
int? index = null;
42+
if (this._KeepTableTimeSorted)
43+
{
44+
index = FetchIndexForRecordInsert(depositDate);
45+
}
46+
int newRecordIndex;
47+
if (index == null)
48+
{
49+
newRecordIndex = table.AppendEmptyRecord();
50+
}
51+
else
52+
{
53+
newRecordIndex = index.Value;
54+
table.InsertEmptyRecord(newRecordIndex);
55+
}
4156
// set transaction type
42-
table.SetCell(AccountTableHeaders.Type.Name, index, AccountTransactionTypes.Deposit.Name);
57+
table.SetCell(AccountTableHeaders.Type.Name, newRecordIndex, AccountTransactionTypes.Deposit.Name);
4358
// select account, currency is defined by account
44-
table.SetCell(AccountTableHeaders.CashAccount.Name, index, cashAccount.Name);
59+
table.SetCell(AccountTableHeaders.CashAccount.Name, newRecordIndex, cashAccount.Name);
4560
// set the time
4661
SplitDateTime time = DateTimeHelper.Split(depositDate);
47-
table.SetCell(AccountTableHeaders.Date.Name, index, time.Date);
48-
table.SetCell(AccountTableHeaders.Time.Name, index, time.Time);
62+
table.SetCell(AccountTableHeaders.Date.Name, newRecordIndex, time.Date);
63+
table.SetCell(AccountTableHeaders.Time.Name, newRecordIndex, time.Time);
4964
// set the amount
50-
table.SetCell(AccountTableHeaders.Value.Name, index, amount.ToString("G"));
65+
table.SetCell(AccountTableHeaders.Value.Name, newRecordIndex, amount.ToString("G"));
5166
// set the notes
5267
if (!string.IsNullOrEmpty(note))
5368
{
54-
table.SetCell(AccountTableHeaders.Note.Name, index, note);
69+
table.SetCell(AccountTableHeaders.Note.Name, newRecordIndex, note);
5570
}
5671
}
5772
}

TransactionTable/AccountTransactions/TransactionPresets/AddDividend.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,47 +60,62 @@ public void AddDividend
6060
string? note = null)
6161
{
6262
Table table = GetTable(dividendDate);
63-
int index = table.AppendEmptyRecord();
63+
// insert record at specified position
64+
int? index = null;
65+
if (this._KeepTableTimeSorted)
66+
{
67+
index = FetchIndexForRecordInsert(dividendDate);
68+
}
69+
int newRecordIndex;
70+
if (index == null)
71+
{
72+
newRecordIndex = table.AppendEmptyRecord();
73+
}
74+
else
75+
{
76+
newRecordIndex = index.Value;
77+
table.InsertEmptyRecord(newRecordIndex);
78+
}
6479
// set transaction type
65-
table.SetCell(AccountTableHeaders.Type.Name, index, AccountTransactionTypes.Dividend.Name);
80+
table.SetCell(AccountTableHeaders.Type.Name, newRecordIndex, AccountTransactionTypes.Dividend.Name);
6681
// select account, currency is defined by account
67-
table.SetCell(AccountTableHeaders.CashAccount.Name, index, cashAccount.Name);
82+
table.SetCell(AccountTableHeaders.CashAccount.Name, newRecordIndex, cashAccount.Name);
6883
// set the time
6984
SplitDateTime time = DateTimeHelper.Split(dividendDate);
70-
table.SetCell(AccountTableHeaders.Date.Name, index, time.Date);
71-
table.SetCell(AccountTableHeaders.Time.Name, index, time.Time);
85+
table.SetCell(AccountTableHeaders.Date.Name, newRecordIndex, time.Date);
86+
table.SetCell(AccountTableHeaders.Time.Name, newRecordIndex, time.Time);
7287
// set the security
7388
if (security != null)
7489
{
7590
if (security.ISIN != null)
7691
{
77-
table.SetCell(AccountTableHeaders.ISIN.Name, index, security.ISIN);
92+
table.SetCell(AccountTableHeaders.ISIN.Name, newRecordIndex, security.ISIN);
7893
}
7994
if (security.WKN != null)
8095
{
81-
table.SetCell(AccountTableHeaders.WKN.Name, index, security.WKN);
96+
table.SetCell(AccountTableHeaders.WKN.Name, newRecordIndex, security.WKN);
8297
}
8398
if (security.TickerSymbol != null)
8499
{
85-
table.SetCell(AccountTableHeaders.Symbol.Name, index, security.TickerSymbol);
100+
table.SetCell(AccountTableHeaders.Symbol.Name, newRecordIndex, security.TickerSymbol);
86101
}
87102
if (security.Name != null)
88103
{
89-
table.SetCell(AccountTableHeaders.SecurityName.Name, index, security.Name);
104+
table.SetCell(AccountTableHeaders.SecurityName.Name, newRecordIndex, security.Name);
90105
}
91-
table.SetCell(AccountTableHeaders.TransactionCurrency.Name, index, security.ReferenceCurrency);
106+
table.SetCell(AccountTableHeaders.TransactionCurrency.Name, newRecordIndex, security.ReferenceCurrency);
92107
}
93108
// set the amount
94-
table.SetCell(AccountTableHeaders.ShareAmount.Name, index, shareAmount.ToString("G"));
95-
table.SetCell(AccountTableHeaders.Value.Name, index, creditNote.ToString("G"));
109+
table.SetCell(AccountTableHeaders.ShareAmount.Name, newRecordIndex, shareAmount.ToString("G"));
110+
table.SetCell(AccountTableHeaders.Value.Name, newRecordIndex, creditNote.ToString("G"));
96111
// set fees
97-
table.SetCell(AccountTableHeaders.Fees.Name, index, fees.ToString("G"));
112+
table.SetCell(AccountTableHeaders.Fees.Name, newRecordIndex, fees.ToString("G"));
98113
// set taxes
99-
table.SetCell(AccountTableHeaders.Taxes.Name, index, taxes.ToString("G"));
114+
table.SetCell(AccountTableHeaders.Taxes.Name, newRecordIndex, taxes.ToString("G"));
100115
// set the notes
101116
if (!string.IsNullOrEmpty(note))
102117
{
103-
table.SetCell(AccountTableHeaders.Note.Name, index, note);
118+
table.SetCell(AccountTableHeaders.Note.Name, newRecordIndex, note);
104119
}
105120
}
106121
}

TransactionTable/AccountTransactions/TransactionPresets/AddFee.cs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,57 @@ public void AddFee(DateTime feeDate, DepositAccount cashAccount, double amount,
3434
public void AddFee(DateTime feeDate, DepositAccount cashAccount, decimal amount, Objects.Security? security = null ,string? note = null)
3535
{
3636
Table table = GetTable(feeDate);
37-
int index = table.AppendEmptyRecord();
37+
// insert record at specified position
38+
int? index = null;
39+
if (this._KeepTableTimeSorted)
40+
{
41+
index = FetchIndexForRecordInsert(feeDate);
42+
}
43+
int newRecordIndex;
44+
if (index == null)
45+
{
46+
newRecordIndex = table.AppendEmptyRecord();
47+
}
48+
else
49+
{
50+
newRecordIndex = index.Value;
51+
table.InsertEmptyRecord(newRecordIndex);
52+
}
3853
// set transaction type
39-
table.SetCell(AccountTableHeaders.Type.Name, index, AccountTransactionTypes.Fees.Name);
54+
table.SetCell(AccountTableHeaders.Type.Name, newRecordIndex, AccountTransactionTypes.Fees.Name);
4055
// select account, currency is defined by account
41-
table.SetCell(AccountTableHeaders.CashAccount.Name, index, cashAccount.Name);
56+
table.SetCell(AccountTableHeaders.CashAccount.Name, newRecordIndex, cashAccount.Name);
4257
// set the time
4358
SplitDateTime time = DateTimeHelper.Split(feeDate);
44-
table.SetCell(AccountTableHeaders.Date.Name, index, time.Date);
45-
table.SetCell(AccountTableHeaders.Time.Name, index, time.Time);
59+
table.SetCell(AccountTableHeaders.Date.Name, newRecordIndex, time.Date);
60+
table.SetCell(AccountTableHeaders.Time.Name, newRecordIndex, time.Time);
4661
// set the amount
47-
table.SetCell(AccountTableHeaders.Value.Name, index, ((decimal)amount).ToString("G"));
62+
table.SetCell(AccountTableHeaders.Value.Name, newRecordIndex, ((decimal)amount).ToString("G"));
4863
// set the security
4964
if (security != null)
5065
{
5166
if (security.ISIN != null)
5267
{
53-
table.SetCell(AccountTableHeaders.ISIN.Name, index, security.ISIN);
68+
table.SetCell(AccountTableHeaders.ISIN.Name, newRecordIndex, security.ISIN);
5469
}
5570
if (security.WKN != null)
5671
{
57-
table.SetCell(AccountTableHeaders.WKN.Name, index, security.WKN);
72+
table.SetCell(AccountTableHeaders.WKN.Name, newRecordIndex, security.WKN);
5873
}
5974
if (security.TickerSymbol != null)
6075
{
61-
table.SetCell(AccountTableHeaders.Symbol.Name, index, security.TickerSymbol);
76+
table.SetCell(AccountTableHeaders.Symbol.Name, newRecordIndex, security.TickerSymbol);
6277
}
6378
if (security.Name != null)
6479
{
65-
table.SetCell(AccountTableHeaders.SecurityName.Name, index, security.Name);
80+
table.SetCell(AccountTableHeaders.SecurityName.Name, newRecordIndex, security.Name);
6681
}
67-
table.SetCell(AccountTableHeaders.TransactionCurrency.Name, index, security.ReferenceCurrency);
82+
table.SetCell(AccountTableHeaders.TransactionCurrency.Name, newRecordIndex, security.ReferenceCurrency);
6883
}
6984
// set the notes
7085
if (!string.IsNullOrEmpty(note))
7186
{
72-
table.SetCell(AccountTableHeaders.Note.Name, index, note);
87+
table.SetCell(AccountTableHeaders.Note.Name, newRecordIndex, note);
7388
}
7489
}
7590
}

TransactionTable/AccountTransactions/TransactionPresets/AddFeeRefund.cs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,57 @@ public void AddFeeRefund(DateTime feeDate, DepositAccount cashAccount, double am
3535
public void AddFeeRefund(DateTime feeDate, DepositAccount cashAccount, decimal amount, Objects.Security? security = null ,string? note = null)
3636
{
3737
Table table = GetTable(feeDate);
38-
int index = table.AppendEmptyRecord();
38+
// insert record at specified position
39+
int? index = null;
40+
if (this._KeepTableTimeSorted)
41+
{
42+
index = FetchIndexForRecordInsert(feeDate);
43+
}
44+
int newRecordIndex;
45+
if (index == null)
46+
{
47+
newRecordIndex = table.AppendEmptyRecord();
48+
}
49+
else
50+
{
51+
newRecordIndex = index.Value;
52+
table.InsertEmptyRecord(newRecordIndex);
53+
}
3954
// set transaction type
40-
table.SetCell(AccountTableHeaders.Type.Name, index, AccountTransactionTypes.FeesRefund.Name);
55+
table.SetCell(AccountTableHeaders.Type.Name, newRecordIndex, AccountTransactionTypes.FeesRefund.Name);
4156
// select account, currency is defined by account
42-
table.SetCell(AccountTableHeaders.CashAccount.Name, index, cashAccount.Name);
57+
table.SetCell(AccountTableHeaders.CashAccount.Name, newRecordIndex, cashAccount.Name);
4358
// set the time
4459
SplitDateTime time = DateTimeHelper.Split(feeDate);
45-
table.SetCell(AccountTableHeaders.Date.Name, index, time.Date);
46-
table.SetCell(AccountTableHeaders.Time.Name, index, time.Time);
60+
table.SetCell(AccountTableHeaders.Date.Name, newRecordIndex, time.Date);
61+
table.SetCell(AccountTableHeaders.Time.Name, newRecordIndex, time.Time);
4762
// set the amount
48-
table.SetCell(AccountTableHeaders.Value.Name, index, ((decimal)amount).ToString("G"));
63+
table.SetCell(AccountTableHeaders.Value.Name, newRecordIndex, ((decimal)amount).ToString("G"));
4964
// set the security
5065
if (security != null)
5166
{
5267
if (security.ISIN != null)
5368
{
54-
table.SetCell(AccountTableHeaders.ISIN.Name, index, security.ISIN);
69+
table.SetCell(AccountTableHeaders.ISIN.Name, newRecordIndex, security.ISIN);
5570
}
5671
if (security.WKN != null)
5772
{
58-
table.SetCell(AccountTableHeaders.WKN.Name, index, security.WKN);
73+
table.SetCell(AccountTableHeaders.WKN.Name, newRecordIndex, security.WKN);
5974
}
6075
if (security.TickerSymbol != null)
6176
{
62-
table.SetCell(AccountTableHeaders.Symbol.Name, index, security.TickerSymbol);
77+
table.SetCell(AccountTableHeaders.Symbol.Name, newRecordIndex, security.TickerSymbol);
6378
}
6479
if (security.Name != null)
6580
{
66-
table.SetCell(AccountTableHeaders.SecurityName.Name, index, security.Name);
81+
table.SetCell(AccountTableHeaders.SecurityName.Name, newRecordIndex, security.Name);
6782
}
68-
table.SetCell(AccountTableHeaders.TransactionCurrency.Name, index, security.ReferenceCurrency);
83+
table.SetCell(AccountTableHeaders.TransactionCurrency.Name, newRecordIndex, security.ReferenceCurrency);
6984
}
7085
// set the notes
7186
if (!string.IsNullOrEmpty(note))
7287
{
73-
table.SetCell(AccountTableHeaders.Note.Name, index, note);
88+
table.SetCell(AccountTableHeaders.Note.Name, newRecordIndex, note);
7489
}
7590
}
7691
}

TransactionTable/AccountTransactions/TransactionPresets/AddInterest.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,46 @@ public void AddInterest(DateTime interestDate, DepositAccount cashAccount,
5656
}
5757
}
5858
Table table = GetTable(interestDate);
59-
int index = table.AppendEmptyRecord();
59+
// insert record at specified position
60+
int? index = null;
61+
if (this._KeepTableTimeSorted)
62+
{
63+
index = FetchIndexForRecordInsert(interestDate);
64+
}
65+
int newRecordIndex;
66+
if (index == null)
67+
{
68+
newRecordIndex = table.AppendEmptyRecord();
69+
}
70+
else
71+
{
72+
newRecordIndex = index.Value;
73+
table.InsertEmptyRecord(newRecordIndex);
74+
}
6075
// set transaction type
61-
table.SetCell(AccountTableHeaders.Type.Name, index, AccountTransactionTypes.Interest.Name);
76+
table.SetCell(AccountTableHeaders.Type.Name, newRecordIndex, AccountTransactionTypes.Interest.Name);
6277
// select account, currency is defined by account
63-
table.SetCell(AccountTableHeaders.CashAccount.Name, index, cashAccount.Name);
78+
table.SetCell(AccountTableHeaders.CashAccount.Name, newRecordIndex, cashAccount.Name);
6479
// set the time
6580
SplitDateTime time = DateTimeHelper.Split(interestDate);
66-
table.SetCell(AccountTableHeaders.Date.Name, index, time.Date);
67-
table.SetCell(AccountTableHeaders.Time.Name, index, time.Time);
81+
table.SetCell(AccountTableHeaders.Date.Name, newRecordIndex, time.Date);
82+
table.SetCell(AccountTableHeaders.Time.Name, newRecordIndex, time.Time);
6883
// set the amount
69-
table.SetCell(AccountTableHeaders.GrossAmount.Name, index, ((decimal)grossAmount).ToString("G"));
84+
table.SetCell(AccountTableHeaders.GrossAmount.Name, newRecordIndex, ((decimal)grossAmount).ToString("G"));
7085
// set taxes
7186
if (taxes != null)
7287
{
73-
table.SetCell(AccountTableHeaders.Taxes.Name, index, ((decimal)taxes).ToString("G"));
74-
table.SetCell(AccountTableHeaders.Value.Name, index, ((decimal)(grossAmount-taxes)).ToString("G"));
88+
table.SetCell(AccountTableHeaders.Taxes.Name, newRecordIndex, ((decimal)taxes).ToString("G"));
89+
table.SetCell(AccountTableHeaders.Value.Name, newRecordIndex, ((decimal)(grossAmount-taxes)).ToString("G"));
7590
}
7691
else
7792
{
78-
table.SetCell(AccountTableHeaders.Value.Name, index, ((decimal)(grossAmount)).ToString("G"));
93+
table.SetCell(AccountTableHeaders.Value.Name, newRecordIndex, ((decimal)(grossAmount)).ToString("G"));
7994
}
8095
// set the notes
8196
if (!string.IsNullOrEmpty(note))
8297
{
83-
table.SetCell(AccountTableHeaders.Note.Name, index, note);
98+
table.SetCell(AccountTableHeaders.Note.Name, newRecordIndex, note);
8499
}
85100
}
86101
}

TransactionTable/AccountTransactions/TransactionPresets/AddInterestCharge.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,36 @@ public void AddInterestCharge(DateTime interestDate, DepositAccount cashAccount,
4343
public void AddInterestCharge(DateTime interestDate, DepositAccount cashAccount, decimal amount, string? note = null)
4444
{
4545
Table table = GetTable(interestDate);
46-
int index = table.AppendEmptyRecord();
46+
// insert record at specified position
47+
int? index = null;
48+
if (this._KeepTableTimeSorted)
49+
{
50+
index = FetchIndexForRecordInsert(interestDate);
51+
}
52+
int newRecordIndex;
53+
if (index == null)
54+
{
55+
newRecordIndex = table.AppendEmptyRecord();
56+
}
57+
else
58+
{
59+
newRecordIndex = index.Value;
60+
table.InsertEmptyRecord(newRecordIndex);
61+
}
4762
// set transaction type
48-
table.SetCell(AccountTableHeaders.Type.Name, index, AccountTransactionTypes.InterestCharge.Name);
63+
table.SetCell(AccountTableHeaders.Type.Name, newRecordIndex, AccountTransactionTypes.InterestCharge.Name);
4964
// select account, currency is defined by account
50-
table.SetCell(AccountTableHeaders.CashAccount.Name, index, cashAccount.Name);
65+
table.SetCell(AccountTableHeaders.CashAccount.Name, newRecordIndex, cashAccount.Name);
5166
// set the time
5267
SplitDateTime time = DateTimeHelper.Split(interestDate);
53-
table.SetCell(AccountTableHeaders.Date.Name, index, time.Date);
54-
table.SetCell(AccountTableHeaders.Time.Name, index, time.Time);
68+
table.SetCell(AccountTableHeaders.Date.Name, newRecordIndex, time.Date);
69+
table.SetCell(AccountTableHeaders.Time.Name, newRecordIndex, time.Time);
5570
// set the amount
56-
table.SetCell(AccountTableHeaders.Value.Name, index, ((decimal)amount).ToString("G"));
71+
table.SetCell(AccountTableHeaders.Value.Name, newRecordIndex, ((decimal)amount).ToString("G"));
5772
// set the notes
5873
if (!string.IsNullOrEmpty(note))
5974
{
60-
table.SetCell(AccountTableHeaders.Note.Name, index, note);
75+
table.SetCell(AccountTableHeaders.Note.Name, newRecordIndex, note);
6176
}
6277
}
6378
}

0 commit comments

Comments
 (0)