Compare commits

...

102 Commits

Author SHA1 Message Date
7e88c9f5bd fix 2023-04-24 10:23:16 +04:00
da91f0641c fix 2023-04-24 10:23:02 +04:00
97736d8dde Исправлен апдейт магазина 2023-04-09 16:13:54 +04:00
8956013a65 Merge branch 'LabWork03_Base' into LabWork03_Hard 2023-04-07 21:46:32 +04:00
6583464c28 Исправление 2023-04-07 21:45:37 +04:00
4e7e88cb3f Merge branch 'LabWork02_Hard' into LabWork03_Hard 2023-04-07 16:06:22 +04:00
71f60ebf7a Исправление 2023-04-07 16:05:54 +04:00
0b3b9b391a Переделан под LINQ метод SellDocument 2023-04-07 16:04:49 +04:00
793c2eae4e merge 2023-03-24 21:01:10 +04:00
5327fd4511 fix 2023-03-13 11:15:33 +04:00
00c2a39c41 Сдана 2 хард 2023-03-13 10:14:57 +04:00
0fb113ffbd Вроде готово 2023-03-12 19:26:43 +04:00
50a53fe8f4 Merge branch 'LabWork02_Hard' into LabWork03_Hard 2023-03-12 19:00:47 +04:00
51738e8616 Обновлена логика продажи из магазинов 2023-03-12 19:00:22 +04:00
cc30da7d11 созданы модели 2023-03-12 18:42:24 +04:00
c3e9384f23 Merge branch 'LabWork03_Base' into LabWork03_Hard 2023-03-12 17:56:03 +04:00
2036d05b3a фикс 2023-03-12 14:58:17 +04:00
cca8ab71f3 Исправления 2023-03-11 15:08:25 +04:00
1ac54c8db8 Merge branch 'LabWork02_Base' into LabWork03_Base 2023-03-10 21:07:06 +04:00
27bd7178b1 Merge branch 'LabWork02_Base' into LabWork02_Hard 2023-03-10 21:06:32 +04:00
80460ececd Требование LINQ 2023-03-10 21:06:09 +04:00
851b151d03 Исправления 2023-03-10 20:47:22 +04:00
cb681bb79e Merge branch 'LabWork03_Base' of http://student.git.athene.tech/Danila_Mochalov/PIbd-23_Mochalov_D.V._LawFirm into LabWork03_Base 2023-03-10 19:48:59 +04:00
3e8b6586d3 Базовая лаб3 вроде работает 2023-03-10 19:48:46 +04:00
5e5d85698b Создание миграции и БД 2023-03-10 19:48:46 +04:00
b3c2b05c5b Создание классов реализации хранения в базе данных 2023-03-10 19:48:46 +04:00
7aa92dbb74 Merge branch 'LabWork02_Base' into LabWork02_Hard 2023-03-10 19:39:05 +04:00
29a8bf30cc Merge branch 'LabWork01_Hard' into LabWork02_Hard 2023-03-10 19:38:46 +04:00
8507a11132 Исправления 2023-03-10 19:37:13 +04:00
716e94751c Merge branch 'LabWork02_Base' of http://student.git.athene.tech/Danila_Mochalov/PIbd-23_Mochalov_D.V._LawFirm into LabWork02_Base 2023-03-10 19:27:16 +04:00
b2c61a619a фикс удаления 2023-03-10 19:27:08 +04:00
862baf93b6 Сдана лаб 2 база 2023-03-10 19:25:23 +04:00
daf95e27b6 Вроде работает 2023-03-10 19:25:23 +04:00
75a544e690 Созданы реализации интерфейсов хранилищ 2023-03-10 19:25:23 +04:00
e390ece7b6 Создан синглтон класс 2023-03-10 19:25:23 +04:00
9c80b7fd37 Созданы модели 2023-03-10 19:25:22 +04:00
3b2493bbaf Merge branch 'LabWork01_Hard' of http://student.git.athene.tech/Danila_Mochalov/PIbd-23_Mochalov_D.V._LawFirm into LabWork01_Hard 2023-03-10 19:23:23 +04:00
b1dfb228b2 Сдана лаб 1 хард 2023-03-10 19:18:42 +04:00
cf13f3028e Доделал дату 2023-03-10 19:16:20 +04:00
5c57715fe3 Вроде готово. Надо исправить отображение даты открытия на форме FormShops 2023-03-10 19:16:20 +04:00
72b59a71eb Реализовано хранилище магазинов, класс магазина, изменен синглтон 2023-03-10 19:16:20 +04:00
14a2efbb78 Реализация логики магазина 2023-03-10 19:16:20 +04:00
8597edb910 Создание интерфейсов хранилища и логики магазина 2023-03-10 19:16:20 +04:00
d67f6123f2 Создание моделей магазина 2023-03-10 19:16:20 +04:00
49152e95c5 Исправления 2023-03-10 19:13:41 +04:00
bb74221578 Вот теперь точно все работает и все сделано (надеюсь) 2023-03-02 22:09:15 +04:00
0f604b38fe Исправил сохранение после продажи 2023-03-01 19:09:58 +04:00
6a68de1873 Вроде все работает, но было бы неплохо порефакторить 2023-03-01 19:04:30 +04:00
94dde9c5d9 Небольшой дебаг сохранения и пополнения магазина 2023-03-01 18:13:57 +04:00
f20984c4ba Изменена форма создания магазина с учетом вместимости 2023-02-27 10:31:58 +04:00
de6f3af8df Изменена логика пополнения магазина с учетом его максимальной вместимости 2023-02-27 10:19:40 +04:00
35ee01f552 Написана какая-то логика продажи в магазине 2023-02-27 09:49:29 +04:00
5b5b8cc6ac Фиксы 2023-02-27 08:49:14 +04:00
ccfe49dde9 фикс удаления 2023-02-26 23:22:27 +04:00
faef920c50 Начата файловая реализация магазина 2023-02-26 23:20:43 +04:00
0c47f0f7cd merge 2023-02-26 13:29:37 +04:00
0e351cdabe Базовая лаб3 вроде работает 2023-02-24 19:23:26 +04:00
ceec6e155c Создание миграции и БД 2023-02-24 18:38:05 +04:00
51d1b13efe Создание классов реализации хранения в базе данных 2023-02-24 17:55:19 +04:00
675b6546f4 Сдана лаб 1 хард 2023-02-13 10:08:11 +04:00
461ada29fb Merge branch 'LabWork01_Hard' of http://student.git.athene.tech/Danila_Mochalov/PIbd-23_Mochalov_D.V._LawFirm into LabWork01_Hard 2023-02-13 09:35:02 +04:00
b199a71b8a Доделал дату 2023-02-13 09:33:49 +04:00
a8b8f627b3 Вроде готово. Надо исправить отображение даты открытия на форме FormShops 2023-02-13 09:33:49 +04:00
39c6ef7591 Реализовано хранилище магазинов, класс магазина, изменен синглтон 2023-02-13 09:33:49 +04:00
390d10adb9 Реализация логики магазина 2023-02-13 09:33:49 +04:00
f773128233 Создание интерфейсов хранилища и логики магазина 2023-02-13 09:33:49 +04:00
53432af1bb Создание моделей магазина 2023-02-13 09:33:49 +04:00
0b14399022 Сдана лаб2 2023-02-13 09:31:49 +04:00
f4370b5d95 Сдана лаб 2 база 2023-02-13 09:29:17 +04:00
a342566d62 Вроде работает 2023-02-13 09:06:12 +04:00
8345b53f15 Созданы реализации интерфейсов хранилищ 2023-02-13 09:06:12 +04:00
2d57093fb6 Создан синглтон класс 2023-02-13 09:06:12 +04:00
9f25b5734c Созданы модели 2023-02-13 09:06:12 +04:00
62af0c7ec5 Исправлена логика изменения статуса заказа 2023-02-13 08:57:11 +04:00
ef3d3d4114 Доделал дату 2023-02-13 08:48:47 +04:00
66e77b2a1a Вроде готово. Надо исправить отображение даты открытия на форме FormShops 2023-02-13 00:19:42 +04:00
4fb74a26c1 Реализовано хранилище магазинов, класс магазина, изменен синглтон 2023-02-12 18:42:09 +04:00
f221cd82d0 Реализация логики магазина 2023-02-12 18:23:39 +04:00
5043230479 Создание интерфейсов хранилища и логики магазина 2023-02-12 16:37:12 +04:00
8ecffb665c Вроде работает 2023-02-11 17:41:53 +04:00
1e40bf95cb Созданы реализации интерфейсов хранилищ 2023-02-11 17:28:24 +04:00
2554343f45 Создан синглтон класс 2023-02-11 16:28:53 +04:00
b549271341 Созданы модели 2023-02-11 15:30:32 +04:00
d4154bcccc Убраны комментарии 2023-02-10 22:00:27 +04:00
a80b2b19fd Создание моделей магазина 2023-02-01 15:17:07 +04:00
a882155736 Сдана лаб1 2023-01-30 10:08:50 +04:00
828af603ab Создана главная форма. Исправлены ошибки 2023-01-30 09:20:55 +04:00
913ea75594 Создана форма создания заказа 2023-01-29 22:17:17 +04:00
884a41f3d2 Создана форма набора документов 2023-01-29 21:37:16 +04:00
fce52d33d0 Создана форма создания документа 2023-01-29 21:29:49 +04:00
22db07b650 Создана форма выбора бланков для документа 2023-01-29 19:57:04 +04:00
d525db81f1 Добавлена форма с набором бланков, изменен класс Program 2023-01-29 19:37:04 +04:00
72a7840dad Создана форма бланка 2023-01-29 19:12:12 +04:00
eabc9c7415 Созданы классы хранилищ 2023-01-29 17:08:07 +04:00
791ab703b2 Созданы классы-компоненты 2023-01-29 16:12:26 +04:00
1342035a29 Создана бизнес логика для сущностей 2023-01-28 23:22:06 +04:00
45beb79552 Созданы контракты хранилища 2023-01-28 20:32:04 +04:00
a19bf4142b Созданы контракты бизнес логики 2023-01-28 19:50:37 +04:00
b3d06a206a Создание View моделей 2023-01-28 19:35:03 +04:00
c5174ca09e Созданы Search модели, изменены модификаторы доступа классов BindingModels 2023-01-28 19:25:49 +04:00
73ab10abd1 Созданы Binding модели 2023-01-28 19:19:41 +04:00
a5e010ed3d Созданы интерфейсы - модели данных 2023-01-28 19:02:11 +04:00
115 changed files with 9036 additions and 183 deletions

1
.gitignore vendored
View File

@ -398,3 +398,4 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
/LawFirm/ImplementationExtensions

View File

@ -3,7 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32616.157
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirm", "LawFirm\LawFirm.csproj", "{9CAD54F8-62BE-4E4B-9F97-8B4DD21896B1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmView", "LawFirm\LawFirmView.csproj", "{9CAD54F8-62BE-4E4B-9F97-8B4DD21896B1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmDataModels", "LawFirmDataModels\LawFirmDataModels.csproj", "{E30F4943-0DB0-4715-881F-BC23EBAAF573}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmContracts", "LawFirmContracts\LawFirmContracts.csproj", "{0BFA7B8D-BA92-4DA4-9477-144606DFFF96}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{E75AF81D-A466-470A-A3F7-EC0E6F33C866}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmDatabaseImplement", "LawFirmDatabaseImplement\LawFirmDatabaseImplement.csproj", "{CB0444D3-5BDA-42DB-95F9-60191AE9073A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +27,30 @@ Global
{9CAD54F8-62BE-4E4B-9F97-8B4DD21896B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9CAD54F8-62BE-4E4B-9F97-8B4DD21896B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9CAD54F8-62BE-4E4B-9F97-8B4DD21896B1}.Release|Any CPU.Build.0 = Release|Any CPU
{E30F4943-0DB0-4715-881F-BC23EBAAF573}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E30F4943-0DB0-4715-881F-BC23EBAAF573}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E30F4943-0DB0-4715-881F-BC23EBAAF573}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E30F4943-0DB0-4715-881F-BC23EBAAF573}.Release|Any CPU.Build.0 = Release|Any CPU
{0BFA7B8D-BA92-4DA4-9477-144606DFFF96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0BFA7B8D-BA92-4DA4-9477-144606DFFF96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BFA7B8D-BA92-4DA4-9477-144606DFFF96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BFA7B8D-BA92-4DA4-9477-144606DFFF96}.Release|Any CPU.Build.0 = Release|Any CPU
{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}.Release|Any CPU.Build.0 = Release|Any CPU
{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.Build.0 = Release|Any CPU
{E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.Build.0 = Release|Any CPU
{CB0444D3-5BDA-42DB-95F9-60191AE9073A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB0444D3-5BDA-42DB-95F9-60191AE9073A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB0444D3-5BDA-42DB-95F9-60191AE9073A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB0444D3-5BDA-42DB-95F9-60191AE9073A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,39 +0,0 @@
namespace LawFirm
{
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
}
}

View File

@ -1,10 +0,0 @@
namespace LawFirm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -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
LawFirm/LawFirm/FormBlank.Designer.cs generated Normal file
View File

@ -0,0 +1,119 @@
namespace LawFirmView
{
partial class FormBlank
{
/// <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.labelBlankName = new System.Windows.Forms.Label();
this.labelPrice = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.textBoxCost = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelBlankName
//
this.labelBlankName.AutoSize = true;
this.labelBlankName.Location = new System.Drawing.Point(31, 19);
this.labelBlankName.Name = "labelBlankName";
this.labelBlankName.Size = new System.Drawing.Size(80, 20);
this.labelBlankName.TabIndex = 0;
this.labelBlankName.Text = "Название:";
//
// labelPrice
//
this.labelPrice.AutoSize = true;
this.labelPrice.Location = new System.Drawing.Point(31, 97);
this.labelPrice.Name = "labelPrice";
this.labelPrice.Size = new System.Drawing.Size(48, 20);
this.labelPrice.TabIndex = 1;
this.labelPrice.Text = "Цена:";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(145, 16);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(300, 27);
this.textBoxName.TabIndex = 2;
//
// textBoxCost
//
this.textBoxCost.Location = new System.Drawing.Point(145, 94);
this.textBoxCost.Name = "textBoxCost";
this.textBoxCost.Size = new System.Drawing.Size(146, 27);
this.textBoxCost.TabIndex = 3;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(145, 155);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.TabIndex = 4;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(290, 155);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormBlank
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(519, 207);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxCost);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelPrice);
this.Controls.Add(this.labelBlankName);
this.Name = "FormBlank";
this.Text = "Бланк";
this.Load += new System.EventHandler(this.FormBlank_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelBlankName;
private Label labelPrice;
private TextBox textBoxName;
private TextBox textBoxCost;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,98 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormBlank : Form
{
private readonly ILogger _logger;
private readonly IBlankLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormBlank(ILogger<FormBlank> logger, IBlankLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormBlank_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение бланка");
var view = _logic.ReadElement(new BlankSearchModel
{
Id =_id.Value
});
if (view != null)
{
textBoxName.Text = view.BlankName;
textBoxCost.Text = view.Cost.ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения бланка");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение бланка");
try
{
var model = new BlankBindingModel
{
Id = _id ?? 0,
BlankName = textBoxName.Text,
Cost = Convert.ToDouble(textBoxCost.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения бланка");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View 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>

115
LawFirm/LawFirm/FormBlanks.Designer.cs generated Normal file
View File

@ -0,0 +1,115 @@
namespace LawFirmView
{
partial class FormBlanks
{
/// <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.buttonEdit = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(507, 426);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(538, 12);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(152, 29);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// buttonEdit
//
this.buttonEdit.Location = new System.Drawing.Point(538, 47);
this.buttonEdit.Name = "buttonEdit";
this.buttonEdit.Size = new System.Drawing.Size(152, 29);
this.buttonEdit.TabIndex = 2;
this.buttonEdit.Text = "Изменить";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(538, 82);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(152, 29);
this.buttonDelete.TabIndex = 3;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(538, 409);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(152, 29);
this.buttonUpdate.TabIndex = 4;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// FormBlanks
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(702, 450);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonEdit);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormBlanks";
this.Text = "Бланки";
this.Load += new System.EventHandler(this.FormBlanks_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonEdit;
private Button buttonDelete;
private Button buttonUpdate;
}
}

View File

@ -0,0 +1,114 @@
using LawFirm;
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormBlanks : Form
{
private readonly ILogger _logger;
private readonly IBlankLogic _logic;
public FormBlanks(ILogger<FormBlanks> logger, IBlankLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormBlanks_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["BlankName"].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(FormBlank));
if (service is FormBlank form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonEdit_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBlank));
if (service is FormBlank form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
private void buttonDelete_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 BlankBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления бланка");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
}

View 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>

View File

@ -0,0 +1,144 @@
namespace LawFirmView
{
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.labelName = new System.Windows.Forms.Label();
this.labelCount = new System.Windows.Forms.Label();
this.labelSum = new System.Windows.Forms.Label();
this.comboBoxDocument = new System.Windows.Forms.ComboBox();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.textBoxSum = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(30, 20);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(79, 20);
this.labelName.TabIndex = 0;
this.labelName.Text = "Документ:";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(30, 70);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(93, 20);
this.labelCount.TabIndex = 1;
this.labelCount.Text = "Количество:";
//
// labelSum
//
this.labelSum.AutoSize = true;
this.labelSum.Location = new System.Drawing.Point(30, 119);
this.labelSum.Name = "labelSum";
this.labelSum.Size = new System.Drawing.Size(58, 20);
this.labelSum.TabIndex = 2;
this.labelSum.Text = "Сумма:";
//
// comboBoxDocument
//
this.comboBoxDocument.FormattingEnabled = true;
this.comboBoxDocument.Location = new System.Drawing.Point(171, 20);
this.comboBoxDocument.Name = "comboBoxDocument";
this.comboBoxDocument.Size = new System.Drawing.Size(262, 28);
this.comboBoxDocument.TabIndex = 3;
this.comboBoxDocument.SelectedIndexChanged += new System.EventHandler(this.comboBoxDocument_SelectedIndexChanged);
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(171, 67);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(262, 27);
this.textBoxCount.TabIndex = 4;
this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged);
//
// textBoxSum
//
this.textBoxSum.Location = new System.Drawing.Point(171, 112);
this.textBoxSum.Name = "textBoxSum";
this.textBoxSum.Size = new System.Drawing.Size(262, 27);
this.textBoxSum.TabIndex = 5;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(239, 164);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(339, 164);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormCreateOrder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(450, 212);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxSum);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.comboBoxDocument);
this.Controls.Add(this.labelSum);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelName);
this.Name = "FormCreateOrder";
this.Text = "Создание заказа";
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelName;
private Label labelCount;
private Label labelSum;
private ComboBox comboBoxDocument;
private TextBox textBoxCount;
private TextBox textBoxSum;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,130 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormCreateOrder : Form
{
private readonly ILogger _logger;
private readonly IDocumentLogic _logicD;
private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IDocumentLogic logicD, IOrderLogic logicO)
{
InitializeComponent();
_logger = logger;
_logicD = logicD;
_logicO = logicO;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка документов для заказа");
try
{
var list = _logicD.ReadList(null);
if (list != null)
{
comboBoxDocument.DisplayMember = "DocumentName";
comboBoxDocument.ValueMember = "Id";
comboBoxDocument.DataSource = list;
comboBoxDocument.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка документов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
{
if (comboBoxDocument.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxDocument.SelectedValue);
var product = _logicD.ReadElement(new DocumentSearchModel
{
Id = id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка расчета суммы заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void textBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void comboBoxDocument_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxDocument.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
DocumentId = Convert.ToInt32(comboBoxDocument.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();
}
}
}

View 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>

235
LawFirm/LawFirm/FormDocument.Designer.cs generated Normal file
View File

@ -0,0 +1,235 @@
namespace LawFirmView
{
partial class FormDocument
{
/// <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.textBoxName = new System.Windows.Forms.TextBox();
this.textBoxPrice = new System.Windows.Forms.TextBox();
this.groupBoxBlanks = new System.Windows.Forms.GroupBox();
this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonEdit = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnBlankName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxBlanks.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(12, 9);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(80, 20);
this.labelName.TabIndex = 0;
this.labelName.Text = "Название:";
//
// labelPrice
//
this.labelPrice.AutoSize = true;
this.labelPrice.Location = new System.Drawing.Point(12, 45);
this.labelPrice.Name = "labelPrice";
this.labelPrice.Size = new System.Drawing.Size(86, 20);
this.labelPrice.TabIndex = 1;
this.labelPrice.Text = "Стоимость:";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(98, 6);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(315, 27);
this.textBoxName.TabIndex = 2;
//
// textBoxPrice
//
this.textBoxPrice.Location = new System.Drawing.Point(98, 39);
this.textBoxPrice.Name = "textBoxPrice";
this.textBoxPrice.Size = new System.Drawing.Size(157, 27);
this.textBoxPrice.TabIndex = 3;
//
// groupBoxBlanks
//
this.groupBoxBlanks.Controls.Add(this.buttonUpdate);
this.groupBoxBlanks.Controls.Add(this.buttonDelete);
this.groupBoxBlanks.Controls.Add(this.buttonEdit);
this.groupBoxBlanks.Controls.Add(this.buttonAdd);
this.groupBoxBlanks.Controls.Add(this.dataGridView);
this.groupBoxBlanks.Location = new System.Drawing.Point(15, 83);
this.groupBoxBlanks.Name = "groupBoxBlanks";
this.groupBoxBlanks.Size = new System.Drawing.Size(699, 275);
this.groupBoxBlanks.TabIndex = 4;
this.groupBoxBlanks.TabStop = false;
this.groupBoxBlanks.Text = "Бланки";
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(521, 240);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(155, 29);
this.buttonUpdate.TabIndex = 4;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(521, 96);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(155, 29);
this.buttonDelete.TabIndex = 3;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonEdit
//
this.buttonEdit.Location = new System.Drawing.Point(521, 61);
this.buttonEdit.Name = "buttonEdit";
this.buttonEdit.Size = new System.Drawing.Size(155, 29);
this.buttonEdit.TabIndex = 2;
this.buttonEdit.Text = "Изменить";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(521, 26);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(155, 29);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.ColumnBlankName,
this.ColumnCount});
this.dataGridView.Location = new System.Drawing.Point(6, 26);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(490, 243);
this.dataGridView.TabIndex = 0;
this.dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellContentClick);
//
// ID
//
this.ID.HeaderText = "ID";
this.ID.MinimumWidth = 6;
this.ID.Name = "ID";
this.ID.Visible = false;
this.ID.Width = 125;
//
// ColumnBlankName
//
this.ColumnBlankName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
this.ColumnBlankName.HeaderText = "Бланк";
this.ColumnBlankName.MinimumWidth = 6;
this.ColumnBlankName.Name = "ColumnBlankName";
this.ColumnBlankName.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.ColumnBlankName.Width = 312;
//
// ColumnCount
//
this.ColumnCount.HeaderText = "Количество";
this.ColumnCount.MinimumWidth = 6;
this.ColumnCount.Name = "ColumnCount";
this.ColumnCount.Width = 125;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(356, 379);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(155, 29);
this.buttonSave.TabIndex = 5;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(536, 379);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(155, 29);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormDocument
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(726, 427);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.groupBoxBlanks);
this.Controls.Add(this.textBoxPrice);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelPrice);
this.Controls.Add(this.labelName);
this.Name = "FormDocument";
this.Text = "Документ";
this.Load += new System.EventHandler(this.FormDocument_Load);
this.groupBoxBlanks.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelName;
private Label labelPrice;
private TextBox textBoxName;
private TextBox textBoxPrice;
private GroupBox groupBoxBlanks;
private DataGridView dataGridView;
private Button buttonUpdate;
private Button buttonDelete;
private Button buttonEdit;
private Button buttonAdd;
private Button buttonSave;
private Button buttonCancel;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn ColumnBlankName;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -0,0 +1,229 @@
using LawFirm;
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using LawFirmDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormDocument : Form
{
private readonly ILogger _logger;
private readonly IDocumentLogic _logic;
private int? _id;
private Dictionary<int, (IBlankModel, int)> _documentBlanks;
public int Id { set { _id = value; } }
public FormDocument(ILogger<FormDocument> logger, IDocumentLogic logic)
{
InitializeComponent();
_logger= logger;
_logic= logic;
_documentBlanks = new Dictionary<int, (IBlankModel, int)>();
}
private void FormDocument_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка документа");
try
{
var view = _logic.ReadElement(new DocumentSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.DocumentName;
textBoxPrice.Text = view.Price.ToString();
_documentBlanks = view.DocumentBlanks ?? new Dictionary<int, (IBlankModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки документа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка бланков документа");
try
{
if (_documentBlanks != null)
{
dataGridView.Rows.Clear();
foreach (var pc in _documentBlanks)
{
dataGridView.Rows.Add(new object[]
{
pc.Key,
pc.Value.Item1.BlankName,
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 _documentBlanks)
{
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
}
return Math.Round(price * 1.1, 2);
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDocumentBlank));
if (service is FormDocumentBlank form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.BlankModel == null)
{
return;
}
_logger.LogInformation("Добавление нового бланка:{ BlankName}- { Count}", form.BlankModel.BlankName, form.Count);
if (_documentBlanks.ContainsKey(form.Id))
{
_documentBlanks[form.Id] = (form.BlankModel,form.Count);
}
else
{
_documentBlanks.Add(form.Id, (form.BlankModel,form.Count));
}
LoadData();
}
}
}
private void buttonEdit_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDocumentBlank));
if (service is FormDocumentBlank form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _documentBlanks[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.BlankModel == null)
{
return;
}
_logger.LogInformation("Изменение бланка:{ BlankName}- { Count}", form.BlankModel.BlankName, form.Count);
_documentBlanks[form.Id] = (form.BlankModel,form.Count);
LoadData();
}
}
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_logger.LogInformation("Удаление бланка:{ BlankName}- { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
_documentBlanks?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxPrice.Text))
{
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_documentBlanks == null || _documentBlanks.Count == 0)
{
MessageBox.Show("Заполните бланки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение документа");
try
{
var model = new DocumentBindingModel
{
Id = _id ?? 0,
DocumentName = textBoxName.Text,
Price = Convert.ToDouble(textBoxPrice.Text),
DocumentBlanks = _documentBlanks
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения документа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}

View 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="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnBlankName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -0,0 +1,119 @@
namespace LawFirmView
{
partial class FormDocumentBlank
{
/// <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.labelBlank = new System.Windows.Forms.Label();
this.labelCount = new System.Windows.Forms.Label();
this.comboBoxBlank = new System.Windows.Forms.ComboBox();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelBlank
//
this.labelBlank.AutoSize = true;
this.labelBlank.Location = new System.Drawing.Point(25, 26);
this.labelBlank.Name = "labelBlank";
this.labelBlank.Size = new System.Drawing.Size(53, 20);
this.labelBlank.TabIndex = 0;
this.labelBlank.Text = "Бланк:";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(25, 94);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(93, 20);
this.labelCount.TabIndex = 1;
this.labelCount.Text = "Количество:";
//
// comboBoxBlank
//
this.comboBoxBlank.FormattingEnabled = true;
this.comboBoxBlank.Location = new System.Drawing.Point(146, 26);
this.comboBoxBlank.Name = "comboBoxBlank";
this.comboBoxBlank.Size = new System.Drawing.Size(322, 28);
this.comboBoxBlank.TabIndex = 2;
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(146, 91);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(322, 27);
this.textBoxCount.TabIndex = 3;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(146, 148);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(143, 29);
this.buttonSave.TabIndex = 4;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(325, 148);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(143, 29);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormDocumentBlank
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(511, 189);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.comboBoxBlank);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelBlank);
this.Name = "FormDocumentBlank";
this.Text = "Бланк документа";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelBlank;
private Label labelCount;
private ComboBox comboBoxBlank;
private TextBox textBoxCount;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,89 @@
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormDocumentBlank : Form
{
private readonly List<BlankViewModel>? _list;
public int Id
{
get
{
return Convert.ToInt32(comboBoxBlank.SelectedValue);
}
set
{
comboBoxBlank.SelectedValue = value;
}
}
public IBlankModel? BlankModel
{
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 FormDocumentBlank(IBlankLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxBlank.DisplayMember = "BlankName";
comboBoxBlank.ValueMember = "Id";
comboBoxBlank.DataSource = _list;
comboBoxBlank.SelectedItem = null;
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxBlank.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();
}
}
}

View 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>

115
LawFirm/LawFirm/FormDocuments.Designer.cs generated Normal file
View File

@ -0,0 +1,115 @@
namespace LawFirmView
{
partial class FormDocuments
{
/// <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.buttonEdit = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(507, 426);
this.dataGridView.TabIndex = 1;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(533, 12);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(152, 29);
this.buttonAdd.TabIndex = 2;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// buttonEdit
//
this.buttonEdit.Location = new System.Drawing.Point(533, 47);
this.buttonEdit.Name = "buttonEdit";
this.buttonEdit.Size = new System.Drawing.Size(152, 29);
this.buttonEdit.TabIndex = 3;
this.buttonEdit.Text = "Изменить";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(533, 82);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(152, 29);
this.buttonDelete.TabIndex = 4;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(533, 409);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(152, 29);
this.buttonUpdate.TabIndex = 5;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// FormDocuments
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(697, 450);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonEdit);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormDocuments";
this.Text = "Документы";
this.Load += new System.EventHandler(this.FormDocuments_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonEdit;
private Button buttonDelete;
private Button buttonUpdate;
}
}

View File

@ -0,0 +1,114 @@
using LawFirm;
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormDocuments : Form
{
private readonly ILogger _logger;
private readonly IDocumentLogic _logic;
public FormDocuments(ILogger<FormDocuments> logger, IDocumentLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormDocuments_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["DocumentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["DocumentBlanks"].Visible = false;
}
_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(FormDocument));
if (service is FormDocument form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonEdit_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDocument));
if (service is FormDocument form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonDelete_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 DocumentBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления документа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View 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>

212
LawFirm/LawFirm/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,212 @@
namespace LawFirmView
{
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.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.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonSetToWork = new System.Windows.Forms.Button();
this.buttonSetToDone = new System.Windows.Forms.Button();
this.buttonSetToFinish = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonSupplyShop = new System.Windows.Forms.Button();
this.buttonSellDocuments = new System.Windows.Forms.Button();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// menuStrip
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
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(1139, 28);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "Справочники";
//
// справочникиToolStripMenuItem
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.бланкиToolStripMenuItem,
this.документыToolStripMenuItem,
this.магазиныToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
this.справочникиToolStripMenuItem.Text = "Справочники";
//
// бланкиToolStripMenuItem
//
this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem";
this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(170, 26);
this.бланкиToolStripMenuItem.Text = "Бланки";
this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.бланкиToolStripMenuItem_Click);
//
// документыToolStripMenuItem
//
this.документыToolStripMenuItem.Name = окументыToolStripMenuItem";
this.документыToolStripMenuItem.Size = new System.Drawing.Size(170, 26);
this.документыToolStripMenuItem.Text = "Документы";
this.документыToolStripMenuItem.Click += new System.EventHandler(this.документыToolStripMenuItem_Click);
//
// магазиныToolStripMenuItem
//
this.магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(170, 26);
this.магазиныToolStripMenuItem.Text = "Магазины";
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 31);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(915, 407);
this.dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(933, 45);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(194, 29);
this.buttonCreateOrder.TabIndex = 2;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.buttonCreateOrder_Click);
//
// buttonSetToWork
//
this.buttonSetToWork.Location = new System.Drawing.Point(933, 80);
this.buttonSetToWork.Name = "buttonSetToWork";
this.buttonSetToWork.Size = new System.Drawing.Size(194, 29);
this.buttonSetToWork.TabIndex = 3;
this.buttonSetToWork.Text = "Отдать на выполнение";
this.buttonSetToWork.UseVisualStyleBackColor = true;
this.buttonSetToWork.Click += new System.EventHandler(this.buttonSetToWork_Click);
//
// buttonSetToDone
//
this.buttonSetToDone.Location = new System.Drawing.Point(933, 115);
this.buttonSetToDone.Name = "buttonSetToDone";
this.buttonSetToDone.Size = new System.Drawing.Size(194, 29);
this.buttonSetToDone.TabIndex = 4;
this.buttonSetToDone.Text = "Заказ готов";
this.buttonSetToDone.UseVisualStyleBackColor = true;
this.buttonSetToDone.Click += new System.EventHandler(this.buttonSetToDone_Click);
//
// buttonSetToFinish
//
this.buttonSetToFinish.Location = new System.Drawing.Point(933, 150);
this.buttonSetToFinish.Name = "buttonSetToFinish";
this.buttonSetToFinish.Size = new System.Drawing.Size(194, 29);
this.buttonSetToFinish.TabIndex = 5;
this.buttonSetToFinish.Text = "Заказ выдан";
this.buttonSetToFinish.UseVisualStyleBackColor = true;
this.buttonSetToFinish.Click += new System.EventHandler(this.buttonSetToFinish_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(933, 410);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(194, 29);
this.buttonUpdate.TabIndex = 6;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// buttonSupplyShop
//
this.buttonSupplyShop.Location = new System.Drawing.Point(933, 185);
this.buttonSupplyShop.Name = "buttonSupplyShop";
this.buttonSupplyShop.Size = new System.Drawing.Size(194, 29);
this.buttonSupplyShop.TabIndex = 7;
this.buttonSupplyShop.Text = "Пополнение магазина";
this.buttonSupplyShop.UseVisualStyleBackColor = true;
this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click);
//
// buttonSellDocuments
//
this.buttonSellDocuments.Location = new System.Drawing.Point(933, 220);
this.buttonSellDocuments.Name = "buttonSellDocuments";
this.buttonSellDocuments.Size = new System.Drawing.Size(194, 29);
this.buttonSellDocuments.TabIndex = 8;
this.buttonSellDocuments.Text = "Продажа документов";
this.buttonSellDocuments.UseVisualStyleBackColor = true;
this.buttonSellDocuments.Click += new System.EventHandler(this.buttonSellDocuments_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1139, 450);
this.Controls.Add(this.buttonSellDocuments);
this.Controls.Add(this.buttonSupplyShop);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonSetToFinish);
this.Controls.Add(this.buttonSetToDone);
this.Controls.Add(this.buttonSetToWork);
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);
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private MenuStrip menuStrip;
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem бланкиToolStripMenuItem;
private ToolStripMenuItem документыToolStripMenuItem;
private DataGridView dataGridView;
private Button buttonCreateOrder;
private Button buttonSetToWork;
private Button buttonSetToDone;
private Button buttonSetToFinish;
private Button buttonUpdate;
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button buttonSupplyShop;
private Button buttonSellDocuments;
}
}

194
LawFirm/LawFirm/FormMain.cs Normal file
View File

@ -0,0 +1,194 @@
using LawFirm;
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
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["DocumentId"].Visible = false;
}
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки заказов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void бланкиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBlanks));
if (service is FormBlanks form)
{
form.ShowDialog();
}
}
private void документыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDocuments));
if (service is FormDocuments form)
{
form.ShowDialog();
}
}
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops 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 buttonSetToWork_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 buttonSetToDone_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("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonSetToFinish_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("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
private void buttonSupplyShop_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply));
if (service is FormShopSupply form)
{
form.ShowDialog();
}
}
private void buttonSellDocuments_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
if (service is FormShopSell form)
{
form.ShowDialog();
}
}
}
}

