Upload files to 'ShipyardView'
This commit is contained in:
parent
e485a46c9f
commit
a0305b1165
@ -27,15 +27,7 @@ namespace ShipyardView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
DataGridView.DataSource = list;
|
||||
DataGridView.Columns["Id"].Visible = false;
|
||||
DataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
DataGridView.Columns["Email"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
DataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
DataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка клиентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
50
ShipyardView/DataGridViewExtension.cs
Normal file
50
ShipyardView/DataGridViewExtension.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ShipyardContracts.Attributes;
|
||||
|
||||
namespace ShipyardView
|
||||
{
|
||||
public static class DataGridViewExtension
|
||||
{
|
||||
public static void FillAndConfigGrid<T>(this DataGridView grid, List<T>? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
grid.DataSource = data;
|
||||
var type = typeof(T);
|
||||
var properties = type.GetProperties();
|
||||
foreach (DataGridViewColumn column in grid.Columns)
|
||||
{
|
||||
var property = properties.FirstOrDefault(x => x.Name == column.Name);
|
||||
if (property == null)
|
||||
{
|
||||
throw new InvalidOperationException($"В типе {type.Name} не найдено свойство с именем {column.Name}");
|
||||
}
|
||||
var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault();
|
||||
if (attribute == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}");
|
||||
}
|
||||
if (attribute is ColumnAttribute columnAttr)
|
||||
{
|
||||
column.HeaderText = columnAttr.Title;
|
||||
column.Visible = columnAttr.Visible;
|
||||
if (columnAttr.IsUseAutoSize)
|
||||
{
|
||||
column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode),
|
||||
columnAttr.GridViewAutoSize.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
column.Width = columnAttr.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ using ShipyardContracts.BindingModels;
|
||||
using ShipyardContracts.BusinessLogicsContracts;
|
||||
using ShipyardView;
|
||||
using System.Windows.Forms;
|
||||
using ShipyardContracts.DI;
|
||||
|
||||
namespace ShipyardView
|
||||
{
|
||||
@ -26,15 +27,8 @@ namespace ShipyardView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ComponentName"].AutoSizeMode =
|
||||
DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Загрузка компонентов");
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка компонентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -45,9 +39,8 @@ namespace ShipyardView
|
||||
}
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service =
|
||||
Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (service is FormComponent form)
|
||||
var service = DependencyManager.Instance.Resolve<FormComponent>();
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
@ -59,8 +52,7 @@ namespace ShipyardView
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service =
|
||||
Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
var service = DependencyManager.Instance.Resolve<FormComponent>();
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
form.Id =
|
||||
|
@ -1,7 +1,9 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ShipyardBusinessLogic;
|
||||
using ShipyardContracts.BindingModels;
|
||||
using ShipyardContracts.BusinessLogicContracts;
|
||||
using ShipyardContracts.BusinessLogicsContracts;
|
||||
using ShipyardContracts.DI;
|
||||
using ShipyardDataModels.Enums;
|
||||
using ShipyardView;
|
||||
using System.Windows.Forms;
|
||||
@ -14,13 +16,16 @@ namespace ShipyardView
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
private readonly IReportLogic _reportLogic;
|
||||
private readonly IWorkProcess _workProcess;
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
|
||||
private readonly IBackUpLogic _backUpLogic;
|
||||
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
_reportLogic = reportLogic;
|
||||
_workProcess = workProcess;
|
||||
_backUpLogic = backUpLogic;
|
||||
}
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
@ -31,16 +36,7 @@ namespace ShipyardView
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
try
|
||||
{
|
||||
var list = _orderLogic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["ShipId"].Visible = false;
|
||||
dataGridView.Columns["ShipName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["ImplementerId"].Visible = false;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -52,7 +48,7 @@ namespace ShipyardView
|
||||
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs
|
||||
e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||
var service = DependencyManager.Instance.Resolve<FormComponents>();
|
||||
if (service is FormComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -60,7 +56,7 @@ namespace ShipyardView
|
||||
}
|
||||
private void ShipsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShips));
|
||||
var service = DependencyManager.Instance.Resolve<FormShips>();
|
||||
if (service is FormShips form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -69,8 +65,7 @@ namespace ShipyardView
|
||||
}
|
||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service =
|
||||
Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
var service = DependencyManager.Instance.Resolve<FormCreateOrder>();
|
||||
if (service is FormCreateOrder form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -186,7 +181,7 @@ namespace ShipyardView
|
||||
|
||||
private void ComponentsShipToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportShipComponents));
|
||||
var service = DependencyManager.Instance.Resolve<FormReportShipComponents>();
|
||||
if (service is FormReportShipComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -195,7 +190,7 @@ namespace ShipyardView
|
||||
|
||||
private void OrderListToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
|
||||
var service = DependencyManager.Instance.Resolve<FormReportOrders>();
|
||||
if (service is FormReportOrders form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -204,7 +199,7 @@ namespace ShipyardView
|
||||
|
||||
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(ClientsForm));
|
||||
var service = DependencyManager.Instance.Resolve<ClientsForm>();
|
||||
if (service is ClientsForm form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -213,13 +208,13 @@ namespace ShipyardView
|
||||
|
||||
private void StartWorkingToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
|
||||
_workProcess.DoWork(DependencyManager.Instance.Resolve<IImplementerLogic>(), _orderLogic);
|
||||
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(ImplementersForm));
|
||||
var service = DependencyManager.Instance.Resolve<ImplementersForm>();
|
||||
if (service is ImplementersForm form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
@ -228,11 +223,36 @@ namespace ShipyardView
|
||||
|
||||
private void mailToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(ViewMailForm));
|
||||
var service = DependencyManager.Instance.Resolve<ViewMailForm>();
|
||||
if (service is ViewMailForm form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateBackUpStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_backUpLogic != null)
|
||||
{
|
||||
var fbd = new FolderBrowserDialog();
|
||||
if (fbd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_backUpLogic.CreateBackUp(new BackUpSaveBinidngModel
|
||||
{
|
||||
FolderName = fbd.SelectedPath
|
||||
});
|
||||
MessageBox.Show("Бекап создан", "Сообщение",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user