From 8a06a50ce7f5840ad7087b933f253b90a507ec3e Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Tue, 7 Feb 2023 13:00:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlumbingRepair/Form1.Designer.cs | 39 --- PlumbingRepair/PlumbingRepair/Form1.cs | 10 - .../PlumbingRepair/FormComponent.Designer.cs | 123 +++++++++ .../PlumbingRepair/FormComponent.cs | 93 +++++++ .../PlumbingRepair/FormComponent.resx | 60 +++++ .../PlumbingRepair/FormComponents.Designer.cs | 113 ++++++++ .../PlumbingRepair/FormComponents.cs | 110 ++++++++ .../{Form1.resx => FormComponents.resx} | 0 .../FormCreateOrder.Designer.cs | 143 ++++++++++ .../PlumbingRepair/FormCreateOrder.cs | 134 ++++++++++ .../PlumbingRepair/FormCreateOrder.resx | 120 +++++++++ .../PlumbingRepair/FormMain.Designer.cs | 173 ++++++++++++ PlumbingRepair/PlumbingRepair/FormMain.cs | 190 +++++++++++++ PlumbingRepair/PlumbingRepair/FormMain.resx | 120 +++++++++ .../PlumbingRepair/FormWork.Designer.cs | 252 ++++++++++++++++++ PlumbingRepair/PlumbingRepair/FormWork.cs | 229 ++++++++++++++++ PlumbingRepair/PlumbingRepair/FormWork.resx | 120 +++++++++ .../FormWorkComponent.Designer.cs | 119 +++++++++ .../PlumbingRepair/FormWorkComponent.cs | 86 ++++++ .../PlumbingRepair/FormWorkComponent.resx | 120 +++++++++ .../PlumbingRepair/FormWorks.Designer.cs | 113 ++++++++ PlumbingRepair/PlumbingRepair/FormWorks.cs | 111 ++++++++ PlumbingRepair/PlumbingRepair/FormWorks.resx | 120 +++++++++ .../PlumbingRepair/PlumbingRepair.csproj | 5 + PlumbingRepair/PlumbingRepair/Program.cs | 2 +- 25 files changed, 2655 insertions(+), 50 deletions(-) delete mode 100644 PlumbingRepair/PlumbingRepair/Form1.Designer.cs delete mode 100644 PlumbingRepair/PlumbingRepair/Form1.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormComponent.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormComponent.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormComponent.resx create mode 100644 PlumbingRepair/PlumbingRepair/FormComponents.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormComponents.cs rename PlumbingRepair/PlumbingRepair/{Form1.resx => FormComponents.resx} (100%) create mode 100644 PlumbingRepair/PlumbingRepair/FormCreateOrder.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormCreateOrder.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormCreateOrder.resx create mode 100644 PlumbingRepair/PlumbingRepair/FormMain.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormMain.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormMain.resx create mode 100644 PlumbingRepair/PlumbingRepair/FormWork.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormWork.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormWork.resx create mode 100644 PlumbingRepair/PlumbingRepair/FormWorkComponent.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormWorkComponent.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormWorkComponent.resx create mode 100644 PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormWorks.cs create mode 100644 PlumbingRepair/PlumbingRepair/FormWorks.resx diff --git a/PlumbingRepair/PlumbingRepair/Form1.Designer.cs b/PlumbingRepair/PlumbingRepair/Form1.Designer.cs deleted file mode 100644 index 0bf1336..0000000 --- a/PlumbingRepair/PlumbingRepair/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace PlumbingRepair -{ - 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/PlumbingRepair/PlumbingRepair/Form1.cs b/PlumbingRepair/PlumbingRepair/Form1.cs deleted file mode 100644 index 24cdd22..0000000 --- a/PlumbingRepair/PlumbingRepair/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace PlumbingRepair -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormComponent.Designer.cs b/PlumbingRepair/PlumbingRepair/FormComponent.Designer.cs new file mode 100644 index 0000000..c1331f3 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponent.Designer.cs @@ -0,0 +1,123 @@ +namespace PlumbingRepair +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ComponentNameLabel = new System.Windows.Forms.Label(); + this.ComponentNameTextBox = new System.Windows.Forms.TextBox(); + this.CostLabel = new System.Windows.Forms.Label(); + this.CostTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // ComponentNameLabel + // + this.ComponentNameLabel.AutoSize = true; + this.ComponentNameLabel.Location = new System.Drawing.Point(22, 20); + this.ComponentNameLabel.Name = "ComponentNameLabel"; + this.ComponentNameLabel.Size = new System.Drawing.Size(84, 20); + this.ComponentNameLabel.TabIndex = 0; + this.ComponentNameLabel.Text = "Название: "; + // + // ComponentNameTextBox + // + this.ComponentNameTextBox.Location = new System.Drawing.Point(103, 16); + this.ComponentNameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ComponentNameTextBox.Name = "ComponentNameTextBox"; + this.ComponentNameTextBox.Size = new System.Drawing.Size(238, 27); + this.ComponentNameTextBox.TabIndex = 2; + // + // CostLabel + // + this.CostLabel.AutoSize = true; + this.CostLabel.Location = new System.Drawing.Point(46, 72); + this.CostLabel.Name = "CostLabel"; + this.CostLabel.Size = new System.Drawing.Size(56, 20); + this.CostLabel.TabIndex = 3; + this.CostLabel.Text = "Цена: "; + // + // CostTextBox + // + this.CostTextBox.Location = new System.Drawing.Point(103, 68); + this.CostTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.CostTextBox.Name = "CostTextBox"; + this.CostTextBox.Size = new System.Drawing.Size(238, 27); + this.CostTextBox.TabIndex = 4; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(154, 120); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(256, 120); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 167); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.CostTextBox); + this.Controls.Add(this.CostLabel); + this.Controls.Add(this.ComponentNameTextBox); + this.Controls.Add(this.ComponentNameLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ComponentNameLabel; + private TextBox ComponentNameTextBox; + private Label CostLabel; + private TextBox CostTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormComponent.cs b/PlumbingRepair/PlumbingRepair/FormComponent.cs new file mode 100644 index 0000000..4c9c8c1 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponent.cs @@ -0,0 +1,93 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepair +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + + if (view != null) + { + ComponentNameTextBox.Text = view.ComponentName; + CostTextBox.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(ComponentNameTextBox.Text)) + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation(" "); + + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = ComponentNameTextBox.Text, + Cost = Convert.ToDouble(CostTextBox.Text) + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception(" . ."); + } + + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormComponent.resx b/PlumbingRepair/PlumbingRepair/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormComponents.Designer.cs b/PlumbingRepair/PlumbingRepair/FormComponents.Designer.cs new file mode 100644 index 0000000..5d5f0b0 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponents.Designer.cs @@ -0,0 +1,113 @@ +namespace PlumbingRepair +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = 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(2, 0); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(551, 551); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(571, 26); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(142, 45); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(571, 93); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(142, 45); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(571, 162); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(142, 45); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(571, 230); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(142, 45); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(725, 552); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormComponents.cs b/PlumbingRepair/PlumbingRepair/FormComponents.cs new file mode 100644 index 0000000..685ca8d --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponents.cs @@ -0,0 +1,110 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; + +namespace PlumbingRepair +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка компонентов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PlumbingRepair/PlumbingRepair/Form1.resx b/PlumbingRepair/PlumbingRepair/FormComponents.resx similarity index 100% rename from PlumbingRepair/PlumbingRepair/Form1.resx rename to PlumbingRepair/PlumbingRepair/FormComponents.resx diff --git a/PlumbingRepair/PlumbingRepair/FormCreateOrder.Designer.cs b/PlumbingRepair/PlumbingRepair/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..952cf4f --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormCreateOrder.Designer.cs @@ -0,0 +1,143 @@ +namespace PlumbingRepair +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.WorkNameLabel = new System.Windows.Forms.Label(); + this.CountLabel = new System.Windows.Forms.Label(); + this.SumLabel = new System.Windows.Forms.Label(); + this.WorkComboBox = new System.Windows.Forms.ComboBox(); + this.CountTextBox = new System.Windows.Forms.TextBox(); + this.SumTextBox = new System.Windows.Forms.TextBox(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SaveButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // WorkNameLabel + // + this.WorkNameLabel.AutoSize = true; + this.WorkNameLabel.Location = new System.Drawing.Point(12, 9); + this.WorkNameLabel.Name = "PackageNameLabel"; + this.WorkNameLabel.Size = new System.Drawing.Size(59, 15); + this.WorkNameLabel.TabIndex = 0; + this.WorkNameLabel.Text = "Изделие: "; + // + // CountLabel + // + this.CountLabel.AutoSize = true; + this.CountLabel.Location = new System.Drawing.Point(12, 40); + this.CountLabel.Name = "CountLabel"; + this.CountLabel.Size = new System.Drawing.Size(78, 15); + this.CountLabel.TabIndex = 1; + this.CountLabel.Text = "Количество: "; + // + // SumLabel + // + this.SumLabel.AutoSize = true; + this.SumLabel.Location = new System.Drawing.Point(12, 72); + this.SumLabel.Name = "SumLabel"; + this.SumLabel.Size = new System.Drawing.Size(51, 15); + this.SumLabel.TabIndex = 2; + this.SumLabel.Text = "Сумма: "; + // + // WorkComboBox + // + this.WorkComboBox.FormattingEnabled = true; + this.WorkComboBox.Location = new System.Drawing.Point(93, 6); + this.WorkComboBox.Name = "PackageComboBox"; + this.WorkComboBox.Size = new System.Drawing.Size(201, 23); + this.WorkComboBox.TabIndex = 3; + this.WorkComboBox.SelectedIndexChanged += new System.EventHandler(this.WorkComboBox_SelectedIndexChanged); + // + // CountTextBox + // + this.CountTextBox.Location = new System.Drawing.Point(93, 37); + this.CountTextBox.Name = "CountTextBox"; + this.CountTextBox.Size = new System.Drawing.Size(201, 23); + this.CountTextBox.TabIndex = 4; + this.CountTextBox.TextChanged += new System.EventHandler(this.CountTextBox_TextChanged); + // + // SumTextBox + // + this.SumTextBox.Location = new System.Drawing.Point(93, 69); + this.SumTextBox.Name = "SumTextBox"; + this.SumTextBox.Size = new System.Drawing.Size(201, 23); + this.SumTextBox.TabIndex = 5; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(219, 113); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(75, 23); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отменить"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(138, 113); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(75, 23); + this.SaveButton.TabIndex = 7; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(309, 153); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SumTextBox); + this.Controls.Add(this.CountTextBox); + this.Controls.Add(this.WorkComboBox); + this.Controls.Add(this.SumLabel); + this.Controls.Add(this.CountLabel); + this.Controls.Add(this.WorkNameLabel); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label WorkNameLabel; + private Label CountLabel; + private Label SumLabel; + private ComboBox WorkComboBox; + private TextBox CountTextBox; + private TextBox SumTextBox; + private Button ButtonCancel; + private Button SaveButton; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormCreateOrder.cs b/PlumbingRepair/PlumbingRepair/FormCreateOrder.cs new file mode 100644 index 0000000..fb46c74 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormCreateOrder.cs @@ -0,0 +1,134 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepair +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IWorkLogic _logicW; + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IWorkLogic logicW, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicW = logicW; + _logicO = logicO; + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий для заказа"); + + try + { + var list = _logicW.ReadList(null); + if (list != null) + { + WorkComboBox.DisplayMember = "WorkName"; + WorkComboBox.ValueMember = "Id"; + WorkComboBox.DataSource = list; + WorkComboBox.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void CalcSum() + { + if (WorkComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text)) + { + try + { + int id = Convert.ToInt32(WorkComboBox.SelectedValue); + + var product = _logicW.ReadElement(new WorkSearchModel + { + Id = id + }); + + int count = Convert.ToInt32(CountTextBox.Text); + SumTextBox.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void CountTextBox_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void WorkComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (WorkComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание заказа"); + + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + WorkId = Convert.ToInt32(WorkComboBox.SelectedValue), + WorkName = WorkComboBox.Text, + Count = Convert.ToInt32(CountTextBox.Text), + Sum = Convert.ToDouble(SumTextBox.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/PlumbingRepair/PlumbingRepair/FormCreateOrder.resx b/PlumbingRepair/PlumbingRepair/FormCreateOrder.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormCreateOrder.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/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs new file mode 100644 index 0000000..b2a825d --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs @@ -0,0 +1,173 @@ +namespace PlumbingRepair +{ + 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.MenuStrip = 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(); + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.CreateOrderButton = new System.Windows.Forms.Button(); + this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); + this.OrderReadyButton = new System.Windows.Forms.Button(); + this.IssuedOrderButton = new System.Windows.Forms.Button(); + this.UpdateListButton = new System.Windows.Forms.Button(); + this.MenuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // MenuStrip + // + this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.СправочникиToolStripMenuItem}); + this.MenuStrip.Location = new System.Drawing.Point(0, 0); + this.MenuStrip.Name = "MenuStrip"; + this.MenuStrip.Size = new System.Drawing.Size(865, 24); + this.MenuStrip.TabIndex = 0; + this.MenuStrip.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 = "Cправочники"; + // + // ИзделияToolStripMenuItem + // + this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.ИзделияToolStripMenuItem.Text = "Изделия"; + this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + // + // КомпонентыToolStripMenuItem + // + this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.КомпонентыToolStripMenuItem.Text = "Компоненты"; + this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(0, 27); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(722, 421); + this.DataGridView.TabIndex = 1; + // + // CreateOrderButton + // + this.CreateOrderButton.Location = new System.Drawing.Point(728, 28); + this.CreateOrderButton.Name = "CreateOrderButton"; + this.CreateOrderButton.Size = new System.Drawing.Size(125, 33); + this.CreateOrderButton.TabIndex = 2; + this.CreateOrderButton.Text = "Создать заказ"; + this.CreateOrderButton.UseVisualStyleBackColor = true; + this.CreateOrderButton.Click += new System.EventHandler(this.CreateOrderButton_Click); + // + // TakeOrderInWorkButton + // + this.TakeOrderInWorkButton.Location = new System.Drawing.Point(728, 83); + this.TakeOrderInWorkButton.Name = "TakeOrderInWorkButton"; + this.TakeOrderInWorkButton.Size = new System.Drawing.Size(125, 39); + this.TakeOrderInWorkButton.TabIndex = 3; + this.TakeOrderInWorkButton.Text = "Отдать на выполнение"; + this.TakeOrderInWorkButton.UseVisualStyleBackColor = true; + this.TakeOrderInWorkButton.Click += new System.EventHandler(this.TakeOrderInWorkButton_Click); + // + // OrderReadyButton + // + this.OrderReadyButton.Location = new System.Drawing.Point(728, 146); + this.OrderReadyButton.Name = "OrderReadyButton"; + this.OrderReadyButton.Size = new System.Drawing.Size(125, 33); + this.OrderReadyButton.TabIndex = 4; + this.OrderReadyButton.Text = "Заказ готов"; + this.OrderReadyButton.UseVisualStyleBackColor = true; + this.OrderReadyButton.Click += new System.EventHandler(this.OrderReadyButton_Click); + // + // IssuedOrderButton + // + this.IssuedOrderButton.Location = new System.Drawing.Point(728, 204); + this.IssuedOrderButton.Name = "IssuedOrderButton"; + this.IssuedOrderButton.Size = new System.Drawing.Size(125, 33); + this.IssuedOrderButton.TabIndex = 5; + this.IssuedOrderButton.Text = "Заказ выдан"; + this.IssuedOrderButton.UseVisualStyleBackColor = true; + this.IssuedOrderButton.Click += new System.EventHandler(this.IssuedOrderButton_Click); + // + // UpdateListButton + // + this.UpdateListButton.Location = new System.Drawing.Point(728, 262); + this.UpdateListButton.Name = "UpdateListButton"; + this.UpdateListButton.Size = new System.Drawing.Size(125, 33); + this.UpdateListButton.TabIndex = 6; + this.UpdateListButton.Text = "Обновить список"; + this.UpdateListButton.UseVisualStyleBackColor = true; + this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(865, 450); + this.Controls.Add(this.UpdateListButton); + this.Controls.Add(this.IssuedOrderButton); + this.Controls.Add(this.OrderReadyButton); + this.Controls.Add(this.TakeOrderInWorkButton); + this.Controls.Add(this.CreateOrderButton); + this.Controls.Add(this.DataGridView); + this.Controls.Add(this.MenuStrip); + this.MainMenuStrip = this.MenuStrip; + this.Name = "FormMain"; + this.Text = "Установка ПО"; + this.MenuStrip.ResumeLayout(false); + this.MenuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip MenuStrip; + private ToolStripMenuItem СправочникиToolStripMenuItem; + private ToolStripMenuItem ИзделияToolStripMenuItem; + private ToolStripMenuItem КомпонентыToolStripMenuItem; + private DataGridView DataGridView; + private Button CreateOrderButton; + private Button TakeOrderInWorkButton; + private Button OrderReadyButton; + private Button IssuedOrderButton; + private Button UpdateListButton; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormMain.cs b/PlumbingRepair/PlumbingRepair/FormMain.cs new file mode 100644 index 0000000..c926035 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormMain.cs @@ -0,0 +1,190 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairDataModels.Enums; + +namespace PlumbingRepair +{ + 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["WorkId"].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(FormComponents)); + + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWorks)); + + if (service is FormWorks form) + { + form.ShowDialog(); + } + } + + private void CreateOrderButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void TakeOrderInWorkButton_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, + WorkId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["WorkId"].Value), + WorkName = DataGridView.SelectedRows[0].Cells["WorkName"].Value.ToString(), + Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].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 IssuedOrderButton_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, + WorkId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["WorkId"].Value), + WorkName = DataGridView.SelectedRows[0].Cells["WorkName"].Value.ToString(), + Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].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 OrderReadyButton_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, + WorkId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["WorkId"].Value), + WorkName = DataGridView.SelectedRows[0].Cells["WorkName"].Value.ToString(), + Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].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 UpdateListButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PlumbingRepair/PlumbingRepair/FormMain.resx b/PlumbingRepair/PlumbingRepair/FormMain.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormMain.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/PlumbingRepair/PlumbingRepair/FormWork.Designer.cs b/PlumbingRepair/PlumbingRepair/FormWork.Designer.cs new file mode 100644 index 0000000..a6164e8 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWork.Designer.cs @@ -0,0 +1,252 @@ +namespace PlumbingRepair +{ + partial class FormWork + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + this.WorkNameLabel = new System.Windows.Forms.Label(); + this.PriceLabel = new System.Windows.Forms.Label(); + this.WorkNameTextBox = new System.Windows.Forms.TextBox(); + this.PriceTextBox = new System.Windows.Forms.TextBox(); + this.ComponentsGroupBox = new System.Windows.Forms.GroupBox(); + this.UpdateButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.AddButton = new System.Windows.Forms.Button(); + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ComponentNameField = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ComponentsGroupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // WorkNameLabel + // + this.WorkNameLabel.AutoSize = true; + this.WorkNameLabel.Location = new System.Drawing.Point(12, 9); + this.WorkNameLabel.Name = "PackageNameLabel"; + this.WorkNameLabel.Size = new System.Drawing.Size(65, 15); + this.WorkNameLabel.TabIndex = 0; + this.WorkNameLabel.Text = "Название: "; + // + // PriceLabel + // + this.PriceLabel.AutoSize = true; + this.PriceLabel.Location = new System.Drawing.Point(12, 43); + this.PriceLabel.Name = "PriceLabel"; + this.PriceLabel.Size = new System.Drawing.Size(73, 15); + this.PriceLabel.TabIndex = 1; + this.PriceLabel.Text = "Стоимость: "; + // + // WorkNameTextBox + // + this.WorkNameTextBox.Location = new System.Drawing.Point(83, 6); + this.WorkNameTextBox.Name = "PackageNameTextBox"; + this.WorkNameTextBox.Size = new System.Drawing.Size(283, 23); + this.WorkNameTextBox.TabIndex = 2; + // + // PriceTextBox + // + this.PriceTextBox.Location = new System.Drawing.Point(83, 40); + this.PriceTextBox.Name = "PriceTextBox"; + this.PriceTextBox.Size = new System.Drawing.Size(283, 23); + this.PriceTextBox.TabIndex = 3; + // + // ComponentsGroupBox + // + this.ComponentsGroupBox.Controls.Add(this.UpdateButton); + this.ComponentsGroupBox.Controls.Add(this.DeleteButton); + this.ComponentsGroupBox.Controls.Add(this.ChangeButton); + this.ComponentsGroupBox.Controls.Add(this.AddButton); + this.ComponentsGroupBox.Controls.Add(this.DataGridView); + this.ComponentsGroupBox.Location = new System.Drawing.Point(12, 80); + this.ComponentsGroupBox.Name = "ComponentsGroupBox"; + this.ComponentsGroupBox.Size = new System.Drawing.Size(722, 350); + this.ComponentsGroupBox.TabIndex = 5; + this.ComponentsGroupBox.TabStop = false; + this.ComponentsGroupBox.Text = "Компоненты"; + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(590, 203); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(110, 38); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(590, 143); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(110, 38); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(590, 82); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(110, 38); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(590, 22); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(110, 38); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // DataGridView + // + dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.DataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ComponentNameField, + this.CountField}); + dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.DataGridView.DefaultCellStyle = dataGridViewCellStyle2; + this.DataGridView.Location = new System.Drawing.Point(6, 22); + this.DataGridView.Name = "DataGridView"; + dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle3.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.DataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle3; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(561, 322); + this.DataGridView.TabIndex = 0; + // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.Name = "ID"; + this.ID.Visible = false; + // + // ComponentNameField + // + this.ComponentNameField.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ComponentNameField.HeaderText = "Компонент"; + this.ComponentNameField.Name = "ComponentNameField"; + // + // CountField + // + this.CountField.HeaderText = "Количество"; + this.CountField.Name = "CountField"; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(602, 446); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(110, 34); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(486, 446); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(110, 34); + this.SaveButton.TabIndex = 8; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // FormWork + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(746, 498); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ComponentsGroupBox); + this.Controls.Add(this.PriceTextBox); + this.Controls.Add(this.WorkNameTextBox); + this.Controls.Add(this.PriceLabel); + this.Controls.Add(this.WorkNameLabel); + this.Name = "FormWork"; + this.Text = "Изделие"; + this.ComponentsGroupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label WorkNameLabel; + private Label PriceLabel; + private TextBox WorkNameTextBox; + private TextBox PriceTextBox; + private GroupBox ComponentsGroupBox; + private Button UpdateButton; + private Button DeleteButton; + private Button ChangeButton; + private Button AddButton; + private DataGridView DataGridView; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ComponentNameField; + private DataGridViewTextBoxColumn CountField; + private Button ButtonCancel; + private Button SaveButton; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormWork.cs b/PlumbingRepair/PlumbingRepair/FormWork.cs new file mode 100644 index 0000000..2d1092c --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWork.cs @@ -0,0 +1,229 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairDataModels.Models; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace PlumbingRepair +{ + public partial class FormWork : Form + { + private readonly ILogger _logger; + + private readonly IWorkLogic _logic; + + private int? _id; + + private Dictionary _workComponents; + + public int Id { set { _id = value; } } + public FormWork(ILogger logger, IWorkLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _workComponents = new Dictionary(); + } + private void FormWork_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + + try + { + var view = _logic.ReadElement(new WorkSearchModel + { + Id = _id.Value + }); + + if (view != null) + { + WorkNameTextBox.Text = view.WorkName; + PriceTextBox.Text = view.Price.ToString(); + _workComponents = view.WorkComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + + try + { + if (_workComponents != null) + { + DataGridView.Rows.Clear(); + foreach (var pc in _workComponents) + { + DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + PriceTextBox.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); + + if (service is FormWorkComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + + if (_workComponents.ContainsKey(form.Id)) + { + _workComponents[form.Id] = (form.ComponentModel, form.Count); + } + + else + { + _workComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + + LoadData(); + } + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWorkComponent)); + + if (service is FormWorkComponent form) + { + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _workComponents[id].Item2; + + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _workComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", DataGridView.SelectedRows[0].Cells[1].Value); + _workComponents?.Remove(Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(WorkNameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(PriceTextBox.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (_workComponents == null || _workComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение изделия"); + + try + { + var model = new WorkBindingModel + { + Id = _id ?? 0, + WorkName = WorkNameTextBox.Text, + Price = Convert.ToDouble(PriceTextBox.Text), + WorkComponents = _workComponents + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private double CalcPrice() + { + double price = 0; + + foreach (var elem in _workComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/PlumbingRepair/PlumbingRepair/FormWork.resx b/PlumbingRepair/PlumbingRepair/FormWork.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWork.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/PlumbingRepair/PlumbingRepair/FormWorkComponent.Designer.cs b/PlumbingRepair/PlumbingRepair/FormWorkComponent.Designer.cs new file mode 100644 index 0000000..84f0d59 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWorkComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace PlumbingRepair +{ + partial class FormWorkComponent + { + /// + /// 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.ComponentSelectLabel = new System.Windows.Forms.Label(); + this.CountLabel = new System.Windows.Forms.Label(); + this.ComponentComboBox = new System.Windows.Forms.ComboBox(); + this.CountTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // ComponentSelectLabel + // + this.ComponentSelectLabel.AutoSize = true; + this.ComponentSelectLabel.Location = new System.Drawing.Point(26, 20); + this.ComponentSelectLabel.Name = "ComponentSelectLabel"; + this.ComponentSelectLabel.Size = new System.Drawing.Size(75, 15); + this.ComponentSelectLabel.TabIndex = 0; + this.ComponentSelectLabel.Text = "Компонент: "; + // + // CountLabel + // + this.CountLabel.AutoSize = true; + this.CountLabel.Location = new System.Drawing.Point(26, 56); + this.CountLabel.Name = "CountLabel"; + this.CountLabel.Size = new System.Drawing.Size(78, 15); + this.CountLabel.TabIndex = 1; + this.CountLabel.Text = "Количество: "; + // + // ComponentComboBox + // + this.ComponentComboBox.FormattingEnabled = true; + this.ComponentComboBox.Location = new System.Drawing.Point(107, 17); + this.ComponentComboBox.Name = "ComponentComboBox"; + this.ComponentComboBox.Size = new System.Drawing.Size(190, 23); + this.ComponentComboBox.TabIndex = 2; + // + // CountTextBox + // + this.CountTextBox.Location = new System.Drawing.Point(107, 53); + this.CountTextBox.Name = "CountTextBox"; + this.CountTextBox.Size = new System.Drawing.Size(190, 23); + this.CountTextBox.TabIndex = 3; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(141, 98); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(75, 23); + this.SaveButton.TabIndex = 4; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(222, 98); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(75, 23); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormWorkComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(337, 141); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.CountTextBox); + this.Controls.Add(this.ComponentComboBox); + this.Controls.Add(this.CountLabel); + this.Controls.Add(this.ComponentSelectLabel); + this.Name = "FormWorkComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ComponentSelectLabel; + private Label CountLabel; + private ComboBox ComponentComboBox; + private TextBox CountTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormWorkComponent.cs b/PlumbingRepair/PlumbingRepair/FormWorkComponent.cs new file mode 100644 index 0000000..c3824ec --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWorkComponent.cs @@ -0,0 +1,86 @@ +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepair +{ + public partial class FormWorkComponent : Form + { + private readonly List? _list; + + public int Id + { + get + { + return Convert.ToInt32(ComponentComboBox.SelectedValue); + } + set + { + ComponentComboBox.SelectedValue = value; + } + } + + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set { CountTextBox.Text = value.ToString(); } + } + + public FormWorkComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + ComponentComboBox.DisplayMember = "ComponentName"; + ComponentComboBox.ValueMember = "Id"; + ComponentComboBox.DataSource = _list; + ComponentComboBox.SelectedItem = null; + } + } + + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (ComponentComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PlumbingRepair/PlumbingRepair/FormWorkComponent.resx b/PlumbingRepair/PlumbingRepair/FormWorkComponent.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWorkComponent.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/PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs b/PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs new file mode 100644 index 0000000..882dac0 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs @@ -0,0 +1,113 @@ +namespace PlumbingRepair +{ + partial class FormWorks + { + /// + /// 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.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = 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(1, 1); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(562, 495); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(585, 12); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(120, 41); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(585, 71); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(120, 41); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(585, 130); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(120, 41); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(585, 191); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(120, 41); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormWorks + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(717, 502); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Name = "FormWorks"; + this.Text = "Изделия"; + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormWorks.cs b/PlumbingRepair/PlumbingRepair/FormWorks.cs new file mode 100644 index 0000000..5cbebac --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWorks.cs @@ -0,0 +1,111 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; + +namespace PlumbingRepair +{ + public partial class FormWorks : Form + { + private readonly ILogger _logger; + private readonly IWorkLogic _logic; + + public FormWorks(ILogger logger, IWorkLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["WorkName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["WorkComponents"].Visible = false; + } + + _logger.LogInformation("Загрузка изделий"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWork)); + + if (service is FormWork form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWork)); + + if (service is FormWork form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_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 WorkBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PlumbingRepair/PlumbingRepair/FormWorks.resx b/PlumbingRepair/PlumbingRepair/FormWorks.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWorks.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/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj b/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj index b57c89e..c4e6d25 100644 --- a/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj +++ b/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj @@ -8,4 +8,9 @@ enable + + + + + \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/Program.cs b/PlumbingRepair/PlumbingRepair/Program.cs index 9bc4817..1d4535b 100644 --- a/PlumbingRepair/PlumbingRepair/Program.cs +++ b/PlumbingRepair/PlumbingRepair/Program.cs @@ -11,7 +11,7 @@ namespace PlumbingRepair // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormComponent()); } } } \ No newline at end of file