View 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>

210
LawFirm/LawFirm/FormShop.Designer.cs generated Normal file
View File

@ -0,0 +1,210 @@
namespace LawFirmView
{
partial class FormShop
{
/// <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.textBoxAddress = new System.Windows.Forms.TextBox();
this.textBoxName = new System.Windows.Forms.TextBox();
this.labelAddress = new System.Windows.Forms.Label();
this.labelName = new System.Windows.Forms.Label();
this.labelOpeningDate = new System.Windows.Forms.Label();
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnDocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.labelMaxCount = new System.Windows.Forms.Label();
this.textBoxMaxCountDocs = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// textBoxAddress
//
this.textBoxAddress.Location = new System.Drawing.Point(100, 45);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(315, 27);
this.textBoxAddress.TabIndex = 7;
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(100, 12);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(315, 27);
this.textBoxName.TabIndex = 6;
//
// labelAddress
//
this.labelAddress.AutoSize = true;
this.labelAddress.Location = new System.Drawing.Point(14, 51);
this.labelAddress.Name = "labelAddress";
this.labelAddress.Size = new System.Drawing.Size(54, 20);
this.labelAddress.TabIndex = 5;
this.labelAddress.Text = "Адрес:";
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(14, 15);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(80, 20);
this.labelName.TabIndex = 4;
this.labelName.Text = "Название:";
//
// labelOpeningDate
//
this.labelOpeningDate.AutoSize = true;
this.labelOpeningDate.Location = new System.Drawing.Point(14, 86);
this.labelOpeningDate.Name = "labelOpeningDate";
this.labelOpeningDate.Size = new System.Drawing.Size(126, 20);
this.labelOpeningDate.TabIndex = 8;
this.labelOpeningDate.Text = "Время открытия:";
//
// dateTimePicker
//
this.dateTimePicker.Location = new System.Drawing.Point(165, 81);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.Size = new System.Drawing.Size(250, 27);
this.dateTimePicker.TabIndex = 9;
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ColumnId,
this.ColumnDocumentName,
this.ColumnCount});
this.dataGridView.Location = new System.Drawing.Point(14, 173);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(401, 265);
this.dataGridView.TabIndex = 10;
//
// ColumnId
//
this.ColumnId.HeaderText = "ID";
this.ColumnId.MinimumWidth = 6;
this.ColumnId.Name = "ColumnId";
this.ColumnId.Visible = false;
this.ColumnId.Width = 125;
//
// ColumnDocumentName
//
this.ColumnDocumentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ColumnDocumentName.HeaderText = "Документ";
this.ColumnDocumentName.MinimumWidth = 6;
this.ColumnDocumentName.Name = "ColumnDocumentName";
//
// ColumnCount
//
this.ColumnCount.HeaderText = "Количество";
this.ColumnCount.MinimumWidth = 6;
this.ColumnCount.Name = "ColumnCount";
this.ColumnCount.Width = 125;
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(228, 448);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(155, 29);
this.buttonCancel.TabIndex = 12;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(48, 448);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(155, 29);
this.buttonSave.TabIndex = 11;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// labelMaxCount
//
this.labelMaxCount.AutoSize = true;
this.labelMaxCount.Location = new System.Drawing.Point(18, 128);
this.labelMaxCount.Name = "labelMaxCount";
this.labelMaxCount.Size = new System.Drawing.Size(216, 20);
this.labelMaxCount.TabIndex = 13;
this.labelMaxCount.Text = "Макс. количество документов";
//
// textBoxMaxCountDocs
//
this.textBoxMaxCountDocs.Location = new System.Drawing.Point(240, 128);
this.textBoxMaxCountDocs.Name = "textBoxMaxCountDocs";
this.textBoxMaxCountDocs.Size = new System.Drawing.Size(175, 27);
this.textBoxMaxCountDocs.TabIndex = 14;
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(445, 489);
this.Controls.Add(this.textBoxMaxCountDocs);
this.Controls.Add(this.labelMaxCount);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.dateTimePicker);
this.Controls.Add(this.labelOpeningDate);
this.Controls.Add(this.textBoxAddress);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelAddress);
this.Controls.Add(this.labelName);
this.Name = "FormShop";
this.Text = "Магазин";
this.Load += new System.EventHandler(this.FormShop_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox textBoxAddress;
private TextBox textBoxName;
private Label labelAddress;
private Label labelName;
private Label labelOpeningDate;
private DateTimePicker dateTimePicker;
private DataGridView dataGridView;
private Button buttonCancel;
private Button buttonSave;
private DataGridViewTextBoxColumn ColumnId;
private DataGridViewTextBoxColumn ColumnDocumentName;
private DataGridViewTextBoxColumn ColumnCount;
private Label labelMaxCount;
private TextBox textBoxMaxCountDocs;
}
}

