LabSubd/Subd/Forms/FormMain.cs

164 lines
4.7 KiB
C#
Raw 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 Contracts.BusinessLogic;
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 Forms
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IVoyageLogic _voyageLogic;
public FormMain(ILogger<FormMain> logger, IVoyageLogic voyageLogic)
{
InitializeComponent();
_logger = logger;
_voyageLogic = voyageLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
_logger.LogInformation("Загрузка ");
try
{
var list = _voyageLogic.ReadList(null);
if (list != null)
{
DataGridView.DataSource = list;
DataGridView.Columns["HumanId"].Visible = false;
DataGridView.Columns["CarId"].Visible = false;
DataGridView.Columns["CompanyId"].Visible = false;
DataGridView.Columns["RouteId"].Visible = false;
DataGridView.Columns["RouteName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridView.Columns["Id"].Visible = false;
DataGridView.Columns["Km"].Visible = false;
}
_logger.LogInformation("Загрузка ");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки машин");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ВодителиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormHumans));
if (service is FormHumans form)
{
form.ShowDialog();
}
}
private void МашиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCars));
if (service is FormCars form)
{
form.ShowDialog();
}
}
private void CreateOrderButton_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormVoyage));
if (service is FormVoyage form)
{
form.ShowDialog();
LoadData();
}
}
private void UpdateListButton_Click(object sender, EventArgs e)
{
LoadData();
}
private void компанииToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCompanies));
if (service is FormCompanies form)
{
form.ShowDialog();
}
}
private void маршрутыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormRoutes));
if (service is FormRoutes form)
{
form.ShowDialog();
}
}
private void местаToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPlaces));
if (service is FormPlaces form)
{
form.ShowDialog();
}
}
private void водителиToolStripMenuItem_Click_1(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportHumans));
if (service is FormReportHumans form)
{
form.ShowDialog();
}
}
private void компанииToolStripMenuItem1_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportCompanies));
if (service is FormReportCompanies form)
{
form.ShowDialog();
}
}
private void статусToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStatuses));
if (service is FormStatuses form)
{
form.ShowDialog();
}
}
}
}