FormRepairs

This commit is contained in:
ShabOl 2024-02-21 11:04:46 +04:00
parent 98ba30c161
commit 49059764f0
5 changed files with 247 additions and 15 deletions

View File

@ -9,8 +9,11 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AutoWorkshopContracts\AutoWorkshopContracts.csproj" />
<ProjectReference Include="..\AutoWorkshopBusinessLogic\AutoWorkshopBusinessLogic.csproj" />
<ProjectReference Include="..\AutoWorkshopImplement\AutoWorkshopListImplement.csproj" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
</ItemGroup>
</Project>

113
AutoWorkshop/Forms/FormRepairs.Designer.cs generated Normal file
View File

@ -0,0 +1,113 @@
namespace AutoWorkshopView.Forms
{
partial class FormRepairs
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
DataGridView = new DataGridView();
AddButton = new Button();
UpdateButton = new Button();
DeleteButton = new Button();
RefreshButton = new Button();
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
SuspendLayout();
//
// DataGridView
//
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
DataGridView.Location = new Point(12, 12);
DataGridView.Name = "DataGridView";
DataGridView.RowHeadersWidth = 51;
DataGridView.Size = new Size(379, 426);
DataGridView.TabIndex = 0;
//
// AddButton
//
AddButton.Location = new Point(397, 12);
AddButton.Name = "AddButton";
AddButton.Size = new Size(148, 29);
AddButton.TabIndex = 1;
AddButton.Text = "Добавить";
AddButton.UseVisualStyleBackColor = true;
AddButton.Click += AddButton_Click;
//
// UpdateButton
//
UpdateButton.Location = new Point(397, 47);
UpdateButton.Name = "UpdateButton";
UpdateButton.Size = new Size(148, 29);
UpdateButton.TabIndex = 2;
UpdateButton.Text = "Изменить";
UpdateButton.UseVisualStyleBackColor = true;
UpdateButton.Click += UpdateButton_Click;
//
// DeleteButton
//
DeleteButton.Location = new Point(397, 82);
DeleteButton.Name = "DeleteButton";
DeleteButton.Size = new Size(148, 29);
DeleteButton.TabIndex = 3;
DeleteButton.Text = "Удалить";
DeleteButton.UseVisualStyleBackColor = true;
DeleteButton.Click += DeleteButton_Click;
//
// RefreshButton
//
RefreshButton.Location = new Point(397, 117);
RefreshButton.Name = "RefreshButton";
RefreshButton.Size = new Size(148, 29);
RefreshButton.TabIndex = 4;
RefreshButton.Text = "Обновить";
RefreshButton.UseVisualStyleBackColor = true;
RefreshButton.Click += RefreshButton_Click;
//
// FormRepairs
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(557, 450);
Controls.Add(RefreshButton);
Controls.Add(DeleteButton);
Controls.Add(UpdateButton);
Controls.Add(AddButton);
Controls.Add(DataGridView);
Name = "FormRepairs";
Text = "FormRepairs";
Load += FormRepairs_Load;
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView DataGridView;
private Button AddButton;
private Button UpdateButton;
private Button DeleteButton;
private Button RefreshButton;
}
}

View File

@ -0,0 +1,114 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.BusinessLogicContracts;
using Microsoft.Extensions.Logging;
namespace AutoWorkshopView.Forms
{
public partial class FormRepairs : Form
{
private readonly ILogger _logger;
private readonly IRepairLogic _logic;
public FormRepairs(ILogger<FormRepairs> Logger, IRepairLogic Logic)
{
InitializeComponent();
_logger = Logger;
_logic = Logic;
}
private void FormRepairs_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var List = _logic.ReadList(null);
if (List != null)
{
DataGridView.DataSource = List;
DataGridView.Columns["Id"].Visible = false;
DataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridView.Columns["RepairComponents"].Visible = false;
}
_logger.LogInformation("Загрузка ремонта");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки ремонта");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AddButton_Click(object sender, EventArgs e)
{
var Service = Program.ServiceProvider?.GetService(typeof(FormRepair));
if (Service is FormRepair Form)
{
if (Form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void UpdateButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
var Service = Program.ServiceProvider?.GetService(typeof(FormRepair));
if (Service is FormRepair Form)
{
var Temp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
Form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (Form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void DeleteButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление ремонта");
try
{
if (!_logic.Delete(new RepairBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления ремонта");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void RefreshButton_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -59,11 +59,9 @@ namespace AutoWorkshopView
private void МороженноеStripMenuItem_Click(object sender, EventArgs e)
{
var Service = Program.ServiceProvider?.GetService(typeof(FormRepair));
var Service = Program.ServiceProvider?.GetService(typeof(FormRepairs));
//// FORMREPAIRS??
if (Service is FormRepair Form)
if (Service is FormRepairs Form)
{
Form.ShowDialog();
}

View File

@ -1,8 +1,11 @@
using AutoWorkshopBusinessLogic.BusinessLogics;
using AutoWorkshopContracts.BusinessLogicContracts;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopListImplement.Implements;
using AutoWorkshopView.Forms;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
namespace AutoWorkshopView
{
@ -14,11 +17,12 @@ namespace AutoWorkshopView
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
var Services = new ServiceCollection();
ConfigureServices(Services);
_serviceProvider = Services.BuildServiceProvider();
_serviceProvider = Services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<MainForm>());
}
@ -32,17 +36,17 @@ namespace AutoWorkshopView
Services.AddTransient<IComponentStorage, ComponentStorage>();
Services.AddTransient<IOrderStorage, OrderStorage>();
Services.AddTransient<IIceCreamStorage, IceCreamStorage>();
Services.AddTransient<IRepairStorage, RepairStorage>();
Services.AddTransient<IComponentLogic, ComponentLogic>();
Services.AddTransient<IOrderLogic, OrderLogic>();
Services.AddTransient<IIceCreamLogic, IceCreamLogic>();
Services.AddTransient<IRepairLogic, RepairLogic>();
Services.AddTransient<MainForm>();
Services.AddTransient<ComponentForm>();
Services.AddTransient<ComponentsForm>();
Services.AddTransient<OrderForm>();
Services.AddTransient<IceCreamForm>();
Services.AddTransient<IceCreamComponentForm>();
Services.AddTransient<IceCreamsForm>();
Services.AddTransient<FormComponent>();
Services.AddTransient<FormComponents>();
Services.AddTransient<FormCreateOrder>();
Services.AddTransient<FormRepair>();
Services.AddTransient<FormRepairComponent>();
Services.AddTransient<FormRepairs>();
}
}
}