From 8b300112a995d05250fcaa76ae922199aa61860c Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Mon, 13 Feb 2023 19:54:37 +0300 Subject: [PATCH] UI layer --- Pizzeria/Pizzeria/Form1.Designer.cs | 39 --- Pizzeria/Pizzeria/Form1.cs | 10 - Pizzeria/Pizzeria/Form1.resx | 120 --------- Pizzeria/Pizzeria/FormComponent.Designer.cs | 119 ++++++++ Pizzeria/Pizzeria/FormComponent.cs | 87 ++++++ Pizzeria/Pizzeria/FormComponent.resx | 60 +++++ Pizzeria/Pizzeria/FormComponents.Designer.cs | 123 +++++++++ Pizzeria/Pizzeria/FormComponents.cs | 103 +++++++ Pizzeria/Pizzeria/FormComponents.resx | 60 +++++ Pizzeria/Pizzeria/FormCreateOrder.Designer.cs | 146 ++++++++++ Pizzeria/Pizzeria/FormCreateOrder.cs | 110 ++++++++ Pizzeria/Pizzeria/FormCreateOrder.resx | 60 +++++ Pizzeria/Pizzeria/FormMain.Designer.cs | 194 +++++++++++++ Pizzeria/Pizzeria/FormMain.cs | 155 +++++++++++ Pizzeria/Pizzeria/FormMain.resx | 66 +++++ Pizzeria/Pizzeria/FormPizza.Designer.cs | 254 ++++++++++++++++++ Pizzeria/Pizzeria/FormPizza.cs | 205 ++++++++++++++ Pizzeria/Pizzeria/FormPizza.resx | 69 +++++ .../Pizzeria/FormPizzaComponent.Designer.cs | 120 +++++++++ Pizzeria/Pizzeria/FormPizzaComponent.cs | 78 ++++++ Pizzeria/Pizzeria/FormPizzaComponent.resx | 60 +++++ Pizzeria/Pizzeria/FormPizzas.Designer.cs | 123 +++++++++ Pizzeria/Pizzeria/FormPizzas.cs | 104 +++++++ Pizzeria/Pizzeria/FormPizzas.resx | 60 +++++ Pizzeria/Pizzeria/Pizzeria.csproj | 19 ++ Pizzeria/Pizzeria/Program.cs | 44 ++- ...racts.ViewModels.PizzaViewModel.datasource | 10 + Pizzeria/Pizzeria/nlog.config | 13 + 28 files changed, 2439 insertions(+), 172 deletions(-) delete mode 100644 Pizzeria/Pizzeria/Form1.Designer.cs delete mode 100644 Pizzeria/Pizzeria/Form1.cs delete mode 100644 Pizzeria/Pizzeria/Form1.resx create mode 100644 Pizzeria/Pizzeria/FormComponent.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormComponent.cs create mode 100644 Pizzeria/Pizzeria/FormComponent.resx create mode 100644 Pizzeria/Pizzeria/FormComponents.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormComponents.cs create mode 100644 Pizzeria/Pizzeria/FormComponents.resx create mode 100644 Pizzeria/Pizzeria/FormCreateOrder.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormCreateOrder.cs create mode 100644 Pizzeria/Pizzeria/FormCreateOrder.resx create mode 100644 Pizzeria/Pizzeria/FormMain.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormMain.cs create mode 100644 Pizzeria/Pizzeria/FormMain.resx create mode 100644 Pizzeria/Pizzeria/FormPizza.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormPizza.cs create mode 100644 Pizzeria/Pizzeria/FormPizza.resx create mode 100644 Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormPizzaComponent.cs create mode 100644 Pizzeria/Pizzeria/FormPizzaComponent.resx create mode 100644 Pizzeria/Pizzeria/FormPizzas.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormPizzas.cs create mode 100644 Pizzeria/Pizzeria/FormPizzas.resx create mode 100644 Pizzeria/Pizzeria/Properties/DataSources/PizzeriaContracts.ViewModels.PizzaViewModel.datasource create mode 100644 Pizzeria/Pizzeria/nlog.config diff --git a/Pizzeria/Pizzeria/Form1.Designer.cs b/Pizzeria/Pizzeria/Form1.Designer.cs deleted file mode 100644 index 2308030..0000000 --- a/Pizzeria/Pizzeria/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace Pizzeria -{ - partial class Form1 - { - /// - /// 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.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/Form1.cs b/Pizzeria/Pizzeria/Form1.cs deleted file mode 100644 index 01e0e10..0000000 --- a/Pizzeria/Pizzeria/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Pizzeria -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/Form1.resx b/Pizzeria/Pizzeria/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/Pizzeria/Pizzeria/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/Pizzeria/Pizzeria/FormComponent.Designer.cs b/Pizzeria/Pizzeria/FormComponent.Designer.cs new file mode 100644 index 0000000..5782b6b --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace Pizzeria +{ + partial class FormComponent + { + /// + /// 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.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(18, 35); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(80, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(18, 68); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(48, 20); + this.label2.TabIndex = 1; + this.label2.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(113, 28); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(257, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(113, 61); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(179, 27); + this.textBoxCost.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(162, 106); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(276, 106); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(394, 155); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormComponent.cs b/Pizzeria/Pizzeria/FormComponent.cs new file mode 100644 index 0000000..15c82b8 --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent.cs @@ -0,0 +1,87 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace Pizzeria +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + 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; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + 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/Pizzeria/Pizzeria/FormComponent.resx b/Pizzeria/Pizzeria/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/FormComponents.Designer.cs b/Pizzeria/Pizzeria/FormComponents.Designer.cs new file mode 100644 index 0000000..ed957c1 --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponents.Designer.cs @@ -0,0 +1,123 @@ +namespace Pizzeria +{ + partial class FormComponents + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(-1, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(591, 484); + this.dataGridView.TabIndex = 0; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button1.Location = new System.Drawing.Point(622, 45); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(94, 29); + this.button1.TabIndex = 1; + this.button1.Text = "Добавить"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // button2 + // + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button2.Location = new System.Drawing.Point(622, 92); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(94, 29); + this.button2.TabIndex = 2; + this.button2.Text = "Изменить"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // button4 + // + this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button4.Location = new System.Drawing.Point(622, 186); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(94, 29); + this.button4.TabIndex = 4; + this.button4.Text = "Обновить"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.ButtonRef_Click); + // + // button5 + // + this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button5.Location = new System.Drawing.Point(622, 139); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(94, 29); + this.button5.TabIndex = 5; + this.button5.Text = "Удалить"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.ButtonDel_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(743, 485); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button button1; + private Button button2; + private Button button4; + private Button button5; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormComponents.cs b/Pizzeria/Pizzeria/FormComponents.cs new file mode 100644 index 0000000..a07acaa --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponents.cs @@ -0,0 +1,103 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + + +namespace Pizzeria +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_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["ComponentName"].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(FormComponent)); + if (service is FormComponent 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(FormComponent)); + if (service is FormComponent 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 ComponentBindingModel + { + 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/Pizzeria/Pizzeria/FormComponents.resx b/Pizzeria/Pizzeria/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..a5ec838 --- /dev/null +++ b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs @@ -0,0 +1,146 @@ +namespace Pizzeria +{ + partial class FormCreateOrder + { + /// + /// 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.comboBoxPizza = new System.Windows.Forms.ComboBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // comboBoxPizza + // + this.comboBoxPizza.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxPizza.FormattingEnabled = true; + this.comboBoxPizza.Location = new System.Drawing.Point(119, 34); + this.comboBoxPizza.Name = "comboBoxPizza"; + this.comboBoxPizza.Size = new System.Drawing.Size(224, 28); + this.comboBoxPizza.TabIndex = 18; + this.comboBoxPizza.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPizza_SelectedIndexChanged); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(249, 145); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 17; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(135, 145); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 16; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(117, 68); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(225, 27); + this.textBoxCount.TabIndex = 15; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(22, 75); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(93, 20); + this.label2.TabIndex = 14; + this.label2.Text = "Количество:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(22, 42); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(71, 20); + this.label1.TabIndex = 13; + this.label1.Text = "Изделие:"; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(118, 101); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(225, 27); + this.textBoxSum.TabIndex = 20; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(23, 108); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(58, 20); + this.label3.TabIndex = 19; + this.label3.Text = "Сумма:"; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(379, 195); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.label3); + this.Controls.Add(this.comboBoxPizza); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxPizza; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label label2; + private Label label1; + private TextBox textBoxSum; + private Label label3; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormCreateOrder.cs b/Pizzeria/Pizzeria/FormCreateOrder.cs new file mode 100644 index 0000000..fd16d95 --- /dev/null +++ b/Pizzeria/Pizzeria/FormCreateOrder.cs @@ -0,0 +1,110 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using Microsoft.Extensions.Logging; + + +namespace Pizzeria +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IPizzaLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка пицц для заказа"); + List _list = _logicP.ReadList(null); + if (_list != null) + { + comboBoxPizza.DisplayMember = "PizzaName"; + comboBoxPizza.ValueMember = "Id"; + comboBoxPizza.DataSource = _list; + comboBoxPizza.SelectedItem = null; + } + } + private void CalcSum() + { + if (comboBoxPizza.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPizza.SelectedValue); + var pizza = _logicP.ReadElement(new PizzaSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (pizza?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxPizza_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPizza.SelectedValue == null) + { + MessageBox.Show("Выберите пиццу", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.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/Pizzeria/Pizzeria/FormCreateOrder.resx b/Pizzeria/Pizzeria/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Pizzeria/Pizzeria/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/FormMain.Designer.cs b/Pizzeria/Pizzeria/FormMain.Designer.cs new file mode 100644 index 0000000..1a753ee --- /dev/null +++ b/Pizzeria/Pizzeria/FormMain.Designer.cs @@ -0,0 +1,194 @@ +namespace Pizzeria +{ + partial class FormMain + { + /// + /// 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.components = new System.ComponentModel.Container(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.button5 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 31); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(935, 408); + this.dataGridView.TabIndex = 0; + // + // button5 + // + this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button5.Location = new System.Drawing.Point(987, 143); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(209, 29); + this.button5.TabIndex = 9; + this.button5.Text = "Заказ готов"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // button4 + // + this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button4.Location = new System.Drawing.Point(987, 190); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(209, 29); + this.button4.TabIndex = 8; + this.button4.Text = "Заказ выдан"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // button2 + // + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button2.Location = new System.Drawing.Point(987, 96); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(209, 29); + this.button2.TabIndex = 7; + this.button2.Text = "Отдать на выполнение"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button1.Location = new System.Drawing.Point(987, 49); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(209, 29); + this.button1.TabIndex = 6; + this.button1.Text = "Создать заказ"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // button3 + // + this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button3.Location = new System.Drawing.Point(987, 236); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(209, 29); + this.button3.TabIndex = 10; + this.button3.Text = "Обновить список"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.ButtonRef_Click); + // + // contextMenuStrip + // + this.contextMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.contextMenuStrip.Name = "contextMenuStrip"; + this.contextMenuStrip.Size = new System.Drawing.Size(61, 4); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1233, 28); + this.menuStrip1.TabIndex = 11; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.изделияToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.изделияToolStripMenuItem.Text = "Пиццы"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ПиццыToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1233, 439); + this.Controls.Add(this.menuStrip1); + this.Controls.Add(this.button3); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.dataGridView); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Абстрактный магазин"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView dataGridView; + private Button button5; + private Button button4; + private Button button2; + private Button button1; + private Button button3; + private ContextMenuStrip contextMenuStrip; + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormMain.cs b/Pizzeria/Pizzeria/FormMain.cs new file mode 100644 index 0000000..1f13dba --- /dev/null +++ b/Pizzeria/Pizzeria/FormMain.cs @@ -0,0 +1,155 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaDataModels; +using Microsoft.Extensions.Logging; + +namespace Pizzeria +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["PizzaId"].Visible = false; + dataGridView.Columns["PizzaName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation(" "); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPizzas)); + if (service is FormPizzas form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private OrderBindingModel getBindingModel() + { + return new OrderBindingModel + { + Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value.ToString()), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + PizzaId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PizzaId"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }; + } + private void ButtonTakeOrderInWork_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(getBindingModel()); + if (!operationResult) + { + throw new Exception(" . ."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_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(getBindingModel()); + if (!operationResult) + { + throw new Exception(" . ."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_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(getBindingModel()); + 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 ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormMain.resx b/Pizzeria/Pizzeria/FormMain.resx new file mode 100644 index 0000000..c8fd0f0 --- /dev/null +++ b/Pizzeria/Pizzeria/FormMain.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 195, 17 + + \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizza.Designer.cs b/Pizzeria/Pizzeria/FormPizza.Designer.cs new file mode 100644 index 0000000..37d7958 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizza.Designer.cs @@ -0,0 +1,254 @@ +namespace Pizzeria +{ + partial class FormPizza + { + /// + /// 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() + { + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBox = new System.Windows.Forms.GroupBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.button5 = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button6 = new System.Windows.Forms.Button(); + this.groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(20, 19); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(80, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(20, 56); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(86, 20); + this.label2.TabIndex = 1; + this.label2.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(106, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(272, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(106, 49); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.ReadOnly = true; + this.textBoxPrice.Size = new System.Drawing.Size(192, 27); + this.textBoxPrice.TabIndex = 3; + // + // groupBox + // + this.groupBox.Controls.Add(this.dataGridView); + this.groupBox.Controls.Add(this.button5); + this.groupBox.Controls.Add(this.button1); + this.groupBox.Controls.Add(this.button2); + this.groupBox.Controls.Add(this.button4); + this.groupBox.Location = new System.Drawing.Point(20, 92); + this.groupBox.Name = "groupBox"; + this.groupBox.Size = new System.Drawing.Size(698, 369); + this.groupBox.TabIndex = 4; + this.groupBox.TabStop = false; + this.groupBox.Text = "Компоненты"; + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle1.NullValue = "Test"; + dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(6, 37); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(473, 298); + this.dataGridView.TabIndex = 11; + // + // ID + // + this.ID.HeaderText = "Ид"; + this.ID.MinimumWidth = 6; + this.ID.Name = "ID"; + this.ID.ReadOnly = true; + this.ID.Visible = false; + this.ID.Width = 125; + // + // Component + // + this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Component.HeaderText = "Компонент"; + this.Component.MinimumWidth = 6; + this.Component.Name = "Component"; + this.Component.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + this.Count.Width = 125; + // + // button5 + // + this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button5.Location = new System.Drawing.Point(569, 146); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(94, 29); + this.button5.TabIndex = 10; + this.button5.Text = "Удалить"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.ButtonDel_Click); + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button1.Location = new System.Drawing.Point(569, 52); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(94, 29); + this.button1.TabIndex = 7; + this.button1.Text = "Добавить"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // button2 + // + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button2.Location = new System.Drawing.Point(569, 99); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(94, 29); + this.button2.TabIndex = 8; + this.button2.Text = "Изменить"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // button4 + // + this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button4.Location = new System.Drawing.Point(569, 193); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(94, 29); + this.button4.TabIndex = 9; + this.button4.Text = "Обновить"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.ButtonRef_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(466, 490); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(94, 29); + this.button3.TabIndex = 5; + this.button3.Text = "Сохранить"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.ButtonSave_Click); + // + // button6 + // + this.button6.Location = new System.Drawing.Point(589, 490); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(94, 29); + this.button6.TabIndex = 6; + this.button6.Text = "Отмена"; + this.button6.UseVisualStyleBackColor = true; + this.button6.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormPizza + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(743, 536); + this.Controls.Add(this.button6); + this.Controls.Add(this.button3); + this.Controls.Add(this.groupBox); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormPizza"; + this.Text = "Пицца"; + this.Load += new System.EventHandler(this.FormPizza_Load); + this.groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox; + private DataGridView dataGridView; + private Button button5; + private Button button1; + private Button button2; + private Button button4; + private Button button3; + private Button button6; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizza.cs b/Pizzeria/Pizzeria/FormPizza.cs new file mode 100644 index 0000000..f21b7ca --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizza.cs @@ -0,0 +1,205 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaDataModels; +using Microsoft.Extensions.Logging; + + +namespace Pizzeria +{ + public partial class FormPizza : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logic; + private int? _id; + private Dictionary _pizzaComponents; + public int Id { set { _id = value; } } + public FormPizza(ILogger logger, IPizzaLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _pizzaComponents = new Dictionary(); + } + private void FormPizza_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка пиццы"); + try + { + var view = _logic.ReadElement(new PizzaSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.PizzaName; + textBoxPrice.Text = view.Price.ToString(); + _pizzaComponents = view.PizzaComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки пиццы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент пиццы"); + try + { + if (_pizzaComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _pizzaComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + 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(FormPizzaComponent)); + if (service is FormPizzaComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_pizzaComponents.ContainsKey(form.Id)) + { + _pizzaComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _pizzaComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPizzaComponent)); + if (service is FormPizzaComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _pizzaComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _pizzaComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + var name = dataGridView.SelectedRows[0].Cells[1].Value; + var count = dataGridView.SelectedRows[0].Cells[2].Value; + _logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", name, count); + + _pizzaComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_pizzaComponents == null || _pizzaComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение пиццы"); + try + { + var model = new PizzaBindingModel + { + Id = _id ?? 0, + PizzaName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + PizzaComponents = _pizzaComponents + }; + 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(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _pizzaComponents) + { + price += (elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2; + } + return Math.Round(price * 1.1, 2); + } + + } +} diff --git a/Pizzeria/Pizzeria/FormPizza.resx b/Pizzeria/Pizzeria/FormPizza.resx new file mode 100644 index 0000000..58a78b5 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizza.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs b/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs new file mode 100644 index 0000000..9d5ab54 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs @@ -0,0 +1,120 @@ +namespace Pizzeria +{ + partial class FormPizzaComponent + { + /// + /// 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.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(249, 101); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(135, 101); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 10; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(118, 59); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(225, 27); + this.textBoxCount.TabIndex = 9; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(23, 66); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(93, 20); + this.label2.TabIndex = 7; + this.label2.Text = "Количество:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(23, 33); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(91, 20); + this.label1.TabIndex = 6; + this.label1.Text = "Компонент:"; + // + // comboBoxComponent + // + this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(120, 25); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(224, 28); + this.comboBoxComponent.TabIndex = 12; + // + // FormPizzaComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(370, 153); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormPizzaComponent"; + this.Text = "Компонент пиццы"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label label2; + private Label label1; + private ComboBox comboBoxComponent; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizzaComponent.cs b/Pizzeria/Pizzeria/FormPizzaComponent.cs new file mode 100644 index 0000000..2ac2bb7 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzaComponent.cs @@ -0,0 +1,78 @@ +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels; + +namespace Pizzeria +{ + public partial class FormPizzaComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + + public FormPizzaComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Pizzeria/Pizzeria/FormPizzaComponent.resx b/Pizzeria/Pizzeria/FormPizzaComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzaComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/FormPizzas.Designer.cs b/Pizzeria/Pizzeria/FormPizzas.Designer.cs new file mode 100644 index 0000000..e54d9e5 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzas.Designer.cs @@ -0,0 +1,123 @@ +namespace Pizzeria +{ + partial class FormPizzas + { + /// + /// 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.button5 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // button5 + // + this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button5.Location = new System.Drawing.Point(614, 139); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(94, 29); + this.button5.TabIndex = 10; + this.button5.Text = "Удалить"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.ButtonDel_Click); + // + // button4 + // + this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button4.Location = new System.Drawing.Point(614, 186); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(94, 29); + this.button4.TabIndex = 9; + this.button4.Text = "Обновить"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.ButtonRef_Click); + // + // button2 + // + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button2.Location = new System.Drawing.Point(614, 92); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(94, 29); + this.button2.TabIndex = 8; + this.button2.Text = "Изменить"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button1.Location = new System.Drawing.Point(614, 45); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(94, 29); + this.button1.TabIndex = 7; + this.button1.Text = "Добавить"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(-4, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(586, 447); + this.dataGridView.TabIndex = 6; + // + // FormPizzas + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(720, 447); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.dataGridView); + this.Name = "FormPizzas"; + this.Text = "FormPizzas"; + this.Load += new System.EventHandler(this.FormPizzas_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button button5; + private Button button4; + private Button button2; + private Button button1; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizzas.cs b/Pizzeria/Pizzeria/FormPizzas.cs new file mode 100644 index 0000000..fb84a32 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzas.cs @@ -0,0 +1,104 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace Pizzeria +{ + public partial class FormPizzas : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logic; + public FormPizzas(ILogger logger, IPizzaLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormPizzas_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["PizzaName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PizzaComponents"].Visible = false; + } + _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(FormPizza)); + if (service is FormPizza 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(FormPizza)); + if (service is FormPizza 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 PizzaBindingModel + { + 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/Pizzeria/Pizzeria/FormPizzas.resx b/Pizzeria/Pizzeria/FormPizzas.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzas.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Pizzeria/Pizzeria/Pizzeria.csproj b/Pizzeria/Pizzeria/Pizzeria.csproj index b57c89e..43e30b3 100644 --- a/Pizzeria/Pizzeria/Pizzeria.csproj +++ b/Pizzeria/Pizzeria/Pizzeria.csproj @@ -8,4 +8,23 @@ enable + + + + + + + + + + + + + + + + Always + + + \ No newline at end of file diff --git a/Pizzeria/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs index 25f4942..4ad8733 100644 --- a/Pizzeria/Pizzeria/Program.cs +++ b/Pizzeria/Pizzeria/Program.cs @@ -1,17 +1,55 @@ +using PizzeriaBusinessLogic; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.StoragesContracts; +using PizzeriaListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace Pizzeria { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + IServiceCollection services = new ServiceCollection(); + ConfigureServices(services); + + _serviceProvider = services.BuildServiceProvider(); + FormMain test = _serviceProvider.GetService(); + //Application.Run(_serviceProvider.GetService()); + Application.Run(test); + } + + private static void ConfigureServices(IServiceCollection 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/Pizzeria/Pizzeria/Properties/DataSources/PizzeriaContracts.ViewModels.PizzaViewModel.datasource b/Pizzeria/Pizzeria/Properties/DataSources/PizzeriaContracts.ViewModels.PizzaViewModel.datasource new file mode 100644 index 0000000..f4df9d1 --- /dev/null +++ b/Pizzeria/Pizzeria/Properties/DataSources/PizzeriaContracts.ViewModels.PizzaViewModel.datasource @@ -0,0 +1,10 @@ + + + + PizzeriaContracts.ViewModels.PizzaViewModel, PizzeriaContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Pizzeria/Pizzeria/nlog.config b/Pizzeria/Pizzeria/nlog.config new file mode 100644 index 0000000..809a1e0 --- /dev/null +++ b/Pizzeria/Pizzeria/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file