diff --git a/CarRepairShop/CarRepairShop/Form1.Designer.cs b/CarRepairShop/CarRepairShop/Form1.Designer.cs deleted file mode 100644 index 9e59291..0000000 --- a/CarRepairShop/CarRepairShop/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace CarRepairShop -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/Form1.cs b/CarRepairShop/CarRepairShop/Form1.cs deleted file mode 100644 index a8a4d35..0000000 --- a/CarRepairShop/CarRepairShop/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace CarRepairShop -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/Form1.resx b/CarRepairShop/CarRepairShop/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/CarRepairShop/CarRepairShop/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormDetail.Designer.cs b/CarRepairShop/CarRepairShop/FormDetail.Designer.cs new file mode 100644 index 0000000..df7b304 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormDetail.Designer.cs @@ -0,0 +1,116 @@ +namespace CarRepairShop +{ + partial class FormDetail + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.LabelName = new System.Windows.Forms.Label(); + this.LabelCost = new System.Windows.Forms.Label(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(112, 9); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(240, 23); + this.textBoxName.TabIndex = 0; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(112, 40); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(138, 23); + this.textBoxCost.TabIndex = 1; + // + // LabelName + // + this.LabelName.AutoSize = true; + this.LabelName.Location = new System.Drawing.Point(27, 11); + this.LabelName.Name = "LabelName"; + this.LabelName.Size = new System.Drawing.Size(59, 15); + this.LabelName.TabIndex = 2; + this.LabelName.Text = "Название"; + // + // LabelCost + // + this.LabelCost.AutoSize = true; + this.LabelCost.Location = new System.Drawing.Point(27, 43); + this.LabelCost.Name = "LabelCost"; + this.LabelCost.Size = new System.Drawing.Size(35, 15); + this.LabelCost.TabIndex = 3; + this.LabelCost.Text = "Цена"; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(152, 77); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(97, 22); + this.ButtonSave.TabIndex = 4; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(270, 77); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(82, 22); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + // + // FormDetail + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(362, 108); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.LabelCost); + this.Controls.Add(this.LabelName); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Name = "FormDetail"; + this.Text = "Деталь"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxCost; + private Label LabelName; + private Label LabelCost; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormDetail.cs b/CarRepairShop/CarRepairShop/FormDetail.cs new file mode 100644 index 0000000..1da3ed9 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormDetail.cs @@ -0,0 +1,96 @@ +using Microsoft.Extensions.Logging; +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.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 CarRepairShop +{ + public partial class FormDetail : Form + { + private readonly ILogger _logger; + private readonly IDetailLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormDetail(ILogger logger, IDetailLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDetail_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new DetailSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.DetailName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new DetailBindingModel + { + Id = _id ?? 0, + DetailName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarRepairShop/CarRepairShop/FormDetail.resx b/CarRepairShop/CarRepairShop/FormDetail.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormDetail.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormDetails.Designer.cs b/CarRepairShop/CarRepairShop/FormDetails.Designer.cs new file mode 100644 index 0000000..6354c94 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormDetails.Designer.cs @@ -0,0 +1,109 @@ +namespace CarRepairShop +{ + partial class FormDetails + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(549, 338); + this.dataGridView.TabIndex = 0; + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(566, 22); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(123, 32); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(566, 68); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(123, 32); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(566, 113); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(123, 32); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(566, 160); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(123, 32); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + // + // FormDetails + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + 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 = "FormDetails"; + this.Text = "Детали"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormDetails.cs b/CarRepairShop/CarRepairShop/FormDetails.cs new file mode 100644 index 0000000..20a3185 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormDetails.cs @@ -0,0 +1,114 @@ +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using CarRepairShop; +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.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 CarRepairShop +{ + public partial class FormDetails : Form + { + private readonly ILogger _logger; + private readonly IDetailLogic _logic; + public FormDetails(ILogger logger, IDetailLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDetails_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["DetailName"].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(FormDetail)); + if (service is FormDetail 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(FormDetail)); + if (service is FormDetail 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 DetailBindingModel + { + 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/CarRepairShop/CarRepairShop/FormDetails.resx b/CarRepairShop/CarRepairShop/FormDetails.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormDetails.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormMain.Designer.cs b/CarRepairShop/CarRepairShop/FormMain.Designer.cs new file mode 100644 index 0000000..80b38e8 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormMain.Designer.cs @@ -0,0 +1,166 @@ +namespace CarRepairShop +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.ButtonCreateOrder = new System.Windows.Forms.Button(); + this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); + this.ButtonOrderReady = new System.Windows.Forms.Button(); + this.ButtonIssuedOrder = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ДеталиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.МашиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(0, 24); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(816, 332); + this.dataGridView1.TabIndex = 0; + // + // ButtonCreateOrder + // + this.ButtonCreateOrder.Location = new System.Drawing.Point(822, 39); + this.ButtonCreateOrder.Name = "ButtonCreateOrder"; + this.ButtonCreateOrder.Size = new System.Drawing.Size(181, 23); + this.ButtonCreateOrder.TabIndex = 1; + this.ButtonCreateOrder.Text = "Создать заказ"; + this.ButtonCreateOrder.UseVisualStyleBackColor = true; + // + // ButtonTakeOrderInWork + // + this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(822, 87); + this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(181, 23); + this.ButtonTakeOrderInWork.TabIndex = 2; + this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + // + // ButtonOrderReady + // + this.ButtonOrderReady.Location = new System.Drawing.Point(822, 137); + this.ButtonOrderReady.Name = "ButtonOrderReady"; + this.ButtonOrderReady.Size = new System.Drawing.Size(181, 23); + this.ButtonOrderReady.TabIndex = 3; + this.ButtonOrderReady.Text = "Заказ готов"; + this.ButtonOrderReady.UseVisualStyleBackColor = true; + // + // ButtonIssuedOrder + // + this.ButtonIssuedOrder.Location = new System.Drawing.Point(822, 191); + this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + this.ButtonIssuedOrder.Size = new System.Drawing.Size(181, 23); + this.ButtonIssuedOrder.TabIndex = 4; + this.ButtonIssuedOrder.Text = "Заказ выдан"; + this.ButtonIssuedOrder.UseVisualStyleBackColor = true; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(822, 246); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(181, 23); + this.ButtonRef.TabIndex = 5; + this.ButtonRef.Text = "Обновить список"; + this.ButtonRef.UseVisualStyleBackColor = true; + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1015, 24); + this.menuStrip1.TabIndex = 6; + this.menuStrip1.Text = "menuStrip1"; + // + // ToolStripMenuItem + // + this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ДеталиToolStripMenuItem, + this.МашиныToolStripMenuItem}); + this.ToolStripMenuItem.Name = "ToolStripMenuItem"; + this.ToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.ToolStripMenuItem.Text = "Справочники"; + // + // ДеталиToolStripMenuItem + // + this.ДеталиToolStripMenuItem.Name = "ДеталиToolStripMenuItem"; + this.ДеталиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ДеталиToolStripMenuItem.Text = "Детали"; + // + // МашиныToolStripMenuItem + // + this.МашиныToolStripMenuItem.Name = "МашиныToolStripMenuItem"; + this.МашиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.МашиныToolStripMenuItem.Text = "Машины"; + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1015, 356); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonIssuedOrder); + this.Controls.Add(this.ButtonOrderReady); + this.Controls.Add(this.ButtonTakeOrderInWork); + this.Controls.Add(this.ButtonCreateOrder); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Автомастерская"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView dataGridView1; + private Button ButtonCreateOrder; + private Button ButtonTakeOrderInWork; + private Button ButtonOrderReady; + private Button ButtonIssuedOrder; + private Button ButtonRef; + private MenuStrip menuStrip1; + private ToolStripMenuItem ToolStripMenuItem; + private ToolStripMenuItem ДеталиToolStripMenuItem; + private ToolStripMenuItem МашиныToolStripMenuItem; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShop/FormMain.cs b/CarRepairShop/CarRepairShop/FormMain.cs new file mode 100644 index 0000000..c8d8a60 --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormMain.cs @@ -0,0 +1,159 @@ +using Microsoft.Extensions.Logging; +using CarRepairShop; +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopDataModels.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; + +namespace CarRepairShop +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ShipId"].Visible = false; + } + _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(FormDetails)); + if (service is FormDetails form) + { + form.ShowDialog(); + } + } + + private void КораблиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShips)); + if (service is FormShips form) + { + form.ShowDialog(); + } + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), ShipName = dataGridView.SelectedRows[0].Cells["ShipName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), ShipName = dataGridView.SelectedRows[0].Cells["ShipName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении.Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), ShipName = dataGridView.SelectedRows[0].Cells["ShipName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarRepairShop/CarRepairShop/FormMain.resx b/CarRepairShop/CarRepairShop/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/CarRepairShop/CarRepairShop/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file