From d7f9f16b23c57bec6c592cee0ace49f6f3545550 Mon Sep 17 00:00:00 2001 From: Viltskaa Date: Tue, 31 Jan 2023 01:11:18 +0400 Subject: [PATCH] complete --- SushiBar/SushiBar/Form1.Designer.cs | 39 ---- SushiBar/SushiBar/Form1.cs | 10 - SushiBar/SushiBar/Form1.resx | 120 ---------- SushiBar/SushiBar/FormComponent.Designer.cs | 121 ++++++++++ SushiBar/SushiBar/FormComponent.cs | 84 +++++++ SushiBar/SushiBar/FormComponent.resx | 60 +++++ SushiBar/SushiBar/FormComponents.Designer.cs | 114 +++++++++ SushiBar/SushiBar/FormComponents.cs | 105 +++++++++ SushiBar/SushiBar/FormComponents.resx | 60 +++++ SushiBar/SushiBar/FormCreateOrder.Designer.cs | 144 ++++++++++++ SushiBar/SushiBar/FormCreateOrder.cs | 121 ++++++++++ SushiBar/SushiBar/FormCreateOrder.resx | 60 +++++ SushiBar/SushiBar/FormMain.Designer.cs | 174 ++++++++++++++ SushiBar/SushiBar/FormMain.cs | 158 +++++++++++++ SushiBar/SushiBar/FormMain.resx | 63 +++++ SushiBar/SushiBar/FormSushi.Designer.cs | 217 ++++++++++++++++++ SushiBar/SushiBar/FormSushi.cs | 211 +++++++++++++++++ SushiBar/SushiBar/FormSushi.resx | 66 ++++++ .../SushiBar/FormSushiComponent.Designer.cs | 119 ++++++++++ SushiBar/SushiBar/FormSushiComponent.cs | 81 +++++++ SushiBar/SushiBar/FormSushiComponent.resx | 60 +++++ .../SushiBar/FormSushiMoreThenOne.Designer.cs | 114 +++++++++ SushiBar/SushiBar/FormSushiMoreThenOne.cs | 104 +++++++++ SushiBar/SushiBar/FormSushiMoreThenOne.resx | 60 +++++ SushiBar/SushiBar/Program.cs | 42 +++- SushiBar/SushiBar/SushiBar.csproj | 10 + .../BusinessLogics/OrderLogic.cs | 4 +- .../ViewModels/OrderViewModel.cs | 2 +- 28 files changed, 2345 insertions(+), 178 deletions(-) delete mode 100644 SushiBar/SushiBar/Form1.Designer.cs delete mode 100644 SushiBar/SushiBar/Form1.cs delete mode 100644 SushiBar/SushiBar/Form1.resx create mode 100644 SushiBar/SushiBar/FormComponent.Designer.cs create mode 100644 SushiBar/SushiBar/FormComponent.cs create mode 100644 SushiBar/SushiBar/FormComponent.resx create mode 100644 SushiBar/SushiBar/FormComponents.Designer.cs create mode 100644 SushiBar/SushiBar/FormComponents.cs create mode 100644 SushiBar/SushiBar/FormComponents.resx create mode 100644 SushiBar/SushiBar/FormCreateOrder.Designer.cs create mode 100644 SushiBar/SushiBar/FormCreateOrder.cs create mode 100644 SushiBar/SushiBar/FormCreateOrder.resx create mode 100644 SushiBar/SushiBar/FormMain.Designer.cs create mode 100644 SushiBar/SushiBar/FormMain.cs create mode 100644 SushiBar/SushiBar/FormMain.resx create mode 100644 SushiBar/SushiBar/FormSushi.Designer.cs create mode 100644 SushiBar/SushiBar/FormSushi.cs create mode 100644 SushiBar/SushiBar/FormSushi.resx create mode 100644 SushiBar/SushiBar/FormSushiComponent.Designer.cs create mode 100644 SushiBar/SushiBar/FormSushiComponent.cs create mode 100644 SushiBar/SushiBar/FormSushiComponent.resx create mode 100644 SushiBar/SushiBar/FormSushiMoreThenOne.Designer.cs create mode 100644 SushiBar/SushiBar/FormSushiMoreThenOne.cs create mode 100644 SushiBar/SushiBar/FormSushiMoreThenOne.resx diff --git a/SushiBar/SushiBar/Form1.Designer.cs b/SushiBar/SushiBar/Form1.Designer.cs deleted file mode 100644 index b5f899b..0000000 --- a/SushiBar/SushiBar/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace SushiBar -{ - 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/SushiBar/SushiBar/Form1.cs b/SushiBar/SushiBar/Form1.cs deleted file mode 100644 index 0eaa471..0000000 --- a/SushiBar/SushiBar/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace SushiBar -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/SushiBar/SushiBar/Form1.resx b/SushiBar/SushiBar/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/SushiBar/SushiBar/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/SushiBar/SushiBar/FormComponent.Designer.cs b/SushiBar/SushiBar/FormComponent.Designer.cs new file mode 100644 index 0000000..b644b79 --- /dev/null +++ b/SushiBar/SushiBar/FormComponent.Designer.cs @@ -0,0 +1,121 @@ +namespace SushiBar +{ + 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.textBoxName = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(57, 6); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(270, 23); + this.textBoxName.TabIndex = 0; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 9); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(39, 15); + this.labelName.TabIndex = 1; + this.labelName.Text = "Name"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(12, 36); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(31, 15); + this.labelCost.TabIndex = 2; + this.labelCost.Text = "Cost"; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(57, 33); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(270, 23); + this.textBoxCost.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.BackColor = System.Drawing.SystemColors.Control; + this.buttonSave.Location = new System.Drawing.Point(12, 62); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(153, 23); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Save"; + this.buttonSave.UseVisualStyleBackColor = false; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.BackColor = System.Drawing.SystemColors.Control; + this.buttonCancel.Location = new System.Drawing.Point(171, 62); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(156, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = false; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(339, 93); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Controls.Add(this.textBoxName); + this.Name = "FormComponent"; + this.Text = "FormComponent"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxName; + private Label labelName; + private Label labelCost; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormComponent.cs b/SushiBar/SushiBar/FormComponent.cs new file mode 100644 index 0000000..d56910d --- /dev/null +++ b/SushiBar/SushiBar/FormComponent.cs @@ -0,0 +1,84 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; + +namespace SushiBar +{ + 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 ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Fill name text box", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Saving Component"); + 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("Error on saving. Additional info below."); + } + MessageBox.Show("Saving is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on saving"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Get component"); + 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, "Error in getting cpmponent"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBar/SushiBar/FormComponent.resx b/SushiBar/SushiBar/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/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/SushiBar/SushiBar/FormComponents.Designer.cs b/SushiBar/SushiBar/FormComponents.Designer.cs new file mode 100644 index 0000000..b34ba72 --- /dev/null +++ b/SushiBar/SushiBar/FormComponents.Designer.cs @@ -0,0 +1,114 @@ +namespace SushiBar +{ + 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonRemove = new System.Windows.Forms.Button(); + this.buttonReload = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(612, 426); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(630, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(158, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Add"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(630, 41); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(158, 23); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Edit"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonRemove + // + this.buttonRemove.Location = new System.Drawing.Point(630, 70); + this.buttonRemove.Name = "buttonRemove"; + this.buttonRemove.Size = new System.Drawing.Size(158, 23); + this.buttonRemove.TabIndex = 3; + this.buttonRemove.Text = "Remove"; + this.buttonRemove.UseVisualStyleBackColor = true; + this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click); + // + // buttonReload + // + this.buttonReload.Location = new System.Drawing.Point(630, 99); + this.buttonReload.Name = "buttonReload"; + this.buttonReload.Size = new System.Drawing.Size(158, 23); + this.buttonReload.TabIndex = 4; + this.buttonReload.Text = "Reload"; + this.buttonReload.UseVisualStyleBackColor = true; + this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonReload); + this.Controls.Add(this.buttonRemove); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonRemove; + private Button buttonReload; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormComponents.cs b/SushiBar/SushiBar/FormComponents.cs new file mode 100644 index 0000000..c8543a9 --- /dev/null +++ b/SushiBar/SushiBar/FormComponents.cs @@ -0,0 +1,105 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBar +{ + 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 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 ButtonEdit_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 ButtonRemove_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Delete component"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Error on deleting. Additional info below."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error delete component"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonReload_Click(object sender, EventArgs e) + { + LoadData(); + } + + 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("Load components"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error load components"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormComponents.resx b/SushiBar/SushiBar/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/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/SushiBar/SushiBar/FormCreateOrder.Designer.cs b/SushiBar/SushiBar/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..1437009 --- /dev/null +++ b/SushiBar/SushiBar/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace SushiBar +{ + 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.labelSushi = new System.Windows.Forms.Label(); + this.comboBoxSushi = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelSum = new System.Windows.Forms.Label(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelSushi + // + this.labelSushi.AutoSize = true; + this.labelSushi.Location = new System.Drawing.Point(12, 9); + this.labelSushi.Name = "labelSushi"; + this.labelSushi.Size = new System.Drawing.Size(35, 15); + this.labelSushi.TabIndex = 0; + this.labelSushi.Text = "Sushi"; + // + // comboBoxSushi + // + this.comboBoxSushi.FormattingEnabled = true; + this.comboBoxSushi.Location = new System.Drawing.Point(53, 6); + this.comboBoxSushi.Name = "comboBoxSushi"; + this.comboBoxSushi.Size = new System.Drawing.Size(197, 23); + this.comboBoxSushi.TabIndex = 1; + this.comboBoxSushi.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSushi_SelectedIndexChanged); + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 41); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(40, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Count"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(53, 38); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(197, 23); + this.textBoxCount.TabIndex = 3; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 74); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(31, 15); + this.labelSum.TabIndex = 4; + this.labelSum.Text = "Sum"; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(53, 71); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(197, 23); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(12, 100); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(105, 23); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Save"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(123, 100); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(127, 23); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(262, 130); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxSushi); + this.Controls.Add(this.labelSushi); + this.Name = "FormCreateOrder"; + this.Text = "FormCreateOrder"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelSushi; + private ComboBox comboBoxSushi; + private Label labelCount; + private TextBox textBoxCount; + private Label labelSum; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormCreateOrder.cs b/SushiBar/SushiBar/FormCreateOrder.cs new file mode 100644 index 0000000..eed5d1b --- /dev/null +++ b/SushiBar/SushiBar/FormCreateOrder.cs @@ -0,0 +1,121 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; + +namespace SushiBar +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logicP; + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, ISushiLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void CalcSum() + { + if (comboBoxSushi.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxSushi.SelectedValue); + var sushi = _logicP.ReadElement(new SushiSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Calculating sum of order"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on calculating sum of order"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = list; + comboBoxSushi.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on loading sushi"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Fill in text box count", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Select sushi", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Create order"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Error on creating order. Additional info below."); + } + MessageBox.Show("Saving is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on saving"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Load sushi for order"); + LoadData(); + } + + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ComboBoxSushi_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + } +} diff --git a/SushiBar/SushiBar/FormCreateOrder.resx b/SushiBar/SushiBar/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/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/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs new file mode 100644 index 0000000..81f4b35 --- /dev/null +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -0,0 +1,174 @@ +namespace SushiBar +{ + 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.directoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonSubmit = new System.Windows.Forms.Button(); + this.buttonReady = new System.Windows.Forms.Button(); + this.buttonIssue = new System.Windows.Forms.Button(); + this.buttonReload = new System.Windows.Forms.Button(); + this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.sushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(656, 411); + this.dataGridView.TabIndex = 0; + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.directoryToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(800, 24); + this.menuStrip1.TabIndex = 1; + this.menuStrip1.Text = "menuStrip1"; + // + // directoryToolStripMenuItem + // + this.directoryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.componentsToolStripMenuItem, + this.sushiToolStripMenuItem}); + this.directoryToolStripMenuItem.Name = "directoryToolStripMenuItem"; + this.directoryToolStripMenuItem.Size = new System.Drawing.Size(67, 20); + this.directoryToolStripMenuItem.Text = "Directory"; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(674, 27); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(114, 23); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Create Order"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonSubmit + // + this.buttonSubmit.Location = new System.Drawing.Point(674, 56); + this.buttonSubmit.Name = "buttonSubmit"; + this.buttonSubmit.Size = new System.Drawing.Size(114, 23); + this.buttonSubmit.TabIndex = 3; + this.buttonSubmit.Text = "Submit"; + this.buttonSubmit.UseVisualStyleBackColor = true; + this.buttonSubmit.Click += new System.EventHandler(this.ButtonSubmit_Click); + // + // buttonReady + // + this.buttonReady.Location = new System.Drawing.Point(674, 85); + this.buttonReady.Name = "buttonReady"; + this.buttonReady.Size = new System.Drawing.Size(114, 23); + this.buttonReady.TabIndex = 4; + this.buttonReady.Text = "Order Ready"; + this.buttonReady.UseVisualStyleBackColor = true; + this.buttonReady.Click += new System.EventHandler(this.ButtonReady_Click); + // + // buttonIssue + // + this.buttonIssue.Location = new System.Drawing.Point(674, 114); + this.buttonIssue.Name = "buttonIssue"; + this.buttonIssue.Size = new System.Drawing.Size(114, 23); + this.buttonIssue.TabIndex = 5; + this.buttonIssue.Text = "Order Issue"; + this.buttonIssue.UseVisualStyleBackColor = true; + this.buttonIssue.Click += new System.EventHandler(this.ButtonIssue_Click); + // + // buttonReload + // + this.buttonReload.Location = new System.Drawing.Point(674, 143); + this.buttonReload.Name = "buttonReload"; + this.buttonReload.Size = new System.Drawing.Size(114, 23); + this.buttonReload.TabIndex = 6; + this.buttonReload.Text = "Reload"; + this.buttonReload.UseVisualStyleBackColor = true; + this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click); + // + // componentsToolStripMenuItem + // + this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.componentsToolStripMenuItem.Text = "Components"; + this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + // + // sushiToolStripMenuItem + // + this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem"; + this.sushiToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.sushiToolStripMenuItem.Text = "Sushi"; + this.sushiToolStripMenuItem.Click += new System.EventHandler(this.sushiToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonReload); + this.Controls.Add(this.buttonIssue); + this.Controls.Add(this.buttonReady); + this.Controls.Add(this.buttonSubmit); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "FormMain"; + 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 MenuStrip menuStrip1; + private ToolStripMenuItem directoryToolStripMenuItem; + private Button buttonCreateOrder; + private Button buttonSubmit; + private Button buttonReady; + private Button buttonIssue; + private Button buttonReload; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem sushiToolStripMenuItem; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs new file mode 100644 index 0000000..b75d098 --- /dev/null +++ b/SushiBar/SushiBar/FormMain.cs @@ -0,0 +1,158 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBar +{ + 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 LoadData() + { + _logger.LogInformation("Load components"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["SushiId"].Visible = false; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on load orders"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void ButtonSubmit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Order №{id}. Change statuc on -Submit", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Error on saving. Additional info below."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error submit order"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void ButtonReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Order №{id}. Change status on -Ready",id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Error on saving. Additional info below."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on change status"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void ButtonIssue_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Order №{id}. Change status on -Issued", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Error on saving. Additional info below."); + } + _logger.LogInformation("Order №{id} issued", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on change status"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonReload_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void sushiToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + + if (service is FormSushi form) + { + form.ShowDialog(); + } + } + } +} diff --git a/SushiBar/SushiBar/FormMain.resx b/SushiBar/SushiBar/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/SushiBar/SushiBar/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SushiBar/SushiBar/FormSushi.Designer.cs b/SushiBar/SushiBar/FormSushi.Designer.cs new file mode 100644 index 0000000..dc821d8 --- /dev/null +++ b/SushiBar/SushiBar/FormSushi.Designer.cs @@ -0,0 +1,217 @@ +namespace SushiBar +{ + partial class FormSushi + { + /// + /// 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.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBox = new System.Windows.Forms.GroupBox(); + this.buttonReload = new System.Windows.Forms.Button(); + this.buttonRemove = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 9); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(39, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Name"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(57, 6); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(589, 23); + this.textBoxName.TabIndex = 1; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(12, 41); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(33, 15); + this.labelCost.TabIndex = 2; + this.labelCost.Text = "Price"; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(57, 38); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(589, 23); + this.textBoxPrice.TabIndex = 3; + // + // groupBox + // + this.groupBox.Controls.Add(this.buttonReload); + this.groupBox.Controls.Add(this.buttonRemove); + this.groupBox.Controls.Add(this.buttonEdit); + this.groupBox.Controls.Add(this.buttonAdd); + this.groupBox.Controls.Add(this.dataGridView); + this.groupBox.Location = new System.Drawing.Point(15, 67); + this.groupBox.Name = "groupBox"; + this.groupBox.Size = new System.Drawing.Size(773, 343); + this.groupBox.TabIndex = 4; + this.groupBox.TabStop = false; + this.groupBox.Text = "Components"; + // + // buttonReload + // + this.buttonReload.Location = new System.Drawing.Point(637, 109); + this.buttonReload.Name = "buttonReload"; + this.buttonReload.Size = new System.Drawing.Size(130, 23); + this.buttonReload.TabIndex = 4; + this.buttonReload.Text = "Reload"; + this.buttonReload.UseVisualStyleBackColor = true; + this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click); + // + // buttonRemove + // + this.buttonRemove.Location = new System.Drawing.Point(637, 80); + this.buttonRemove.Name = "buttonRemove"; + this.buttonRemove.Size = new System.Drawing.Size(130, 23); + this.buttonRemove.TabIndex = 3; + this.buttonRemove.Text = "Remove"; + this.buttonRemove.UseVisualStyleBackColor = true; + this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(637, 51); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 23); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Edit"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(637, 22); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Add"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(6, 22); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(625, 315); + this.dataGridView.TabIndex = 0; + // + // Component + // + this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Component.HeaderText = "Component"; + this.Component.Name = "Component"; + // + // Count + // + this.Count.HeaderText = "Count"; + this.Count.Name = "Count"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(658, 415); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(130, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(522, 415); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(130, 23); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Save"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormSushi + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.groupBox); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormSushi"; + this.Text = "FormSushi"; + this.Load += new System.EventHandler(this.FormSushi_Load); + this.groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Label labelCost; + private TextBox textBoxPrice; + private GroupBox groupBox; + private Button buttonReload; + private Button buttonRemove; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs new file mode 100644 index 0000000..699c58c --- /dev/null +++ b/SushiBar/SushiBar/FormSushi.cs @@ -0,0 +1,211 @@ +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarDataModels.Models; + +namespace SushiBar +{ + public partial class FormSushi : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logic; + private int? _id; + private Dictionary _sushiComponents; + public int Id { set { _id = value; } } + + public FormSushi(ILogger logger, ISushiLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _sushiComponents = new Dictionary(); + } + + private void LoadData() + { + _logger.LogInformation("Load components"); + try + { + if (_sushiComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _sushiComponents) + { + 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 double CalcPrice() + { + double price = 0; + foreach (var elem in _sushiComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + + } + + private void FormSushi_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Load records"); + try + { + var view = _logic.ReadElement(new SushiSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.SushiName; + textBoxPrice.Text = view.Price.ToString(); + _sushiComponents = view.SushiComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on loading"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); + if (service is FormSushiComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Add new component:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_sushiComponents.ContainsKey(form.Id)) + { + _sushiComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _sushiComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); + if (service is FormSushiComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _sushiComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Edit component:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _sushiComponents[form.Id] = (form.ComponentModel,form.Count); + LoadData(); + } + } + } + } + + private void ButtonRemove_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Delte record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Deleting component: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _sushiComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + + } + + private void ButtonReload_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Fill in name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Fill in cost", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_sushiComponents == null || _sushiComponents.Count == 0) + { + MessageBox.Show("Fill in components", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Saving component"); + try + { + var model = new SushiBindingModel + { + Id = _id ?? 0, + SushiName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + SushiComponents = _sushiComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Error on saving. Additional info below."); + } + MessageBox.Show("Saving is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on saving"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBar/SushiBar/FormSushi.resx b/SushiBar/SushiBar/FormSushi.resx new file mode 100644 index 0000000..9c00fcb --- /dev/null +++ b/SushiBar/SushiBar/FormSushi.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 + + + True + + + True + + \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushiComponent.Designer.cs b/SushiBar/SushiBar/FormSushiComponent.Designer.cs new file mode 100644 index 0000000..0f427df --- /dev/null +++ b/SushiBar/SushiBar/FormSushiComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace SushiBar +{ + partial class FormSushiComponent + { + /// + /// 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.labelComp = new System.Windows.Forms.Label(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelComp + // + this.labelComp.AutoSize = true; + this.labelComp.Location = new System.Drawing.Point(12, 9); + this.labelComp.Name = "labelComp"; + this.labelComp.Size = new System.Drawing.Size(71, 15); + this.labelComp.TabIndex = 0; + this.labelComp.Text = "Component"; + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(89, 6); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(224, 23); + this.comboBoxComponent.TabIndex = 1; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 41); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(40, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Count"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(89, 38); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(224, 23); + this.textBoxCount.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(12, 67); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(143, 23); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Save"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(161, 67); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(152, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSushiComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(325, 99); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.labelComp); + this.Name = "FormSushiComponent"; + this.Text = "FormSushiComponent"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComp; + private ComboBox comboBoxComponent; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushiComponent.cs b/SushiBar/SushiBar/FormSushiComponent.cs new file mode 100644 index 0000000..be86298 --- /dev/null +++ b/SushiBar/SushiBar/FormSushiComponent.cs @@ -0,0 +1,81 @@ +using Microsoft.VisualBasic.Logging; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBar +{ + public partial class FormSushiComponent: 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 FormSushiComponent(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("Fill in text box count", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Select component", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBar/SushiBar/FormSushiComponent.resx b/SushiBar/SushiBar/FormSushiComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormSushiComponent.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/SushiBar/SushiBar/FormSushiMoreThenOne.Designer.cs b/SushiBar/SushiBar/FormSushiMoreThenOne.Designer.cs new file mode 100644 index 0000000..9db4ce2 --- /dev/null +++ b/SushiBar/SushiBar/FormSushiMoreThenOne.Designer.cs @@ -0,0 +1,114 @@ +namespace SushiBar +{ + partial class FormSushiMoreThenOne + { + /// + /// 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonRemove = new System.Windows.Forms.Button(); + this.buttonReload = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(422, 426); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(440, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(168, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Add"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(440, 41); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(168, 23); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Edit"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonRemove + // + this.buttonRemove.Location = new System.Drawing.Point(440, 70); + this.buttonRemove.Name = "buttonRemove"; + this.buttonRemove.Size = new System.Drawing.Size(168, 23); + this.buttonRemove.TabIndex = 3; + this.buttonRemove.Text = "Remove"; + this.buttonRemove.UseVisualStyleBackColor = true; + this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click); + // + // buttonReload + // + this.buttonReload.Location = new System.Drawing.Point(440, 99); + this.buttonReload.Name = "buttonReload"; + this.buttonReload.Size = new System.Drawing.Size(168, 23); + this.buttonReload.TabIndex = 4; + this.buttonReload.Text = "Reload"; + this.buttonReload.UseVisualStyleBackColor = true; + this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click); + // + // FormSushiMoreThenOne + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(620, 450); + this.Controls.Add(this.buttonReload); + this.Controls.Add(this.buttonRemove); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormSushiMoreThenOne"; + this.Text = "FormSushiMoreThenOne"; + this.Load += new System.EventHandler(this.FormSushiMoreThenOne_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonRemove; + private Button buttonReload; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushiMoreThenOne.cs b/SushiBar/SushiBar/FormSushiMoreThenOne.cs new file mode 100644 index 0000000..90fa957 --- /dev/null +++ b/SushiBar/SushiBar/FormSushiMoreThenOne.cs @@ -0,0 +1,104 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; + +namespace SushiBar +{ + public partial class FormSushiMoreThenOne : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logic; + public FormSushiMoreThenOne(ILogger logger, ISushiLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["SushiComponents"].Visible = false; + } + + _logger.LogInformation("Load sushi"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Error on load sushi"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + if (service is FormSushi form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + if (service is FormSushi form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonRemove_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Delete sushi"); + try + { + if (!_logic.Delete(new SushiBindingModel { Id = id })) + { + throw new Exception("Error on deleting. Additional info below."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error delete sushi"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonReload_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormSushiMoreThenOne_Load(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBar/SushiBar/FormSushiMoreThenOne.resx b/SushiBar/SushiBar/FormSushiMoreThenOne.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SushiBar/SushiBar/FormSushiMoreThenOne.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/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 402417b..beb4c1c 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -1,17 +1,47 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using SushiBarBusinessLogic.BusinessLogics; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.StoragesContracts; +using SushibarListImplement.Implements; + namespace SushiBar { internal static class Program { - /// - /// The main entry point for the application. - /// + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + [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()); + 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/SushiBar/SushiBar/SushiBar.csproj b/SushiBar/SushiBar/SushiBar.csproj index b57c89e..52a0900 100644 --- a/SushiBar/SushiBar/SushiBar.csproj +++ b/SushiBar/SushiBar/SushiBar.csproj @@ -8,4 +8,14 @@ enable + + + + + + + + + + \ No newline at end of file diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 79d8b46..6b27301 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -13,7 +13,7 @@ namespace SushiBarBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; @@ -22,7 +22,7 @@ namespace SushiBarBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - model.Status = SushiBarDataModels.Enums.OrderStatus.Accepted; + model.Status = OrderStatus.Accepted; if (_orderStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index c31b276..4cc6956 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -10,7 +10,7 @@ namespace SushiBarContracts.ViewModels public int Id { get; set; } public int SushiId { get; set; } - [DisplayName("Product")] + [DisplayName("Sushi")] public string SushiName { get; set; } = string.Empty; [DisplayName("Count")]