PIbd-23_Ivanov_V.N._Pizzeria/Pizzeria/PizzeriaView/FormMail.cs

116 lines
3.8 KiB
C#
Raw Permalink Normal View History

2024-04-03 09:19:16 +04:00
using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.Extensions.Logging;
using Pizzeria;
using PizzeriaBusinessLogic.BusinessLogics;
using PizzeriaContracts.BindingModels;
2024-04-02 16:35:18 +04:00
using PizzeriaContracts.BusinessLogicsContracts;
2024-04-03 09:19:16 +04:00
using PizzeriaContracts.SearchModels;
2024-04-02 16:35:18 +04:00
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 PizzeriaView
{
public partial class FormMail : Form
{
private readonly ILogger _logger;
private readonly IMessageInfoLogic _logic;
private int currentPage = 1;
private int pageLength = 2;
2024-04-02 16:35:18 +04:00
public FormMail(ILogger<FormMail> logger, IMessageInfoLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
2024-04-02 16:35:18 +04:00
private void LoadData()
{
try
{
var list = _logic.ReadList(new MessageInfoSearchModel()
{
PageLength = pageLength,
PageIndex = currentPage
2024-04-03 09:19:16 +04:00
});
numericUpDownPage.Value = pageLength;
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["MessageId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ReplyMessageId"].Visible = false;
dataGridView.Columns["Reply"].Visible = false;
dataGridView.Columns["IsReply"].Visible = false;
dataGridView.Columns["Body"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка почтовых собщений");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки почтовых сообщений");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
2024-04-02 16:35:18 +04:00
private void FormMail_Load(object sender, EventArgs e)
{
LoadData();
}
2024-04-03 09:19:16 +04:00
private void buttonOpen_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count <= 0)
return;
2024-04-03 09:19:16 +04:00
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;
2024-04-03 09:19:16 +04:00
if (!Convert.ToBoolean(dataGridView.SelectedRows[0].Cells["IsReaded"].Value))
{
_logic.Update(new MessageInfoBindingModel
{
MessageId = messageId,
IsReaded = true,
ReplyMessageId = dataGridView.SelectedRows[0].Cells["ReplyMessageId"].Value?.ToString()
});
}
2024-04-03 09:19:16 +04:00
form.ShowDialog();
LoadData();
}
}
2024-04-03 09:19:16 +04:00
private void buttonPreveous_Click(object sender, EventArgs e)
{
currentPage = Math.Max(1, currentPage - 1);
LoadData();
}
2024-04-03 09:19:16 +04:00
private void buttonNext_Click(object sender, EventArgs e)
{
currentPage++;
LoadData();
}
2024-04-03 09:19:16 +04:00
private void numericUpDownPage_ValueChanged(object sender, EventArgs e)
{
pageLength = Math.Max(1, (int)numericUpDownPage.Value);
LoadData();
}
}
2024-04-02 16:35:18 +04:00
}