diff --git a/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs
index 60955dd..005b042 100644
--- a/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs
+++ b/FurnitureAssembly/FurnitureAssembly/FormMail.Designer.cs
@@ -31,6 +31,7 @@
this.dataGridViewMail = new System.Windows.Forms.DataGridView();
this.buttonPrev = new System.Windows.Forms.Button();
this.buttonNext = new System.Windows.Forms.Button();
+ this.buttonOpen = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridViewMail)).BeginInit();
this.SuspendLayout();
//
@@ -63,11 +64,22 @@
this.buttonNext.UseVisualStyleBackColor = true;
this.buttonNext.Click += new System.EventHandler(this.buttonNext_Click);
//
+ // buttonOpen
+ //
+ this.buttonOpen.Location = new System.Drawing.Point(702, 455);
+ this.buttonOpen.Name = "buttonOpen";
+ this.buttonOpen.Size = new System.Drawing.Size(75, 23);
+ this.buttonOpen.TabIndex = 3;
+ this.buttonOpen.Text = "Открыть";
+ this.buttonOpen.UseVisualStyleBackColor = true;
+ this.buttonOpen.Click += new System.EventHandler(this.buttonOpen_Click);
+ //
// FormMail
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 483);
+ this.Controls.Add(this.buttonOpen);
this.Controls.Add(this.buttonNext);
this.Controls.Add(this.buttonPrev);
this.Controls.Add(this.dataGridViewMail);
@@ -84,5 +96,6 @@
private DataGridView dataGridViewMail;
private Button buttonPrev;
private Button buttonNext;
+ private Button buttonOpen;
}
}
\ No newline at end of file
diff --git a/FurnitureAssembly/FurnitureAssembly/FormMail.cs b/FurnitureAssembly/FurnitureAssembly/FormMail.cs
index 3876b7c..d4c2a37 100644
--- a/FurnitureAssembly/FurnitureAssembly/FormMail.cs
+++ b/FurnitureAssembly/FurnitureAssembly/FormMail.cs
@@ -79,5 +79,21 @@ namespace FurnitureAssembly
}
}
}
+
+ private void buttonOpen_Click(object sender, EventArgs e)
+ {
+ if (dataGridViewMail.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormOneMail));
+ if (service is FormOneMail form)
+ {
+ form.MessageId = (string)dataGridViewMail.SelectedRows[0].Cells["MessageId"].Value;
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
}
}
diff --git a/FurnitureAssembly/FurnitureAssembly/FormOneMail.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormOneMail.Designer.cs
new file mode 100644
index 0000000..861a8cc
--- /dev/null
+++ b/FurnitureAssembly/FurnitureAssembly/FormOneMail.Designer.cs
@@ -0,0 +1,190 @@
+namespace FurnitureAssembly
+{
+ partial class FormOneMail
+ {
+ ///
+ /// 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);
+ }
+
+ #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()
+ {
+ this.textBoxSenderName = new System.Windows.Forms.TextBox();
+ this.dateTime = new System.Windows.Forms.DateTimePicker();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.richTextBoxBody = new System.Windows.Forms.RichTextBox();
+ this.labelSenderName = new System.Windows.Forms.Label();
+ this.labelDate = new System.Windows.Forms.Label();
+ this.labelName = new System.Windows.Forms.Label();
+ this.richTextBoxReply = new System.Windows.Forms.RichTextBox();
+ this.labelBody = new System.Windows.Forms.Label();
+ this.labelReply = new System.Windows.Forms.Label();
+ this.buttonSend = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // textBoxSenderName
+ //
+ this.textBoxSenderName.Enabled = false;
+ this.textBoxSenderName.Location = new System.Drawing.Point(39, 46);
+ this.textBoxSenderName.Name = "textBoxSenderName";
+ this.textBoxSenderName.Size = new System.Drawing.Size(187, 23);
+ this.textBoxSenderName.TabIndex = 1;
+ //
+ // dateTime
+ //
+ this.dateTime.Enabled = false;
+ this.dateTime.Location = new System.Drawing.Point(254, 46);
+ this.dateTime.Name = "dateTime";
+ this.dateTime.Size = new System.Drawing.Size(144, 23);
+ this.dateTime.TabIndex = 2;
+ //
+ // textBoxName
+ //
+ this.textBoxName.Enabled = false;
+ this.textBoxName.Location = new System.Drawing.Point(39, 100);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(692, 23);
+ this.textBoxName.TabIndex = 3;
+ //
+ // richTextBoxBody
+ //
+ this.richTextBoxBody.Enabled = false;
+ this.richTextBoxBody.Location = new System.Drawing.Point(39, 150);
+ this.richTextBoxBody.Name = "richTextBoxBody";
+ this.richTextBoxBody.Size = new System.Drawing.Size(692, 111);
+ this.richTextBoxBody.TabIndex = 4;
+ this.richTextBoxBody.Text = "";
+ //
+ // labelSenderName
+ //
+ this.labelSenderName.AutoSize = true;
+ this.labelSenderName.Location = new System.Drawing.Point(39, 22);
+ this.labelSenderName.Name = "labelSenderName";
+ this.labelSenderName.Size = new System.Drawing.Size(78, 15);
+ this.labelSenderName.TabIndex = 5;
+ this.labelSenderName.Text = "Отправитель";
+ //
+ // labelDate
+ //
+ this.labelDate.AutoSize = true;
+ this.labelDate.Location = new System.Drawing.Point(254, 22);
+ this.labelDate.Name = "labelDate";
+ this.labelDate.Size = new System.Drawing.Size(76, 15);
+ this.labelDate.TabIndex = 6;
+ this.labelDate.Text = "Дата письма";
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(39, 82);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(65, 15);
+ this.labelName.TabIndex = 7;
+ this.labelName.Text = "Заголовок";
+ //
+ // richTextBoxReply
+ //
+ this.richTextBoxReply.Location = new System.Drawing.Point(39, 290);
+ this.richTextBoxReply.Name = "richTextBoxReply";
+ this.richTextBoxReply.Size = new System.Drawing.Size(692, 111);
+ this.richTextBoxReply.TabIndex = 8;
+ this.richTextBoxReply.Text = "";
+ //
+ // labelBody
+ //
+ this.labelBody.AutoSize = true;
+ this.labelBody.Location = new System.Drawing.Point(39, 132);
+ this.labelBody.Name = "labelBody";
+ this.labelBody.Size = new System.Drawing.Size(80, 15);
+ this.labelBody.TabIndex = 9;
+ this.labelBody.Text = "Текст письма";
+ //
+ // labelReply
+ //
+ this.labelReply.AutoSize = true;
+ this.labelReply.Location = new System.Drawing.Point(39, 272);
+ this.labelReply.Name = "labelReply";
+ this.labelReply.Size = new System.Drawing.Size(38, 15);
+ this.labelReply.TabIndex = 10;
+ this.labelReply.Text = "Ответ";
+ //
+ // buttonSend
+ //
+ this.buttonSend.Location = new System.Drawing.Point(656, 415);
+ this.buttonSend.Name = "buttonSend";
+ this.buttonSend.Size = new System.Drawing.Size(75, 23);
+ this.buttonSend.TabIndex = 11;
+ this.buttonSend.Text = "Отправить";
+ this.buttonSend.UseVisualStyleBackColor = true;
+ this.buttonSend.Click += new System.EventHandler(this.buttonSend_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(545, 415);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 12;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // FormOneMail
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(755, 450);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSend);
+ this.Controls.Add(this.labelReply);
+ this.Controls.Add(this.labelBody);
+ this.Controls.Add(this.richTextBoxReply);
+ this.Controls.Add(this.labelName);
+ this.Controls.Add(this.labelDate);
+ this.Controls.Add(this.labelSenderName);
+ this.Controls.Add(this.richTextBoxBody);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.dateTime);
+ this.Controls.Add(this.textBoxSenderName);
+ this.Name = "FormOneMail";
+ this.Text = "Ответ на письмо";
+ this.Load += new System.EventHandler(this.FormOneMail_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+ private TextBox textBoxSenderName;
+ private DateTimePicker dateTime;
+ private TextBox textBoxName;
+ private RichTextBox richTextBoxBody;
+ private Label labelSenderName;
+ private Label labelDate;
+ private Label labelName;
+ private RichTextBox richTextBoxReply;
+ private Label labelBody;
+ private Label labelReply;
+ private Button buttonSend;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/FurnitureAssembly/FurnitureAssembly/FormOneMail.cs b/FurnitureAssembly/FurnitureAssembly/FormOneMail.cs
new file mode 100644
index 0000000..18a6cb6
--- /dev/null
+++ b/FurnitureAssembly/FurnitureAssembly/FormOneMail.cs
@@ -0,0 +1,100 @@
+using FurnitureAssemblyBusinessLogic.MailWorker;
+using FurnitureAssemblyContracts.BusinessLogicsContarcts;
+using FurnitureAssemblyContracts.SearchModels;
+using FurnitureAssemblyContracts.ViewModels;
+using FurnitureAssemblyDataModels.Models;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace FurnitureAssembly
+{
+ public partial class FormOneMail : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IMessageInfoLogic _logic;
+ private readonly AbstractMailWorker _mailWorker;
+ private MessageInfoViewModel messageInfo;
+ public string MessageId { get; set; } = string.Empty;
+ public FormOneMail(ILogger logger, IMessageInfoLogic messageInfoLogic, AbstractMailWorker mailWorker)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = messageInfoLogic;
+ _mailWorker = mailWorker;
+ }
+
+ private void FormOneMail_Load(object sender, EventArgs e)
+ {
+ if (!string.IsNullOrEmpty(MessageId))
+ {
+ _logger.LogInformation("Загрузка письма");
+ try
+ {
+ messageInfo = _logic.ReadElement(new()
+ {
+ MessageId = MessageId
+ });
+ if (messageInfo == null)
+ {
+ throw new ArgumentNullException($"Письма с id {MessageId} не существует");
+ }
+ textBoxSenderName.Text = messageInfo.SenderName;
+ textBoxName.Text = messageInfo.Subject;
+ richTextBoxBody.Text = messageInfo.Body;
+ richTextBoxReply.Text = messageInfo.Reply;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки письма");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ _logic.Update(new()
+ {
+ MessageId = MessageId,
+ Reply = messageInfo?.Reply,
+ IsRead = true,
+ });
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+
+ private void buttonSend_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(richTextBoxReply.Text))
+ {
+ MessageBox.Show("Напишите ответ для отправки", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _mailWorker.MailSendAsync(new()
+ {
+ MailAddress = messageInfo.SenderName,
+ Subject = messageInfo.Subject,
+ Text = richTextBoxReply.Text
+ });
+ _logic.Update(new()
+ {
+ MessageId = MessageId,
+ Reply = richTextBoxReply.Text,
+ IsRead = true
+ });
+ MessageBox.Show("Успешно отправлен ответ на письмо", "Отправка ответа на письмо", MessageBoxButtons.OK);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ }
+}
diff --git a/FurnitureAssembly/FurnitureAssembly/FormOneMail.resx b/FurnitureAssembly/FurnitureAssembly/FormOneMail.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/FurnitureAssembly/FurnitureAssembly/FormOneMail.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs
index c505c06..3ee771d 100644
--- a/FurnitureAssembly/FurnitureAssembly/Program.cs
+++ b/FurnitureAssembly/FurnitureAssembly/Program.cs
@@ -112,6 +112,7 @@ namespace FurnitureAssembly
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
}
private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck();