diff --git a/AbstractShopBusinessLogic/BusinessLogics/ShopLogic.cs b/AbstractShopBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..6f35a4c --- /dev/null +++ b/AbstractShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,161 @@ +using Microsoft.Extensions.Logging; +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContracts; +using DinerContracts.SearchModels; +using DinerContracts.StoragesContracts; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DinerListImplement.Implements; + +namespace DinerBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + private readonly ISnackStorage _snackStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage, ISnackStorage snackStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _snackStorage = snackStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool MakeSupply(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0"); + } + var shop = _shopStorage.GetElement(new ShopSearchModel + { + Id = model.ShopId + }); + if (shop == null) + { + throw new ArgumentException("Магазина не существует"); + } + if (shop.ShopSnacks.ContainsKey(model.SnackId)) + { + var oldValue = shop.ShopSnacks[model.SnackId]; + oldValue.Item2 += model.Count; + shop.ShopSnacks[model.SnackId] = oldValue; + } + else + { + var snack = _snackStorage.GetElement(new SnackSearchModel + { + Id = model.SnackId + }); + if (snack == null) + { + throw new ArgumentException($"Поставка: Товар с id:{model.SnackId} не найденн"); + } + shop.ShopSnacks.Add(model.SnackId, (snack, model.Count)); + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/AbstractShopBusinessLogic/DinerBusinessLogic.csproj b/AbstractShopBusinessLogic/DinerBusinessLogic.csproj index 6c7b98e..1244c6d 100644 --- a/AbstractShopBusinessLogic/DinerBusinessLogic.csproj +++ b/AbstractShopBusinessLogic/DinerBusinessLogic.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -12,6 +12,7 @@ + diff --git a/AbstractShopContracts/BindingModels/ShopBindingModel.cs b/AbstractShopContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..d4d5088 --- /dev/null +++ b/AbstractShopContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,18 @@ +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string Adress { get; set; } = string.Empty; + public DateTime OpeningDate { get; set; } = DateTime.Now; + public Dictionary ShopSnacks { get; set; } = new(); + } +} \ No newline at end of file diff --git a/AbstractShopContracts/BindingModels/SupplyBindingModel.cs b/AbstractShopContracts/BindingModels/SupplyBindingModel.cs new file mode 100644 index 0000000..844dee4 --- /dev/null +++ b/AbstractShopContracts/BindingModels/SupplyBindingModel.cs @@ -0,0 +1,16 @@ +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BindingModels +{ + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + public int SnackId { get; set; } + public int Count { get; set; } + } +} \ No newline at end of file diff --git a/AbstractShopContracts/BusinessLogicsContracts/IShopLogic.cs b/AbstractShopContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..1d540ad --- /dev/null +++ b/AbstractShopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,21 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool MakeSupply(SupplyBindingModel model); + } +} \ No newline at end of file diff --git a/AbstractShopContracts/SearchModels/ShopSearchModel.cs b/AbstractShopContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..d9d3a11 --- /dev/null +++ b/AbstractShopContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} \ No newline at end of file diff --git a/AbstractShopContracts/StoragesContracts/IShopStorage.cs b/AbstractShopContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..9c62afa --- /dev/null +++ b/AbstractShopContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} \ No newline at end of file diff --git a/AbstractShopContracts/ViewModels/ShopViewModel.cs b/AbstractShopContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..85331fc --- /dev/null +++ b/AbstractShopContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,22 @@ +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Adress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopSnacks { get; set; } = new(); + } +} \ No newline at end of file diff --git a/AbstractShopDataModels/Models/IShopModel.cs b/AbstractShopDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..e236e00 --- /dev/null +++ b/AbstractShopDataModels/Models/IShopModel.cs @@ -0,0 +1,18 @@ +using DinerDataModels; +using DinerDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Adress { get; } + DateTime OpeningDate { get; } + Dictionary ShopSnacks { get; } + } +} \ No newline at end of file diff --git a/AbstractShopDataModels/Models/ISupplyModel.cs b/AbstractShopDataModels/Models/ISupplyModel.cs new file mode 100644 index 0000000..1211d46 --- /dev/null +++ b/AbstractShopDataModels/Models/ISupplyModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerDataModels.Models +{ + public interface ISupplyModel + { + int ShopId { get; } + int SnackId { get; } + int Count { get; } + } +} \ No newline at end of file diff --git a/Diner/AbstractShopListImplement/DataListSingleton.cs b/Diner/AbstractShopListImplement/DataListSingleton.cs index 2d1d2d3..da777c0 100644 --- a/Diner/AbstractShopListImplement/DataListSingleton.cs +++ b/Diner/AbstractShopListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace DinerListImplement public List Components { get; set; } public List Orders { get; set; } public List Products { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Products = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/Diner/AbstractShopListImplement/Implements/ShopStorage.cs b/Diner/AbstractShopListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..7095fc8 --- /dev/null +++ b/Diner/AbstractShopListImplement/Implements/ShopStorage.cs @@ -0,0 +1,113 @@ +using DinerContracts.BindingModels; +using DinerContracts.SearchModels; +using DinerContracts.StoragesContracts; +using DinerContracts.ViewModels; +using DinerListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/Diner/AbstractShopListImplement/Models/Shop.cs b/Diner/AbstractShopListImplement/Models/Shop.cs new file mode 100644 index 0000000..8a666ee --- /dev/null +++ b/Diner/AbstractShopListImplement/Models/Shop.cs @@ -0,0 +1,55 @@ +using DinerDataModels.Models; +using DinerContracts.BindingModels; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopSnacks { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopSnacks = ShopSnacks + }; + } +} \ No newline at end of file diff --git a/Diner/Diner/DinerView.csproj b/Diner/Diner/DinerView.csproj index 1df4deb..9c3757b 100644 --- a/Diner/Diner/DinerView.csproj +++ b/Diner/Diner/DinerView.csproj @@ -17,4 +17,19 @@ + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/Diner/Diner/FormCreateSupply.Designer.cs b/Diner/Diner/FormCreateSupply.Designer.cs new file mode 100644 index 0000000..fde6034 --- /dev/null +++ b/Diner/Diner/FormCreateSupply.Designer.cs @@ -0,0 +1,142 @@ +namespace DinerView +{ + partial class FormCreateSupply + { + /// + /// 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() + { + comboBoxShop = new ComboBox(); + labelShop = new Label(); + labelPizza = new Label(); + comboBoxSnack = new ComboBox(); + labelCount = new Label(); + textBoxCount = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // comboBoxShop + // + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(115, 12); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(344, 28); + comboBoxShop.TabIndex = 0; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(12, 15); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(76, 20); + labelShop.TabIndex = 1; + labelShop.Text = "Магазин: "; + // + // labelPizza + // + labelPizza.AutoSize = true; + labelPizza.Location = new Point(12, 49); + labelPizza.Name = "labelPizza"; + labelPizza.Size = new Size(75, 20); + labelPizza.TabIndex = 2; + labelPizza.Text = "Изделие: "; + // + // comboBoxSnack + // + comboBoxSnack.FormattingEnabled = true; + comboBoxSnack.Location = new Point(115, 46); + comboBoxSnack.Name = "comboBoxSnack"; + comboBoxSnack.Size = new Size(344, 28); + comboBoxSnack.TabIndex = 3; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 83); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 4; + labelCount.Text = "Количество: "; + // + // textBoxCount + // + textBoxCount.Location = new Point(115, 80); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(344, 27); + textBoxCount.TabIndex = 5; + // + // buttonCancel + // + buttonCancel.Location = new Point(300, 113); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(116, 39); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(168, 113); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(116, 39); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormCreateSupply + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(471, 164); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxSnack); + Controls.Add(labelPizza); + Controls.Add(labelShop); + Controls.Add(comboBoxShop); + Name = "FormCreateSupply"; + Text = "Создание поставки"; + Load += FormCreateSupply_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxShop; + private Label labelShop; + private Label labelPizza; + private ComboBox comboBoxSnack; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/Diner/Diner/FormCreateSupply.cs b/Diner/Diner/FormCreateSupply.cs new file mode 100644 index 0000000..588dea9 --- /dev/null +++ b/Diner/Diner/FormCreateSupply.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContracts; +using DinerContracts.ViewModels; +using System; +using System.Collections; +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; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace DinerView +{ + public partial class FormCreateSupply : Form + { + private readonly ILogger _logger; + private readonly ISnackLogic _logicP; + private readonly IShopLogic _logicS; + private List _shopList = new List(); + private List _snackList = new List(); + + public FormCreateSupply(ILogger logger, ISnackLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + + private void FormCreateSupply_Load(object sender, EventArgs e) + { + _shopList = _logicS.ReadList(null); + _snackList = _logicP.ReadList(null); + if (_shopList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopList; + comboBoxShop.SelectedItem = null; + _logger.LogInformation("Загрузка магазинов для поставок"); + } + if (_snackList != null) + { + comboBoxSnack.DisplayMember = "SnackName"; + comboBoxSnack.ValueMember = "Id"; + comboBoxSnack.DataSource = _snackList; + comboBoxSnack.SelectedItem = null; + _logger.LogInformation("Загрузка закуски для поставок"); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSnack.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.MakeSupply(new SupplyBindingModel + { + ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), + SnackId = Convert.ToInt32(comboBoxSnack.SelectedValue), + Count = 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, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Diner/Diner/FormCreateSupply.resx b/Diner/Diner/FormCreateSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Diner/Diner/FormCreateSupply.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/Diner/Diner/FormMain.Designer.cs b/Diner/Diner/FormMain.Designer.cs index 802160c..2f7fe59 100644 --- a/Diner/Diner/FormMain.Designer.cs +++ b/Diner/Diner/FormMain.Designer.cs @@ -28,136 +28,158 @@ /// private void InitializeComponent() { - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.buttonOrderReady = new System.Windows.Forms.Button(); - this.buttonIssuedOrder = new System.Windows.Forms.Button(); - this.buttonRef = new System.Windows.Forms.Button(); - this.toolStrip1 = new System.Windows.Forms.ToolStrip(); - this.toolStripLabel1 = new System.Windows.Forms.ToolStripDropDownButton(); - this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.snacksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.toolStrip1.SuspendLayout(); - this.SuspendLayout(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + toolStrip1 = new ToolStrip(); + toolStripLabel1 = new ToolStripDropDownButton(); + componentsToolStripMenuItem = new ToolStripMenuItem(); + snacksToolStripMenuItem = new ToolStripMenuItem(); + toolStripDropDownButton1 = new ToolStripDropDownButton(); + поставкаToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + toolStrip1.SuspendLayout(); + SuspendLayout(); // // dataGridView // - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(0, 27); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(986, 421); - this.dataGridView.TabIndex = 0; + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(986, 421); + dataGridView.TabIndex = 0; // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(1040, 88); - this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(202, 29); - this.buttonCreateOrder.TabIndex = 1; - this.buttonCreateOrder.Text = "Создать заказ"; - this.buttonCreateOrder.UseVisualStyleBackColor = true; - this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + buttonCreateOrder.Location = new Point(1040, 88); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(202, 29); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; // // buttonTakeOrderInWork // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1040, 136); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(202, 29); - this.buttonTakeOrderInWork.TabIndex = 2; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + buttonTakeOrderInWork.Location = new Point(1040, 136); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(202, 29); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; // // buttonOrderReady // - this.buttonOrderReady.Location = new System.Drawing.Point(1040, 184); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(202, 29); - this.buttonOrderReady.TabIndex = 3; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + buttonOrderReady.Location = new Point(1040, 184); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(202, 29); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; // // buttonIssuedOrder // - this.buttonIssuedOrder.Location = new System.Drawing.Point(1040, 237); - this.buttonIssuedOrder.Name = "buttonIssuedOrder"; - this.buttonIssuedOrder.Size = new System.Drawing.Size(202, 29); - this.buttonIssuedOrder.TabIndex = 4; - this.buttonIssuedOrder.Text = "Заказ выдан"; - this.buttonIssuedOrder.UseVisualStyleBackColor = true; - this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + buttonIssuedOrder.Location = new Point(1040, 237); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(202, 29); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(1040, 287); - this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(202, 29); - this.buttonRef.TabIndex = 5; - this.buttonRef.Text = "Обновить список"; - this.buttonRef.UseVisualStyleBackColor = true; - this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + buttonRef.Location = new Point(1040, 287); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(202, 29); + buttonRef.TabIndex = 5; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; // // toolStrip1 // - this.toolStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripLabel1}); - this.toolStrip1.Location = new System.Drawing.Point(0, 0); - this.toolStrip1.Name = "toolStrip1"; - this.toolStrip1.Size = new System.Drawing.Size(1280, 27); - this.toolStrip1.TabIndex = 6; - this.toolStrip1.Text = "toolStrip1"; + toolStrip1.ImageScalingSize = new Size(20, 20); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripLabel1, toolStripDropDownButton1 }); + toolStrip1.Location = new Point(0, 0); + toolStrip1.Name = "toolStrip1"; + toolStrip1.Size = new Size(1280, 27); + toolStrip1.TabIndex = 6; + toolStrip1.Text = "toolStrip1"; // // toolStripLabel1 // - this.toolStripLabel1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.componentsToolStripMenuItem, - this.snacksToolStripMenuItem}); - this.toolStripLabel1.Name = "toolStripLabel1"; - this.toolStripLabel1.Size = new System.Drawing.Size(117, 24); - this.toolStripLabel1.Text = "Справочники"; + toolStripLabel1.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, snacksToolStripMenuItem, магазиныToolStripMenuItem }); + toolStripLabel1.Name = "toolStripLabel1"; + toolStripLabel1.Size = new Size(117, 24); + toolStripLabel1.Text = "Справочники"; // // componentsToolStripMenuItem // - this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - this.componentsToolStripMenuItem.Size = new System.Drawing.Size(224, 26); - this.componentsToolStripMenuItem.Text = "Компоненты"; - this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentToolStripMenuItem_Click); + componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + componentsToolStripMenuItem.Size = new Size(224, 26); + componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += ComponentToolStripMenuItem_Click; // // snacksToolStripMenuItem // - this.snacksToolStripMenuItem.Name = "snacksToolStripMenuItem"; - this.snacksToolStripMenuItem.Size = new System.Drawing.Size(224, 26); - this.snacksToolStripMenuItem.Text = "Закуски"; - this.snacksToolStripMenuItem.Click += new System.EventHandler(this.ProductToolStripMenuItem_Click); + snacksToolStripMenuItem.Name = "snacksToolStripMenuItem"; + snacksToolStripMenuItem.Size = new Size(224, 26); + snacksToolStripMenuItem.Text = "Закуски"; + snacksToolStripMenuItem.Click += ProductToolStripMenuItem_Click; + // + // toolStripDropDownButton1 + // + toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem }); + toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; + toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + toolStripDropDownButton1.Size = new Size(95, 24); + toolStripDropDownButton1.Text = "Операции"; + // + // поставкаToolStripMenuItem + // + поставкаToolStripMenuItem.Name = "поставкаToolStripMenuItem"; + поставкаToolStripMenuItem.Size = new Size(224, 26); + поставкаToolStripMenuItem.Text = "Поставка"; + поставкаToolStripMenuItem.Click += transactionToolStripMenuItem_Click; + // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1280, 450); - this.Controls.Add(this.toolStrip1); - this.Controls.Add(this.buttonRef); - this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); - this.Controls.Add(this.buttonCreateOrder); - this.Controls.Add(this.dataGridView); - this.Name = "FormMain"; - this.Text = "Закусочная"; - this.Load += new System.EventHandler(this.FormMain_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.toolStrip1.ResumeLayout(false); - this.toolStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1280, 450); + Controls.Add(toolStrip1); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Name = "FormMain"; + Text = "Закусочная"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + toolStrip1.ResumeLayout(false); + toolStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -172,5 +194,8 @@ private ToolStripDropDownButton toolStripLabel1; private ToolStripMenuItem componentsToolStripMenuItem; private ToolStripMenuItem snacksToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripDropDownButton toolStripDropDownButton1; + private ToolStripMenuItem поставкаToolStripMenuItem; } } \ No newline at end of file diff --git a/Diner/Diner/FormMain.cs b/Diner/Diner/FormMain.cs index 31f1058..b7fe7b9 100644 --- a/Diner/Diner/FormMain.cs +++ b/Diner/Diner/FormMain.cs @@ -1,7 +1,9 @@ using DinerContracts.BindingModels; using DinerContracts.BusinessLogicsContracts; using DinerDataModels.Enum; +using DinerView; using Microsoft.Extensions.Logging; +using DinerView; namespace Diner { @@ -161,5 +163,22 @@ namespace Diner { 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 transactionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + if (service is FormCreateSupply form) + { + form.ShowDialog(); + } + } } } diff --git a/Diner/Diner/FormMain.resx b/Diner/Diner/FormMain.resx index 37e571f..c354583 100644 --- a/Diner/Diner/FormMain.resx +++ b/Diner/Diner/FormMain.resx @@ -1,4 +1,64 @@ - + + + diff --git a/Diner/Diner/FormShop.Designer.cs b/Diner/Diner/FormShop.Designer.cs new file mode 100644 index 0000000..ee461b3 --- /dev/null +++ b/Diner/Diner/FormShop.Designer.cs @@ -0,0 +1,189 @@ +namespace DinerView +{ + 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() + { + labelName = new Label(); + textBoxName = new TextBox(); + textBoxAdress = new TextBox(); + labelAdress = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + dataGridView = new DataGridView(); + label1 = new Label(); + dateTimeOpen = new DateTimePicker(); + id = new DataGridViewTextBoxColumn(); + DinerName = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(11, 15); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 0; + labelName.Text = "Название: "; + // + // textBoxName + // + textBoxName.Location = new Point(102, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(276, 27); + textBoxName.TabIndex = 1; + // + // textBoxAdress + // + textBoxAdress.Location = new Point(102, 59); + textBoxAdress.Name = "textBoxAdress"; + textBoxAdress.Size = new Size(427, 27); + textBoxAdress.TabIndex = 3; + // + // labelAdress + // + labelAdress.AutoSize = true; + labelAdress.Location = new Point(11, 61); + labelAdress.Name = "labelAdress"; + labelAdress.Size = new Size(58, 20); + labelAdress.TabIndex = 2; + labelAdress.Text = "Адрес: "; + // + // buttonCancel + // + buttonCancel.Location = new Point(451, 457); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(130, 44); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(315, 457); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(130, 44); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, DinerName, Count }); + dataGridView.Location = new Point(12, 144); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; + dataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(569, 307); + dataGridView.TabIndex = 7; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 103); + label1.Name = "label1"; + label1.Size = new Size(110, 20); + label1.TabIndex = 8; + label1.Text = "Дата открытия"; + // + // dateTimeOpen + // + dateTimeOpen.Location = new Point(128, 103); + dateTimeOpen.Name = "dateTimeOpen"; + dateTimeOpen.Size = new Size(401, 27); + dateTimeOpen.TabIndex = 9; + // + // id + // + id.HeaderText = "id"; + id.MinimumWidth = 6; + id.Name = "id"; + id.ReadOnly = true; + id.Visible = false; + // + // DinerName + // + DinerName.HeaderText = "Закуска"; + DinerName.MinimumWidth = 6; + DinerName.Name = "DinerName"; + DinerName.ReadOnly = true; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.ReadOnly = true; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(593, 513); + Controls.Add(dateTimeOpen); + Controls.Add(label1); + Controls.Add(dataGridView); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxAdress); + Controls.Add(labelAdress); + Controls.Add(textBoxName); + Controls.Add(labelName); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxAdress; + private Label labelAdress; + private Button buttonCancel; + private Button buttonSave; + private DataGridView dataGridView; + private Label label1; + private DateTimePicker dateTimeOpen; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn DinerName; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/Diner/Diner/FormShop.cs b/Diner/Diner/FormShop.cs new file mode 100644 index 0000000..c34f982 --- /dev/null +++ b/Diner/Diner/FormShop.cs @@ -0,0 +1,128 @@ +using DinerDataModels.Models; +using Microsoft.Extensions.Logging; +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContracts; +using DinerContracts.SearchModels; +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 DinerView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + private Dictionary _ShopSnacks; + private DateTime? _openingDate = null; + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _ShopSnacks = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAdress.Text = view.Adress; + dateTimeOpen.Value = view.OpeningDate; + _ShopSnacks = view.ShopSnacks ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_ShopSnacks != null) + { + dataGridView.Rows.Clear(); + foreach (var sr in _ShopSnacks) + { + dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.SnackName, sr.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Adress = textBoxAdress.Text, + OpeningDate = dateTimeOpen.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); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Diner/Diner/FormShop.resx b/Diner/Diner/FormShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Diner/Diner/FormShop.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/Diner/Diner/FormShops.Designer.cs b/Diner/Diner/FormShops.Designer.cs new file mode 100644 index 0000000..1d28ead --- /dev/null +++ b/Diner/Diner/FormShops.Designer.cs @@ -0,0 +1,130 @@ +namespace DinerView +{ + 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() + { + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(608, 12); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(180, 426); + this.ToolsPanel.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(31, 206); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 36); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(31, 142); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 36); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(31, 76); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 36); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(31, 16); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 36); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(590, 426); + this.dataGridView.TabIndex = 2; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + this.ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Diner/Diner/FormShops.cs b/Diner/Diner/FormShops.cs new file mode 100644 index 0000000..11735c1 --- /dev/null +++ b/Diner/Diner/FormShops.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using Diner; +using DinerContracts.BindingModels; +using DinerContracts.BusinessLogicsContracts; +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 DinerView +{ + 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 FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopDiners"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_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 ButtonUpd_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 ButtonDel_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); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Diner/Diner/FormShops.resx b/Diner/Diner/FormShops.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Diner/Diner/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/Diner/Diner/Program.cs b/Diner/Diner/Program.cs index 8684190..8a61d8f 100644 --- a/Diner/Diner/Program.cs +++ b/Diner/Diner/Program.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using DinerBusinessLogic.BusinessLogics; +using DinerView; namespace Diner { @@ -46,6 +47,11 @@ namespace Diner services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Diner/Diner/Properties/Resources.Designer.cs b/Diner/Diner/Properties/Resources.Designer.cs new file mode 100644 index 0000000..c751ab2 --- /dev/null +++ b/Diner/Diner/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace DinerView.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DinerView.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Diner/Diner/Properties/Resources.resx b/Diner/Diner/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Diner/Diner/Properties/Resources.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