diff --git a/Shipyard/Shipyard/FormMails.Designer.cs b/Shipyard/Shipyard/FormMails.Designer.cs index 536e064..d84a447 100644 --- a/Shipyard/Shipyard/FormMails.Designer.cs +++ b/Shipyard/Shipyard/FormMails.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/Shipyard/Shipyard/FormMails.cs b/Shipyard/Shipyard/FormMails.cs index 2010045..e9a98b3 100644 --- a/Shipyard/Shipyard/FormMails.cs +++ b/Shipyard/Shipyard/FormMails.cs @@ -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 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) + { + + } } } diff --git a/Shipyard/ShipyardContracts/SearchModels/MessageInfoSearchModel.cs b/Shipyard/ShipyardContracts/SearchModels/MessageInfoSearchModel.cs index 12a7f8b..2d50385 100644 --- a/Shipyard/ShipyardContracts/SearchModels/MessageInfoSearchModel.cs +++ b/Shipyard/ShipyardContracts/SearchModels/MessageInfoSearchModel.cs @@ -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; } } } diff --git a/Shipyard/ShipyardDataBaseImplement/Implements/MessageInfoStorage.cs b/Shipyard/ShipyardDataBaseImplement/Implements/MessageInfoStorage.cs index f14a1e8..378a692 100644 --- a/Shipyard/ShipyardDataBaseImplement/Implements/MessageInfoStorage.cs +++ b/Shipyard/ShipyardDataBaseImplement/Implements/MessageInfoStorage.cs @@ -28,13 +28,22 @@ namespace ShipyardDataBaseImplement.Implements public List 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 GetFullList()