Лабораторная работа 1.
This commit is contained in:
parent
b6c47f004c
commit
10544435c2
@ -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
|
||||
|
39
TravelCompany/TravelCompany/Form1.Designer.cs
generated
39
TravelCompany/TravelCompany/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace TravelCompany
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace TravelCompany
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
119
TravelCompany/TravelCompany/FormCondition.Designer.cs
generated
Normal file
119
TravelCompany/TravelCompany/FormCondition.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace TravelCompany
|
||||
{
|
||||
partial class FormCondition
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
96
TravelCompany/TravelCompany/FormCondition.cs
Normal file
96
TravelCompany/TravelCompany/FormCondition.cs
Normal file
@ -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<FormCondition> 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();
|
||||
}
|
||||
}
|
||||
}
|
60
TravelCompany/TravelCompany/FormCondition.resx
Normal file
60
TravelCompany/TravelCompany/FormCondition.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
119
TravelCompany/TravelCompany/FormConditions.Designer.cs
generated
Normal file
119
TravelCompany/TravelCompany/FormConditions.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace TravelCompany
|
||||
{
|
||||
partial class FormConditions
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
115
TravelCompany/TravelCompany/FormConditions.cs
Normal file
115
TravelCompany/TravelCompany/FormConditions.cs
Normal file
@ -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<FormConditions> 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();
|
||||
}
|
||||
}
|
||||
}
|
60
TravelCompany/TravelCompany/FormConditions.resx
Normal file
60
TravelCompany/TravelCompany/FormConditions.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
145
TravelCompany/TravelCompany/FormCreateOrder.Designer.cs
generated
Normal file
145
TravelCompany/TravelCompany/FormCreateOrder.Designer.cs
generated
Normal file
@ -0,0 +1,145 @@
|
||||
namespace TravelCompany
|
||||
{
|
||||
partial class FormCreateOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
123
TravelCompany/TravelCompany/FormCreateOrder.cs
Normal file
123
TravelCompany/TravelCompany/FormCreateOrder.cs
Normal file
@ -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<TravelViewModel>? _list;
|
||||
public FormCreateOrder(ILogger<FormCreateOrder> 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();
|
||||
}
|
||||
}
|
||||
}
|
60
TravelCompany/TravelCompany/FormCreateOrder.resx
Normal file
60
TravelCompany/TravelCompany/FormCreateOrder.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
180
TravelCompany/TravelCompany/FormMain.Designer.cs
generated
Normal file
180
TravelCompany/TravelCompany/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,180 @@
|
||||
namespace TravelCompany
|
||||
{
|
||||
partial class FormMain
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
155
TravelCompany/TravelCompany/FormMain.cs
Normal file
155
TravelCompany/TravelCompany/FormMain.cs
Normal file
@ -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<FormMain> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
63
TravelCompany/TravelCompany/FormMain.resx
Normal file
63
TravelCompany/TravelCompany/FormMain.resx
Normal file
@ -0,0 +1,63 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
240
TravelCompany/TravelCompany/FormTravel.Designer.cs
generated
Normal file
240
TravelCompany/TravelCompany/FormTravel.Designer.cs
generated
Normal file
@ -0,0 +1,240 @@
|
||||
namespace TravelCompany
|
||||
{
|
||||
partial class FormTravel
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
224
TravelCompany/TravelCompany/FormTravel.cs
Normal file
224
TravelCompany/TravelCompany/FormTravel.cs
Normal file
@ -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<int, (IConditionModel, int)> _travelConditions;
|
||||
public int Id { set { _id = value; } }
|
||||
public FormTravel(ILogger<FormTravel> logger, ITravelLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_travelConditions = new Dictionary<int, (IConditionModel, int)>();
|
||||
}
|
||||
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<int, (IConditionModel, int)>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
69
TravelCompany/TravelCompany/FormTravel.resx
Normal file
69
TravelCompany/TravelCompany/FormTravel.resx
Normal file
@ -0,0 +1,69 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="ConditionId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ConditionName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Cost.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
119
TravelCompany/TravelCompany/FormTravelCondition.Designer.cs
generated
Normal file
119
TravelCompany/TravelCompany/FormTravelCondition.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace TravelCompany
|
||||
{
|
||||
partial class FormTravelCondition
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
92
TravelCompany/TravelCompany/FormTravelCondition.cs
Normal file
92
TravelCompany/TravelCompany/FormTravelCondition.cs
Normal file
@ -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<ConditionViewModel>? _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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
60
TravelCompany/TravelCompany/FormTravelCondition.resx
Normal file
60
TravelCompany/TravelCompany/FormTravelCondition.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
119
TravelCompany/TravelCompany/FormTravels.Designer.cs
generated
Normal file
119
TravelCompany/TravelCompany/FormTravels.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace TravelCompany
|
||||
{
|
||||
partial class FormTravels
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
116
TravelCompany/TravelCompany/FormTravels.cs
Normal file
116
TravelCompany/TravelCompany/FormTravels.cs
Normal file
@ -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<FormTravels> 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();
|
||||
}
|
||||
}
|
||||
}
|
60
TravelCompany/TravelCompany/FormTravels.resx
Normal file
60
TravelCompany/TravelCompany/FormTravels.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -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;
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -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<FormMain>());
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
services.AddTransient<IConditionStorage, ConditionStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<ITravelStorage, TravelStorage>();
|
||||
services.AddTransient<IConditionLogic, ConditionLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<ITravelLogic, TravelLogic>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormCondition>();
|
||||
services.AddTransient<FormConditions>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormTravel>();
|
||||
services.AddTransient<FormTravelCondition>();
|
||||
services.AddTransient<FormTravels>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -8,4 +8,28 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="nlog.config" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TravelCompanyBusinessLogic\TravelCompanyBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\TravelCompanyContracts\TravelCompanyContracts.csproj" />
|
||||
<ProjectReference Include="..\TravelCompanyDataModels\TravelCompanyDataModels.csproj" />
|
||||
<ProjectReference Include="..\TravelCompanyListImplement\TravelCompanyListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
15
TravelCompany/TravelCompany/nlog.config
Normal file
15
TravelCompany/TravelCompany/nlog.config
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" internalLogLevel="Info">
|
||||
|
||||
<targets>
|
||||
<target xsi:type="File" name="tofile" fileName="${basedir}/TravelCompany-${shortdate}.log" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
@ -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<ConditionLogic> logger, IConditionStorage ConditionStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_ConditionStorage = ConditionStorage;
|
||||
}
|
||||
public List<ConditionViewModel>? 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("Компонент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<OrderLogic> 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<OrderViewModel>? 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 уже существует");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<TravelLogic> logger, ITravelStorage TravelStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_TravelStorage = TravelStorage;
|
||||
}
|
||||
|
||||
public List<TravelViewModel>? 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("Путешествие с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TravelCompanyContracts\TravelCompanyContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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<int, (IConditionModel, int)> TravelConditions
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
@ -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<ConditionViewModel>? ReadList(ConditionSearchModel? model);
|
||||
ConditionViewModel? ReadElement(ConditionSearchModel model);
|
||||
bool Create(ConditionBindingModel model);
|
||||
bool Update(ConditionBindingModel model);
|
||||
bool Delete(ConditionBindingModel model);
|
||||
}
|
||||
}
|
@ -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<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
bool DeliveryOrder(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -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<TravelViewModel>? ReadList(TravelSearchModel? model);
|
||||
TravelViewModel? ReadElement(TravelSearchModel model);
|
||||
bool Create(TravelBindingModel model);
|
||||
bool Update(TravelBindingModel model);
|
||||
bool Delete(TravelBindingModel model);
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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<ConditionViewModel> GetFullList();
|
||||
List<ConditionViewModel> GetFilteredList(ConditionSearchModel model);
|
||||
ConditionViewModel? GetElement(ConditionSearchModel model);
|
||||
ConditionViewModel? Insert(ConditionBindingModel model);
|
||||
ConditionViewModel? Update(ConditionBindingModel model);
|
||||
ConditionViewModel? Delete(ConditionBindingModel model);
|
||||
}
|
||||
}
|
@ -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<OrderViewModel> GetFullList();
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -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<TravelViewModel> GetFullList();
|
||||
List<TravelViewModel> GetFilteredList(TravelSearchModel model);
|
||||
TravelViewModel? GetElement(TravelSearchModel model);
|
||||
TravelViewModel? Insert(TravelBindingModel model);
|
||||
TravelViewModel? Update(TravelBindingModel model);
|
||||
TravelViewModel? Delete(TravelBindingModel model);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TravelCompanyDataModels\TravelCompanyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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<int, (IConditionModel, int)> TravelConditions
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
11
TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs
Normal file
11
TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace TravelCompanyDataModels.Enums
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
Неизвестен = -1,
|
||||
Принят = 0,
|
||||
Выполняется = 1,
|
||||
Готов = 2,
|
||||
Выдан = 3
|
||||
}
|
||||
}
|
13
TravelCompany/TravelCompanyDataModels/IId.cs
Normal file
13
TravelCompany/TravelCompanyDataModels/IId.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
19
TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs
Normal file
19
TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
15
TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs
Normal file
15
TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs
Normal file
@ -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<int, (IConditionModel, int)> TravelConditions { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -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<Condition> Conditions { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Travel> Travels { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Conditions = new List<Condition>();
|
||||
Orders = new List<Order>();
|
||||
Travels = new List<Travel>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DataListSingleton();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<ConditionViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ConditionViewModel>();
|
||||
foreach (var condition in _source.Conditions)
|
||||
{
|
||||
result.Add(condition.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<ConditionViewModel> GetFilteredList(ConditionSearchModel model)
|
||||
{
|
||||
var result = new List<ConditionViewModel>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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<OrderViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
result.Add(InsertTravelName(order.GetViewModel));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<TravelViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<TravelViewModel>();
|
||||
foreach (var travel in _source.Travels)
|
||||
{
|
||||
result.Add(travel.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<TravelViewModel> GetFilteredList(TravelSearchModel model)
|
||||
{
|
||||
var result = new List<TravelViewModel>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
47
TravelCompany/TravelCompanyListImplement/Models/Condition.cs
Normal file
47
TravelCompany/TravelCompanyListImplement/Models/Condition.cs
Normal file
@ -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
|
||||
};
|
||||
}
|
||||
}
|
61
TravelCompany/TravelCompanyListImplement/Models/Order.cs
Normal file
61
TravelCompany/TravelCompanyListImplement/Models/Order.cs
Normal file
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
55
TravelCompany/TravelCompanyListImplement/Models/Travel.cs
Normal file
55
TravelCompany/TravelCompanyListImplement/Models/Travel.cs
Normal file
@ -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<int, (IConditionModel, int)> TravelConditions
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<int, (IConditionModel, int)>();
|
||||
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
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TravelCompanyContracts\TravelCompanyContracts.csproj" />
|
||||
<ProjectReference Include="..\TravelCompanyDataModels\TravelCompanyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user