Putilin P. A. Lab work 2 Hard #11

Closed
Pavel wants to merge 15 commits from Lab2Hard into Lab1Hard
9 changed files with 159 additions and 6 deletions
Showing only changes of commit a4f141b711 - Show all commits

View File

@ -40,7 +40,10 @@
this.comboBoxShop = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.dateTimePickerOpening = new System.Windows.Forms.DateTimePicker();
this.label4 = new System.Windows.Forms.Label();
this.numericUpDownMaxReinforced = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxReinforced)).BeginInit();
this.SuspendLayout();
//
// buttonSave
@ -145,11 +148,29 @@
this.dateTimePickerOpening.Size = new System.Drawing.Size(200, 23);
this.dateTimePickerOpening.TabIndex = 18;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(606, 10);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(115, 15);
this.label4.TabIndex = 19;
this.label4.Text = "Максимум изделий";
//
// numericUpDownMaxReinforced
//
this.numericUpDownMaxReinforced.Location = new System.Drawing.Point(606, 26);
this.numericUpDownMaxReinforced.Name = "numericUpDownMaxReinforced";
this.numericUpDownMaxReinforced.Size = new System.Drawing.Size(120, 23);
this.numericUpDownMaxReinforced.TabIndex = 20;
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(737, 319);
this.Controls.Add(this.numericUpDownMaxReinforced);
this.Controls.Add(this.label4);
this.Controls.Add(this.dateTimePickerOpening);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.buttonCancel);
@ -163,6 +184,7 @@
this.Text = "Изделия магазина";
this.Load += new System.EventHandler(this.FormShop_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxReinforced)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -182,5 +204,7 @@
private TextBox comboBoxShop;
private Label label1;
private DateTimePicker dateTimePickerOpening;
private Label label4;
private NumericUpDown numericUpDownMaxReinforced;
}
}

View File

@ -48,6 +48,7 @@ namespace PrecastConcretePlantView
var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.Text));
if (model != null)
{
numericUpDownMaxReinforced.Value = model.MaxCountReinforceds;
comboBoxShop.Text = model.Name;
textBoxAddress.Text = model.Address;
dateTimePickerOpening.Value = model.DateOpening;
@ -91,6 +92,7 @@ namespace PrecastConcretePlantView
{
ShopBindingModel model = new()
{
MaxCountReinforceds = (int)numericUpDownMaxReinforced.Value,
Name = comboBoxShop.Text,
Address = textBoxAddress.Text,
DateOpening = dateTimePickerOpening.Value,

View File

@ -12,10 +12,14 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IReinforcedStorage _reinforcedStorage;
private readonly IShopLogic _shopLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IReinforcedStorage reinforcedStorage, IShopLogic shopLogic)
{
_logger = logger;
_orderStorage = orderStorage;
_reinforcedStorage = reinforcedStorage;
_shopLogic = shopLogic;
}
public bool CreateOrder(OrderBindingModel model)

View File

@ -9,6 +9,8 @@ namespace PrecastConcretePlantContracts.BindingModels
public string Address { get; set; } = string.Empty;
public int MaxCountReinforceds { get; set; }
public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary<int, (IReinforcedModel, int)> Reinforceds

View File

@ -13,5 +13,7 @@ namespace PrecastConcretePlantContracts.StoragesContract
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool HasNeedReinforceds(IReinforcedModel reinforced, int needCount);
public bool SellReinforceds(IReinforcedModel reinforced, int needCount);
}
}

View File

@ -13,6 +13,9 @@ namespace PrecastConcretePlantContracts.ViewModels
[DisplayName("Адрес магазина")]
public string Address { get; set; } = string.Empty;
[DisplayName("Максимальное количество изделий в магазине")]
public int MaxCountReinforceds { get; set; }
[DisplayName("Время открытия")]
public DateTime DateOpening { get; set; } = DateTime.Now;

View File

@ -6,6 +6,7 @@ namespace PrecastConcretePlantDataModels
{
string Name { get; }
string Address { get; }
int MaxCountReinforceds { get; }
DateTime DateOpening { get; }
Dictionary<int, (IReinforcedModel, int)> Reinforceds { get; }
}

View File

@ -0,0 +1,109 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels;
using PrecastConcretePlantDataModels.Models;
using System.Xml.Linq;
namespace PrecastConcretePlantFileImplement
{
public class Shop : IShopModel
{
public string Name { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public int MaxCountReinforceds { get; private set; }
public DateTime DateOpening { get; private set; }
public Dictionary<int, int> CountReinforceds { get; private set; } = new();
private Dictionary<int, (IReinforcedModel, int)>? _cachedReinforceds = null;
public Dictionary<int, (IReinforcedModel, int)> Reinforceds
{
get
{
if (_cachedReinforceds == null)
{
var source = DataFileSingleton.GetInstance();
_cachedReinforceds = CountReinforceds
.ToDictionary(x => x.Key, x => (source.Reinforceds
.FirstOrDefault(y => y.Id == x.Key)! as IReinforcedModel, x.Value));
}
return _cachedReinforceds;
}
}
public int Id { get; private set; }
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
Name = model.Name,
Address = model.Address,
DateOpening = model.DateOpening,
MaxCountReinforceds = model.MaxCountReinforceds,
CountReinforceds = new()
};
}
public static Shop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
Name = element.Element("Name")!.Value,
Address = element.Element("Address")!.Value,
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
MaxCountReinforceds = Convert.ToInt32(element.Element("MaxCountReinforceds")!.Value),
CountReinforceds = element.Element("CountReinforceds")!.Elements("CountReinforced")
.ToDictionary(
x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value)
)
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
Address = model.Address;
DateOpening = model.DateOpening;
CountReinforceds = model.Reinforceds.ToDictionary(x => x.Key, x => x.Value.Item2);
_cachedReinforceds = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Address = Address,
Reinforceds = Reinforceds,
DateOpening = DateOpening,
MaxCountReinforceds = MaxCountReinforceds,
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("Name", Name),
new XElement("Address", Address),
new XElement("DateOpening", DateOpening),
new XElement("MaxCountReinforceds", MaxCountReinforceds),
new XElement("CountReinforceds", CountReinforceds
.Select(x => new XElement("CountReinforced",
new XElement("Key", x.Key),
new XElement("Value", x.Value))
))
);
}
}

View File

@ -2,11 +2,7 @@
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContract;
using PrecastConcretePlantContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PrecastConcretePlantDataModels.Models;
namespace PrecastConcretePlantFileImplement
{
@ -32,11 +28,21 @@ namespace PrecastConcretePlantFileImplement
throw new NotImplementedException();
}
public bool HasNeedReinforceds(IReinforcedModel reinforced, int needCount)
{
throw new NotImplementedException();
}
public ShopViewModel? Insert(ShopBindingModel model)
{
throw new NotImplementedException();
}
public bool SellReinforceds(IReinforcedModel reinforced, int needCount)
{
throw new NotImplementedException();
}
public ShopViewModel? Update(ShopBindingModel model)
{
throw new NotImplementedException();