diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs index 90aeb50..13f1e1b 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs @@ -9,6 +9,8 @@ namespace BlackcmithWorkshopFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string ManufactureFileName = "Manufacture.xml"; + private readonly string ShopFileName = "Shops.xml"; + public List Shops { get; private set; } private readonly string ClientFileName = "Client.xml"; public List Components { get; private set; } public List Orders { get; private set; } @@ -28,6 +30,8 @@ namespace BlackcmithWorkshopFileImplement "Manufactures", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, + "Shops", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); private DataFileSingleton() @@ -38,6 +42,8 @@ namespace BlackcmithWorkshopFileImplement Manufacture.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => + Shop.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; } diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ShopStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..a2e1546 --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,129 @@ +using BlackcmithWorkshopFileImplement; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton _source; + public ShopStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return _source.Shops + .Select(x => x.GetViewModel) + .ToList(); + } + public List 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 component = _source.Shops.FirstOrDefault(x => x.Id == + model.Id); + if (component == null) + { + return null; + } + component.Update(model); + _source.SaveShops(); + return component.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; + } + private bool CheckSell(int ManufactureId, int count) + { + count -= _source.Shops.Select(x => x.ShopManufactures.Select(y => + (y.Value.Item1.Id == ManufactureId ? y.Value.Item2 : 0)).Sum()).Sum(); + return count <= 0; + } + public bool SellManufactures(IManufactureModel model, int count) + { + var neededManufacture = _source.Manufactures.FirstOrDefault(x => x.Id == model.Id); + if (neededManufacture == null || !CheckSell(neededManufacture.Id, count)) + { + return false; + } + for (int i = 0; i < _source.Shops.Count; i++) + { + var shop = _source.Shops[i]; + var assortment = shop.ShopManufactures; + foreach (var manufacture in assortment.Where(x => x.Value.Item1.Id == neededManufacture.Id)) + { + var min = Math.Min(manufacture.Value.Item2, count); + assortment[manufacture.Value.Item1.Id] = (manufacture.Value.Item1, manufacture.Value.Item2 - min); + count -= min; + if (count <= 0) + { + break; + } + } + shop.Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + OpeningDate = shop.OpeningDate, + MaxCapacity = shop.MaxCapacity, + ShopManufactures = assortment + }); + } + _source.SaveShops(); + return true; + } + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Shop.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Shop.cs new file mode 100644 index 0000000..974e93b --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Shop.cs @@ -0,0 +1,107 @@ +using BlackcmithWorkshopFileImplement; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.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 OpeningDate { get; private set; } + public int MaxCapacity { get; private set; } + public Dictionary Manufactures { get; private set; } = new(); + private Dictionary? _shopManufactures = null; + public Dictionary ShopManufactures + { + get + { + if (_shopManufactures == null) + { + var source = DataFileSingleton.GetInstance(); + _shopManufactures = Manufactures.ToDictionary(x => x.Key, y => + ((source.Manufactures.FirstOrDefault(z => z.Id == y.Key) as IManufactureModel)!, + y.Value)); + } + return _shopManufactures; + } + } + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + return null; + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + OpeningDate = model.OpeningDate, + MaxCapacity = model.MaxCapacity, + Manufactures = model.ShopManufactures.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + 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, + MaxCapacity = Convert.ToInt32(element.Element("MaxCapacity")!.Value), + OpeningDate = Convert.ToDateTime(element.Element("DateOpen")!.Value), + Manufactures = element.Element("ShopManufactures")!.Elements("ShopManufacture") + .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; + OpeningDate = model.OpeningDate; + MaxCapacity = model.MaxCapacity; + if (model.ShopManufactures.Count > 0) + { + Manufactures = model.ShopManufactures.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopManufactures = null; + } + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + OpeningDate = OpeningDate, + MaxCapacity = MaxCapacity, + ShopManufactures = ShopManufactures + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpen", OpeningDate), + new XElement("MaxCapacity", MaxCapacity), + new XElement("ShopManufactures", Manufactures + .Select(x => new XElement("ShopManufacture", + new XElement("Key", x.Key), + new XElement("Value", x.Value)) + ).ToArray())); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index 20f9c10..7b043ed 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -30,4 +30,10 @@ + + + Never + + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index b31a161..1aa1218 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -32,6 +32,9 @@ GuidesToolStripMenuItem = new ToolStripMenuItem(); ComponentsToolStripMenuItem = new ToolStripMenuItem(); ManufacturesToolStripMenuItem = new ToolStripMenuItem(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + SupplyToolStripMenuItem = new ToolStripMenuItem(); + SalesToolStripMenuItem = new ToolStripMenuItem(); ReportsToolStripMenuItem = new ToolStripMenuItem(); ManufacturesListToolStripMenuItem = new ToolStripMenuItem(); ManufacturesComponentsListToolStripMenuItem = new ToolStripMenuItem(); @@ -42,6 +45,9 @@ buttonIssued = new Button(); buttonReady = new Button(); buttonTakeInWork = new Button(); + DatesOrdersListToolStripMenuItem = new ToolStripMenuItem(); + ShopsListToolStripMenuItem = new ToolStripMenuItem(); + ShopsManufacturesListToolStripMenuItem = new ToolStripMenuItem(); ClientsToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); @@ -58,6 +64,7 @@ // // GuidesToolStripMenuItem // + GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ShopsToolStripMenuItem, SupplyToolStripMenuItem, SalesToolStripMenuItem }); GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ClientsToolStripMenuItem}); GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; GuidesToolStripMenuItem.Size = new Size(94, 20); @@ -77,8 +84,30 @@ ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(198, 22); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // SupplyToolStripMenuItem + // + SupplyToolStripMenuItem.Name = "SupplyToolStripMenuItem"; + SupplyToolStripMenuItem.Size = new Size(198, 22); + SupplyToolStripMenuItem.Text = "Пополнение магазина"; + SupplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // + // SalesToolStripMenuItem + // + SalesToolStripMenuItem.Name = "SalesToolStripMenuItem"; + SalesToolStripMenuItem.Size = new Size(198, 22); + SalesToolStripMenuItem.Text = "Продажи"; + SalesToolStripMenuItem.Click += SalesToolStripMenuItem_Click; + // // ReportsToolStripMenuItem // + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem, DatesOrdersListToolStripMenuItem, ShopsListToolStripMenuItem, ShopsManufacturesListToolStripMenuItem }); ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem}); ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; ReportsToolStripMenuItem.Size = new Size(60, 20); @@ -164,6 +193,27 @@ buttonTakeInWork.UseVisualStyleBackColor = true; buttonTakeInWork.Click += TakeInWorkButton_Click; // + // DatesOrdersListToolStripMenuItem + // + DatesOrdersListToolStripMenuItem.Name = "DatesOrdersListToolStripMenuItem"; + DatesOrdersListToolStripMenuItem.Size = new Size(225, 22); + DatesOrdersListToolStripMenuItem.Text = "Заказы по датам"; + DatesOrdersListToolStripMenuItem.Click += DatesOrdersListToolStripMenuItem_Click; + // + // ShopsListToolStripMenuItem + // + ShopsListToolStripMenuItem.Name = "ShopsListToolStripMenuItem"; + ShopsListToolStripMenuItem.Size = new Size(225, 22); + ShopsListToolStripMenuItem.Text = "Магазины"; + ShopsListToolStripMenuItem.Click += ShopsListToolStripMenuItem_Click; + // + // ShopsManufacturesListToolStripMenuItem + // + ShopsManufacturesListToolStripMenuItem.Name = "ShopsManufacturesListToolStripMenuItem"; + ShopsManufacturesListToolStripMenuItem.Size = new Size(225, 22); + ShopsManufacturesListToolStripMenuItem.Text = "Изделия по магазинам"; + ShopsManufacturesListToolStripMenuItem.Click += ShopsManufacturesListToolStripMenuItem_Click; + // // ClientsToolStripMenuItem // ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; @@ -207,10 +257,16 @@ private Button buttonIssued; private Button buttonReady; private Button buttonTakeInWork; + private ToolStripMenuItem ShopsToolStripMenuItem; + private ToolStripMenuItem SupplyToolStripMenuItem; + private ToolStripMenuItem SalesToolStripMenuItem; private ToolStripMenuItem ReportsToolStripMenuItem; private ToolStripMenuItem ManufacturesListToolStripMenuItem; private ToolStripMenuItem ManufacturesComponentsListToolStripMenuItem; private ToolStripMenuItem OrdersListToolStripMenuItem; + private ToolStripMenuItem DatesOrdersListToolStripMenuItem; + private ToolStripMenuItem ShopsListToolStripMenuItem; + private ToolStripMenuItem ShopsManufacturesListToolStripMenuItem; private ToolStripMenuItem ClientsToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index de700cd..904eb26 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -167,6 +167,30 @@ namespace BlacksmithWorkshop { LoadData(); } + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } + private void SalesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSell)); + if (service is FormSell form) + { + form.ShowDialog(); + } + } private void ManufacturesListToolStripMenuItem_Click(object sender, EventArgs e) { using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; @@ -196,6 +220,35 @@ namespace BlacksmithWorkshop form.ShowDialog(); } } + private void DatesOrdersListToolStripMenuItem_Click(object sender, EventArgs e) + { + var service =Program.ServiceProvider?.GetService(typeof(ReportDatesOrdersForm)); + if (service is ReportDatesOrdersForm form) + { + form.ShowDialog(); + } + } + private void ShopsListToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + private void ShopsManufacturesListToolStripMenuItem_Click(object sender, EventArgs e) + { + var service =Program.ServiceProvider?.GetService(typeof(ReportShopsManufacturesForm)); + if (service is ReportShopsManufacturesForm form) + { + form.ShowDialog(); + } + } private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(ClientsForm)); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSell.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSell.Designer.cs new file mode 100644 index 0000000..bbf1c11 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSell.Designer.cs @@ -0,0 +1,120 @@ +namespace BlacksmithWorkshop +{ + partial class FormSell + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + ManufactureComboBox = new ComboBox(); + ManufactureLabel = new Label(); + CountLabel = new Label(); + CountTextBox = new TextBox(); + ButtonSave = new Button(); + ButtonCancel = new Button(); + SuspendLayout(); + // + // ManufactureComboBox + // + ManufactureComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ManufactureComboBox.FormattingEnabled = true; + ManufactureComboBox.Location = new Point(99, 12); + ManufactureComboBox.Name = "ManufactureComboBox"; + ManufactureComboBox.Size = new Size(121, 23); + ManufactureComboBox.TabIndex = 0; + // + // ManufactureLabel + // + ManufactureLabel.AutoSize = true; + ManufactureLabel.Location = new Point(12, 20); + ManufactureLabel.Name = "ManufactureLabel"; + ManufactureLabel.Size = new Size(53, 15); + ManufactureLabel.TabIndex = 1; + ManufactureLabel.Text = "Изделие"; + // + // CountLabel + // + CountLabel.AutoSize = true; + CountLabel.Location = new Point(21, 49); + CountLabel.Name = "CountLabel"; + CountLabel.Size = new Size(72, 15); + CountLabel.TabIndex = 2; + CountLabel.Text = "Количество"; + // + // CountTextBox + // + CountTextBox.Location = new Point(99, 41); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(121, 23); + CountTextBox.TabIndex = 3; + // + // ButtonSave + // + ButtonSave.Location = new Point(64, 73); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(75, 23); + ButtonSave.TabIndex = 4; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(145, 73); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(75, 23); + ButtonCancel.TabIndex = 5; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // FormSell + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(224, 108); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(CountTextBox); + Controls.Add(CountLabel); + Controls.Add(ManufactureLabel); + Controls.Add(ManufactureComboBox); + Name = "FormSell"; + StartPosition = FormStartPosition.CenterParent; + Text = "Форма продажи"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox ManufactureComboBox; + private Label ManufactureLabel; + private Label CountLabel; + private TextBox CountTextBox; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSell.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSell.cs new file mode 100644 index 0000000..b5ffaa3 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSell.cs @@ -0,0 +1,113 @@ +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.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 BlacksmithWorkshop +{ + public partial class FormSell : Form + { + private readonly List? _manufactureList; + IShopLogic _shopLogic; + IManufactureLogic _manufactureLogic; + public FormSell(IManufactureLogic manufactureLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _manufactureLogic = manufactureLogic; + _manufactureList = manufactureLogic.ReadList(null); + if (_manufactureList != null) + { + ManufactureComboBox.DisplayMember = "ManufactureName"; + ManufactureComboBox.ValueMember = "Id"; + ManufactureComboBox.DataSource = _manufactureList; + ManufactureComboBox.SelectedItem = null; + } + } + public int ManufactureId + { + get + { + return Convert.ToInt32(ManufactureComboBox.SelectedValue); + } + set + { + ManufactureComboBox.SelectedValue = value; + } + } + public IManufactureModel? ManufactureModel + { + get + { + if (_manufactureList == null) + { + return null; + } + foreach (var elem in _manufactureList) + { + if (elem.Id == ManufactureId) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set + { CountTextBox.Text = value.ToString(); } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ManufactureComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите кузнечное изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + int count = Convert.ToInt32(CountTextBox.Text); + var manufacture = _manufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }); + if (manufacture == null) + { + throw new ApplicationException("Ошибка при продаже. Ошибка получения данных об элементе."); + } + if (!_shopLogic.SellManufactures(manufacture, count)) + { + throw new ApplicationException("Ошибка при продаже. Недостаточно изделий данного типа в магазинах."); + } + MessageBox.Show("Продажа прошла успешно"); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception) + { + MessageBox.Show("Ошибка при продаже."); + return; + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSell.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormSell.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSell.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs new file mode 100644 index 0000000..3b7011a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs @@ -0,0 +1,211 @@ +namespace BlacksmithWorkshop +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnPrice = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + dateTimePicker = new DateTimePicker(); + labelName = new Label(); + labelAddress = new Label(); + labelDate = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + CapacityUpDown = new NumericUpDown(); + CapacityLabel = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)CapacityUpDown).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnPrice, ColumnCount }); + dataGridView.Location = new Point(12, 128); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(553, 254); + dataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = ""; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Изделие"; + ColumnName.Name = "ColumnName"; + // + // ColumnPrice + // + ColumnPrice.HeaderText = "Цена"; + ColumnPrice.Name = "ColumnPrice"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(150, 63); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(166, 23); + dateTimePicker.TabIndex = 1; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 2; + labelName.Text = "Название:"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(12, 38); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(43, 15); + labelAddress.TabIndex = 3; + labelAddress.Text = "Адрес:"; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(12, 69); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(90, 15); + labelDate.TabIndex = 4; + labelDate.Text = "Дата открытия:"; + // + // textBoxName + // + textBoxName.Location = new Point(150, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(166, 23); + textBoxName.TabIndex = 5; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(150, 35); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(166, 23); + textBoxAddress.TabIndex = 6; + // + // buttonSave + // + buttonSave.Location = new Point(12, 401); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(123, 25); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += SaveButton_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(150, 401); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(123, 25); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += CancelButton_Click; + // + // CapacityUpDown + // + CapacityUpDown.Location = new Point(150, 92); + CapacityUpDown.Maximum = new decimal(new int[] { 10000, 0, 0, 0 }); + CapacityUpDown.Name = "CapacityUpDown"; + CapacityUpDown.Size = new Size(166, 23); + CapacityUpDown.TabIndex = 9; + // + // CapacityLabel + // + CapacityLabel.AutoSize = true; + CapacityLabel.Location = new Point(12, 94); + CapacityLabel.Name = "CapacityLabel"; + CapacityLabel.Size = new Size(80, 15); + CapacityLabel.TabIndex = 10; + CapacityLabel.Text = "Вместимость"; + // + // FormShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(585, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelDate); + Controls.Add(labelAddress); + Controls.Add(labelName); + Controls.Add(dateTimePicker); + Controls.Add(dataGridView); + Controls.Add(CapacityLabel); + Controls.Add(CapacityUpDown); + Name = "FormShop"; + StartPosition = FormStartPosition.CenterParent; + Text = "Магазин"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)CapacityUpDown).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DataGridView dataGridView; + private DateTimePicker dateTimePicker; + private Label labelName; + private Label labelAddress; + private Label labelDate; + private TextBox textBoxName; + private TextBox textBoxAddress; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnPrice; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonSave; + private Button buttonCancel; + private NumericUpDown CapacityUpDown; + private Label CapacityLabel; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs new file mode 100644 index 0000000..bc29ad2 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs @@ -0,0 +1,123 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.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 BlacksmithWorkshop +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _manufactures; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _manufactures = new(); + } + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); + if (shop != null) + { + textBoxName.Text = shop.ShopName; + textBoxAddress.Text = shop.Address; + dateTimePicker.Text = shop.OpeningDate.ToString(); + _manufactures = shop.ShopManufactures ?? new Dictionary(); + CapacityUpDown.Value = shop.MaxCapacity; + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка товаров магазина"); + try + { + if (_manufactures != null) + { + foreach (var manufactures in _manufactures) + { + dataGridView.Rows.Add(new object[] { manufactures.Key, manufactures.Value.Item1.ManufactureName, + manufactures.Value.Item1.Price, manufactures.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + OpeningDate = dateTimePicker.Value.Date, + MaxCapacity = Convert.ToInt32(CapacityUpDown.Value) + }; + 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); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx new file mode 100644 index 0000000..b0c7c5d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs new file mode 100644 index 0000000..7755f6d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs @@ -0,0 +1,114 @@ +namespace BlacksmithWorkshop +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(567, 450); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(617, 22); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(152, 33); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Создать"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += AddButton_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(617, 61); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(152, 33); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += UpdateButton_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(617, 100); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(152, 33); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += DeleteButton_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(617, 139); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(152, 33); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += RefreshButton_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + StartPosition = FormStartPosition.CenterParent; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs new file mode 100644 index 0000000..e9fcb99 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs @@ -0,0 +1,110 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.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 BlacksmithWorkshop +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + 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["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["OpeningDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopManufactures"].Visible = false; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form._id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void RefreshButton_Click(object sender, EventArgs e) + { + 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 ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs new file mode 100644 index 0000000..5e2f0fd --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs @@ -0,0 +1,108 @@ +namespace BlacksmithWorkshop +{ + partial class FormSupply + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + ShopComboBox = new ComboBox(); + ManufactureComboBox = new ComboBox(); + CountTextBox = new TextBox(); + buttonSave = new Button(); + buttonCansel = new Button(); + SuspendLayout(); + // + // ShopComboBox + // + ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ShopComboBox.FormattingEnabled = true; + ShopComboBox.Location = new Point(12, 12); + ShopComboBox.Name = "ShopComboBox"; + ShopComboBox.Size = new Size(224, 23); + ShopComboBox.TabIndex = 0; + // + // ManufactureComboBox + // + ManufactureComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ManufactureComboBox.FormattingEnabled = true; + ManufactureComboBox.Location = new Point(242, 12); + ManufactureComboBox.Name = "ManufactureComboBox"; + ManufactureComboBox.Size = new Size(224, 23); + ManufactureComboBox.TabIndex = 1; + // + // CountTextBox + // + CountTextBox.Location = new Point(472, 12); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(224, 23); + CountTextBox.TabIndex = 2; + // + // buttonSave + // + buttonSave.Location = new Point(162, 47); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(157, 28); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += SaveButton_Click; + // + // buttonCansel + // + buttonCansel.Location = new Point(394, 47); + buttonCansel.Name = "buttonCansel"; + buttonCansel.Size = new Size(157, 28); + buttonCansel.TabIndex = 4; + buttonCansel.Text = "Отмена"; + buttonCansel.UseVisualStyleBackColor = true; + buttonCansel.Click += CancelButton_Click; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(707, 87); + Controls.Add(buttonCansel); + Controls.Add(buttonSave); + Controls.Add(CountTextBox); + Controls.Add(ManufactureComboBox); + Controls.Add(ShopComboBox); + Name = "FormSupply"; + StartPosition = FormStartPosition.CenterParent; + Text = "Пополнение магазина"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox ShopComboBox; + private ComboBox ManufactureComboBox; + private TextBox CountTextBox; + private Button buttonSave; + private Button buttonCansel; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs new file mode 100644 index 0000000..9742c1e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs @@ -0,0 +1,139 @@ +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +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 BlacksmithWorkshop +{ + public partial class FormSupply : Form + { + private readonly List? _manufactureList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IManufactureLogic _manufactureLogic; + public int ShopId + { + get + { + return Convert.ToInt32(ShopComboBox.SelectedValue); + } + set + { + ShopComboBox.SelectedValue = value; + } + } + public int ManufactureId + { + get + { + return Convert.ToInt32(ManufactureComboBox.SelectedValue); + } + set + { + ManufactureComboBox.SelectedValue = value; + } + } + public IManufactureModel? ManufactureModel + { + get + { + if (_manufactureList == null) + { + return null; + } + foreach (var elem in _manufactureList) + { + if (elem.Id == ManufactureId) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set { CountTextBox.Text = value.ToString(); } + } + public FormSupply(IManufactureLogic ManufactureLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _manufactureLogic = ManufactureLogic; + _manufactureList = ManufactureLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_manufactureList != null) + { + ManufactureComboBox.DisplayMember = "ManufactureName"; + ManufactureComboBox.ValueMember = "Id"; + ManufactureComboBox.DataSource = _manufactureList; + ManufactureComboBox.SelectedItem = null; + } + if (_shopsList != null) + { + ShopComboBox.DisplayMember = "ShopName"; + ShopComboBox.ValueMember = "Id"; + ShopComboBox.DataSource = _shopsList; + ShopComboBox.SelectedItem = null; + } + } + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ManufactureComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите кузнечное изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ShopComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + int count = Convert.ToInt32(CountTextBox.Text); + bool res = _shopLogic.ReplenishManufactures( + new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, + _manufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }), + count + ); + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index f80fc7f..17cd428 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -46,6 +46,8 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -55,8 +57,14 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ReportDatesOrdersForm.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ReportDatesOrdersForm.Designer.cs new file mode 100644 index 0000000..f2b027a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ReportDatesOrdersForm.Designer.cs @@ -0,0 +1,86 @@ +namespace BlacksmithWorkshop +{ + partial class ReportDatesOrdersForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel = new Panel(); + MakeButton = new Button(); + ToPdfButton = new Button(); + SuspendLayout(); + // + // panel + // + panel.Location = new Point(10, 37); + panel.Margin = new Padding(3, 2, 3, 2); + panel.Name = "panel"; + panel.Size = new Size(679, 291); + panel.TabIndex = 0; + // + // MakeButton + // + MakeButton.Location = new Point(12, 11); + MakeButton.Margin = new Padding(3, 2, 3, 2); + MakeButton.Name = "MakeButton"; + MakeButton.Size = new Size(115, 22); + MakeButton.TabIndex = 1; + MakeButton.Text = "Сформировать"; + MakeButton.UseVisualStyleBackColor = true; + MakeButton.Click += MakeButton_Click; + // + // ToPdfButton + // + ToPdfButton.Location = new Point(133, 11); + ToPdfButton.Margin = new Padding(3, 2, 3, 2); + ToPdfButton.Name = "ToPdfButton"; + ToPdfButton.Size = new Size(124, 22); + ToPdfButton.TabIndex = 2; + ToPdfButton.Text = "Сохранить в PDF"; + ToPdfButton.UseVisualStyleBackColor = true; + ToPdfButton.Click += ToPdfButton_Click; + // + // ReportDatesOrdersForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(700, 344); + Controls.Add(ToPdfButton); + Controls.Add(MakeButton); + Controls.Add(panel); + Margin = new Padding(3, 2, 3, 2); + Name = "ReportDatesOrdersForm"; + Text = "Заказы по датам"; + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button MakeButton; + private Button ToPdfButton; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ReportDatesOrdersForm.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ReportDatesOrdersForm.cs new file mode 100644 index 0000000..334d317 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ReportDatesOrdersForm.cs @@ -0,0 +1,77 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +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 BlacksmithWorkshop +{ + public partial class ReportDatesOrdersForm : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + public ReportDatesOrdersForm(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrdersByDate.rdlc", FileMode.Open)); + panel.Controls.Add(reportViewer); + } + + private void MakeButton_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetDatesOrders(); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на весь период по датам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ToPdfButton_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveDatesOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Сохранение списка заказов на весь период по датам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ReportDatesOrdersForm.resx b/BlacksmithWorkshop/BlacksmithWorkshop/ReportDatesOrdersForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ReportDatesOrdersForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ReportOrdersByDate.rdlc b/BlacksmithWorkshop/BlacksmithWorkshop/ReportOrdersByDate.rdlc new file mode 100644 index 0000000..58dc07c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ReportOrdersByDate.rdlc @@ -0,0 +1,401 @@ + + + + + + true + true + + + + + Заказы по датам + + + + + + + 0.24cm + 1cm + 21cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 3cm + + + 4.905cm + + + 7cm + + + + + 0.6cm + + + + + true + true + + + + + Дата + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Количество заказов + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма по заказам + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!DateOfOrders.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Count.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 2.72391cm + 0.55245cm + 1.2cm + 14.905cm + 1 + + + + + + true + true + + + + + Итого: + + + + + + + 4.24cm + 8.55245cm + 0.6cm + 2.5cm + 2 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + 4.24cm + 11.05245cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + 2in +