Почти всё

This commit is contained in:
dimazhelovanov 2023-03-26 23:35:58 +03:00
parent f9004f50f6
commit 3b1b9f88b4
24 changed files with 1269 additions and 488 deletions

View File

@ -0,0 +1,125 @@
namespace BlacksmithWorkshop
{
partial class FormClients
{
/// <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()
{
dataGridView = new DataGridView();
Id = new DataGridViewTextBoxColumn();
СlientFIO = new DataGridViewTextBoxColumn();
Email = new DataGridViewTextBoxColumn();
Password = new DataGridViewTextBoxColumn();
buttonDelete = new Button();
buttonUpdate = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Id, СlientFIO, Email, Password });
dataGridView.Location = new Point(-4, 1);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(657, 450);
dataGridView.TabIndex = 0;
//
// Id
//
Id.HeaderText = "Id";
Id.MinimumWidth = 6;
Id.Name = "Id";
Id.Width = 125;
//
// СlientFIO
//
СlientFIO.HeaderText = "ФИО клиента";
СlientFIO.MinimumWidth = 6;
СlientFIO.Name = "СlientFIO";
СlientFIO.Width = 125;
//
// Email
//
Email.HeaderText = "E-mail";
Email.MinimumWidth = 6;
Email.Name = "Email";
Email.Width = 125;
//
// Password
//
Password.HeaderText = "Пароль";
Password.MinimumWidth = 6;
Password.Name = "Password";
Password.Width = 125;
//
// buttonDelete
//
buttonDelete.Location = new Point(671, 28);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(94, 29);
buttonDelete.TabIndex = 1;
buttonDelete.Text = "Удалить";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += ButtonDelete_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(671, 84);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(94, 29);
buttonUpdate.TabIndex = 2;
buttonUpdate.Text = "Обновить";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += ButtonUpdate_Click;
//
// FormClients
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonUpdate);
Controls.Add(buttonDelete);
Controls.Add(dataGridView);
Name = "FormClients";
Text = "Клиенты";
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonDelete;
private Button buttonUpdate;
private DataGridViewTextBoxColumn Id;
private DataGridViewTextBoxColumn СlientFIO;
private DataGridViewTextBoxColumn Email;
private DataGridViewTextBoxColumn Password;
}
}

View File

@ -0,0 +1,90 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using Microsoft.EntityFrameworkCore.Diagnostics;
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 BlacksmithWorkshop
{
public partial class FormClients : Form
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
public FormClients(ILogger<FormComponents> logger, IClientLogic
logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Email"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_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 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 ClientBindingModel
{
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,72 @@
<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="СlientFIO.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Email.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Password.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -1,216 +1,217 @@
namespace BlacksmithWorkshop
{
partial class FormMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
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);
}
/// <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
#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.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.справочникиToolStripMenuItem1 = 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.ComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ComponentsManufactueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.OrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonnTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem1,
this.отчётыToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(920, 28);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// справочникиToolStripMenuItem1
//
this.справочникиToolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.компонентыToolStripMenuItem,
this.кузнечныеИзделияToolStripMenuItem});
this.справочникиToolStripMenuItem1.Name = "справочникиToolStripMenuItem1";
this.справочникиToolStripMenuItem1.Size = new System.Drawing.Size(117, 24);
this.справочникиToolStripMenuItem1.Text = "Справочники";
//
// компонентыToolStripMenuItem
//
this.компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(227, 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(227, 26);
this.кузнечныеИзделияToolStripMenuItem.Text = "КузнечныеИзделия";
this.кузнечныеИзделияToolStripMenuItem.Click += new System.EventHandler(this.КузнечныеИзделияToolStripMenuItem_Click);
//
// отчётыToolStripMenuItem
//
this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ComponentsToolStripMenuItem,
this.ComponentsManufactueToolStripMenuItem,
this.OrdersToolStripMenuItem});
this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(73, 24);
this.отчётыToolStripMenuItem.Text = "Отчёты";
//
// ComponentsToolStripMenuItem
//
this.ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem";
this.ComponentsToolStripMenuItem.Size = new System.Drawing.Size(276, 26);
this.ComponentsToolStripMenuItem.Text = "Список компонентов";
this.ComponentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// ComponentsManufactueToolStripMenuItem
//
this.ComponentsManufactueToolStripMenuItem.Name = "ComponentsManufactueToolStripMenuItem";
this.ComponentsManufactueToolStripMenuItem.Size = new System.Drawing.Size(276, 26);
this.ComponentsManufactueToolStripMenuItem.Text = "Компоненты по изделиям";
this.ComponentsManufactueToolStripMenuItem.Click += new System.EventHandler(this.ComponentsManufactueToolStripMenuItem_Click);
//
// OrdersToolStripMenuItem
//
this.OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem";
this.OrdersToolStripMenuItem.Size = new System.Drawing.Size(276, 26);
this.OrdersToolStripMenuItem.Text = "Список заказов";
this.OrdersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
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(684, 407);
this.dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(721, 55);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(187, 29);
this.buttonCreateOrder.TabIndex = 2;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
// buttonnTakeOrderInWork
//
this.buttonnTakeOrderInWork.Location = new System.Drawing.Point(721, 111);
this.buttonnTakeOrderInWork.Name = "buttonnTakeOrderInWork";
this.buttonnTakeOrderInWork.Size = new System.Drawing.Size(187, 29);
this.buttonnTakeOrderInWork.TabIndex = 3;
this.buttonnTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonnTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonnTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
//
// buttonOrderReady
//
this.buttonOrderReady.Location = new System.Drawing.Point(721, 166);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.Size = new System.Drawing.Size(187, 29);
this.buttonOrderReady.TabIndex = 4;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Location = new System.Drawing.Point(721, 221);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.Size = new System.Drawing.Size(187, 29);
this.buttonIssuedOrder.TabIndex = 5;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(721, 280);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(187, 29);
this.buttonRef.TabIndex = 6;
this.buttonRef.Text = "Обновить список";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(920, 450);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonOrderReady);
this.Controls.Add(this.buttonnTakeOrderInWork);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormMain";
this.Text = "Магазин кузнечных изделий";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
menuStrip1 = new MenuStrip();
справочникиToolStripMenuItem1 = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
кузнечныеИзделияToolStripMenuItem = new ToolStripMenuItem();
отчётыToolStripMenuItem = new ToolStripMenuItem();
ComponentsToolStripMenuItem = new ToolStripMenuItem();
ComponentsManufactueToolStripMenuItem = new ToolStripMenuItem();
OrdersToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonnTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
клиентыToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem1, отчётыToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(920, 28);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1";
//
// справочникиToolStripMenuItem1
//
справочникиToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, кузнечныеИзделияToolStripMenuItem, клиентыToolStripMenuItem });
справочникиToolStripMenuItem1.Name = "справочникиToolStripMenuItem1";
справочникиToolStripMenuItem1.Size = new Size(117, 24);
справочникиToolStripMenuItem1.Text = "Справочники";
//
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(227, 26);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
//
// кузнечныеИзделияToolStripMenuItem
//
кузнечныеИзделияToolStripMenuItem.Name = узнечныеИзделияToolStripMenuItem";
кузнечныеИзделияToolStripMenuItem.Size = new Size(227, 26);
кузнечныеИзделияToolStripMenuItem.Text = "КузнечныеИзделия";
кузнечныеИзделияToolStripMenuItem.Click += КузнечныеИзделияToolStripMenuItem_Click;
//
// отчётыToolStripMenuItem
//
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ComponentsManufactueToolStripMenuItem, OrdersToolStripMenuItem });
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
отчётыToolStripMenuItem.Size = new Size(73, 24);
отчётыToolStripMenuItem.Text = "Отчёты";
//
// ComponentsToolStripMenuItem
//
ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem";
ComponentsToolStripMenuItem.Size = new Size(276, 26);
ComponentsToolStripMenuItem.Text = "Список компонентов";
ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
//
// ComponentsManufactueToolStripMenuItem
//
ComponentsManufactueToolStripMenuItem.Name = "ComponentsManufactueToolStripMenuItem";
ComponentsManufactueToolStripMenuItem.Size = new Size(276, 26);
ComponentsManufactueToolStripMenuItem.Text = "Компоненты по изделиям";
ComponentsManufactueToolStripMenuItem.Click += ComponentsManufactueToolStripMenuItem_Click;
//
// OrdersToolStripMenuItem
//
OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem";
OrdersToolStripMenuItem.Size = new Size(276, 26);
OrdersToolStripMenuItem.Text = "Список заказов";
OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
//
// dataGridView
//
dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 31);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(684, 407);
dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(721, 55);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(187, 29);
buttonCreateOrder.TabIndex = 2;
buttonCreateOrder.Text = "Создать заказ";
buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += ButtonCreateOrder_Click;
//
// buttonnTakeOrderInWork
//
buttonnTakeOrderInWork.Location = new Point(721, 111);
buttonnTakeOrderInWork.Name = "buttonnTakeOrderInWork";
buttonnTakeOrderInWork.Size = new Size(187, 29);
buttonnTakeOrderInWork.TabIndex = 3;
buttonnTakeOrderInWork.Text = "Отдать на выполнение";
buttonnTakeOrderInWork.UseVisualStyleBackColor = true;
buttonnTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(721, 166);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(187, 29);
buttonOrderReady.TabIndex = 4;
buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += ButtonOrderReady_Click;
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(721, 221);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(187, 29);
buttonIssuedOrder.TabIndex = 5;
buttonIssuedOrder.Text = "Заказ выдан";
buttonIssuedOrder.UseVisualStyleBackColor = true;
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
//
// buttonRef
//
buttonRef.Location = new Point(721, 280);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(187, 29);
buttonRef.TabIndex = 6;
buttonRef.Text = "Обновить список";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// клиентыToolStripMenuItem
//
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
клиентыToolStripMenuItem.Size = new Size(227, 26);
клиентыToolStripMenuItem.Text = "Клиенты";
клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(920, 450);
Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
Controls.Add(buttonnTakeOrderInWork);
Controls.Add(buttonCreateOrder);
Controls.Add(dataGridView);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Name = "FormMain";
Text = "Магазин кузнечных изделий";
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
}
#endregion
#endregion
private MenuStrip menuStrip1;
private DataGridView dataGridView;
private Button buttonCreateOrder;
private ToolStripMenuItem справочникиToolStripMenuItem1;
private Button buttonnTakeOrderInWork;
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem кузнечныеИзделияToolStripMenuItem;
private ToolStripMenuItem отчётыToolStripMenuItem;
private ToolStripMenuItem ComponentsToolStripMenuItem;
private ToolStripMenuItem ComponentsManufactueToolStripMenuItem;
private ToolStripMenuItem OrdersToolStripMenuItem;
}
private MenuStrip menuStrip1;
private DataGridView dataGridView;
private Button buttonCreateOrder;
private ToolStripMenuItem справочникиToolStripMenuItem1;
private Button buttonnTakeOrderInWork;
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem кузнечныеИзделияToolStripMenuItem;
private ToolStripMenuItem отчётыToolStripMenuItem;
private ToolStripMenuItem ComponentsToolStripMenuItem;
private ToolStripMenuItem ComponentsManufactueToolStripMenuItem;
private ToolStripMenuItem OrdersToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem;
}
}

View File

@ -15,227 +15,238 @@ using System.Windows.Forms;
namespace BlacksmithWorkshop
{
public partial class FormMain : Form
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
LoadData();
_reportLogic = reportLogic;
}
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
LoadData();
_reportLogic = reportLogic;
}
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["ManufactureId"].Visible = false;
}
_logger.LogInformation("Загрузка компонентов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки компонентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
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["ManufactureId"].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(FormManufactures));
if (service is FormManufactures form)
{
form.ShowDialog();
}
}
private void КузнечныеИзделияToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormManufactures));
if (service is FormManufactures form)
{
form.ShowDialog();
}
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents 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 КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new
OrderBindingModel
{ Id = id,
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
}
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
id);
try
{
var operationResult = _orderLogic.FinishOrder(new
OrderBindingModel
{
Id = id,
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new
OrderBindingModel
{
Id = id,
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
}
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'",
id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new
OrderBindingModel
{
Id = id,
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",
id);
try
{
var operationResult = _orderLogic.FinishOrder(new
OrderBindingModel
{
Id = id,
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveComponentsToWordFile(new ReportBindingModel
{
FileName = dialog.FileName
});
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'",
id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new
OrderBindingModel
{
Id = id,
ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString())
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ComponentsManufactueToolStripMenuItem_Click(object sender, EventArgs e)
{
var service =
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveComponentsToWordFile(new ReportBindingModel
{
FileName = dialog.FileName
});
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
private void ComponentsManufactueToolStripMenuItem_Click(object sender, EventArgs e)
{
var service =
Program.ServiceProvider?.GetService(typeof(FormReportManufactureComponents));
if (service is FormReportManufactureComponents form)
{
form.ShowDialog();
}
}
if (service is FormReportManufactureComponents form)
{
form.ShowDialog();
}
}
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service =
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service =
Program.ServiceProvider?.GetService(typeof(FormReportOrders));
if (service is FormReportOrders form)
{
form.ShowDialog();
}
}
}
if (service is FormReportOrders form)
{
form.ShowDialog();
}
}
private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service =
Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
}
}

View File

@ -60,6 +60,7 @@ namespace BlacksmithWorkshop
services.AddTransient<FormManufactures>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormReportManufactureComponents>();
services.AddTransient<FormClients>();
}
}
}

View File

@ -1,7 +1,9 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
@ -12,29 +14,115 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
{
public class ClientLogic : IClientLogic
{
public bool Create(ClientBindingModel model)
private readonly ILogger _logger;
private readonly IClientStorage _clientStorage;
public ClientLogic(ILogger<ComponentLogic> logger, IClientStorage
clientStorage)
{
_logger = logger;
_clientStorage = clientStorage;
}
public bool Create(ClientBindingModel model)
{
throw new NotImplementedException();
}
CheckModel(model);
if (_clientStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ClientBindingModel model)
{
throw new NotImplementedException();
}
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_clientStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ClientViewModel? ReadElement(ClientSearchModel model)
{
throw new NotImplementedException();
}
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ClientFIO:{ ClientFIO}. ClientEmail:{ ClientEmail}. Id:{ Id}", model.ClientFIO, model.Email, model.Id);
var element = _clientStorage.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<ClientViewModel>? ReadList(ClientSearchModel? model)
{
throw new NotImplementedException();
}
_logger.LogInformation("ReadElement. ClientFIO:{ ClientFIO}. ClientEmail:{ ClientEmail}. Id:{ Id}", model.ClientFIO, model.Email, model.Id);
var list = model == null ? _clientStorage.GetFullList() :
_clientStorage.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(ClientBindingModel model)
{
throw new NotImplementedException();
}
}
CheckModel(model);
if (_clientStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(ClientBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ClientFIO))
{
throw new ArgumentNullException("Введите ФИО",
nameof(model.ClientFIO));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Введите E-Mail",
nameof(model.Email));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Введите пароль",
nameof(model.Password));
}
_logger.LogInformation("Client. Client:{ClientFIO}. Email:{ Email}. Id: { Id}", model.ClientFIO, model.Email, model.Id);
var element = _clientStorage.GetElement(new ClientSearchModel
{
Email = model.Email
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Данный e-mail уже зарегистрирован");
}
}
}
}

View File

@ -27,5 +27,10 @@ namespace BlacksmithWorkshopContracts.ViewModels
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
}
public int ClientId { get; set; }
[DisplayName("Клиент")]
public string ClientFIO { get; set;} = string.Empty;
}
}

View File

@ -15,5 +15,6 @@ namespace BlacksmithWorkshopDataModel.Models
OrderStatus Status { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
}
int ClientId { get; }
}
}

View File

@ -23,6 +23,7 @@ optionsBuilder)
public virtual DbSet<Manufacture> Manufactures { set; get; }
public virtual DbSet<ManufactureComponent> ManufactureComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Client> Clients { set; get; }
}
}

View File

@ -2,6 +2,7 @@
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -14,28 +15,67 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
{
public ClientViewModel? Delete(ClientBindingModel model)
{
throw new NotImplementedException();
}
using var context = new BlacksmithWorkshopDatabase();
var element = context.Clients.FirstOrDefault(rec => rec.Id ==
model.Id);
if (element != null)
{
context.Clients.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
throw new NotImplementedException();
}
if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
{
return null;
}
using var context = new BlacksmithWorkshopDatabase();
return context.Clients
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Email) && x.Email ==
model.Email) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
throw new NotImplementedException();
}
if (string.IsNullOrEmpty(model.Email) || !model.Id.HasValue)
{
return new();
}
using var context = new BlacksmithWorkshopDatabase();
return context.Clients
.Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))
.Select(x => x.GetViewModel)
.ToList();
}
public List<ClientViewModel> GetFullList()
{
throw new NotImplementedException();
}
using var context = new BlacksmithWorkshopDatabase();
return context.Clients
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
throw new NotImplementedException();
}
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
using var context = new BlacksmithWorkshopDatabase();
context.Clients.Add(newClient);
context.SaveChanges();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{

View File

@ -50,7 +50,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
}
using var context = new BlacksmithWorkshopDatabase();
return context.Orders
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || model.ClientId == x.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}

View File

