106 lines
3.6 KiB
C#
106 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using WinFormDiApp.BL.Models;
|
|
using WinFormDiApp.BLI;
|
|
|
|
namespace WinFormDiApp
|
|
{
|
|
public partial class frmPayments : Form
|
|
{
|
|
private bool _enableClearing;
|
|
private readonly IAccountRecordRepository _accountRecordRepository;
|
|
|
|
public bool EnableClearing
|
|
{
|
|
get
|
|
{
|
|
return _enableClearing;
|
|
}
|
|
set
|
|
{
|
|
_enableClearing = value;
|
|
}
|
|
}
|
|
|
|
public frmPayments(IAccountRecordRepository accountRecordRepository)
|
|
{
|
|
InitializeComponent();
|
|
lvPayments.Items.Clear();
|
|
_accountRecordRepository = accountRecordRepository;
|
|
}
|
|
public IEnumerable<AccountRecord>? CustomPayments { get; set; } = null;
|
|
private void frmPayments_Load(object sender, EventArgs e)
|
|
{
|
|
//MessageBox.Show("Load");
|
|
btnRensa.Visible = _enableClearing;
|
|
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();
|
|
foreach (var account in payments)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
else CustomPayments = null;
|
|
}
|
|
|
|
private void btnRensa_Click(object sender, EventArgs e)
|
|
{
|
|
if(MessageBox.Show("Verkligen Säker på att rensa DB?","Payments", MessageBoxButtons.YesNo, MessageBoxIcon.Question)==DialogResult.Yes)
|
|
{
|
|
MessageBox.Show("Nu rensar vi");
|
|
_accountRecordRepository.DeleteAllAccountRecords();
|
|
|
|
lvPayments.Items.Clear();
|
|
var payments = _accountRecordRepository.GetAllAccounts();
|
|
foreach (var account in payments)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|