diff --git a/ProjectFlowerShop/ComponentForm.Designer.cs b/ProjectFlowerShop/ComponentForm.Designer.cs index fa8fe19..8280a16 100644 --- a/ProjectFlowerShop/ComponentForm.Designer.cs +++ b/ProjectFlowerShop/ComponentForm.Designer.cs @@ -28,12 +28,91 @@ /// private void InitializeComponent() { - components = new System.ComponentModel.Container(); + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(77, 20); + labelName.TabIndex = 0; + labelName.Text = "Название"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 46); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(45, 20); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена"; + // + // textBoxName + // + textBoxName.Location = new Point(118, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(243, 27); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(118, 43); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(243, 27); + textBoxPrice.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(267, 103); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить "; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(367, 103); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // ComponentForm + // + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Text = "Form1"; + ClientSize = new Size(466, 144); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "ComponentForm"; + Text = "Компонент"; + Load += ComponentForm_Load; + ResumeLayout(false); + PerformLayout(); } #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/ProjectFlowerShop/ComponentForm.cs b/ProjectFlowerShop/ComponentForm.cs index f7ae647..4c9ffe3 100644 --- a/ProjectFlowerShop/ComponentForm.cs +++ b/ProjectFlowerShop/ComponentForm.cs @@ -3,6 +3,7 @@ using FlowerShopContracts.BusinessLogicsContracts; using Microsoft.VisualBasic.Logging; using FlowerShopContracts.SearchModels; using System.Windows.Forms; +using FlowerShopContracts.BindingModels; namespace ProjectFlowerShop { @@ -19,6 +20,72 @@ namespace ProjectFlowerShop _logic = logic; } + private void ComponentForm_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; + textBoxPrice.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(textBoxPrice.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(); + } } } \ No newline at end of file diff --git a/ProjectFlowerShop/FormComponents.Designer.cs b/ProjectFlowerShop/FormComponents.Designer.cs new file mode 100644 index 0000000..72236be --- /dev/null +++ b/ProjectFlowerShop/FormComponents.Designer.cs @@ -0,0 +1,144 @@ +namespace ProjectFlowerShop +{ + 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() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonChange = new Button(); + buttonRemove = new Button(); + buttonReload = new Button(); + Id = new DataGridViewTextBoxColumn(); + Name = new DataGridViewTextBoxColumn(); + Price = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.Control; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { Id, Name, Price }); + dataGridView.Location = new Point(1, 1); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(558, 449); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(565, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(223, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonChange + // + buttonChange.Location = new Point(565, 47); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(223, 29); + buttonChange.TabIndex = 2; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += buttonChange_Click; + // + // buttonRemove + // + buttonRemove.Location = new Point(565, 82); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(223, 29); + buttonRemove.TabIndex = 3; + buttonRemove.Text = "Удалить"; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonReload + // + buttonReload.Location = new Point(565, 117); + buttonReload.Name = "buttonReload"; + buttonReload.Size = new Size(223, 29); + buttonReload.TabIndex = 4; + buttonReload.Text = "Обновить"; + buttonReload.UseVisualStyleBackColor = true; + buttonReload.Click += buttonReload_Click; + // + // Id + // + Id.HeaderText = "Id"; + Id.MinimumWidth = 6; + Id.Name = "Id"; + Id.Visible = false; + Id.Width = 200; + // + // Name + // + Name.HeaderText = "Name"; + Name.MinimumWidth = 6; + Name.Name = "Name"; + Name.Width = 380; + // + // Price + // + Price.HeaderText = "Price"; + Price.MinimumWidth = 6; + Price.Name = "Price"; + Price.Width = 125; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonReload); + Controls.Add(buttonRemove); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonRemove; + private Button buttonReload; + private DataGridViewTextBoxColumn Id; + private DataGridViewTextBoxColumn Name; + private DataGridViewTextBoxColumn Price; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/FormComponents.cs b/ProjectFlowerShop/FormComponents.cs new file mode 100644 index 0000000..051a3d1 --- /dev/null +++ b/ProjectFlowerShop/FormComponents.cs @@ -0,0 +1,119 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFlowerShop +{ + 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(ComponentForm)); + if (service is ComponentForm form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(ComponentForm)); + if (service is ComponentForm 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("Удалить запись?", "Вопрос", + 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 buttonReload_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/ProjectFlowerShop/FormComponents.resx b/ProjectFlowerShop/FormComponents.resx new file mode 100644 index 0000000..d1d25ab --- /dev/null +++ b/ProjectFlowerShop/FormComponents.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/ProjectFlowerShop/FormProductComponent.Designer.cs b/ProjectFlowerShop/FormProductComponent.Designer.cs new file mode 100644 index 0000000..807a79e --- /dev/null +++ b/ProjectFlowerShop/FormProductComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace ProjectFlowerShop +{ + partial class FormProductComponent + { + /// + /// 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() + { + labelComponent = new Label(); + labelNumber = new Label(); + comboBoxComponent = new ComboBox(); + textBoxNumber = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(32, 15); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(88, 20); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент"; + // + // labelNumber + // + labelNumber.AutoSize = true; + labelNumber.Location = new Point(32, 56); + labelNumber.Name = "labelNumber"; + labelNumber.Size = new Size(90, 20); + labelNumber.TabIndex = 1; + labelNumber.Text = "Количество"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(220, 12); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(362, 28); + comboBoxComponent.TabIndex = 2; + // + // textBoxNumber + // + textBoxNumber.Location = new Point(220, 53); + textBoxNumber.Name = "textBoxNumber"; + textBoxNumber.Size = new Size(362, 27); + textBoxNumber.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(338, 191); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(119, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(463, 191); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(119, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormProductComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(594, 232); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxNumber); + Controls.Add(comboBoxComponent); + Controls.Add(labelNumber); + Controls.Add(labelComponent); + Name = "FormProductComponent"; + Text = "FormProductComponent"; + Load += FormProductComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelNumber; + private ComboBox comboBoxComponent; + private TextBox textBoxNumber; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/FormProductComponent.cs b/ProjectFlowerShop/FormProductComponent.cs new file mode 100644 index 0000000..cafef61 --- /dev/null +++ b/ProjectFlowerShop/FormProductComponent.cs @@ -0,0 +1,97 @@ +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFlowerShop +{ + public partial class FormProductComponent : 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(textBoxNumber.Text); } + set + { textBoxNumber.Text = value.ToString(); } + } + public FormProductComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void FormProductComponent_Load(object sender, EventArgs e) + { + + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxNumber.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/ProjectFlowerShop/FormProductComponent.resx b/ProjectFlowerShop/FormProductComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectFlowerShop/FormProductComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file