PIbd-21. Anisin R.S. Lab work 05. Hard #15

Closed
RuslanAnisin wants to merge 9 commits from lab5_hard into lab5
21 changed files with 765 additions and 16 deletions
Showing only changes of commit 51df1aeb59 - Show all commits

View File

@ -13,7 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopDataModels", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopListImplement", "CarRepairShopListImplement\CarRepairShopListImplement.csproj", "{5EF355A9-2708-47C4-B7B1-6D1CB89CDC02}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShopFileImplement", "CarRepairShopFileImplement\CarRepairShopFileImplement.csproj", "{FD920623-E8C5-45DE-9D7F-A6C643102F9D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopFileImplement", "CarRepairShopFileImplement\CarRepairShopFileImplement.csproj", "{4966A8B7-5985-48DF-834A-3E41D2E0D01D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -41,10 +41,10 @@ Global
{5EF355A9-2708-47C4-B7B1-6D1CB89CDC02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EF355A9-2708-47C4-B7B1-6D1CB89CDC02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5EF355A9-2708-47C4-B7B1-6D1CB89CDC02}.Release|Any CPU.Build.0 = Release|Any CPU
{FD920623-E8C5-45DE-9D7F-A6C643102F9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD920623-E8C5-45DE-9D7F-A6C643102F9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD920623-E8C5-45DE-9D7F-A6C643102F9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD920623-E8C5-45DE-9D7F-A6C643102F9D}.Release|Any CPU.Build.0 = Release|Any CPU
{4966A8B7-5985-48DF-834A-3E41D2E0D01D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4966A8B7-5985-48DF-834A-3E41D2E0D01D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4966A8B7-5985-48DF-834A-3E41D2E0D01D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4966A8B7-5985-48DF-834A-3E41D2E0D01D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -4,6 +4,7 @@ using CarRepairShopContracts.SearchModels;
using CarRepairShopContracts.StoragesContracts;
using CarRepairShopContracts.ViewModels;
using CarRepairShopDataModels.Enums;
using CarRepairShopDataModels.Models;
using Microsoft.Extensions.Logging;
namespace CarRepairShopBusinessLogic.BusinessLogics
@ -14,10 +15,20 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IRepairStorage _repairStorage;
private readonly IShopStorage _shopStorage;
private readonly IShopLogic _shopLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IRepairStorage repairStorage,
IShopStorage shopStorage, IShopLogic shopLogic)
{
_logger = logger;
_orderStorage = orderStorage;
_repairStorage = repairStorage;
_shopStorage = shopStorage;
_shopLogic = shopLogic;
}
public bool CreateOrder(OrderBindingModel model)
@ -106,6 +117,20 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
newStatus, order.Status);
return false;
}
if (newStatus == OrderStatus.Выдан)
{
var repair = _repairStorage.GetElement(new RepairSearchModel() { Id = order.RepairId });
if (repair == null)
{
_logger.LogWarning("Change status operation failed. Repairs not found");
return false;
}
if (!DeliverRepairs(repair, order.Count))
{
_logger.LogWarning("Change status operation failed. Repairs delivery operation failed");
return false;
}
}
model.RepairId = order.RepairId;
model.Count = order.Count;
model.Sum = order.Sum;
@ -125,5 +150,62 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
}
return true;
}
private bool DeliverRepairs(IRepairModel repair, int count)
{
if (count <= 0)
{
_logger.LogWarning("Repairs delivery operation failed. Repair count <= 0");
return false;
}
var shopList = _shopStorage.GetFullList();
int shopsCapacity = shopList.Sum(x => x.RepairMaxAmount);
int currentRepairs = shopList.Select(x => x.ShopRepairs.Sum(y => y.Value.Item2)).Sum();
int freePlaces = shopsCapacity - currentRepairs;
if (freePlaces < count)
{
_logger.LogWarning("Repairs delivery operation failed. No space for new repairs");
return false;
}
foreach (var shop in shopList)
{
freePlaces = shop.RepairMaxAmount - shop.ShopRepairs.Sum(x => x.Value.Item2);
if (freePlaces == 0)
{
continue;
}
if (freePlaces >= count)
{
if (_shopLogic.MakeShipment(new() { Id = shop.Id }, repair, count))
{
count = 0;
}
else
{
_logger.LogWarning("Repairs delivery operation failed");
return false;
}
}
else
{
if (_shopLogic.MakeShipment(new() { Id = shop.Id }, repair, freePlaces))
{
count -= freePlaces;
}
else
{
_logger.LogWarning("Repairs delivery operation failed");
return false;
}
}
if (count == 0)
{
return true;
}
}
return false;
}
}
}

View File

@ -105,6 +105,11 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
_logger.LogWarning("MakeShipment(GetElement). Element not found");
return false;
}
if (shop.RepairMaxAmount - shop.ShopRepairs.Sum(x => x.Value.Item2) < count)
{
_logger.LogWarning("MakeShipment error. No space for new repairs");
return false;
}
if (shop.ShopRepairs.ContainsKey(repair.Id))
{
var shopIC = shop.ShopRepairs[repair.Id];
@ -125,6 +130,7 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
ShopName = shop.ShopName,
Address = shop.Address,
DateOpening = shop.DateOpening,
RepairMaxAmount = shop.RepairMaxAmount,
ShopRepairs = shop.ShopRepairs,
}) == null)
{
@ -133,6 +139,10 @@ namespace CarRepairShopBusinessLogic.BusinessLogics
}
return true;
}
public bool MakeSale(IRepairModel model, int count)
{
return _shopStorage.MakeSale(model, count);
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{

View File

@ -17,5 +17,7 @@ namespace CarRepairShopContracts.BindingModels
get;
set;
} = new();
public int RepairMaxAmount { get; set; }
}
}

View File

@ -18,5 +18,7 @@ namespace CarRepairShopContracts.BusinessLogicsContracts
bool Delete(ShopBindingModel model);
bool MakeShipment(ShopSearchModel shopModel, IRepairModel Repair, int count);
bool MakeSale(IRepairModel model, int count);
}
}

View File

@ -1,6 +1,7 @@
using CarRepairShopContracts.BindingModels;
using CarRepairShopContracts.SearchModels;
using CarRepairShopContracts.ViewModels;
using CarRepairShopDataModels.Models;
namespace CarRepairShopContracts.StoragesContracts
{
@ -17,5 +18,7 @@ namespace CarRepairShopContracts.StoragesContracts
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool MakeSale(IRepairModel model, int count);
}
}

View File

@ -21,5 +21,8 @@ namespace CarRepairShopContracts.ViewModels
get;
set;
} = new();
[DisplayName("Максимальное количество ремонтов")]
public int RepairMaxAmount { get; set; }
}
}

View File

@ -11,5 +11,7 @@ namespace CarRepairShopDataModels.Models
DateTime DateOpening { get; }
Dictionary<int, (IRepairModel, int)> ShopRepairs { get; }
int RepairMaxAmount { get; }
}
}

View File

@ -13,12 +13,16 @@ namespace CarRepairShopFileImplement
private readonly string RepairFileName = "Repair.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Repair> Repairs { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@ -34,11 +38,14 @@ namespace CarRepairShopFileImplement
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Repairs = LoadData(RepairFileName, "Repair", x => Repair.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)

View File

@ -0,0 +1,134 @@
using CarRepairShopContracts.BindingModels;
using CarRepairShopContracts.SearchModels;
using CarRepairShopContracts.StoragesContracts;
using CarRepairShopContracts.ViewModels;
using CarRepairShopFileImplement;
using CarRepairShopDataModels.Models;
using CarRepairShopFileImplement.Models;
using System.Collections.Generic;
namespace CarRepairShopFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton source;
public ShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ShopViewModel> GetFullList()
{
return source.Shops
.Select(x => x.GetViewModel)
.ToList();
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName))
{
return new();
}
return source.Shops
.Where(x => x.ShopName.Contains(model.ShopName))
.Select(x => x.GetViewModel)
.ToList();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
return source.Shops
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
source.Shops.Add(newShop);
source.SaveShops();
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop == null)
{
return null;
}
shop.Update(model);
source.SaveShops();
return shop.GetViewModel;
}
public ShopViewModel? Delete(ShopBindingModel model)
{
var element = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Shops.Remove(element);
source.SaveShops();
return element.GetViewModel;
}
return null;
}
public bool MakeSale(IRepairModel model, int count)
{
var repair = source.Repairs.FirstOrDefault(x => x.Id == model.Id);
int countInShops = source.Shops.SelectMany(x => x.ShopRepairs).Sum(y => y.Key == model.Id ? y.Value.Item2 : 0);
if (repair == null || countInShops < count)
{
return false;
}
foreach (var shop in source.Shops)
{
var shopRepairs = shop.ShopRepairs.Where(x => x.Key == model.Id);
if (shopRepairs.Any())
{
var shopRepair = shopRepairs.First();
int min = Math.Min(shopRepair.Value.Item2, count);
if (min == shopRepair.Value.Item2)
{
shop.ShopRepairs.Remove(shopRepair.Key);
}
else
{
shop.ShopRepairs[shopRepair.Key] = (shopRepair.Value.Item1, shopRepair.Value.Item2 - min);
}
shop.Update(new ShopBindingModel
{
Id = shop.Id,
ShopName = shop.ShopName,
Address = shop.Address,
DateOpening = shop.DateOpening,
ShopRepairs = shop.ShopRepairs,
RepairMaxAmount = shop.RepairMaxAmount
});
count -= min;
if (count <= 0)
{
break;
}
}
}
source.SaveShops();
return true;
}
}
}

