diff --git a/TravelCompany/TravelCompany.sln b/TravelCompany/TravelCompany.sln
index abe2e33..b8d7350 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.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelCompany", "TravelCompany\TravelCompany.csproj", "{90ACA6FB-2B0B-40E5-B412-889C50092E91}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelCompany", "TravelCompany\TravelCompany.csproj", "{90ACA6FB-2B0B-40E5-B412-889C50092E91}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelCompanyDataModels", "TravelCompanyDataModels\TravelCompanyDataModels.csproj", "{B6C3B648-81B7-4696-85BC-2B7F82443D99}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelCompanyContracts", "TravelCompanyContracts\TravelCompanyContracts.csproj", "{0C66C42B-3326-42BF-9C71-E3153AAAF598}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelCompanyBusinessLogic", "TravelCompanyBusinessLogic\TravelCompanyBusinessLogic.csproj", "{A636CF3E-87F6-4C8B-99C6-8EA066516C0A}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelCompanyListImplement", "TravelCompanyListImplement\TravelCompanyListImplement.csproj", "{0FF615FA-A053-4DF6-99E6-CFC50A1D88C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +23,22 @@ Global
{90ACA6FB-2B0B-40E5-B412-889C50092E91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90ACA6FB-2B0B-40E5-B412-889C50092E91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90ACA6FB-2B0B-40E5-B412-889C50092E91}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B6C3B648-81B7-4696-85BC-2B7F82443D99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B6C3B648-81B7-4696-85BC-2B7F82443D99}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B6C3B648-81B7-4696-85BC-2B7F82443D99}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B6C3B648-81B7-4696-85BC-2B7F82443D99}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0C66C42B-3326-42BF-9C71-E3153AAAF598}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0C66C42B-3326-42BF-9C71-E3153AAAF598}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0C66C42B-3326-42BF-9C71-E3153AAAF598}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0C66C42B-3326-42BF-9C71-E3153AAAF598}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A636CF3E-87F6-4C8B-99C6-8EA066516C0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A636CF3E-87F6-4C8B-99C6-8EA066516C0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A636CF3E-87F6-4C8B-99C6-8EA066516C0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A636CF3E-87F6-4C8B-99C6-8EA066516C0A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0FF615FA-A053-4DF6-99E6-CFC50A1D88C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0FF615FA-A053-4DF6-99E6-CFC50A1D88C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0FF615FA-A053-4DF6-99E6-CFC50A1D88C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0FF615FA-A053-4DF6-99E6-CFC50A1D88C9}.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/Form1.resx b/TravelCompany/TravelCompany/Form1.resx
deleted file mode 100644
index 1af7de1..0000000
--- a/TravelCompany/TravelCompany/Form1.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormCondition.Designer.cs b/TravelCompany/TravelCompany/FormCondition.Designer.cs
new file mode 100644
index 0000000..d7f5630
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormCondition.Designer.cs
@@ -0,0 +1,119 @@
+namespace TravelCompany
+{
+ partial class FormCondition
+ {
+ ///
+ /// 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.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.labelName = new System.Windows.Forms.Label();
+ this.labelPrice = new System.Windows.Forms.Label();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxPrice = new System.Windows.Forms.TextBox();
+ this.SuspendLayout();
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(324, 91);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(112, 34);
+ this.buttonSave.TabIndex = 0;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(447, 91);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(112, 34);
+ this.buttonCancel.TabIndex = 1;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(12, 38);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(90, 25);
+ this.labelName.TabIndex = 2;
+ this.labelName.Text = "Название";
+ //
+ // labelPrice
+ //
+ this.labelPrice.AutoSize = true;
+ this.labelPrice.Location = new System.Drawing.Point(49, 94);
+ this.labelPrice.Name = "labelPrice";
+ this.labelPrice.Size = new System.Drawing.Size(53, 25);
+ this.labelPrice.TabIndex = 3;
+ this.labelPrice.Text = "Цена";
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(120, 38);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(439, 31);
+ this.textBoxName.TabIndex = 4;
+ //
+ // textBoxPrice
+ //
+ this.textBoxPrice.Location = new System.Drawing.Point(120, 91);
+ this.textBoxPrice.Name = "textBoxPrice";
+ this.textBoxPrice.Size = new System.Drawing.Size(186, 31);
+ this.textBoxPrice.TabIndex = 5;
+ //
+ // FormCondition
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(577, 151);
+ this.Controls.Add(this.textBoxPrice);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.labelPrice);
+ this.Controls.Add(this.labelName);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Name = "FormCondition";
+ this.Text = "Условие";
+ this.Load += new System.EventHandler(this.FormCondition_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Button buttonSave;
+ private Button buttonCancel;
+ private Label labelName;
+ private Label labelPrice;
+ private TextBox textBoxName;
+ private TextBox textBoxPrice;
+ }
+}
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormCondition.cs b/TravelCompany/TravelCompany/FormCondition.cs
new file mode 100644
index 0000000..ebaef8c
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormCondition.cs
@@ -0,0 +1,96 @@
+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.BindingModels;
+using TravelCompanyContracts.BusinessLogicsContracts;
+using TravelCompanyContracts.SearchModels;
+
+namespace TravelCompany
+{
+ public partial class FormCondition : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IConditionLogic _logic;
+ private int? _id;
+ public int Id { set { _id = value; } }
+ public FormCondition(ILogger logger, IConditionLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormCondition_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation("Получение компонента");
+ var view = _logic.ReadElement(new ConditionSearchModel
+ {
+ Id =
+ _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.ConditionName;
+ textBoxPrice.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 ConditionBindingModel
+ {
+ Id = _id ?? 0,
+ ConditionName = textBoxName.Text,
+ Cost = Convert.ToDouble(textBoxPrice.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/FormCondition.resx b/TravelCompany/TravelCompany/FormCondition.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormCondition.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormConditions.Designer.cs b/TravelCompany/TravelCompany/FormConditions.Designer.cs
new file mode 100644
index 0000000..54a1ab7
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormConditions.Designer.cs
@@ -0,0 +1,119 @@
+namespace TravelCompany
+{
+ partial class FormConditions
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonRef = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.BackgroundColor = System.Drawing.Color.White;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(2, 2);
+ this.dataGridView.MultiSelect = false;
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersVisible = false;
+ this.dataGridView.RowHeadersWidth = 62;
+ this.dataGridView.RowTemplate.Height = 33;
+ this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+ this.dataGridView.Size = new System.Drawing.Size(525, 521);
+ this.dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(554, 28);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(112, 34);
+ this.buttonAdd.TabIndex = 1;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(554, 104);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(112, 34);
+ this.buttonUpd.TabIndex = 2;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonDel
+ //
+ this.buttonDel.Location = new System.Drawing.Point(554, 186);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(112, 34);
+ this.buttonDel.TabIndex = 3;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(554, 275);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(112, 34);
+ this.buttonRef.TabIndex = 4;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // FormConditions
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(687, 524);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonDel);
+ this.Controls.Add(this.buttonUpd);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormConditions";
+ this.Text = "Условия";
+ this.Load += new System.EventHandler(this.FormConditions_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonUpd;
+ private Button buttonDel;
+ private Button buttonRef;
+ }
+}
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormConditions.cs b/TravelCompany/TravelCompany/FormConditions.cs
new file mode 100644
index 0000000..6a870a8
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormConditions.cs
@@ -0,0 +1,115 @@
+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.BindingModels;
+
+namespace TravelCompany
+{
+ public partial class FormConditions : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IConditionLogic _logic;
+ public FormConditions(ILogger logger, IConditionLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["ConditionName"].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(FormCondition));
+ if (service is FormCondition 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(FormCondition));
+ if (service is FormCondition 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 ConditionBindingModel
+ {
+ 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();
+ }
+
+ private void FormConditions_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/TravelCompany/TravelCompany/FormConditions.resx b/TravelCompany/TravelCompany/FormConditions.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormConditions.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormCreateOrder.Designer.cs b/TravelCompany/TravelCompany/FormCreateOrder.Designer.cs
new file mode 100644
index 0000000..effbed4
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormCreateOrder.Designer.cs
@@ -0,0 +1,145 @@
+namespace TravelCompany
+{
+ partial class FormCreateOrder
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.labelSum = new System.Windows.Forms.Label();
+ this.labelTravel = new System.Windows.Forms.Label();
+ this.labelCount = new System.Windows.Forms.Label();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.comboBoxTravel = new System.Windows.Forms.ComboBox();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.textBoxSum = new System.Windows.Forms.TextBox();
+ this.SuspendLayout();
+ //
+ // labelSum
+ //
+ this.labelSum.AutoSize = true;
+ this.labelSum.Location = new System.Drawing.Point(82, 151);
+ this.labelSum.Name = "labelSum";
+ this.labelSum.Size = new System.Drawing.Size(71, 25);
+ this.labelSum.TabIndex = 0;
+ this.labelSum.Text = "Сумма:";
+ //
+ // labelTravel
+ //
+ this.labelTravel.AutoSize = true;
+ this.labelTravel.Location = new System.Drawing.Point(32, 30);
+ this.labelTravel.Name = "labelTravel";
+ this.labelTravel.Size = new System.Drawing.Size(121, 25);
+ this.labelTravel.TabIndex = 1;
+ this.labelTravel.Text = "Путешествие:";
+ //
+ // labelCount
+ //
+ this.labelCount.AutoSize = true;
+ this.labelCount.Location = new System.Drawing.Point(42, 94);
+ this.labelCount.Name = "labelCount";
+ this.labelCount.Size = new System.Drawing.Size(111, 25);
+ this.labelCount.TabIndex = 2;
+ this.labelCount.Text = "Количество:";
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(468, 207);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(112, 34);
+ this.buttonCancel.TabIndex = 4;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(338, 207);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(112, 34);
+ this.buttonSave.TabIndex = 3;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click_1);
+ //
+ // comboBoxTravel
+ //
+ this.comboBoxTravel.FormattingEnabled = true;
+ this.comboBoxTravel.Location = new System.Drawing.Point(169, 27);
+ this.comboBoxTravel.Name = "comboBoxTravel";
+ this.comboBoxTravel.Size = new System.Drawing.Size(365, 33);
+ this.comboBoxTravel.TabIndex = 5;
+ this.comboBoxTravel.SelectedIndexChanged += new System.EventHandler(this.comboBoxTravel_SelectedIndexChanged);
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(169, 91);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(365, 31);
+ this.textBoxCount.TabIndex = 6;
+ this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged);
+ //
+ // textBoxSum
+ //
+ this.textBoxSum.Location = new System.Drawing.Point(169, 151);
+ this.textBoxSum.Name = "textBoxSum";
+ this.textBoxSum.ReadOnly = true;
+ this.textBoxSum.Size = new System.Drawing.Size(365, 31);
+ this.textBoxSum.TabIndex = 7;
+ //
+ // FormCreateOrder
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(605, 256);
+ this.Controls.Add(this.textBoxSum);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.comboBoxTravel);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.labelCount);
+ this.Controls.Add(this.labelTravel);
+ this.Controls.Add(this.labelSum);
+ this.Name = "FormCreateOrder";
+ this.Text = "FormCreateOrder";
+ this.Load += new System.EventHandler(this.FormCreateOrder_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelSum;
+ private Label labelTravel;
+ private Label labelCount;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private ComboBox comboBoxTravel;
+ private TextBox textBoxCount;
+ private TextBox textBoxSum;
+ }
+}
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormCreateOrder.cs b/TravelCompany/TravelCompany/FormCreateOrder.cs
new file mode 100644
index 0000000..9dcd203
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormCreateOrder.cs
@@ -0,0 +1,123 @@
+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.BindingModels;
+using TravelCompanyContracts.BusinessLogicsContracts;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+using System.Collections;
+
+
+namespace TravelCompany
+{
+ public partial class FormCreateOrder : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ITravelLogic _logicT;
+ private readonly IOrderLogic _logicO;
+ private List? _list;
+ public FormCreateOrder(ILogger logger, ITravelLogic logicT, IOrderLogic logicO)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicT = logicT;
+ _logicO = logicO;
+ }
+ private void FormCreateOrder_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка путешествий для заказа");
+ _list = _logicT.ReadList(null);
+ if (_list != null)
+ {
+ comboBoxTravel.DisplayMember = "TravelName";
+ comboBoxTravel.ValueMember = "Id";
+ comboBoxTravel.DataSource = _list;
+ comboBoxTravel.SelectedItem = null;
+ }
+ }
+ private void CalcSum()
+ {
+ if (comboBoxTravel.SelectedValue != null &&
+ !string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ try
+ {
+ int id = Convert.ToInt32(comboBoxTravel.SelectedValue);
+ var travel = _logicT.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 buttonSave_Click_1(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();
+ }
+
+ private void comboBoxTravel_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+
+ private void textBoxCount_TextChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+ }
+}
diff --git a/TravelCompany/TravelCompany/FormCreateOrder.resx b/TravelCompany/TravelCompany/FormCreateOrder.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormCreateOrder.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormMain.Designer.cs b/TravelCompany/TravelCompany/FormMain.Designer.cs
new file mode 100644
index 0000000..b17d4bc
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormMain.Designer.cs
@@ -0,0 +1,180 @@
+namespace TravelCompany
+{
+ partial class FormMain
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.menuStrip = new System.Windows.Forms.MenuStrip();
+ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.условияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.путешествияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.buttonCreateOrder = new System.Windows.Forms.Button();
+ this.ButtonTakeOrderInWork = new System.Windows.Forms.Button();
+ this.ButtonOrderReady = new System.Windows.Forms.Button();
+ this.ButtonIssuedOrder = new System.Windows.Forms.Button();
+ this.ButtonRef = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.menuStrip.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.BackgroundColor = System.Drawing.Color.White;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(4, 45);
+ this.dataGridView.MultiSelect = false;
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersVisible = false;
+ this.dataGridView.RowHeadersWidth = 62;
+ this.dataGridView.RowTemplate.Height = 33;
+ this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+ this.dataGridView.Size = new System.Drawing.Size(1201, 520);
+ this.dataGridView.TabIndex = 0;
+ //
+ // menuStrip
+ //
+ this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
+ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.справочникиToolStripMenuItem});
+ this.menuStrip.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip.Name = "menuStrip";
+ this.menuStrip.Size = new System.Drawing.Size(1452, 33);
+ this.menuStrip.TabIndex = 1;
+ this.menuStrip.Text = "menuStrip1";
+ //
+ // справочникиToolStripMenuItem
+ //
+ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.условияToolStripMenuItem,
+ this.путешествияToolStripMenuItem});
+ this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
+ this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29);
+ this.справочникиToolStripMenuItem.Text = "Справочники";
+ //
+ // условияToolStripMenuItem
+ //
+ this.условияToolStripMenuItem.Name = "условияToolStripMenuItem";
+ this.условияToolStripMenuItem.Size = new System.Drawing.Size(219, 34);
+ this.условияToolStripMenuItem.Text = "Условия";
+ this.условияToolStripMenuItem.Click += new System.EventHandler(this.условияToolStripMenuItem_Click);
+ //
+ // путешествияToolStripMenuItem
+ //
+ this.путешествияToolStripMenuItem.Name = "путешествияToolStripMenuItem";
+ this.путешествияToolStripMenuItem.Size = new System.Drawing.Size(219, 34);
+ this.путешествияToolStripMenuItem.Text = "Путешествия";
+ this.путешествияToolStripMenuItem.Click += new System.EventHandler(this.путешествияToolStripMenuItem_Click);
+ //
+ // buttonCreateOrder
+ //
+ this.buttonCreateOrder.Location = new System.Drawing.Point(1224, 55);
+ this.buttonCreateOrder.Name = "buttonCreateOrder";
+ this.buttonCreateOrder.Size = new System.Drawing.Size(216, 34);
+ this.buttonCreateOrder.TabIndex = 2;
+ this.buttonCreateOrder.Text = "Создать заказ";
+ this.buttonCreateOrder.UseVisualStyleBackColor = true;
+ this.buttonCreateOrder.Click += new System.EventHandler(this.buttonCreateOrder_Click);
+ //
+ // ButtonTakeOrderInWork
+ //
+ this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(1224, 124);
+ this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork";
+ this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(216, 34);
+ this.ButtonTakeOrderInWork.TabIndex = 3;
+ this.ButtonTakeOrderInWork.Text = "Отдать на выполнение";
+ this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true;
+ this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
+ //
+ // ButtonOrderReady
+ //
+ this.ButtonOrderReady.Location = new System.Drawing.Point(1224, 203);
+ this.ButtonOrderReady.Name = "ButtonOrderReady";
+ this.ButtonOrderReady.Size = new System.Drawing.Size(216, 34);
+ this.ButtonOrderReady.TabIndex = 4;
+ this.ButtonOrderReady.Text = "Заказ готов";
+ this.ButtonOrderReady.UseVisualStyleBackColor = true;
+ this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
+ //
+ // ButtonIssuedOrder
+ //
+ this.ButtonIssuedOrder.Location = new System.Drawing.Point(1224, 267);
+ this.ButtonIssuedOrder.Name = "ButtonIssuedOrder";
+ this.ButtonIssuedOrder.Size = new System.Drawing.Size(216, 34);
+ this.ButtonIssuedOrder.TabIndex = 5;
+ this.ButtonIssuedOrder.Text = "Заказ выдан";
+ this.ButtonIssuedOrder.UseVisualStyleBackColor = true;
+ this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
+ //
+ // ButtonRef
+ //
+ this.ButtonRef.Location = new System.Drawing.Point(1224, 338);
+ this.ButtonRef.Name = "ButtonRef";
+ this.ButtonRef.Size = new System.Drawing.Size(216, 34);
+ this.ButtonRef.TabIndex = 6;
+ this.ButtonRef.Text = "Обновить список";
+ this.ButtonRef.UseVisualStyleBackColor = true;
+ this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // FormMain
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1452, 577);
+ this.Controls.Add(this.ButtonRef);
+ this.Controls.Add(this.ButtonIssuedOrder);
+ this.Controls.Add(this.ButtonOrderReady);
+ this.Controls.Add(this.ButtonTakeOrderInWork);
+ this.Controls.Add(this.buttonCreateOrder);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.menuStrip);
+ this.MainMenuStrip = this.menuStrip;
+ this.Name = "FormMain";
+ this.Text = "Туристическая фирма";
+ this.Load += new System.EventHandler(this.FormMain_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.menuStrip.ResumeLayout(false);
+ this.menuStrip.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem справочникиToolStripMenuItem;
+ private ToolStripMenuItem условияToolStripMenuItem;
+ private ToolStripMenuItem путешествияToolStripMenuItem;
+ private Button buttonCreateOrder;
+ private Button ButtonTakeOrderInWork;
+ private Button ButtonOrderReady;
+ private Button ButtonIssuedOrder;
+ private Button ButtonRef;
+ }
+}
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormMain.cs b/TravelCompany/TravelCompany/FormMain.cs
new file mode 100644
index 0000000..b40f6c6
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormMain.cs
@@ -0,0 +1,155 @@
+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.BindingModels;
+using TravelCompanyContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+
+
+
+namespace TravelCompany
+{
+ 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;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделий");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void условияToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormConditions));
+ if (service is FormConditions 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();
+ }
+
+ private void путешествияToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormTravels));
+ if (service is FormTravels form)
+ {
+ form.ShowDialog();
+ }
+ }
+ }
+}
diff --git a/TravelCompany/TravelCompany/FormMain.resx b/TravelCompany/TravelCompany/FormMain.resx
new file mode 100644
index 0000000..81a9e3d
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormMain.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormTravel.Designer.cs b/TravelCompany/TravelCompany/FormTravel.Designer.cs
new file mode 100644
index 0000000..8b31201
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormTravel.Designer.cs
@@ -0,0 +1,240 @@
+namespace TravelCompany
+{
+ 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()
+ {
+ this.labelName = new System.Windows.Forms.Label();
+ this.labelPrice = new System.Windows.Forms.Label();
+ this.groupBoxConditions = new System.Windows.Forms.GroupBox();
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ConditionId = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ConditionName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Cost = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.textBoxPrice = new System.Windows.Forms.TextBox();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.groupBoxConditions.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(30, 26);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(94, 25);
+ this.labelName.TabIndex = 0;
+ this.labelName.Text = "Название:";
+ //
+ // labelPrice
+ //
+ this.labelPrice.AutoSize = true;
+ this.labelPrice.Location = new System.Drawing.Point(21, 65);
+ this.labelPrice.Name = "labelPrice";
+ this.labelPrice.Size = new System.Drawing.Size(103, 25);
+ this.labelPrice.TabIndex = 1;
+ this.labelPrice.Text = "Стоимость:";
+ //
+ // groupBoxConditions
+ //
+ this.groupBoxConditions.Controls.Add(this.buttonRef);
+ this.groupBoxConditions.Controls.Add(this.dataGridView);
+ this.groupBoxConditions.Controls.Add(this.buttonDel);
+ this.groupBoxConditions.Controls.Add(this.buttonAdd);
+ this.groupBoxConditions.Controls.Add(this.buttonUpd);
+ this.groupBoxConditions.Location = new System.Drawing.Point(12, 120);
+ this.groupBoxConditions.Name = "groupBoxConditions";
+ this.groupBoxConditions.Size = new System.Drawing.Size(803, 366);
+ this.groupBoxConditions.TabIndex = 2;
+ this.groupBoxConditions.TabStop = false;
+ this.groupBoxConditions.Text = "Условия путешествия";
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(662, 290);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(117, 45);
+ this.buttonRef.TabIndex = 8;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.BackgroundColor = System.Drawing.Color.White;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ConditionId,
+ this.ConditionName,
+ this.Cost});
+ this.dataGridView.Location = new System.Drawing.Point(18, 30);
+ this.dataGridView.MultiSelect = false;
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersVisible = false;
+ this.dataGridView.RowHeadersWidth = 62;
+ this.dataGridView.RowTemplate.Height = 33;
+ this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+ this.dataGridView.Size = new System.Drawing.Size(624, 317);
+ this.dataGridView.TabIndex = 0;
+ //
+ // ConditionId
+ //
+ this.ConditionId.HeaderText = "ID";
+ this.ConditionId.MinimumWidth = 8;
+ this.ConditionId.Name = "ConditionId";
+ this.ConditionId.ReadOnly = true;
+ this.ConditionId.Visible = false;
+ this.ConditionId.Width = 150;
+ //
+ // ConditionName
+ //
+ this.ConditionName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.ConditionName.HeaderText = "Название";
+ this.ConditionName.MinimumWidth = 8;
+ this.ConditionName.Name = "ConditionName";
+ this.ConditionName.ReadOnly = true;
+ //
+ // Cost
+ //
+ this.Cost.HeaderText = "Цена";
+ this.Cost.MinimumWidth = 8;
+ this.Cost.Name = "Cost";
+ this.Cost.ReadOnly = true;
+ this.Cost.Width = 150;
+ //
+ // buttonDel
+ //
+ this.buttonDel.Location = new System.Drawing.Point(662, 208);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(117, 45);
+ this.buttonDel.TabIndex = 7;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(662, 52);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(117, 45);
+ this.buttonAdd.TabIndex = 5;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(662, 127);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(117, 45);
+ this.buttonUpd.TabIndex = 6;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click);
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(130, 26);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(308, 31);
+ this.textBoxName.TabIndex = 3;
+ //
+ // textBoxPrice
+ //
+ this.textBoxPrice.Location = new System.Drawing.Point(130, 65);
+ this.textBoxPrice.Name = "textBoxPrice";
+ this.textBoxPrice.ReadOnly = true;
+ this.textBoxPrice.Size = new System.Drawing.Size(150, 31);
+ this.textBoxPrice.TabIndex = 4;
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(537, 500);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(117, 36);
+ this.buttonCancel.TabIndex = 10;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(669, 500);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(122, 36);
+ this.buttonSave.TabIndex = 9;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
+ //
+ // FormTravel
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(830, 548);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.textBoxPrice);
+ this.Controls.Add(this.textBoxName);
+ this.Controls.Add(this.groupBoxConditions);
+ this.Controls.Add(this.labelPrice);
+ this.Controls.Add(this.labelName);
+ this.Name = "FormTravel";
+ this.Text = "Путешествие";
+ this.Load += new System.EventHandler(this.FormTravel_Load);
+ this.groupBoxConditions.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelPrice;
+ private GroupBox groupBoxConditions;
+ private DataGridView dataGridView;
+ private TextBox textBoxName;
+ private TextBox textBoxPrice;
+ private Button buttonRef;
+ private Button buttonDel;
+ private Button buttonAdd;
+ private Button buttonUpd;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private DataGridViewTextBoxColumn ConditionId;
+ private DataGridViewTextBoxColumn ConditionName;
+ private DataGridViewTextBoxColumn Cost;
+ }
+}
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormTravel.cs b/TravelCompany/TravelCompany/FormTravel.cs
new file mode 100644
index 0000000..a02c63d
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormTravel.cs
@@ -0,0 +1,224 @@
+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.BindingModels;
+using TravelCompanyContracts.BusinessLogicsContracts;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyDataModels.Models;
+using Microsoft.Extensions.Logging;
+
+namespace TravelCompany
+{
+ public partial class FormTravel : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ITravelLogic _logic;
+ private int? _id;
+ private Dictionary _travelConditions;
+ public int Id { set { _id = value; } }
+ public FormTravel(ILogger logger, ITravelLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _travelConditions = 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();
+ _travelConditions = view.TravelConditions ?? new
+ Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка компонент изделия");
+ try
+ {
+ if (_travelConditions != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var pc in _travelConditions)
+ {
+ dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ConditionName, pc.Value.Item2 });
+ }
+ textBoxPrice.Text = CalcPrice().ToString();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки компонент изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+
+ private double CalcPrice()
+ {
+ double price = 0;
+ foreach (var elem in _travelConditions)
+ {
+ price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
+ }
+ return Math.Round(price * 1.1, 2);
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+
+ 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("Удаление компонента:{ConditionName}- { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
+ _travelConditions?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ 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 (_travelConditions == null || _travelConditions.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),
+ TravelConditions = _travelConditions
+ };
+ 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 buttonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void buttonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormTravelCondition));
+ if (service is FormTravelCondition form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ConditionModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Добавление нового условия:{ ConditionName} - { Count}", form.ConditionModel.ConditionName, form.Count);
+ if (_travelConditions.ContainsKey(form.Id))
+ {
+ _travelConditions[form.Id] = (form.ConditionModel,
+ form.Count);
+ }
+ else
+ {
+ _travelConditions.Add(form.Id, (form.ConditionModel,
+ form.Count));
+ }
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormTravelCondition));
+ if (service is FormTravelCondition form)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _travelConditions[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ConditionModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Изменение компонента:{ ConditionName}- { Count}", form.ConditionModel.ConditionName, form.Count);
+ _travelConditions[form.Id] = (form.ConditionModel, form.Count);
+ LoadData();
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormTravel.resx b/TravelCompany/TravelCompany/FormTravel.resx
new file mode 100644
index 0000000..a202a8c
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormTravel.resx
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/FormTravelCondition.Designer.cs b/TravelCompany/TravelCompany/FormTravelCondition.Designer.cs
new file mode 100644
index 0000000..c10c953
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormTravelCondition.Designer.cs
@@ -0,0 +1,119 @@
+namespace TravelCompany
+{
+ partial class FormTravelCondition
+ {
+ ///
+ /// 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.textBoxCount = new System.Windows.Forms.TextBox();
+ this.labelCount = new System.Windows.Forms.Label();
+ this.labelName = new System.Windows.Forms.Label();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.comboBoxCondition = new System.Windows.Forms.ComboBox();
+ this.SuspendLayout();
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(126, 77);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(181, 31);
+ this.textBoxCount.TabIndex = 11;
+ //
+ // labelCount
+ //
+ this.labelCount.AutoSize = true;
+ this.labelCount.Location = new System.Drawing.Point(4, 77);
+ this.labelCount.Name = "labelCount";
+ this.labelCount.Size = new System.Drawing.Size(111, 25);
+ this.labelCount.TabIndex = 9;
+ this.labelCount.Text = "Количество:";
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(32, 28);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(83, 25);
+ this.labelName.TabIndex = 8;
+ this.labelName.Text = "Условие:";
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(443, 77);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(112, 34);
+ this.buttonCancel.TabIndex = 7;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(325, 75);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(112, 34);
+ this.buttonSave.TabIndex = 6;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // comboBoxCondition
+ //
+ this.comboBoxCondition.FormattingEnabled = true;
+ this.comboBoxCondition.Location = new System.Drawing.Point(126, 26);
+ this.comboBoxCondition.Name = "comboBoxCondition";
+ this.comboBoxCondition.Size = new System.Drawing.Size(429, 33);
+ this.comboBoxCondition.TabIndex = 12;
+ //
+ // FormTravelCondition
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(584, 137);
+ this.Controls.Add(this.comboBoxCondition);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.labelCount);
+ this.Controls.Add(this.labelName);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Name = "FormTravelCondition";
+ this.Text = "FormTravelComponent";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private TextBox textBoxCount;
+ private Label labelCount;
+ private Label labelName;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private ComboBox comboBoxCondition;
+ }
+}
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormTravelCondition.cs b/TravelCompany/TravelCompany/FormTravelCondition.cs
new file mode 100644
index 0000000..e331b71
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormTravelCondition.cs
@@ -0,0 +1,92 @@
+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.ViewModels;
+using TravelCompanyDataModels.Models;
+
+namespace TravelCompany
+{
+ public partial class FormTravelCondition : Form
+ {
+ private readonly List? _list;
+ public int Id
+ {
+ get
+ {
+ return Convert.ToInt32(comboBoxCondition.SelectedValue);
+ }
+ set
+ {
+ comboBoxCondition.SelectedValue = value;
+ }
+ }
+ public IConditionModel? ConditionModel
+ {
+ 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 FormTravelCondition(IConditionLogic logic)
+ {
+ InitializeComponent();
+ _list = logic.ReadList(null);
+ if (_list != null)
+ {
+ comboBoxCondition.DisplayMember = "ConditionName";
+ comboBoxCondition.ValueMember = "Id";
+ comboBoxCondition.DataSource = _list;
+ comboBoxCondition.SelectedItem = null;
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxCondition.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/FormTravelCondition.resx b/TravelCompany/TravelCompany/FormTravelCondition.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormTravelCondition.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/FormTravels.Designer.cs b/TravelCompany/TravelCompany/FormTravels.Designer.cs
new file mode 100644
index 0000000..5ddc764
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormTravels.Designer.cs
@@ -0,0 +1,119 @@
+namespace TravelCompany
+{
+ 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()
+ {
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonRef
+ //
+ this.buttonRef.Location = new System.Drawing.Point(560, 280);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(112, 34);
+ this.buttonRef.TabIndex = 9;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // buttonDel
+ //
+ this.buttonDel.Location = new System.Drawing.Point(560, 191);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(112, 34);
+ this.buttonDel.TabIndex = 8;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(560, 109);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(112, 34);
+ this.buttonUpd.TabIndex = 7;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(560, 33);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(112, 34);
+ this.buttonAdd.TabIndex = 6;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.BackgroundColor = System.Drawing.Color.White;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(8, 7);
+ this.dataGridView.MultiSelect = false;
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersVisible = false;
+ this.dataGridView.RowHeadersWidth = 62;
+ this.dataGridView.RowTemplate.Height = 33;
+ this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+ this.dataGridView.Size = new System.Drawing.Size(525, 521);
+ this.dataGridView.TabIndex = 5;
+ //
+ // FormTravels
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(704, 536);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonDel);
+ this.Controls.Add(this.buttonUpd);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormTravels";
+ this.Text = "Путешествия";
+ this.Load += new System.EventHandler(this.FormTravels_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.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..55b79e0
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormTravels.cs
@@ -0,0 +1,116 @@
+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.BindingModels;
+using TravelCompanyContracts.BusinessLogicsContracts;
+
+namespace TravelCompany
+{
+ 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 LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["TravelConditions"].Visible = false;
+ dataGridView.Columns["TravelName"].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(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();
+ }
+
+ private void FormTravels_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/TravelCompany/TravelCompany/FormTravels.resx b/TravelCompany/TravelCompany/FormTravels.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/TravelCompany/TravelCompany/FormTravels.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/Program.cs b/TravelCompany/TravelCompany/Program.cs
index 9429054..6e49f02 100644
--- a/TravelCompany/TravelCompany/Program.cs
+++ b/TravelCompany/TravelCompany/Program.cs
@@ -1,7 +1,17 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+using TravelCompanyContracts.BusinessLogicsContracts;
+using TravelCompanyContracts.StoragesContracts;
+using TravelCompanyListImplement.Implements;
+using TravelCompanyBusinessLogic.BusinessLogic;
+
namespace TravelCompany
{
internal static class Program
{
+ private static ServiceProvider? _serviceProvider;
+ public static ServiceProvider? ServiceProvider => _serviceProvider;
///
/// The main entry point for the application.
///
@@ -11,7 +21,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..2cfe538 100644
--- a/TravelCompany/TravelCompany/TravelCompany.csproj
+++ b/TravelCompany/TravelCompany/TravelCompany.csproj
@@ -8,4 +8,28 @@
enable
+
+
+
+
+
+
+ Always
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TravelCompany/TravelCompany/nlog.config b/TravelCompany/TravelCompany/nlog.config
new file mode 100644
index 0000000..8b8ffd8
--- /dev/null
+++ b/TravelCompany/TravelCompany/nlog.config
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ConditionLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ConditionLogic.cs
new file mode 100644
index 0000000..2894d2e
--- /dev/null
+++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ConditionLogic.cs
@@ -0,0 +1,112 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.BusinessLogicsContracts;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.StoragesContracts;
+using TravelCompanyContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+
+
+namespace TravelCompanyBusinessLogic.BusinessLogic
+{
+ public class ConditionLogic : IConditionLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IConditionStorage _ConditionStorage;
+ public ConditionLogic(ILogger logger, IConditionStorage ConditionStorage)
+ {
+ _logger = logger;
+ _ConditionStorage = ConditionStorage;
+ }
+ public List? ReadList(ConditionSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. ConditionName:{ConditionName}.Id:{ Id}", model?.ConditionName, model?.Id);
+ var list = model == null ? _ConditionStorage.GetFullList() : _ConditionStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public ConditionViewModel? ReadElement(ConditionSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. ConditionName:{ConditionName}.Id:{ Id}", model.ConditionName, model.Id);
+ var element = _ConditionStorage.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(ConditionBindingModel model)
+ {
+ CheckModel(model);
+ if (_ConditionStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(ConditionBindingModel model)
+ {
+ CheckModel(model);
+ if (_ConditionStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(ConditionBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_ConditionStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(ConditionBindingModel model, bool withParams =
+ true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ConditionName))
+ {
+ throw new ArgumentNullException("Нет названия компонента",
+ nameof(model.ConditionName));
+ }
+ if (model.Cost <= 0)
+ {
+ throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
+ }
+ _logger.LogInformation("Condition. ConditionName:{ConditionName}.Cost:{ Cost}.Id: { Id}", model.ConditionName, model.Cost, model.Id);
+ var element = _ConditionStorage.GetElement(new ConditionSearchModel { ConditionName = model.ConditionName });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Компонент с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/OrderLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/OrderLogic.cs
new file mode 100644
index 0000000..699eabb
--- /dev/null
+++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/OrderLogic.cs
@@ -0,0 +1,147 @@
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.BusinessLogicsContracts;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.StoragesContracts;
+using TravelCompanyContracts.ViewModels;
+using TravelCompanyDataModels.Enums;
+
+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 bool CreateOrder(OrderBindingModel model)
+ {
+ CheckModel(model);
+ if (model.Status != OrderStatus.Неизвестен) return false;
+ model.Status = OrderStatus.Принят;
+ if (_orderStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool DeliveryOrder(OrderBindingModel model)
+ {
+ CheckModel(model, false);
+ var element = _orderStorage.GetElement(new OrderSearchModel
+ {
+ Id = model.Id
+ });
+ if (element == null)
+ {
+ _logger.LogWarning("Read operation failed");
+ return false;
+ }
+ if (element.Status != OrderStatus.Готов)
+ {
+ _logger.LogWarning("Status change operation failed");
+ throw new InvalidOperationException("Нельзя выдать заказ, если его статус не 'Готов'!");
+ }
+ model.Status = OrderStatus.Выдан;
+ model.DateImplement = DateTime.Now;
+ _orderStorage.Update(model);
+ return true;
+ }
+
+ public bool FinishOrder(OrderBindingModel model)
+ {
+ CheckModel(model, false);
+ var element = _orderStorage.GetElement(new OrderSearchModel
+ {
+ Id = model.Id
+ });
+ if (element == null)
+ {
+ _logger.LogWarning("Read operation failed");
+ return false;
+ }
+ if (element.Status != OrderStatus.Выполняется)
+ {
+ _logger.LogWarning("Status change operation failed");
+ throw new InvalidOperationException("Статус заказа 'Готов' может быть присвоен только заказам со статусом 'Выполняется'!");
+ }
+ model.Status = OrderStatus.Готов;
+ _orderStorage.Update(model);
+ return true;
+ }
+
+ public List? ReadList(OrderSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. Id:{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 TakeOrderInWork(OrderBindingModel model)
+ {
+ CheckModel(model, false);
+ var element = _orderStorage.GetElement(new OrderSearchModel
+ {
+ Id = model.Id
+ });
+ if (element == null)
+ {
+ _logger.LogWarning("Read operation failed");
+ return false;
+ }
+ if (element.Status != OrderStatus.Принят)
+ {
+ _logger.LogWarning("Status change operation failed");
+ throw new InvalidOperationException("Статус заказа 'Выполняется' может быть присвоен только заказам со статусом 'Принят'!");
+ }
+ model.Status = OrderStatus.Выполняется;
+ _orderStorage.Update(model);
+ return true;
+ }
+
+ private void CheckModel(OrderBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.Sum <= 0)
+ {
+ throw new ArgumentNullException("Сумма заказа должна быть больше 0!", nameof(model.Sum));
+ }
+ if (model.Count <= 0)
+ {
+ throw new ArgumentNullException("Количество изделий должно быть более 0!", nameof(model.Count));
+ }
+ _logger.LogInformation("Order. Sum:{Sum}. Id:{Id}", model.Sum, model.Id);
+ var element = _orderStorage.GetElement(new OrderSearchModel
+ {
+ Id = model.Id
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Заказ с таким ID уже существует");
+ }
+ }
+ }
+}
diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/TravelLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/TravelLogic.cs
new file mode 100644
index 0000000..db37f0f
--- /dev/null
+++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/TravelLogic.cs
@@ -0,0 +1,112 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.BusinessLogicsContracts;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.StoragesContracts;
+using TravelCompanyContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+
+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:{ Price}.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..015f884
--- /dev/null
+++ b/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj
@@ -0,0 +1,20 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/ConditionBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/ConditionBindingModel.cs
new file mode 100644
index 0000000..7d6dd37
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/BindingModels/ConditionBindingModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyDataModels.Models;
+
+namespace TravelCompanyContracts.BindingModels
+{
+ public class ConditionBindingModel : IConditionModel
+ {
+ public int Id { get; set; }
+ public string ConditionName {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..6d24acd
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/BindingModels/OrderBindingModel.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyDataModels.Models;
+using TravelCompanyDataModels.Enums;
+
+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..d5b8898
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/BindingModels/TravelBindingModel.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyDataModels.Models;
+
+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 TravelConditions
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IConditionLogic.cs b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IConditionLogic.cs
new file mode 100644
index 0000000..be0c7a4
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IConditionLogic.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.ViewModels;
+
+namespace TravelCompanyContracts.BusinessLogicsContracts
+{
+ public interface IConditionLogic
+ {
+ List? ReadList(ConditionSearchModel? model);
+ ConditionViewModel? ReadElement(ConditionSearchModel model);
+ bool Create(ConditionBindingModel model);
+ bool Update(ConditionBindingModel model);
+ bool Delete(ConditionBindingModel model);
+ }
+}
diff --git a/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IOrderLogic.cs b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IOrderLogic.cs
new file mode 100644
index 0000000..612a1fa
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.ViewModels;
+
+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..b9e06c8
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/BusinessLogicsContracts/ITravelLogic.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.ViewModels;
+
+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/ConditionSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/ConditionSearchModel.cs
new file mode 100644
index 0000000..f07121f
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/SearchModels/ConditionSearchModel.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 ConditionSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ConditionName { 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/IConditionStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesContracts/IConditionStorage.cs
new file mode 100644
index 0000000..a0f17f7
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/IConditionStorage.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.ViewModels;
+
+namespace TravelCompanyContracts.StoragesContracts
+{
+ public interface IConditionStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ConditionSearchModel model);
+ ConditionViewModel? GetElement(ConditionSearchModel model);
+ ConditionViewModel? Insert(ConditionBindingModel model);
+ ConditionViewModel? Update(ConditionBindingModel model);
+ ConditionViewModel? Delete(ConditionBindingModel model);
+ }
+}
diff --git a/TravelCompany/TravelCompanyContracts/StoragesContracts/IOrderStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesContracts/IOrderStorage.cs
new file mode 100644
index 0000000..114bc73
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/IOrderStorage.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.ViewModels;
+
+
+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..b96e593
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/ITravelStorage.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.ViewModels;
+
+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..78baecb
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/ConditionViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/ConditionViewModel.cs
new file mode 100644
index 0000000..c6834be
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/ViewModels/ConditionViewModel.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyDataModels.Models;
+using System.ComponentModel;
+
+namespace TravelCompanyContracts.ViewModels
+{
+ public class ConditionViewModel : IConditionModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название условия")]
+ public string ConditionName { 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..24bd5f3
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyDataModels.Enums;
+using TravelCompanyDataModels.Models;
+using System.ComponentModel;
+
+
+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..7473cff
--- /dev/null
+++ b/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyDataModels.Models;
+using System.ComponentModel;
+
+namespace TravelCompanyContracts.ViewModels
+{
+ public class TravelViewModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название путешествия")]
+ public string TravelName { get; set; } = string.Empty;
+ [DisplayName("Цена")]
+ public double Price { get; set; }
+ public Dictionary TravelConditions
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs b/TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs
new file mode 100644
index 0000000..760ff65
--- /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/IConditionModel.cs b/TravelCompany/TravelCompanyDataModels/Models/IConditionModel.cs
new file mode 100644
index 0000000..dd626b7
--- /dev/null
+++ b/TravelCompany/TravelCompanyDataModels/Models/IConditionModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TravelCompanyDataModels.Models
+{
+ public interface IConditionModel : IId
+ {
+ string ConditionName { get; }
+ double Cost { get; }
+ }
+}
diff --git a/TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs b/TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs
new file mode 100644
index 0000000..b23d3aa
--- /dev/null
+++ b/TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+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; }
+ }
+}
diff --git a/TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs b/TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs
new file mode 100644
index 0000000..0fcd8e6
--- /dev/null
+++ b/TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TravelCompanyDataModels.Models
+{
+ public interface ITravelModel : IId
+ {
+ string TravelName { get; }
+ double Price { get; }
+ Dictionary TravelConditions { get; }
+ }
+}
diff --git a/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj b/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj
new file mode 100644
index 0000000..132c02c
--- /dev/null
+++ b/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
diff --git a/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs b/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs
new file mode 100644
index 0000000..13e8321
--- /dev/null
+++ b/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyListImplement.Models;
+
+namespace TravelCompanyListImplement
+{
+ internal class DataListSingleton
+ {
+ private static DataListSingleton? _instance;
+ public List Conditions { get; set; }
+ public List Orders { get; set; }
+ public List Travels { get; set; }
+ private DataListSingleton()
+ {
+ Conditions = 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/ConditionStorage.cs b/TravelCompany/TravelCompanyListImplement/Implements/ConditionStorage.cs
new file mode 100644
index 0000000..0e6e162
--- /dev/null
+++ b/TravelCompany/TravelCompanyListImplement/Implements/ConditionStorage.cs
@@ -0,0 +1,109 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.StoragesContracts;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.ViewModels;
+using TravelCompanyListImplement.Models;
+
+namespace TravelCompanyListImplement.Implements
+{
+ public class ConditionStorage : IConditionStorage
+ {
+ private readonly DataListSingleton _source;
+ public ConditionStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var condition in _source.Conditions)
+ {
+ result.Add(condition.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(ConditionSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.ConditionName))
+ {
+ return result;
+ }
+ foreach (var condition in _source.Conditions)
+ {
+ if (condition.ConditionName.Contains(model.ConditionName))
+ {
+ result.Add(condition.GetViewModel);
+ }
+ }
+ return result;
+ }
+ public ConditionViewModel? GetElement(ConditionSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ConditionName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var condition in _source.Conditions)
+ {
+ if ((!string.IsNullOrEmpty(model.ConditionName) &&
+ condition.ConditionName == model.ConditionName) ||
+ (model.Id.HasValue && condition.Id == model.Id))
+ {
+ return condition.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ConditionViewModel? Insert(ConditionBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var condition in _source.Conditions)
+ {
+ if (model.Id <= condition.Id)
+ {
+ model.Id = condition.Id + 1;
+ }
+ }
+ var newCondition = Condition.Create(model);
+ if (newCondition == null)
+ {
+ return null;
+ }
+ _source.Conditions.Add(newCondition);
+ return newCondition.GetViewModel;
+ }
+ public ConditionViewModel? Update(ConditionBindingModel model)
+ {
+ foreach (var condition in _source.Conditions)
+ {
+ if (condition.Id == model.Id)
+ {
+ condition.Update(model);
+ return condition.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ConditionViewModel? Delete(ConditionBindingModel model)
+ {
+ for (int i = 0; i < _source.Conditions.Count; ++i)
+ {
+ if (_source.Conditions[i].Id == model.Id)
+ {
+ var element = _source.Conditions[i];
+ _source.Conditions.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..23997db
--- /dev/null
+++ b/TravelCompany/TravelCompanyListImplement/Implements/OrderStorage.cs
@@ -0,0 +1,119 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.StoragesContracts;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.ViewModels;
+using TravelCompanyListImplement.Models;
+
+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(InsertTravelName(order.GetViewModel));
+ }
+ return result;
+ }
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ var result = new List();
+ if (!model.Id.HasValue)
+ {
+ return result;
+ }
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ result.Add(InsertTravelName(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 InsertTravelName(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 InsertTravelName(newOrder.GetViewModel);
+ }
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ order.Update(model);
+ return InsertTravelName(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 InsertTravelName(element.GetViewModel);
+ }
+ }
+ return null;
+ }
+
+ public OrderViewModel InsertTravelName(OrderViewModel notFullModel)
+ {
+ var travels = _source.Travels;
+ for (int i = 0; i < travels.Count; i++)
+ {
+ if (travels[i].Id == notFullModel.TravelId)
+ {
+ notFullModel.TravelName = travels[i].TravelName;
+ break;
+ }
+ }
+ return notFullModel;
+ }
+ }
+}
diff --git a/TravelCompany/TravelCompanyListImplement/Implements/TravelStorage.cs b/TravelCompany/TravelCompanyListImplement/Implements/TravelStorage.cs
new file mode 100644
index 0000000..494d1e4
--- /dev/null
+++ b/TravelCompany/TravelCompanyListImplement/Implements/TravelStorage.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.StoragesContracts;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.SearchModels;
+using TravelCompanyContracts.ViewModels;
+using TravelCompanyListImplement.Models;
+
+namespace TravelCompanyListImplement.Implements
+{
+ public class TravelStorage : ITravelStorage
+ {
+ private readonly DataListSingleton _source;
+ public TravelStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var travel in _source.Travels)
+ {
+ result.Add(travel.GetViewModel);
+ }
+ return result;
+ }
+ 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 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 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;
+ }
+ 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;
+ }
+ }
+}
diff --git a/TravelCompany/TravelCompanyListImplement/Models/Condition.cs b/TravelCompany/TravelCompanyListImplement/Models/Condition.cs
new file mode 100644
index 0000000..f310928
--- /dev/null
+++ b/TravelCompany/TravelCompanyListImplement/Models/Condition.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.ViewModels;
+using TravelCompanyDataModels.Models;
+
+namespace TravelCompanyListImplement.Models
+{
+ public class Condition : IConditionModel
+ {
+ public int Id { get; private set; }
+ public string ConditionName { get; private set; } = string.Empty;
+ public double Cost { get; set; }
+ public static Condition? Create(ConditionBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Condition()
+ {
+ Id = model.Id,
+ ConditionName = model.ConditionName,
+ Cost = model.Cost
+ };
+ }
+ public void Update(ConditionBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ConditionName = model.ConditionName;
+ Cost = model.Cost;
+ }
+ public ConditionViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ConditionName = ConditionName,
+ Cost = Cost
+ };
+ }
+}
diff --git a/TravelCompany/TravelCompanyListImplement/Models/Order.cs b/TravelCompany/TravelCompanyListImplement/Models/Order.cs
new file mode 100644
index 0000000..58685cf
--- /dev/null
+++ b/TravelCompany/TravelCompanyListImplement/Models/Order.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.ViewModels;
+using TravelCompanyDataModels.Enums;
+using TravelCompanyDataModels.Models;
+
+namespace TravelCompanyListImplement.Models
+{
+ public class Order : IOrderModel
+ {
+ public int Id { get; private set; }
+ public int TravelId { get; set; }
+ public int Count { get; set; }
+ public double Sum { get; set; }
+ public OrderStatus Status { get; set; }
+ public DateTime DateCreate { get; set; }
+ public DateTime? DateImplement { get; 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;
+ }
+ Status = model.Status;
+ 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..f08866e
--- /dev/null
+++ b/TravelCompany/TravelCompanyListImplement/Models/Travel.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TravelCompanyContracts.BindingModels;
+using TravelCompanyContracts.ViewModels;
+using TravelCompanyDataModels.Models;
+
+namespace TravelCompanyListImplement.Models
+{
+ public 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 TravelConditions
+ {
+ 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,
+ TravelConditions = model.TravelConditions
+ };
+ }
+ public void Update(TravelBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ TravelName = model.TravelName;
+ Price = model.Price;
+ TravelConditions = model.TravelConditions;
+ }
+ public TravelViewModel GetViewModel => new()
+ {
+ Id = Id,
+ TravelName = TravelName,
+ Price = Price,
+ TravelConditions = TravelConditions
+ };
+
+ }
+}
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
+
+
+
+
+
+
+
+