@ -0,0 +1,68 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModel.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopDatabaseImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
[Required]
public string ClientFIO { get; private set; } = string.Empty;
[Required]
public string Email { get; private set; } = string.Empty;
[Required]
public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public static Client Create(ClientViewModel model)
{
return new Client
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
}
}

View File

@ -4,6 +4,7 @@ using BlacksmithWorkshopDataModel.Enums;
using BlacksmithWorkshopDataModel.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -13,6 +14,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int ManufactureId { get; private set; }
public int Count { get; private set; }
@ -25,9 +27,12 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
public DateTime? DateImplement { get; private set; }
public int Id { get; private set; }
public static Order? Create(OrderBindingModel model)
[Required]
public int ClientId { get; private set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
@ -42,7 +47,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
DateImplement = model.DateImplement,
ClientId = model.ClientId
};
@ -62,9 +68,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
ClientId = model.ClientId;
}
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
@ -74,7 +82,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
DateImplement = DateImplement,
ClientId = ClientId
};
}
}

View File

@ -14,10 +14,12 @@ namespace BlacksmithWorkshopFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string ManufactureFileName = "Manufacture.xml";
public List<Component> Components { get; private set; }
private readonly string ClientFileName = "Client.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Manufacture> Manufactures { get; private set; }
public static DataFileSingleton GetInstance()
public List<Client> Clients { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
@ -30,14 +32,17 @@ namespace BlacksmithWorkshopFileImplement
public void SaveManufactures() => SaveData(Manufactures, ManufactureFileName,
"Manufactures", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
private DataFileSingleton()
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x =>
Component.Create(x)!)!;
Manufactures = LoadData(ManufactureFileName, "Manufacture", x =>
Manufacture.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
}
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
Func<XElement, T> selectFunction)
{

View File

@ -2,6 +2,7 @@
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -12,34 +13,82 @@ namespace BlacksmithWorkshopFileImplement.Implements
{
public class ClientStorage : IClientStorage
{
public ClientViewModel? Delete(ClientBindingModel model)
private readonly DataFileSingleton source;
public ClientStorage()
{
source = DataFileSingleton.GetInstance();
}
public ClientViewModel? Delete(ClientBindingModel model)
{
throw new NotImplementedException();
}
var element = source.Clients.FirstOrDefault(x => x.Id ==
model.Id);
if (element != null)
{
source.Clients.Remove(element);
source.SaveClients();
return element.GetViewModel;
}
return null;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
throw new NotImplementedException();
}
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
{
return null;
}
return source.Clients
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Email) && x.Email ==
model.Email) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
throw new NotImplementedException();
}
if (string.IsNullOrEmpty(model.Email))
{
return new();
}
return source.Clients
.Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))
.Select(x => x.GetViewModel)
.ToList();
}
public List<ClientViewModel> GetFullList()
{
throw new NotImplementedException();
}
return source.Clients
.Select(x => x.GetViewModel)
.ToList();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
throw new NotImplementedException();
}
model.Id = source.Clients.Count > 0 ? source.Clients.Max(x =>
x.Id) + 1 : 1;
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
source.Clients.Add(newClient);
source.SaveClients();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
throw new NotImplementedException();
}
var client = source.Clients.FirstOrDefault(x => x.Id ==
model.Id);
if (client == null)
{
return null;
}
client.Update(model);
source.SaveComponents();
return client.GetViewModel;
}
}
}

View File

@ -49,7 +49,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
return new();
}
return source.Orders
.Where(x => x.Id == model.Id)
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}

View File

@ -0,0 +1,76 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModel.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public static Client? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Client()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ClientFIO = element.Element("ClientFIO")!.Value,
Email = element.Element("Email")!.Value,
Password = element.Element("Password")!.Value
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
public XElement GetXElement => new("Client",
new XAttribute("Id", Id),
new XElement("ClientFIO", ClientFIO),
new XElement("Email", Email),
new XElement("Password", Password));
}
}

View File

@ -27,6 +27,7 @@ namespace BlacksmithWorkshopFileImplement.Models
public DateTime? DateImplement { get; private set; }
public int Id { get; private set; }
public int ClientId { get; private set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
@ -42,7 +43,8 @@ namespace BlacksmithWorkshopFileImplement.Models
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
DateImplement = model.DateImplement,
ClientId = model.ClientId
};
@ -62,8 +64,9 @@ namespace BlacksmithWorkshopFileImplement.Models
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value)
};
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value)
};
}
public void Update(OrderBindingModel model)
{
@ -79,9 +82,10 @@ namespace BlacksmithWorkshopFileImplement.Models
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
ClientId = model.ClientId;
}
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
@ -91,8 +95,10 @@ namespace BlacksmithWorkshopFileImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
DateImplement = DateImplement,
ClientId = ClientId
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("ManufactureId", ManufactureId),
@ -101,7 +107,8 @@ namespace BlacksmithWorkshopFileImplement.Models
new XElement("Sum", Sum.ToString()),
new XElement("Status", ((int)Status).ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString()));
new XElement("DateImplement", DateImplement.ToString()),
new XElement("ClientId", ClientId));
}
}

