112 lines
3.0 KiB
C#
112 lines
3.0 KiB
C#
using BookShopContracts.BusinessLogicsContracts;
|
||
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 BookShopView
|
||
{
|
||
public partial class FormMain : Form
|
||
{
|
||
private readonly ILogger _logger;
|
||
private readonly IOrderLogic _orderLogic;
|
||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
||
{
|
||
InitializeComponent();
|
||
_logger = logger;
|
||
_orderLogic = orderLogic;
|
||
}
|
||
private void FormMain_Load(object sender, EventArgs e)
|
||
{
|
||
LoadData();
|
||
}
|
||
private void LoadData()
|
||
{
|
||
_logger.LogInformation("Загрузка заказов");
|
||
try
|
||
{
|
||
var list = _orderLogic.ReadList(null);
|
||
if (list != null)
|
||
{
|
||
dataGridView.DataSource = list;
|
||
dataGridView.Columns["BookId"].Visible = false;
|
||
dataGridView.Columns["BookName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
dataGridView.Columns["ClientId"].Visible = false;
|
||
dataGridView.Columns["ClientSurname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
dataGridView.Columns["Count"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
dataGridView.Columns["Sum"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
dataGridView.Columns["DateCreate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
}
|
||
_logger.LogInformation("Загрузка заказов");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка загрузки заказов");
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
|
||
private void AuthorsToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormAuthors));
|
||
if (service is FormAuthors form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
private void GenresToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormGenres));
|
||
|
||
if (service is FormGenres form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
private void BooksToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormBooks));
|
||
|
||
if (service is FormBooks form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
|
||
|
||
if (service is FormClients form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void buttonCreateOrder_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormСreateOrder));
|
||
if (service is FormСreateOrder form)
|
||
{
|
||
form.ShowDialog();
|
||
LoadData();
|
||
}
|
||
}
|
||
|
||
private void testsToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormTests));
|
||
|
||
if (service is FormTests form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
}
|
||
}
|