Detaljvisning per mottagare fixad

This commit is contained in:
2023-09-13 00:41:07 +02:00
parent de6e196809
commit d7774c70ee
4 changed files with 62 additions and 26 deletions

View File

@ -7,20 +7,23 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using WinFormDiApp;
namespace WinFormDi.UserControls namespace WinFormDi.UserControls
{ {
public partial class ucCustomerValue : UserControl public partial class ucCustomerValue : UserControl
{ {
private readonly frmSearchData _parentForm;
public ucCustomerValue() public ucCustomerValue(frmSearchData parentForm)
{ {
InitializeComponent(); InitializeComponent();
_parentForm = parentForm;
} }
private void btnShowMore_Click(object sender, EventArgs e) private void btnShowMore_Click(object sender, EventArgs e)
{ {
_parentForm.ShowDetails(Convert.ToString(this.Tag));
} }
public string Receiver { get => lblCustName.Text; set => lblCustName.Text = value; } public string Receiver { get => lblCustName.Text; set => lblCustName.Text = value; }

View File

@ -100,6 +100,7 @@
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
Text = "frmPayments"; Text = "frmPayments";
Load += frmPayments_Load; Load += frmPayments_Load;
Shown += frmPayments_Shown;
ResumeLayout(false); ResumeLayout(false);
} }

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using WinFormDiApp.BL.Models;
using WinFormDiApp.BLI; using WinFormDiApp.BLI;
namespace WinFormDiApp namespace WinFormDiApp
@ -21,8 +22,34 @@ namespace WinFormDiApp
lvPayments.Items.Clear(); lvPayments.Items.Clear();
_accountRecordRepository = accountRecordRepository; _accountRecordRepository = accountRecordRepository;
} }
public IEnumerable<AccountRecord>? CustomPayments { get; set; } = null;
private void frmPayments_Load(object sender, EventArgs e) private void frmPayments_Load(object sender, EventArgs e)
{
//MessageBox.Show("Load");
lvPayments.Items.Clear();
if (CustomPayments != null)
{
foreach (var account in CustomPayments)
{
var lvitem = lvPayments.Items.Add(account.Id.ToString());
lvitem.SubItems.Add(account.Mottagare);
lvitem.SubItems.Add(account.Konto);
lvitem.SubItems.Add(account.Belopp.ToString());
lvitem.SubItems.Add(account.BetalDatum.ToShortDateString());
lvitem.SubItems.Add(account.Avisering);
}
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void frmPayments_Shown(object sender, EventArgs e)
{
//MessageBox.Show("Shown");
if (CustomPayments == null)
{ {
lvPayments.Items.Clear(); lvPayments.Items.Clear();
var payments = _accountRecordRepository.GetAllAccounts(); var payments = _accountRecordRepository.GetAllAccounts();
@ -36,10 +63,7 @@ namespace WinFormDiApp
lvitem.SubItems.Add(account.Avisering); lvitem.SubItems.Add(account.Avisering);
} }
} }
else CustomPayments = null;
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
} }
} }
} }

View File

@ -16,16 +16,21 @@ namespace WinFormDiApp
{ {
public partial class frmSearchData : Form public partial class frmSearchData : Form
{ {
private class AccCount : AccountRecord IEnumerable<AccountRecord>? foundRecs = null;
private class AccCount
{ {
public AccountRecord? AcRec { get; set; }
public int NoOfRecs { get; set; } public int NoOfRecs { get; set; }
public double SearchedSum { get; set; }
} }
private readonly IAccountRecordRepository _accountRecordRepository; private readonly IAccountRecordRepository _accountRecordRepository;
private readonly frmPayments _showPayments;
public frmSearchData(IAccountRecordRepository accountRecordRepository) public frmSearchData(IAccountRecordRepository accountRecordRepository,frmPayments showPayments)
{ {
InitializeComponent(); InitializeComponent();
_accountRecordRepository = accountRecordRepository; _accountRecordRepository = accountRecordRepository;
_showPayments = showPayments;
} }
private void btnClose_Click(object sender, EventArgs e) private void btnClose_Click(object sender, EventArgs e)
@ -36,8 +41,8 @@ namespace WinFormDiApp
private void btnStartSearch_Click(object sender, EventArgs e) private void btnStartSearch_Click(object sender, EventArgs e)
{ {
flpPanel1.Controls.Clear(); flpPanel1.Controls.Clear();
var result = _accountRecordRepository.GetAllAccBetweenDates(dtpFrom.Value, dtpTo.Value); foundRecs = _accountRecordRepository.GetAllAccBetweenDates(dtpFrom.Value, dtpTo.Value);
var aggregates = aggegateAccounts(result); var aggregates = aggegateAccounts(foundRecs);
foreach (var account in aggregates) foreach (var account in aggregates)
{ {
var ucCustV = createAndFillUCcv(account); var ucCustV = createAndFillUCcv(account);
@ -47,10 +52,11 @@ namespace WinFormDiApp
private ucCustomerValue createAndFillUCcv(AccCount account) private ucCustomerValue createAndFillUCcv(AccCount account)
{ {
var result = new ucCustomerValue(); var result = new ucCustomerValue(this);
result.Amount = String.Format("{0:0.00}", account.Belopp).adjustRight(); result.Amount = String.Format("{0:0.00}", account.SearchedSum).adjustRight();
result.Receiver = account.Mottagare; result.Receiver = account.AcRec.Mottagare;
result.Number = Convert.ToString(account.NoOfRecs); result.Number = Convert.ToString(account.NoOfRecs);
result.Tag = account.AcRec.Konto;
return result; return result;
} }
@ -63,7 +69,7 @@ namespace WinFormDiApp
{ {
if (accountRecord.Mottagare == oldMott) if (accountRecord.Mottagare == oldMott)
{ {
wrkRec.Belopp += accountRecord.Belopp; wrkRec.SearchedSum += accountRecord.Belopp;
wrkRec.NoOfRecs++; wrkRec.NoOfRecs++;
} }
else else
@ -88,14 +94,16 @@ namespace WinFormDiApp
{ {
AccCount acc = new AccCount(); AccCount acc = new AccCount();
acc.NoOfRecs = 1; acc.NoOfRecs = 1;
acc.BetalDatum = accountRecord.BetalDatum; acc.AcRec = accountRecord;
acc.Stored = accountRecord.Stored; acc.SearchedSum = accountRecord.Belopp;
acc.Mottagare = accountRecord.Mottagare;
acc.Konto = accountRecord.Konto;
acc.Avisering = accountRecord.Avisering;
acc.Belopp = accountRecord.Belopp;
acc.Id = accountRecord.Id;
return acc; return acc;
} }
public void ShowDetails(string accountNo)
{
IEnumerable<AccountRecord> detailRecs = foundRecs.Where(fr => fr.Konto==accountNo);
_showPayments.CustomPayments = detailRecs;
_showPayments.ShowDialog();
}
} }
} }