View File

@ -13,11 +13,13 @@ namespace BlacksmithWorkshopListImplement
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Manufacture> Manufactures { get; set; }
private DataListSingleton()
public List<Client> Clients { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Manufactures = new List<Manufacture>();
Clients = new List<Client>();
}
public static DataListSingleton GetInstance()
{

View File

@ -2,6 +2,7 @@
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,35 +12,102 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopListImplement.Implements
{
public class ClientStorage : IClientStorage
{
public ClientViewModel? Delete(ClientBindingModel model)
private readonly DataListSingleton _source;
public ClientStorage()
{
_source = DataListSingleton.GetInstance();
}
public ClientViewModel? Delete(ClientBindingModel model)
{
throw new NotImplementedException();
}
for (int i = 0; i < _source.Clients.Count; ++i)
{
if (_source.Clients[i].Id == model.Id)
{
var element = _source.Clients[i];
_source.Clients.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
throw new NotImplementedException();
}
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
{
return null;
}
foreach (var client in _source.Clients)
{
if ((!string.IsNullOrEmpty(model.Email) &&
client.Email == model.Email) ||
(model.Id.HasValue && client.Id == model.Id))
{
return client.GetViewModel;
}
}
return null;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
throw new NotImplementedException();
}
var result = new List<ClientViewModel>();
if (string.IsNullOrEmpty(model.Email))
{
return result;
}
foreach (var client in _source.Clients)
{
if (client.Email.Equals(model.Email) && client.Password.Equals(model.Password))
{
result.Add(client.GetViewModel);
}
}
return result;
}
public List<ClientViewModel> GetFullList()
{
throw new NotImplementedException();
}
var result = new List<ClientViewModel>();
foreach (var client in _source.Clients)
{
result.Add(client.GetViewModel);
}
return result;
}
public ClientViewModel? Insert(ClientBindingModel model)
{
throw new NotImplementedException();
}
model.Id = 1;
foreach (var client in _source.Clients)
{
if (model.Id <= client.Id)
{
model.Id = client.Id + 1;
}
}
var newClients = Client.Create(model);
if (newClients == null)
{
return null;
}
_source.Clients.Add(newClients);
return newClients.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
throw new NotImplementedException();
}
foreach (var client in _source.Clients)
{
if (client.Id == model.Id)
{
client.Update(model);
return client.GetViewModel;
}
}
return null;
}
}
}

View File

@ -59,7 +59,7 @@ namespace BlacksmithWorkshopListImplement.Implements
foreach (var order in _source.Orders)
{
if (order.Id == model.Id )/*|| model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo)*/
if (order.Id == model.Id && model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo || order.ClientId == model.ClientId)
{
result.Add(order.GetViewModel);
}

View File

@ -0,0 +1,54 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModel.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopListImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel? model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public void Update(ClientBindingModel? model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
}
}

View File

@ -31,6 +31,7 @@ namespace BlacksmithWorkshopListImplement.Models
public int Id { get; set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
@ -46,7 +47,8 @@ namespace BlacksmithWorkshopListImplement.Models
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
ManufactureId = model.ManufactureId,
ManufactureName = model.ManufactureName
ManufactureName = model.ManufactureName,
ClientId = model.ClientId
};
}
public void Update(OrderBindingModel? model)
@ -63,6 +65,7 @@ namespace BlacksmithWorkshopListImplement.Models
DateImplement = model.DateImplement;
ManufactureId = model.ManufactureId;
ManufactureName = model.ManufactureName;
ClientId = model.ClientId;
}
public OrderViewModel GetViewModel => new()
{
@ -73,7 +76,10 @@ namespace BlacksmithWorkshopListImplement.Models
DateCreate = DateCreate,
DateImplement = DateImplement,
ManufactureId = ManufactureId,
ManufactureName = ManufactureName
ManufactureName = ManufactureName,
ClientId = ClientId
};
}
public int ClientId { get; set; }
}
}