diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.Designer.cs
index 1b0abda..222453c 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.Designer.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.Designer.cs
@@ -1,63 +1,89 @@
namespace BlacksmithWorkshop
{
- partial class FormMails
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
+ partial class FormMails
+ {
+ ///
+ /// 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);
- }
+ ///
+ /// 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
+ #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()
- {
- dataGridView = new DataGridView();
- ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
- SuspendLayout();
- //
- // dataGridView
- //
- dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- dataGridView.Dock = DockStyle.Fill;
- dataGridView.Location = new Point(0, 0);
- dataGridView.Name = "dataGridView";
- dataGridView.RowHeadersWidth = 51;
- dataGridView.RowTemplate.Height = 29;
- dataGridView.Size = new Size(800, 450);
- dataGridView.TabIndex = 0;
- //
- // FormMails
- //
- AutoScaleDimensions = new SizeF(8F, 20F);
- AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(800, 450);
- Controls.Add(dataGridView);
- Name = "FormMails";
- Text = "Письма";
- Load += FormMails_Load;
- ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
- ResumeLayout(false);
- }
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ dataGridView = new DataGridView();
+ buttonForward = new Button();
+ buttonBack = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Dock = DockStyle.Top;
+ dataGridView.Location = new Point(0, 0);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(800, 393);
+ dataGridView.TabIndex = 0;
+ //
+ // buttonForward
+ //
+ buttonForward.Location = new Point(156, 409);
+ buttonForward.Name = "buttonForward";
+ buttonForward.Size = new Size(175, 29);
+ buttonForward.TabIndex = 1;
+ buttonForward.Text = "Вперёд";
+ buttonForward.UseVisualStyleBackColor = true;
+ buttonForward.Click += ButtonForward_Click;
+ //
+ // buttonBack
+ //
+ buttonBack.Location = new Point(466, 409);
+ buttonBack.Name = "buttonBack";
+ buttonBack.Size = new Size(173, 29);
+ buttonBack.TabIndex = 2;
+ buttonBack.Text = "Назад";
+ buttonBack.UseVisualStyleBackColor = true;
+ buttonBack.Click += ButtonBack_Click;
+ //
+ // FormMails
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(buttonBack);
+ Controls.Add(buttonForward);
+ Controls.Add(dataGridView);
+ Name = "FormMails";
+ Text = "Письма";
+ Load += FormMails_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
- #endregion
+ #endregion
- private DataGridView dataGridView;
- }
+ private DataGridView dataGridView;
+ private Button buttonForward;
+ private Button buttonBack;
+ }
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs
index 56ae275..5032b9f 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMails.cs
@@ -13,48 +13,84 @@ using System.Windows.Forms;
namespace BlacksmithWorkshop
{
- public partial class FormMails : Form
- {
- private readonly ILogger _logger;
+ public partial class FormMails : Form
+ {
+ private readonly ILogger _logger;
- private readonly IMessageInfoLogic _messageLogic;
+ private readonly IMessageInfoLogic _messageLogic;
- public FormMails(ILogger logger, IMessageInfoLogic messageLogic)
- {
- InitializeComponent();
+ private int numberPaginationPage;
- _logger = logger;
- _messageLogic = messageLogic;
- }
+ private int paginationSize;
- private void FormMails_Load(object sender, EventArgs e)
- {
- LoadData();
- }
+ public FormMails(ILogger logger, IMessageInfoLogic messageLogic)
+ {
+ InitializeComponent();
- private void LoadData()
- {
- _logger.LogInformation("Загрузка писем");
+ _logger = logger;
+ _messageLogic = messageLogic;
- try
- {
- var list = _messageLogic.ReadList(null);
+ paginationSize = 10;
+ }
- if (list != null)
- {
- dataGridView.DataSource = list;
- dataGridView.Columns["MessageId"].Visible = false;
- dataGridView.Columns["ClientId"].Visible = false;
- dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
+ private void FormMails_Load(object sender, EventArgs e)
+ {
+ numberPaginationPage = 1;
- _logger.LogInformation("Успешная загрузка писем");
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка загрузки писем");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка писем");
+
+ try
+ {
+ var list = _messageLogic.ReadList(null);
+
+ //проверка на то, чтобы не стали выводить несуществующие элементы списка
+ if ((numberPaginationPage - 1) * 10 + paginationSize > list.Count)
+ {
+ paginationSize = list.Count - (numberPaginationPage - 1) * 10;
+ }
+
+ //получение писем, согласно номеру страницы пагинации
+ var paginationList = list.GetRange((numberPaginationPage - 1) * 10, paginationSize);
+
+ if (list != null)
+ {
+ dataGridView.DataSource = paginationList;
+ dataGridView.Columns["MessageId"].Visible = false;
+ dataGridView.Columns["ClientId"].Visible = false;
+ dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+
+ _logger.LogInformation("Успешная загрузка писем");
+
+ paginationSize = 10;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки писем");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonForward_Click(object sender, EventArgs e)
+ {
+ numberPaginationPage += 1;
+
+ LoadData();
+ }
+
+ private void ButtonBack_Click(object sender, EventArgs e)
+ {
+ if(numberPaginationPage > 1)
+ {
+ numberPaginationPage -= 1;
+ }
+
+ LoadData();
+ }
+ }
}