View File

@ -0,0 +1,108 @@
using CarRepairShopContracts.BindingModels;
using CarRepairShopContracts.ViewModels;
using CarRepairShopDataModels.Models;
using System.Xml.Linq;
namespace CarRepairShopFileImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime DateOpening { get; private set; }
public Dictionary<int, int> Repairs { get; private set; } = new();
private Dictionary<int, (IRepairModel, int)>? _shopRepairs = null;
public Dictionary<int, (IRepairModel, int)> ShopRepairs
{
get
{
if (_shopRepairs == null)
{
var source = DataFileSingleton.GetInstance();
_shopRepairs = Repairs.ToDictionary(x => x.Key,
y => ((source.Repairs.FirstOrDefault(z => z.Id == y.Key) as IRepairModel)!, y.Value));
}
return _shopRepairs;
}
}
public int RepairMaxAmount { get; private set; }
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateOpening = model.DateOpening,
Repairs = model.ShopRepairs.ToDictionary(x => x.Key, x => x.Value.Item2),
RepairMaxAmount = model.RepairMaxAmount
};
}
public static Shop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Shop()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Address = element.Element("Address")!.Value,
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
RepairMaxAmount = Convert.ToInt32(element.Element("RepairMaxAmount")!.Value),
Repairs = element.Element("ShopRepairs")!.Elements("ShopRepair")
.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Address = model.Address;
DateOpening = model.DateOpening;
RepairMaxAmount = model.RepairMaxAmount;
Repairs = model.ShopRepairs.ToDictionary(x => x.Key, x => x.Value.Item2);
_shopRepairs = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
DateOpening = DateOpening,
ShopRepairs = ShopRepairs,
RepairMaxAmount = RepairMaxAmount
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Address", Address),
new XElement("DateOpening", DateOpening.ToString()),
new XElement("RepairMaxAmount", RepairMaxAmount.ToString()),
new XElement("ShopRepairs",
Repairs.Select(x => new XElement("ShopRepair",
new XElement("Key", x.Key),
new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -2,6 +2,7 @@
using CarRepairShopContracts.SearchModels;
using CarRepairShopContracts.StoragesContracts;
using CarRepairShopContracts.ViewModels;
using CarRepairShopDataModels.Models;
using CarRepairShopListImplement;
using CarRepairShopListImplement.Models;
@ -106,5 +107,10 @@ namespace CarRepairShopListImplement.Implements
}
return null;
}
public bool MakeSale(IRepairModel model, int count)
{
throw new NotImplementedException();
}
}
}

View File

@ -20,6 +20,8 @@ namespace CarRepairShopListImplement.Models
private set;
} = new Dictionary<int, (IRepairModel, int)>();
public int RepairMaxAmount { get; private set; }
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
@ -32,7 +34,8 @@ namespace CarRepairShopListImplement.Models
ShopName = model.ShopName,
Address = model.Address,
DateOpening = model.DateOpening,
ShopRepairs = model.ShopRepairs
ShopRepairs = model.ShopRepairs,
RepairMaxAmount = model.RepairMaxAmount
};
}
@ -46,6 +49,7 @@ namespace CarRepairShopListImplement.Models
Address = model.Address;
DateOpening = model.DateOpening;
ShopRepairs = model.ShopRepairs;
RepairMaxAmount = model.RepairMaxAmount;
}
public ShopViewModel GetViewModel => new()
@ -54,7 +58,8 @@ namespace CarRepairShopListImplement.Models
ShopName = ShopName,
Address = Address,
DateOpening = DateOpening,
ShopRepairs = ShopRepairs
ShopRepairs = ShopRepairs,
RepairMaxAmount = RepairMaxAmount
};
}
}

View File

@ -162,5 +162,14 @@ namespace CarRepairShopView
form.ShowDialog();
}
}
private void продажаРемонтовToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSale));
if (service is FormSale form)
{
form.ShowDialog();
}
}
}
}

