Добавление магазина + логики + формы

This commit is contained in:
Володя 2023-04-19 20:23:06 +03:00
parent f27ce6cc8e
commit 322fd334ca
28 changed files with 2263 additions and 3 deletions

View File

@ -0,0 +1,181 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantBusinessLogic.BusinessLogics
{
public class CarShopLogic : ICarShopLogic
{
private readonly ILogger _logger;
private readonly ICarShopStorage _shopStorage;
public CarShopLogic(ILogger<CarShopLogic> logger, ICarShopStorage shopStorage)
{
_logger = logger;
_shopStorage = shopStorage;
}
public bool AddCar(CarShopSearchModel model, ICarModel car, int quantity)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (quantity <= 0)
{
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity));
}
_logger.LogInformation("AddCarInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
var element = _shopStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("AddCarInShop element not found");
return false;
}
_logger.LogInformation("AddCarInShop find. Id:{Id}", element.Id);
if (element.Cars.TryGetValue(car.Id, out var pair))
{
element.Cars[car.Id] = (car, quantity + pair.Item2);
_logger.LogInformation("AddCarInShop. Has been added {quantity} {car} in {ShopName}", quantity, car.CarName, element.ShopName);
}
else
{
element.Cars[car.Id] = (car, quantity);
_logger.LogInformation("AddCarInShop. Has been added {quantity} new Car {car} in {ShopName}", quantity, car.CarName, element.ShopName);
}
_shopStorage.Update(new()
{
Id = element.Id,
Adress = element.Adress,
ShopName = element.ShopName,
DateOpen = element.DateOpen,
Cars = element.Cars
});
return true;
}
public bool Create(CarShopBindingModel model)
{
CheckModel(model);
model.Cars = new();
if (_shopStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(CarShopBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_shopStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public CarShopViewModel? ReadElement(CarShopSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
var element = _shopStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<CarShopViewModel>? ReadList(CarShopSearchModel? model)
{
_logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id} ", model?.ShopName, model?.Id);
var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(CarShopBindingModel model)
{
CheckModel(model, false);
if (string.IsNullOrEmpty(model.ShopName))
{
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
}
if (_shopStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(CarShopBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ShopName))
{
throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
}
_logger.LogInformation("Shop. ShopName:{0}.Adress:{1}. Id: {2}", model.ShopName, model.Adress, model.Id);
var element = _shopStorage.GetElement(new CarShopSearchModel
{
ShopName = model.ShopName
});
if (element != null && element.Id != model.Id && element.ShopName == model.ShopName)
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,22 @@
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantContracts.BindingModels
{
public class CarShopBindingModel : ICarShop
{
public string ShopName { get; set; } = String.Empty;
public string Adress { get; set; } = String.Empty ;
public DateTime DateOpen { get; set; } = new();
public Dictionary<int, (ICarModel, int)> Cars { get; set; } = new();
public int Id { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantContracts.BusinessLogicsContracts
{
public interface ICarShopLogic
{
List<CarShopViewModel>? ReadList(CarShopSearchModel? model);
CarShopViewModel? ReadElement(CarShopSearchModel model);
bool Create(CarShopBindingModel model);
bool Update(CarShopBindingModel model);
bool Delete(CarShopBindingModel model);
bool AddCar(CarShopSearchModel model, ICarModel car, int quantity);
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantContracts.SearchModel
{
public class CarShopSearchModel
{
public int? Id { get; set; }
public string? ShopName { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantContracts.StoragesContracts
{
public interface ICarShopStorage
{
List<CarShopViewModel> GetFullList();
List<CarShopViewModel> GetFilteredList(CarShopSearchModel model);
CarShopViewModel? GetElement(CarShopSearchModel model);
CarShopViewModel? Insert(CarShopBindingModel model);
CarShopViewModel? Update(CarShopBindingModel model);
CarShopViewModel? Delete(CarShopBindingModel model);
}
}

View File

@ -0,0 +1,24 @@
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantContracts.ViewModel
{
public class CarShopViewModel : ICarShop
{
[DisplayName("Название магазина")]
public string ShopName { get; set; } = String.Empty;
[DisplayName("Адрес")]
public string Adress { get; set; } = String.Empty;
[DisplayName("Дата открытия")]
public DateTime DateOpen { get; set; } = new();
public Dictionary<int, (ICarModel, int)> Cars { get; set; } = new();
public int Id { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantDataModels.Models
{
public interface ICarShop : IId
{
string ShopName { get; }
string Adress { get; }
DateTime DateOpen { get; }
Dictionary<int, (ICarModel, int)> Cars { get; }
}
}

View File

@ -13,11 +13,13 @@ namespace AutomobilePlantListImplement
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Car> Cars { get; set; }
public List<CarShop> Shops { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Cars = new List<Car>();
Shops = new List<CarShop>();
}
public static DataListSingleton GetInstance()
{

View File

@ -0,0 +1,121 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantContracts.StoragesContracts;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantListImplement.Implements
{
public class CarShopStorege : ICarShopStorage
{
private readonly DataListSingleton _source;
public CarShopStorege()
{
_source = DataListSingleton.GetInstance();
}
public List<CarShopViewModel> GetFullList()
{
var result = new List<CarShopViewModel>();
foreach (var shop in _source.Shops)
{
result.Add(shop.GetViewModel);
}
return result;
}
public List<CarShopViewModel> GetFilteredList(CarShopSearchModel model)
{
var result = new List<CarShopViewModel>();
if (string.IsNullOrEmpty(model.ShopName))
{
return result;
}
foreach (var shop in _source.Shops)
{
if (shop.ShopName.Contains(model.ShopName))
{
result.Add(shop.GetViewModel);
}
}
return result;
}
public CarShopViewModel? GetElement(CarShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
foreach (var shop in _source.Shops)
{
if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id))
{
return shop.GetViewModel;
}
}
return null;
}
public CarShopViewModel? Insert(CarShopBindingModel model)
{
model.Id = 1;
foreach (var shop in _source.Shops)
{
if (model.Id <= shop.Id)
{
model.Id = shop.Id + 1;
}
}
var newShop = CarShop.Create(model);
if (newShop == null)
{
return null;
}
_source.Shops.Add(newShop);
return newShop.GetViewModel;
}
public CarShopViewModel? Update(CarShopBindingModel model)
{
foreach (var shop in _source.Shops)
{
if (shop.Id == model.Id)
{
shop.Update(model);
return shop.GetViewModel;
}
}
return null;
}
public CarShopViewModel? Delete(CarShopBindingModel model)
{
for (int i = 0; i < _source.Shops.Count; ++i)
{
if (_source.Shops[i].Id == model.Id)
{
var element = _source.Shops[i];
_source.Shops.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,60 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.ViewModel;
using AutomobilePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace AutomobilePlantListImplement.Models
{
public class CarShop : ICarShop
{
public string ShopName { get; private set; } = String.Empty;
public string Adress { get; private set; } = String.Empty;
public DateTime DateOpen { get; private set; }
public Dictionary<int, (ICarModel, int)> Cars { get; private set; } = new ();
public int Id { get; private set; }
public static CarShop? Create(CarShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new CarShop()
{
Id = model.Id,
ShopName = model.ShopName,
Adress = model.Adress,
DateOpen = model.DateOpen,
Cars = new()
};
}
public void Update(CarShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Adress = model.Adress;
DateOpen = model.DateOpen;
Cars = model.Cars;
}
public CarShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
DateOpen = DateOpen,
Cars = Cars
};
}
}

View File

@ -32,12 +32,14 @@
this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.DataGridView = new System.Windows.Forms.DataGridView();
this.CreateOrderButton = new System.Windows.Forms.Button();
this.TakeOrderInWorkButton = new System.Windows.Forms.Button();
this.OrderReadyButton = new System.Windows.Forms.Button();
this.IssuedOrderButton = new System.Windows.Forms.Button();
this.UpdateListButton = new System.Windows.Forms.Button();
this.AddShopCarButton = new System.Windows.Forms.Button();
this.MenuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
this.SuspendLayout();
@ -58,7 +60,8 @@
//
this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ИзделияToolStripMenuItem,
this.КомпонентыToolStripMenuItem});
this.КомпонентыToolStripMenuItem,
this.магазиныToolStripMenuItem});
this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem";
this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
this.СправочникиToolStripMenuItem.Text = "Cправочники";
@ -66,17 +69,24 @@
// ИзделияToolStripMenuItem
//
this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.ИзделияToolStripMenuItem.Text = "Изделия";
this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
//
// КомпонентыToolStripMenuItem
//
this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.КомпонентыToolStripMenuItem.Text = "Компоненты";
this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
//
// магазиныToolStripMenuItem
//
this.магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.магазиныToolStripMenuItem.Text = "Магазины";
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
//
// DataGridView
//
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
@ -143,11 +153,22 @@
this.UpdateListButton.UseVisualStyleBackColor = true;
this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click);
//
// AddShopCarButton
//
this.AddShopCarButton.Location = new System.Drawing.Point(832, 416);
this.AddShopCarButton.Name = "AddShopCarButton";
this.AddShopCarButton.Size = new System.Drawing.Size(143, 56);
this.AddShopCarButton.TabIndex = 7;
this.AddShopCarButton.Text = "Пополнить магазин";
this.AddShopCarButton.UseVisualStyleBackColor = true;
this.AddShopCarButton.Click += new System.EventHandler(this.AddShopCarButton_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(989, 600);
this.Controls.Add(this.AddShopCarButton);
this.Controls.Add(this.UpdateListButton);
this.Controls.Add(this.IssuedOrderButton);
this.Controls.Add(this.OrderReadyButton);
@ -180,5 +201,7 @@
private Button OrderReadyButton;
private Button IssuedOrderButton;
private Button UpdateListButton;
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button AddShopCarButton;
}
}

View File

@ -196,5 +196,26 @@ namespace AutomobilePlant
{
LoadData();
}
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void AddShopCarButton_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopAdd));
if (service is FormShopAdd form)
{
form.ShowDialog();
LoadData();
}
}
}
}

View File

@ -0,0 +1,181 @@
namespace AutomobilePlant
{
partial class FormShop
{
/// <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()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
this.CarGroupBox = new System.Windows.Forms.GroupBox();
this.DataGridView = new System.Windows.Forms.DataGridView();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.CarNameField = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.UpdateButton = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button();
this.SaveButton = new System.Windows.Forms.Button();
this.CarGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
this.SuspendLayout();
//
// CarGroupBox
//
this.CarGroupBox.Controls.Add(this.DataGridView);
this.CarGroupBox.Location = new System.Drawing.Point(12, 13);
this.CarGroupBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.CarGroupBox.Name = "CarGroupBox";
this.CarGroupBox.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.CarGroupBox.Size = new System.Drawing.Size(825, 467);
this.CarGroupBox.TabIndex = 5;
this.CarGroupBox.TabStop = false;
this.CarGroupBox.Text = "машиины";
//
// DataGridView
//
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.CarNameField,
this.CountField});
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.DataGridView.DefaultCellStyle = dataGridViewCellStyle2;
this.DataGridView.Location = new System.Drawing.Point(7, 29);
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.DataGridView.Name = "DataGridView";
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
this.DataGridView.RowHeadersWidth = 51;
this.DataGridView.RowTemplate.Height = 25;
this.DataGridView.Size = new System.Drawing.Size(762, 429);
this.DataGridView.TabIndex = 0;
//
// ID
//
this.ID.HeaderText = "ID";
this.ID.MinimumWidth = 6;
this.ID.Name = "ID";
this.ID.Visible = false;
this.ID.Width = 125;
//
// CarNameField
//
this.CarNameField.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.CarNameField.HeaderText = "Машина";
this.CarNameField.MinimumWidth = 6;
this.CarNameField.Name = "CarNameField";
//
// CountField
//
this.CountField.HeaderText = "Количество";
this.CountField.MinimumWidth = 6;
this.CountField.Name = "CountField";
this.CountField.Width = 125;
//
// UpdateButton
//
this.UpdateButton.Location = new System.Drawing.Point(395, 505);
this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.UpdateButton.Name = "UpdateButton";
this.UpdateButton.Size = new System.Drawing.Size(126, 51);
this.UpdateButton.TabIndex = 4;
this.UpdateButton.Text = "Обновить";
this.UpdateButton.UseVisualStyleBackColor = true;
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(695, 505);
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(126, 45);
this.ButtonCancel.TabIndex = 7;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// SaveButton
//
this.SaveButton.Location = new System.Drawing.Point(548, 505);
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(126, 45);
this.SaveButton.TabIndex = 8;
this.SaveButton.Text = "Сохранить";
this.SaveButton.UseVisualStyleBackColor = true;
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(853, 568);
this.Controls.Add(this.UpdateButton);
this.Controls.Add(this.SaveButton);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.CarGroupBox);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormShop";
this.Text = "Магазин";
this.Load += new System.EventHandler(this.FormShop_Load);
this.CarGroupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox CarGroupBox;
private Button UpdateButton;
private DataGridView DataGridView;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn CarNameField;
private DataGridViewTextBoxColumn CountField;
private Button ButtonCancel;
private Button SaveButton;
}
}

View File

@ -0,0 +1,112 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantDataModels.Models;
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 AutomobilePlant
{
public partial class FormShop : Form
{
private readonly ILogger _logger;
private readonly ICarShopLogic _logic;
private int? _id;
private Dictionary<int, (ICarModel, int)> _carComponents;
public int Id { set { _id = value; } }
public FormShop(ILogger<FormShop> logger, ICarShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_carComponents = new Dictionary<int, (ICarModel, int)>();
}
private void FormShop_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка магазина");
try
{
var view = _logic.ReadElement(new CarShopSearchModel
{
Id =
_id.Value
});
if (view != null)
{
_carComponents = view.Cars ?? new
Dictionary<int, (ICarModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка машин магазина");
try
{
if (_carComponents != null)
{
DataGridView.Rows.Clear();
foreach (var pc in _carComponents)
{
DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.CarName, pc.Value.Item2 });
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки машин магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void UpdateButton_Click(object sender, EventArgs e)
{
LoadData();
}
private void SaveButton_Click(object sender, EventArgs e)
{
_logger.LogInformation("Сохранение магазина");
try
{
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,142 @@
namespace AutomobilePlant
{
partial class FormShopAdd
{
/// <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()
{
this.ShopNameComboBox = new System.Windows.Forms.ComboBox();
this.CarComboBox = new System.Windows.Forms.ComboBox();
this.NameShopLabel = new System.Windows.Forms.Label();
this.CarLabel = new System.Windows.Forms.Label();
this.CountTextBox = new System.Windows.Forms.TextBox();
this.CountLabel = new System.Windows.Forms.Label();
this.SaveButton = new System.Windows.Forms.Button();
this.CancelButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// ShopNameComboBox
//
this.ShopNameComboBox.FormattingEnabled = true;
this.ShopNameComboBox.Location = new System.Drawing.Point(113, 41);
this.ShopNameComboBox.Name = "ShopNameComboBox";
this.ShopNameComboBox.Size = new System.Drawing.Size(233, 28);
this.ShopNameComboBox.TabIndex = 0;
//
// CarComboBox
//
this.CarComboBox.FormattingEnabled = true;
this.CarComboBox.Location = new System.Drawing.Point(113, 93);
this.CarComboBox.Name = "CarComboBox";
this.CarComboBox.Size = new System.Drawing.Size(233, 28);
this.CarComboBox.TabIndex = 1;
//
// NameShopLabel
//
this.NameShopLabel.AutoSize = true;
this.NameShopLabel.Location = new System.Drawing.Point(12, 44);
this.NameShopLabel.Name = "NameShopLabel";
this.NameShopLabel.Size = new System.Drawing.Size(69, 20);
this.NameShopLabel.TabIndex = 2;
this.NameShopLabel.Text = "Магазин";
//
// CarLabel
//
this.CarLabel.AutoSize = true;
this.CarLabel.Location = new System.Drawing.Point(12, 96);
this.CarLabel.Name = "CarLabel";
this.CarLabel.Size = new System.Drawing.Size(68, 20);
this.CarLabel.TabIndex = 3;
this.CarLabel.Text = "Изделие";
//
// CountTextBox
//
this.CountTextBox.Location = new System.Drawing.Point(113, 139);
this.CountTextBox.Name = "CountTextBox";
this.CountTextBox.Size = new System.Drawing.Size(233, 27);
this.CountTextBox.TabIndex = 4;
//
// CountLabel
//
this.CountLabel.AutoSize = true;
this.CountLabel.Location = new System.Drawing.Point(12, 146);
this.CountLabel.Name = "CountLabel";
this.CountLabel.Size = new System.Drawing.Size(58, 20);
this.CountLabel.TabIndex = 5;
this.CountLabel.Text = "Кол-во";
//
// SaveButton
//
this.SaveButton.Location = new System.Drawing.Point(130, 189);
this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(94, 44);
this.SaveButton.TabIndex = 6;
this.SaveButton.Text = "Сохранить";
this.SaveButton.UseVisualStyleBackColor = true;
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
//
// CancelButton
//
this.CancelButton.Location = new System.Drawing.Point(252, 189);
this.CancelButton.Name = "CancelButton";
this.CancelButton.Size = new System.Drawing.Size(94, 44);
this.CancelButton.TabIndex = 7;
this.CancelButton.Text = "Закрыть";
this.CancelButton.UseVisualStyleBackColor = true;
this.CancelButton.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormShopAdd
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(413, 245);
this.Controls.Add(this.CancelButton);
this.Controls.Add(this.SaveButton);
this.Controls.Add(this.CountLabel);
this.Controls.Add(this.CountTextBox);
this.Controls.Add(this.CarLabel);
this.Controls.Add(this.NameShopLabel);
this.Controls.Add(this.CarComboBox);
this.Controls.Add(this.ShopNameComboBox);
this.Name = "FormShopAdd";
this.Text = "FormShopAdd";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private ComboBox ShopNameComboBox;
private ComboBox CarComboBox;
private Label NameShopLabel;
private Label CarLabel;
private TextBox CountTextBox;
private Label CountLabel;
private Button SaveButton;
private Button CancelButton;
}
}

View File

@ -0,0 +1,104 @@
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.ViewModel;
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 AutomobilePlant
{
public partial class FormShopAdd : Form
{
private readonly ILogger _logger;
private readonly ICarShopLogic _shopLogic;
private readonly ICarLogic _carLogic;
private readonly List<CarShopViewModel>? _listShops;
private readonly List<CarViewModel>? _listCars;
public FormShopAdd(ILogger<FormShopAdd> logger, ICarShopLogic shopLogic, ICarLogic carLogic)
{
InitializeComponent();
_shopLogic = shopLogic;
_carLogic = carLogic;
_logger = logger;
_listShops = shopLogic.ReadList(null);
if (_listShops != null)
{
ShopNameComboBox.DisplayMember = "ShopName";
ShopNameComboBox.ValueMember = "Id";
ShopNameComboBox.DataSource = _listShops;
ShopNameComboBox.SelectedItem = null;
}
_listCars = carLogic.ReadList(null);
if (_listCars != null)
{
CarComboBox.DisplayMember = "CarName";
CarComboBox.ValueMember = "Id";
CarComboBox.DataSource = _listCars;
CarComboBox.SelectedItem = null;
}
}
private void SaveButton_Click(object sender, EventArgs e)
{
if (ShopNameComboBox.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (CarComboBox.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Добавление изделия в магазин");
try
{
var car = _carLogic.ReadElement(new()
{
Id = (int)CarComboBox.SelectedValue
});
if (car == null)
{
throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
}
var resultOperation = _shopLogic.AddCar(
model: new() { Id = (int)ShopNameComboBox.SelectedValue },
car: car,
quantity: Convert.ToInt32(CountTextBox.Text)
);
if (!resultOperation)
{
throw new Exception("Ошибка при добавлении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,239 @@
namespace AutomobilePlant
{
partial class FormShopCar
{
/// <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()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
this.ShopNameLabel = new System.Windows.Forms.Label();
this.AdressLabel = new System.Windows.Forms.Label();
this.ShopNameTextBox = new System.Windows.Forms.TextBox();
this.AdressTextBox = new System.Windows.Forms.TextBox();
this.ComponentsGroupBox = new System.Windows.Forms.GroupBox();
this.ButtonCancel = new System.Windows.Forms.Button();
this.SaveButton = new System.Windows.Forms.Button();
this.UpdateButton = new System.Windows.Forms.Button();
this.DataGridView = new System.Windows.Forms.DataGridView();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ComponentNameField = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.DateOpenPicker = new System.Windows.Forms.DateTimePicker();
this.ComponentsGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
this.SuspendLayout();
//
// ShopNameLabel
//
this.ShopNameLabel.AutoSize = true;
this.ShopNameLabel.Location = new System.Drawing.Point(14, 12);
this.ShopNameLabel.Name = "ShopNameLabel";
this.ShopNameLabel.Size = new System.Drawing.Size(84, 20);
this.ShopNameLabel.TabIndex = 0;
this.ShopNameLabel.Text = "Название: ";
//
// AdressLabel
//
this.AdressLabel.AutoSize = true;
this.AdressLabel.Location = new System.Drawing.Point(14, 57);
this.AdressLabel.Name = "AdressLabel";
this.AdressLabel.Size = new System.Drawing.Size(51, 20);
this.AdressLabel.TabIndex = 1;
this.AdressLabel.Text = "Адрес";
//
// ShopNameTextBox
//
this.ShopNameTextBox.Location = new System.Drawing.Point(95, 8);
this.ShopNameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ShopNameTextBox.Name = "ShopNameTextBox";
this.ShopNameTextBox.Size = new System.Drawing.Size(323, 27);
this.ShopNameTextBox.TabIndex = 2;
//
// AdressTextBox
//
this.AdressTextBox.Location = new System.Drawing.Point(95, 53);
this.AdressTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.AdressTextBox.Name = "AdressTextBox";
this.AdressTextBox.Size = new System.Drawing.Size(323, 27);
this.AdressTextBox.TabIndex = 3;
//
// ComponentsGroupBox
//
this.ComponentsGroupBox.Controls.Add(this.ButtonCancel);
this.ComponentsGroupBox.Controls.Add(this.SaveButton);
this.ComponentsGroupBox.Controls.Add(this.UpdateButton);
this.ComponentsGroupBox.Controls.Add(this.DataGridView);
this.ComponentsGroupBox.Location = new System.Drawing.Point(14, 107);
this.ComponentsGroupBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ComponentsGroupBox.Name = "ComponentsGroupBox";
this.ComponentsGroupBox.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ComponentsGroupBox.Size = new System.Drawing.Size(825, 467);
this.ComponentsGroupBox.TabIndex = 5;
this.ComponentsGroupBox.TabStop = false;
this.ComponentsGroupBox.Text = "Машины";
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(674, 232);
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(126, 45);
this.ButtonCancel.TabIndex = 7;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// SaveButton
//
this.SaveButton.Location = new System.Drawing.Point(674, 79);
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(126, 45);
this.SaveButton.TabIndex = 8;
this.SaveButton.Text = "Сохранить";
this.SaveButton.UseVisualStyleBackColor = true;
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
//
// UpdateButton
//
this.UpdateButton.Location = new System.Drawing.Point(674, 142);
this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.UpdateButton.Name = "UpdateButton";
this.UpdateButton.Size = new System.Drawing.Size(126, 51);
this.UpdateButton.TabIndex = 4;
this.UpdateButton.Text = "Обновить";
this.UpdateButton.UseVisualStyleBackColor = true;
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
//
// DataGridView
//
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.ComponentNameField,
this.CountField});
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.DataGridView.DefaultCellStyle = dataGridViewCellStyle2;
this.DataGridView.Location = new System.Drawing.Point(7, 29);
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.DataGridView.Name = "DataGridView";
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
this.DataGridView.RowHeadersWidth = 51;
this.DataGridView.RowTemplate.Height = 25;
this.DataGridView.Size = new System.Drawing.Size(641, 429);
this.DataGridView.TabIndex = 0;
//
// ID
//
this.ID.HeaderText = "ID";
this.ID.MinimumWidth = 6;
this.ID.Name = "ID";
this.ID.Visible = false;
this.ID.Width = 125;
//
// ComponentNameField
//
this.ComponentNameField.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ComponentNameField.HeaderText = "Машина";
this.ComponentNameField.MinimumWidth = 6;
this.ComponentNameField.Name = "ComponentNameField";
//
// CountField
//
this.CountField.HeaderText = "Количество";
this.CountField.MinimumWidth = 6;
this.CountField.Name = "CountField";
this.CountField.Width = 125;
//
// DateOpenPicker
//
this.DateOpenPicker.Location = new System.Drawing.Point(471, 8);
this.DateOpenPicker.Name = "DateOpenPicker";
this.DateOpenPicker.Size = new System.Drawing.Size(250, 27);
this.DateOpenPicker.TabIndex = 6;
//
// FormShopCar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(853, 664);
this.Controls.Add(this.DateOpenPicker);
this.Controls.Add(this.ComponentsGroupBox);
this.Controls.Add(this.AdressTextBox);
this.Controls.Add(this.ShopNameTextBox);
this.Controls.Add(this.AdressLabel);
this.Controls.Add(this.ShopNameLabel);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormShopCar";
this.Text = "Изделие";
this.Load += new System.EventHandler(this.FormCar_Load);
this.ComponentsGroupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label ShopNameLabel;
private Label AdressLabel;
private TextBox ShopNameTextBox;
private TextBox AdressTextBox;
private GroupBox ComponentsGroupBox;
private Button UpdateButton;
private DataGridView DataGridView;
private Button ButtonCancel;
private Button SaveButton;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn ComponentNameField;
private DataGridViewTextBoxColumn CountField;
private DateTimePicker DateOpenPicker;
}
}

View File

@ -0,0 +1,140 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.SearchModel;
using AutomobilePlantDataModels.Models;
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 AutomobilePlant
{
public partial class FormShopCar : Form
{
private readonly ILogger _logger;
private readonly ICarShopLogic _logic;
private int? _id;
private Dictionary<int, (ICarModel, int)> _cars;
public int Id { set { _id = value; } }
public FormShopCar(ILogger<FormCar> logger, ICarShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_cars = new Dictionary<int, (ICarModel, int)>();
}
private void FormCar_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка изделия");
try
{
var view = _logic.ReadElement(new CarShopSearchModel
{
Id =
_id.Value
});
if (view != null)
{
ShopNameTextBox.Text = view.ShopName;
AdressTextBox.Text = view.Adress;
DateOpenPicker.Value = view.DateOpen;
_cars = view.Cars ?? new
Dictionary<int, (ICarModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка компонент изделия");
try
{
if (_cars != null)
{
DataGridView.Rows.Clear();
foreach (var pc in _cars)
{
DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.CarName, pc.Value.Item2 });
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки компонент изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void UpdateButton_Click(object sender, EventArgs e)
{
LoadData();
}
private void SaveButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(ShopNameTextBox.Text))
{
MessageBox.Show("Заполните название", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(AdressTextBox.Text))
{
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение изделия");
try
{
var model = new CarShopBindingModel
{
Id = _id ?? 0,
ShopName = ShopNameTextBox.Text,
DateOpen = DateOpenPicker.Value,
Adress = AdressTextBox.Text,
Cars = _cars
};
var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,123 @@
namespace AutomobilePlant
{
partial class FormShopCreate
{
/// <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()
{
this.ShopNameLabel = new System.Windows.Forms.Label();
this.ShopNameTextBox = new System.Windows.Forms.TextBox();
this.AdressLabel = new System.Windows.Forms.Label();
this.AdressTextBox = new System.Windows.Forms.TextBox();
this.SaveButton = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// ShopNameLabel
//
this.ShopNameLabel.AutoSize = true;
this.ShopNameLabel.Location = new System.Drawing.Point(22, 20);
this.ShopNameLabel.Name = "ShopNameLabel";
this.ShopNameLabel.Size = new System.Drawing.Size(84, 20);
this.ShopNameLabel.TabIndex = 0;
this.ShopNameLabel.Text = "Название: ";
//
// ShopNameTextBox
//
this.ShopNameTextBox.Location = new System.Drawing.Point(103, 16);
this.ShopNameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ShopNameTextBox.Name = "ShopNameTextBox";
this.ShopNameTextBox.Size = new System.Drawing.Size(238, 27);
this.ShopNameTextBox.TabIndex = 2;
//
// AdressLabel
//
this.AdressLabel.AutoSize = true;
this.AdressLabel.Location = new System.Drawing.Point(46, 72);
this.AdressLabel.Name = "AdressLabel";
this.AdressLabel.Size = new System.Drawing.Size(58, 20);
this.AdressLabel.TabIndex = 3;
this.AdressLabel.Text = "Адресс";
//
// AdressTextBox
//
this.AdressTextBox.Location = new System.Drawing.Point(103, 68);
this.AdressTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.AdressTextBox.Name = "AdressTextBox";
this.AdressTextBox.Size = new System.Drawing.Size(238, 27);
this.AdressTextBox.TabIndex = 4;
//
// SaveButton
//
this.SaveButton.Location = new System.Drawing.Point(154, 120);
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(95, 31);
this.SaveButton.TabIndex = 5;
this.SaveButton.Text = "Сохранить";
this.SaveButton.UseVisualStyleBackColor = true;
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(256, 120);
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(86, 31);
this.ButtonCancel.TabIndex = 6;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormShopCreate
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(375, 167);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.SaveButton);
this.Controls.Add(this.AdressTextBox);
this.Controls.Add(this.AdressLabel);
this.Controls.Add(this.ShopNameTextBox);
this.Controls.Add(this.ShopNameLabel);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormShopCreate";
this.Text = "Магазин";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label ShopNameLabel;
private TextBox ShopNameTextBox;
private Label AdressLabel;
private TextBox AdressTextBox;
private Button SaveButton;
private Button ButtonCancel;
}
}

View File

@ -0,0 +1,108 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.BusinessLogicsContracts;
using AutomobilePlantContracts.SearchModel;
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 AutomobilePlant
{
public partial class FormShopCreate : Form
{
private readonly ILogger _logger;
private readonly ICarShopLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormShopCreate(ILogger<FormShopCreate> logger, ICarShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormShopCreate_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение магазина");
var view = _logic.ReadElement(new CarShopSearchModel
{
Id = _id.Value
});
if (view != null)
{
ShopNameTextBox.Text = view.ShopName;
AdressTextBox.Text = view.Adress.ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void SaveButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(ShopNameTextBox.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(AdressTextBox.Text))
{
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
var model = new CarShopBindingModel
{
Id = _id ?? 0,
ShopName = ShopNameTextBox.Text,
Adress = AdressTextBox.Text,
DateOpen = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc)
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,135 @@
namespace AutomobilePlant
{
partial class FormShops
{
/// <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()
{
this.DataGridView = new System.Windows.Forms.DataGridView();
this.AddButton = new System.Windows.Forms.Button();
this.ChangeButton = new System.Windows.Forms.Button();
this.DeleteButton = new System.Windows.Forms.Button();
this.UpdateButton = new System.Windows.Forms.Button();
this.SeeButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
this.SuspendLayout();
//
// DataGridView
//
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.DataGridView.Location = new System.Drawing.Point(1, 1);
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.DataGridView.Name = "DataGridView";
this.DataGridView.RowHeadersWidth = 51;
this.DataGridView.RowTemplate.Height = 25;
this.DataGridView.Size = new System.Drawing.Size(642, 660);
this.DataGridView.TabIndex = 0;
//
// AddButton
//
this.AddButton.Location = new System.Drawing.Point(669, 16);
this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.AddButton.Name = "AddButton";
this.AddButton.Size = new System.Drawing.Size(137, 55);
this.AddButton.TabIndex = 1;
this.AddButton.Text = "Добавить";
this.AddButton.UseVisualStyleBackColor = true;
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
//
// ChangeButton
//
this.ChangeButton.Location = new System.Drawing.Point(669, 95);
this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ChangeButton.Name = "ChangeButton";
this.ChangeButton.Size = new System.Drawing.Size(137, 55);
this.ChangeButton.TabIndex = 2;
this.ChangeButton.Text = "Изменить";
this.ChangeButton.UseVisualStyleBackColor = true;
this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click);
//
// DeleteButton
//
this.DeleteButton.Location = new System.Drawing.Point(669, 173);
this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.DeleteButton.Name = "DeleteButton";
this.DeleteButton.Size = new System.Drawing.Size(137, 55);
this.DeleteButton.TabIndex = 3;
this.DeleteButton.Text = "Удалить";
this.DeleteButton.UseVisualStyleBackColor = true;
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
//
// UpdateButton
//
this.UpdateButton.Location = new System.Drawing.Point(669, 255);
this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.UpdateButton.Name = "UpdateButton";
this.UpdateButton.Size = new System.Drawing.Size(137, 55);
this.UpdateButton.TabIndex = 4;
this.UpdateButton.Text = "Обновить";
this.UpdateButton.UseVisualStyleBackColor = true;
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
//
// SeeButton
//
this.SeeButton.Location = new System.Drawing.Point(669, 338);
this.SeeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.SeeButton.Name = "SeeButton";
this.SeeButton.Size = new System.Drawing.Size(137, 55);
this.SeeButton.TabIndex = 5;
this.SeeButton.Text = "Посмотреть";
this.SeeButton.UseVisualStyleBackColor = true;
this.SeeButton.Click += new System.EventHandler(this.SeeButton_Click);
//
// FormShops
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(819, 669);
this.Controls.Add(this.SeeButton);
this.Controls.Add(this.UpdateButton);
this.Controls.Add(this.DeleteButton);
this.Controls.Add(this.ChangeButton);
this.Controls.Add(this.AddButton);
this.Controls.Add(this.DataGridView);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormShops";
this.Text = "Магазины";
this.Load += new System.EventHandler(this.FormComponents_Load);
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView DataGridView;
private Button AddButton;
private Button ChangeButton;
private Button DeleteButton;
private Button UpdateButton;
private Button SeeButton;
}
}

View File

@ -0,0 +1,140 @@
using AutomobilePlantContracts.BindingModels;
using AutomobilePlantContracts.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 AutomobilePlant
{
public partial class FormShops : Form
{
private readonly ILogger _logger;
private readonly ICarShopLogic _logic;
public FormShops(ILogger<FormShops> logger, ICarShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormComponents_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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridView.Columns["Adress"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridView.Columns["Cars"].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(FormShopCar));
if (service is FormShopCar form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ChangeButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopCar));
if (service is FormShopCar form)
{
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 CarShopBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void UpdateButton_Click(object sender, EventArgs e)
{
LoadData();
}
private void SeeButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -37,9 +37,13 @@ namespace AutomobilePlant
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ICarStorage, CarStorage>();
services.AddTransient<ICarShopStorage, CarShopStorege>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ICarLogic, CarLogic>();
services.AddTransient<ICarShopLogic, CarShopLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
@ -47,6 +51,11 @@ namespace AutomobilePlant
services.AddTransient<FormCar>();
services.AddTransient<FormCarComponent>();
services.AddTransient<FormCars>();
services.AddTransient<FormShops>();
services.AddTransient<FormShop>();
services.AddTransient<FormShopCar>();
services.AddTransient<FormShopAdd>();
services.AddTransient<FormShopCreate>();
}
}