diff --git a/PlumbingRepair/PlumbingRepair.sln b/PlumbingRepair/PlumbingRepair.sln index c6873d0..52166b3 100644 --- a/PlumbingRepair/PlumbingRepair.sln +++ b/PlumbingRepair/PlumbingRepair.sln @@ -1,25 +1,49 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.6.33801.468 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepair", "PlumbingRepair\PlumbingRepair.csproj", "{16CDF38C-189C-4BED-AB66-DB3C212C4047}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {16CDF38C-189C-4BED-AB66-DB3C212C4047}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {16CDF38C-189C-4BED-AB66-DB3C212C4047}.Debug|Any CPU.Build.0 = Debug|Any CPU - {16CDF38C-189C-4BED-AB66-DB3C212C4047}.Release|Any CPU.ActiveCfg = Release|Any CPU - {16CDF38C-189C-4BED-AB66-DB3C212C4047}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {1BA93531-B041-4CEC-AEAB-2877EA63E1E5} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33801.468 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairView", "PlumbingRepair\PlumbingRepairView.csproj", "{16CDF38C-189C-4BED-AB66-DB3C212C4047}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairDataModels", "PlumbingRepairDataModels\PlumbingRepairDataModels.csproj", "{F62B3ADF-0FE7-4066-BEF7-5DB0AE1A53A9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairContracts", "PlumbingRepairContracts\PlumbingRepairContracts.csproj", "{FD429137-A114-4447-B51A-FCC11FEF7E2C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairBusinessLogic", "PlumbingRepairBusinessLogic\PlumbingRepairBusinessLogic.csproj", "{B960E476-E516-4BAA-B5D7-55F29B376993}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairListImplement", "PlumbingRepairListImplement\PlumbingRepairListImplement.csproj", "{E89CA82F-2FEA-4235-93A2-E5A412D0116F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {16CDF38C-189C-4BED-AB66-DB3C212C4047}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16CDF38C-189C-4BED-AB66-DB3C212C4047}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16CDF38C-189C-4BED-AB66-DB3C212C4047}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16CDF38C-189C-4BED-AB66-DB3C212C4047}.Release|Any CPU.Build.0 = Release|Any CPU + {F62B3ADF-0FE7-4066-BEF7-5DB0AE1A53A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F62B3ADF-0FE7-4066-BEF7-5DB0AE1A53A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F62B3ADF-0FE7-4066-BEF7-5DB0AE1A53A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F62B3ADF-0FE7-4066-BEF7-5DB0AE1A53A9}.Release|Any CPU.Build.0 = Release|Any CPU + {FD429137-A114-4447-B51A-FCC11FEF7E2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FD429137-A114-4447-B51A-FCC11FEF7E2C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FD429137-A114-4447-B51A-FCC11FEF7E2C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FD429137-A114-4447-B51A-FCC11FEF7E2C}.Release|Any CPU.Build.0 = Release|Any CPU + {B960E476-E516-4BAA-B5D7-55F29B376993}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B960E476-E516-4BAA-B5D7-55F29B376993}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B960E476-E516-4BAA-B5D7-55F29B376993}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B960E476-E516-4BAA-B5D7-55F29B376993}.Release|Any CPU.Build.0 = Release|Any CPU + {E89CA82F-2FEA-4235-93A2-E5A412D0116F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E89CA82F-2FEA-4235-93A2-E5A412D0116F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E89CA82F-2FEA-4235-93A2-E5A412D0116F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E89CA82F-2FEA-4235-93A2-E5A412D0116F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1BA93531-B041-4CEC-AEAB-2877EA63E1E5} + EndGlobalSection +EndGlobal 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..d5db281 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponent.Designer.cs @@ -0,0 +1,117 @@ +namespace PlumbingRepairView +{ + 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() + { + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + labelName = new Label(); + labelCost = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(140, 13); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(168, 31); + textBoxName.TabIndex = 0; + // + // textBoxCost + // + textBoxCost.Location = new Point(140, 58); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(168, 31); + textBoxCost.TabIndex = 1; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(10, 19); + labelName.Name = "labelName"; + labelName.Size = new Size(94, 25); + labelName.TabIndex = 2; + labelName.Text = "Название:"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(12, 64); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(57, 25); + labelCost.TabIndex = 3; + labelCost.Text = "Цена:"; + // + // buttonSave + // + buttonSave.Location = new Point(163, 95); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(112, 34); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(281, 95); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 34); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(374, 141); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCost); + Controls.Add(labelName); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Name = "FormComponent"; + Text = "Компонент"; + ResumeLayout(false); + 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/PlumbingRepair/PlumbingRepair/FormComponent.cs b/PlumbingRepair/PlumbingRepair/FormComponent.cs new file mode 100644 index 0000000..c080e07 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponent.cs @@ -0,0 +1,87 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using System.Windows.Forms; + +namespace PlumbingRepairView +{ + 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) + { + textBoxName.Text = view.ComponentName; + 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 ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception(" . ."); + } + 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..a395bff --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponent.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/FormComponents.Designer.cs b/PlumbingRepair/PlumbingRepair/FormComponents.Designer.cs new file mode 100644 index 0000000..5e091c0 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponents.Designer.cs @@ -0,0 +1,119 @@ +namespace PlumbingRepairView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonDel = new Button(); + buttonChange = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(10, 8); + dataGridView.Margin = new Padding(2, 2, 2, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.Size = new Size(512, 404); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(547, 33); + buttonAdd.Margin = new Padding(2, 2, 2, 2); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(108, 27); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(547, 85); + buttonDel.Margin = new Padding(2, 2, 2, 2); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(108, 27); + buttonDel.TabIndex = 2; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonChange + // + buttonChange.Location = new Point(547, 147); + buttonChange.Margin = new Padding(2, 2, 2, 2); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(108, 27); + buttonChange.TabIndex = 3; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonUpd_Click; + // + // buttonRef + // + buttonRef.Location = new Point(547, 209); + buttonRef.Margin = new Padding(2, 2, 2, 2); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(108, 27); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(678, 422); + Controls.Add(buttonRef); + Controls.Add(buttonChange); + Controls.Add(buttonDel); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(2, 2, 2, 2); + Name = "FormComponents"; + Text = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonDel; + private Button buttonChange; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormComponents.cs b/PlumbingRepair/PlumbingRepair/FormComponents.cs new file mode 100644 index 0000000..3b86239 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponents.cs @@ -0,0 +1,102 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; + +namespace PlumbingRepairView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent 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(FormComponent)); + if (service is FormComponent 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 ComponentBindingModel + { + 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/PlumbingRepair/PlumbingRepair/FormComponents.resx b/PlumbingRepair/PlumbingRepair/FormComponents.resx new file mode 100644 index 0000000..0f362c9 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormComponents.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/FormCreateOrder.Designer.cs b/PlumbingRepair/PlumbingRepair/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..564b4b3 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormCreateOrder.Designer.cs @@ -0,0 +1,143 @@ +namespace PlumbingRepairView +{ + 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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + comboBoxWork = new ComboBox(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(23, 18); + label1.Name = "label1"; + label1.Size = new Size(60, 20); + label1.TabIndex = 0; + label1.Text = "Работа:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(23, 55); + label2.Name = "label2"; + label2.Size = new Size(93, 20); + label2.TabIndex = 1; + label2.Text = "Количество:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(23, 92); + label3.Name = "label3"; + label3.Size = new Size(58, 20); + label3.TabIndex = 2; + label3.Text = "Сумма:"; + // + // buttonCancel + // + buttonCancel.Location = new Point(389, 139); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(289, 139); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(142, 55); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(341, 27); + textBoxCount.TabIndex = 5; + textBoxCount.TextChanged += textBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(142, 92); + textBoxSum.Name = "textBoxSum"; + textBoxSum.Size = new Size(341, 27); + textBoxSum.TabIndex = 6; + // + // comboBoxWork + // + comboBoxWork.FormattingEnabled = true; + comboBoxWork.Location = new Point(142, 18); + comboBoxWork.Name = "comboBoxWork"; + comboBoxWork.Size = new Size(341, 28); + comboBoxWork.TabIndex = 7; + comboBoxWork.SelectedIndexChanged += comboBoxWork_SelectedIndexChanged; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(495, 180); + Controls.Add(comboBoxWork); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormCreateOrder"; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private TextBox textBoxSum; + private ComboBox comboBoxWork; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormCreateOrder.cs b/PlumbingRepair/PlumbingRepair/FormCreateOrder.cs new file mode 100644 index 0000000..b12da69 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormCreateOrder.cs @@ -0,0 +1,141 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.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 PlumbingRepairView +{ + 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) + { + comboBoxWork.DisplayMember = "WorkName"; + comboBoxWork.ValueMember = "Id"; + comboBoxWork.DataSource = list; + comboBoxWork.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 (comboBoxWork.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxWork.SelectedValue); + + var product = _logicW.ReadElement(new WorkSearchModel + { + Id = id + }); + + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.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 textBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void comboBoxWork_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxWork.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание заказа"); + + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + WorkId = Convert.ToInt32(comboBoxWork.SelectedValue), + WorkName = comboBoxWork.Text, + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.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..0f362c9 --- /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..d0970cd --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs @@ -0,0 +1,172 @@ +namespace PlumbingRepairView +{ + 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() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + работыToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonUpdateList = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(819, 28); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, работыToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; + // + // работыToolStripMenuItem + // + работыToolStripMenuItem.Name = "работыToolStripMenuItem"; + работыToolStripMenuItem.Size = new Size(182, 26); + работыToolStripMenuItem.Text = "Работы"; + работыToolStripMenuItem.Click += работыToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 31); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(586, 420); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(608, 44); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(170, 29); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(608, 132); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(170, 29); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(608, 223); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(170, 29); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(608, 313); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(170, 29); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonUpdateList + // + buttonUpdateList.Location = new Point(608, 384); + buttonUpdateList.Name = "buttonUpdateList"; + buttonUpdateList.Size = new Size(170, 29); + buttonUpdateList.TabIndex = 6; + buttonUpdateList.Text = "Обновить список"; + buttonUpdateList.UseVisualStyleBackColor = true; + buttonUpdateList.Click += buttonUpdateList_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(819, 474); + Controls.Add(buttonUpdateList); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Ремонт сантехники"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonUpdateList; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem работыToolStripMenuItem; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormMain.cs b/PlumbingRepair/PlumbingRepair/FormMain.cs new file mode 100644 index 0000000..3ba4a05 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormMain.cs @@ -0,0 +1,199 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairDataModels.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 PlumbingRepairView +{ + 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 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, + 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 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.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("Ошибка при сохранении. Дополнительная информация в логах."); + } + + 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.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("Ошибка при сохранении. Дополнительная информация в логах."); + } + + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonUpdateList_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PlumbingRepair/PlumbingRepair/FormMain.resx b/PlumbingRepair/PlumbingRepair/FormMain.resx new file mode 100644 index 0000000..069f056 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormWork.Designer.cs b/PlumbingRepair/PlumbingRepair/FormWork.Designer.cs new file mode 100644 index 0000000..7efd0de --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWork.Designer.cs @@ -0,0 +1,241 @@ +namespace PlumbingRepairView +{ + 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() + { + label1 = new Label(); + label2 = new Label(); + groupBox1 = new GroupBox(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ComponentId = new DataGridViewTextBoxColumn(); + ComponentName = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(40, 12); + label1.Margin = new Padding(4, 0, 4, 0); + label1.Name = "label1"; + label1.Size = new Size(94, 25); + label1.TabIndex = 0; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(40, 61); + label2.Margin = new Padding(4, 0, 4, 0); + label2.Name = "label2"; + label2.Size = new Size(103, 25); + label2.TabIndex = 1; + label2.Text = "Стоимость:"; + // + // groupBox1 + // + groupBox1.Controls.Add(buttonRef); + groupBox1.Controls.Add(buttonDel); + groupBox1.Controls.Add(buttonUpd); + groupBox1.Controls.Add(buttonAdd); + groupBox1.Controls.Add(dataGridView); + groupBox1.Location = new Point(40, 108); + groupBox1.Margin = new Padding(4, 4, 4, 4); + groupBox1.Name = "groupBox1"; + groupBox1.Padding = new Padding(4, 4, 4, 4); + groupBox1.Size = new Size(945, 384); + groupBox1.TabIndex = 2; + groupBox1.TabStop = false; + groupBox1.Text = "Компоненты"; + // + // buttonRef + // + buttonRef.Location = new Point(752, 258); + buttonRef.Margin = new Padding(4, 4, 4, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(118, 36); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += UpdateButton_Click; + // + // buttonDel + // + buttonDel.Location = new Point(752, 190); + buttonDel.Margin = new Padding(4, 4, 4, 4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(118, 36); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += DeleteButton_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(752, 122); + buttonUpd.Margin = new Padding(4, 4, 4, 4); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(118, 36); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ChangeButton_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(752, 55); + buttonAdd.Margin = new Padding(4, 4, 4, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(118, 36); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += AddButton_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ComponentId, ComponentName, Count }); + dataGridView.Location = new Point(0, 32); + dataGridView.Margin = new Padding(4, 4, 4, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(668, 344); + dataGridView.TabIndex = 0; + // + // ComponentId + // + ComponentId.HeaderText = "Id"; + ComponentId.MinimumWidth = 6; + ComponentId.Name = "ComponentId"; + ComponentId.Visible = false; + ComponentId.Width = 125; + // + // ComponentName + // + ComponentName.HeaderText = "Компонент"; + ComponentName.MinimumWidth = 6; + ComponentName.Name = "ComponentName"; + ComponentName.Width = 355; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.Width = 125; + // + // textBoxName + // + textBoxName.Location = new Point(188, 12); + textBoxName.Margin = new Padding(4, 4, 4, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(373, 31); + textBoxName.TabIndex = 3; + // + // textBoxCost + // + textBoxCost.Location = new Point(188, 61); + textBoxCost.Margin = new Padding(4, 4, 4, 4); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(256, 31); + textBoxCost.TabIndex = 4; + // + // buttonCancel + // + buttonCancel.Location = new Point(857, 511); + buttonCancel.Margin = new Padding(4, 4, 4, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(118, 36); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(731, 511); + buttonSave.Margin = new Padding(4, 4, 4, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(118, 36); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += SaveButton_Click; + // + // FormWork + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1000, 562); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(groupBox1); + Controls.Add(label2); + Controls.Add(label1); + Margin = new Padding(4, 4, 4, 4); + Name = "FormWork"; + Text = "Работа"; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private GroupBox groupBox1; + private DataGridView dataGridView; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn ComponentId; + private DataGridViewTextBoxColumn ComponentName; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/FormWork.cs b/PlumbingRepair/PlumbingRepair/FormWork.cs new file mode 100644 index 0000000..d79d70e --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWork.cs @@ -0,0 +1,237 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PlumbingRepairView +{ + 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) + { + textBoxName.Text = view.WorkName; + textBoxCost.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 }); + } + textBoxCost.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(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(textBoxCost.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 = textBoxName.Text, + Price = Convert.ToDouble(textBoxCost.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..a395bff --- /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..7ae6a31 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWorkComponent.Designer.cs @@ -0,0 +1,125 @@ +namespace PlumbingRepairView +{ + 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() + { + comboBoxComponent = new ComboBox(); + labelComponent = new Label(); + labelCount = new Label(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(110, 10); + comboBoxComponent.Margin = new Padding(2, 2, 2, 2); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(237, 28); + comboBoxComponent.TabIndex = 0; + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(10, 12); + labelComponent.Margin = new Padding(2, 0, 2, 0); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(91, 20); + labelComponent.TabIndex = 1; + labelComponent.Text = "Компонент:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(10, 55); + labelCount.Margin = new Padding(2, 0, 2, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 2; + labelCount.Text = "Количество:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(112, 55); + textBoxCount.Margin = new Padding(2, 2, 2, 2); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(235, 27); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(142, 85); + buttonSave.Margin = new Padding(2, 2, 2, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(90, 27); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(236, 85); + buttonCancel.Margin = new Padding(2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(66, 27); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormWorkComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(356, 117); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Controls.Add(comboBoxComponent); + Margin = new Padding(2, 2, 2, 2); + Name = "FormWorkComponent"; + Text = "Компонент Изделия"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxComponent; + private Label labelComponent; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonSave; + 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..38771b3 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWorkComponent.cs @@ -0,0 +1,89 @@ +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PlumbingRepairView +{ + public partial class FormWorkComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + public FormWorkComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} diff --git a/PlumbingRepair/PlumbingRepair/FormWorkComponent.resx b/PlumbingRepair/PlumbingRepair/FormWorkComponent.resx new file mode 100644 index 0000000..0f362c9 --- /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..5231cdb --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWorks.Designer.cs @@ -0,0 +1,114 @@ +namespace PlumbingRepairView +{ + 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.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(1, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(611, 449); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(670, 23); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.AddButton_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(670, 75); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ChangeButton_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(670, 132); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.DeleteButton_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(670, 188); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormWorks + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + 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 = "FormWorks"; + 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/PlumbingRepair/PlumbingRepair/FormWorks.cs b/PlumbingRepair/PlumbingRepair/FormWorks.cs new file mode 100644 index 0000000..b09fdda --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/FormWorks.cs @@ -0,0 +1,120 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.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 PlumbingRepairView +{ + 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/Form1.resx b/PlumbingRepair/PlumbingRepair/FormWorks.resx similarity index 100% rename from PlumbingRepair/PlumbingRepair/Form1.resx rename to PlumbingRepair/PlumbingRepair/FormWorks.resx diff --git a/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj b/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj deleted file mode 100644 index b57c89e..0000000 --- a/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj b/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj new file mode 100644 index 0000000..777ae54 --- /dev/null +++ b/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj @@ -0,0 +1,45 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + + \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepair/Program.cs b/PlumbingRepair/PlumbingRepair/Program.cs index 9bc4817..e7dd925 100644 --- a/PlumbingRepair/PlumbingRepair/Program.cs +++ b/PlumbingRepair/PlumbingRepair/Program.cs @@ -1,7 +1,17 @@ -namespace PlumbingRepair +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using PlumbingRepairBusinessLogic.BusinessLogics; + +namespace PlumbingRepairView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +21,33 @@ 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()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ComponentLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..f869cc4 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,113 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName: {ComponentName}.Id:{Id} ", + model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : + _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{Id}", + model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", + nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{Cost}. Id: {Id}", + model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..5fc5c55 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,140 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage + orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList.OrderId:{Id} ", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : + _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement.Id:{Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order Status incorrect."); + return false; + } + + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model); + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + + model.Status = newStatus; + + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.WorkId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.WorkId)); + } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId); + } + } +} diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkLogic.cs new file mode 100644 index 0000000..93e1f00 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkLogic.cs @@ -0,0 +1,118 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairBusinessLogic.BusinessLogics +{ + public class WorkLogic : IWorkLogic + { + private readonly ILogger _logger; + private readonly IWorkStorage _workStorage; + public WorkLogic(ILogger logger, IWorkStorage + workStorage) + { + _logger = logger; + _workStorage = workStorage; + } + public List? ReadList(WorkSearchModel? model) + { + _logger.LogInformation("ReadList. WorkName: {WorkName}.Id:{Id} ", + model?.WorkName, model?.Id); + var list = model == null ? _workStorage.GetFullList() : + _workStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public WorkViewModel? ReadElement(WorkSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. WorkName:{WorkName}.Id:{Id}", + model.WorkName, model.Id); + var element = _workStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(WorkBindingModel model) + { + CheckModel(model); + if (_workStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(WorkBindingModel model) + { + CheckModel(model); + if (_workStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(WorkBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_workStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(WorkBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.WorkName)) + { + throw new ArgumentNullException("Нет названия работы", + nameof(model.WorkName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена работы должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Work. WorkName:{WorkName}.Price:{Price}. Id: {Id}", + model.WorkName, model.Price, model.Id); + var element = _workStorage.GetElement(new WorkSearchModel + { + WorkName = model.WorkName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Работа с таким названием уже есть"); + } + } + } +} diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj b/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj new file mode 100644 index 0000000..973510f --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/ComponentBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..679aab2 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..42ed7cb --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PlumbingRepairDataModels.Models; +using PlumbingRepairDataModels.Enums; + +namespace PlumbingRepairContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int WorkId { get; set; } + public String WorkName { get; set; } = string.Empty; + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/WorkBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/WorkBindingModel.cs new file mode 100644 index 0000000..a02fe03 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/WorkBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairContracts.BindingModels +{ + public class WorkBindingModel : IWorkModel + { + public int Id { get; set; } + public string WorkName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary WorkComponents + { get; set; } = new(); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IComponentLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..ed446bd --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..7bdf845 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkLogic.cs new file mode 100644 index 0000000..bd5dba3 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkLogic.cs @@ -0,0 +1,20 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IWorkLogic + { + List? ReadList(WorkSearchModel? model); + WorkViewModel? ReadElement(WorkSearchModel model); + bool Create(WorkBindingModel model); + bool Update(WorkBindingModel model); + bool Delete(WorkBindingModel model); + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj b/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj new file mode 100644 index 0000000..667ab73 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/PlumbingRepairContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/ComponentSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..5bda8ef --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..d1df87a --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/WorkSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/WorkSearchModel.cs new file mode 100644 index 0000000..7a4c385 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/WorkSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.SearchModels +{ + public class WorkSearchModel + { + public int? Id { get; set; } + public string? WorkName { get; set; } + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IComponentStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..722b5b5 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IOrderStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..0ae4569 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IWorkStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IWorkStorage.cs new file mode 100644 index 0000000..253affd --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IWorkStorage.cs @@ -0,0 +1,21 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.StoragesContracts +{ + public interface IWorkStorage + { + List GetFullList(); + List GetFilteredList(WorkSearchModel model); + WorkViewModel? GetElement(WorkSearchModel model); + WorkViewModel? Insert(WorkBindingModel model); + WorkViewModel? Update(WorkBindingModel model); + WorkViewModel? Delete(WorkBindingModel model); + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..6ffcec2 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..7b1a30e --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using PlumbingRepairDataModels.Enums; +using PlumbingRepairDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int WorkId { get; set; } + [DisplayName("Работа")] + public string WorkName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs new file mode 100644 index 0000000..68caa32 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/WorkViewModel.cs @@ -0,0 +1,21 @@ +using PlumbingRepairDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairContracts.ViewModels +{ + public class WorkViewModel : IWorkModel + { + public int Id { get; set; } + [DisplayName("Название работы")] + public string WorkName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary WorkComponents + { get; set; } = new(); + } +} diff --git a/PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs b/PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..387ac9c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDataModels/IId.cs b/PlumbingRepair/PlumbingRepairDataModels/IId.cs new file mode 100644 index 0000000..bb2cdbd --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace PlumbingRepairDataModels +{ + public interface IId + { + int Id { get; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDataModels/Models/IComponentModel.cs b/PlumbingRepair/PlumbingRepairDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..dd84a9f --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs b/PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..330360c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using PlumbingRepairDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairDataModels.Models +{ + public interface IOrderModel : IId + { + int WorkId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/PlumbingRepair/PlumbingRepairDataModels/Models/IWorkModel.cs b/PlumbingRepair/PlumbingRepairDataModels/Models/IWorkModel.cs new file mode 100644 index 0000000..3bd0de3 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/Models/IWorkModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairDataModels.Models +{ + public interface IWorkModel : IId + { + string WorkName { get; } + double Price { get; } + Dictionary WorkComponents { get; } + } +} diff --git a/PlumbingRepair/PlumbingRepairDataModels/PlumbingRepairDataModels.csproj b/PlumbingRepair/PlumbingRepairDataModels/PlumbingRepairDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/PlumbingRepairDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs b/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs new file mode 100644 index 0000000..93d388a --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using PlumbingRepairListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Works { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Works = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/ComponentStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..8c350cb --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,107 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..ab24931 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs @@ -0,0 +1,105 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/WorkStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/WorkStorage.cs new file mode 100644 index 0000000..7e3846d --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/WorkStorage.cs @@ -0,0 +1,126 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairListImplement.Implements +{ + public class WorkStorage : IWorkStorage + { + private readonly DataListSingleton _source; + + public WorkStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + + foreach (var work in _source.Works) + { + result.Add(work.GetViewModel); + } + + return result; + } + + public List GetFilteredList(WorkSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.WorkName)) + { + return result; + } + + foreach (var work in _source.Works) + { + if (work.WorkName.Contains(model.WorkName)) + { + result.Add(work.GetViewModel); + } + } + + return result; + } + + public WorkViewModel? GetElement(WorkSearchModel model) + { + if (string.IsNullOrEmpty(model.WorkName) && !model.Id.HasValue) + { + return null; + } + + foreach (var work in _source.Works) + { + if ((!string.IsNullOrEmpty(model.WorkName) && work.WorkName == model.WorkName) || (model.Id.HasValue && work.Id == model.Id)) + { + return work.GetViewModel; + } + } + + return null; + } + + public WorkViewModel? Insert(WorkBindingModel model) + { + model.Id = 1; + + foreach (var work in _source.Works) + { + if (model.Id <= work.Id) + { + model.Id = work.Id + 1; + } + } + + var newWork = Work.Create(model); + + if (newWork == null) + { + return null; + } + + _source.Works.Add(newWork); + + return newWork.GetViewModel; + } + + public WorkViewModel? Update(WorkBindingModel model) + { + foreach (var work in _source.Works) + { + if (work.Id == model.Id) + { + work.Update(model); + return work.GetViewModel; + } + } + + return null; + } + + public WorkViewModel? Delete(WorkBindingModel model) + { + for (int i = 0; i < _source.Works.Count; ++i) + { + if (_source.Works[i].Id == model.Id) + { + var element = _source.Works[i]; + _source.Works.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs new file mode 100644 index 0000000..a84a43e --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs new file mode 100644 index 0000000..1a2420e --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs @@ -0,0 +1,65 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Enums; +using PlumbingRepairDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int WorkId { get; private set; } + public String WorkName { get; private set; } = string.Empty; + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if(model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + WorkId = model.WorkId, + WorkName = model.WorkName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + WorkId = WorkId, + WorkName = WorkName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs new file mode 100644 index 0000000..2971326 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs @@ -0,0 +1,55 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairListImplement.Models +{ + public class Work : IWorkModel + { + public int Id { get; private set; } + public string WorkName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary WorkComponents + { + get; + private set; + } = new Dictionary(); + public static Work? Create(WorkBindingModel? model) + { + if (model == null) + { + return null; + } + return new Work() + { + Id = model.Id, + WorkName = model.WorkName, + Price = model.Price, + WorkComponents = model.WorkComponents + }; + } + public void Update(WorkBindingModel? model) + { + if (model == null) + { + return; + } + WorkName = model.WorkName; + Price = model.Price; + WorkComponents = model.WorkComponents; + } + public WorkViewModel GetViewModel => new() + { + Id = Id, + WorkName = WorkName, + Price = Price, + WorkComponents = WorkComponents + }; + } +} diff --git a/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj b/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj new file mode 100644 index 0000000..05f8377 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/PlumbingRepairListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj b/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj new file mode 100644 index 0000000..4194bad --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/PlumbingRepairView.csproj @@ -0,0 +1,22 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/Program.cs b/PlumbingRepair/PlumbingRepairView/Program.cs new file mode 100644 index 0000000..9aa4ced --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/Program.cs @@ -0,0 +1,53 @@ +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using PlumbingRepairBusinessLogic.BusinessLogics; + +namespace PlumbingRepairView +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } +} \ No newline at end of file