diff --git a/StorageCompany/StorageCompanyView/Form1.Designer.cs b/StorageCompany/StorageCompanyView/Form1.Designer.cs deleted file mode 100644 index 1be05e4..0000000 --- a/StorageCompany/StorageCompanyView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace StorageCompanyView -{ - 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 - } -} diff --git a/StorageCompany/StorageCompanyView/Form1.cs b/StorageCompany/StorageCompanyView/Form1.cs deleted file mode 100644 index 0d6b840..0000000 --- a/StorageCompany/StorageCompanyView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace StorageCompanyView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/StorageCompany/StorageCompanyView/FormClient.Designer.cs b/StorageCompany/StorageCompanyView/FormClient.Designer.cs new file mode 100644 index 0000000..8d37621 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormClient.Designer.cs @@ -0,0 +1,127 @@ +namespace StorageCompanyView +{ + partial class FormClient + { + /// + /// 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() + { + label1 = new Label(); + textBox1 = new TextBox(); + textBox2 = new TextBox(); + label2 = new Label(); + textBox3 = new TextBox(); + label3 = new Label(); + button2 = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 9); + label1.Name = "label1"; + label1.Size = new Size(34, 15); + label1.TabIndex = 0; + label1.Text = "ФИО"; + // + // textBox1 + // + textBox1.Location = new Point(12, 27); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(177, 23); + textBox1.TabIndex = 1; + // + // textBox2 + // + textBox2.Location = new Point(12, 83); + textBox2.Name = "textBox2"; + textBox2.Size = new Size(177, 23); + textBox2.TabIndex = 3; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 65); + label2.Name = "label2"; + label2.Size = new Size(36, 15); + label2.TabIndex = 2; + label2.Text = "Email"; + // + // textBox3 + // + textBox3.Location = new Point(12, 138); + textBox3.Name = "textBox3"; + textBox3.Size = new Size(177, 23); + textBox3.TabIndex = 5; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 120); + label3.Name = "label3"; + label3.Size = new Size(38, 15); + label3.TabIndex = 4; + label3.Text = "label3"; + // + // button2 + // + button2.Location = new Point(61, 179); + button2.Name = "button2"; + button2.Size = new Size(75, 23); + button2.TabIndex = 7; + button2.Text = "Сохранить"; + button2.UseVisualStyleBackColor = true; + button2.Click += ButtonSave_Click; + // + // FormClient + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(204, 228); + Controls.Add(button2); + Controls.Add(textBox3); + Controls.Add(label3); + Controls.Add(textBox2); + Controls.Add(label2); + Controls.Add(textBox1); + Controls.Add(label1); + Name = "FormClient"; + Text = "FormClient"; + Load += FormClient_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private TextBox textBox1; + private TextBox textBox2; + private Label label2; + private TextBox textBox3; + private Label label3; + private Button button2; + } +} \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormClient.cs b/StorageCompany/StorageCompanyView/FormClient.cs new file mode 100644 index 0000000..9821115 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormClient.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using StorageCompanyContracts.BindingModels; +using StorageCompanyContracts.BusinessLogicsContracts; +using StorageCompanyContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace StorageCompanyView +{ + public partial class FormClient : Form + { + private readonly ILogger _logger; + + private readonly IClientLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + public FormClient(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormClient_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение клиента"); + var view = _logic.ReadElement(new ClientSearchModel { Id = _id.Value }); + if (view != null) + { + textBox1.Text = view.ClientFIO; + textBox2.Text = view.Email; + textBox3.Text = view.Password; + } + } + 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(textBox1.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBox2.Text)) + { + MessageBox.Show("Заполните email", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBox3.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение клиента"); + try + { + var model = new ClientBindingModel + { + Id = _id ?? 0, + ClientFIO = textBox1.Text, + Email = textBox2.Text, + Password = textBox3.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/StorageCompany/StorageCompanyView/FormClient.resx b/StorageCompany/StorageCompanyView/FormClient.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormClient.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormClients.Designer.cs b/StorageCompany/StorageCompanyView/FormClients.Designer.cs new file mode 100644 index 0000000..91397b2 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormClients.Designer.cs @@ -0,0 +1,120 @@ +namespace StorageCompanyView +{ + partial class FormClients + { + /// + /// 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.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(370, 132); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(370, 91); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(370, 50); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(370, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(350, 312); + this.dataGridView.TabIndex = 0; + // + // FormClients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(464, 312); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormClients"; + this.Load += FormClients_Load; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Button buttonRef; + private System.Windows.Forms.Button buttonDel; + private System.Windows.Forms.Button buttonUpd; + private System.Windows.Forms.Button buttonAdd; + private System.Windows.Forms.DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormClients.cs b/StorageCompany/StorageCompanyView/FormClients.cs new file mode 100644 index 0000000..7212199 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormClients.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using StorageCompanyContracts.BindingModels; +using StorageCompanyContracts.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 StorageCompanyView +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + private readonly IClientLogic _logic; + public FormClients(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + + } + _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(FormClient)); + if (service is FormClient 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(FormClient)); + if (service is FormClient 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 ClientBindingModel { 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/StorageCompany/StorageCompanyView/Form1.resx b/StorageCompany/StorageCompanyView/FormClients.resx similarity index 100% rename from StorageCompany/StorageCompanyView/Form1.resx rename to StorageCompany/StorageCompanyView/FormClients.resx diff --git a/StorageCompany/StorageCompanyView/FormCreateSale.Designer.cs b/StorageCompany/StorageCompanyView/FormCreateSale.Designer.cs new file mode 100644 index 0000000..d3083b4 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormCreateSale.Designer.cs @@ -0,0 +1,145 @@ +namespace StorageCompanyView +{ + partial class FormCreateSale + { + /// + /// 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() + { + labelCount = new Label(); + comboBoxWood = new ComboBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxCount = new TextBox(); + labelWood = new Label(); + labelClient = new Label(); + comboBoxClient = new ComboBox(); + SuspendLayout(); + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(20, 102); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(78, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество :"; + // + // comboBoxWood + // + comboBoxWood.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxWood.FormattingEnabled = true; + comboBoxWood.Location = new Point(124, 12); + comboBoxWood.Name = "comboBoxWood"; + comboBoxWood.Size = new Size(300, 23); + comboBoxWood.TabIndex = 4; + // + // buttonCancel + // + buttonCancel.Location = new Point(249, 141); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 36); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(107, 141); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 36); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(124, 99); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(300, 23); + textBoxCount.TabIndex = 5; + // + // labelWood + // + labelWood.AutoSize = true; + labelWood.Location = new Point(20, 15); + labelWood.Name = "labelWood"; + labelWood.Size = new Size(56, 15); + labelWood.TabIndex = 3; + labelWood.Text = "Продукт:"; + // + // labelClient + // + labelClient.AutoSize = true; + labelClient.Location = new Point(20, 59); + labelClient.Name = "labelClient"; + labelClient.Size = new Size(49, 15); + labelClient.TabIndex = 9; + labelClient.Text = "Клиент:"; + // + // comboBoxClient + // + comboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(124, 56); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(300, 23); + comboBoxClient.TabIndex = 10; + // + // FormCreateSale + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(452, 198); + Controls.Add(comboBoxClient); + Controls.Add(labelClient); + Controls.Add(labelCount); + Controls.Add(comboBoxWood); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(labelWood); + Margin = new Padding(4, 3, 4, 3); + Name = "FormCreateSale"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказ"; + Load += FormCreateSale_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label labelCount; + private ComboBox comboBoxWood; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label labelWood; + private Label labelClient; + private ComboBox comboBoxClient; + } +} \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormCreateSale.cs b/StorageCompany/StorageCompanyView/FormCreateSale.cs new file mode 100644 index 0000000..7955ccc --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormCreateSale.cs @@ -0,0 +1,118 @@ +using Microsoft.Extensions.Logging; +using StorageCompanyContracts.BindingModels; +using StorageCompanyContracts.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 StorageCompanyView +{ + public partial class FormCreateSale : Form + { + private readonly ILogger _logger; + private readonly IProductLogic _logicW; + private readonly IClientLogic _logicC; + private readonly ISaleLogic _logicO; + public FormCreateSale(ILogger logger, IProductLogic logicP, ISaleLogic logicO, IClientLogic logicC) + { + InitializeComponent(); + _logger = logger; + _logicW = logicP; + _logicO = logicO; + _logicC = logicC; + } + private void FormCreateSale_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicW.ReadList(null); + if (list != null) + { + comboBoxWood.DisplayMember = "ProductName"; + comboBoxWood.ValueMember = "Id"; + comboBoxWood.DataSource = list; + comboBoxWood.SelectedItem = null; + } + _logger.LogInformation("Изделия загружены"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxClient.DisplayMember = "ClientFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = list; + comboBoxClient.SelectedItem = null; + } + _logger.LogInformation("Изделия загружены"); + } + 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(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxWood.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxClient.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.Create(new SaleBindingModel + { + ProductId = Convert.ToInt32(comboBoxWood.SelectedValue), + ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), + SaleNum = Convert.ToInt32(textBoxCount.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/StorageCompany/StorageCompanyView/FormCreateSale.resx b/StorageCompany/StorageCompanyView/FormCreateSale.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormCreateSale.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormCreateSupply.Designer.cs b/StorageCompany/StorageCompanyView/FormCreateSupply.Designer.cs new file mode 100644 index 0000000..dfeeef9 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormCreateSupply.Designer.cs @@ -0,0 +1,145 @@ +namespace StorageCompanyView +{ + partial class FormCreateSupply + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelCount = new Label(); + comboBoxWood = new ComboBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxCount = new TextBox(); + labelWood = new Label(); + labelClient = new Label(); + comboBoxClient = new ComboBox(); + SuspendLayout(); + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(20, 102); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(78, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество :"; + // + // comboBoxWood + // + comboBoxWood.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxWood.FormattingEnabled = true; + comboBoxWood.Location = new Point(124, 12); + comboBoxWood.Name = "comboBoxWood"; + comboBoxWood.Size = new Size(300, 23); + comboBoxWood.TabIndex = 4; + // + // buttonCancel + // + buttonCancel.Location = new Point(249, 141); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 36); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(107, 141); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 36); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(124, 99); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(300, 23); + textBoxCount.TabIndex = 5; + // + // labelWood + // + labelWood.AutoSize = true; + labelWood.Location = new Point(20, 15); + labelWood.Name = "labelWood"; + labelWood.Size = new Size(56, 15); + labelWood.TabIndex = 3; + labelWood.Text = "Продукт:"; + // + // labelClient + // + labelClient.AutoSize = true; + labelClient.Location = new Point(20, 59); + labelClient.Name = "labelClient"; + labelClient.Size = new Size(73, 15); + labelClient.TabIndex = 9; + labelClient.Text = "Поставщик:"; + // + // comboBoxClient + // + comboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(124, 56); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(300, 23); + comboBoxClient.TabIndex = 10; + // + // FormCreateSupply + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(452, 198); + Controls.Add(comboBoxClient); + Controls.Add(labelClient); + Controls.Add(labelCount); + Controls.Add(comboBoxWood); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(labelWood); + Margin = new Padding(4, 3, 4, 3); + Name = "FormCreateSupply"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заказ"; + Load += FormCreateSupply_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label labelCount; + private ComboBox comboBoxWood; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label labelWood; + private Label labelClient; + private ComboBox comboBoxClient; + } +} \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormCreateSupply.cs b/StorageCompany/StorageCompanyView/FormCreateSupply.cs new file mode 100644 index 0000000..a806988 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormCreateSupply.cs @@ -0,0 +1,118 @@ +using Microsoft.Extensions.Logging; +using StorageCompanyContracts.BindingModels; +using StorageCompanyContracts.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 StorageCompanyView +{ + public partial class FormCreateSupply : Form + { + private readonly ILogger _logger; + private readonly IProductLogic _logicW; + private readonly IProviderLogic _logicC; + private readonly ISupplyLogic _logicO; + public FormCreateSupply(ILogger logger, IProductLogic logicP, ISupplyLogic logicO, IProviderLogic logicC) + { + InitializeComponent(); + _logger = logger; + _logicW = logicP; + _logicO = logicO; + _logicC = logicC; + } + private void FormCreateSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicW.ReadList(null); + if (list != null) + { + comboBoxWood.DisplayMember = "ProductName"; + comboBoxWood.ValueMember = "Id"; + comboBoxWood.DataSource = list; + comboBoxWood.SelectedItem = null; + } + _logger.LogInformation("Изделия загружены"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxClient.DisplayMember = "ProviderFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = list; + comboBoxClient.SelectedItem = null; + } + _logger.LogInformation("Изделия загружены"); + } + 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(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxWood.SelectedItem == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxClient.SelectedItem == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.Create(new SupplyBindingModel + { + ProductId = Convert.ToInt32(comboBoxWood.SelectedValue), + ProviderId = Convert.ToInt32(comboBoxClient.SelectedValue), + SupplyNum = Convert.ToInt32(textBoxCount.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/StorageCompany/StorageCompanyView/FormCreateSupply.resx b/StorageCompany/StorageCompanyView/FormCreateSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormCreateSupply.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormMain.Designer.cs b/StorageCompany/StorageCompanyView/FormMain.Designer.cs new file mode 100644 index 0000000..9d61e88 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormMain.Designer.cs @@ -0,0 +1,171 @@ +namespace StorageCompanyView +{ + 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() + { + dataGridView1 = new DataGridView(); + dataGridView2 = new DataGridView(); + menuStrip1 = new MenuStrip(); + продуктыToolStripMenuItem = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); + поставщикиToolStripMenuItem = new ToolStripMenuItem(); + button1 = new Button(); + button2 = new Button(); + label1 = new Label(); + label2 = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView2).BeginInit(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView1 + // + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Location = new Point(12, 53); + dataGridView1.Name = "dataGridView1"; + dataGridView1.RowTemplate.Height = 25; + dataGridView1.Size = new Size(776, 185); + dataGridView1.TabIndex = 0; + // + // dataGridView2 + // + dataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView2.Location = new Point(12, 269); + dataGridView2.Name = "dataGridView2"; + dataGridView2.RowTemplate.Height = 25; + dataGridView2.Size = new Size(776, 185); + dataGridView2.TabIndex = 1; + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { продуктыToolStripMenuItem, клиентыToolStripMenuItem, поставщикиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(800, 24); + menuStrip1.TabIndex = 2; + menuStrip1.Text = "menuStrip1"; + // + // продуктыToolStripMenuItem + // + продуктыToolStripMenuItem.Name = "продуктыToolStripMenuItem"; + продуктыToolStripMenuItem.Size = new Size(74, 20); + продуктыToolStripMenuItem.Text = "Продукты"; + продуктыToolStripMenuItem.Click += ПродуктыToolStripMenuItem_Click; + // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(67, 20); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click; + // + // поставщикиToolStripMenuItem + // + поставщикиToolStripMenuItem.Name = "поставщикиToolStripMenuItem"; + поставщикиToolStripMenuItem.Size = new Size(89, 20); + поставщикиToolStripMenuItem.Text = "Поставщики"; + поставщикиToolStripMenuItem.Click += ПоставщикиToolStripMenuItem_Click; + // + // button1 + // + button1.Location = new Point(635, 27); + button1.Name = "button1"; + button1.Size = new Size(153, 23); + button1.TabIndex = 3; + button1.Text = "Создать поставку"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonCreateSupply_Click; + // + // button2 + // + button2.Location = new Point(635, 245); + button2.Name = "button2"; + button2.Size = new Size(153, 23); + button2.TabIndex = 4; + button2.Text = "Создать продажу"; + button2.UseVisualStyleBackColor = true; + button2.Click += ButtonCreateSale_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point); + label1.Location = new Point(346, 24); + label1.Name = "label1"; + label1.Size = new Size(94, 25); + label1.TabIndex = 5; + label1.Text = "Поставки"; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point); + label2.Location = new Point(346, 241); + label2.Name = "label2"; + label2.Size = new Size(93, 25); + label2.TabIndex = 6; + label2.Text = "Продажи"; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 467); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(button2); + Controls.Add(button1); + Controls.Add(dataGridView2); + Controls.Add(dataGridView1); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "FormMain"; + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView2).EndInit(); + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DataGridView dataGridView1; + private DataGridView dataGridView2; + private MenuStrip menuStrip1; + private ToolStripMenuItem продуктыToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem поставщикиToolStripMenuItem; + private Button button1; + private Button button2; + private Label label1; + private Label label2; + } +} \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormMain.cs b/StorageCompany/StorageCompanyView/FormMain.cs new file mode 100644 index 0000000..04cc13a --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormMain.cs @@ -0,0 +1,110 @@ +using Microsoft.Extensions.Logging; +using StorageCompanyContracts.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 StorageCompanyView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly ISaleLogic _saleLogic; + private readonly ISupplyLogic _supplyLogic; + public FormMain(ILogger logger, ISaleLogic saleLogic, ISupplyLogic supplyLogic) + { + InitializeComponent(); + _logger = logger; + _saleLogic = saleLogic; + _supplyLogic = supplyLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка продаж"); + try + { + var list = _saleLogic.ReadList(null); + if (list != null) + { + dataGridView2.DataSource = list; + + } + _logger.LogInformation("Загрузка продаж"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки продаж"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка поставок"); + try + { + var list = _supplyLogic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + + } + _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(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } + private void ПоставщикиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProviders)); + if (service is FormProviders form) + { + form.ShowDialog(); + } + } + private void ПродуктыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProducts)); + if (service is FormProducts form) + { + form.ShowDialog(); + } + } + private void ButtonCreateSale_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSale)); + if (service is FormCreateSale form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonCreateSupply_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + if (service is FormCreateSupply form) + { + form.ShowDialog(); + LoadData(); + } + } + } +} diff --git a/StorageCompany/StorageCompanyView/FormMain.resx b/StorageCompany/StorageCompanyView/FormMain.resx new file mode 100644 index 0000000..9e93228 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormMain.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 75 + + \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormProduct.Designer.cs b/StorageCompany/StorageCompanyView/FormProduct.Designer.cs new file mode 100644 index 0000000..6a0e527 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProduct.Designer.cs @@ -0,0 +1,106 @@ +namespace StorageCompanyView +{ + partial class FormProduct + { + /// + /// 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() + { + label1 = new Label(); + textBox1 = new TextBox(); + label2 = new Label(); + button1 = new Button(); + comboBox1 = new ComboBox(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 9); + label1.Name = "label1"; + label1.Size = new Size(59, 15); + label1.TabIndex = 0; + label1.Text = "Название"; + // + // textBox1 + // + textBox1.Location = new Point(12, 27); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(177, 23); + textBox1.TabIndex = 1; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 65); + label2.Name = "label2"; + label2.Size = new Size(27, 15); + label2.TabIndex = 2; + label2.Text = "Тип"; + // + // button1 + // + button1.Location = new Point(61, 112); + button1.Name = "button1"; + button1.Size = new Size(75, 23); + button1.TabIndex = 6; + button1.Text = "Сохранить"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonSave_Click; + // + // comboBox1 + // + comboBox1.FormattingEnabled = true; + comboBox1.Location = new Point(12, 83); + comboBox1.Name = "comboBox1"; + comboBox1.Size = new Size(177, 23); + comboBox1.TabIndex = 7; + // + // FormProduct + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(204, 144); + Controls.Add(comboBox1); + Controls.Add(button1); + Controls.Add(label2); + Controls.Add(textBox1); + Controls.Add(label1); + Name = "FormProduct"; + Text = "FormProduct"; + Load += FormProduct_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private TextBox textBox1; + private Label label2; + private Button button1; + private ComboBox comboBox1; + } +} \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormProduct.cs b/StorageCompany/StorageCompanyView/FormProduct.cs new file mode 100644 index 0000000..df31dfc --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProduct.cs @@ -0,0 +1,105 @@ +using Microsoft.Extensions.Logging; +using StorageCompanyContracts.BindingModels; +using StorageCompanyContracts.BusinessLogicsContracts; +using StorageCompanyContracts.SearchModels; +using StorageCompanyDataModels.Enums; +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; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace StorageCompanyView +{ + public partial class FormProduct : Form + { + private readonly ILogger _logger; + + private readonly IProductLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + public FormProduct(ILogger logger, IProductLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormProduct_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение клиента"); + var view = _logic.ReadElement(new ProductSearchModel { Id = _id.Value }); + if (view != null) + { + textBox1.Text = view.ProductName; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компклиентаонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + else + { + comboBox1.DataSource = Enum.GetValues(typeof(ProductType)); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBox1.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBox1.SelectedValue == null) + { + MessageBox.Show("Заполните тип", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение клиента"); + try + { + var model = new ProductBindingModel + { + Id = _id ?? 0, + ProductName = textBox1.Text, + ProductType = (ProductType)comboBox1.SelectedItem, + ProductNum = 0 + }; + 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/StorageCompany/StorageCompanyView/FormProduct.resx b/StorageCompany/StorageCompanyView/FormProduct.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProduct.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormProducts.Designer.cs b/StorageCompany/StorageCompanyView/FormProducts.Designer.cs new file mode 100644 index 0000000..6664e05 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProducts.Designer.cs @@ -0,0 +1,120 @@ +namespace StorageCompanyView +{ + partial class FormProducts + { + /// + /// 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.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(370, 132); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(370, 91); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(370, 50); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(370, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(350, 312); + this.dataGridView.TabIndex = 0; + // + // FormProducts + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(464, 312); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormProducts"; + this.Load += FormProducts_Load; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Button buttonRef; + private System.Windows.Forms.Button buttonDel; + private System.Windows.Forms.Button buttonUpd; + private System.Windows.Forms.Button buttonAdd; + private System.Windows.Forms.DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormProducts.cs b/StorageCompany/StorageCompanyView/FormProducts.cs new file mode 100644 index 0000000..6a9e69e --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProducts.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using StorageCompanyContracts.BindingModels; +using StorageCompanyContracts.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 StorageCompanyView +{ + public partial class FormProducts : Form + { + private readonly ILogger _logger; + private readonly IProductLogic _logic; + public FormProducts(ILogger logger, IProductLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormProducts_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + + } + _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(FormProduct)); + if (service is FormProduct 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(FormProduct)); + if (service is FormProduct 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 ProductBindingModel { 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/StorageCompany/StorageCompanyView/FormProducts.resx b/StorageCompany/StorageCompanyView/FormProducts.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProducts.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormProvider.Designer.cs b/StorageCompany/StorageCompanyView/FormProvider.Designer.cs new file mode 100644 index 0000000..3fc3fa6 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProvider.Designer.cs @@ -0,0 +1,127 @@ +namespace StorageCompanyView +{ + partial class FormProvider + { + /// + /// 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() + { + label1 = new Label(); + textBox1 = new TextBox(); + textBox2 = new TextBox(); + label2 = new Label(); + textBox3 = new TextBox(); + label3 = new Label(); + button1 = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 9); + label1.Name = "label1"; + label1.Size = new Size(34, 15); + label1.TabIndex = 0; + label1.Text = "ФИО"; + // + // textBox1 + // + textBox1.Location = new Point(12, 27); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(177, 23); + textBox1.TabIndex = 1; + // + // textBox2 + // + textBox2.Location = new Point(12, 83); + textBox2.Name = "textBox2"; + textBox2.Size = new Size(177, 23); + textBox2.TabIndex = 3; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 65); + label2.Name = "label2"; + label2.Size = new Size(36, 15); + label2.TabIndex = 2; + label2.Text = "Email"; + // + // textBox3 + // + textBox3.Location = new Point(12, 138); + textBox3.Name = "textBox3"; + textBox3.Size = new Size(177, 23); + textBox3.TabIndex = 5; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 120); + label3.Name = "label3"; + label3.Size = new Size(49, 15); + label3.TabIndex = 4; + label3.Text = "Пароль"; + // + // button1 + // + button1.Location = new Point(61, 176); + button1.Name = "button1"; + button1.Size = new Size(75, 23); + button1.TabIndex = 6; + button1.Text = "Сохранить"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonSave_Click; + // + // FormProvider + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(204, 207); + Controls.Add(button1); + Controls.Add(textBox3); + Controls.Add(label3); + Controls.Add(textBox2); + Controls.Add(label2); + Controls.Add(textBox1); + Controls.Add(label1); + Name = "FormProvider"; + Text = "FormProvider"; + Load += FormProvider_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private TextBox textBox1; + private TextBox textBox2; + private Label label2; + private TextBox textBox3; + private Label label3; + private Button button1; + } +} \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormProvider.cs b/StorageCompany/StorageCompanyView/FormProvider.cs new file mode 100644 index 0000000..56639e6 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProvider.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using StorageCompanyContracts.BindingModels; +using StorageCompanyContracts.BusinessLogicsContracts; +using StorageCompanyContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace StorageCompanyView +{ + public partial class FormProvider : Form + { + private readonly ILogger _logger; + + private readonly IProviderLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + public FormProvider(ILogger logger, IProviderLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormProvider_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение клиента"); + var view = _logic.ReadElement(new ProviderSearchModel { Id = _id.Value }); + if (view != null) + { + textBox1.Text = view.ProviderFIO; + textBox2.Text = view.Email; + textBox3.Text = view.Password; + } + } + 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(textBox1.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBox2.Text)) + { + MessageBox.Show("Заполните email", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBox3.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение клиента"); + try + { + var model = new ProviderBindingModel + { + Id = _id ?? 0, + ProviderFIO = textBox1.Text, + Email = textBox2.Text, + Password = textBox3.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/StorageCompany/StorageCompanyView/FormProvider.resx b/StorageCompany/StorageCompanyView/FormProvider.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProvider.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormProviders.Designer.cs b/StorageCompany/StorageCompanyView/FormProviders.Designer.cs new file mode 100644 index 0000000..39d8379 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProviders.Designer.cs @@ -0,0 +1,120 @@ +namespace StorageCompanyView +{ + partial class FormProviders + { + /// + /// 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.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(370, 132); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(370, 91); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(370, 50); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(370, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(350, 312); + this.dataGridView.TabIndex = 0; + // + // FormProviders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(464, 312); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormProviders"; + this.Load += FormProviders_Load; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Button buttonRef; + private System.Windows.Forms.Button buttonDel; + private System.Windows.Forms.Button buttonUpd; + private System.Windows.Forms.Button buttonAdd; + private System.Windows.Forms.DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/FormProviders.cs b/StorageCompany/StorageCompanyView/FormProviders.cs new file mode 100644 index 0000000..f12c29c --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProviders.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using StorageCompanyContracts.BindingModels; +using StorageCompanyContracts.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 StorageCompanyView +{ + public partial class FormProviders : Form + { + private readonly ILogger _logger; + private readonly IProviderLogic _logic; + public FormProviders(ILogger logger, IProviderLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormProviders_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + + } + _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(FormProvider)); + if (service is FormProvider 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(FormProvider)); + if (service is FormProvider 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 ProviderBindingModel { 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/StorageCompany/StorageCompanyView/FormProviders.resx b/StorageCompany/StorageCompanyView/FormProviders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/StorageCompany/StorageCompanyView/FormProviders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/Program.cs b/StorageCompany/StorageCompanyView/Program.cs index c8fc0a1..b8b5826 100644 --- a/StorageCompany/StorageCompanyView/Program.cs +++ b/StorageCompany/StorageCompanyView/Program.cs @@ -1,17 +1,60 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using StorageCompanyBusinessLogics.BusinessLogics; +using StorageCompanyContracts.BusinessLogicsContracts; +using StorageCompanyContracts.StoragesContracts; +using StorageCompanyDatabaseImplement.Implements; +using NLog.Extensions.Logging; + namespace StorageCompanyView { - internal static class Program - { - /// - /// 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()); - } - } + 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(); + 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(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } } \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/StorageCompanyView.csproj b/StorageCompany/StorageCompanyView/StorageCompanyView.csproj index b57c89e..89a9103 100644 --- a/StorageCompany/StorageCompanyView/StorageCompanyView.csproj +++ b/StorageCompany/StorageCompanyView/StorageCompanyView.csproj @@ -8,4 +8,20 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + \ No newline at end of file diff --git a/StorageCompany/StorageCompanyView/nlog.config b/StorageCompany/StorageCompanyView/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/StorageCompany/StorageCompanyView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file