Пагинация для декстопа.
This commit is contained in:
parent
24b5dad676
commit
4e78fd4c3e
@ -1,63 +1,89 @@
|
||||
namespace BlacksmithWorkshop
|
||||
{
|
||||
partial class FormMails
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
partial class FormMails
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
@ -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<FormMails> 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<FormMails> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user