PIbd22_Kuznetsov_A.V._Sewin.../SewingDresses/SewingDressesView/MainForm.cs

175 lines
4.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using System.Windows.Forms;
using SewingDressesBusinessLogic.BusinessLogic;
using SewingDressesDatabaseImplement.Implements;
using SewingDressesContracts.DI;
namespace SewingDressesView
{
public partial class MainForm : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess;
private readonly IBackUpLogic _backUpLogic;
public MainForm(ILogger<MainForm> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
_workProcess = workProcess;
_backUpLogic = backUpLogic;
}
private void LoadData()
{
try
{
dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
_logger.LogInformation("Load orders");
}
catch (Exception ex)
{
_logger.LogError(ex, "Load orders error");
}
}
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{
var form = DependencyManager.Instance.Resolve<ComponentsForm>();
form.ShowDialog();
}
private void DressesToolStripMenuItem_Click(object sender, EventArgs e)
{
var form = DependencyManager.Instance.Resolve<DressesForm>();
form.ShowDialog();
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var form = DependencyManager.Instance.Resolve<OrderForm>();
form.ShowDialog();
LoadData();
}
private void buttonOrderGive_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Status change on 'Given'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Order №{id} given", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Change status on 'Give' error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonOrderUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
private void MainForm_Load(object sender, EventArgs e)
{
LoadData();
}
private void ComponentProductsToolStripMenuItemReport_Click(object sender, EventArgs e)
{
var form = DependencyManager.Instance.Resolve<ReportDressComponentsForm>();
form.ShowDialog();
}
private void OrdersToolStripMenuItemReport_Click(object sender, EventArgs e)
{
var form = DependencyManager.Instance.Resolve<ReportOrdersForm>();
form.ShowDialog();
}
private void DressesToolStripMenuItemReport_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveComponentsToWordFile(new ReportBindingModel
{
FileName = dialog.FileName
});
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void clientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var form = DependencyManager.Instance.Resolve<ClientsForm>();
form.ShowDialog();
}
private void ImplementToolStripMenuItem_Click(object sender, EventArgs e)
{
var form = DependencyManager.Instance.Resolve<ImplementsForm>();
form.ShowDialog();
}
private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork(DependencyManager.Instance.Resolve<IImplementLogic>(), _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void emailsToolStripMenuItem_Click(object sender, EventArgs e)
{
var form = DependencyManager.Instance.Resolve<MailForm>();
form.ShowDialog();
}
private void СоздатьБекапToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (_backUpLogic != null)
{
var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
_backUpLogic.CreateBackUp(new BackUpSaveBindingModel
{
FolderName = fbd.SelectedPath
});
MessageBox.Show("Бекап создан", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}