diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs index 035854b..5dec33e 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs index 6daff3e..ed629e3 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs @@ -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, diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs index b40d4ad..bc2fc77 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs @@ -12,10 +12,14 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IReinforcedStorage _reinforcedStorage; + private readonly IShopLogic _shopLogic; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IReinforcedStorage reinforcedStorage, IShopLogic shopLogic) { _logger = logger; _orderStorage = orderStorage; + _reinforcedStorage = reinforcedStorage; + _shopLogic = shopLogic; } public bool CreateOrder(OrderBindingModel model) diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs index 3f9f982..7ddddc4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -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 Reinforceds diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs index 060b96a..c493ea3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs @@ -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); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs index 49cc4c2..3ecfc28 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -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; diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs index 7522011..5e252ae 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs @@ -6,6 +6,7 @@ namespace PrecastConcretePlantDataModels { string Name { get; } string Address { get; } + int MaxCountReinforceds { get; } DateTime DateOpening { get; } Dictionary Reinforceds { get; } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs new file mode 100644 index 0000000..ce969c9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs @@ -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 CountReinforceds { get; private set; } = new(); + + private Dictionary? _cachedReinforceds = null; + public Dictionary 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)) + )) + ); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs index af859f5..a10b774 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs @@ -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();