View File

@ -40,6 +40,7 @@
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonRef = new System.Windows.Forms.Button();
продажаРемонтовToolStripMenuItem = new ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -48,7 +49,8 @@
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem,
пополнениеМагазинаToolStripMenuItem });
пополнениеМагазинаToolStripMenuItem,
продажаРемонтовToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2);
@ -69,21 +71,21 @@
// компонентыToolStripMenuItem
//
this.компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.компонентыToolStripMenuItem.Text = "Компоненты";
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
//
// ремонтыToolStripMenuItem
//
this.ремонтыToolStripMenuItem.Name = "ремонтыToolStripMenuItem";
this.ремонтыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.ремонтыToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.ремонтыToolStripMenuItem.Text = "Ремонты";
this.ремонтыToolStripMenuItem.Click += new System.EventHandler(this.РемонтыToolStripMenuItem_Click);
//
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(180, 22);
магазиныToolStripMenuItem.Size = new Size(145, 22);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click;
//
@ -173,6 +175,13 @@
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// продажаРемонтовToolStripMenuItem
//
продажаРемонтовToolStripMenuItem.Name = "продажаРемонтовToolStripMenuItem";
продажаРемонтовToolStripMenuItem.Size = new Size(143, 20);
продажаРемонтовToolStripMenuItem.Text = "Продажа Ремонтов";
продажаРемонтовToolStripMenuItem.Click += продажаРемонтовToolStripMenuItem_Click;
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -213,6 +222,7 @@
private System.Windows.Forms.Button buttonRef;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
private ToolStripMenuItem продажаРемонтовToolStripMenuItem;
}
}

View File

