diff --git a/WinFormDi.BLR/AccountRecordRepository.cs b/WinFormDi.BLR/AccountRecordRepository.cs index cb6a5a5..c96328c 100644 --- a/WinFormDi.BLR/AccountRecordRepository.cs +++ b/WinFormDi.BLR/AccountRecordRepository.cs @@ -53,22 +53,19 @@ public class AccountRecordRepository : IAccountRecordRepository public IEnumerable GetAllAccBetweenDates(DateTime dateFrom, DateTime dateTo) { IEnumerable result = null; - using (ApplicationDbContext dc = _dataContext) - { - result = (from acc in dc.AccountRecords - where acc.BetalDatum>dateFrom && acc.BetalDatum dateFrom && acc.BetalDatum < dateTo + orderby acc.Mottagare, acc.BetalDatum descending + select new AccountRecord + { + Id = acc.Id, + BetalDatum = acc.BetalDatum, + Mottagare = acc.Mottagare, + Avisering = acc.Avisering, + Belopp = acc.Belopp, + Konto = acc.Konto, + Stored = acc.Stored + }).ToList(); return result; } diff --git a/WinFormDi/UserControls/ucCustomerValue.Designer.cs b/WinFormDi/UserControls/ucCustomerValue.Designer.cs new file mode 100644 index 0000000..7fad43a --- /dev/null +++ b/WinFormDi/UserControls/ucCustomerValue.Designer.cs @@ -0,0 +1,100 @@ +namespace WinFormDi.UserControls +{ + partial class ucCustomerValue + { + /// + /// 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 Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + lblCustName = new Label(); + lblAmount = new Label(); + btnShowMore = new Button(); + lblNumberof = new Label(); + SuspendLayout(); + // + // lblCustName + // + lblCustName.AutoSize = true; + lblCustName.Font = new Font("Verdana Pro", 9F, FontStyle.Bold, GraphicsUnit.Point); + lblCustName.Location = new Point(3, 9); + lblCustName.Name = "lblCustName"; + lblCustName.Size = new Size(123, 14); + lblCustName.TabIndex = 0; + lblCustName.Text = "Customer default"; + // + // lblAmount + // + lblAmount.AutoSize = true; + lblAmount.Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point); + lblAmount.Location = new Point(317, 5); + lblAmount.Name = "lblAmount"; + lblAmount.Size = new Size(36, 20); + lblAmount.TabIndex = 1; + lblAmount.Text = "0,00"; + // + // btnShowMore + // + btnShowMore.BackColor = Color.FromArgb(192, 192, 255); + btnShowMore.ForeColor = Color.FromArgb(0, 0, 64); + btnShowMore.Location = new Point(563, 5); + btnShowMore.Name = "btnShowMore"; + btnShowMore.Size = new Size(72, 23); + btnShowMore.TabIndex = 2; + btnShowMore.Text = "Visa mer"; + btnShowMore.UseVisualStyleBackColor = false; + btnShowMore.Click += btnShowMore_Click; + // + // lblNumberof + // + lblNumberof.AutoSize = true; + lblNumberof.Location = new Point(505, 9); + lblNumberof.Name = "lblNumberof"; + lblNumberof.Size = new Size(13, 15); + lblNumberof.TabIndex = 3; + lblNumberof.Text = "0"; + // + // ucCustomerValue + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = Color.FromArgb(192, 255, 255); + Controls.Add(lblNumberof); + Controls.Add(btnShowMore); + Controls.Add(lblAmount); + Controls.Add(lblCustName); + Name = "ucCustomerValue"; + Size = new Size(638, 28); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label lblCustName; + private Label lblAmount; + private Button btnShowMore; + private Label lblNumberof; + } +} diff --git a/WinFormDi/UserControls/ucCustomerValue.cs b/WinFormDi/UserControls/ucCustomerValue.cs new file mode 100644 index 0000000..e417eb2 --- /dev/null +++ b/WinFormDi/UserControls/ucCustomerValue.cs @@ -0,0 +1,30 @@ +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; + +namespace WinFormDi.UserControls +{ + public partial class ucCustomerValue : UserControl + { + + public ucCustomerValue() + { + InitializeComponent(); + } + + private void btnShowMore_Click(object sender, EventArgs e) + { + + } + + public string Receiver { get => lblCustName.Text; set => lblCustName.Text = value; } + public string Number { get => lblNumberof.Text; set => lblNumberof.Text = value; } + public string Amount { get => lblAmount.Text; set => lblAmount.Text = value; } + } +} diff --git a/WinFormDi/UserControls/ucCustomerValue.resx b/WinFormDi/UserControls/ucCustomerValue.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormDi/UserControls/ucCustomerValue.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 diff --git a/WinFormDi/frmSearchData.Designer.cs b/WinFormDi/frmSearchData.Designer.cs index fc6fa17..d19b929 100644 --- a/WinFormDi/frmSearchData.Designer.cs +++ b/WinFormDi/frmSearchData.Designer.cs @@ -35,6 +35,7 @@ lblDateTo = new Label(); dtpTo = new DateTimePicker(); btnStartSearch = new Button(); + flpPanel1 = new FlowLayoutPanel(); SuspendLayout(); // // btnClose @@ -99,12 +100,23 @@ btnStartSearch.TabIndex = 7; btnStartSearch.Text = "Starta sökning"; btnStartSearch.UseVisualStyleBackColor = true; + btnStartSearch.Click += btnStartSearch_Click; + // + // flpPanel1 + // + flpPanel1.AutoScroll = true; + flpPanel1.BackColor = Color.Silver; + flpPanel1.Location = new Point(21, 102); + flpPanel1.Name = "flpPanel1"; + flpPanel1.Size = new Size(668, 314); + flpPanel1.TabIndex = 8; // // frmSearchData // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); + Controls.Add(flpPanel1); Controls.Add(btnStartSearch); Controls.Add(dtpTo); Controls.Add(lblDateTo); @@ -128,5 +140,6 @@ private Label lblDateTo; private DateTimePicker dtpTo; private Button btnStartSearch; + private FlowLayoutPanel flpPanel1; } } \ No newline at end of file diff --git a/WinFormDi/frmSearchData.cs b/WinFormDi/frmSearchData.cs index 64403f5..2085f1c 100644 --- a/WinFormDi/frmSearchData.cs +++ b/WinFormDi/frmSearchData.cs @@ -7,12 +7,19 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using WinFormDi.UserControls; +using WinFormDiApp.BL.Helpers; +using WinFormDiApp.BL.Models; using WinFormDiApp.BLI; namespace WinFormDiApp { public partial class frmSearchData : Form { + private class AccCount : AccountRecord + { + public int NoOfRecs { get; set; } + } private readonly IAccountRecordRepository _accountRecordRepository; public frmSearchData(IAccountRecordRepository accountRecordRepository) @@ -25,5 +32,70 @@ namespace WinFormDiApp { this.Close(); } + + private void btnStartSearch_Click(object sender, EventArgs e) + { + flpPanel1.Controls.Clear(); + var result = _accountRecordRepository.GetAllAccBetweenDates(dtpFrom.Value, dtpTo.Value); + var aggregates = aggegateAccounts(result); + foreach (var account in aggregates) + { + var ucCustV = createAndFillUCcv(account); + flpPanel1.Controls.Add(ucCustV); + } + } + + private ucCustomerValue createAndFillUCcv(AccCount account) + { + var result = new ucCustomerValue(); + result.Amount = String.Format("{0:0.00}", account.Belopp).adjustRight(); + result.Receiver = account.Mottagare; + result.Number = Convert.ToString(account.NoOfRecs); + return result; + } + + private IEnumerable aggegateAccounts(IEnumerable result) + { + List Localresult = new List(); + string oldMott = string.Empty; + AccCount wrkRec = null; + foreach (var accountRecord in result) + { + if (accountRecord.Mottagare == oldMott) + { + wrkRec.Belopp += accountRecord.Belopp; + wrkRec.NoOfRecs++; + } + else + { + oldMott = accountRecord.Mottagare; + if (wrkRec != null) + { + Localresult.Add(wrkRec); + wrkRec = AddAccountRecord(accountRecord); + } + else + { + wrkRec = AddAccountRecord(accountRecord); + } + } + } + Localresult.Add(wrkRec); + return Localresult; + } + + private AccCount AddAccountRecord(AccountRecord accountRecord) + { + 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; + return acc; + } } } diff --git a/WinFormDiApp.BL/Helpers/Extensions.cs b/WinFormDiApp.BL/Helpers/Extensions.cs index eee26eb..cde2445 100644 --- a/WinFormDiApp.BL/Helpers/Extensions.cs +++ b/WinFormDiApp.BL/Helpers/Extensions.cs @@ -23,4 +23,12 @@ public static class Extensions } else return false; } + + public static string adjustRight(this string value) { + if (!string.IsNullOrEmpty(value) && value.Length < 20) + { + return " ".Substring(0, 20 - value.Length)+value; + } + else return value; + } } diff --git a/cacsvedan@mercedes-benz.com.jpeg b/cacsvedan@mercedes-benz.com.jpeg new file mode 100644 index 0000000..dc22990 Binary files /dev/null and b/cacsvedan@mercedes-benz.com.jpeg differ