144
LawFirm/LawFirm/FormShop.cs Normal file
View File

@ -0,0 +1,144 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormShop : Form
{
private readonly IShopLogic _logic;
private readonly ILogger _logger;
private Dictionary<int, (IDocumentModel, int)> _shopDocuments;
private int? _id;
public int Id { set { _id = value; } }
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_shopDocuments = new();
}
private void FormShop_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка магазина");
try
{
var view = _logic.ReadElement(new ShopSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.Name;
textBoxAddress.Text = view.Adress;
_shopDocuments = view.ShopDocuments ?? new Dictionary<int, (IDocumentModel, int)>();
textBoxMaxCountDocs.Text = view.MaxCountDocuments.ToString();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка документов магазина");
try
{
if (_shopDocuments != null)
{
dataGridView.Rows.Clear();
foreach (var pc in _shopDocuments)
{
dataGridView.Rows.Add(new object[]
{
pc.Key,
pc.Value.Item1.DocumentName,
pc.Value.Item2
}
);
}
}
}
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;
}
if (string.IsNullOrEmpty(textBoxAddress.Text))
{
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxMaxCountDocs.Text))
{
MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
Name = textBoxName.Text,
Adress = textBoxAddress.Text,
OpeningDate = dateTimePicker.Value.Date,
MaxCountDocuments = Convert.ToInt32(textBoxMaxCountDocs.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();
}
}
}

View 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="ColumnId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnDocumentName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

119
LawFirm/LawFirm/FormShopSell.Designer.cs generated Normal file
View File

