diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index de32208..af7c72c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -100,7 +100,8 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + } private static void MailCheck(object obj) => ServiceProvider? .GetService()?.MailCheck(); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.Designer.cs index 1134e76..a19be20 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.Designer.cs @@ -34,6 +34,7 @@ numericUpDownPage = new NumericUpDown(); buttonPreveous = new Button(); buttonNext = new Button(); + pageTextBox = new TextBox(); panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownPage).BeginInit(); @@ -64,9 +65,9 @@ // // buttonOpen // - buttonOpen.Location = new Point(722, 187); + buttonOpen.Location = new Point(705, 235); buttonOpen.Name = "buttonOpen"; - buttonOpen.Size = new Size(74, 23); + buttonOpen.Size = new Size(106, 23); buttonOpen.TabIndex = 1; buttonOpen.Text = "Прочитать"; buttonOpen.UseVisualStyleBackColor = true; @@ -74,19 +75,19 @@ // // numericUpDownPage // - numericUpDownPage.Location = new Point(722, 215); + numericUpDownPage.Location = new Point(705, 263); numericUpDownPage.Margin = new Padding(3, 2, 3, 2); numericUpDownPage.Name = "numericUpDownPage"; - numericUpDownPage.Size = new Size(74, 23); + numericUpDownPage.Size = new Size(106, 23); numericUpDownPage.TabIndex = 4; numericUpDownPage.ValueChanged += numericUpDownPage_ValueChanged; // // buttonPreveous // - buttonPreveous.Location = new Point(722, 242); + buttonPreveous.Location = new Point(705, 289); buttonPreveous.Margin = new Padding(3, 2, 3, 2); buttonPreveous.Name = "buttonPreveous"; - buttonPreveous.Size = new Size(34, 22); + buttonPreveous.Size = new Size(35, 25); buttonPreveous.TabIndex = 5; buttonPreveous.Text = "<-"; buttonPreveous.UseVisualStyleBackColor = true; @@ -94,20 +95,31 @@ // // buttonNext // - buttonNext.Location = new Point(763, 242); + buttonNext.Location = new Point(776, 289); buttonNext.Margin = new Padding(3, 2, 3, 2); buttonNext.Name = "buttonNext"; - buttonNext.Size = new Size(34, 22); + buttonNext.Size = new Size(35, 25); buttonNext.TabIndex = 6; buttonNext.Text = "->"; buttonNext.UseVisualStyleBackColor = true; buttonNext.Click += buttonNext_Click; // + // pageTextBox + // + pageTextBox.Enabled = false; + pageTextBox.Location = new Point(746, 289); + pageTextBox.Name = "pageTextBox"; + pageTextBox.ReadOnly = true; + pageTextBox.Size = new Size(24, 23); + pageTextBox.TabIndex = 7; + pageTextBox.Text = "0"; + // // ViewMailForm // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(809, 321); + ClientSize = new Size(817, 321); + Controls.Add(pageTextBox); Controls.Add(buttonNext); Controls.Add(buttonPreveous); Controls.Add(numericUpDownPage); @@ -121,6 +133,7 @@ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownPage).EndInit(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -131,5 +144,6 @@ private NumericUpDown numericUpDownPage; private Button buttonPreveous; private Button buttonNext; + private TextBox pageTextBox; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.cs index 17727d7..f39a658 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ViewMailForm.cs @@ -14,23 +14,24 @@ using System.Windows.Forms; namespace BlacksmithWorkshop { - public partial class ViewMailForm : Form - { - private readonly ILogger _logger; - private readonly IMessageInfoLogic _logic; + public partial class ViewMailForm : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; private int currentPage = 1; - private int pageLength = 2; + private int pageLength = 3; public ViewMailForm(ILogger logger, IMessageInfoLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } - private void ViewMailForm_Load(object sender, EventArgs e) - { + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void ViewMailForm_Load(object sender, EventArgs e) + { LoadData(); numericUpDownPage.Value = pageLength; - } + pageTextBox.Text = currentPage.ToString(); + } private void LoadData() { try @@ -63,14 +64,12 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count <= 0) return; - var service = Program.ServiceProvider?.GetService(typeof(FormLetter)); if (service is FormLetter form) { string? messageId = dataGridView.SelectedRows[0].Cells["MessageId"].Value.ToString(); if (messageId == null) return; form.messageId = messageId; - if (!Convert.ToBoolean(dataGridView.SelectedRows[0].Cells["IsReaded"].Value)) { _logic.Update(new MessageInfoBindingModel @@ -80,24 +79,22 @@ namespace BlacksmithWorkshop ReplyMessageId = dataGridView.SelectedRows[0].Cells["ReplyMessageId"].Value?.ToString() }); } - form.ShowDialog(); LoadData(); } } - private void buttonPreveous_Click(object sender, EventArgs e) { currentPage = Math.Max(1, currentPage - 1); + pageTextBox.Text = currentPage.ToString(); LoadData(); } - private void buttonNext_Click(object sender, EventArgs e) { currentPage++; + pageTextBox.Text = currentPage.ToString(); LoadData(); } - private void numericUpDownPage_ValueChanged(object sender, EventArgs e) { pageLength = Math.Max(1, (int)numericUpDownPage.Value); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/MailKitWorker.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/MailKitWorker.cs index 7921e70..ed4c7a8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/MailKitWorker.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/MailWorker/MailKitWorker.cs @@ -25,12 +25,10 @@ namespace BlacksmithWorkshopBusinessLogic.MailWorker { ConfigurateSmtpClient(objSmtpClient); CreateMessage(objMailMessage, info); - if (info is MailReplySendInfoBindingModel replyInfo) { objMailMessage.Headers.Add("In-Reply-To", replyInfo.ParentMessageId); objMailMessage.Headers.Add("References", replyInfo.ParentMessageId); - string messageGuid = Guid.NewGuid().ToString(); objMailMessage.Headers.Add("Message-Id", messageGuid); resount = messageGuid; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/MessageInfoStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/MessageInfoStorage.cs index a452719..f1cd533 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/MessageInfoStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/MessageInfoStorage.cs @@ -24,32 +24,36 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } public List GetFilteredList(MessageInfoSearchModel model) { - if (!model.ClientId.HasValue && !model.PageLength.HasValue && !model.PageIndex.HasValue) + if (model == null || !model.ClientId.HasValue && !model.PageLength.HasValue && !model.PageIndex.HasValue) { return new(); } using var context = new BlacksmithWorkshopDataBase(); - var request = context.Messages - .Where(x => !x.IsReply); - if (model.ClientId.HasValue) - request = request - .Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId); if (model.PageLength.HasValue) { int skipRows = model.PageIndex.HasValue ? (model.PageIndex.Value - 1) * model.PageLength.Value : 0; - request = request - .Skip(skipRows) - .Take(model.PageLength.Value); + return context.Messages + .Where(x => !x.IsReply) + .Where(x => !model.ClientId.HasValue || x.ClientId.HasValue && x.ClientId == model.ClientId) + .OrderBy(x => x.DateDelivery) + .Skip(skipRows) + .Take(model.PageLength.Value) + .Select(x => x.GetViewModel) + .ToList(); } - return request - .Select(x => x.GetViewModel) - .ToList(); + return context.Messages + .Where(x => !x.IsReply) + .Where(x => !model.ClientId.HasValue || x.ClientId.HasValue && x.ClientId == model.ClientId) + .OrderBy(x => x.DateDelivery) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { using var context = new BlacksmithWorkshopDataBase(); return context.Messages - .Select(x => x.GetViewModel) + .OrderBy(x => x.DateDelivery) + .Select(x => x.GetViewModel) .ToList(); } public MessageInfoViewModel? Insert(MessageInfoBindingModel model)