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

View File

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

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormDiApp.BL.Models;
using WinFormDiApp.BLI;
namespace WinFormDiApp
@ -21,8 +22,34 @@ namespace WinFormDiApp
lvPayments.Items.Clear();
_accountRecordRepository = accountRecordRepository;
}
public IEnumerable<AccountRecord>? CustomPayments { get; set; } = null;
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();
var payments = _accountRecordRepository.GetAllAccounts();
@ -36,10 +63,7 @@ namespace WinFormDiApp
lvitem.SubItems.Add(account.Avisering);
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
else CustomPayments = null;
}
}
}

View File

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