Форма для ответа и чтения
This commit is contained in:
parent
94ef4d11d0
commit
77e21b6bf9
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
190
FurnitureAssembly/FurnitureAssembly/FormOneMail.Designer.cs
generated
Normal file
190
FurnitureAssembly/FurnitureAssembly/FormOneMail.Designer.cs
generated
Normal file
@ -0,0 +1,190 @@
|
||||
namespace FurnitureAssembly
|
||||
{
|
||||
partial class FormOneMail
|
||||
{
|
||||
/// <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);
|
||||
}
|
||||
|
||||
#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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
100
FurnitureAssembly/FurnitureAssembly/FormOneMail.cs
Normal file
100
FurnitureAssembly/FurnitureAssembly/FormOneMail.cs
Normal file
@ -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<FormOneMail> 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();
|
||||
}
|
||||
}
|
||||
}
|
60
FurnitureAssembly/FurnitureAssembly/FormOneMail.resx
Normal file
60
FurnitureAssembly/FurnitureAssembly/FormOneMail.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -112,6 +112,7 @@ namespace FurnitureAssembly
|
||||
services.AddTransient<FormImplementers>();
|
||||
services.AddTransient<FormImplementer>();
|
||||
services.AddTransient<FormMail>();
|
||||
services.AddTransient<FormOneMail>();
|
||||
}
|
||||
|
||||
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
|
||||
|
Loading…
Reference in New Issue
Block a user