diff --git a/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs index bd0089c..60955dd 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs @@ -29,6 +29,8 @@ private void InitializeComponent() { this.dataGridViewMail = new System.Windows.Forms.DataGridView(); + this.buttonPrev = new System.Windows.Forms.Button(); + this.buttonNext = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewMail)).BeginInit(); this.SuspendLayout(); // @@ -41,11 +43,33 @@ this.dataGridViewMail.Size = new System.Drawing.Size(801, 449); this.dataGridViewMail.TabIndex = 0; // + // buttonPrev + // + this.buttonPrev.Location = new System.Drawing.Point(266, 455); + this.buttonPrev.Name = "buttonPrev"; + this.buttonPrev.Size = new System.Drawing.Size(90, 23); + this.buttonPrev.TabIndex = 1; + this.buttonPrev.Text = "Предыдущая"; + this.buttonPrev.UseVisualStyleBackColor = true; + this.buttonPrev.Click += new System.EventHandler(this.buttonPrev_Click); + // + // buttonNext + // + this.buttonNext.Location = new System.Drawing.Point(453, 455); + this.buttonNext.Name = "buttonNext"; + this.buttonNext.Size = new System.Drawing.Size(90, 23); + this.buttonNext.TabIndex = 2; + this.buttonNext.Text = "Следующая"; + this.buttonNext.UseVisualStyleBackColor = true; + this.buttonNext.Click += new System.EventHandler(this.buttonNext_Click); + // // FormMail // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(800, 483); + this.Controls.Add(this.buttonNext); + this.Controls.Add(this.buttonPrev); this.Controls.Add(this.dataGridViewMail); this.Name = "FormMail"; this.Text = "Письма"; @@ -58,5 +82,7 @@ #endregion private DataGridView dataGridViewMail; + private Button buttonPrev; + private Button buttonNext; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMail.cs b/FurnitureAssembly/FurnitureAssembly/FormMail.cs index fd2afdb..3876b7c 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMail.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMail.cs @@ -9,6 +9,9 @@ namespace FurnitureAssembly { private readonly ILogger _logger; private readonly IMessageInfoLogic _logic; + private readonly int pageSize = 5; + private int _page = 1; + private int _totalPages = 1; public FormMail(ILogger logger, IMessageInfoLogic logic) { InitializeComponent(); @@ -17,12 +20,23 @@ namespace FurnitureAssembly } private void FormMail_Load(object sender, EventArgs e) + { + LoadData(); + buttonPrev.Enabled = false; + } + + private void LoadData() { try { var list = _logic.ReadList(null); + if (list != null) { + var totalCount = list!.Capacity; + _totalPages = (int)Math.Ceiling((decimal)totalCount / pageSize); + list = list!.Skip((_page - 1) * pageSize).Take(pageSize).ToList(); + dataGridViewMail.DataSource = list; dataGridViewMail.Columns["ClientId"].Visible = false; dataGridViewMail.Columns["MessageId"].Visible = false; @@ -37,5 +51,33 @@ namespace FurnitureAssembly MessageBoxIcon.Error); } } + + private void buttonPrev_Click(object sender, EventArgs e) + { + if (_page > 1) + { + _page -= 1; + buttonNext.Enabled = true; + LoadData(); + if (_page == 1) + { + buttonPrev.Enabled = false; + } + } + } + + private void buttonNext_Click(object sender, EventArgs e) + { + if (_page < _totalPages) + { + _page += 1; + buttonPrev.Enabled = true; + LoadData(); + if (_page == _totalPages) + { + buttonNext.Enabled = false; + } + } + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyClientApp/Controllers/HomeController.cs b/FurnitureAssembly/FurnitureAssemblyClientApp/Controllers/HomeController.cs index 006e742..e54c3bd 100644 --- a/FurnitureAssembly/FurnitureAssemblyClientApp/Controllers/HomeController.cs +++ b/FurnitureAssembly/FurnitureAssemblyClientApp/Controllers/HomeController.cs @@ -2,6 +2,7 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; using System.Diagnostics; @@ -148,13 +149,21 @@ namespace FurnitureAssemblyClientApp.Controllers } [HttpGet] - public IActionResult Mails() + public IActionResult Mails(int page = 1) { if (APIClient.Client == null) { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/client/getmessages?clientId={ APIClient.Client.Id}")); + + int pageSize = 2; + var data = APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}"); + int totalItems = data.Count; + int totalPages = (int)Math.Ceiling((decimal)totalItems / pageSize); + var model = data.Skip((page - 1) * pageSize).Take(pageSize).ToList(); + ViewBag.TotalPages = totalPages; + ViewBag.CurrentPage = page; + return View(model); } } diff --git a/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml b/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml index 413db5e..38507cd 100644 --- a/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyClientApp/Views/Home/Mails.cshtml @@ -10,34 +10,57 @@ ViewData["Title"] = "Mails"; @{ if (Model == null) { -

Авторизируйтесь

+

Авторизируйтесь

return; } - - - - - - - - - - @foreach (var item in Model) + +
Дата письмаЗаголовокТекст
+ + + + + + + + + @foreach (var item in Model) { - - + - - - + + + + } - -
Дата письмаЗаголовокТекст
- @Html.DisplayFor(modelItem => +
+ @Html.DisplayFor(modelItem => item.DateDelivery) - - @Html.DisplayFor(modelItem => item.Subject) - - @Html.DisplayFor(modelItem =>item.Body) -
+ @Html.DisplayFor(modelItem => item.Subject) + + @Html.DisplayFor(modelItem =>item.Body) +
+ + + @if (ViewBag.TotalPages > 1) + { + + } } \ No newline at end of file