101 lines
3.2 KiB
C#
101 lines
3.2 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.Helpers;
|
|
using WinFormDiApp.BL.Models;
|
|
using WinFormDiApp.BLI;
|
|
|
|
namespace WinFormDiApp
|
|
{
|
|
public partial class frmEditPayment : Form
|
|
{
|
|
private readonly IAccountRecordRepository _recordRepository;
|
|
|
|
public frmEditPayment(IAccountRecordRepository recordRepository)
|
|
{
|
|
InitializeComponent();
|
|
_recordRepository = recordRepository;
|
|
}
|
|
|
|
private void rbNew_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (rbNew.Checked)
|
|
{
|
|
txtId.Enabled = false;
|
|
btnSearch.Enabled = false;
|
|
btnSearch.Visible = false;
|
|
|
|
}
|
|
}
|
|
|
|
private void rbEdit_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (rbEdit.Checked)
|
|
{
|
|
txtId.Enabled = true;
|
|
btnSearch.Enabled = true;
|
|
btnSearch.Visible = true;
|
|
}
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
if (txtId.Text.IsNumeric())
|
|
{
|
|
var editRecord = _recordRepository.GetAccount(int.Parse(txtId.Text));
|
|
if (editRecord != null)
|
|
{
|
|
txtAccount.Text = editRecord.Konto.ToString();
|
|
txtAmount.Text = editRecord.Belopp.ToString();
|
|
txtPayInfo.Text = editRecord.Avisering.ToString();
|
|
txtReceiver.Text = editRecord.Mottagare.ToString();
|
|
dtpPayDate.Value = editRecord.BetalDatum;
|
|
txtSaved.Text = editRecord.Stored.ToLongDateString();
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
AccountRecord saveRecord = new AccountRecord();
|
|
if(rbEdit.Checked)
|
|
{
|
|
saveRecord.Id = Convert.ToInt32( txtId.Text);
|
|
saveRecord.Stored = DateTime.Parse(txtSaved.Text);
|
|
}
|
|
saveRecord.Konto = txtAccount.Text;
|
|
saveRecord.Belopp = Convert.ToDouble(txtAmount.Text);
|
|
saveRecord.Avisering = txtPayInfo.Text;
|
|
saveRecord.Mottagare = txtReceiver.Text;
|
|
saveRecord.BetalDatum =dtpPayDate.Value;
|
|
;
|
|
|
|
_recordRepository.SaveAcountRecord(saveRecord);
|
|
|
|
if (saveRecord != null)
|
|
{
|
|
rbEdit.Checked = true;
|
|
txtId.Text = saveRecord.Id.ToString();
|
|
txtAccount.Text = saveRecord.Konto.ToString();
|
|
txtAmount.Text = saveRecord.Belopp.ToString();
|
|
txtPayInfo.Text = saveRecord.Avisering.ToString();
|
|
txtReceiver.Text = saveRecord.Mottagare.ToString();
|
|
dtpPayDate.Value = saveRecord.BetalDatum;
|
|
txtSaved.Text = saveRecord.Stored.ToLongDateString();
|
|
}
|
|
}
|
|
}
|
|
}
|