From 148f6aaabf1b8ae26771602bb02d378f71561a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Tue, 20 Feb 2024 18:02:07 +0100 Subject: [PATCH] Summering vid listning av transar --- WinFormDi.BLI/IAccountRecordRepository.cs | 1 + WinFormDi.BLR/AccountRecordRepository.cs | 6 ++ WinFormDi.BLR/ReadingIn.cs | 2 + WinFormDi/ListViewColumnSorter.cs | 105 ++++++++++++++++++++++ WinFormDi/frmPayments.cs | 3 + 5 files changed, 117 insertions(+) create mode 100644 WinFormDi/ListViewColumnSorter.cs diff --git a/WinFormDi.BLI/IAccountRecordRepository.cs b/WinFormDi.BLI/IAccountRecordRepository.cs index 183187f..0add9ad 100644 --- a/WinFormDi.BLI/IAccountRecordRepository.cs +++ b/WinFormDi.BLI/IAccountRecordRepository.cs @@ -11,5 +11,6 @@ namespace WinFormDiApp.BLI IEnumerable GetAllAccBetweenDates(DateTime dateFrom, DateTime dateTo); IEnumerable GetAllAccounts(); AccountRecord GetAccount(int id); + AccountRecord GetAccountByDateBelKonto(DateTime _date, double _belopp, string _konto); } } \ No newline at end of file diff --git a/WinFormDi.BLR/AccountRecordRepository.cs b/WinFormDi.BLR/AccountRecordRepository.cs index ceac900..5d9956e 100644 --- a/WinFormDi.BLR/AccountRecordRepository.cs +++ b/WinFormDi.BLR/AccountRecordRepository.cs @@ -132,4 +132,10 @@ public class AccountRecordRepository : IAccountRecordRepository return accountRec; } + public AccountRecord GetAccountByDateBelKonto(DateTime _date,double _belopp,string _konto) + { + var accountRec = _dataContext.AccountRecords.FirstOrDefault(a => a.BetalDatum == _date && a.Belopp==_belopp && a.Konto==_konto); + return accountRec; + } + } diff --git a/WinFormDi.BLR/ReadingIn.cs b/WinFormDi.BLR/ReadingIn.cs index 0c50dc7..f8c113b 100644 --- a/WinFormDi.BLR/ReadingIn.cs +++ b/WinFormDi.BLR/ReadingIn.cs @@ -144,7 +144,9 @@ public class ReadingIn : IReadingIn, IDisposable restab.ToList().ForEach(x => { + if (_accountRecordRepository.GetAccountByDateBelKonto(x.BetalDatum, x.Belopp, x.Konto)==null) _accountRecordRepository.AddAccountRecord(x); + else { }; }); // restab.ToList().ForEach(x => { _accountRecordRepository.AddAccountRecord(x); }); diff --git a/WinFormDi/ListViewColumnSorter.cs b/WinFormDi/ListViewColumnSorter.cs new file mode 100644 index 0000000..3150e9b --- /dev/null +++ b/WinFormDi/ListViewColumnSorter.cs @@ -0,0 +1,105 @@ +using System.Collections; +using System.Windows.Forms; + +/// +/// This class is an implementation of the 'IComparer' interface. +/// +public class ListViewColumnSorter : IComparer +{ + /// + /// Specifies the column to be sorted + /// + private int ColumnToSort; + + /// + /// Specifies the order in which to sort (i.e. 'Ascending'). + /// + private SortOrder OrderOfSort; + + /// + /// Case insensitive comparer object + /// + private CaseInsensitiveComparer ObjectCompare; + + /// + /// Class constructor. Initializes various elements + /// + public ListViewColumnSorter() + { + // Initialize the column to '0' + ColumnToSort = 0; + + // Initialize the sort order to 'none' + OrderOfSort = SortOrder.None; + + // Initialize the CaseInsensitiveComparer object + ObjectCompare = new CaseInsensitiveComparer(); + } + + /// + /// This method is inherited from the IComparer interface. It compares the two objects passed using a case insensitive comparison. + /// + /// First object to be compared + /// Second object to be compared + /// The result of the comparison. "0" if equal, negative if 'x' is less than 'y' and positive if 'x' is greater than 'y' + public int Compare(object x, object y) + { + int compareResult; + ListViewItem listviewX, listviewY; + + // Cast the objects to be compared to ListViewItem objects + listviewX = (ListViewItem)x; + listviewY = (ListViewItem)y; + + // Compare the two items + compareResult = ObjectCompare.Compare(listviewX.SubItems[ColumnToSort].Text, listviewY.SubItems[ColumnToSort].Text); + + // Calculate correct return value based on object comparison + if (OrderOfSort == SortOrder.Ascending) + { + // Ascending sort is selected, return normal result of compare operation + return compareResult; + } + else if (OrderOfSort == SortOrder.Descending) + { + // Descending sort is selected, return negative result of compare operation + return (-compareResult); + } + else + { + // Return '0' to indicate they are equal + return 0; + } + } + + /// + /// Gets or sets the number of the column to which to apply the sorting operation (Defaults to '0'). + /// + public int SortColumn + { + set + { + ColumnToSort = value; + } + get + { + return ColumnToSort; + } + } + + /// + /// Gets or sets the order of sorting to apply (for example, 'Ascending' or 'Descending'). + /// + public SortOrder Order + { + set + { + OrderOfSort = value; + } + get + { + return OrderOfSort; + } + } + +} \ No newline at end of file diff --git a/WinFormDi/frmPayments.cs b/WinFormDi/frmPayments.cs index cd5ce09..a300574 100644 --- a/WinFormDi/frmPayments.cs +++ b/WinFormDi/frmPayments.cs @@ -119,5 +119,8 @@ namespace WinFormDiApp } } } + //------------------------------------------------- sorting ------------ + + //------------------------------------------------- sorting ------------ } }