diff --git a/WinFormDi.BLI/IAccountRecordRepository.cs b/WinFormDi.BLI/IAccountRecordRepository.cs index ba09f1c..0a02099 100644 --- a/WinFormDi.BLI/IAccountRecordRepository.cs +++ b/WinFormDi.BLI/IAccountRecordRepository.cs @@ -8,5 +8,6 @@ namespace WinFormDiApp.BLI bool DeleteAccountRecord(AccountRecord record); IEnumerable GetAllAccBetweenDates(DateTime dateFrom, DateTime dateTo); IEnumerable GetAllAccounts(); + AccountRecord GetAccount(int id); } } \ No newline at end of file diff --git a/WinFormDi.BLR/AccountRecordRepository.cs b/WinFormDi.BLR/AccountRecordRepository.cs index c96328c..f1b5930 100644 --- a/WinFormDi.BLR/AccountRecordRepository.cs +++ b/WinFormDi.BLR/AccountRecordRepository.cs @@ -74,4 +74,10 @@ public class AccountRecordRepository : IAccountRecordRepository return _dataContext.AccountRecords; } + public AccountRecord GetAccount(int id) + { + var accountRec = _dataContext.AccountRecords.FirstOrDefault(a => a.Id == id); + return accountRec; + } + } diff --git a/WinFormDi/ContainerConfig.cs b/WinFormDi/ContainerConfig.cs index 64d918f..fa66398 100644 --- a/WinFormDi/ContainerConfig.cs +++ b/WinFormDi/ContainerConfig.cs @@ -14,6 +14,7 @@ using WinFormDiApp.DAL; using WinFormDiApp.BL; using WinFormDiApp.BLI; using WinFormDiApp.BLR; +using WinFormDi; namespace WinFormDiApp { @@ -44,7 +45,8 @@ namespace WinFormDiApp .AddTransient() .AddTransient() .AddTransient() - .AddTransient(); + .AddTransient() + .AddTransient(); }); return builder.Build(); } diff --git a/WinFormDi/MainWindow.Designer.cs b/WinFormDi/MainWindow.Designer.cs index 03ffa91..b702b45 100644 --- a/WinFormDi/MainWindow.Designer.cs +++ b/WinFormDi/MainWindow.Designer.cs @@ -34,6 +34,7 @@ btnLoadPayments = new Button(); btnSearchPayments = new Button(); btnClose = new Button(); + btnEdit = new Button(); SuspendLayout(); // // helloText @@ -96,11 +97,22 @@ btnClose.UseVisualStyleBackColor = true; btnClose.Click += btnClose_Click; // + // btnEdit + // + btnEdit.Location = new Point(75, 128); + btnEdit.Name = "btnEdit"; + btnEdit.Size = new Size(156, 23); + btnEdit.TabIndex = 6; + btnEdit.Text = "Justera/Addera betalning"; + btnEdit.UseVisualStyleBackColor = true; + btnEdit.Click += btnEdit_Click; + // // MainWindow // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); + Controls.Add(btnEdit); Controls.Add(btnClose); Controls.Add(btnSearchPayments); Controls.Add(btnLoadPayments); @@ -124,5 +136,6 @@ private Button btnLoadPayments; private Button btnSearchPayments; private Button btnClose; + private Button btnEdit; } } \ No newline at end of file diff --git a/WinFormDi/MainWindow.cs b/WinFormDi/MainWindow.cs index 2efbcb9..35efeb8 100644 --- a/WinFormDi/MainWindow.cs +++ b/WinFormDi/MainWindow.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using WinFormDi; namespace WinFormDiApp { @@ -17,12 +18,14 @@ namespace WinFormDiApp private readonly frmPayments _payments; private readonly frmReadPayments _readPayments; private readonly frmSearchData _searchData; + private readonly frmEditPayment _editPayment; public MainWindow( IMessages messages, frmPayments payments, frmReadPayments readPayments, - frmSearchData searchData + frmSearchData searchData, + frmEditPayment editPayment ) { InitializeComponent(); @@ -30,6 +33,7 @@ namespace WinFormDiApp _payments = payments; _readPayments = readPayments; _searchData = searchData; + _editPayment = editPayment; } private void MainWindow_Load(object sender, EventArgs e) @@ -62,5 +66,10 @@ namespace WinFormDiApp { this.Close(); } + + private void btnEdit_Click(object sender, EventArgs e) + { + _editPayment.ShowDialog(); + } } } diff --git a/WinFormDi/frmEditPayment.Designer.cs b/WinFormDi/frmEditPayment.Designer.cs new file mode 100644 index 0000000..7871e9a --- /dev/null +++ b/WinFormDi/frmEditPayment.Designer.cs @@ -0,0 +1,288 @@ +namespace WinFormDiApp +{ + partial class frmEditPayment + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + lblHeader = new Label(); + rbNew = new RadioButton(); + rbEdit = new RadioButton(); + lblIdHeader = new Label(); + txtId = new TextBox(); + txtAccount = new TextBox(); + lblKonto = new Label(); + txtReceiver = new TextBox(); + lblReceiver = new Label(); + txtAmount = new TextBox(); + lblAmount = new Label(); + lblPayDate = new Label(); + txtPayInfo = new TextBox(); + lblBetInfo = new Label(); + tblChangeRegTime = new Label(); + dtpPayDate = new DateTimePicker(); + btnSave = new Button(); + btnClose = new Button(); + btnSearch = new Button(); + txtSaved = new TextBox(); + SuspendLayout(); + // + // lblHeader + // + lblHeader.AutoSize = true; + lblHeader.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); + lblHeader.Location = new Point(30, 29); + lblHeader.Name = "lblHeader"; + lblHeader.Size = new Size(216, 21); + lblHeader.TabIndex = 0; + lblHeader.Text = "Manuell inmatning / justering"; + // + // rbNew + // + rbNew.AutoSize = true; + rbNew.Checked = true; + rbNew.Location = new Point(33, 75); + rbNew.Name = "rbNew"; + rbNew.Size = new Size(103, 19); + rbNew.TabIndex = 2; + rbNew.TabStop = true; + rbNew.Text = "Ny registrering"; + rbNew.UseVisualStyleBackColor = true; + rbNew.CheckedChanged += rbNew_CheckedChanged; + // + // rbEdit + // + rbEdit.AutoSize = true; + rbEdit.Location = new Point(33, 100); + rbEdit.Name = "rbEdit"; + rbEdit.Size = new Size(68, 19); + rbEdit.TabIndex = 3; + rbEdit.Text = "Ändring"; + rbEdit.UseVisualStyleBackColor = true; + rbEdit.CheckedChanged += rbEdit_CheckedChanged; + // + // lblIdHeader + // + lblIdHeader.AutoSize = true; + lblIdHeader.Location = new Point(33, 134); + lblIdHeader.Name = "lblIdHeader"; + lblIdHeader.Size = new Size(51, 15); + lblIdHeader.TabIndex = 4; + lblIdHeader.Text = "Identitet"; + // + // txtId + // + txtId.Enabled = false; + txtId.Location = new Point(133, 131); + txtId.Name = "txtId"; + txtId.Size = new Size(139, 23); + txtId.TabIndex = 5; + // + // txtAccount + // + txtAccount.Location = new Point(133, 163); + txtAccount.Name = "txtAccount"; + txtAccount.Size = new Size(139, 23); + txtAccount.TabIndex = 7; + // + // lblKonto + // + lblKonto.AutoSize = true; + lblKonto.Location = new Point(33, 166); + lblKonto.Name = "lblKonto"; + lblKonto.Size = new Size(39, 15); + lblKonto.TabIndex = 6; + lblKonto.Text = "Konto"; + // + // txtReceiver + // + txtReceiver.Location = new Point(133, 201); + txtReceiver.Name = "txtReceiver"; + txtReceiver.Size = new Size(353, 23); + txtReceiver.TabIndex = 9; + // + // lblReceiver + // + lblReceiver.AutoSize = true; + lblReceiver.Location = new Point(33, 204); + lblReceiver.Name = "lblReceiver"; + lblReceiver.Size = new Size(62, 15); + lblReceiver.TabIndex = 8; + lblReceiver.Text = "Mottagare"; + // + // txtAmount + // + txtAmount.Location = new Point(133, 239); + txtAmount.Name = "txtAmount"; + txtAmount.Size = new Size(139, 23); + txtAmount.TabIndex = 11; + // + // lblAmount + // + lblAmount.AutoSize = true; + lblAmount.Location = new Point(33, 242); + lblAmount.Name = "lblAmount"; + lblAmount.Size = new Size(44, 15); + lblAmount.TabIndex = 10; + lblAmount.Text = "Belopp"; + // + // lblPayDate + // + lblPayDate.AutoSize = true; + lblPayDate.Location = new Point(33, 280); + lblPayDate.Name = "lblPayDate"; + lblPayDate.Size = new Size(67, 15); + lblPayDate.TabIndex = 12; + lblPayDate.Text = "Förfallodag"; + // + // txtPayInfo + // + txtPayInfo.Location = new Point(133, 315); + txtPayInfo.Name = "txtPayInfo"; + txtPayInfo.Size = new Size(139, 23); + txtPayInfo.TabIndex = 15; + // + // lblBetInfo + // + lblBetInfo.AutoSize = true; + lblBetInfo.Location = new Point(30, 318); + lblBetInfo.Name = "lblBetInfo"; + lblBetInfo.Size = new Size(56, 15); + lblBetInfo.TabIndex = 14; + lblBetInfo.Text = "Avisering"; + // + // tblChangeRegTime + // + tblChangeRegTime.AutoSize = true; + tblChangeRegTime.Location = new Point(33, 356); + tblChangeRegTime.Name = "tblChangeRegTime"; + tblChangeRegTime.Size = new Size(89, 15); + tblChangeRegTime.TabIndex = 16; + tblChangeRegTime.Text = "Ändring Sparad"; + // + // dtpPayDate + // + dtpPayDate.Format = DateTimePickerFormat.Short; + dtpPayDate.Location = new Point(133, 274); + dtpPayDate.Name = "dtpPayDate"; + dtpPayDate.Size = new Size(139, 23); + dtpPayDate.TabIndex = 18; + // + // btnSave + // + btnSave.Location = new Point(330, 464); + btnSave.Name = "btnSave"; + btnSave.Size = new Size(75, 23); + btnSave.TabIndex = 19; + btnSave.Text = "Spara"; + btnSave.UseVisualStyleBackColor = true; + // + // btnClose + // + btnClose.Location = new Point(411, 464); + btnClose.Name = "btnClose"; + btnClose.Size = new Size(75, 23); + btnClose.TabIndex = 20; + btnClose.Text = "Avbryt"; + btnClose.UseVisualStyleBackColor = true; + btnClose.Click += btnClose_Click; + // + // btnSearch + // + btnSearch.Location = new Point(278, 130); + btnSearch.Name = "btnSearch"; + btnSearch.Size = new Size(75, 23); + btnSearch.TabIndex = 21; + btnSearch.Text = "Sök post"; + btnSearch.UseVisualStyleBackColor = true; + btnSearch.Visible = false; + btnSearch.Click += btnSearch_Click; + // + // txtSaved + // + txtSaved.Enabled = false; + txtSaved.Location = new Point(133, 353); + txtSaved.Name = "txtSaved"; + txtSaved.Size = new Size(139, 23); + txtSaved.TabIndex = 17; + // + // frmEditPayment + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(527, 509); + Controls.Add(btnSearch); + Controls.Add(btnClose); + Controls.Add(btnSave); + Controls.Add(dtpPayDate); + Controls.Add(txtSaved); + Controls.Add(tblChangeRegTime); + Controls.Add(txtPayInfo); + Controls.Add(lblBetInfo); + Controls.Add(lblPayDate); + Controls.Add(txtAmount); + Controls.Add(lblAmount); + Controls.Add(txtReceiver); + Controls.Add(lblReceiver); + Controls.Add(txtAccount); + Controls.Add(lblKonto); + Controls.Add(txtId); + Controls.Add(lblIdHeader); + Controls.Add(rbEdit); + Controls.Add(rbNew); + Controls.Add(lblHeader); + Name = "frmEditPayment"; + StartPosition = FormStartPosition.CenterScreen; + Text = "frmEditPayment"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label lblHeader; + private RadioButton rbNew; + private RadioButton rbEdit; + private Label lblIdHeader; + private TextBox txtId; + private TextBox txtAccount; + private Label lblKonto; + private TextBox txtReceiver; + private Label lblReceiver; + private TextBox txtAmount; + private Label lblAmount; + private TextBox txtLastPaydate; + private Label lblPayDate; + private TextBox txtPayInfo; + private Label lblBetInfo; + private Label tblChangeRegTime; + private DateTimePicker dtpPayDate; + private Button btnSave; + private Button btnClose; + private Button btnSearch; + private TextBox txtSaved; + } +} \ No newline at end of file diff --git a/WinFormDi/frmEditPayment.cs b/WinFormDi/frmEditPayment.cs new file mode 100644 index 0000000..df39363 --- /dev/null +++ b/WinFormDi/frmEditPayment.cs @@ -0,0 +1,69 @@ +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.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(); + + } + } + } + } +} diff --git a/WinFormDi/frmEditPayment.resx b/WinFormDi/frmEditPayment.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormDi/frmEditPayment.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file