From 966aff265e90714f922fdf8057d4f6e8d96d1d04 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Wed, 7 Feb 2024 11:05:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IceCreamShop/ComponentForm.Designer.cs | 33 ++-- IceCreamShop/IceCreamShop/ComponentForm.cs | 2 +- .../IceCreamComponentForm.Designer.cs | 35 ++-- .../IceCreamShop/IceCreamForm.Designer.cs | 71 ++++--- IceCreamShop/IceCreamShop/IceCreamForm.resx | 3 + IceCreamShop/IceCreamShop/IceCreamShop.csproj | 6 + .../IceCreamShop/IceCreamsForm.Designer.cs | 113 +++++++++++ IceCreamShop/IceCreamShop/IceCreamsForm.cs | 116 +++++++++++ IceCreamShop/IceCreamShop/IceCreamsForm.resx | 120 ++++++++++++ .../IceCreamShop/MainForm.Designer.cs | 171 ++++++++++++++++ IceCreamShop/IceCreamShop/MainForm.cs | 183 ++++++++++++++++++ IceCreamShop/IceCreamShop/MainForm.resx | 123 ++++++++++++ .../IceCreamShop/OrderForm.Designer.cs | 86 ++++---- IceCreamShop/IceCreamShop/OrderForm.cs | 110 ++++++++++- IceCreamShop/IceCreamShop/OrderForm.resx | 3 + IceCreamShop/IceCreamShop/Program.cs | 38 +++- .../BusinessLogic/OrderLogic.cs | 1 + .../ViewModels/OrderViewModel.cs | 2 +- .../Implements/OrderStorage.cs | 19 +- 19 files changed, 1134 insertions(+), 101 deletions(-) create mode 100644 IceCreamShop/IceCreamShop/IceCreamsForm.Designer.cs create mode 100644 IceCreamShop/IceCreamShop/IceCreamsForm.cs create mode 100644 IceCreamShop/IceCreamShop/IceCreamsForm.resx create mode 100644 IceCreamShop/IceCreamShop/MainForm.Designer.cs create mode 100644 IceCreamShop/IceCreamShop/MainForm.cs create mode 100644 IceCreamShop/IceCreamShop/MainForm.resx diff --git a/IceCreamShop/IceCreamShop/ComponentForm.Designer.cs b/IceCreamShop/IceCreamShop/ComponentForm.Designer.cs index 5a465fd..5498661 100644 --- a/IceCreamShop/IceCreamShop/ComponentForm.Designer.cs +++ b/IceCreamShop/IceCreamShop/ComponentForm.Designer.cs @@ -38,42 +38,45 @@ // // NameTextBox // - NameTextBox.Location = new Point(72, 12); + NameTextBox.Location = new Point(92, 13); + NameTextBox.Margin = new Padding(3, 4, 3, 4); NameTextBox.Name = "NameTextBox"; - NameTextBox.Size = new Size(243, 23); + NameTextBox.Size = new Size(277, 27); NameTextBox.TabIndex = 0; // // CostTextBox // - CostTextBox.Location = new Point(72, 41); + CostTextBox.Location = new Point(92, 56); + CostTextBox.Margin = new Padding(3, 4, 3, 4); CostTextBox.Name = "CostTextBox"; - CostTextBox.Size = new Size(119, 23); + CostTextBox.Size = new Size(135, 27); CostTextBox.TabIndex = 1; // // NameLabel // NameLabel.AutoSize = true; - NameLabel.Location = new Point(7, 20); + NameLabel.Location = new Point(8, 27); NameLabel.Name = "NameLabel"; - NameLabel.Size = new Size(59, 15); + NameLabel.Size = new Size(77, 20); NameLabel.TabIndex = 2; NameLabel.Text = "Название"; // // CostLabel // CostLabel.AutoSize = true; - CostLabel.Location = new Point(7, 49); + CostLabel.Location = new Point(8, 65); CostLabel.Name = "CostLabel"; - CostLabel.Size = new Size(35, 15); + CostLabel.Size = new Size(45, 20); CostLabel.TabIndex = 3; CostLabel.Text = "Цена"; // // CancelButton // CancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - CancelButton.Location = new Point(235, 68); + CancelButton.Location = new Point(282, 91); + CancelButton.Margin = new Padding(3, 4, 3, 4); CancelButton.Name = "CancelButton"; - CancelButton.Size = new Size(75, 23); + CancelButton.Size = new Size(86, 31); CancelButton.TabIndex = 4; CancelButton.Text = "Отмена"; CancelButton.UseVisualStyleBackColor = true; @@ -82,9 +85,10 @@ // SaveButton // SaveButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - SaveButton.Location = new Point(154, 68); + SaveButton.Location = new Point(189, 91); + SaveButton.Margin = new Padding(3, 4, 3, 4); SaveButton.Name = "SaveButton"; - SaveButton.Size = new Size(75, 23); + SaveButton.Size = new Size(86, 31); SaveButton.TabIndex = 5; SaveButton.Text = "Сохранить"; SaveButton.UseVisualStyleBackColor = true; @@ -92,16 +96,17 @@ // // ComponentForm // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; AutoSizeMode = AutoSizeMode.GrowAndShrink; - ClientSize = new Size(322, 97); + ClientSize = new Size(381, 129); Controls.Add(SaveButton); Controls.Add(CancelButton); Controls.Add(CostLabel); Controls.Add(NameLabel); Controls.Add(CostTextBox); Controls.Add(NameTextBox); + Margin = new Padding(3, 4, 3, 4); Name = "ComponentForm"; Text = "Компонент"; Load += FormComponent_Load; diff --git a/IceCreamShop/IceCreamShop/ComponentForm.cs b/IceCreamShop/IceCreamShop/ComponentForm.cs index 8cd8cbe..1aa4384 100644 --- a/IceCreamShop/IceCreamShop/ComponentForm.cs +++ b/IceCreamShop/IceCreamShop/ComponentForm.cs @@ -61,7 +61,7 @@ namespace IceCreamShop { Id = _id ?? 0, ComponentName = NameTextBox.Text, - Cost = Convert.ToDouble(NameTextBox.Text) + Cost = Convert.ToDouble(CostTextBox.Text) }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); diff --git a/IceCreamShop/IceCreamShop/IceCreamComponentForm.Designer.cs b/IceCreamShop/IceCreamShop/IceCreamComponentForm.Designer.cs index aa2ae3f..cfa4ba4 100644 --- a/IceCreamShop/IceCreamShop/IceCreamComponentForm.Designer.cs +++ b/IceCreamShop/IceCreamShop/IceCreamComponentForm.Designer.cs @@ -39,65 +39,72 @@ // ComponentLabel // ComponentLabel.AutoSize = true; - ComponentLabel.Location = new Point(12, 9); + ComponentLabel.Location = new Point(14, 12); ComponentLabel.Name = "ComponentLabel"; - ComponentLabel.Size = new Size(69, 15); + ComponentLabel.Size = new Size(88, 20); ComponentLabel.TabIndex = 0; ComponentLabel.Text = "Компонент"; // // CountLabel // CountLabel.AutoSize = true; - CountLabel.Location = new Point(12, 40); + CountLabel.Location = new Point(14, 53); CountLabel.Name = "CountLabel"; - CountLabel.Size = new Size(72, 15); + CountLabel.Size = new Size(90, 20); CountLabel.TabIndex = 1; CountLabel.Text = "Количество"; // // CountTextBox // - CountTextBox.Location = new Point(87, 37); + CountTextBox.Location = new Point(99, 49); + CountTextBox.Margin = new Padding(3, 4, 3, 4); CountTextBox.Name = "CountTextBox"; - CountTextBox.Size = new Size(292, 23); + CountTextBox.Size = new Size(333, 27); CountTextBox.TabIndex = 2; // // ComboBox // ComboBox.FormattingEnabled = true; - ComboBox.Location = new Point(87, 6); + ComboBox.Location = new Point(99, 8); + ComboBox.Margin = new Padding(3, 4, 3, 4); ComboBox.Name = "ComboBox"; - ComboBox.Size = new Size(292, 23); + ComboBox.Size = new Size(333, 28); ComboBox.TabIndex = 3; // // SaveButton // - SaveButton.Location = new Point(218, 66); + SaveButton.Location = new Point(249, 88); + SaveButton.Margin = new Padding(3, 4, 3, 4); SaveButton.Name = "SaveButton"; - SaveButton.Size = new Size(75, 23); + SaveButton.Size = new Size(86, 31); SaveButton.TabIndex = 4; SaveButton.Text = "Сохранить"; SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += ButtonSave_Click; // // CancelButton // - CancelButton.Location = new Point(299, 66); + CancelButton.Location = new Point(342, 88); + CancelButton.Margin = new Padding(3, 4, 3, 4); CancelButton.Name = "CancelButton"; - CancelButton.Size = new Size(75, 23); + CancelButton.Size = new Size(86, 31); CancelButton.TabIndex = 5; CancelButton.Text = "Отмена"; CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += ButtonCancel_Click; // // IceCreamComponentForm // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(391, 96); + ClientSize = new Size(447, 128); Controls.Add(CancelButton); Controls.Add(SaveButton); Controls.Add(ComboBox); Controls.Add(CountTextBox); Controls.Add(CountLabel); Controls.Add(ComponentLabel); + Margin = new Padding(3, 4, 3, 4); Name = "IceCreamComponentForm"; Text = "Компонент мороженного"; ResumeLayout(false); diff --git a/IceCreamShop/IceCreamShop/IceCreamForm.Designer.cs b/IceCreamShop/IceCreamShop/IceCreamForm.Designer.cs index 8c0d8d9..80aa528 100644 --- a/IceCreamShop/IceCreamShop/IceCreamForm.Designer.cs +++ b/IceCreamShop/IceCreamShop/IceCreamForm.Designer.cs @@ -50,33 +50,35 @@ // NameLabel // NameLabel.AutoSize = true; - NameLabel.Location = new Point(12, 9); + NameLabel.Location = new Point(14, 12); NameLabel.Name = "NameLabel"; - NameLabel.Size = new Size(59, 15); + NameLabel.Size = new Size(77, 20); NameLabel.TabIndex = 0; NameLabel.Text = "Название"; // // PriceLabel // PriceLabel.AutoSize = true; - PriceLabel.Location = new Point(12, 35); + PriceLabel.Location = new Point(14, 47); PriceLabel.Name = "PriceLabel"; - PriceLabel.Size = new Size(35, 15); + PriceLabel.Size = new Size(45, 20); PriceLabel.TabIndex = 1; PriceLabel.Text = "Цена"; // // NameTextBox // - NameTextBox.Location = new Point(77, 6); + NameTextBox.Location = new Point(88, 8); + NameTextBox.Margin = new Padding(3, 4, 3, 4); NameTextBox.Name = "NameTextBox"; - NameTextBox.Size = new Size(237, 23); + NameTextBox.Size = new Size(270, 27); NameTextBox.TabIndex = 2; // // PriceTextBox // - PriceTextBox.Location = new Point(77, 32); + PriceTextBox.Location = new Point(88, 43); + PriceTextBox.Margin = new Padding(3, 4, 3, 4); PriceTextBox.Name = "PriceTextBox"; - PriceTextBox.Size = new Size(100, 23); + PriceTextBox.Size = new Size(114, 27); PriceTextBox.TabIndex = 3; // // ComponentsGroupBox @@ -86,18 +88,21 @@ ComponentsGroupBox.Controls.Add(UpdateButton); ComponentsGroupBox.Controls.Add(AddButton); ComponentsGroupBox.Controls.Add(DataGridView); - ComponentsGroupBox.Location = new Point(12, 64); + ComponentsGroupBox.Location = new Point(14, 85); + ComponentsGroupBox.Margin = new Padding(3, 4, 3, 4); ComponentsGroupBox.Name = "ComponentsGroupBox"; - ComponentsGroupBox.Size = new Size(582, 287); + ComponentsGroupBox.Padding = new Padding(3, 4, 3, 4); + ComponentsGroupBox.Size = new Size(665, 383); ComponentsGroupBox.TabIndex = 4; ComponentsGroupBox.TabStop = false; ComponentsGroupBox.Text = "Компоненты"; // // RefreshButton // - RefreshButton.Location = new Point(481, 109); + RefreshButton.Location = new Point(550, 145); + RefreshButton.Margin = new Padding(3, 4, 3, 4); RefreshButton.Name = "RefreshButton"; - RefreshButton.Size = new Size(75, 23); + RefreshButton.Size = new Size(86, 31); RefreshButton.TabIndex = 4; RefreshButton.Text = "Обновить"; RefreshButton.UseVisualStyleBackColor = true; @@ -105,9 +110,10 @@ // // DeleteButton // - DeleteButton.Location = new Point(481, 80); + DeleteButton.Location = new Point(550, 107); + DeleteButton.Margin = new Padding(3, 4, 3, 4); DeleteButton.Name = "DeleteButton"; - DeleteButton.Size = new Size(75, 23); + DeleteButton.Size = new Size(86, 31); DeleteButton.TabIndex = 3; DeleteButton.Text = "Удалить"; DeleteButton.UseVisualStyleBackColor = true; @@ -115,9 +121,10 @@ // // UpdateButton // - UpdateButton.Location = new Point(481, 51); + UpdateButton.Location = new Point(550, 68); + UpdateButton.Margin = new Padding(3, 4, 3, 4); UpdateButton.Name = "UpdateButton"; - UpdateButton.Size = new Size(75, 23); + UpdateButton.Size = new Size(86, 31); UpdateButton.TabIndex = 2; UpdateButton.Text = "Изменить"; UpdateButton.UseVisualStyleBackColor = true; @@ -125,9 +132,10 @@ // // AddButton // - AddButton.Location = new Point(481, 22); + AddButton.Location = new Point(550, 29); + AddButton.Margin = new Padding(3, 4, 3, 4); AddButton.Name = "AddButton"; - AddButton.Size = new Size(75, 23); + AddButton.Size = new Size(86, 31); AddButton.TabIndex = 1; AddButton.Text = "Добавить"; AddButton.UseVisualStyleBackColor = true; @@ -137,34 +145,41 @@ // DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; DataGridView.Columns.AddRange(new DataGridViewColumn[] { IdColumn, ComponentNameColumn, CountColumn }); - DataGridView.Location = new Point(6, 22); + DataGridView.Location = new Point(7, 29); + DataGridView.Margin = new Padding(3, 4, 3, 4); DataGridView.Name = "DataGridView"; - DataGridView.Size = new Size(442, 259); + DataGridView.RowHeadersWidth = 51; + DataGridView.Size = new Size(505, 345); DataGridView.TabIndex = 0; // // IdColumn // IdColumn.HeaderText = "Column1"; + IdColumn.MinimumWidth = 6; IdColumn.Name = "IdColumn"; IdColumn.Visible = false; - IdColumn.Width = 5; + IdColumn.Width = 6; // // ComponentNameColumn // ComponentNameColumn.HeaderText = "Компонент"; + ComponentNameColumn.MinimumWidth = 6; ComponentNameColumn.Name = "ComponentNameColumn"; ComponentNameColumn.Width = 300; // // CountColumn // CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; CountColumn.Name = "CountColumn"; + CountColumn.Width = 125; // // SaveButton // - SaveButton.Location = new Point(424, 363); + SaveButton.Location = new Point(485, 484); + SaveButton.Margin = new Padding(3, 4, 3, 4); SaveButton.Name = "SaveButton"; - SaveButton.Size = new Size(75, 23); + SaveButton.Size = new Size(86, 31); SaveButton.TabIndex = 5; SaveButton.Text = "Сохранить"; SaveButton.UseVisualStyleBackColor = true; @@ -172,18 +187,19 @@ // // CancelButton // - CancelButton.Location = new Point(505, 363); + CancelButton.Location = new Point(577, 484); + CancelButton.Margin = new Padding(3, 4, 3, 4); CancelButton.Name = "CancelButton"; - CancelButton.Size = new Size(75, 23); + CancelButton.Size = new Size(86, 31); CancelButton.TabIndex = 6; CancelButton.Text = "Отмена"; CancelButton.UseVisualStyleBackColor = true; // // IceCreamForm // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(606, 398); + ClientSize = new Size(693, 531); Controls.Add(CancelButton); Controls.Add(SaveButton); Controls.Add(ComponentsGroupBox); @@ -191,6 +207,7 @@ Controls.Add(NameTextBox); Controls.Add(PriceLabel); Controls.Add(NameLabel); + Margin = new Padding(3, 4, 3, 4); Name = "IceCreamForm"; Text = "Мороженное"; ComponentsGroupBox.ResumeLayout(false); diff --git a/IceCreamShop/IceCreamShop/IceCreamForm.resx b/IceCreamShop/IceCreamShop/IceCreamForm.resx index 00fe0b0..1902b19 100644 --- a/IceCreamShop/IceCreamShop/IceCreamForm.resx +++ b/IceCreamShop/IceCreamShop/IceCreamForm.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + True diff --git a/IceCreamShop/IceCreamShop/IceCreamShop.csproj b/IceCreamShop/IceCreamShop/IceCreamShop.csproj index 1b5663b..c0a5632 100644 --- a/IceCreamShop/IceCreamShop/IceCreamShop.csproj +++ b/IceCreamShop/IceCreamShop/IceCreamShop.csproj @@ -8,6 +8,12 @@ enable + + + + + + diff --git a/IceCreamShop/IceCreamShop/IceCreamsForm.Designer.cs b/IceCreamShop/IceCreamShop/IceCreamsForm.Designer.cs new file mode 100644 index 0000000..4bb5d0d --- /dev/null +++ b/IceCreamShop/IceCreamShop/IceCreamsForm.Designer.cs @@ -0,0 +1,113 @@ +namespace IceCreamShop +{ + partial class IceCreamsForm + { + /// + /// 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(); + AddButton = new Button(); + UpdateButton = new Button(); + DeleteButton = new Button(); + RefreshButton = new Button(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 12); + DataGridView.Name = "DataGridView"; + DataGridView.RowHeadersWidth = 51; + DataGridView.Size = new Size(379, 426); + DataGridView.TabIndex = 0; + // + // AddButton + // + AddButton.Location = new Point(397, 12); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(148, 29); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(397, 47); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(148, 29); + UpdateButton.TabIndex = 2; + UpdateButton.Text = "Изменить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += UpdateButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(397, 82); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(148, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(397, 117); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(148, 29); + RefreshButton.TabIndex = 4; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // IceCreamsForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(557, 450); + Controls.Add(RefreshButton); + Controls.Add(DeleteButton); + Controls.Add(UpdateButton); + Controls.Add(AddButton); + Controls.Add(DataGridView); + Name = "IceCreamsForm"; + Text = "IceCreamsForm"; + Load += IceCreamsForm_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button UpdateButton; + private Button DeleteButton; + private Button RefreshButton; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/IceCreamsForm.cs b/IceCreamShop/IceCreamShop/IceCreamsForm.cs new file mode 100644 index 0000000..a27ea73 --- /dev/null +++ b/IceCreamShop/IceCreamShop/IceCreamsForm.cs @@ -0,0 +1,116 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.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 IceCreamShop +{ + public partial class IceCreamsForm : Form + { + private readonly ILogger _logger; + private readonly IIceCreamLogic _logic; + public IceCreamsForm(ILogger logger, IIceCreamLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void IceCreamsForm_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["IceCreamName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["IceCreamComponents"].Visible = false; + } + _logger.LogInformation("Загрузка мороженого"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки мороженого"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(IceCreamForm)); + if (service is IceCreamForm 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(IceCreamForm)); + if (service is IceCreamForm form) + { + var tmp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + 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 IceCreamBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления мороженого"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + + } + } +} diff --git a/IceCreamShop/IceCreamShop/IceCreamsForm.resx b/IceCreamShop/IceCreamShop/IceCreamsForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/IceCreamShop/IceCreamShop/IceCreamsForm.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/IceCreamShop/IceCreamShop/MainForm.Designer.cs b/IceCreamShop/IceCreamShop/MainForm.Designer.cs new file mode 100644 index 0000000..2b62d4f --- /dev/null +++ b/IceCreamShop/IceCreamShop/MainForm.Designer.cs @@ -0,0 +1,171 @@ +namespace IceCreamShop +{ + partial class MainForm + { + /// + /// 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() + { + menuStrip1 = new MenuStrip(); + ToolStripMenu = new ToolStripMenuItem(); + КомпонентыStripMenuItem = new ToolStripMenuItem(); + МороженноеStripMenuItem = new ToolStripMenuItem(); + DataGridView = new DataGridView(); + CreateOrderButton = new Button(); + TakeInWorkButton = new Button(); + ReadyButton = new Button(); + IssuedButton = new Button(); + RefreshButton = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { ToolStripMenu }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1296, 28); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // ToolStripMenu + // + ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, МороженноеStripMenuItem }); + ToolStripMenu.Name = "ToolStripMenu"; + ToolStripMenu.Size = new Size(117, 24); + ToolStripMenu.Text = "Справочники"; + // + // КомпонентыStripMenuItem + // + КомпонентыStripMenuItem.Name = "КомпонентыStripMenuItem"; + КомпонентыStripMenuItem.Size = new Size(186, 26); + КомпонентыStripMenuItem.Text = "Компоненты"; + КомпонентыStripMenuItem.Click += КомпонентыStripMenuItem_Click; + // + // МороженноеStripMenuItem + // + МороженноеStripMenuItem.Name = "МороженноеStripMenuItem"; + МороженноеStripMenuItem.Size = new Size(186, 26); + МороженноеStripMenuItem.Text = "Мороженное"; + МороженноеStripMenuItem.Click += МороженноеStripMenuItem_Click; + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 31); + DataGridView.Name = "DataGridView"; + DataGridView.RowHeadersWidth = 51; + DataGridView.Size = new Size(1007, 407); + DataGridView.TabIndex = 1; + // + // CreateOrderButton + // + CreateOrderButton.Location = new Point(1025, 31); + CreateOrderButton.Name = "CreateOrderButton"; + CreateOrderButton.Size = new Size(259, 29); + CreateOrderButton.TabIndex = 2; + CreateOrderButton.Text = "Создать заказ"; + CreateOrderButton.UseVisualStyleBackColor = true; + CreateOrderButton.Click += CreateOrderButton_Click; + // + // TakeInWorkButton + // + TakeInWorkButton.Location = new Point(1025, 66); + TakeInWorkButton.Name = "TakeInWorkButton"; + TakeInWorkButton.Size = new Size(259, 29); + TakeInWorkButton.TabIndex = 3; + TakeInWorkButton.Text = "Отдать заказ в работу"; + TakeInWorkButton.UseVisualStyleBackColor = true; + TakeInWorkButton.Click += TakeInWorkButton_Click; + // + // ReadyButton + // + ReadyButton.Location = new Point(1025, 101); + ReadyButton.Name = "ReadyButton"; + ReadyButton.Size = new Size(259, 29); + ReadyButton.TabIndex = 4; + ReadyButton.Text = "Заказ готов"; + ReadyButton.UseVisualStyleBackColor = true; + ReadyButton.Click += ReadyButton_Click; + // + // IssuedButton + // + IssuedButton.Location = new Point(1025, 136); + IssuedButton.Name = "IssuedButton"; + IssuedButton.Size = new Size(259, 29); + IssuedButton.TabIndex = 5; + IssuedButton.Text = "Заказ выдан"; + IssuedButton.UseVisualStyleBackColor = true; + IssuedButton.Click += IssuedButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(1025, 171); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(259, 29); + RefreshButton.TabIndex = 6; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // MainForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1296, 450); + Controls.Add(RefreshButton); + Controls.Add(IssuedButton); + Controls.Add(ReadyButton); + Controls.Add(TakeInWorkButton); + Controls.Add(CreateOrderButton); + Controls.Add(DataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "MainForm"; + Text = "MainForm"; + Load += MainForm_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem ToolStripMenu; + private ToolStripMenuItem КомпонентыStripMenuItem; + private ToolStripMenuItem МороженноеStripMenuItem; + private DataGridView DataGridView; + private Button CreateOrderButton; + private Button TakeInWorkButton; + private Button ReadyButton; + private Button IssuedButton; + private Button RefreshButton; + } +} \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/MainForm.cs b/IceCreamShop/IceCreamShop/MainForm.cs new file mode 100644 index 0000000..af5dbec --- /dev/null +++ b/IceCreamShop/IceCreamShop/MainForm.cs @@ -0,0 +1,183 @@ +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopDataModels; +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 IceCreamShop +{ + public partial class MainForm : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public MainForm(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void КомпонентыStripMenuItem_Click(object sender, EventArgs e) + { + var service = +Program.ServiceProvider?.GetService(typeof(ComponentsForm)); + if (service is ComponentsForm form) + { + form.ShowDialog(); + } + + } + + private void MainForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["IceCreamId"].Visible = false; + DataGridView.Columns["IceCreamName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void МороженноеStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(IceCreamsForm)); + if (service is IceCreamsForm form) + { + form.ShowDialog(); + } + } + + private void CreateOrderButton_Click(object sender, EventArgs e) + { + var service = +Program.ServiceProvider?.GetService(typeof(OrderForm)); + if (service is OrderForm form) + { + form.ShowDialog(); + LoadData(); + } + } + + private OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + IceCreamId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["IceCreamId"].Value), + Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }; + } + + private void TakeInWorkButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + + private void ReadyButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void IssuedButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/IceCreamShop/IceCreamShop/MainForm.resx b/IceCreamShop/IceCreamShop/MainForm.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/IceCreamShop/IceCreamShop/MainForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/OrderForm.Designer.cs b/IceCreamShop/IceCreamShop/OrderForm.Designer.cs index adfd95c..45eb614 100644 --- a/IceCreamShop/IceCreamShop/OrderForm.Designer.cs +++ b/IceCreamShop/IceCreamShop/OrderForm.Designer.cs @@ -28,9 +28,9 @@ /// private void InitializeComponent() { - comboBox1 = new ComboBox(); - textBox1 = new TextBox(); - textBox2 = new TextBox(); + IceCreamComboBox = new ComboBox(); + CountTextBox = new TextBox(); + SumTextBox = new TextBox(); SaveButton = new Button(); CancelButton = new Button(); IceCreamLabel = new Label(); @@ -38,97 +38,109 @@ SumLabel = new Label(); SuspendLayout(); // - // comboBox1 + // IceCreamComboBox // - comboBox1.FormattingEnabled = true; - comboBox1.Location = new Point(103, 12); - comboBox1.Name = "comboBox1"; - comboBox1.Size = new Size(232, 23); - comboBox1.TabIndex = 0; + IceCreamComboBox.FormattingEnabled = true; + IceCreamComboBox.Location = new Point(118, 16); + IceCreamComboBox.Margin = new Padding(3, 4, 3, 4); + IceCreamComboBox.Name = "IceCreamComboBox"; + IceCreamComboBox.Size = new Size(265, 28); + IceCreamComboBox.TabIndex = 0; + IceCreamComboBox.SelectedIndexChanged += IceCreamComboBox_SelectedIndexChanged; // - // textBox1 + // CountTextBox // - textBox1.Location = new Point(103, 41); - textBox1.Name = "textBox1"; - textBox1.Size = new Size(232, 23); - textBox1.TabIndex = 1; + CountTextBox.Location = new Point(118, 55); + CountTextBox.Margin = new Padding(3, 4, 3, 4); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(265, 27); + CountTextBox.TabIndex = 1; + CountTextBox.TextChanged += CountTextBox_TextChanged; // - // textBox2 + // SumTextBox // - textBox2.Location = new Point(103, 70); - textBox2.Name = "textBox2"; - textBox2.Size = new Size(232, 23); - textBox2.TabIndex = 2; + SumTextBox.Location = new Point(118, 93); + SumTextBox.Margin = new Padding(3, 4, 3, 4); + SumTextBox.Name = "SumTextBox"; + SumTextBox.Size = new Size(265, 27); + SumTextBox.TabIndex = 2; + SumTextBox.TextChanged += SumTextBox_TextChanged; // // SaveButton // - SaveButton.Location = new Point(179, 99); + SaveButton.Location = new Point(198, 132); + SaveButton.Margin = new Padding(3, 4, 3, 4); SaveButton.Name = "SaveButton"; - SaveButton.Size = new Size(75, 23); + SaveButton.Size = new Size(93, 31); SaveButton.TabIndex = 3; SaveButton.Text = "Сохранить"; SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; // // CancelButton // - CancelButton.Location = new Point(260, 99); + CancelButton.Location = new Point(297, 132); + CancelButton.Margin = new Padding(3, 4, 3, 4); CancelButton.Name = "CancelButton"; - CancelButton.Size = new Size(75, 23); + CancelButton.Size = new Size(86, 31); CancelButton.TabIndex = 4; CancelButton.Text = "Отмена"; CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; // // IceCreamLabel // IceCreamLabel.AutoSize = true; - IceCreamLabel.Location = new Point(12, 15); + IceCreamLabel.Location = new Point(14, 20); IceCreamLabel.Name = "IceCreamLabel"; - IceCreamLabel.Size = new Size(81, 15); + IceCreamLabel.Size = new Size(103, 20); IceCreamLabel.TabIndex = 5; IceCreamLabel.Text = "Мороженное"; // // CountLabel // CountLabel.AutoSize = true; - CountLabel.Location = new Point(12, 44); + CountLabel.Location = new Point(14, 59); CountLabel.Name = "CountLabel"; - CountLabel.Size = new Size(72, 15); + CountLabel.Size = new Size(90, 20); CountLabel.TabIndex = 6; CountLabel.Text = "Количество"; // // SumLabel // SumLabel.AutoSize = true; - SumLabel.Location = new Point(12, 73); + SumLabel.Location = new Point(14, 97); SumLabel.Name = "SumLabel"; - SumLabel.Size = new Size(45, 15); + SumLabel.Size = new Size(55, 20); SumLabel.TabIndex = 7; SumLabel.Text = "Сумма"; // // OrderForm // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(348, 128); + ClientSize = new Size(398, 171); Controls.Add(SumLabel); Controls.Add(CountLabel); Controls.Add(IceCreamLabel); Controls.Add(CancelButton); Controls.Add(SaveButton); - Controls.Add(textBox2); - Controls.Add(textBox1); - Controls.Add(comboBox1); + Controls.Add(SumTextBox); + Controls.Add(CountTextBox); + Controls.Add(IceCreamComboBox); + Margin = new Padding(3, 4, 3, 4); Name = "OrderForm"; Text = "OrderForm"; + Load += OrderForm_Load; ResumeLayout(false); PerformLayout(); } #endregion - private ComboBox comboBox1; - private TextBox textBox1; - private TextBox textBox2; + private ComboBox IceCreamComboBox; + private TextBox CountTextBox; + private TextBox SumTextBox; private Button SaveButton; private Button CancelButton; private Label IceCreamLabel; diff --git a/IceCreamShop/IceCreamShop/OrderForm.cs b/IceCreamShop/IceCreamShop/OrderForm.cs index 2ed7048..6dba73b 100644 --- a/IceCreamShop/IceCreamShop/OrderForm.cs +++ b/IceCreamShop/IceCreamShop/OrderForm.cs @@ -1,4 +1,6 @@ -using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.BindingModels; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.SearchModels; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -29,9 +31,113 @@ logicI, IOrderLogic logicO) private void OrderForm_Load(object sender, EventArgs e) { _logger.LogInformation("Загрузка мороженного для заказа"); - // прописать логику + try + { + var list = _logicI.ReadList(null); + if (list != null) + { + IceCreamComboBox.DisplayMember = "IceCreamName"; + IceCreamComboBox.ValueMember = "Id"; + IceCreamComboBox.DataSource = list; + IceCreamComboBox.SelectedItem = null; + } + _logger.LogInformation("Мороженное загружено"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки мороженного"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (IceCreamComboBox.SelectedValue != null && + !string.IsNullOrEmpty(CountTextBox.Text)) + { + try + { + int id = Convert.ToInt32(IceCreamComboBox.SelectedValue); + var product = _logicI.ReadElement(new IceCreamSearchModel + { + Id + = id + }); + int count = Convert.ToInt32(CountTextBox.Text); + SumTextBox.Text = Math.Round(count * (product?.Price ?? 0), + 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void CountTextBox_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void SumTextBox_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (IceCreamComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите мороженное", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + IceCreamId = Convert.ToInt32(IceCreamComboBox.SelectedValue), + Count = Convert.ToInt32(CountTextBox.Text), + Sum = Convert.ToDouble(SumTextBox.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 CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void IceCreamComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } } } diff --git a/IceCreamShop/IceCreamShop/OrderForm.resx b/IceCreamShop/IceCreamShop/OrderForm.resx index af32865..46a2fc0 100644 --- a/IceCreamShop/IceCreamShop/OrderForm.resx +++ b/IceCreamShop/IceCreamShop/OrderForm.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + \ No newline at end of file diff --git a/IceCreamShop/IceCreamShop/Program.cs b/IceCreamShop/IceCreamShop/Program.cs index df9c06d..f670921 100644 --- a/IceCreamShop/IceCreamShop/Program.cs +++ b/IceCreamShop/IceCreamShop/Program.cs @@ -1,7 +1,17 @@ +using IceCreamShopBusinessLogic.BusinessLogic; +using IceCreamShopContracts.BusinessLogicsContracts; +using IceCreamShopContracts.StoragesContracts; +using IceCreamShopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace IceCreamShop { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +21,31 @@ namespace IceCreamShop // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new ComponentForm()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + 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/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/OrderLogic.cs b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/OrderLogic.cs index 8ba98d2..93d334d 100644 --- a/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/IceCreamShop/IceCreamShopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -66,6 +66,7 @@ namespace IceCreamShopBusinessLogic.BusinessLogic throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } model.Status = status; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; _orderStorage.Update(model); return true; } diff --git a/IceCreamShop/IceCreamShopContracts/ViewModels/OrderViewModel.cs b/IceCreamShop/IceCreamShopContracts/ViewModels/OrderViewModel.cs index acdd259..1798b86 100644 --- a/IceCreamShop/IceCreamShopContracts/ViewModels/OrderViewModel.cs +++ b/IceCreamShop/IceCreamShopContracts/ViewModels/OrderViewModel.cs @@ -15,7 +15,7 @@ namespace IceCreamShopContracts.ViewModels public int Id { get; set; } public int IceCreamId { get; set; } [DisplayName("Мороженное")] - public string ProductName { get; set; } = string.Empty; + public string IceCreamName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/IceCreamShop/IceCreamShopListImplement/Implements/OrderStorage.cs b/IceCreamShop/IceCreamShopListImplement/Implements/OrderStorage.cs index a1c0ab1..d10184b 100644 --- a/IceCreamShop/IceCreamShopListImplement/Implements/OrderStorage.cs +++ b/IceCreamShop/IceCreamShopListImplement/Implements/OrderStorage.cs @@ -21,9 +21,9 @@ namespace IceCreamShopListImplement.Implements public List GetFullList() { var result = new List(); - foreach (var component in _source.Orders) + foreach (var order in _source.Orders) { - result.Add(component.GetViewModel); + result.Add(AccessIceCreamStorage(order.GetViewModel)); } return result; } @@ -39,7 +39,7 @@ namespace IceCreamShopListImplement.Implements { if (order.Id == model.Id) { - result.Add(order.GetViewModel); + result.Add(AccessIceCreamStorage(order.GetViewModel)); } } return result; @@ -102,6 +102,19 @@ namespace IceCreamShopListImplement.Implements } return null; } + + public OrderViewModel AccessIceCreamStorage(OrderViewModel model) + { + foreach (var iceCream in _source.IceCreams) + { + if (iceCream.Id == model.IceCreamId) + { + model.IceCreamName = iceCream.IceCreamName; + break; + } + } + return model; + } } }