Пагинация desktop (1 пункт)

This commit is contained in:
Павел Сорокин 2023-04-30 19:45:57 +04:00
parent 3300b0f5a1
commit fe0d9c7ecc
4 changed files with 89 additions and 15 deletions

View File

@ -29,25 +29,60 @@
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonForward = new System.Windows.Forms.Button();
this.buttonBack = new System.Windows.Forms.Button();
this.buttonOpen = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
this.dataGridView.Location = new System.Drawing.Point(0, 0);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(800, 450);
this.dataGridView.Size = new System.Drawing.Size(641, 453);
this.dataGridView.TabIndex = 0;
//
// buttonForward
//
this.buttonForward.Location = new System.Drawing.Point(737, 385);
this.buttonForward.Name = "buttonForward";
this.buttonForward.Size = new System.Drawing.Size(51, 29);
this.buttonForward.TabIndex = 1;
this.buttonForward.Text = ">>";
this.buttonForward.UseVisualStyleBackColor = true;
this.buttonForward.Click += new System.EventHandler(this.ButtonForward_Click);
//
// buttonBack
//
this.buttonBack.Location = new System.Drawing.Point(660, 385);
this.buttonBack.Name = "buttonBack";
this.buttonBack.Size = new System.Drawing.Size(51, 29);
this.buttonBack.TabIndex = 2;
this.buttonBack.Text = "<<";
this.buttonBack.UseVisualStyleBackColor = true;
this.buttonBack.Click += new System.EventHandler(this.ButtonBack_Click);
//
// buttonOpen
//
this.buttonOpen.Location = new System.Drawing.Point(660, 12);
this.buttonOpen.Name = "buttonOpen";
this.buttonOpen.Size = new System.Drawing.Size(128, 36);
this.buttonOpen.TabIndex = 3;
this.buttonOpen.Text = "Открыть";
this.buttonOpen.UseVisualStyleBackColor = true;
//
// FormMails
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.ClientSize = new System.Drawing.Size(800, 453);
this.Controls.Add(this.buttonOpen);
this.Controls.Add(this.buttonBack);
this.Controls.Add(this.buttonForward);
this.Controls.Add(this.dataGridView);
this.Name = "FormMails";
this.Text = "Письма";
@ -60,5 +95,8 @@
#endregion
private DataGridView dataGridView;
private Button buttonForward;
private Button buttonBack;
private Button buttonOpen;
}
}

View File

@ -15,6 +15,8 @@ namespace ShipyardView
public partial class FormMails : Form
{
private readonly ILogger _logger;
private int pageCount = 0;
private readonly int countPerPage = 5;
private readonly IMessageInfoLogic _logic;
public FormMails(ILogger<FormMails> logger, IMessageInfoLogic logic)
@ -22,18 +24,18 @@ namespace ShipyardView
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormMails_Load(object sender, EventArgs e)
private void LoadData(int page)
{
try
{
var list = _logic.ReadList(null);
var list = _logic.ReadList(new() { Page = page, PageCount = countPerPage });
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка писем");
@ -41,10 +43,31 @@ namespace ShipyardView
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки писем");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormMails_Load(object sender, EventArgs e)
{
LoadData(0);
}
private void ButtonBack_Click(object sender, EventArgs e)
{
pageCount = pageCount > 0 ? pageCount - 1 : 0;
LoadData(pageCount);
}
private void ButtonForward_Click(object sender, EventArgs e)
{
pageCount++;
LoadData(pageCount);
}
private void ButtonOpen_Click(object sender, EventArgs e)
{
}
}
}

View File

@ -11,5 +11,9 @@ namespace ShipyardContracts.SearchModels
public int? ClientId { get; set; }
public string? MessageId { get; set; }
public int? Page { get; set; }
public int? PageCount { get; set; }
}
}

View File

@ -28,13 +28,22 @@ namespace ShipyardDataBaseImplement.Implements
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{
if (!model.ClientId.HasValue)
return new();
using var context = new ShipyardDataBase();
return context.Messages
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
if (model.ClientId.HasValue && model.Page.HasValue && model.PageCount.HasValue)
{
return context.Messages
.Where(x => x.ClientId == model.ClientId)
.Skip(model.PageCount.Value * model.Page.Value).Take(model.PageCount.Value)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Page.HasValue && model.PageCount.HasValue)
{
return context.Messages
.Skip(model.PageCount.Value * model.Page.Value).Take(model.PageCount.Value)
.Select(x => x.GetViewModel).ToList();
}
return new();
}
public List<MessageInfoViewModel> GetFullList()