Spara ny /ändrad införd
This commit is contained in:
@ -5,6 +5,7 @@ namespace WinFormDiApp.BLI
|
||||
public interface IAccountRecordRepository
|
||||
{
|
||||
bool AddAccountRecord(AccountRecord record);
|
||||
AccountRecord SaveAcountRecord(AccountRecord record);
|
||||
bool DeleteAccountRecord(AccountRecord record);
|
||||
IEnumerable<AccountRecord> GetAllAccBetweenDates(DateTime dateFrom, DateTime dateTo);
|
||||
IEnumerable<AccountRecord> GetAllAccounts();
|
||||
|
||||
@ -35,6 +35,43 @@ public class AccountRecordRepository : IAccountRecordRepository
|
||||
|
||||
}
|
||||
|
||||
public AccountRecord SaveAcountRecord(AccountRecord record)
|
||||
{
|
||||
try
|
||||
{
|
||||
var entity = (from account in _dataContext.AccountRecords
|
||||
where account.Id == record.Id
|
||||
select account).FirstOrDefault();
|
||||
if (entity == null)
|
||||
{
|
||||
entity = new AccountRecord();
|
||||
_dataContext.AccountRecords.Add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Stored= record.Stored;
|
||||
}
|
||||
|
||||
entity.Avisering = record.Avisering;
|
||||
entity.BetalDatum = record.BetalDatum;
|
||||
entity.Belopp = record.Belopp;
|
||||
entity.Konto = record.Konto;
|
||||
entity.Mottagare = record.Mottagare;
|
||||
|
||||
_dataContext.SaveChanges();
|
||||
|
||||
record.Id = entity.Id;
|
||||
|
||||
return entity;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError("Error occured in SaveAccountRecord :-->{iMessage}", e.Message);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool DeleteAccountRecord(AccountRecord record)
|
||||
{
|
||||
try
|
||||
|
||||
1
WinFormDi/frmEditPayment.Designer.cs
generated
1
WinFormDi/frmEditPayment.Designer.cs
generated
@ -199,6 +199,7 @@
|
||||
btnSave.TabIndex = 19;
|
||||
btnSave.Text = "Spara";
|
||||
btnSave.UseVisualStyleBackColor = true;
|
||||
btnSave.Click += btnSave_Click;
|
||||
//
|
||||
// btnClose
|
||||
//
|
||||
|
||||
@ -8,6 +8,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using WinFormDiApp.BL.Helpers;
|
||||
using WinFormDiApp.BL.Models;
|
||||
using WinFormDiApp.BLI;
|
||||
|
||||
namespace WinFormDiApp
|
||||
@ -65,5 +66,35 @@ namespace WinFormDiApp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user