@ -0,0 +1,119 @@
namespace LawFirmView
{
partial class FormShopSell
{
/// <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.labelCount = new System.Windows.Forms.Label();
this.labelDocument = new System.Windows.Forms.Label();
this.comboBoxDocument = new System.Windows.Forms.ComboBox();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.buttonSell = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(23, 76);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(93, 20);
this.labelCount.TabIndex = 1;
this.labelCount.Text = "Количество:";
//
// labelDocument
//
this.labelDocument.AutoSize = true;
this.labelDocument.Location = new System.Drawing.Point(23, 24);
this.labelDocument.Name = "labelDocument";
this.labelDocument.Size = new System.Drawing.Size(79, 20);
this.labelDocument.TabIndex = 2;
this.labelDocument.Text = "Документ:";
//
// comboBoxDocument
//
this.comboBoxDocument.FormattingEnabled = true;
this.comboBoxDocument.Location = new System.Drawing.Point(124, 24);
this.comboBoxDocument.Name = "comboBoxDocument";
this.comboBoxDocument.Size = new System.Drawing.Size(278, 28);
this.comboBoxDocument.TabIndex = 4;
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(124, 73);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(158, 27);
this.textBoxCount.TabIndex = 5;
//
// buttonSell
//
this.buttonSell.Location = new System.Drawing.Point(188, 142);
this.buttonSell.Name = "buttonSell";
this.buttonSell.Size = new System.Drawing.Size(94, 29);
this.buttonSell.TabIndex = 6;
this.buttonSell.Text = "Продажа";
this.buttonSell.UseVisualStyleBackColor = true;
this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(308, 142);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormShopSell
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(459, 198);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSell);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.comboBoxDocument);
this.Controls.Add(this.labelDocument);
this.Controls.Add(this.labelCount);
this.Name = "FormShopSell";
this.Text = "Продажа из магазина";
this.Load += new System.EventHandler(this.FormShopSell_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelCount;
private Label labelDocument;
private ComboBox comboBoxDocument;
private TextBox textBoxCount;
private Button buttonSell;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,96 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormShopSell : Form
{
private readonly ILogger _logger;
private readonly IDocumentLogic _logicD;
private readonly IShopLogic _logicS;
public FormShopSell(ILogger<FormShopSell> logger, IDocumentLogic logicD, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicD = logicD;
_logicS = logicS;
}
private void FormShopSell_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка документов для продажи");
try
{
var list = _logicD.ReadList(null);
if (list != null)
{
comboBoxDocument.DisplayMember = "DocumentName";
comboBoxDocument.ValueMember = "Id";
comboBoxDocument.DataSource = list;
comboBoxDocument.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка документов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonSell_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxDocument.SelectedValue == null)
{
MessageBox.Show("Выберите документ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание продажи");
try
{
var operationResult = _logicS.SellDocument(
new DocumentBindingModel
{
Id = Convert.ToInt32(comboBoxDocument.SelectedValue)
},
Convert.ToInt32(textBoxCount.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();
}
}
}

View 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>

144
LawFirm/LawFirm/FormShopSupply.Designer.cs generated Normal file
View File

@ -0,0 +1,144 @@
namespace LawFirmView
{
partial class FormShopSupply
{
/// <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.labelShop = new System.Windows.Forms.Label();
this.labelDocument = new System.Windows.Forms.Label();
this.labelDocumentCount = new System.Windows.Forms.Label();
this.comboBoxShop = new System.Windows.Forms.ComboBox();
this.comboBoxDocument = new System.Windows.Forms.ComboBox();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelShop
//
this.labelShop.AutoSize = true;
this.labelShop.Location = new System.Drawing.Point(26, 19);
this.labelShop.Name = "labelShop";
this.labelShop.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.labelShop.Size = new System.Drawing.Size(72, 20);
this.labelShop.TabIndex = 0;
this.labelShop.Text = "Магазин:";
//
// labelDocument
//
this.labelDocument.AutoSize = true;
this.labelDocument.Location = new System.Drawing.Point(26, 72);
this.labelDocument.Name = "labelDocument";
this.labelDocument.Size = new System.Drawing.Size(79, 20);
this.labelDocument.TabIndex = 1;
this.labelDocument.Text = "Документ:";
//
// labelDocumentCount
//
this.labelDocumentCount.AutoSize = true;
this.labelDocumentCount.Location = new System.Drawing.Point(26, 122);
this.labelDocumentCount.Name = "labelDocumentCount";
this.labelDocumentCount.Size = new System.Drawing.Size(93, 20);
this.labelDocumentCount.TabIndex = 2;
this.labelDocumentCount.Text = "Количество:";
//
// comboBoxShop
//
this.comboBoxShop.FormattingEnabled = true;
this.comboBoxShop.Location = new System.Drawing.Point(148, 19);
this.comboBoxShop.Name = "comboBoxShop";
this.comboBoxShop.Size = new System.Drawing.Size(251, 28);
this.comboBoxShop.TabIndex = 3;
//
// comboBoxDocument
//
this.comboBoxDocument.FormattingEnabled = true;
this.comboBoxDocument.Location = new System.Drawing.Point(148, 69);
this.comboBoxDocument.Name = "comboBoxDocument";
this.comboBoxDocument.Size = new System.Drawing.Size(251, 28);
this.comboBoxDocument.TabIndex = 4;
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(148, 122);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(125, 27);
this.textBoxCount.TabIndex = 5;
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(305, 183);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 9;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(205, 183);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.TabIndex = 8;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// FormShopSupply
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(436, 243);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.comboBoxDocument);
this.Controls.Add(this.comboBoxShop);
this.Controls.Add(this.labelDocumentCount);
this.Controls.Add(this.labelDocument);
this.Controls.Add(this.labelShop);
this.Name = "FormShopSupply";
this.Text = "Пополнение магазина";
this.Load += new System.EventHandler(this.FormShopSupply_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelShop;
private Label labelDocument;
private Label labelDocumentCount;
private ComboBox comboBoxShop;
private ComboBox comboBoxDocument;
private TextBox textBoxCount;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@ -0,0 +1,125 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormShopSupply : Form
{
private readonly ILogger _logger;
private readonly IDocumentLogic _logicD;
private readonly IShopLogic _logicS;
public FormShopSupply(ILogger<FormShopSupply> logger, IDocumentLogic logicD, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicD = logicD;
_logicS = logicS;
}
private void FormShopSupply_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка документов для пополнения");
try
{
var list = _logicD.ReadList(null);
if (list != null)
{
comboBoxDocument.DisplayMember = "DocumentName";
comboBoxDocument.ValueMember = "Id";
comboBoxDocument.DataSource = list;
comboBoxDocument.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка документов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Загрузка магазинов для пополнения");
try
{
var list = _logicS.ReadList(null);
if (list != null)
{
comboBoxShop.DisplayMember = "Name";
comboBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = list;
comboBoxShop.SelectedItem = null;
}
}
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(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxDocument.SelectedValue == null)
{
MessageBox.Show("Выберите документ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxShop.SelectedValue== null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание поставки");
try
{
var operationResult = _logicS.SupplyDocuments(
new ShopSearchModel
{
Id = Convert.ToInt32(comboBoxShop.SelectedValue),
Name = comboBoxShop.Text
},
new DocumentBindingModel
{
Id = Convert.ToInt32(comboBoxDocument.SelectedValue),
DocumentName = comboBoxDocument.Text
},
Convert.ToInt32(textBoxCount.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();
}
}
}

View 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>

115
LawFirm/LawFirm/FormShops.Designer.cs generated Normal file
View File

@ -0,0 +1,115 @@
namespace LawFirmView
{
partial class FormShops
{
/// <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.buttonUpdate = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonEdit = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(561, 426);
this.dataGridView.TabIndex = 0;
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(627, 409);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(152, 29);
this.buttonUpdate.TabIndex = 9;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(627, 82);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(152, 29);
this.buttonDelete.TabIndex = 8;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonEdit
//
this.buttonEdit.Location = new System.Drawing.Point(627, 47);
this.buttonEdit.Name = "buttonEdit";
this.buttonEdit.Size = new System.Drawing.Size(152, 29);
this.buttonEdit.TabIndex = 7;
this.buttonEdit.Text = "Изменить";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(627, 12);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(152, 29);
this.buttonAdd.TabIndex = 6;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// FormShops
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonEdit);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormShops";
this.Text = "Магазины";
this.Load += new System.EventHandler(this.FormShops_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonUpdate;
private Button buttonDelete;
private Button buttonEdit;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,124 @@
using LawFirm;
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LawFirmView
{
public partial class FormShops : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
public FormShops(ILogger<FormDocuments> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormShops_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ShopDocuments"].Visible = false;
}
_logger.LogInformation("Загрузка магазинов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonEdit_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonDelete_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 ShopBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
}

View 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>

View File

@ -1,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" 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="..\LawFirmBusinessLogic\LawFirmBusinessLogic.csproj" />
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
<ProjectReference Include="..\LawFirmDatabaseImplement\LawFirmDatabaseImplement.csproj" />
<ProjectReference Include="..\LawFirmFileImplement\LawFirmFileImplement.csproj" />
<ProjectReference Include="..\LawFirmListImplements\LawFirmListImplements.csproj" />
</ItemGroup>
</Project>

View File

@ -1,7 +1,19 @@
using LawFirmBusinessLogic.BusinessLogics;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.StorageContracts;
using LawFirmDatabaseImplement.Implements;
using LawFirmView;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System;
namespace LawFirm
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -11,7 +23,41 @@ namespace LawFirm
// 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<IBlankStorage, BlankStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IDocumentStorage, DocumentStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IBlankLogic, BlankLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IDocumentLogic, DocumentLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormBlank>();
services.AddTransient<FormBlanks>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormDocument>();
services.AddTransient<FormDocumentBlank>();
services.AddTransient<FormDocuments>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormShopSupply>();
services.AddTransient<FormShopSell>();
}
}
}
}

View File

@ -0,0 +1,122 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmBusinessLogic.BusinessLogics
{
public class BlankLogic : IBlankLogic
{
private readonly ILogger _logger;
private readonly IBlankStorage _blankStorage;
public BlankLogic (ILogger<BlankLogic> logger, IBlankStorage blankStorage)
{
_logger = logger;
_blankStorage = blankStorage;
}
public bool Create(BlankBindingModel model)
{
CheckModel(model);
if (_blankStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(BlankBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_blankStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public BlankViewModel? ReadElement(BlankSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. BlankName:{BlankName}.Id:{ Id}", model.BlankName, model.Id);
var element = _blankStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<BlankViewModel>? ReadList(BlankSearchModel? model)
{
_logger.LogInformation("ReadList. BlankName:{BlankName}.Id:{ Id}", model?.BlankName, model?.Id);
var list = model == null ? _blankStorage.GetFullList() : _blankStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(BlankBindingModel model)
{
CheckModel(model);
if (_blankStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(BlankBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.BlankName))
{
throw new ArgumentNullException("Нет названия бланка", nameof(model.BlankName));
}
if (model.Cost <= 0)
{
throw new ArgumentNullException("Цена бланка должна быть больше 0", nameof(model.Cost));
}
_logger.LogInformation("Blank. BlankName:{BlankName}.Cost:{ Cost}. Id: { Id}", model.BlankName, model.Cost, model.Id);
var element = _blankStorage.GetElement(new BlankSearchModel
{
BlankName = model.BlankName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Бланк с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,119 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmBusinessLogic.BusinessLogics
{
public class DocumentLogic : IDocumentLogic
{
private readonly ILogger _logger;
private readonly IDocumentStorage _documentStorage;
public DocumentLogic(ILogger<DocumentLogic> logger, IDocumentStorage documentStorage)
{
_logger = logger;
_documentStorage = documentStorage;
}
public bool Create(DocumentBindingModel model)
{
CheckModel(model);
if (_documentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(DocumentBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_documentStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public DocumentViewModel? ReadElement(DocumentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. DocumentName:{DocumentName}.Id:{ Id}", model.DocumentName, model.Id);
var element = _documentStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<DocumentViewModel>? ReadList(DocumentSearchModel? model)
{
_logger.LogInformation("ReadList. DocumentName:{DocumentName}.Id:{ Id}", model?.DocumentName, model?.Id);
var list = model == null ? _documentStorage.GetFullList() : _documentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(DocumentBindingModel model)
{
CheckModel(model);
if (_documentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(DocumentBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.DocumentName))
{
throw new ArgumentNullException("Нет названия документа", nameof(model.DocumentName));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Стоимость документа должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Document. DocumentName:{DocumentName}.Price:{ Price}. Id: { Id}", model.DocumentName, model.Price, model.Id);
var element = _documentStorage.GetElement(new DocumentSearchModel
{
DocumentName = model.DocumentName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Документ с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,224 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Enums;
using LawFirmDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly IShopLogic _shopLogic;
private readonly IDocumentStorage _documentStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IDocumentStorage documentStorage, IShopStorage shopStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopLogic = shopLogic;
_documentStorage = documentStorage;
_shopStorage = shopStorage;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен)
{
_logger.LogWarning("Insert operation failed. Order status incorrect.");
return false;
}
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
model.Status = OrderStatus.Неизвестен;
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool StatusUpdate(OrderBindingModel rawModel, OrderStatus newStatus)
{
var viewModel = _orderStorage.GetElement(new OrderSearchModel
{
Id = rawModel.Id
});
if (viewModel == null)
{
_logger.LogWarning("Order model not found");
return false;
}
OrderBindingModel model = new OrderBindingModel
{
Id = viewModel.Id,
DocumentId = viewModel.DocumentId,
Status = viewModel.Status,
DateCreate = viewModel.DateCreate,
DateImplement = viewModel.DateImplement,
Count = viewModel.Count,
Sum = viewModel.Sum
};
CheckModel(model, false);
if (model.Status + 1 != newStatus)
{
_logger.LogWarning("Status update to " + newStatus.ToString() +" operation failed. Order status incorrect.");
return false;
}
if (newStatus == OrderStatus.Готов)
{
var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId});
if (document == null)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Document not found.");
return false;
}
if (CheckThenSupplyMany(document, model.Count) == false)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error.");
return false;
}
}
model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool CheckThenSupplyMany(IDocumentModel document, int count)
{
if (count <= 0)
{
_logger.LogWarning("Check then supply operation error. Document count < 0.");
return false;
}
int freeSpace = 0;
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace += shop.MaxCountDocuments;
foreach (var doc in shop.ShopDocuments)
{
freeSpace -= doc.Value.Item2;
}
}
if (freeSpace - count < 0)
{
_logger.LogWarning("Check then supply operation error. There's no place for new docs in shops.");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace = shop.MaxCountDocuments;
foreach (var doc in shop.ShopDocuments)
{
freeSpace -= doc.Value.Item2;
}
if (freeSpace == 0)
{
continue;
}
if (freeSpace - count >= 0)
{
if (_shopLogic.SupplyDocuments(new() { Id = shop.Id }, document, count)) count = 0;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (freeSpace - count < 0)
{
if (_shopLogic.SupplyDocuments(new() { Id = shop.Id }, document, freeSpace)) count -= freeSpace;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (count <= 0)
{
return true;
}
}
return false;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
public bool DeliveryOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Готов);
}
public bool FinishOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выдан);
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("Order. OrderID:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.DocumentId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.DocumentId));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество документов в заказе должно быть больше 0", nameof(model.Count));
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
}
_logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.DocumentId);
}
}
}

View File

@ -0,0 +1,189 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.BusinessLogicContracts;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace LawFirmBusinessLogic.BusinessLogics
{
public class ShopLogic : IShopLogic
{
private readonly ILogger _logger;
private readonly IShopStorage _shopStorage;
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
{
_logger = logger;
_shopStorage = shopStorage;
}
public ShopViewModel? ReadElement(ShopSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Shop Name:{0}.ID:{1}", model.Name, model.Id);
var element = _shopStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
{
_logger.LogInformation("ReadList. Shop Name:{0}.ID:{1} ", model?.Name, model?.Id);
var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}
if (count <= 0)
{
throw new ArgumentNullException("Count of documents in supply myst be more than 0", nameof(count));
}
var shopElement = _shopStorage.GetElement(model);
if (shopElement == null)
{
_logger.LogWarning("Required shop element not found in storage");
return false;
}
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
var countDocs = 0;
foreach (var doc in shopElement.ShopDocuments)
{
countDocs += doc.Value.Item2;
}
if (shopElement.MaxCountDocuments - countDocs >= count)
{
if (shopElement.ShopDocuments.TryGetValue(document.Id, out var sameDocument))
{
shopElement.ShopDocuments[document.Id] = (document, sameDocument.Item2 + count);
_logger.LogInformation("Same document found by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name);
}
else
{
shopElement.ShopDocuments[document.Id] = (document, count);
_logger.LogInformation("New document added by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name);
}
_shopStorage.Update(new()
{
Id = shopElement.Id,
Name = shopElement.Name,
Adress = shopElement.Adress,
OpeningDate = shopElement.OpeningDate,
ShopDocuments = shopElement.ShopDocuments,
MaxCountDocuments = shopElement.MaxCountDocuments
});
}
else
{
_logger.LogWarning("Required shop is overflowed");
return false;
}
return true;
}
public bool SellDocument(IDocumentModel document, int count)
{;
return _shopStorage.SellDocument(document, count);
}
public bool Create(ShopBindingModel model)
{
CheckModel(model);
if (_shopStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ShopBindingModel model)
{
CheckModel(model);
if (_shopStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ShopBindingModel model)
{
CheckModel(model, false);
if (_shopStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name));
}
if (model.MaxCountDocuments < 0)
{
throw new InvalidOperationException("Магазин с отрицательным количеством максимального количества документов!");
}
_logger.LogInformation("Shop. Name: {0}, Adress: {1}, ID: {2}", model.Name, model.Adress, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
{
Name = model.Name
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,18 @@
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BindingModels
{
public class BlankBindingModel : IBlankModel
{
public string BlankName { get; set; } = string.Empty;
public double Cost { get; set; }
public int Id {get; set;}
}
}

View File

@ -0,0 +1,20 @@
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BindingModels
{
public class DocumentBindingModel : IDocumentModel
{
public string DocumentName {get; set;} = string.Empty;
public double Price { get; set; }
public Dictionary<int, (IBlankModel, int)> DocumentBlanks { get; set; } = new();
public int Id { get; set; }
}
}

View File

@ -0,0 +1,27 @@
using LawFirmDataModels.Enums;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public int DocumentId { 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; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,24 @@
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BindingModels
{
public class ShopBindingModel : IShopModel
{
public string Name { get; set; } = string.Empty;
public string Adress { get; set; } = string.Empty;
public DateTime OpeningDate { get; set; }
public Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; set; } = new();
public int Id { get; set; }
public int MaxCountDocuments { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BusinessLogicContracts
{
public interface IBlankLogic
{
List<BlankViewModel>? ReadList(BlankSearchModel? model);
BlankViewModel? ReadElement(BlankSearchModel model);
bool Create(BlankBindingModel model);
bool Update(BlankBindingModel model);
bool Delete(BlankBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BusinessLogicContracts
{
public interface IDocumentLogic
{
List<DocumentViewModel>? ReadList(DocumentSearchModel? model);
DocumentViewModel? ReadElement(DocumentSearchModel model);
bool Create(DocumentBindingModel model);
bool Update(DocumentBindingModel model);
bool Delete(DocumentBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BusinessLogicContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
}
}

View File

@ -0,0 +1,23 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.BusinessLogicContracts
{
public interface IShopLogic
{
ShopViewModel? ReadElement(ShopSearchModel model);
List<ShopViewModel>? ReadList(ShopSearchModel? model);
bool Create(ShopBindingModel model);
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count);
bool SellDocument(IDocumentModel document, int count);
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LawFirmDataModels\LawFirmDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.SearchModels
{
public class BlankSearchModel
{
public int? Id { get; set; }
public string? BlankName { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.SearchModels
{
public class DocumentSearchModel
{
public int? Id { get; set; }
public string? DocumentName { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.SearchModels
{
public class ShopSearchModel
{
public int? Id { get; set; }
public string? Name { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.StorageContracts
{
public interface IBlankStorage
{
List<BlankViewModel> GetFullList();
List<BlankViewModel> GetFilteredList(BlankSearchModel model);
BlankViewModel? GetElement(BlankSearchModel model);
BlankViewModel? Insert(BlankBindingModel model);
BlankViewModel? Update(BlankBindingModel model);
BlankViewModel? Delete(BlankBindingModel model);
}
}

View File

@ -0,0 +1,22 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.StorageContracts
{
public interface IDocumentStorage
{
List<DocumentViewModel> GetFullList();
List<DocumentViewModel> GetFilteredList(DocumentSearchModel model);
DocumentViewModel? GetElement(DocumentSearchModel model);
DocumentViewModel? Insert(DocumentBindingModel model);
DocumentViewModel? Update(DocumentBindingModel model);
DocumentViewModel? Delete(DocumentBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.StorageContracts
{
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);
}
}

View File

@ -0,0 +1,23 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.StorageContracts
{
public interface IShopStorage
{
ShopViewModel? GetElement(ShopSearchModel model);
List<ShopViewModel> GetFullList();
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool SellDocument(IDocumentModel model, int count);
}
}

View File

@ -0,0 +1,21 @@
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.ViewModels
{
public class BlankViewModel : IBlankModel
{
[DisplayName("Название бланка")]
public string BlankName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Cost { get; set; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.ViewModels
{
public class DocumentViewModel : IDocumentModel
{
[DisplayName("Название документа")]
public string DocumentName {get; set;} = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
public Dictionary<int, (IBlankModel, int)> DocumentBlanks { get; set; } = new();
public int Id { get; set; }
}
}

View File

@ -0,0 +1,39 @@
using LawFirmDataModels.Enums;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
public int DocumentId { get; set; }
[DisplayName("Номер")]
public int Id { get; set; }
[DisplayName("Документ")]
public string DocumentName { 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; }
}
}

View File

@ -0,0 +1,27 @@
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmContracts.ViewModels
{
public class ShopViewModel : IShopModel
{
[DisplayName("Название магазина")]
public string Name { get; set; } = string.Empty;
[DisplayName("Адрес")]
public string Adress { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
public DateTime OpeningDate { get; set; }
public Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; set; } = new();
public int Id { get; set; }
[DisplayName("Макс. документов в магазине")]
public int MaxCountDocuments { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDataModels.Enums
{
public enum OrderStatus
{
Неизвестен = -1,
Принят = 0,
Выполняется = 1,
Готов = 2,
Выдан = 3,
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDataModels
{
public interface IId
{
int Id { get; }
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDataModels.Models
{
public interface IBlankModel : IId
{
string BlankName { get; }
double Cost { get; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDataModels.Models
{
public interface IDocumentModel : IId
{
string DocumentName { get; }
double Price { get; }
Dictionary<int, (IBlankModel, int)> DocumentBlanks { get; }
}
}

View File

@ -0,0 +1,20 @@
using LawFirmDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDataModels.Models
{
public interface IOrderModel : IId
{
int DocumentId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDataModels.Models
{
public interface IShopModel : IId
{
String Name { get; }
String Adress { get; }
DateTime OpeningDate { get; }
Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; }
int MaxCountDocuments { get; }
}
}

View File

@ -0,0 +1,91 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Implements
{
public class BlankStorage : IBlankStorage
{
public BlankViewModel? GetElement(BlankSearchModel model)
{
if (string.IsNullOrEmpty(model.BlankName) && !model.Id.HasValue)
{
return null;
}
using var context = new LawFirmDatabase();
return context.Blanks.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.BlankName) && x.BlankName == model.BlankName)
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<BlankViewModel> GetFilteredList(BlankSearchModel model)
{
if (string.IsNullOrEmpty(model.BlankName))
{
return new();
}
using var context = new LawFirmDatabase();
return context.Blanks
.Where(x => x.BlankName.Contains(model.BlankName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<BlankViewModel> GetFullList()
{
using var context = new LawFirmDatabase();
return context.Blanks.Select(x => x.GetViewModel).ToList();
}
public BlankViewModel? Insert(BlankBindingModel model)
{
var newBlank = Blank.Create(model);
if (newBlank == null)
{
return null;
}
using var context = new LawFirmDatabase();
context.Blanks.Add(newBlank);
context.SaveChanges();
return newBlank.GetViewModel;
}
public BlankViewModel? Update(BlankBindingModel model)
{
using var context = new LawFirmDatabase();
var blank = context.Blanks.FirstOrDefault(x => x.Id == model.Id);
if (blank == null)
{
return null;
}
blank.Update(model);
context.SaveChanges();
return blank.GetViewModel;
}
public BlankViewModel? Delete(BlankBindingModel model)
{
using var context = new LawFirmDatabase();
var element = context.Blanks.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Blanks.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,131 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Implements
{
public class DocumentStorage : IDocumentStorage
{
public DocumentViewModel? GetElement(DocumentSearchModel model)
{
if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue)
{
return null;
}
using var context = new LawFirmDatabase();
return context.Documents.Include(x => x.Blanks)
.ThenInclude(x => x.Blank)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) &&
x.DocumentName == model.DocumentName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<DocumentViewModel> GetFilteredList(DocumentSearchModel model)
{
if (string.IsNullOrEmpty(model.DocumentName))
{
return new();
}
using var context = new LawFirmDatabase();
return context.Documents
.Include(x => x.Blanks)
.ThenInclude(x => x.Blank)
.Where(x => x.DocumentName.Contains(model.DocumentName))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<DocumentViewModel> GetFullList()
{
using var context = new LawFirmDatabase();
return context.Documents
.Include(x => x.Blanks)
.ThenInclude(x => x.Blank)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public DocumentViewModel? Insert(DocumentBindingModel model)
{
using var context = new LawFirmDatabase();
using var transaction = context.Database.BeginTransaction();
{
try
{
var newDoc = Document.Create(context, model);
if (newDoc == null)
{
transaction.Rollback();
return null;
}
context.Documents.Add(newDoc);
context.SaveChanges();
context.Database.CommitTransaction();
return newDoc.GetViewModel;
}
catch (Exception)
{
transaction.Rollback();
return null;
}
}
}
public DocumentViewModel? Update(DocumentBindingModel model)
{
using var context = new LawFirmDatabase();
using var transaction = context.Database.BeginTransaction();
{
try
{
var document = context.Documents.FirstOrDefault(x => x.Id == model.Id);
if (document == null)
{
transaction.Rollback();
return null;
}
document.Update(model);
document.UpdateComponents(context, model);
context.SaveChanges();
context.Database.CommitTransaction();
return document.GetViewModel;
}
catch (Exception)
{
transaction.Rollback();
return null;
}
}
}
public DocumentViewModel? Delete(DocumentBindingModel model)
{
using var context = new LawFirmDatabase();
var element = context.Documents.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Documents.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,85 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new LawFirmDatabase();
return context.Orders.Include(x => x.Document).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
using var context = new LawFirmDatabase();
return context.Orders
.Where(x => x.Id == model.Id)
.Include(x => x.Document)
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFullList()
{
using var context = new LawFirmDatabase();
return context.Orders.Include(x => x.Document).Select(x => x.GetViewModel).ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
{
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
using var context = new LawFirmDatabase();
context.Orders.Add(newOrder);
context.SaveChanges();
return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new LawFirmDatabase();
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
return context.Orders.Include(x => x.Document).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new LawFirmDatabase();
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,146 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmDatabaseImplement.Models;
using LawFirmDataModels.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Implements
{
public class ShopStorage : IShopStorage
{
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return new();
}
using var context = new LawFirmDatabase();
return context.Shops.Include(x => x.Documents).ThenInclude(x => x.Document).FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new LawFirmDatabase();
return context.Shops.Include(x => x.Documents).ThenInclude(x => x.Document).Where(x => x.Name.Contains(model.Name)).ToList().Select(x => x.GetViewModel).ToList();
}
public List<ShopViewModel> GetFullList()
{
using var context = new LawFirmDatabase();
return context.Shops.Include(x => x.Documents).ThenInclude(x => x.Document).ToList().Select(x => x.GetViewModel).ToList();
}
public ShopViewModel? Insert(ShopBindingModel model)
{
using var context = new LawFirmDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var newShop = Shop.Create(context, model);
if (newShop == null)
{
return null;
}
if (context.Shops.Any(x => x.Name == newShop.Name))
{
throw new Exception("Название магазина уже занято");
}
context.Shops.Add(newShop);
context.SaveChanges();
transaction.Commit();
return newShop.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public ShopViewModel? Update(ShopBindingModel model)
{
using var context = new LawFirmDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var shop = context.Shops.Include(x => x.Documents).FirstOrDefault(x => x.Id == model.Id);
if (shop == null)
{
return null;
}
shop.Update(model);
context.SaveChanges();
if (model.ShopDocuments.Count > 0)
{
shop.UpdateDocuments(context, model);
}
transaction.Commit();
return shop.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public ShopViewModel? Delete(ShopBindingModel model)
{
using var context = new LawFirmDatabase();
var shop = context.Shops.Include(x => x.Documents).FirstOrDefault(x => x.Id == model.Id);
if (shop != null)
{
context.Shops.Remove(shop);
context.SaveChanges();
return shop.GetViewModel;
}
return null;
}
public bool SellDocument(IDocumentModel model, int count)
{
using var context = new LawFirmDatabase();
using var transaction = context.Database.BeginTransaction();
foreach (var shopDocs in context.ShopDocuments.Where(x => x.DocumentId == model.Id))
{
var min = Math.Min(count, shopDocs.Count);
shopDocs.Count -= min;
count -= min;
if (count <= 0)
{
break;
}
}
if (count == 0)
{
context.SaveChanges();
transaction.Commit();
}
else
{
transaction.Rollback();
}
if (count > 0)
{
return false;
}
return true;
}
}
}

View File

@ -0,0 +1,30 @@
using LawFirmDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement
{
public class LawFirmDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DANYAXREN\SQLEXPRESS;Initial Catalog=LawFirmDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Blank> Blanks { set; get; }
public virtual DbSet<Document> Documents { set; get; }
public virtual DbSet<DocumentBlank> DocumentBlanks { set; get; }
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Shop> Shops { set; get; }
public virtual DbSet<ShopDocument> ShopDocuments { set; get; }
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
<ProjectReference Include="..\LawFirmDataModels\LawFirmDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,173 @@
// <auto-generated />
using System;
using LawFirmDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
[DbContext(typeof(LawFirmDatabase))]
[Migration("20230224135956_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("BlankName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Blanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DocumentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Documents");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BlankId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BlankId");
b.HasIndex("DocumentId");
b.ToTable("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.Property<string>("DocumentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DocumentId");
b.ToTable("Orders");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Blank", "Blank")
.WithMany("DocumentBlanks")
.HasForeignKey("BlankId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Blanks")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Blank");
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Document", null)
.WithMany("Orders")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Navigation("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Navigation("Blanks");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,126 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Blanks",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
BlankName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Blanks", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Documents",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DocumentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Documents", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DocumentBlanks",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DocumentId = table.Column<int>(type: "int", nullable: false),
BlankId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DocumentBlanks", x => x.Id);
table.ForeignKey(
name: "FK_DocumentBlanks_Blanks_BlankId",
column: x => x.BlankId,
principalTable: "Blanks",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DocumentBlanks_Documents_DocumentId",
column: x => x.DocumentId,
principalTable: "Documents",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DocumentId = table.Column<int>(type: "int", nullable: false),
DocumentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Documents_DocumentId",
column: x => x.DocumentId,
principalTable: "Documents",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_DocumentBlanks_BlankId",
table: "DocumentBlanks",
column: "BlankId");
migrationBuilder.CreateIndex(
name: "IX_DocumentBlanks_DocumentId",
table: "DocumentBlanks",
column: "DocumentId");
migrationBuilder.CreateIndex(
name: "IX_Orders_DocumentId",
table: "Orders",
column: "DocumentId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DocumentBlanks");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "Blanks");
migrationBuilder.DropTable(
name: "Documents");
}
}
}

View File

@ -0,0 +1,171 @@
// <auto-generated />
using System;
using LawFirmDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
[DbContext(typeof(LawFirmDatabase))]
[Migration("20230310164628_OrderFix")]
partial class OrderFix
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("BlankName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Blanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DocumentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Documents");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BlankId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BlankId");
b.HasIndex("DocumentId");
b.ToTable("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DocumentId");
b.ToTable("Orders");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Blank", "Blank")
.WithMany("DocumentBlanks")
.HasForeignKey("BlankId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Blanks")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Blank");
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Orders")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Navigation("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Navigation("Blanks");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class OrderFix : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "DocumentName",
table: "Orders");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "DocumentName",
table: "Orders",
type: "nvarchar(max)",
nullable: false,
defaultValue: "");
}
}
}

View File

@ -0,0 +1,248 @@
// <auto-generated />
using System;
using LawFirmDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
[DbContext(typeof(LawFirmDatabase))]
[Migration("20230312152057_ShopsAdded")]
partial class ShopsAdded
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("BlankName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Blanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DocumentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Documents");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BlankId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BlankId");
b.HasIndex("DocumentId");
b.ToTable("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DocumentId");
b.ToTable("Orders");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Adress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("MaxCountDocuments")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OpeningDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.ShopDocument", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DocumentId");
b.HasIndex("ShopId");
b.ToTable("ShopDocuments");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Blank", "Blank")
.WithMany("DocumentBlanks")
.HasForeignKey("BlankId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Blanks")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Blank");
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Orders")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.ShopDocument", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany()
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Shop", "Shop")
.WithMany("Documents")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Document");
b.Navigation("Shop");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Navigation("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Navigation("Blanks");
b.Navigation("Orders");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Documents");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,78 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class ShopsAdded : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Shops",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Adress = table.Column<string>(type: "nvarchar(max)", nullable: false),
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
MaxCountDocuments = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Shops", x => x.Id);
});
migrationBuilder.CreateTable(
name: "ShopDocuments",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DocumentId = table.Column<int>(type: "int", nullable: false),
ShopId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ShopDocuments", x => x.Id);
table.ForeignKey(
name: "FK_ShopDocuments_Documents_DocumentId",
column: x => x.DocumentId,
principalTable: "Documents",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ShopDocuments_Shops_ShopId",
column: x => x.ShopId,
principalTable: "Shops",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ShopDocuments_DocumentId",
table: "ShopDocuments",
column: "DocumentId");
migrationBuilder.CreateIndex(
name: "IX_ShopDocuments_ShopId",
table: "ShopDocuments",
column: "ShopId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ShopDocuments");
migrationBuilder.DropTable(
name: "Shops");
}
}
}

View File

@ -0,0 +1,250 @@
// <auto-generated />
using System;
using LawFirmDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
[DbContext(typeof(LawFirmDatabase))]
[Migration("20230424062106_ShopDocumentBindFix")]
partial class ShopDocumentBindFix
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("BlankName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Blanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DocumentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Documents");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BlankId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BlankId");
b.HasIndex("DocumentId");
b.ToTable("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DocumentId");
b.ToTable("Orders");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Adress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("MaxCountDocuments")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OpeningDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.ShopDocument", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DocumentId");
b.HasIndex("ShopId");
b.ToTable("ShopDocuments");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Blank", "Blank")
.WithMany("DocumentBlanks")
.HasForeignKey("BlankId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Blanks")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Blank");
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Orders")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.ShopDocument", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Shops")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Shop", "Shop")
.WithMany("Documents")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Document");
b.Navigation("Shop");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Navigation("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Navigation("Blanks");
b.Navigation("Orders");
b.Navigation("Shops");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Documents");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class ShopDocumentBindFix : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -0,0 +1,247 @@
// <auto-generated />
using System;
using LawFirmDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace LawFirmDatabaseImplement.Migrations
{
[DbContext(typeof(LawFirmDatabase))]
partial class LawFirmDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("BlankName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Blanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DocumentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Documents");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BlankId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BlankId");
b.HasIndex("DocumentId");
b.ToTable("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DocumentId");
b.ToTable("Orders");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Adress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("MaxCountDocuments")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OpeningDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.ShopDocument", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DocumentId")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DocumentId");
b.HasIndex("ShopId");
b.ToTable("ShopDocuments");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.DocumentBlank", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Blank", "Blank")
.WithMany("DocumentBlanks")
.HasForeignKey("BlankId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Blanks")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Blank");
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Orders")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Document");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.ShopDocument", b =>
{
b.HasOne("LawFirmDatabaseImplement.Models.Document", "Document")
.WithMany("Shops")
.HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LawFirmDatabaseImplement.Models.Shop", "Shop")
.WithMany("Documents")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Document");
b.Navigation("Shop");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
{
b.Navigation("DocumentBlanks");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Document", b =>
{
b.Navigation("Blanks");
b.Navigation("Orders");
b.Navigation("Shops");
});
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Documents");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,56 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Models
{
public class Blank : IBlankModel
{
public int Id { get; private set; }
[Required]
public string BlankName { get; private set; } = String.Empty;
[Required]
public double Cost { get; set; }
[ForeignKey("BlankId")]
public virtual List<DocumentBlank> DocumentBlanks { get; set; } = new();
public static Blank? Create(BlankBindingModel? model)
{
if (model == null)
{
return null;
}
return new Blank()
{
Id = model.Id,
BlankName = model.BlankName,
Cost = model.Cost
};
}
public void Update(BlankBindingModel? model)
{
if (model == null)
{
return;
}
BlankName = model.BlankName;
Cost = model.Cost;
}
public BlankViewModel GetViewModel => new()
{
Id = Id,
BlankName = BlankName,
Cost = Cost
};
}
}

View File

@ -0,0 +1,104 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Models
{
public class Document : IDocumentModel
{
public int Id { get; private set; }
[Required]
public string DocumentName { get; private set; } = string.Empty;
[Required]
public double Price { get; private set; }
private Dictionary<int, (IBlankModel, int)>? _documentBlanks = null;
[NotMapped]
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
{
get
{
if (_documentBlanks == null)
{
_documentBlanks = Blanks.ToDictionary(recPC => recPC.BlankId, recPC => (recPC.Blank as IBlankModel, recPC.Count));
}
return _documentBlanks;
}
}
[ForeignKey("DocumentId")]
public virtual List<DocumentBlank> Blanks { get; set; } = new();
[ForeignKey("DocumentId")]
public virtual List<Order> Orders { get; set; } = new();
[ForeignKey("DocumentId")]
public virtual List<ShopDocument> Shops { get; set; } = new();
public static Document? Create(LawFirmDatabase context, DocumentBindingModel model)
{
var blanks = context.Blanks;
return new Document()
{
Id = model.Id,
DocumentName = model.DocumentName,
Price = model.Price,
Blanks = model.DocumentBlanks.Select(x => new DocumentBlank
{
Blank = context.Blanks.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
public void Update(DocumentBindingModel model)
{
DocumentName = model.DocumentName;
Price = model.Price;
}
public DocumentViewModel GetViewModel => new()
{
Id = Id,
DocumentName = DocumentName,
Price = Price,
DocumentBlanks = DocumentBlanks
};
public void UpdateComponents(LawFirmDatabase context, DocumentBindingModel model)
{
var documentBlanks = context.DocumentBlanks.Where(rec => rec.DocumentId == model.Id).ToList();
if (documentBlanks != null && documentBlanks.Count > 0)
{ // удалили те, которых нет в модели
context.DocumentBlanks.RemoveRange(documentBlanks.Where(rec => !model.DocumentBlanks.ContainsKey(rec.BlankId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateBlank in documentBlanks)
{
updateBlank.Count = model.DocumentBlanks[updateBlank.BlankId].Item2;
model.DocumentBlanks.Remove(updateBlank.BlankId);
}
context.SaveChanges();
}
var document = context.Documents.First(x => x.Id == Id);
foreach (var pc in model.DocumentBlanks)
{
context.DocumentBlanks.Add(new DocumentBlank
{
Document = document,
Blank = context.Blanks.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_documentBlanks = null;
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Models
{
public class DocumentBlank
{
public int Id { get; set; }
[Required]
public int DocumentId { get; set; }
[Required]
public int BlankId { get; set; }
[Required]
public int Count { get; set; }
public virtual Blank Blank { get; set; } = new();
public virtual Document Document { get; set; } = new();
}
}

View File

@ -0,0 +1,71 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Enums;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
[Required]
public int DocumentId { get; private set; }
[Required]
public int Count { get; private set; }
[Required]
public double Sum { get; private set; }
[Required]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public virtual Document Document { get; set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order
{
DocumentId = model.DocumentId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
Id = model.Id,
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
DocumentId = DocumentId,
Count = Count,
Sum = Sum,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,
Status = Status,
DocumentName = Document.DocumentName
};
}
}

View File

@ -0,0 +1,113 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Adress { get; set; } = string.Empty;
[Required]
public DateTime OpeningDate { get; set; }
[ForeignKey("ShopId")]
public List<ShopDocument> Documents { get; set; } = new();
private Dictionary<int, (IDocumentModel, int)>? _shopDocuments = null;
[NotMapped]
public Dictionary<int, (IDocumentModel, int)> ShopDocuments
{
get
{
if (_shopDocuments == null)
{
_shopDocuments = Documents.ToDictionary(recPC => recPC.DocumentId, recPC => (recPC.Document as IDocumentModel, recPC.Count));
}
return _shopDocuments;
}
}
[Required]
public int MaxCountDocuments { get; set; }
public static Shop Create(LawFirmDatabase context, ShopBindingModel model)
{
return new Shop()
{
Id = model.Id,
Name = model.Name,
Adress = model.Adress,
OpeningDate = model.OpeningDate,
Documents = model.ShopDocuments.Select(x => new ShopDocument
{
Document = context.Documents.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList(),
MaxCountDocuments = model.MaxCountDocuments
};
}
public void Update(ShopBindingModel model)
{
Name = model.Name;
Adress = model.Adress;
OpeningDate = model.OpeningDate;
MaxCountDocuments = model.MaxCountDocuments;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Adress = Adress,
OpeningDate = OpeningDate,
ShopDocuments = ShopDocuments,
MaxCountDocuments = MaxCountDocuments
};
public void UpdateDocuments(LawFirmDatabase context, ShopBindingModel model)
{
var ShopDocuments = context.ShopDocuments.Where(rec => rec.ShopId == model.Id).ToList();
if (ShopDocuments != null && ShopDocuments.Count > 0)
{
// удалили те, которых нет в модели
context.ShopDocuments.RemoveRange(ShopDocuments.Where(rec => !model.ShopDocuments.ContainsKey(rec.DocumentId)));
context.SaveChanges();
ShopDocuments = context.ShopDocuments.Where(rec => rec.ShopId == model.Id).ToList();
// обновили количество у существующих записей
foreach (var updateDoc in ShopDocuments)
{
updateDoc.Count = model.ShopDocuments[updateDoc.DocumentId].Item2;
model.ShopDocuments.Remove(updateDoc.DocumentId);
}
context.SaveChanges();
}
var shop = context.Shops.First(x => x.Id == Id);
foreach (var elem in model.ShopDocuments)
{
context.ShopDocuments.Add(new ShopDocument
{
Shop = shop,
Document = context.Documents.First(x => x.Id == elem.Key),
Count = elem.Value.Item2
});
context.SaveChanges();
}
_shopDocuments = null;
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmDatabaseImplement.Models
{
public class ShopDocument
{
public int Id { get; set; }
[Required]
public int DocumentId { get; set; }
[Required]
public int ShopId { get; set; }
[Required]
public int Count { get; set; }
public virtual Shop Shop { get; set; } = new();
public virtual Document Document { get; set; } = new();
}
}

View File

@ -0,0 +1,60 @@
using LawFirmFileImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace LawFirmFileImplement
{
public class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string BlankFileName = "Blank.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string DocumentFileName = "Document.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Blank> Blanks { get; private set; }
public List<Order> Orders { get; private set; }
public List<Document> Documents { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
instance = new DataFileSingleton();
}
return instance;
}
public void SaveBlanks() => SaveData(Blanks, BlankFileName, "Blanks", x => x.GetXElement);
public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!;
Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}

View File

@ -0,0 +1,88 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmFileImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmFileImplement.Implements
{
public class BlankStorage : IBlankStorage
{
private readonly DataFileSingleton source;
public BlankStorage()
{
source = DataFileSingleton.GetInstance();
}
public BlankViewModel? GetElement(BlankSearchModel model)
{
if (string.IsNullOrEmpty(model.BlankName) && !model.Id.HasValue)
{
return null;
}
return source.Blanks
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.BlankName) && x.BlankName == model.BlankName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<BlankViewModel> GetFilteredList(BlankSearchModel model)
{
if (string.IsNullOrEmpty(model.BlankName))
{
return new();
}
return source.Blanks
.Where(x => x.BlankName.Contains(model.BlankName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<BlankViewModel> GetFullList()
{
return source.Blanks.Select(x => x.GetViewModel).ToList();
}
public BlankViewModel? Insert(BlankBindingModel model)
{
model.Id = source.Blanks.Count > 0 ? source.Blanks.Max(x => x.Id) + 1 : 1;
var newBlank = Blank.Create(model);
if (newBlank == null)
{
return null;
}
source.Blanks.Add(newBlank);
source.SaveBlanks();
return newBlank.GetViewModel;
}
public BlankViewModel? Update(BlankBindingModel model)
{
var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id);
if (blank == null)
{
return null;
}
blank.Update(model);
source.SaveBlanks();
return blank.GetViewModel;
}
public BlankViewModel? Delete(BlankBindingModel model)
{
var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id);
if (blank == null)
{
return null;
}
source.Blanks.Remove(blank);
source.SaveBlanks();
return blank.GetViewModel;
}
}
}

View File

@ -0,0 +1,88 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace LawFirmFileImplement.Implements
{
public class DocumentStorage : IDocumentStorage
{
private readonly DataFileSingleton source;
public DocumentStorage()
{
source = DataFileSingleton.GetInstance();
}
public DocumentViewModel? GetElement(DocumentSearchModel model)
{
if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue)
{
return null;
}
return source.Documents
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && x.DocumentName == model.DocumentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<DocumentViewModel> GetFilteredList(DocumentSearchModel model)
{
if (string.IsNullOrEmpty(model.DocumentName))
{
return new();
}
return source.Documents
.Where(x => x.DocumentName.Contains(model.DocumentName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<DocumentViewModel> GetFullList()
{
return source.Documents.Select(x => x.GetViewModel).ToList();
}
public DocumentViewModel? Insert(DocumentBindingModel model)
{
model.Id = source.Documents.Count > 0 ? source.Documents.Max(x => x.Id) + 1 : 1;
var newDoc = Document.Create(model);
if (newDoc == null)
{
return null;
}
source.Documents.Add(newDoc);
source.SaveDocuments();
return newDoc.GetViewModel;
}
public DocumentViewModel? Update(DocumentBindingModel model)
{
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
if (document == null)
{
return null;
}
document.Update(model);
source.SaveDocuments();
return document.GetViewModel;
}
public DocumentViewModel? Delete(DocumentBindingModel model)
{
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
if (document == null)
{
return null;
}
source.Documents.Remove(document);
source.SaveDocuments();
return document.GetViewModel;
}
}
}

View File

@ -0,0 +1,98 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmFileImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton source;
public OrderStorage()
{
source = DataFileSingleton.GetInstance();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return GetViewModel(source.Orders
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
return source.Orders
.Where(x => x.Id == model.Id)
.Select(x => GetViewModel(x))
.ToList();
}
public List<OrderViewModel> GetFullList()
{
return source.Orders.Select(x => GetViewModel(x)).ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
source.Orders.Add(newOrder);
source.SaveOrders();
return GetViewModel(newOrder);
}
public OrderViewModel? Update(OrderBindingModel model)
{
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
source.SaveOrders();
return GetViewModel(order);
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
source.Orders.Remove(order);
source.SaveOrders();
return GetViewModel(order);
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var document = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId);
if (document != null)
{
viewModel.DocumentName = document.DocumentName;
}
return viewModel;
}
}
}

View File

@ -0,0 +1,148 @@
using LawFirmContracts.BindingModels;
using LawFirmContracts.SearchModels;
using LawFirmContracts.StorageContracts;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using LawFirmFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawFirmFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton source;
public ShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
return source.Shops
.Select(x => x.GetViewModel)
.Where(x => x.Name.Contains(model.Name ?? string.Empty))
.ToList();
}
public List<ShopViewModel> GetFullList()
{
return source.Shops.Select(shop => shop.GetViewModel).ToList();
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
source.Shops.Add(newShop);
source.SaveShops();
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop == null)
{
return null;
}
shop.Update(model);
source.SaveShops();
return shop.GetViewModel;
}
public ShopViewModel? Delete(ShopBindingModel model)
{
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop == null)
{
return null;
}
source.Shops.Remove(shop);
source.SaveShops();
return shop.GetViewModel;
}
public bool SellDocument(IDocumentModel model, int count)
{
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
if (document == null)
{
return false;
}
var countStore = count;
var shopDocuments = source.Shops.SelectMany(shop => shop.ShopDocuments.Where(doc => doc.Value.Item1.Id == document.Id));
foreach (var doc in shopDocuments)
{
count -= doc.Value.Item2;
if (count <= 0)
{
break;
}
}
if (count > 0)
{
return false;
}
count = countStore;
foreach (var shop in source.Shops)
{
var documents = shop.ShopDocuments;
foreach (var doc in documents.Where(x => x.Value.Item1.Id == document.Id))
{
var min = Math.Min(doc.Value.Item2, count);
documents[doc.Value.Item1.Id] = (doc.Value.Item1, doc.Value.Item2 - min);
count -= min;
if (count <= 0)
{
break;
}
}
shop.Update(new ShopBindingModel
{
Id = shop.Id,
Name = shop.Name,
Adress = shop.Adress,
OpeningDate = shop.OpeningDate,
MaxCountDocuments = shop.MaxCountDocuments,
ShopDocuments = documents
});
source.SaveShops();
if (count <= 0) break;
}
return count <= 0;
}
}
}

Some files were not shown because too many files have changed in this diff Show More