@ -0,0 +1,127 @@
namespace CarRepairShopView
{
partial class FormSale
{
/// <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()
{
buttonCancel = new Button();
buttonSale = new Button();
textBoxCount = new TextBox();
labelCount = new Label();
comboBoxRepair = new ComboBox();
labelRepair = new Label();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Location = new Point(253, 83);
buttonCancel.Margin = new Padding(4, 3, 4, 3);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(88, 27);
buttonCancel.TabIndex = 17;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonSale
//
buttonSale.Location = new Point(159, 83);
buttonSale.Margin = new Padding(4, 3, 4, 3);
buttonSale.Name = "buttonSale";
buttonSale.Size = new Size(88, 27);
buttonSale.TabIndex = 16;
buttonSale.Text = "Продать";
buttonSale.UseVisualStyleBackColor = true;
buttonSale.Click += ButtonSale_Click;
//
// textBoxCount
//
textBoxCount.Location = new Point(101, 51);
textBoxCount.Margin = new Padding(4, 3, 4, 3);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(252, 23);
textBoxCount.TabIndex = 15;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(13, 54);
labelCount.Margin = new Padding(4, 0, 4, 0);
labelCount.Name = "labelCount";
labelCount.Size = new Size(78, 15);
labelCount.TabIndex = 14;
labelCount.Text = "Количество :";
//
// comboBoxRepair
//
comboBoxRepair.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxRepair.FormattingEnabled = true;
comboBoxRepair.Location = new Point(101, 15);
comboBoxRepair.Margin = new Padding(4, 3, 4, 3);
comboBoxRepair.Name = "comboBoxRepair";
comboBoxRepair.Size = new Size(252, 23);
comboBoxRepair.TabIndex = 13;
//
// labelRepair
//
labelRepair.AutoSize = true;
labelRepair.Location = new Point(13, 19);
labelRepair.Margin = new Padding(4, 0, 4, 0);
labelRepair.Name = "labelRepair";
labelRepair.Size = new Size(80, 15);
labelRepair.TabIndex = 12;
labelRepair.Text = "Ремонт :";
//
// FormRepairSale
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(373, 123);
Controls.Add(buttonCancel);
Controls.Add(buttonSale);
Controls.Add(textBoxCount);
Controls.Add(labelCount);
Controls.Add(comboBoxRepair);
Controls.Add(labelRepair);
Name = "FormRepairSale";
StartPosition = FormStartPosition.CenterScreen;
Text = "Продажа ремонта";
Load += FormRepairSale_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSale;
private TextBox textBoxCount;
private Label labelCount;
private ComboBox comboBoxRepair;
private Label labelRepair;
}
}

View File

@ -0,0 +1,87 @@
using CarRepairShopContracts.BusinessLogicsContracts;
using CarRepairShopContracts.BindingModels;
using Microsoft.Extensions.Logging;
namespace CarRepairShopView
{
public partial class FormSale : Form
{
private readonly ILogger _logger;
private readonly IRepairLogic _logicRepair;
private readonly IShopLogic _logicShop;
public FormSale(ILogger<FormMakeShipment> logger, IRepairLogic logicRepair, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicRepair = logicRepair;
_logicShop = logicShop;
}
private void FormRepairSale_Load(object sender, EventArgs e)
{
_logger.LogInformation("Repairs loading");
try
{
var list = _logicRepair.ReadList(null);
if (list != null)
{
comboBoxRepair.DisplayMember = "RepairName";
comboBoxRepair.ValueMember = "Id";
comboBoxRepair.DataSource = list;
comboBoxRepair.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Repairs loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSale_Click(object sender, EventArgs e)
{
if (comboBoxRepair.SelectedValue == null)
{
MessageBox.Show("Выберите ремонт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Repair sale");
try
{
var operationResult = _logicShop.MakeSale(
new RepairBindingModel
{
Id = Convert.ToInt32(comboBoxRepair.SelectedValue)
},
Convert.ToInt32(textBoxCount.Text)
);
if (!operationResult)
{
throw new Exception("Ошибка при продаже.");
}
MessageBox.Show("Продажа прошла успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Repair sale error");
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,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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

@ -41,6 +41,8 @@
ColumnCount = new DataGridViewTextBoxColumn();
buttonSave = new Button();
buttonCancel = new Button();
textBoxMaximum = new TextBox();
labelMaximum = new Label();
groupBoxRepairs.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -101,7 +103,7 @@
// groupBoxRepairs
//
groupBoxRepairs.Controls.Add(dataGridView);
groupBoxRepairs.Location = new Point(4, 100);
groupBoxRepairs.Location = new Point(5, 138);
groupBoxRepairs.Margin = new Padding(4, 3, 4, 3);
groupBoxRepairs.Name = "groupBoxRepairs";
groupBoxRepairs.Padding = new Padding(4, 3, 4, 3);
@ -150,7 +152,7 @@
//
// buttonSave
//
buttonSave.Location = new Point(255, 394);
buttonSave.Location = new Point(256, 434);
buttonSave.Margin = new Padding(4, 3, 4, 3);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(88, 27);
@ -161,7 +163,7 @@
//
// buttonCancel
//
buttonCancel.Location = new Point(359, 394);
buttonCancel.Location = new Point(360, 434);
buttonCancel.Margin = new Padding(4, 3, 4, 3);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(88, 27);
@ -170,11 +172,31 @@
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// textBoxMaximum
//
textBoxMaximum.Location = new Point(169, 97);
textBoxMaximum.Margin = new Padding(4, 3, 4, 3);
textBoxMaximum.Name = "textBoxMaximum";
textBoxMaximum.Size = new Size(175, 23);
textBoxMaximum.TabIndex = 11;
//
// labelMaximum
//
labelMaximum.AutoSize = true;
labelMaximum.Location = new Point(14, 100);
labelMaximum.Margin = new Padding(4, 0, 4, 0);
labelMaximum.Name = "labelMaximum";
labelMaximum.Size = new Size(147, 15);
labelMaximum.TabIndex = 10;
labelMaximum.Text = "Максимум ремонта :";
//
// FormShop
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(478, 432);
ClientSize = new Size(478, 468);
Controls.Add(textBoxMaximum);
Controls.Add(labelMaximum);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(groupBoxRepairs);
@ -209,5 +231,7 @@
private DataGridViewTextBoxColumn ColumnCount;
private Button buttonSave;
private Button buttonCancel;
private TextBox textBoxMaximum;
private Label labelMaximum;
}
}

View File

@ -38,6 +38,7 @@ namespace CarRepairShopView
{
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address;
textBoxMaximum.Text = view.RepairMaxAmount.ToString();
dateTimePicker.Value = view.DateOpening;
_shopRepairs = view.ShopRepairs ?? new Dictionary<int, (IRepairModel, int)>();
LoadData();
@ -89,6 +90,11 @@ namespace CarRepairShopView
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxMaximum.Text))
{
MessageBox.Show("Заполните максимальное количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Shop saving");
try
{
@ -98,6 +104,7 @@ namespace CarRepairShopView
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpening = dateTimePicker.Value,
RepairMaxAmount = Convert.ToInt32(textBoxMaximum.Text),
ShopRepairs = _shopRepairs
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);

View File

@ -54,6 +54,7 @@ namespace CarRepairShopView
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormMakeShipment>();
services.AddTransient<FormSale>();
}
}
}