From e2c3254b36aea618db91853e7479e49396867b43 Mon Sep 17 00:00:00 2001 From: marusya Date: Wed, 7 Feb 2024 19:42:14 +0400 Subject: [PATCH] =?UTF-8?q?1=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TravelCompany/TravelCompany.sln | 26 +- TravelCompany/TravelCompany/Form1.Designer.cs | 39 --- TravelCompany/TravelCompany/Form1.cs | 10 - .../TravelCompany/FormComponent.Designer.cs | 122 +++++++++ TravelCompany/TravelCompany/FormComponent.cs | 95 +++++++ .../{Form1.resx => FormComponent.resx} | 50 ++-- .../TravelCompany/FormComponents.Designer.cs | 121 +++++++++ TravelCompany/TravelCompany/FormComponents.cs | 113 +++++++++ .../TravelCompany/FormComponents.resx | 120 +++++++++ .../TravelCompany/FormCreateOrder.Designer.cs | 144 +++++++++++ .../TravelCompany/FormCreateOrder.cs | 123 +++++++++ .../TravelCompany/FormCreateOrder.resx | 120 +++++++++ .../TravelCompany/FormMain.Designer.cs | 177 +++++++++++++ TravelCompany/TravelCompany/FormMain.cs | 155 ++++++++++++ TravelCompany/TravelCompany/FormMain.resx | 142 +++++++++++ .../TravelCompany/FormTravel.Designer.cs | 235 ++++++++++++++++++ TravelCompany/TravelCompany/FormTravel.cs | 205 +++++++++++++++ TravelCompany/TravelCompany/FormTravel.resx | 129 ++++++++++ .../FormTravelComponent.Designer.cs | 118 +++++++++ .../TravelCompany/FormTravelComponent.cs | 89 +++++++ .../TravelCompany/FormTravelComponent.resx | 120 +++++++++ .../TravelCompany/FormTravels.Designer.cs | 116 +++++++++ TravelCompany/TravelCompany/FormTravels.cs | 115 +++++++++ TravelCompany/TravelCompany/FormTravels.resx | 120 +++++++++ TravelCompany/TravelCompany/Program.cs | 38 ++- .../TravelCompany/TravelCompany.csproj | 15 ++ TravelCompany/TravelCompany/nlog.config | 15 ++ .../BusinessLogic/ComponentLogic.cs | 113 +++++++++ .../BusinessLogic/OrderLogic.cs | 141 +++++++++++ .../BusinessLogic/TravelLogic.cs | 118 +++++++++ .../TravelCompanyBusinessLogic.csproj | 23 ++ .../BindingModels/ComponentBindingModel.cs | 16 ++ .../BindingModels/OrderBindingModel.cs | 21 ++ .../BindingModels/TravelBindingModel.cs | 17 ++ .../IComponentLogic.cs | 21 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 30 +++ .../BusinessLogicsContracts/ITravelLogic.cs | 20 ++ .../SearchModels/ComponentSearchModel.cs | 14 ++ .../SearchModels/OrderSearchModel.cs | 13 + .../SearchModels/TravelSearchModel.cs | 14 ++ .../StoragesContracts/IComponentStorage.cs | 22 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../StoragesContracts/ITravelStorage.cs | 21 ++ .../TravelCompanyContracts.csproj | 22 ++ .../ViewModels/ComponentViewModel.cs | 19 ++ .../ViewModels/OrderViewModel.cs | 29 +++ .../ViewModels/TravelViewModel.cs | 21 ++ .../Enums/OrderStatus.cs | 11 + TravelCompany/TravelCompanyDataModels/IId.cs | 13 + .../Models/IComponentModel.cs | 8 + .../Models/IOrderModel.cs | 14 ++ .../Models/ITravelModel.cs | 9 + .../TravelCompanyDataModels.csproj | 18 ++ .../DataListSingleton.cs | 31 +++ .../Implements/ComponentStorage.cs | 106 ++++++++ .../Implements/OrderStorage.cs | 125 ++++++++++ .../Implements/TravelStorage.cs | 112 +++++++++ .../Models/Component.cs | 41 +++ .../Models/Order.cs | 64 +++++ .../Models/Travel.cs | 55 ++++ .../TravelCompanyListImplement.csproj | 14 ++ 61 files changed, 4133 insertions(+), 76 deletions(-) delete mode 100644 TravelCompany/TravelCompany/Form1.Designer.cs delete mode 100644 TravelCompany/TravelCompany/Form1.cs create mode 100644 TravelCompany/TravelCompany/FormComponent.Designer.cs create mode 100644 TravelCompany/TravelCompany/FormComponent.cs rename TravelCompany/TravelCompany/{Form1.resx => FormComponent.resx} (93%) create mode 100644 TravelCompany/TravelCompany/FormComponents.Designer.cs create mode 100644 TravelCompany/TravelCompany/FormComponents.cs create mode 100644 TravelCompany/TravelCompany/FormComponents.resx create mode 100644 TravelCompany/TravelCompany/FormCreateOrder.Designer.cs create mode 100644 TravelCompany/TravelCompany/FormCreateOrder.cs create mode 100644 TravelCompany/TravelCompany/FormCreateOrder.resx create mode 100644 TravelCompany/TravelCompany/FormMain.Designer.cs create mode 100644 TravelCompany/TravelCompany/FormMain.cs create mode 100644 TravelCompany/TravelCompany/FormMain.resx create mode 100644 TravelCompany/TravelCompany/FormTravel.Designer.cs create mode 100644 TravelCompany/TravelCompany/FormTravel.cs create mode 100644 TravelCompany/TravelCompany/FormTravel.resx create mode 100644 TravelCompany/TravelCompany/FormTravelComponent.Designer.cs create mode 100644 TravelCompany/TravelCompany/FormTravelComponent.cs create mode 100644 TravelCompany/TravelCompany/FormTravelComponent.resx create mode 100644 TravelCompany/TravelCompany/FormTravels.Designer.cs create mode 100644 TravelCompany/TravelCompany/FormTravels.cs create mode 100644 TravelCompany/TravelCompany/FormTravels.resx create mode 100644 TravelCompany/TravelCompany/nlog.config create mode 100644 TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ComponentLogic.cs create mode 100644 TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/OrderLogic.cs create mode 100644 TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/TravelLogic.cs create mode 100644 TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj create mode 100644 TravelCompany/TravelCompanyContracts/BindingModels/ComponentBindingModel.cs create mode 100644 TravelCompany/TravelCompanyContracts/BindingModels/OrderBindingModel.cs create mode 100644 TravelCompany/TravelCompanyContracts/BindingModels/TravelBindingModel.cs create mode 100644 TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/ITravelLogic.cs create mode 100644 TravelCompany/TravelCompanyContracts/SearchModels/ComponentSearchModel.cs create mode 100644 TravelCompany/TravelCompanyContracts/SearchModels/OrderSearchModel.cs create mode 100644 TravelCompany/TravelCompanyContracts/SearchModels/TravelSearchModel.cs create mode 100644 TravelCompany/TravelCompanyContracts/StoragesContracts/IComponentStorage.cs create mode 100644 TravelCompany/TravelCompanyContracts/StoragesContracts/IOrderStorage.cs create mode 100644 TravelCompany/TravelCompanyContracts/StoragesContracts/ITravelStorage.cs create mode 100644 TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj create mode 100644 TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs create mode 100644 TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs create mode 100644 TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs create mode 100644 TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs create mode 100644 TravelCompany/TravelCompanyDataModels/IId.cs create mode 100644 TravelCompany/TravelCompanyDataModels/Models/IComponentModel.cs create mode 100644 TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs create mode 100644 TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs create mode 100644 TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj create mode 100644 TravelCompany/TravelCompanyListImplement/DataListSingleton.cs create mode 100644 TravelCompany/TravelCompanyListImplement/Implements/ComponentStorage.cs create mode 100644 TravelCompany/TravelCompanyListImplement/Implements/OrderStorage.cs create mode 100644 TravelCompany/TravelCompanyListImplement/Implements/TravelStorage.cs create mode 100644 TravelCompany/TravelCompanyListImplement/Models/Component.cs create mode 100644 TravelCompany/TravelCompanyListImplement/Models/Order.cs create mode 100644 TravelCompany/TravelCompanyListImplement/Models/Travel.cs create mode 100644 TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj diff --git a/TravelCompany/TravelCompany.sln b/TravelCompany/TravelCompany.sln index bd53df9..a8219b0 100644 --- a/TravelCompany/TravelCompany.sln +++ b/TravelCompany/TravelCompany.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34024.191 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelCompany", "TravelCompany\TravelCompany.csproj", "{32E4B160-CD6F-419E-8436-D0194ED66568}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelCompany", "TravelCompany\TravelCompany.csproj", "{32E4B160-CD6F-419E-8436-D0194ED66568}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelCompanyDataModels", "TravelCompanyDataModels\TravelCompanyDataModels.csproj", "{F44E7E58-0372-42BD-A42C-3F6C498F549D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelCompanyContracts", "TravelCompanyContracts\TravelCompanyContracts.csproj", "{0F4C2D1A-DDEC-4D02-A493-06A79EF1926D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelCompanyBusinessLogic", "TravelCompanyBusinessLogic\TravelCompanyBusinessLogic.csproj", "{8171EC22-92EF-4916-BD50-B8D68018F6C2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelCompanyListImplement", "TravelCompanyListImplement\TravelCompanyListImplement.csproj", "{46AEB3CA-9FB8-444A-9145-B274C5FBEF6B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {32E4B160-CD6F-419E-8436-D0194ED66568}.Debug|Any CPU.Build.0 = Debug|Any CPU {32E4B160-CD6F-419E-8436-D0194ED66568}.Release|Any CPU.ActiveCfg = Release|Any CPU {32E4B160-CD6F-419E-8436-D0194ED66568}.Release|Any CPU.Build.0 = Release|Any CPU + {F44E7E58-0372-42BD-A42C-3F6C498F549D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F44E7E58-0372-42BD-A42C-3F6C498F549D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F44E7E58-0372-42BD-A42C-3F6C498F549D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F44E7E58-0372-42BD-A42C-3F6C498F549D}.Release|Any CPU.Build.0 = Release|Any CPU + {0F4C2D1A-DDEC-4D02-A493-06A79EF1926D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F4C2D1A-DDEC-4D02-A493-06A79EF1926D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F4C2D1A-DDEC-4D02-A493-06A79EF1926D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F4C2D1A-DDEC-4D02-A493-06A79EF1926D}.Release|Any CPU.Build.0 = Release|Any CPU + {8171EC22-92EF-4916-BD50-B8D68018F6C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8171EC22-92EF-4916-BD50-B8D68018F6C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8171EC22-92EF-4916-BD50-B8D68018F6C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8171EC22-92EF-4916-BD50-B8D68018F6C2}.Release|Any CPU.Build.0 = Release|Any CPU + {46AEB3CA-9FB8-444A-9145-B274C5FBEF6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46AEB3CA-9FB8-444A-9145-B274C5FBEF6B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46AEB3CA-9FB8-444A-9145-B274C5FBEF6B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46AEB3CA-9FB8-444A-9145-B274C5FBEF6B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TravelCompany/TravelCompany/Form1.Designer.cs b/TravelCompany/TravelCompany/Form1.Designer.cs deleted file mode 100644 index 0ed38d9..0000000 --- a/TravelCompany/TravelCompany/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace TravelCompany -{ - 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/TravelCompany/TravelCompany/Form1.cs b/TravelCompany/TravelCompany/Form1.cs deleted file mode 100644 index b2169b8..0000000 --- a/TravelCompany/TravelCompany/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace TravelCompany -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormComponent.Designer.cs b/TravelCompany/TravelCompany/FormComponent.Designer.cs new file mode 100644 index 0000000..5f51c77 --- /dev/null +++ b/TravelCompany/TravelCompany/FormComponent.Designer.cs @@ -0,0 +1,122 @@ +namespace TravelCompany.Forms +{ + 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() + { + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(217, 119); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(98, 34); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(325, 119); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(98, 34); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(24, 30); + label1.Name = "label1"; + label1.Size = new Size(80, 20); + label1.TabIndex = 2; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(24, 69); + label2.Name = "label2"; + label2.Size = new Size(48, 20); + label2.TabIndex = 3; + label2.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(118, 26); + textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(305, 27); + textBoxName.TabIndex = 4; + // + // textBoxCost + // + textBoxCost.Location = new Point(118, 65); + textBoxCost.Margin = new Padding(3, 4, 3, 4); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(186, 27); + textBoxCost.TabIndex = 5; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(462, 174); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Margin = new Padding(3, 4, 3, 4); + Name = "FormComponent"; + Text = "Компонент"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxCost; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormComponent.cs b/TravelCompany/TravelCompany/FormComponent.cs new file mode 100644 index 0000000..0f887c7 --- /dev/null +++ b/TravelCompany/TravelCompany/FormComponent.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Microsoft.Extensions.Logging; +using TravelCompanyContracts.BusinessLogicsContracts; +using Microsoft.VisualBasic.Logging; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.BindingModels; + +namespace TravelCompany.Forms +{ + 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(); + } + } +} diff --git a/TravelCompany/TravelCompany/Form1.resx b/TravelCompany/TravelCompany/FormComponent.resx similarity index 93% rename from TravelCompany/TravelCompany/Form1.resx rename to TravelCompany/TravelCompany/FormComponent.resx index 1af7de1..af32865 100644 --- a/TravelCompany/TravelCompany/Form1.resx +++ b/TravelCompany/TravelCompany/FormComponent.resx @@ -1,17 +1,17 @@  - diff --git a/TravelCompany/TravelCompany/FormComponents.Designer.cs b/TravelCompany/TravelCompany/FormComponents.Designer.cs new file mode 100644 index 0000000..5c92f12 --- /dev/null +++ b/TravelCompany/TravelCompany/FormComponents.Designer.cs @@ -0,0 +1,121 @@ +namespace TravelCompany.Forms +{ + 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(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(-1, -2); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 24; + dataGridView.Size = new Size(499, 568); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(525, 48); + buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(125, 35); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(525, 98); + buttonUpd.Margin = new Padding(3, 4, 3, 4); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(125, 35); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(525, 150); + buttonDel.Margin = new Padding(3, 4, 3, 4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(125, 35); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(525, 201); + buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(125, 35); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(676, 562); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormComponents"; + Text = "Список компонентов"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + 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/TravelCompany/TravelCompany/FormComponents.cs b/TravelCompany/TravelCompany/FormComponents.cs new file mode 100644 index 0000000..6fc3a44 --- /dev/null +++ b/TravelCompany/TravelCompany/FormComponents.cs @@ -0,0 +1,113 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TravelCompany.Forms +{ + 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/TravelCompany/TravelCompany/FormComponents.resx b/TravelCompany/TravelCompany/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TravelCompany/TravelCompany/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/TravelCompany/TravelCompany/FormCreateOrder.Designer.cs b/TravelCompany/TravelCompany/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..1ec37f3 --- /dev/null +++ b/TravelCompany/TravelCompany/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace TravelCompany.Forms +{ + 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(); + textBoxCount = new TextBox(); + comboBoxTravel = new ComboBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(19, 12); + label1.Name = "label1"; + label1.Size = new Size(56, 15); + label1.TabIndex = 0; + label1.Text = "Изделие:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(19, 44); + label2.Name = "label2"; + label2.Size = new Size(75, 15); + label2.TabIndex = 1; + label2.Text = "Количество:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(19, 70); + label3.Name = "label3"; + label3.Size = new Size(48, 15); + label3.TabIndex = 2; + label3.Text = "Сумма:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(103, 41); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(246, 23); + textBoxCount.TabIndex = 3; + textBoxCount.TextChanged += textBoxCount_TextChanged; + // + // comboBoxTravel + // + comboBoxTravel.FormattingEnabled = true; + comboBoxTravel.Location = new Point(103, 10); + comboBoxTravel.Name = "comboBoxTravel"; + comboBoxTravel.Size = new Size(246, 23); + comboBoxTravel.TabIndex = 4; + comboBoxTravel.SelectedIndexChanged += ComboBoxTravel_SelectedIndexChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(103, 70); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(246, 23); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(150, 101); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 26); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(249, 101); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 26); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(374, 136); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(comboBoxTravel); + Controls.Add(textBoxCount); + 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 TextBox textBoxCount; + private ComboBox comboBoxTravel; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormCreateOrder.cs b/TravelCompany/TravelCompany/FormCreateOrder.cs new file mode 100644 index 0000000..8cff27f --- /dev/null +++ b/TravelCompany/TravelCompany/FormCreateOrder.cs @@ -0,0 +1,123 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TravelCompany.Forms +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ITravelLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, ITravelLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxTravel.DisplayMember = "TravelName"; + comboBoxTravel.ValueMember = "Id"; + comboBoxTravel.DataSource = list; + comboBoxTravel.SelectedItem = null; + _logger.LogInformation("Загрузка изделий для заказа"); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + } + } + private void CalcSum() + { + if (comboBoxTravel.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxTravel.SelectedValue); + var Travel = _logicP.ReadElement(new TravelSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Travel?.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 ComboBoxTravel_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 (comboBoxTravel.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + TravelId = Convert.ToInt32(comboBoxTravel.SelectedValue), + 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/TravelCompany/TravelCompany/FormCreateOrder.resx b/TravelCompany/TravelCompany/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TravelCompany/TravelCompany/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/TravelCompany/TravelCompany/FormMain.Designer.cs b/TravelCompany/TravelCompany/FormMain.Designer.cs new file mode 100644 index 0000000..cfb5db8 --- /dev/null +++ b/TravelCompany/TravelCompany/FormMain.Designer.cs @@ -0,0 +1,177 @@ +namespace TravelCompany.Forms +{ + 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() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); + toolStrip1 = new ToolStrip(); + toolStripDropDownButton1 = new ToolStripDropDownButton(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + ПутёвкиToolStripMenuItem = new ToolStripMenuItem(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + dataGridView = new DataGridView(); + toolStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // toolStrip1 + // + toolStrip1.ImageScalingSize = new Size(20, 20); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1 }); + toolStrip1.Location = new Point(0, 0); + toolStrip1.Name = "toolStrip1"; + toolStrip1.Size = new Size(969, 25); + toolStrip1.TabIndex = 0; + toolStrip1.Text = "toolStrip1"; + // + // toolStripDropDownButton1 + // + toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, ПутёвкиToolStripMenuItem }); + toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); + toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; + toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + toolStripDropDownButton1.Size = new Size(88, 22); + toolStripDropDownButton1.Text = "Справочник"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(180, 22); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; + // + // ПутёвкиToolStripMenuItem + // + ПутёвкиToolStripMenuItem.Name = "ПутёвкиToolStripMenuItem"; + ПутёвкиToolStripMenuItem.Size = new Size(180, 22); + ПутёвкиToolStripMenuItem.Text = "Туристич. путёвки"; + ПутёвкиToolStripMenuItem.Click += консервыToolStripMenuItem_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(800, 56); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(141, 24); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(800, 100); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(141, 24); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(800, 142); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(141, 24); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(800, 181); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(141, 24); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(800, 222); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(141, 24); + buttonRef.TabIndex = 5; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 26); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 24; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(763, 435); + dataGridView.TabIndex = 6; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(969, 461); + Controls.Add(dataGridView); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(toolStrip1); + Name = "FormMain"; + Text = "Рыбный завод"; + Load += FormMain_Load; + toolStrip1.ResumeLayout(false); + toolStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ToolStrip toolStrip1; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + private DataGridView dataGridView; + private ToolStripDropDownButton toolStripDropDownButton1; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem ПутёвкиToolStripMenuItem; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormMain.cs b/TravelCompany/TravelCompany/FormMain.cs new file mode 100644 index 0000000..d25b396 --- /dev/null +++ b/TravelCompany/TravelCompany/FormMain.cs @@ -0,0 +1,155 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TravelCompany.Forms +{ + 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["TravelId"].Visible = false; + dataGridView.Columns["TravelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + } + } + 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(FormTravels)); + + if (service is FormTravels 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, + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/TravelCompany/TravelCompany/FormMain.resx b/TravelCompany/TravelCompany/FormMain.resx new file mode 100644 index 0000000..e226a59 --- /dev/null +++ b/TravelCompany/TravelCompany/FormMain.resx @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + 56 + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravel.Designer.cs b/TravelCompany/TravelCompany/FormTravel.Designer.cs new file mode 100644 index 0000000..589ad9d --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravel.Designer.cs @@ -0,0 +1,235 @@ +namespace TravelCompany.Forms +{ + partial class FormTravel + { + /// + /// 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(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + dataGridView = new DataGridView(); + Number = new DataGridViewTextBoxColumn(); + Component = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBox1 = new GroupBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + groupBox1.SuspendLayout(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(16, 15); + label1.Name = "label1"; + label1.Size = new Size(62, 15); + label1.TabIndex = 0; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(16, 41); + label2.Name = "label2"; + label2.Size = new Size(70, 15); + label2.TabIndex = 1; + label2.Text = "Стоимость:"; + // + // buttonAdd + // + buttonAdd.Location = new Point(574, 44); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(97, 28); + buttonAdd.TabIndex = 0; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(574, 90); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(97, 28); + buttonUpd.TabIndex = 1; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(574, 134); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(97, 28); + buttonDel.TabIndex = 2; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(574, 173); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(97, 28); + buttonRef.TabIndex = 3; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { Number, Component, Count }); + dataGridView.Location = new Point(0, 20); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 24; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.ShowEditingIcon = false; + dataGridView.Size = new Size(549, 332); + dataGridView.TabIndex = 4; + // + // Number + // + Number.HeaderText = "Номер"; + Number.MinimumWidth = 6; + Number.Name = "Number"; + Number.ReadOnly = true; + Number.Width = 60; + // + // Component + // + Component.HeaderText = "Компонент"; + Component.MinimumWidth = 6; + Component.Name = "Component"; + Component.ReadOnly = true; + Component.Width = 125; + // + // Count + // + Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.ReadOnly = true; + // + // textBoxName + // + textBoxName.Location = new Point(94, 14); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(246, 23); + textBoxName.TabIndex = 3; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(94, 39); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.ReadOnly = true; + textBoxPrice.Size = new Size(85, 23); + textBoxPrice.TabIndex = 4; + textBoxPrice.TabStop = false; + // + // groupBox1 + // + groupBox1.Controls.Add(buttonRef); + groupBox1.Controls.Add(buttonDel); + groupBox1.Controls.Add(dataGridView); + groupBox1.Controls.Add(buttonUpd); + groupBox1.Controls.Add(buttonAdd); + groupBox1.Location = new Point(14, 71); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(689, 367); + groupBox1.TabIndex = 5; + groupBox1.TabStop = false; + groupBox1.Text = "Компоненты"; + // + // buttonSave + // + buttonSave.Location = new Point(397, 454); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(114, 28); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(533, 454); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(114, 28); + buttonCancel.TabIndex = 0; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormTravel + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(711, 497); + Controls.Add(groupBox1); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label1); + Name = "FormTravel"; + Text = "Туристическая путёвка"; + Load += FormTravel_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + groupBox1.ResumeLayout(false); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox1; + private DataGridViewTextBoxColumn Number; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravel.cs b/TravelCompany/TravelCompany/FormTravel.cs new file mode 100644 index 0000000..2dd37b9 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravel.cs @@ -0,0 +1,205 @@ +using TravelCompanyDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.BindingModels; + +namespace TravelCompany.Forms +{ + public partial class FormTravel : Form + { + private readonly ILogger _logger; + private readonly ITravelLogic _logic; + private int? _id; + private Dictionary _productComponents; + public int Id { set { _id = value; } } + public FormTravel(ILogger logger, ITravelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _productComponents = new Dictionary(); + } + private void FormTravel_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new TravelSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.TravelName; + textBoxPrice.Text = view.Price.ToString(); + _productComponents = view.TravelComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_productComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _productComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + } + } + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTravelComponent)); + if (service is FormTravelComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + if (_productComponents.ContainsKey(form.Id)) + { + _productComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _productComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTravelComponent)); + if (service is FormTravelComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _productComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _productComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void buttonDel_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); + _productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_productComponents == null || _productComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new TravelBindingModel + { + Id = _id ?? 0, + TravelName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + TravelComponents = _productComponents + }; + 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 _productComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/TravelCompany/TravelCompany/FormTravel.resx b/TravelCompany/TravelCompany/FormTravel.resx new file mode 100644 index 0000000..5052aba --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravel.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravelComponent.Designer.cs b/TravelCompany/TravelCompany/FormTravelComponent.Designer.cs new file mode 100644 index 0000000..0966c6f --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravelComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace TravelCompany.Forms +{ + partial class FormTravelComponent + { + /// + /// 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() + { + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(174, 75); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(86, 27); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(270, 75); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 27); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 14); + label1.Name = "label1"; + label1.Size = new Size(72, 15); + label1.TabIndex = 2; + label1.Text = "Компонент:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 44); + label2.Name = "label2"; + label2.Size = new Size(75, 15); + label2.TabIndex = 3; + label2.Text = "Количество:"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(106, 9); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(250, 23); + comboBoxComponent.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(106, 44); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(250, 23); + textBoxCount.TabIndex = 5; + // + // FormTravelComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(373, 112); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormTravelComponent"; + Text = "Компонент туристической путёвки"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravelComponent.cs b/TravelCompany/TravelCompany/FormTravelComponent.cs new file mode 100644 index 0000000..282cfa1 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravelComponent.cs @@ -0,0 +1,89 @@ +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.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 TravelCompany.Forms +{ + public partial class FormTravelComponent : 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 FormTravelComponent(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/TravelCompany/TravelCompany/FormTravelComponent.resx b/TravelCompany/TravelCompany/FormTravelComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravelComponent.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/TravelCompany/TravelCompany/FormTravels.Designer.cs b/TravelCompany/TravelCompany/FormTravels.Designer.cs new file mode 100644 index 0000000..053d8b3 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravels.Designer.cs @@ -0,0 +1,116 @@ +namespace TravelCompany.Forms +{ + partial class FormTravels + { + /// + /// 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() + { + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonRef + // + buttonRef.Location = new Point(648, 135); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(112, 26); + buttonRef.TabIndex = 9; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(648, 97); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(112, 26); + buttonDel.TabIndex = 8; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(648, 58); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(112, 26); + buttonUpd.TabIndex = 7; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(648, 20); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(112, 26); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(-1, 0); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 24; + dataGridView.Size = new Size(620, 426); + dataGridView.TabIndex = 5; + // + // FormTravels + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(783, 428); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(3, 2, 3, 2); + Name = "FormTravels"; + Text = "Список туристических путёвок"; + Load += FormTravels_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravels.cs b/TravelCompany/TravelCompany/FormTravels.cs new file mode 100644 index 0000000..34d66d2 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravels.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TravelCompany; +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace TravelCompany.Forms +{ + public partial class FormTravels : Form + { + private readonly ILogger _logger; + private readonly ITravelLogic _logic; + public FormTravels(ILogger logger, ITravelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormTravels_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["TravelComponents"].Visible = false; + dataGridView.Columns["TravelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка консерв"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTravel)); + if (service is FormTravel 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(FormTravel)); + if (service is FormTravel 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 TravelBindingModel + { + 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/TravelCompany/TravelCompany/FormTravels.resx b/TravelCompany/TravelCompany/FormTravels.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravels.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/TravelCompany/TravelCompany/Program.cs b/TravelCompany/TravelCompany/Program.cs index 9429054..80d41e4 100644 --- a/TravelCompany/TravelCompany/Program.cs +++ b/TravelCompany/TravelCompany/Program.cs @@ -1,7 +1,18 @@ +using TravelCompany.Forms; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyBusinessLogic.BusinessLogic; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace TravelCompany { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +22,32 @@ namespace TravelCompany // 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/TravelCompany/TravelCompany/TravelCompany.csproj b/TravelCompany/TravelCompany/TravelCompany.csproj index b57c89e..8612256 100644 --- a/TravelCompany/TravelCompany/TravelCompany.csproj +++ b/TravelCompany/TravelCompany/TravelCompany.csproj @@ -8,4 +8,19 @@ enable + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/nlog.config b/TravelCompany/TravelCompany/nlog.config new file mode 100644 index 0000000..af70d20 --- /dev/null +++ b/TravelCompany/TravelCompany/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ComponentLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..c3112f3 --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -0,0 +1,113 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace TravelCompanyBusinessLogic.BusinessLogic +{ + 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/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/OrderLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..e7c1295 --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,141 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyBusinessLogic.BusinessLogic +{ + 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 bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Неизвестен) + return false; + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Выдан); + } + + public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel() + { + Id = model.Id + }); + if (element == null) + { + throw new ArgumentNullException(nameof(element)); + } + + model.TravelId = element.TravelId; + model.DateCreate = element.DateCreate; + model.DateImplement = element.DateImplement; + model.Status = element.Status; + model.Count = element.Count; + model.Sum = element.Sum; + + if (model.Status != orderStatus - 1) + { + _logger.LogWarning("Status update to " + orderStatus + " operation failed"); + return false; + } + model.Status = orderStatus; + + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Changing status operation faled"); + return false; + } + return true; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} должна быть позже даты его создания {model.DateCreate}"); + } + _logger.LogInformation("Travel. TravelId:{TravelId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.TravelId, model.Count, model.Sum, model.Id); + } + } +} diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/TravelLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/TravelLogic.cs new file mode 100644 index 0000000..69719fe --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/TravelLogic.cs @@ -0,0 +1,118 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyBusinessLogic.BusinessLogic +{ + public class TravelLogic : ITravelLogic + { + private readonly ILogger _logger; + private readonly ITravelStorage _TravelStorage; + public TravelLogic(ILogger logger, ITravelStorage + TravelStorage) + { + _logger = logger; + _TravelStorage = TravelStorage; + } + public List? ReadList(TravelSearchModel? model) + { + _logger.LogInformation("ReadList. TravelName:{TravelName}.Id:{Id}", model?.TravelName, model?.Id); + var list = model == null ? _TravelStorage.GetFullList() : _TravelStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public TravelViewModel? ReadElement(TravelSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. TravelName:{TravelName}.Id:{Id}", model.TravelName, model.Id); + var element = _TravelStorage.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(TravelBindingModel model) + { + CheckModel(model); + if (_TravelStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(TravelBindingModel model) + { + CheckModel(model); + if (_TravelStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(TravelBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_TravelStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(TravelBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.TravelName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.TravelName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Travel. TravelName:{TravelName}.Price:{Cost}. Id: {Id}", model.TravelName, model.Price, model.Id); + var element = _TravelStorage.GetElement(new TravelSearchModel + { + TravelName = model.TravelName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj b/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj new file mode 100644 index 0000000..fd62a0d --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/ComponentBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..ee3837f --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/OrderBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..20802d2 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using TravelCompanyDataModels.Enums; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int TravelId { get; set; } + 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; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/TravelBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/TravelBindingModel.cs new file mode 100644 index 0000000..49993f0 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BindingModels/TravelBindingModel.cs @@ -0,0 +1,17 @@ +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BindingModels +{ + public class TravelBindingModel : ITravelModel + { + public int Id { get; set; } + public string TravelName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary TravelComponents { get; set; } = new(); + } +} diff --git a/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IComponentLogic.cs b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..f7af27c --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,21 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.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/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IOrderLogic.cs b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..03a4beb --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,30 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.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/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/ITravelLogic.cs b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/ITravelLogic.cs new file mode 100644 index 0000000..d499914 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/ITravelLogic.cs @@ -0,0 +1,20 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BusinessLogicsContracts +{ + public interface ITravelLogic + { + List? ReadList(TravelSearchModel? model); + TravelViewModel? ReadElement(TravelSearchModel model); + bool Create(TravelBindingModel model); + bool Update(TravelBindingModel model); + bool Delete(TravelBindingModel model); + } +} diff --git a/TravelCompany/TravelCompanyContracts/SearchModels/ComponentSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..9d6102f --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/SearchModels/OrderSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..d2c7549 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/SearchModels/TravelSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/TravelSearchModel.cs new file mode 100644 index 0000000..6b13d69 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/SearchModels/TravelSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.SearchModels +{ + public class TravelSearchModel + { + public int? Id { get; set; } + public string? TravelName { get; set; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/StoragesContracts/IComponentStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..617243a --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.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/TravelCompany/TravelCompanyContracts/StoragesContracts/IOrderStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..b4d8462 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.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/TravelCompany/TravelCompanyContracts/StoragesContracts/ITravelStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesContracts/ITravelStorage.cs new file mode 100644 index 0000000..b85d24b --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/ITravelStorage.cs @@ -0,0 +1,21 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.StoragesContracts +{ + public interface ITravelStorage + { + List GetFullList(); + List GetFilteredList(TravelSearchModel model); + TravelViewModel? GetElement(TravelSearchModel model); + TravelViewModel? Insert(TravelBindingModel model); + TravelViewModel? Update(TravelBindingModel model); + TravelViewModel? Delete(TravelBindingModel model); + } +} diff --git a/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj b/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj new file mode 100644 index 0000000..f3c43e1 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..f865958 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.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/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..022bc49 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,29 @@ +using TravelCompanyDataModels.Enums; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.ViewModels +{ + public class OrderViewModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int TravelId { get; set; } + [DisplayName("Изделие")] + public string TravelName { 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/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs new file mode 100644 index 0000000..d8c1e55 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs @@ -0,0 +1,21 @@ +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.ViewModels +{ + public class TravelViewModel : ITravelModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string TravelName { get; set; } + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary TravelComponents { get; set; } = new(); + + } +} diff --git a/TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs b/TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..0e8a2ca --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace TravelCompanyDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3, + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyDataModels/IId.cs b/TravelCompany/TravelCompanyDataModels/IId.cs new file mode 100644 index 0000000..cdccdc8 --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/TravelCompany/TravelCompanyDataModels/Models/IComponentModel.cs b/TravelCompany/TravelCompanyDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..946afa3 --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/Models/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace TravelCompanyDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs b/TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..22a55af --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs @@ -0,0 +1,14 @@ +using TravelCompanyDataModels.Enums; + +namespace TravelCompanyDataModels.Models +{ + public interface IOrderModel : IId + { + int TravelId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs b/TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs new file mode 100644 index 0000000..101f593 --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs @@ -0,0 +1,9 @@ +namespace TravelCompanyDataModels.Models +{ + public interface ITravelModel : IId + { + string TravelName { get; } + double Price { get; } + Dictionary TravelComponents { get; } + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj b/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj new file mode 100644 index 0000000..d80c28f --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs b/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs new file mode 100644 index 0000000..01817fb --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using TravelCompanyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Travels { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Travels = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Implements/ComponentStorage.cs b/TravelCompany/TravelCompanyListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..dddef2b --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,106 @@ +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.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/TravelCompany/TravelCompanyListImplement/Implements/OrderStorage.cs b/TravelCompany/TravelCompanyListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..0676fe2 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Implements/OrderStorage.cs @@ -0,0 +1,125 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.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(AttachTravelName(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null || !model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AttachTravelName(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 AttachTravelName(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 AttachTravelName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachTravelName(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 AttachTravelName(element.GetViewModel); + } + } + return null; + } + + private OrderViewModel AttachTravelName(OrderViewModel model) + { + foreach (var Travel in _source.Travels) + { + if (Travel.Id == model.TravelId) + { + model.TravelName = Travel.TravelName; + return model; + } + } + return model; + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Implements/TravelStorage.cs b/TravelCompany/TravelCompanyListImplement/Implements/TravelStorage.cs new file mode 100644 index 0000000..7673715 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Implements/TravelStorage.cs @@ -0,0 +1,112 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Implements +{ + public class TravelStorage : ITravelStorage + { + private readonly DataListSingleton _source; + public TravelStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public TravelViewModel? Delete(TravelBindingModel model) + { + for (int i = 0; i < _source.Travels.Count; ++i) + { + if (_source.Travels[i].Id == model.Id) + { + var element = _source.Travels[i]; + _source.Travels.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public TravelViewModel? GetElement(TravelSearchModel model) + { + if (string.IsNullOrEmpty(model.TravelName) && !model.Id.HasValue) + { + return null; + } + foreach (var Travel in _source.Travels) + { + if ((!string.IsNullOrEmpty(model.TravelName) && Travel.TravelName == model.TravelName) || + (model.Id.HasValue && Travel.Id == model.Id)) + { + return Travel.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(TravelSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.TravelName)) + { + return result; + } + foreach (var Travel in _source.Travels) + { + if (Travel.TravelName.Contains(model.TravelName)) + { + result.Add(Travel.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var Travel in _source.Travels) + { + result.Add(Travel.GetViewModel); + } + return result; + } + + public TravelViewModel? Insert(TravelBindingModel model) + { + model.Id = 1; + foreach (var Travel in _source.Travels) + { + if (model.Id <= Travel.Id) + { + model.Id = Travel.Id + 1; + } + } + var newTravel = Travel.Create(model); + if (newTravel == null) + { + return null; + } + _source.Travels.Add(newTravel); + return newTravel.GetViewModel; + } + + public TravelViewModel? Update(TravelBindingModel model) + { + foreach (var Travel in _source.Travels) + { + if (Travel.Id == model.Id) + { + Travel.Update(model); + return Travel.GetViewModel; + } + } + return null; + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Models/Component.cs b/TravelCompany/TravelCompanyListImplement/Models/Component.cs new file mode 100644 index 0000000..1c9f49a --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; + +namespace TravelCompanyListImplement.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/TravelCompany/TravelCompanyListImplement/Models/Order.cs b/TravelCompany/TravelCompanyListImplement/Models/Order.cs new file mode 100644 index 0000000..b26f50c --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Models/Order.cs @@ -0,0 +1,64 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Enums; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int TravelId { get; private set; } + 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, + TravelId = model.TravelId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + TravelId = model.TravelId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + TravelId = TravelId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Models/Travel.cs b/TravelCompany/TravelCompanyListImplement/Models/Travel.cs new file mode 100644 index 0000000..32ff4bc --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Models/Travel.cs @@ -0,0 +1,55 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Models +{ + internal class Travel : ITravelModel + { + public int Id { get; private set; } + public string TravelName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary TravelComponents + { + get; + private set; + } = new Dictionary(); + public static Travel? Create(TravelBindingModel? model) + { + if (model == null) + { + return null; + } + return new Travel() + { + Id = model.Id, + TravelName = model.TravelName, + Price = model.Price, + TravelComponents = model.TravelComponents + }; + } + public void Update(TravelBindingModel? model) + { + if (model == null) + { + return; + } + TravelName = model.TravelName; + Price = model.Price; + TravelComponents = model.TravelComponents; + } + public TravelViewModel GetViewModel => new() + { + Id = Id, + TravelName = TravelName, + Price = Price, + TravelComponents = TravelComponents + }; + + } +} diff --git a/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj b/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj new file mode 100644 index 0000000..9ba85b1 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + +