Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
ad9ce78231 | |||
16d9bd2048 | |||
658b0bc060 | |||
6833381b98 | |||
f6966a2f78 | |||
b8929bf9eb |
30
ProjectSellPC/ProjectSellPC/Entites/Cheque.cs
Normal file
30
ProjectSellPC/ProjectSellPC/Entites/Cheque.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Entites
|
||||||
|
{
|
||||||
|
public class Cheque
|
||||||
|
{
|
||||||
|
[System.ComponentModel.Browsable(false)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Товары")]
|
||||||
|
public List<ProductInCheque> Products { get; set; }
|
||||||
|
[DisplayName("Клиент")]
|
||||||
|
public Client Client { get; set; }
|
||||||
|
|
||||||
|
[System.ComponentModel.Browsable(false)]
|
||||||
|
public int ClientId { get; set; }
|
||||||
|
[DisplayName("Дата покупки")]
|
||||||
|
public DateTime PurchaseDate { get; set; }
|
||||||
|
|
||||||
|
public static Cheque CreateEntity(int id, List<ProductInCheque> products, Client client, DateTime purchaseDate)
|
||||||
|
{
|
||||||
|
return new Cheque
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Products = products,
|
||||||
|
Client = client,
|
||||||
|
PurchaseDate = purchaseDate
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
ProjectSellPC/ProjectSellPC/Entites/Client.cs
Normal file
37
ProjectSellPC/ProjectSellPC/Entites/Client.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using ProjectSellPC.Entites.Enums;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Entites
|
||||||
|
{
|
||||||
|
public class Client
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Имя")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
[DisplayName("Номер телефона")]
|
||||||
|
public string PhoneNumber { get; set; }
|
||||||
|
[DisplayName("Вид клиента")]
|
||||||
|
public ClientType ClientType { get; set; }
|
||||||
|
|
||||||
|
public static Client CreateEntity(int id, string name, string phoneNumber, ClientType clientType)
|
||||||
|
{
|
||||||
|
return new Client
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Name = name,
|
||||||
|
PhoneNumber = phoneNumber,
|
||||||
|
ClientType = clientType
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
ProjectSellPC/ProjectSellPC/Entites/Enums/ClientType.cs
Normal file
15
ProjectSellPC/ProjectSellPC/Entites/Enums/ClientType.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Entites.Enums
|
||||||
|
{
|
||||||
|
public enum ClientType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Individual = 1,
|
||||||
|
Business = 2
|
||||||
|
}
|
||||||
|
}
|
23
ProjectSellPC/ProjectSellPC/Entites/Enums/ProductType.cs
Normal file
23
ProjectSellPC/ProjectSellPC/Entites/Enums/ProductType.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Entites.Enums
|
||||||
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum ProductType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Laptop = 1,
|
||||||
|
Desktop = 2, // Настольный компьютер
|
||||||
|
Monitor = 4, // Монитор
|
||||||
|
Keyboard = 8, // Клавиатура
|
||||||
|
Mouse = 16, // Мышь
|
||||||
|
Headset = 32, // Наушники
|
||||||
|
Webcam = 64, // Веб-камера
|
||||||
|
Printer = 128, // Принтер
|
||||||
|
Software = 256 // Программное обеспечение
|
||||||
|
}
|
||||||
|
}
|
31
ProjectSellPC/ProjectSellPC/Entites/Product.cs
Normal file
31
ProjectSellPC/ProjectSellPC/Entites/Product.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using ProjectSellPC.Entites.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Entites
|
||||||
|
{
|
||||||
|
public class Product
|
||||||
|
{
|
||||||
|
public int ID { get; private set; }
|
||||||
|
[DisplayName("Имя")]
|
||||||
|
public string Name { get; private set; }
|
||||||
|
[DisplayName("Описание")]
|
||||||
|
public string Description { get; private set; }
|
||||||
|
[DisplayName("Цена")]
|
||||||
|
public decimal Price { get; private set; }
|
||||||
|
[DisplayName("Вид")]
|
||||||
|
public ProductType ProductType { get; private set; }
|
||||||
|
|
||||||
|
public static Product CreateEntity(int id, string name, string desc, decimal price, ProductType productType)
|
||||||
|
{
|
||||||
|
return new Product { ID = id,
|
||||||
|
Name = name ?? string.Empty,
|
||||||
|
Description = desc ?? string.Empty,
|
||||||
|
Price = price,
|
||||||
|
ProductType = productType };
|
||||||
|
}
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
ProjectSellPC/ProjectSellPC/Entites/ProductInCheque..cs
Normal file
25
ProjectSellPC/ProjectSellPC/Entites/ProductInCheque..cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace ProjectSellPC.Entites
|
||||||
|
{
|
||||||
|
public class ProductInCheque
|
||||||
|
{
|
||||||
|
public int ID { get; set; }
|
||||||
|
[System.ComponentModel.Browsable(false)]
|
||||||
|
public int ProductID { get; set; }
|
||||||
|
[Browsable(false)]
|
||||||
|
public int ChequeID { get; set; }
|
||||||
|
[DisplayName("Количество")]
|
||||||
|
public int Count { get; set; }
|
||||||
|
// Временное свойство для отображения названия товара
|
||||||
|
[Browsable(false)] // Скрываем свойство в DataGridView
|
||||||
|
public string ProductName { get; set; }
|
||||||
|
public static ProductInCheque CreateElement(int id, int count)
|
||||||
|
{
|
||||||
|
return new ProductInCheque { ProductID = id, Count = count };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
ProjectSellPC/ProjectSellPC/Entites/ProductsOnWarehouse.cs
Normal file
29
ProjectSellPC/ProjectSellPC/Entites/ProductsOnWarehouse.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Entites
|
||||||
|
{
|
||||||
|
public class ProductsOnWarehouse
|
||||||
|
{
|
||||||
|
[System.ComponentModel.Browsable(false)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[System.ComponentModel.Browsable(false)]
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
[DisplayName("Товар")]
|
||||||
|
public Product Product { get; set; }
|
||||||
|
[System.ComponentModel.Browsable(false)]
|
||||||
|
public int WarehouseId { get; set; }
|
||||||
|
[DisplayName("Склад")]
|
||||||
|
public Warehouse Warehouse { get; set; }
|
||||||
|
[DisplayName("Количество")]
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
public static ProductsOnWarehouse CreateEntity(int id, Product product, Warehouse Warehouse, int count)
|
||||||
|
{
|
||||||
|
return new ProductsOnWarehouse { Warehouse = Warehouse, Id = id, Product = product, Count = count };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
ProjectSellPC/ProjectSellPC/Entites/Warehouse.cs
Normal file
29
ProjectSellPC/ProjectSellPC/Entites/Warehouse.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Entites
|
||||||
|
{
|
||||||
|
public class Warehouse
|
||||||
|
{
|
||||||
|
[System.ComponentModel.Browsable(false)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Вместимость")]
|
||||||
|
public int Size { get; set; } // Вместимость
|
||||||
|
[DisplayName("Адрес")]
|
||||||
|
public string Adress { get; set; }
|
||||||
|
|
||||||
|
public static Warehouse CreateEntity(int id, int size, string adress)
|
||||||
|
{
|
||||||
|
return new Warehouse { Id = id, Size = size, Adress = adress };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Adress;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
ProjectSellPC/ProjectSellPC/Form1.Designer.cs
generated
39
ProjectSellPC/ProjectSellPC/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace ProjectSellPC
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form1";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace ProjectSellPC
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
77
ProjectSellPC/ProjectSellPC/Forms/Cheque/ChequeForm.Designer.cs
generated
Normal file
77
ProjectSellPC/ProjectSellPC/Forms/Cheque/ChequeForm.Designer.cs
generated
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
namespace ProjectSellPC.Forms.Receipt
|
||||||
|
{
|
||||||
|
partial class ChequeForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
addButton = new Button();
|
||||||
|
ChequesDataGridView = new DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)ChequesDataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// addButton
|
||||||
|
//
|
||||||
|
addButton.BackColor = SystemColors.Control;
|
||||||
|
addButton.Location = new Point(878, 12);
|
||||||
|
addButton.Name = "addButton";
|
||||||
|
addButton.Size = new Size(161, 60);
|
||||||
|
addButton.TabIndex = 3;
|
||||||
|
addButton.Text = "Добавить";
|
||||||
|
addButton.UseVisualStyleBackColor = false;
|
||||||
|
addButton.Click += addButton_Click;
|
||||||
|
//
|
||||||
|
// ChequesDataGridView
|
||||||
|
//
|
||||||
|
ChequesDataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
ChequesDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
ChequesDataGridView.Location = new Point(12, 12);
|
||||||
|
ChequesDataGridView.Name = "ChequesDataGridView";
|
||||||
|
ChequesDataGridView.RowHeadersWidth = 51;
|
||||||
|
ChequesDataGridView.Size = new Size(851, 399);
|
||||||
|
ChequesDataGridView.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// ChequeForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1056, 450);
|
||||||
|
Controls.Add(addButton);
|
||||||
|
Controls.Add(ChequesDataGridView);
|
||||||
|
Name = "ChequeForm";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Чеки";
|
||||||
|
Load += ChequeForm_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)ChequesDataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button addButton;
|
||||||
|
private DataGridView ChequesDataGridView;
|
||||||
|
}
|
||||||
|
}
|
100
ProjectSellPC/ProjectSellPC/Forms/Cheque/ChequeForm.cs
Normal file
100
ProjectSellPC/ProjectSellPC/Forms/Cheque/ChequeForm.cs
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using Unity;
|
||||||
|
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 ProjectSellPC.Forms.Receipt
|
||||||
|
{
|
||||||
|
public partial class ChequeForm : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly IChequeRepository _ChequeRepository;
|
||||||
|
private readonly IClientRepository _clientRepository;
|
||||||
|
private readonly IProductRepository _productRepository; // Добавляем репозиторий товаров
|
||||||
|
|
||||||
|
public ChequeForm(IUnityContainer unityContainer, IChequeRepository ChequeRepository, IClientRepository clientRepository, IProductRepository productRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_container = unityContainer ?? throw new ArgumentNullException(nameof(unityContainer));
|
||||||
|
_ChequeRepository = ChequeRepository ?? throw new ArgumentNullException(nameof(ChequeRepository));
|
||||||
|
_clientRepository = clientRepository ?? throw new ArgumentNullException(nameof(clientRepository));
|
||||||
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository)); // Инициализация репозитория товаров
|
||||||
|
}
|
||||||
|
private void ChequeForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Получаем все чеки и удаляем дубликаты по ID
|
||||||
|
var cheques = _ChequeRepository.ReadAll()
|
||||||
|
.GroupBy(c => c.Id)
|
||||||
|
.Select(g => g.First())
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
// Загружаем информацию о клиентах
|
||||||
|
foreach (var cheque in cheques)
|
||||||
|
{
|
||||||
|
cheque.Client = _clientRepository.Read(cheque.ClientId);
|
||||||
|
|
||||||
|
// Загружаем названия товаров для каждого чека
|
||||||
|
foreach (var productInCheque in cheque.Products)
|
||||||
|
{
|
||||||
|
var product = _productRepository.Read(productInCheque.ProductID);
|
||||||
|
productInCheque.ProductName = product?.Name ?? "Неизвестный товар";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Привязываем данные к DataGridView
|
||||||
|
ChequesDataGridView.DataSource = cheques.Select(c => new
|
||||||
|
{
|
||||||
|
Id = c.Id,
|
||||||
|
ClientName = c.Client?.Name ?? "Неизвестно",
|
||||||
|
PurchaseDate = c.PurchaseDate,
|
||||||
|
Products = string.Join(", ", c.Products.Select(p => p.ProductName)), // Названия товаров через запятую
|
||||||
|
Quantities = string.Join(", ", c.Products.Select(p => p.Count.ToString())) // Количество товаров через запятую
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
// Настройка столбцов DataGridView
|
||||||
|
ChequesDataGridView.Columns["Id"].HeaderText = "ID";
|
||||||
|
ChequesDataGridView.Columns["ClientName"].HeaderText = "Клиент";
|
||||||
|
ChequesDataGridView.Columns["PurchaseDate"].HeaderText = "Дата покупки";
|
||||||
|
ChequesDataGridView.Columns["Products"].HeaderText = "Товары";
|
||||||
|
ChequesDataGridView.Columns["Quantities"].HeaderText = "Количество";
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void addButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<ChequeSettingsForm>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectSellPC/ProjectSellPC/Forms/Cheque/ChequeForm.resx
Normal file
120
ProjectSellPC/ProjectSellPC/Forms/Cheque/ChequeForm.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
134
ProjectSellPC/ProjectSellPC/Forms/Cheque/ChequeSettingsForm .Designer.cs
generated
Normal file
134
ProjectSellPC/ProjectSellPC/Forms/Cheque/ChequeSettingsForm .Designer.cs
generated
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
namespace ProjectSellPC.Forms.Receipt
|
||||||
|
{
|
||||||
|
partial class ChequeSettingsForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
customerComboBox = new ComboBox();
|
||||||
|
label1 = new Label();
|
||||||
|
saveButton = new Button();
|
||||||
|
label4 = new Label();
|
||||||
|
productsDataGridView = new DataGridView();
|
||||||
|
ProductColoumn = new DataGridViewComboBoxColumn();
|
||||||
|
ProductCount = new DataGridViewTextBoxColumn();
|
||||||
|
((System.ComponentModel.ISupportInitialize)productsDataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// customerComboBox
|
||||||
|
//
|
||||||
|
customerComboBox.FormattingEnabled = true;
|
||||||
|
customerComboBox.Location = new Point(152, 6);
|
||||||
|
customerComboBox.Name = "customerComboBox";
|
||||||
|
customerComboBox.Size = new Size(151, 28);
|
||||||
|
customerComboBox.TabIndex = 18;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(12, 9);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(97, 20);
|
||||||
|
label1.TabIndex = 17;
|
||||||
|
label1.Text = "Покупатель: ";
|
||||||
|
//
|
||||||
|
// saveButton
|
||||||
|
//
|
||||||
|
saveButton.Anchor = AnchorStyles.Bottom;
|
||||||
|
saveButton.Location = new Point(125, 297);
|
||||||
|
saveButton.Name = "saveButton";
|
||||||
|
saveButton.Size = new Size(94, 29);
|
||||||
|
saveButton.TabIndex = 19;
|
||||||
|
saveButton.Text = "Сохранить";
|
||||||
|
saveButton.UseVisualStyleBackColor = true;
|
||||||
|
saveButton.Click += saveButton_Click;
|
||||||
|
//
|
||||||
|
// label4
|
||||||
|
//
|
||||||
|
label4.AutoSize = true;
|
||||||
|
label4.Location = new Point(12, 44);
|
||||||
|
label4.Name = "label4";
|
||||||
|
label4.Size = new Size(54, 20);
|
||||||
|
label4.TabIndex = 15;
|
||||||
|
label4.Text = "Товар:";
|
||||||
|
//
|
||||||
|
// productsDataGridView
|
||||||
|
//
|
||||||
|
productsDataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
productsDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
productsDataGridView.Columns.AddRange(new DataGridViewColumn[] { ProductColoumn, ProductCount });
|
||||||
|
productsDataGridView.Location = new Point(12, 67);
|
||||||
|
productsDataGridView.Name = "productsDataGridView";
|
||||||
|
productsDataGridView.RowHeadersWidth = 51;
|
||||||
|
productsDataGridView.Size = new Size(336, 224);
|
||||||
|
productsDataGridView.TabIndex = 20;
|
||||||
|
//
|
||||||
|
// ProductColoumn
|
||||||
|
//
|
||||||
|
ProductColoumn.HeaderText = "Товары";
|
||||||
|
ProductColoumn.MinimumWidth = 6;
|
||||||
|
ProductColoumn.Name = "ProductColoumn";
|
||||||
|
ProductColoumn.Resizable = DataGridViewTriState.True;
|
||||||
|
ProductColoumn.SortMode = DataGridViewColumnSortMode.Automatic;
|
||||||
|
ProductColoumn.Width = 125;
|
||||||
|
//
|
||||||
|
// ProductCount
|
||||||
|
//
|
||||||
|
ProductCount.HeaderText = "Количество";
|
||||||
|
ProductCount.MinimumWidth = 6;
|
||||||
|
ProductCount.Name = "ProductCount";
|
||||||
|
ProductCount.Width = 125;
|
||||||
|
//
|
||||||
|
// ChequeSettingsForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(360, 338);
|
||||||
|
Controls.Add(productsDataGridView);
|
||||||
|
Controls.Add(saveButton);
|
||||||
|
Controls.Add(customerComboBox);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Controls.Add(label4);
|
||||||
|
Name = "ChequeSettingsForm";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Новый чек";
|
||||||
|
Load += ChequeSettingsForm_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)productsDataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private ComboBox customerComboBox;
|
||||||
|
private Label label1;
|
||||||
|
private Button saveButton;
|
||||||
|
private Label label4;
|
||||||
|
private DataGridView productsDataGridView;
|
||||||
|
private DataGridViewComboBoxColumn ProductColoumn;
|
||||||
|
private DataGridViewTextBoxColumn ProductCount;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using ProjectSellPC.Entites.Enums;
|
||||||
|
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 ProjectSellPC.Forms.Receipt
|
||||||
|
{
|
||||||
|
public partial class ChequeSettingsForm : Form
|
||||||
|
{
|
||||||
|
private readonly IChequeRepository _ChequeRepository;
|
||||||
|
private readonly IProductRepository _productRepository;
|
||||||
|
private readonly IClientRepository _customerRepository;
|
||||||
|
|
||||||
|
public ChequeSettingsForm(IChequeRepository ChequeRepository, IProductRepository productRepository, IClientRepository customerRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_ChequeRepository = ChequeRepository ?? throw new ArgumentNullException(nameof(ChequeRepository));
|
||||||
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
|
||||||
|
_customerRepository = customerRepository ?? throw new ArgumentNullException(nameof(customerRepository));
|
||||||
|
|
||||||
|
|
||||||
|
ProductColoumn.DataSource = _productRepository.ReadAll().ToList();
|
||||||
|
ProductColoumn.DisplayMember = "Name";
|
||||||
|
ProductColoumn.ValueMember = "Id";
|
||||||
|
|
||||||
|
customerComboBox.DataSource = _customerRepository.ReadAll().ToList();
|
||||||
|
customerComboBox.DisplayMember = "Name";
|
||||||
|
customerComboBox.ValueMember = "Id";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChequeSettingsForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (productsDataGridView.RowCount < 1 || customerComboBox.SelectedItem == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Необходимо выбрать товар и клиента");
|
||||||
|
}
|
||||||
|
|
||||||
|
var products = CreateListProducts();
|
||||||
|
var customer = (Client)customerComboBox.SelectedItem;
|
||||||
|
|
||||||
|
var cheque = Cheque.CreateEntity(0, products, customer, DateTime.Now);
|
||||||
|
_ChequeRepository.Create(cheque);
|
||||||
|
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при создании чека", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private List<ProductInCheque> CreateListProducts()
|
||||||
|
{
|
||||||
|
var list = new List<ProductInCheque>();
|
||||||
|
foreach (DataGridViewRow row in productsDataGridView.Rows)
|
||||||
|
{
|
||||||
|
if (row.Cells["ProductColoumn"].Value == null || row.Cells["ProductCount"].Value == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
list.Add(ProductInCheque.CreateElement(Convert.ToInt32(row.Cells["ProductColoumn"].Value), Convert.ToInt32(row.Cells["ProductCount"].Value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,126 @@
|
|||||||
|
<?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>
|
||||||
|
<metadata name="ProductColoumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="ProductCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
103
ProjectSellPC/ProjectSellPC/Forms/Clients/ClientForm.Designer.cs
generated
Normal file
103
ProjectSellPC/ProjectSellPC/Forms/Clients/ClientForm.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
namespace ProjectSellPC.Forms
|
||||||
|
{
|
||||||
|
partial class ClientForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
deleteButton = new Button();
|
||||||
|
editButton = new Button();
|
||||||
|
addButton = new Button();
|
||||||
|
productsDataGridView = new DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)productsDataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// deleteButton
|
||||||
|
//
|
||||||
|
deleteButton.Location = new Point(869, 144);
|
||||||
|
deleteButton.Name = "deleteButton";
|
||||||
|
deleteButton.Size = new Size(161, 60);
|
||||||
|
deleteButton.TabIndex = 7;
|
||||||
|
deleteButton.Text = "Удалить";
|
||||||
|
deleteButton.UseVisualStyleBackColor = true;
|
||||||
|
deleteButton.Click += deleteButton_Click;
|
||||||
|
//
|
||||||
|
// editButton
|
||||||
|
//
|
||||||
|
editButton.Location = new Point(869, 78);
|
||||||
|
editButton.Name = "editButton";
|
||||||
|
editButton.Size = new Size(161, 60);
|
||||||
|
editButton.TabIndex = 6;
|
||||||
|
editButton.Text = "Редактировать";
|
||||||
|
editButton.UseVisualStyleBackColor = true;
|
||||||
|
editButton.Click += editButton_Click;
|
||||||
|
//
|
||||||
|
// addButton
|
||||||
|
//
|
||||||
|
addButton.BackColor = SystemColors.Control;
|
||||||
|
addButton.Location = new Point(869, 12);
|
||||||
|
addButton.Name = "addButton";
|
||||||
|
addButton.Size = new Size(161, 60);
|
||||||
|
addButton.TabIndex = 5;
|
||||||
|
addButton.Text = "Добавить";
|
||||||
|
addButton.UseVisualStyleBackColor = false;
|
||||||
|
addButton.Click += addButton_Click;
|
||||||
|
//
|
||||||
|
// productsDataGridView
|
||||||
|
//
|
||||||
|
productsDataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
productsDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
productsDataGridView.Location = new Point(12, 12);
|
||||||
|
productsDataGridView.Name = "productsDataGridView";
|
||||||
|
productsDataGridView.RowHeadersWidth = 51;
|
||||||
|
productsDataGridView.Size = new Size(851, 400);
|
||||||
|
productsDataGridView.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// ClientForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1056, 424);
|
||||||
|
Controls.Add(deleteButton);
|
||||||
|
Controls.Add(editButton);
|
||||||
|
Controls.Add(addButton);
|
||||||
|
Controls.Add(productsDataGridView);
|
||||||
|
Name = "ClientForm";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Клиенты";
|
||||||
|
Load += ClientForm_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)productsDataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button deleteButton;
|
||||||
|
private Button editButton;
|
||||||
|
private Button addButton;
|
||||||
|
private DataGridView productsDataGridView;
|
||||||
|
}
|
||||||
|
}
|
116
ProjectSellPC/ProjectSellPC/Forms/Clients/ClientForm.cs
Normal file
116
ProjectSellPC/ProjectSellPC/Forms/Clients/ClientForm.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
using ProjectSellPC.Forms.Clients;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using Unity;
|
||||||
|
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 ProjectSellPC.Forms
|
||||||
|
{
|
||||||
|
public partial class ClientForm : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly IClientRepository _repository;
|
||||||
|
|
||||||
|
public ClientForm(IUnityContainer unityContainer, IClientRepository clientRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_container = unityContainer ?? throw new ArgumentNullException(nameof(unityContainer));
|
||||||
|
_repository = clientRepository ?? throw new ArgumentNullException(nameof(_repository));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClientForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadList()
|
||||||
|
{
|
||||||
|
|
||||||
|
productsDataGridView.DataSource = _repository.ReadAll();
|
||||||
|
productsDataGridView.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (productsDataGridView.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = Convert.ToInt32(productsDataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<ClientFormSettings>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void editButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<ClientFormSettings>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_repository.Delete(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectSellPC/ProjectSellPC/Forms/Clients/ClientForm.resx
Normal file
120
ProjectSellPC/ProjectSellPC/Forms/Clients/ClientForm.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
133
ProjectSellPC/ProjectSellPC/Forms/Clients/ClientFormSettings.Designer.cs
generated
Normal file
133
ProjectSellPC/ProjectSellPC/Forms/Clients/ClientFormSettings.Designer.cs
generated
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
namespace ProjectSellPC.Forms.Clients
|
||||||
|
{
|
||||||
|
partial class ClientFormSettings
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
label2 = new Label();
|
||||||
|
label1 = new Label();
|
||||||
|
nameTextbox = new TextBox();
|
||||||
|
saveButton = new Button();
|
||||||
|
phoneNumberTextbox = new TextBox();
|
||||||
|
typeCombobox = new ComboBox();
|
||||||
|
label4 = new Label();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(13, 59);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(130, 20);
|
||||||
|
label2.TabIndex = 13;
|
||||||
|
label2.Text = "Номер телефона:";
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(13, 12);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(122, 20);
|
||||||
|
label1.TabIndex = 11;
|
||||||
|
label1.Text = "Имя покупателя";
|
||||||
|
//
|
||||||
|
// nameTextbox
|
||||||
|
//
|
||||||
|
nameTextbox.Location = new Point(153, 12);
|
||||||
|
nameTextbox.Name = "nameTextbox";
|
||||||
|
nameTextbox.Size = new Size(210, 27);
|
||||||
|
nameTextbox.TabIndex = 10;
|
||||||
|
//
|
||||||
|
// saveButton
|
||||||
|
//
|
||||||
|
saveButton.Anchor = AnchorStyles.Bottom;
|
||||||
|
saveButton.Location = new Point(153, 229);
|
||||||
|
saveButton.Name = "saveButton";
|
||||||
|
saveButton.Size = new Size(94, 29);
|
||||||
|
saveButton.TabIndex = 9;
|
||||||
|
saveButton.Text = "Сохранить";
|
||||||
|
saveButton.UseVisualStyleBackColor = true;
|
||||||
|
saveButton.Click += saveButton_Click;
|
||||||
|
//
|
||||||
|
// phoneNumberTextbox
|
||||||
|
//
|
||||||
|
phoneNumberTextbox.Location = new Point(153, 59);
|
||||||
|
phoneNumberTextbox.Name = "phoneNumberTextbox";
|
||||||
|
phoneNumberTextbox.Size = new Size(210, 27);
|
||||||
|
phoneNumberTextbox.TabIndex = 18;
|
||||||
|
//
|
||||||
|
// typeCombobox
|
||||||
|
//
|
||||||
|
typeCombobox.FormattingEnabled = true;
|
||||||
|
typeCombobox.Location = new Point(153, 101);
|
||||||
|
typeCombobox.Name = "typeCombobox";
|
||||||
|
typeCombobox.Size = new Size(151, 28);
|
||||||
|
typeCombobox.TabIndex = 20;
|
||||||
|
//
|
||||||
|
// label4
|
||||||
|
//
|
||||||
|
label4.AutoSize = true;
|
||||||
|
label4.Location = new Point(13, 104);
|
||||||
|
label4.Name = "label4";
|
||||||
|
label4.Size = new Size(38, 20);
|
||||||
|
label4.TabIndex = 19;
|
||||||
|
label4.Text = "Вид:";
|
||||||
|
//
|
||||||
|
// ClientFormSettings
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(388, 270);
|
||||||
|
Controls.Add(typeCombobox);
|
||||||
|
Controls.Add(label4);
|
||||||
|
Controls.Add(phoneNumberTextbox);
|
||||||
|
Controls.Add(label2);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Controls.Add(nameTextbox);
|
||||||
|
Controls.Add(saveButton);
|
||||||
|
Name = "ClientFormSettings";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Регистрация клиента";
|
||||||
|
Load += ClientFormSettings_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private ComboBox typeCombobox;
|
||||||
|
private Label label4;
|
||||||
|
private Label label3;
|
||||||
|
private NumericUpDown priceNumeric;
|
||||||
|
private Label label2;
|
||||||
|
private TextBox descriptionTextbox;
|
||||||
|
private Label label1;
|
||||||
|
private TextBox nameTextbox;
|
||||||
|
private Button saveButton;
|
||||||
|
private TextBox phoneNumberTextbox;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
using ProjectSellPC.Entites.Enums;
|
||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
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 ProjectSellPC.Forms.Clients
|
||||||
|
{
|
||||||
|
public partial class ClientFormSettings : Form
|
||||||
|
{
|
||||||
|
private readonly IClientRepository _repository;
|
||||||
|
|
||||||
|
private int? _clientId;
|
||||||
|
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var client = _repository.Read(value);
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException(nameof(client));
|
||||||
|
}
|
||||||
|
nameTextbox.Text = client.Name;
|
||||||
|
phoneNumberTextbox.Text = client.PhoneNumber;
|
||||||
|
typeCombobox.SelectedItem = client.ClientType;
|
||||||
|
|
||||||
|
_clientId = value;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientFormSettings(IClientRepository clientRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_repository = clientRepository ?? throw new ArgumentNullException(nameof(clientRepository));
|
||||||
|
typeCombobox.DataSource = Enum.GetValues(typeof(ClientType));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClientFormSettings_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(nameTextbox.Text) ||
|
||||||
|
string.IsNullOrWhiteSpace(phoneNumberTextbox.Text) || typeCombobox.SelectedIndex < 1
|
||||||
|
|| typeCombobox.SelectedIndex < 1)
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_clientId.HasValue)
|
||||||
|
{
|
||||||
|
|
||||||
|
_repository.Update(CreateClient(_clientId.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
_repository.Create(CreateClient(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Client CreateClient(int id)
|
||||||
|
{
|
||||||
|
return Client.CreateEntity(id, nameTextbox.Text, phoneNumberTextbox.Text, (ClientType)typeCombobox.SelectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
89
ProjectSellPC/ProjectSellPC/Forms/DocReports/DirectoryReportForm.Designer.cs
generated
Normal file
89
ProjectSellPC/ProjectSellPC/Forms/DocReports/DirectoryReportForm.Designer.cs
generated
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using DocumentFormat.OpenXml.Spreadsheet;
|
||||||
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Forms.DocReports
|
||||||
|
{
|
||||||
|
partial class DocReportForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
label1 = new Label();
|
||||||
|
buildReportButton = new Button();
|
||||||
|
entitiesCheckedListBox = new CheckedListBox();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(12, 9);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(164, 20);
|
||||||
|
label1.TabIndex = 0;
|
||||||
|
label1.Text = "Что включить в отчет?";
|
||||||
|
//
|
||||||
|
// buildReportButton
|
||||||
|
//
|
||||||
|
buildReportButton.Anchor = AnchorStyles.Bottom;
|
||||||
|
buildReportButton.Location = new Point(81, 174);
|
||||||
|
buildReportButton.Name = "buildReportButton";
|
||||||
|
buildReportButton.Size = new Size(143, 29);
|
||||||
|
buildReportButton.TabIndex = 1;
|
||||||
|
buildReportButton.Text = "Сформировать";
|
||||||
|
buildReportButton.UseVisualStyleBackColor = true;
|
||||||
|
buildReportButton.Click += buildReportButton_Click;
|
||||||
|
//
|
||||||
|
// entitiesCheckedListBox
|
||||||
|
//
|
||||||
|
entitiesCheckedListBox.FormattingEnabled = true;
|
||||||
|
entitiesCheckedListBox.Items.AddRange(new object[] { "Клиенты", "Товары", "Склады" });
|
||||||
|
entitiesCheckedListBox.Location = new Point(12, 42);
|
||||||
|
entitiesCheckedListBox.Name = "entitiesCheckedListBox";
|
||||||
|
entitiesCheckedListBox.Size = new Size(273, 114);
|
||||||
|
entitiesCheckedListBox.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// DocReportForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(311, 215);
|
||||||
|
Controls.Add(entitiesCheckedListBox);
|
||||||
|
Controls.Add(buildReportButton);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Name = "DocReportForm";
|
||||||
|
Text = "DocReportForm";
|
||||||
|
Load += DocReportForm_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label label1;
|
||||||
|
private Button buildReportButton;
|
||||||
|
private CheckedListBox entitiesCheckedListBox;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
using ProjectSellPC.DocBuilder;
|
||||||
|
using ProjectSellPC.DocumentsBuilder;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Forms.DocReports
|
||||||
|
{
|
||||||
|
public partial class DocReportForm : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
|
||||||
|
public DocReportForm(IUnityContainer container)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DocReportForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildReportButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!entitiesCheckedListBox.GetItemChecked(0) && !entitiesCheckedListBox.GetItemChecked(1) && !entitiesCheckedListBox.GetItemChecked(2))
|
||||||
|
{
|
||||||
|
throw new Exception("Не выбран ни один справочник для выгрузки");
|
||||||
|
}
|
||||||
|
|
||||||
|
var sfd = new SaveFileDialog()
|
||||||
|
{
|
||||||
|
Filter = "Docx Files | *.docx"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (sfd.ShowDialog() != DialogResult.OK)
|
||||||
|
{
|
||||||
|
throw new Exception("Не выбран файла для отчета");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_container.Resolve<DocReport>().CreateDoc(sfd.FileName, entitiesCheckedListBox.GetItemChecked(0),
|
||||||
|
entitiesCheckedListBox.GetItemChecked(1),
|
||||||
|
entitiesCheckedListBox.GetItemChecked(2)))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Документ сформирован",
|
||||||
|
"Формирование документа",
|
||||||
|
MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Возникли ошибки при документа.Подробности в логах",
|
||||||
|
"Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
165
ProjectSellPC/ProjectSellPC/Forms/DocReports/ExcelReportForm.Designer.cs
generated
Normal file
165
ProjectSellPC/ProjectSellPC/Forms/DocReports/ExcelReportForm.Designer.cs
generated
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
namespace ProjectSellPC.Forms.DocReports
|
||||||
|
{
|
||||||
|
partial class ExcelReportForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
formButton = new Button();
|
||||||
|
dateTimePickerDo = new DateTimePicker();
|
||||||
|
label4 = new Label();
|
||||||
|
dateTimePickerOt = new DateTimePicker();
|
||||||
|
label3 = new Label();
|
||||||
|
productCombobox = new ComboBox();
|
||||||
|
label2 = new Label();
|
||||||
|
pathChoiceButton = new Button();
|
||||||
|
pathTextbox = new TextBox();
|
||||||
|
label1 = new Label();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// formButton
|
||||||
|
//
|
||||||
|
formButton.Anchor = AnchorStyles.Bottom;
|
||||||
|
formButton.Location = new Point(178, 240);
|
||||||
|
formButton.Name = "formButton";
|
||||||
|
formButton.Size = new Size(138, 29);
|
||||||
|
formButton.TabIndex = 29;
|
||||||
|
formButton.Text = "Формировать";
|
||||||
|
formButton.UseVisualStyleBackColor = true;
|
||||||
|
formButton.Click += formButton_Click;
|
||||||
|
//
|
||||||
|
// dateTimePickerDo
|
||||||
|
//
|
||||||
|
dateTimePickerDo.Location = new Point(156, 161);
|
||||||
|
dateTimePickerDo.Name = "dateTimePickerDo";
|
||||||
|
dateTimePickerDo.Size = new Size(250, 27);
|
||||||
|
dateTimePickerDo.TabIndex = 28;
|
||||||
|
//
|
||||||
|
// label4
|
||||||
|
//
|
||||||
|
label4.AutoSize = true;
|
||||||
|
label4.Location = new Point(19, 166);
|
||||||
|
label4.Name = "label4";
|
||||||
|
label4.Size = new Size(31, 20);
|
||||||
|
label4.TabIndex = 27;
|
||||||
|
label4.Text = "До:";
|
||||||
|
//
|
||||||
|
// dateTimePickerOt
|
||||||
|
//
|
||||||
|
dateTimePickerOt.Location = new Point(156, 117);
|
||||||
|
dateTimePickerOt.Name = "dateTimePickerOt";
|
||||||
|
dateTimePickerOt.Size = new Size(250, 27);
|
||||||
|
dateTimePickerOt.TabIndex = 26;
|
||||||
|
//
|
||||||
|
// label3
|
||||||
|
//
|
||||||
|
label3.AutoSize = true;
|
||||||
|
label3.Location = new Point(19, 122);
|
||||||
|
label3.Name = "label3";
|
||||||
|
label3.Size = new Size(29, 20);
|
||||||
|
label3.TabIndex = 25;
|
||||||
|
label3.Text = "От:";
|
||||||
|
//
|
||||||
|
// productCombobox
|
||||||
|
//
|
||||||
|
productCombobox.FormattingEnabled = true;
|
||||||
|
productCombobox.Location = new Point(156, 68);
|
||||||
|
productCombobox.Name = "productCombobox";
|
||||||
|
productCombobox.Size = new Size(251, 28);
|
||||||
|
productCombobox.TabIndex = 24;
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(19, 71);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(54, 20);
|
||||||
|
label2.TabIndex = 23;
|
||||||
|
label2.Text = "Товар:";
|
||||||
|
//
|
||||||
|
// pathChoiceButton
|
||||||
|
//
|
||||||
|
pathChoiceButton.Location = new Point(372, 14);
|
||||||
|
pathChoiceButton.Name = "pathChoiceButton";
|
||||||
|
pathChoiceButton.Size = new Size(35, 29);
|
||||||
|
pathChoiceButton.TabIndex = 22;
|
||||||
|
pathChoiceButton.Text = "...";
|
||||||
|
pathChoiceButton.UseVisualStyleBackColor = true;
|
||||||
|
pathChoiceButton.Click += pathChoiceButton_Click;
|
||||||
|
//
|
||||||
|
// pathTextbox
|
||||||
|
//
|
||||||
|
pathTextbox.Location = new Point(156, 15);
|
||||||
|
pathTextbox.Name = "pathTextbox";
|
||||||
|
pathTextbox.ReadOnly = true;
|
||||||
|
pathTextbox.Size = new Size(210, 27);
|
||||||
|
pathTextbox.TabIndex = 21;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(19, 18);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(116, 20);
|
||||||
|
label1.TabIndex = 20;
|
||||||
|
label1.Text = "Путь до файла: ";
|
||||||
|
//
|
||||||
|
// ExcelReportForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(478, 281);
|
||||||
|
Controls.Add(formButton);
|
||||||
|
Controls.Add(dateTimePickerDo);
|
||||||
|
Controls.Add(label4);
|
||||||
|
Controls.Add(dateTimePickerOt);
|
||||||
|
Controls.Add(label3);
|
||||||
|
Controls.Add(productCombobox);
|
||||||
|
Controls.Add(label2);
|
||||||
|
Controls.Add(pathChoiceButton);
|
||||||
|
Controls.Add(pathTextbox);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Name = "ExcelReportForm";
|
||||||
|
Text = "ExcelReportForm";
|
||||||
|
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button formButton;
|
||||||
|
private DateTimePicker dateTimePickerDo;
|
||||||
|
private Label label4;
|
||||||
|
private DateTimePicker dateTimePickerOt;
|
||||||
|
private Label label3;
|
||||||
|
private ComboBox productCombobox;
|
||||||
|
private Label label2;
|
||||||
|
private Button pathChoiceButton;
|
||||||
|
private TextBox pathTextbox;
|
||||||
|
private Label label1;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
using System;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
using ProjectSellPC.DocBuilder;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Forms.DocReports
|
||||||
|
{
|
||||||
|
public partial class ExcelReportForm : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
|
||||||
|
public ExcelReportForm(IUnityContainer container, IProductRepository productRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
|
|
||||||
|
productCombobox.DataSource = productRepository.ReadAll();
|
||||||
|
productCombobox.DisplayMember = "Name";
|
||||||
|
productCombobox.ValueMember = "Id";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void formButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(pathTextbox.Text))
|
||||||
|
{
|
||||||
|
throw new Exception("Отсутствует имя файла для отчета");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (productCombobox.SelectedIndex < 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Не выбран товар");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dateTimePickerDo.Value <= dateTimePickerOt.Value)
|
||||||
|
{
|
||||||
|
throw new Exception("Дата начала должна быть раньше даты окончания");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_container.Resolve<TableReport>().CreateTable(pathTextbox.Text,
|
||||||
|
(int)productCombobox.SelectedValue!,
|
||||||
|
dateTimePickerOt.Value, dateTimePickerDo.Value))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Документ сформирован", "Формирование документа",
|
||||||
|
MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", "Формирование документа",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при создании очета",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pathChoiceButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var sfd = new SaveFileDialog()
|
||||||
|
{
|
||||||
|
Filter = "Excel Files | *.xlsx"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (sfd.ShowDialog() != DialogResult.OK)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pathTextbox.Text = sfd.FileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
110
ProjectSellPC/ProjectSellPC/Forms/DocReports/PdfReportForm.Designer.cs
generated
Normal file
110
ProjectSellPC/ProjectSellPC/Forms/DocReports/PdfReportForm.Designer.cs
generated
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
namespace ProjectSellPC.Forms.DocReports
|
||||||
|
{
|
||||||
|
|
||||||
|
partial class PdfReportForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
formButton = new Button();
|
||||||
|
fileDialogButton = new Button();
|
||||||
|
fileLabel = new Label();
|
||||||
|
label1 = new Label();
|
||||||
|
dateTimePicker = new DateTimePicker();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// formButton
|
||||||
|
//
|
||||||
|
formButton.Anchor = AnchorStyles.Bottom;
|
||||||
|
formButton.Location = new Point(106, 138);
|
||||||
|
formButton.Name = "formButton";
|
||||||
|
formButton.Size = new Size(138, 29);
|
||||||
|
formButton.TabIndex = 30;
|
||||||
|
formButton.Text = "Формировать";
|
||||||
|
formButton.UseVisualStyleBackColor = true;
|
||||||
|
formButton.Click += formButton_Click;
|
||||||
|
//
|
||||||
|
// fileDialogButton
|
||||||
|
//
|
||||||
|
fileDialogButton.Location = new Point(41, 23);
|
||||||
|
fileDialogButton.Name = "fileDialogButton";
|
||||||
|
fileDialogButton.Size = new Size(94, 29);
|
||||||
|
fileDialogButton.TabIndex = 31;
|
||||||
|
fileDialogButton.Text = "Выбрать";
|
||||||
|
fileDialogButton.UseVisualStyleBackColor = true;
|
||||||
|
fileDialogButton.Click += button1_Click;
|
||||||
|
//
|
||||||
|
// fileLabel
|
||||||
|
//
|
||||||
|
fileLabel.AutoSize = true;
|
||||||
|
fileLabel.Location = new Point(141, 28);
|
||||||
|
fileLabel.Name = "fileLabel";
|
||||||
|
fileLabel.Size = new Size(45, 20);
|
||||||
|
fileLabel.TabIndex = 32;
|
||||||
|
fileLabel.Text = "Файл";
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(41, 80);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(44, 20);
|
||||||
|
label1.TabIndex = 33;
|
||||||
|
label1.Text = "Дата:";
|
||||||
|
//
|
||||||
|
// dateTimePicker
|
||||||
|
//
|
||||||
|
dateTimePicker.Location = new Point(91, 78);
|
||||||
|
dateTimePicker.Name = "dateTimePicker";
|
||||||
|
dateTimePicker.Size = new Size(250, 27);
|
||||||
|
dateTimePicker.TabIndex = 34;
|
||||||
|
//
|
||||||
|
// PdfReportForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(362, 179);
|
||||||
|
Controls.Add(dateTimePicker);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Controls.Add(fileLabel);
|
||||||
|
Controls.Add(fileDialogButton);
|
||||||
|
Controls.Add(formButton);
|
||||||
|
Name = "PdfReportForm";
|
||||||
|
Text = "PdfReportForm";
|
||||||
|
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button formButton;
|
||||||
|
private Button fileDialogButton;
|
||||||
|
private Label fileLabel;
|
||||||
|
private Label label1;
|
||||||
|
private DateTimePicker dateTimePicker;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
using ProjectSellPC.DocBuilder;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Unity;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Forms.DocReports
|
||||||
|
{
|
||||||
|
public partial class PdfReportForm : Form
|
||||||
|
{
|
||||||
|
private string _fileName = string.Empty;
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
|
||||||
|
public PdfReportForm(IUnityContainer container)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void button1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var sfd = new SaveFileDialog()
|
||||||
|
{
|
||||||
|
Filter = "Pdf Files | *.pdf"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (sfd.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
_fileName = sfd.FileName;
|
||||||
|
fileLabel.Text = Path.GetFileName(_fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void formButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(_fileName))
|
||||||
|
{
|
||||||
|
throw new Exception("Отсутствует имя файла для отчета");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_container.Resolve<ChartReport>().CreateChart(_fileName, dateTimePicker.Value))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Документ сформирован", "Формирование документа",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах",
|
||||||
|
"Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при создании очета", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectSellPC/ProjectSellPC/Forms/DocReports/PdfReportForm.resx
Normal file
120
ProjectSellPC/ProjectSellPC/Forms/DocReports/PdfReportForm.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
167
ProjectSellPC/ProjectSellPC/Forms/Form1.Designer.cs
generated
Normal file
167
ProjectSellPC/ProjectSellPC/Forms/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
namespace ProjectSellPC
|
||||||
|
{
|
||||||
|
partial class ShopForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ShopForm));
|
||||||
|
menuStrip1 = new MenuStrip();
|
||||||
|
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
товарыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
клиентыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
складыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
операцииToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
товарыНаСкладеToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
чекиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
отчетToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
документсправочникToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
продажиТоваровToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
отчетграфикToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
menuStrip1.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// menuStrip1
|
||||||
|
//
|
||||||
|
menuStrip1.ImageScalingSize = new Size(20, 20);
|
||||||
|
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетToolStripMenuItem });
|
||||||
|
menuStrip1.Location = new Point(0, 0);
|
||||||
|
menuStrip1.Name = "menuStrip1";
|
||||||
|
menuStrip1.Size = new Size(800, 28);
|
||||||
|
menuStrip1.TabIndex = 0;
|
||||||
|
menuStrip1.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// справочникиToolStripMenuItem
|
||||||
|
//
|
||||||
|
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { товарыToolStripMenuItem, клиентыToolStripMenuItem, складыToolStripMenuItem });
|
||||||
|
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||||
|
справочникиToolStripMenuItem.Size = new Size(126, 24);
|
||||||
|
справочникиToolStripMenuItem.Text = "Справочники...";
|
||||||
|
//
|
||||||
|
// товарыToolStripMenuItem
|
||||||
|
//
|
||||||
|
товарыToolStripMenuItem.Name = "товарыToolStripMenuItem";
|
||||||
|
товарыToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
товарыToolStripMenuItem.Text = "Товары";
|
||||||
|
товарыToolStripMenuItem.Click += товарыToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// клиентыToolStripMenuItem
|
||||||
|
//
|
||||||
|
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
|
||||||
|
клиентыToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
клиентыToolStripMenuItem.Text = "Клиенты";
|
||||||
|
клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// складыToolStripMenuItem
|
||||||
|
//
|
||||||
|
складыToolStripMenuItem.Name = "складыToolStripMenuItem";
|
||||||
|
складыToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
складыToolStripMenuItem.Text = "Склады";
|
||||||
|
складыToolStripMenuItem.Click += складыToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// операцииToolStripMenuItem
|
||||||
|
//
|
||||||
|
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { товарыНаСкладеToolStripMenuItem, чекиToolStripMenuItem });
|
||||||
|
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
|
||||||
|
операцииToolStripMenuItem.Size = new Size(104, 24);
|
||||||
|
операцииToolStripMenuItem.Text = "Операции...";
|
||||||
|
//
|
||||||
|
// товарыНаСкладеToolStripMenuItem
|
||||||
|
//
|
||||||
|
товарыНаСкладеToolStripMenuItem.Name = "товарыНаСкладеToolStripMenuItem";
|
||||||
|
товарыНаСкладеToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
товарыНаСкладеToolStripMenuItem.Text = "Товары на складе";
|
||||||
|
товарыНаСкладеToolStripMenuItem.Click += товарыНаСкаледToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// чекиToolStripMenuItem
|
||||||
|
//
|
||||||
|
чекиToolStripMenuItem.Name = "чекиToolStripMenuItem";
|
||||||
|
чекиToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
чекиToolStripMenuItem.Text = "Чеки...";
|
||||||
|
чекиToolStripMenuItem.Click += чекиToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// отчетToolStripMenuItem
|
||||||
|
//
|
||||||
|
отчетToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документсправочникToolStripMenuItem, продажиТоваровToolStripMenuItem, отчетграфикToolStripMenuItem });
|
||||||
|
отчетToolStripMenuItem.Name = "отчетToolStripMenuItem";
|
||||||
|
отчетToolStripMenuItem.Size = new Size(82, 24);
|
||||||
|
отчетToolStripMenuItem.Text = "Отчеты...";
|
||||||
|
//
|
||||||
|
// документсправочникToolStripMenuItem
|
||||||
|
//
|
||||||
|
документсправочникToolStripMenuItem.Name = "документсправочникToolStripMenuItem";
|
||||||
|
документсправочникToolStripMenuItem.Size = new Size(248, 26);
|
||||||
|
документсправочникToolStripMenuItem.Text = "Документ-справочник";
|
||||||
|
документсправочникToolStripMenuItem.Click += документсправочникToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// продажиТоваровToolStripMenuItem
|
||||||
|
//
|
||||||
|
продажиТоваровToolStripMenuItem.Name = "продажиТоваровToolStripMenuItem";
|
||||||
|
продажиТоваровToolStripMenuItem.Size = new Size(248, 26);
|
||||||
|
продажиТоваровToolStripMenuItem.Text = "Продажи товаров";
|
||||||
|
продажиТоваровToolStripMenuItem.Click += продажиТоваровToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// отчетграфикToolStripMenuItem
|
||||||
|
//
|
||||||
|
отчетграфикToolStripMenuItem.Name = "отчетграфикToolStripMenuItem";
|
||||||
|
отчетграфикToolStripMenuItem.Size = new Size(248, 26);
|
||||||
|
отчетграфикToolStripMenuItem.Text = "Отчет-график";
|
||||||
|
отчетграфикToolStripMenuItem.Click += отчетграфикToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// ShopForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
BackgroundImage = (Image)resources.GetObject("$this.BackgroundImage");
|
||||||
|
BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(menuStrip1);
|
||||||
|
MainMenuStrip = menuStrip1;
|
||||||
|
Name = "ShopForm";
|
||||||
|
Text = "Магазин электроники";
|
||||||
|
Load += ShopForm_Load;
|
||||||
|
menuStrip1.ResumeLayout(false);
|
||||||
|
menuStrip1.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private MenuStrip menuStrip1;
|
||||||
|
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem товарыToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem клиентыToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem складыToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem операцииToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem товарыНаСкладеToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem чекиToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem отчетToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem документсправочникToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem продажиТоваровToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem отчетграфикToolStripMenuItem;
|
||||||
|
}
|
||||||
|
}
|
69
ProjectSellPC/ProjectSellPC/Forms/Form1.cs
Normal file
69
ProjectSellPC/ProjectSellPC/Forms/Form1.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
using ProjectSellPC.Forms;
|
||||||
|
using ProjectSellPC.Forms.ProductsOnWarehouse;
|
||||||
|
using ProjectSellPC.Forms.Receipt;
|
||||||
|
using ProjectSellPC.Forms.Warehouse;
|
||||||
|
using ProjectSellPC.Forms.DocReports;
|
||||||
|
using Unity;
|
||||||
|
|
||||||
|
namespace ProjectSellPC
|
||||||
|
{
|
||||||
|
public partial class ShopForm : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
|
||||||
|
public ShopForm(IUnityContainer container)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void òîâàðûToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_container.Resolve<ProductForm>().ShowDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void êëèåíòûToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_container.Resolve<ClientForm>().ShowDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ñêëàäûToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_container.Resolve<WarehouseForm>().ShowDialog();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void òîâàðûÍàÑêàëåäToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_container.Resolve<ProductsOnWarehouseForm>().ShowDialog();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ÷åêèToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_container.Resolve<ChequeForm>().ShowDialog();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void äîêóìåíòñïðàâî÷íèêToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_container.Resolve<DocReportForm>().ShowDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ïðîäàæèÒîâàðîâToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_container.Resolve<ExcelReportForm>().ShowDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShopForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void îò÷åòãðàôèêToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_container.Resolve<PdfReportForm>().ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1848
ProjectSellPC/ProjectSellPC/Forms/Form1.resx
Normal file
1848
ProjectSellPC/ProjectSellPC/Forms/Form1.resx
Normal file
File diff suppressed because it is too large
Load Diff
103
ProjectSellPC/ProjectSellPC/Forms/Products/ProductForm.Designer.cs
generated
Normal file
103
ProjectSellPC/ProjectSellPC/Forms/Products/ProductForm.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
namespace ProjectSellPC
|
||||||
|
{
|
||||||
|
partial class ProductForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
productsDataGridView = new DataGridView();
|
||||||
|
addButton = new Button();
|
||||||
|
editButton = new Button();
|
||||||
|
deleteButton = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)productsDataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// productsDataGridView
|
||||||
|
//
|
||||||
|
productsDataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
productsDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
productsDataGridView.Location = new Point(12, 12);
|
||||||
|
productsDataGridView.Name = "productsDataGridView";
|
||||||
|
productsDataGridView.RowHeadersWidth = 51;
|
||||||
|
productsDataGridView.Size = new Size(851, 399);
|
||||||
|
productsDataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// addButton
|
||||||
|
//
|
||||||
|
addButton.BackColor = SystemColors.Control;
|
||||||
|
addButton.Location = new Point(878, 12);
|
||||||
|
addButton.Name = "addButton";
|
||||||
|
addButton.Size = new Size(161, 60);
|
||||||
|
addButton.TabIndex = 1;
|
||||||
|
addButton.Text = "Добавить";
|
||||||
|
addButton.UseVisualStyleBackColor = false;
|
||||||
|
addButton.Click += addButton_Click;
|
||||||
|
//
|
||||||
|
// editButton
|
||||||
|
//
|
||||||
|
editButton.Location = new Point(878, 87);
|
||||||
|
editButton.Name = "editButton";
|
||||||
|
editButton.Size = new Size(161, 60);
|
||||||
|
editButton.TabIndex = 2;
|
||||||
|
editButton.Text = "Редактировать";
|
||||||
|
editButton.UseVisualStyleBackColor = true;
|
||||||
|
editButton.Click += editButton_Click;
|
||||||
|
//
|
||||||
|
// deleteButton
|
||||||
|
//
|
||||||
|
deleteButton.Location = new Point(878, 163);
|
||||||
|
deleteButton.Name = "deleteButton";
|
||||||
|
deleteButton.Size = new Size(161, 60);
|
||||||
|
deleteButton.TabIndex = 3;
|
||||||
|
deleteButton.Text = "Удалить";
|
||||||
|
deleteButton.UseVisualStyleBackColor = true;
|
||||||
|
deleteButton.Click += deleteButton_Click;
|
||||||
|
//
|
||||||
|
// ProductForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1051, 423);
|
||||||
|
Controls.Add(deleteButton);
|
||||||
|
Controls.Add(editButton);
|
||||||
|
Controls.Add(addButton);
|
||||||
|
Controls.Add(productsDataGridView);
|
||||||
|
Name = "ProductForm";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Товары";
|
||||||
|
Load += ProductForm_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)productsDataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView productsDataGridView;
|
||||||
|
private Button addButton;
|
||||||
|
private Button editButton;
|
||||||
|
private Button deleteButton;
|
||||||
|
}
|
||||||
|
}
|
115
ProjectSellPC/ProjectSellPC/Forms/Products/ProductForm.cs
Normal file
115
ProjectSellPC/ProjectSellPC/Forms/Products/ProductForm.cs
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using Unity;
|
||||||
|
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 ProjectSellPC
|
||||||
|
{
|
||||||
|
public partial class ProductForm : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly IProductRepository _productRepository;
|
||||||
|
|
||||||
|
public ProductForm(IUnityContainer unityContainer, IProductRepository productRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_container = unityContainer ?? throw new ArgumentNullException(nameof(unityContainer));
|
||||||
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(_productRepository));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProductForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadList()
|
||||||
|
{
|
||||||
|
|
||||||
|
productsDataGridView.DataSource = _productRepository.ReadAll();
|
||||||
|
productsDataGridView.Columns["ID"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (productsDataGridView.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = Convert.ToInt32(productsDataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<ProductSettingsForm>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void editButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<ProductSettingsForm>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_productRepository.Delete(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectSellPC/ProjectSellPC/Forms/Products/ProductForm.resx
Normal file
120
ProjectSellPC/ProjectSellPC/Forms/Products/ProductForm.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
157
ProjectSellPC/ProjectSellPC/Forms/Products/ProductSettingsForm.Designer.cs
generated
Normal file
157
ProjectSellPC/ProjectSellPC/Forms/Products/ProductSettingsForm.Designer.cs
generated
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
namespace ProjectSellPC
|
||||||
|
{
|
||||||
|
partial class ProductSettingsForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
saveButton = new Button();
|
||||||
|
productNameTextbox = new TextBox();
|
||||||
|
label1 = new Label();
|
||||||
|
label2 = new Label();
|
||||||
|
descriptionTextbox = new TextBox();
|
||||||
|
priceNumeric = new NumericUpDown();
|
||||||
|
label3 = new Label();
|
||||||
|
label4 = new Label();
|
||||||
|
typeChequeedListBox = new CheckedListBox();
|
||||||
|
((System.ComponentModel.ISupportInitialize)priceNumeric).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// saveButton
|
||||||
|
//
|
||||||
|
saveButton.Anchor = AnchorStyles.Bottom;
|
||||||
|
saveButton.Location = new Point(157, 436);
|
||||||
|
saveButton.Name = "saveButton";
|
||||||
|
saveButton.Size = new Size(94, 29);
|
||||||
|
saveButton.TabIndex = 0;
|
||||||
|
saveButton.Text = "Сохранить";
|
||||||
|
saveButton.UseVisualStyleBackColor = true;
|
||||||
|
saveButton.Click += saveButton_Click;
|
||||||
|
//
|
||||||
|
// productNameTextbox
|
||||||
|
//
|
||||||
|
productNameTextbox.Location = new Point(152, 36);
|
||||||
|
productNameTextbox.Name = "productNameTextbox";
|
||||||
|
productNameTextbox.Size = new Size(210, 27);
|
||||||
|
productNameTextbox.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(12, 36);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(94, 20);
|
||||||
|
label1.TabIndex = 2;
|
||||||
|
label1.Text = "Имя товара:";
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(12, 83);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(134, 20);
|
||||||
|
label2.TabIndex = 4;
|
||||||
|
label2.Text = "Описание товара:";
|
||||||
|
//
|
||||||
|
// descriptionTextbox
|
||||||
|
//
|
||||||
|
descriptionTextbox.Location = new Point(152, 83);
|
||||||
|
descriptionTextbox.Multiline = true;
|
||||||
|
descriptionTextbox.Name = "descriptionTextbox";
|
||||||
|
descriptionTextbox.Size = new Size(210, 132);
|
||||||
|
descriptionTextbox.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// priceNumeric
|
||||||
|
//
|
||||||
|
priceNumeric.DecimalPlaces = 2;
|
||||||
|
priceNumeric.Location = new Point(152, 233);
|
||||||
|
priceNumeric.Name = "priceNumeric";
|
||||||
|
priceNumeric.Size = new Size(99, 27);
|
||||||
|
priceNumeric.TabIndex = 5;
|
||||||
|
priceNumeric.ThousandsSeparator = true;
|
||||||
|
//
|
||||||
|
// label3
|
||||||
|
//
|
||||||
|
label3.AutoSize = true;
|
||||||
|
label3.Location = new Point(12, 235);
|
||||||
|
label3.Name = "label3";
|
||||||
|
label3.Size = new Size(48, 20);
|
||||||
|
label3.TabIndex = 6;
|
||||||
|
label3.Text = "Цена:";
|
||||||
|
//
|
||||||
|
// label4
|
||||||
|
//
|
||||||
|
label4.AutoSize = true;
|
||||||
|
label4.Location = new Point(12, 285);
|
||||||
|
label4.Name = "label4";
|
||||||
|
label4.Size = new Size(38, 20);
|
||||||
|
label4.TabIndex = 7;
|
||||||
|
label4.Text = "Вид:";
|
||||||
|
//
|
||||||
|
// typeChequeedListBox
|
||||||
|
//
|
||||||
|
typeChequeedListBox.FormattingEnabled = true;
|
||||||
|
typeChequeedListBox.Location = new Point(152, 285);
|
||||||
|
typeChequeedListBox.Name = "typeChequeedListBox";
|
||||||
|
typeChequeedListBox.Size = new Size(150, 114);
|
||||||
|
typeChequeedListBox.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// ProductSettingsForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(409, 477);
|
||||||
|
Controls.Add(typeChequeedListBox);
|
||||||
|
Controls.Add(label4);
|
||||||
|
Controls.Add(label3);
|
||||||
|
Controls.Add(priceNumeric);
|
||||||
|
Controls.Add(label2);
|
||||||
|
Controls.Add(descriptionTextbox);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Controls.Add(productNameTextbox);
|
||||||
|
Controls.Add(saveButton);
|
||||||
|
Name = "ProductSettingsForm";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Настройка товара...";
|
||||||
|
Load += ProductSettingsForm_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)priceNumeric).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button saveButton;
|
||||||
|
private TextBox productNameTextbox;
|
||||||
|
private Label label1;
|
||||||
|
private Label label2;
|
||||||
|
private TextBox descriptionTextbox;
|
||||||
|
private NumericUpDown priceNumeric;
|
||||||
|
private Label label3;
|
||||||
|
private Label label4;
|
||||||
|
private CheckedListBox typeChequeedListBox;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,107 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using ProjectSellPC.Entites.Enums;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using Microsoft.VisualBasic.FileIO;
|
||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ProjectSellPC
|
||||||
|
{
|
||||||
|
public partial class ProductSettingsForm : Form
|
||||||
|
{
|
||||||
|
private readonly IProductRepository _productRepository;
|
||||||
|
|
||||||
|
private int? _productId;
|
||||||
|
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var product = _productRepository.Read(value);
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException(nameof(product));
|
||||||
|
}
|
||||||
|
productNameTextbox.Text = product.Name;
|
||||||
|
descriptionTextbox.Text = product.Description;
|
||||||
|
foreach (ProductType elem in Enum.GetValues(typeof(ProductType)))
|
||||||
|
{
|
||||||
|
if ((elem & product.ProductType) != 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
typeChequeedListBox.SetItemChecked(typeChequeedListBox.Items.IndexOf(elem), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
priceNumeric.Value = product.Price;
|
||||||
|
_productId = value;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductSettingsForm(IProductRepository productRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var elem in Enum.GetValues(typeof(ProductType)))
|
||||||
|
{
|
||||||
|
typeChequeedListBox.Items.Add(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProductSettingsForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(productNameTextbox.Text) ||
|
||||||
|
string.IsNullOrWhiteSpace(descriptionTextbox.Text) || typeChequeedListBox.CheckedItems.Count == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_productId.HasValue)
|
||||||
|
{
|
||||||
|
|
||||||
|
_productRepository.Update(CreateProduct(_productId.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
_productRepository.Create(CreateProduct(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Product CreateProduct(int id)
|
||||||
|
{
|
||||||
|
ProductType type = ProductType.None;
|
||||||
|
foreach (var elem in typeChequeedListBox.CheckedItems)
|
||||||
|
{
|
||||||
|
type |= (ProductType)elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Product.CreateEntity(id, productNameTextbox.Text, descriptionTextbox.Text, priceNumeric.Value, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
77
ProjectSellPC/ProjectSellPC/Forms/ProductsOnWarehouse/ProductsOnWarehouseForm.Designer.cs
generated
Normal file
77
ProjectSellPC/ProjectSellPC/Forms/ProductsOnWarehouse/ProductsOnWarehouseForm.Designer.cs
generated
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
namespace ProjectSellPC.Forms.ProductsOnWarehouse
|
||||||
|
{
|
||||||
|
partial class ProductsOnWarehouseForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
addButton = new Button();
|
||||||
|
productsDataGridView = new DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)productsDataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// addButton
|
||||||
|
//
|
||||||
|
addButton.BackColor = SystemColors.Control;
|
||||||
|
addButton.Location = new Point(881, 12);
|
||||||
|
addButton.Name = "addButton";
|
||||||
|
addButton.Size = new Size(161, 60);
|
||||||
|
addButton.TabIndex = 9;
|
||||||
|
addButton.Text = "Добавить";
|
||||||
|
addButton.UseVisualStyleBackColor = false;
|
||||||
|
addButton.Click += addButton_Click;
|
||||||
|
//
|
||||||
|
// productsDataGridView
|
||||||
|
//
|
||||||
|
productsDataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
productsDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
productsDataGridView.Location = new Point(12, 12);
|
||||||
|
productsDataGridView.Name = "productsDataGridView";
|
||||||
|
productsDataGridView.RowHeadersWidth = 51;
|
||||||
|
productsDataGridView.Size = new Size(851, 400);
|
||||||
|
productsDataGridView.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// ProductsOnWarehouseForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1064, 450);
|
||||||
|
Controls.Add(addButton);
|
||||||
|
Controls.Add(productsDataGridView);
|
||||||
|
Name = "ProductsOnWarehouseForm";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Товары на складе";
|
||||||
|
Load += ProductsOnWarehouse_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)productsDataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button addButton;
|
||||||
|
private DataGridView productsDataGridView;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using Unity;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using 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 ProjectSellPC.Forms.ProductsOnWarehouse
|
||||||
|
{
|
||||||
|
public partial class ProductsOnWarehouseForm : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly IProductOnWarehouseRepository _productOnWarehouseRepository;
|
||||||
|
|
||||||
|
public ProductsOnWarehouseForm(IUnityContainer unityContainer, IProductOnWarehouseRepository productOnWarehouseRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_container = unityContainer ?? throw new ArgumentNullException(nameof(unityContainer));
|
||||||
|
_productOnWarehouseRepository = productOnWarehouseRepository ?? throw new ArgumentNullException(nameof(productOnWarehouseRepository));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProductsOnWarehouse_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadList() => productsDataGridView.DataSource = _productOnWarehouseRepository.ReadAll();
|
||||||
|
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (productsDataGridView.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = Convert.ToInt32(productsDataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<ProductsOnWarehouseSettingsForm>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_productOnWarehouseRepository.Delete(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
134
ProjectSellPC/ProjectSellPC/Forms/ProductsOnWarehouse/ProductsOnWarehouseSettingsForm.Designer.cs
generated
Normal file
134
ProjectSellPC/ProjectSellPC/Forms/ProductsOnWarehouse/ProductsOnWarehouseSettingsForm.Designer.cs
generated
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
namespace ProjectSellPC.Forms.ProductsOnWarehouse
|
||||||
|
{
|
||||||
|
partial class ProductsOnWarehouseSettingsForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
productCombobox = new ComboBox();
|
||||||
|
label4 = new Label();
|
||||||
|
label3 = new Label();
|
||||||
|
countNumeric = new NumericUpDown();
|
||||||
|
WarehouseCombobox = new ComboBox();
|
||||||
|
label1 = new Label();
|
||||||
|
saveButton = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)countNumeric).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// productCombobox
|
||||||
|
//
|
||||||
|
productCombobox.FormattingEnabled = true;
|
||||||
|
productCombobox.Location = new Point(155, 12);
|
||||||
|
productCombobox.Name = "productCombobox";
|
||||||
|
productCombobox.Size = new Size(151, 28);
|
||||||
|
productCombobox.TabIndex = 12;
|
||||||
|
//
|
||||||
|
// label4
|
||||||
|
//
|
||||||
|
label4.AutoSize = true;
|
||||||
|
label4.Location = new Point(15, 15);
|
||||||
|
label4.Name = "label4";
|
||||||
|
label4.Size = new Size(54, 20);
|
||||||
|
label4.TabIndex = 11;
|
||||||
|
label4.Text = "Товар:";
|
||||||
|
//
|
||||||
|
// label3
|
||||||
|
//
|
||||||
|
label3.AutoSize = true;
|
||||||
|
label3.Location = new Point(15, 82);
|
||||||
|
label3.Name = "label3";
|
||||||
|
label3.Size = new Size(103, 20);
|
||||||
|
label3.TabIndex = 10;
|
||||||
|
label3.Text = "В количестве:";
|
||||||
|
//
|
||||||
|
// countNumeric
|
||||||
|
//
|
||||||
|
countNumeric.Location = new Point(155, 80);
|
||||||
|
countNumeric.Name = "countNumeric";
|
||||||
|
countNumeric.Size = new Size(99, 27);
|
||||||
|
countNumeric.TabIndex = 9;
|
||||||
|
countNumeric.ThousandsSeparator = true;
|
||||||
|
//
|
||||||
|
// WarehouseCombobox
|
||||||
|
//
|
||||||
|
WarehouseCombobox.FormattingEnabled = true;
|
||||||
|
WarehouseCombobox.Location = new Point(155, 46);
|
||||||
|
WarehouseCombobox.Name = "WarehouseCombobox";
|
||||||
|
WarehouseCombobox.Size = new Size(151, 28);
|
||||||
|
WarehouseCombobox.TabIndex = 14;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(15, 49);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(81, 20);
|
||||||
|
label1.TabIndex = 13;
|
||||||
|
label1.Text = "На складе:";
|
||||||
|
//
|
||||||
|
// saveButton
|
||||||
|
//
|
||||||
|
saveButton.Anchor = AnchorStyles.Bottom;
|
||||||
|
saveButton.Location = new Point(155, 175);
|
||||||
|
saveButton.Name = "saveButton";
|
||||||
|
saveButton.Size = new Size(94, 29);
|
||||||
|
saveButton.TabIndex = 15;
|
||||||
|
saveButton.Text = "Сохранить";
|
||||||
|
saveButton.UseVisualStyleBackColor = true;
|
||||||
|
saveButton.Click += saveButton_Click;
|
||||||
|
//
|
||||||
|
// ProductsOnWarehouseSettingsForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(411, 216);
|
||||||
|
Controls.Add(saveButton);
|
||||||
|
Controls.Add(WarehouseCombobox);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Controls.Add(productCombobox);
|
||||||
|
Controls.Add(label4);
|
||||||
|
Controls.Add(label3);
|
||||||
|
Controls.Add(countNumeric);
|
||||||
|
Name = "ProductsOnWarehouseSettingsForm";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Продукт на складе...";
|
||||||
|
Load += ProductsOnWarehouseSettingsForm_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)countNumeric).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private ComboBox productCombobox;
|
||||||
|
private Label label4;
|
||||||
|
private Label label3;
|
||||||
|
private NumericUpDown countNumeric;
|
||||||
|
private ComboBox WarehouseCombobox;
|
||||||
|
private Label label1;
|
||||||
|
private Button saveButton;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
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 ProjectSellPC.Forms.ProductsOnWarehouse
|
||||||
|
{
|
||||||
|
public partial class ProductsOnWarehouseSettingsForm : Form
|
||||||
|
{
|
||||||
|
private readonly IProductOnWarehouseRepository _productOnWarehouseRepository;
|
||||||
|
private readonly IProductRepository _productRepository;
|
||||||
|
private readonly IWarehouseRepository _WarehouseRepository;
|
||||||
|
|
||||||
|
private int? _recordId;
|
||||||
|
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var record = _productOnWarehouseRepository.Read(value);
|
||||||
|
if (record == null)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException("Record not found");
|
||||||
|
}
|
||||||
|
//ProductComboBox
|
||||||
|
foreach (var item in _productRepository.ReadAll())
|
||||||
|
{
|
||||||
|
if (item.ID == record.ProductId)
|
||||||
|
{
|
||||||
|
productCombobox.SelectedItem = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//WarehouseCombobox
|
||||||
|
foreach (var item in _WarehouseRepository.ReadAll())
|
||||||
|
{
|
||||||
|
if (item.Id == record.WarehouseId)
|
||||||
|
{
|
||||||
|
WarehouseCombobox.SelectedItem = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
countNumeric.Value = record.Count;
|
||||||
|
_recordId = value;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductsOnWarehouseSettingsForm(
|
||||||
|
IProductOnWarehouseRepository productOnWarehouseRepository,
|
||||||
|
IProductRepository productRepository,
|
||||||
|
IWarehouseRepository WarehouseRepository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_productOnWarehouseRepository = productOnWarehouseRepository ?? throw new ArgumentNullException(nameof(productOnWarehouseRepository));
|
||||||
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
|
||||||
|
_WarehouseRepository = WarehouseRepository ?? throw new ArgumentNullException(nameof(WarehouseRepository));
|
||||||
|
|
||||||
|
LoadComboboxes();
|
||||||
|
}
|
||||||
|
private void ProductsOnWarehouseSettingsForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
private void LoadComboboxes()
|
||||||
|
{
|
||||||
|
productCombobox.DataSource = _productRepository.ReadAll().ToList();
|
||||||
|
productCombobox.DisplayMember = "Name";
|
||||||
|
productCombobox.ValueMember = "Id";
|
||||||
|
|
||||||
|
WarehouseCombobox.DataSource = _WarehouseRepository.ReadAll().ToList();
|
||||||
|
WarehouseCombobox.DisplayMember = "Adress";
|
||||||
|
//WarehouseCombobox.ValueMember = "Id";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (productCombobox.SelectedItem == null || WarehouseCombobox.SelectedItem == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Заполните все поля");
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedProduct = (Product)productCombobox.SelectedItem;
|
||||||
|
var selectedWarehouse = (Entites.Warehouse)WarehouseCombobox.SelectedItem;
|
||||||
|
var count = (int)countNumeric.Value;
|
||||||
|
_productOnWarehouseRepository.Create(CreateProductOnWarehouse(0, selectedProduct, selectedWarehouse, count));
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Entites.ProductsOnWarehouse CreateProductOnWarehouse(int id, Product product, Entites.Warehouse Warehouse, int count)
|
||||||
|
{
|
||||||
|
return Entites.ProductsOnWarehouse.CreateEntity(id, product, Warehouse, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
103
ProjectSellPC/ProjectSellPC/Forms/Warehouse/WarehouseForm.Designer.cs
generated
Normal file
103
ProjectSellPC/ProjectSellPC/Forms/Warehouse/WarehouseForm.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
namespace ProjectSellPC.Forms.Warehouse
|
||||||
|
{
|
||||||
|
partial class WarehouseForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
deleteButton = new Button();
|
||||||
|
editButton = new Button();
|
||||||
|
addButton = new Button();
|
||||||
|
WarehousesDataGridView = new DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)WarehousesDataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// deleteButton
|
||||||
|
//
|
||||||
|
deleteButton.Location = new Point(869, 144);
|
||||||
|
deleteButton.Name = "deleteButton";
|
||||||
|
deleteButton.Size = new Size(161, 60);
|
||||||
|
deleteButton.TabIndex = 11;
|
||||||
|
deleteButton.Text = "Удалить";
|
||||||
|
deleteButton.UseVisualStyleBackColor = true;
|
||||||
|
deleteButton.Click += deleteButton_Click;
|
||||||
|
//
|
||||||
|
// editButton
|
||||||
|
//
|
||||||
|
editButton.Location = new Point(869, 78);
|
||||||
|
editButton.Name = "editButton";
|
||||||
|
editButton.Size = new Size(161, 60);
|
||||||
|
editButton.TabIndex = 10;
|
||||||
|
editButton.Text = "Редактировать";
|
||||||
|
editButton.UseVisualStyleBackColor = true;
|
||||||
|
editButton.Click += editButton_Click;
|
||||||
|
//
|
||||||
|
// addButton
|
||||||
|
//
|
||||||
|
addButton.BackColor = SystemColors.Control;
|
||||||
|
addButton.Location = new Point(869, 12);
|
||||||
|
addButton.Name = "addButton";
|
||||||
|
addButton.Size = new Size(161, 60);
|
||||||
|
addButton.TabIndex = 9;
|
||||||
|
addButton.Text = "Добавить";
|
||||||
|
addButton.UseVisualStyleBackColor = false;
|
||||||
|
addButton.Click += addButton_Click;
|
||||||
|
//
|
||||||
|
// WarehousesDataGridView
|
||||||
|
//
|
||||||
|
WarehousesDataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
WarehousesDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
WarehousesDataGridView.Location = new Point(12, 12);
|
||||||
|
WarehousesDataGridView.Name = "WarehousesDataGridView";
|
||||||
|
WarehousesDataGridView.RowHeadersWidth = 51;
|
||||||
|
WarehousesDataGridView.Size = new Size(851, 416);
|
||||||
|
WarehousesDataGridView.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// WarehouseForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1058, 440);
|
||||||
|
Controls.Add(deleteButton);
|
||||||
|
Controls.Add(editButton);
|
||||||
|
Controls.Add(addButton);
|
||||||
|
Controls.Add(WarehousesDataGridView);
|
||||||
|
Name = "WarehouseForm";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Склады";
|
||||||
|
Load += WarehouseForm_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)WarehousesDataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button deleteButton;
|
||||||
|
private Button editButton;
|
||||||
|
private Button addButton;
|
||||||
|
private DataGridView WarehousesDataGridView;
|
||||||
|
}
|
||||||
|
}
|
111
ProjectSellPC/ProjectSellPC/Forms/Warehouse/WarehouseForm.cs
Normal file
111
ProjectSellPC/ProjectSellPC/Forms/Warehouse/WarehouseForm.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using ProjectSellPC.Forms.Clients;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using Unity;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Forms.Warehouse
|
||||||
|
{
|
||||||
|
public partial class WarehouseForm : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
private readonly IWarehouseRepository _repository;
|
||||||
|
|
||||||
|
public WarehouseForm(IUnityContainer unityContainer, IWarehouseRepository repository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_container = unityContainer ?? throw new ArgumentNullException(nameof(unityContainer));
|
||||||
|
_repository = repository ?? throw new ArgumentNullException(nameof(_repository));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WarehouseForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadList() => WarehousesDataGridView.DataSource = _repository.ReadAll();
|
||||||
|
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (WarehousesDataGridView.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = Convert.ToInt32(WarehousesDataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_container.Resolve<WarehouseSettingsForm>().ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void editButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = _container.Resolve<WarehouseSettingsForm>();
|
||||||
|
form.Id = findId;
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_repository.Delete(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectSellPC/ProjectSellPC/Forms/Warehouse/WarehouseForm.resx
Normal file
120
ProjectSellPC/ProjectSellPC/Forms/Warehouse/WarehouseForm.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
110
ProjectSellPC/ProjectSellPC/Forms/Warehouse/WarehouseSettingsForm.Designer.cs
generated
Normal file
110
ProjectSellPC/ProjectSellPC/Forms/Warehouse/WarehouseSettingsForm.Designer.cs
generated
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
namespace ProjectSellPC.Forms.Warehouse
|
||||||
|
{
|
||||||
|
partial class WarehouseSettingsForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
label3 = new Label();
|
||||||
|
sizeNumeric = new NumericUpDown();
|
||||||
|
label1 = new Label();
|
||||||
|
adressTextbox = new TextBox();
|
||||||
|
saveButton = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)sizeNumeric).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// label3
|
||||||
|
//
|
||||||
|
label3.AutoSize = true;
|
||||||
|
label3.Location = new Point(12, 67);
|
||||||
|
label3.Name = "label3";
|
||||||
|
label3.Size = new Size(100, 20);
|
||||||
|
label3.TabIndex = 11;
|
||||||
|
label3.Text = "Вместимость";
|
||||||
|
//
|
||||||
|
// sizeNumeric
|
||||||
|
//
|
||||||
|
sizeNumeric.Location = new Point(119, 65);
|
||||||
|
sizeNumeric.Name = "sizeNumeric";
|
||||||
|
sizeNumeric.Size = new Size(99, 27);
|
||||||
|
sizeNumeric.TabIndex = 10;
|
||||||
|
sizeNumeric.ThousandsSeparator = true;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(12, 22);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(104, 20);
|
||||||
|
label1.TabIndex = 9;
|
||||||
|
label1.Text = "Адрес склада:";
|
||||||
|
//
|
||||||
|
// adressTextbox
|
||||||
|
//
|
||||||
|
adressTextbox.Location = new Point(119, 19);
|
||||||
|
adressTextbox.Name = "adressTextbox";
|
||||||
|
adressTextbox.Size = new Size(210, 27);
|
||||||
|
adressTextbox.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// saveButton
|
||||||
|
//
|
||||||
|
saveButton.Anchor = AnchorStyles.Bottom;
|
||||||
|
saveButton.Location = new Point(129, 117);
|
||||||
|
saveButton.Name = "saveButton";
|
||||||
|
saveButton.Size = new Size(94, 29);
|
||||||
|
saveButton.TabIndex = 7;
|
||||||
|
saveButton.Text = "Сохранить";
|
||||||
|
saveButton.UseVisualStyleBackColor = true;
|
||||||
|
saveButton.Click += saveButton_Click;
|
||||||
|
//
|
||||||
|
// WarehouseSettingsForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(364, 158);
|
||||||
|
Controls.Add(label3);
|
||||||
|
Controls.Add(sizeNumeric);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Controls.Add(adressTextbox);
|
||||||
|
Controls.Add(saveButton);
|
||||||
|
Name = "WarehouseSettingsForm";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Настройки склада";
|
||||||
|
Load += WarehouseFormSettings_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)sizeNumeric).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label label3;
|
||||||
|
private NumericUpDown sizeNumeric;
|
||||||
|
private Label label1;
|
||||||
|
private TextBox adressTextbox;
|
||||||
|
private Button saveButton;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
using ProjectSellPC.Entites.Enums;
|
||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Forms.Warehouse
|
||||||
|
{
|
||||||
|
public partial class WarehouseSettingsForm : Form
|
||||||
|
{
|
||||||
|
private readonly IWarehouseRepository _repository;
|
||||||
|
|
||||||
|
private int? _WarehouseID;
|
||||||
|
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var Warehouse = _repository.Read(value);
|
||||||
|
if (Warehouse == null)
|
||||||
|
{
|
||||||
|
throw new InvalidDataException(nameof(Warehouse));
|
||||||
|
}
|
||||||
|
adressTextbox.Text = Warehouse.Adress;
|
||||||
|
sizeNumeric.Value = Warehouse.Size;
|
||||||
|
_WarehouseID = value;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public WarehouseSettingsForm(IWarehouseRepository repository)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WarehouseFormSettings_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(adressTextbox.Text))
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_WarehouseID.HasValue)
|
||||||
|
{
|
||||||
|
|
||||||
|
_repository.Update(CreateWarehouse(_WarehouseID.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
_repository.Create(CreateWarehouse(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Entites.Warehouse CreateWarehouse(int id)
|
||||||
|
{
|
||||||
|
return Entites.Warehouse.CreateEntity(id, (int)sizeNumeric.Value, adressTextbox.Text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
@ -1,3 +1,11 @@
|
|||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using ProjectSellPC.Repos.Impements;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Unity;
|
||||||
|
using Unity.Lifetime;
|
||||||
|
using Serilog;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace ProjectSellPC
|
namespace ProjectSellPC
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -8,10 +16,36 @@ namespace ProjectSellPC
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new Form1());
|
Application.Run(CreateContainer().Resolve<ShopForm>());
|
||||||
|
}
|
||||||
|
private static IUnityContainer CreateContainer()
|
||||||
|
{
|
||||||
|
var container = new UnityContainer();
|
||||||
|
|
||||||
|
container.RegisterInstance<ILoggerFactory>(CreateLoggerFactory());
|
||||||
|
|
||||||
|
container.RegisterType<IConnectionString, ConnectionString>(new SingletonLifetimeManager());
|
||||||
|
|
||||||
|
container.RegisterType<IProductRepository, ProductRepo>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<IClientRepository, ClientRepo>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<IWarehouseRepository, WarehouseRepo>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<IProductOnWarehouseRepository, ProductsOnWarehouseRepo>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<IProductInChequeRepository, ProductInChequeRepo>(new TransientLifetimeManager());
|
||||||
|
container.RegisterType<IChequeRepository, ChequeRepo>(new TransientLifetimeManager());
|
||||||
|
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
private static LoggerFactory CreateLoggerFactory()
|
||||||
|
{
|
||||||
|
var loggerFactory = new LoggerFactory();
|
||||||
|
loggerFactory.AddSerilog(new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json")
|
||||||
|
.Build())
|
||||||
|
.CreateLogger());
|
||||||
|
return loggerFactory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,4 +8,25 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||||
|
<PackageReference Include="DocumentFormat.OpenXml" Version="3.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Npgsql" Version="9.0.2" />
|
||||||
|
<PackageReference Include="PDFsharp-MigraDoc" Version="6.1.1" />
|
||||||
|
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Unity" Version="5.11.10" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
63
ProjectSellPC/ProjectSellPC/Properties/Resources.Designer.cs
generated
Normal file
63
ProjectSellPC/ProjectSellPC/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код создан программой.
|
||||||
|
// Исполняемая версия:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||||
|
// повторной генерации кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||||
|
/// </summary>
|
||||||
|
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||||
|
// с помощью такого средства, как ResGen или Visual Studio.
|
||||||
|
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||||
|
// с параметром /str или перестройте свой проект VS.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
internal class Resources {
|
||||||
|
|
||||||
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
|
internal Resources() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
|
get {
|
||||||
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectSellPC.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||||
|
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get {
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
ProjectSellPC/ProjectSellPC/Properties/Resources.resx
Normal file
120
ProjectSellPC/ProjectSellPC/Properties/Resources.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
64
ProjectSellPC/ProjectSellPC/Reports/ChartReport.cs
Normal file
64
ProjectSellPC/ProjectSellPC/Reports/ChartReport.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Reflection.PortableExecutable;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.DocBuilder
|
||||||
|
{
|
||||||
|
internal class ChartReport
|
||||||
|
{
|
||||||
|
private readonly IChequeRepository _chequeRepository; // Репозиторий для получения данных о чеках
|
||||||
|
private readonly IProductRepository _productRepository; // Репозиторий для получения данных о продуктах
|
||||||
|
private readonly ILogger<ChartReport> _logger;
|
||||||
|
|
||||||
|
public ChartReport(IChequeRepository checkRepository, IProductRepository productRepository, ILoggerFactory loggerFactory)
|
||||||
|
{
|
||||||
|
_chequeRepository = checkRepository ?? throw new ArgumentNullException(nameof(checkRepository));
|
||||||
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
|
||||||
|
_logger = loggerFactory.CreateLogger<ChartReport>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CreateChart(string filePath, DateTime dateTime)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
new PdfBuilder(filePath)
|
||||||
|
.AddHeader("Отчет по продажам товаров")
|
||||||
|
.AddPieChart("Проданные товары", GetData(dateTime)) // Диаграмма с продуктами
|
||||||
|
.AddDate(dateTime) // Добавляем дату создания отчёта
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||||
|
{
|
||||||
|
// Получаем все чеки, которые были оформлены в указанную дату
|
||||||
|
var checkData = _chequeRepository
|
||||||
|
.ReadAll()
|
||||||
|
.Where(x => x.PurchaseDate.Date == dateTime.Date) // Фильтрация по дате
|
||||||
|
.SelectMany(x => x.Products) // Получаем все продукты из всех чеков
|
||||||
|
.GroupBy(p => p.ProductID) // Группируем по ID продукта
|
||||||
|
.Select(g =>
|
||||||
|
{
|
||||||
|
// Получаем продукт по ProductID
|
||||||
|
var product = _productRepository.Read(g.Key);
|
||||||
|
return (Caption: product.Name, Value: (double)g.Sum(p => p.Count)); // Преобразуем Count в double
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return checkData;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
94
ProjectSellPC/ProjectSellPC/Reports/DocReport.cs
Normal file
94
ProjectSellPC/ProjectSellPC/Reports/DocReport.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using ProjectSellPC.DocBuilder;
|
||||||
|
using ProjectSellPC.Repos.Impements;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.DocumentsBuilder
|
||||||
|
{
|
||||||
|
internal class DocReport
|
||||||
|
{
|
||||||
|
private readonly IClientRepository _clientRepository;
|
||||||
|
|
||||||
|
private readonly IProductRepository _productRepository;
|
||||||
|
|
||||||
|
private readonly IWarehouseRepository _warehouseRepository;
|
||||||
|
|
||||||
|
private readonly ILogger<DocReport> _logger;
|
||||||
|
|
||||||
|
public DocReport(IClientRepository clientRepository, IProductRepository productRepository, IWarehouseRepository warehouseRepository, ILoggerFactory loggerFactory)
|
||||||
|
{
|
||||||
|
_clientRepository = clientRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(clientRepository));
|
||||||
|
_productRepository = productRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(productRepository));
|
||||||
|
_warehouseRepository = warehouseRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(warehouseRepository));
|
||||||
|
_logger = loggerFactory.CreateLogger<DocReport>();
|
||||||
|
}
|
||||||
|
public bool CreateDoc(string filePath, bool includeClients, bool includeProducts, bool includeStorage)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var builder = new WordBuilder(filePath)
|
||||||
|
.AddHeader("Документ со справочниками");
|
||||||
|
|
||||||
|
if (includeClients)
|
||||||
|
{
|
||||||
|
builder.AddParagraph("Клиенты")
|
||||||
|
.AddTable(new int[] { 2400, 2400, 3200, 1200 }, GetClients());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeProducts)
|
||||||
|
{
|
||||||
|
builder.AddParagraph("Товары")
|
||||||
|
.AddTable(new int[] { 2400, 2400, 2400, 2400, 2400 }, GetProducts());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeStorage)
|
||||||
|
{
|
||||||
|
builder.AddParagraph("Склады")
|
||||||
|
.AddTable(new int[] { 2400, 2400, 1200 }, GetStorage());
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.Build();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<string[]> GetClients()
|
||||||
|
{
|
||||||
|
List<string[]> result = _clientRepository.ReadAll().Select(x => new string[] { x.Id.ToString(), x.Name, x.PhoneNumber, x.ClientType.ToString() }).ToList();
|
||||||
|
|
||||||
|
result.Insert(0, new string[] { "ID", "Имя", "Номер телефона", "Тип клиента" });
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private List<string[]> GetProducts()
|
||||||
|
{
|
||||||
|
List<string[]> result = _productRepository.ReadAll().Select(x => new string[] { x.ID.ToString(), x.Name, x.Description, x.ProductType.ToString(), x.Price.ToString() + " р." }).ToList();
|
||||||
|
|
||||||
|
result.Insert(0, new string[] { "ID", "Имя", "Описание", "Тип товара", "Цена" });
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private List<string[]> GetStorage()
|
||||||
|
{
|
||||||
|
List<string[]> result = _warehouseRepository.ReadAll().Select(x => new string[] { x.Id.ToString(), x.Adress, x.Size.ToString()}).ToList();
|
||||||
|
|
||||||
|
result.Insert(0, new string[] { "ID", "Адрес", "Вместимость"});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
256
ProjectSellPC/ProjectSellPC/Reports/ExcelBuilder.cs
Normal file
256
ProjectSellPC/ProjectSellPC/Reports/ExcelBuilder.cs
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
using DocumentFormat.OpenXml.Packaging;
|
||||||
|
using DocumentFormat.OpenXml.Spreadsheet;
|
||||||
|
using DocumentFormat.OpenXml;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.DocBuilder
|
||||||
|
{
|
||||||
|
internal class ExcelBuilder
|
||||||
|
{
|
||||||
|
private readonly string _filePath;
|
||||||
|
private readonly SheetData _sheetData;
|
||||||
|
private readonly MergeCells _mergeCells;
|
||||||
|
private readonly Columns _columns;
|
||||||
|
private uint _rowIndex = 0;
|
||||||
|
|
||||||
|
public ExcelBuilder(string filePath)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(filePath))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(filePath));
|
||||||
|
}
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
{
|
||||||
|
File.Delete(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
_filePath = filePath;
|
||||||
|
_sheetData = new SheetData();
|
||||||
|
_mergeCells = new MergeCells();
|
||||||
|
_columns = new Columns();
|
||||||
|
_rowIndex = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExcelBuilder AddHeader(string header, int startIndex, int count)
|
||||||
|
{
|
||||||
|
CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithBorders);
|
||||||
|
for (int i = startIndex + 1; i < startIndex + count; ++i)
|
||||||
|
{
|
||||||
|
CreateCell(i, _rowIndex, "", StyleIndex.BoldTextWithBorders);
|
||||||
|
}
|
||||||
|
|
||||||
|
_mergeCells.Append(new MergeCell()
|
||||||
|
{
|
||||||
|
Reference = new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}")
|
||||||
|
});
|
||||||
|
|
||||||
|
_rowIndex++;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExcelBuilder AddParagraph(string text, int columnIndex)
|
||||||
|
{
|
||||||
|
CreateCell(columnIndex, _rowIndex++, text, StyleIndex.SimpleTextWithBorders);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExcelBuilder AddTable(int[] columnsWidths, List<string[]> data)
|
||||||
|
{
|
||||||
|
if (columnsWidths == null || columnsWidths.Length == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(columnsWidths));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data == null || data.Count == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.Any(x => x.Length != columnsWidths.Length))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("widths.Length != data.Length");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint counter = 1;
|
||||||
|
int coef = 2;
|
||||||
|
_columns.Append(columnsWidths.Select(x => new Column
|
||||||
|
{
|
||||||
|
Min = counter,
|
||||||
|
Max = counter++,
|
||||||
|
Width = x * coef,
|
||||||
|
CustomWidth = true
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Добавляем строки таблицы
|
||||||
|
for (int i = 0; i < data.Count; ++i)
|
||||||
|
{
|
||||||
|
var isBoldRow = i == 0 || i == data.Count - 1; // Только заголовок и последняя строка жирные
|
||||||
|
var styleIndex = isBoldRow ? StyleIndex.BoldTextWithBorders : StyleIndex.SimpleTextWithBorders;
|
||||||
|
|
||||||
|
for (int j = 0; j < data[i].Length; ++j)
|
||||||
|
{
|
||||||
|
CreateCell(j, _rowIndex, data[i][j], styleIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
_rowIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum StyleIndex
|
||||||
|
{
|
||||||
|
SimpleTextWithoutBorder = 0,
|
||||||
|
BoldText = 1,
|
||||||
|
SimpleTextWithBorders = 2,
|
||||||
|
BoldTextWithBorders = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Build()
|
||||||
|
{
|
||||||
|
using var spreadsheetDocument = SpreadsheetDocument.Create(_filePath, SpreadsheetDocumentType.Workbook);
|
||||||
|
var workbookpart = spreadsheetDocument.AddWorkbookPart();
|
||||||
|
GenerateStyle(workbookpart);
|
||||||
|
workbookpart.Workbook = new Workbook();
|
||||||
|
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||||
|
worksheetPart.Worksheet = new Worksheet();
|
||||||
|
if (_columns.HasChildren)
|
||||||
|
{
|
||||||
|
worksheetPart.Worksheet.Append(_columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
worksheetPart.Worksheet.Append(_sheetData);
|
||||||
|
var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets());
|
||||||
|
var sheet = new Sheet()
|
||||||
|
{
|
||||||
|
Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
|
||||||
|
SheetId = 1,
|
||||||
|
Name = "Лист 1"
|
||||||
|
};
|
||||||
|
|
||||||
|
sheets.Append(sheet);
|
||||||
|
if (_mergeCells.HasChildren)
|
||||||
|
{
|
||||||
|
worksheetPart.Worksheet.InsertAfter(_mergeCells, worksheetPart.Worksheet.Elements<SheetData>().First());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GenerateStyle(WorkbookPart workbookPart)
|
||||||
|
{
|
||||||
|
var workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>();
|
||||||
|
workbookStylesPart.Stylesheet = new Stylesheet();
|
||||||
|
|
||||||
|
// Шрифты
|
||||||
|
var fonts = new Fonts() { Count = 2 };
|
||||||
|
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
|
||||||
|
{
|
||||||
|
FontSize = new FontSize() { Val = 11 },
|
||||||
|
FontName = new FontName() { Val = "Calibri" }
|
||||||
|
});
|
||||||
|
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
|
||||||
|
{
|
||||||
|
Bold = new Bold(),
|
||||||
|
FontSize = new FontSize() { Val = 11 },
|
||||||
|
FontName = new FontName() { Val = "Calibri" }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Заполнение
|
||||||
|
var fills = new Fills() { Count = 1 };
|
||||||
|
fills.Append(new Fill
|
||||||
|
{
|
||||||
|
PatternFill = new PatternFill { PatternType = PatternValues.None }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Границы
|
||||||
|
var borders = new Borders() { Count = 2 };
|
||||||
|
borders.Append(new Border()); // Без границ
|
||||||
|
borders.Append(new Border
|
||||||
|
{
|
||||||
|
LeftBorder = new LeftBorder { Style = BorderStyleValues.Thin },
|
||||||
|
RightBorder = new RightBorder { Style = BorderStyleValues.Thin },
|
||||||
|
TopBorder = new TopBorder { Style = BorderStyleValues.Thin },
|
||||||
|
BottomBorder = new BottomBorder { Style = BorderStyleValues.Thin }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Форматы ячеек
|
||||||
|
var cellFormats = new CellFormats() { Count = 4 };
|
||||||
|
cellFormats.Append(new CellFormat
|
||||||
|
{
|
||||||
|
FontId = 0,
|
||||||
|
FillId = 0,
|
||||||
|
BorderId = 0,
|
||||||
|
ApplyFont = true
|
||||||
|
}); // Обычный текст без границ
|
||||||
|
cellFormats.Append(new CellFormat
|
||||||
|
{
|
||||||
|
FontId = 1,
|
||||||
|
FillId = 0,
|
||||||
|
BorderId = 0,
|
||||||
|
ApplyFont = true
|
||||||
|
}); // Жирный текст без границ
|
||||||
|
cellFormats.Append(new CellFormat
|
||||||
|
{
|
||||||
|
FontId = 0,
|
||||||
|
FillId = 0,
|
||||||
|
BorderId = 1,
|
||||||
|
ApplyFont = true,
|
||||||
|
ApplyBorder = true
|
||||||
|
}); // Обычный текст с границами
|
||||||
|
cellFormats.Append(new CellFormat
|
||||||
|
{
|
||||||
|
FontId = 1,
|
||||||
|
FillId = 0,
|
||||||
|
BorderId = 1,
|
||||||
|
ApplyFont = true,
|
||||||
|
ApplyBorder = true
|
||||||
|
}); // Жирный текст с границами
|
||||||
|
|
||||||
|
workbookStylesPart.Stylesheet.Append(fonts);
|
||||||
|
workbookStylesPart.Stylesheet.Append(fills);
|
||||||
|
workbookStylesPart.Stylesheet.Append(borders);
|
||||||
|
workbookStylesPart.Stylesheet.Append(cellFormats);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void CreateCell(int columnIndex, uint rowIndex, string text, StyleIndex styleIndex)
|
||||||
|
{
|
||||||
|
var columnName = GetExcelColumnName(columnIndex);
|
||||||
|
var cellReference = columnName + rowIndex;
|
||||||
|
|
||||||
|
var row = _sheetData.Elements<Row>().FirstOrDefault(r => r.RowIndex == rowIndex);
|
||||||
|
if (row == null)
|
||||||
|
{
|
||||||
|
row = new Row() { RowIndex = rowIndex };
|
||||||
|
_sheetData.Append(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
var cell = new Cell
|
||||||
|
{
|
||||||
|
CellReference = cellReference,
|
||||||
|
StyleIndex = (UInt32Value)(uint)styleIndex,
|
||||||
|
CellValue = new CellValue(text),
|
||||||
|
DataType = new EnumValue<CellValues>(CellValues.String)
|
||||||
|
};
|
||||||
|
|
||||||
|
row.Append(cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetExcelColumnName(int index)
|
||||||
|
{
|
||||||
|
int div = index;
|
||||||
|
string columnName = string.Empty;
|
||||||
|
while (div >= 0)
|
||||||
|
{
|
||||||
|
columnName = (char)(div % 26 + 65) + columnName;
|
||||||
|
div = div / 26 - 1;
|
||||||
|
}
|
||||||
|
return columnName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
113
ProjectSellPC/ProjectSellPC/Reports/PdfBuilder.cs
Normal file
113
ProjectSellPC/ProjectSellPC/Reports/PdfBuilder.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
using MigraDoc.DocumentObjectModel;
|
||||||
|
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||||
|
using MigraDoc.Rendering;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Chart = MigraDoc.DocumentObjectModel.Shapes.Charts.Chart;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.DocBuilder
|
||||||
|
{
|
||||||
|
internal class PdfBuilder
|
||||||
|
{
|
||||||
|
private readonly string _filePath;
|
||||||
|
|
||||||
|
private readonly Document _document;
|
||||||
|
|
||||||
|
public PdfBuilder(string filePath)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(filePath))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
{
|
||||||
|
File.Delete(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
_filePath = filePath;
|
||||||
|
_document = new Document();
|
||||||
|
DefineStyles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PdfBuilder AddHeader(string header)
|
||||||
|
{
|
||||||
|
_document.AddSection().AddParagraph(header, "NormalBold");
|
||||||
|
return this;//подпись, число
|
||||||
|
}
|
||||||
|
public PdfBuilder AddDate(DateTime date)
|
||||||
|
{
|
||||||
|
var paragraph = _document.LastSection.AddParagraph();
|
||||||
|
paragraph.AddText("Дата создания отчёта: ");
|
||||||
|
paragraph.AddText(date.ToString("dd.MM.yyyy")); // Форматируем дату в строку
|
||||||
|
paragraph.Format.Alignment = ParagraphAlignment.Right; // Выравнивание по правому краю
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public PdfBuilder AddPieChart(string title, List<(string Caption, double
|
||||||
|
Value)> data)
|
||||||
|
{
|
||||||
|
if (data == null || data.Count == 0)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
var chart = new Chart(ChartType.Pie2D);
|
||||||
|
var series = chart.SeriesCollection.AddSeries();
|
||||||
|
series.Add(data.Select(x => x.Value).ToArray());
|
||||||
|
|
||||||
|
var xseries = chart.XValues.AddXSeries();
|
||||||
|
xseries.Add(data.Select(x => x.Caption).ToArray());
|
||||||
|
|
||||||
|
chart.DataLabel.Type = DataLabelType.Percent;
|
||||||
|
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
|
||||||
|
|
||||||
|
chart.Width = Unit.FromCentimeter(16);
|
||||||
|
chart.Height = Unit.FromCentimeter(12);
|
||||||
|
|
||||||
|
chart.TopArea.AddParagraph(title);
|
||||||
|
|
||||||
|
chart.XAxis.MajorTickMark = TickMarkType.Outside;
|
||||||
|
|
||||||
|
chart.YAxis.MajorTickMark = TickMarkType.Outside;
|
||||||
|
chart.YAxis.HasMajorGridlines = true;
|
||||||
|
|
||||||
|
chart.PlotArea.LineFormat.Width = 1;
|
||||||
|
chart.PlotArea.LineFormat.Visible = true;
|
||||||
|
|
||||||
|
chart.TopArea.AddLegend();
|
||||||
|
|
||||||
|
_document.LastSection.Add(chart);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Build()
|
||||||
|
{
|
||||||
|
var renderer = new PdfDocumentRenderer(true)
|
||||||
|
{
|
||||||
|
Document = _document
|
||||||
|
};
|
||||||
|
|
||||||
|
renderer.RenderDocument();
|
||||||
|
renderer.PdfDocument.Save(_filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DefineStyles()
|
||||||
|
{
|
||||||
|
// Получаем стандартный стиль Normal
|
||||||
|
var normalStyle = _document.Styles["Normal"];
|
||||||
|
normalStyle.Font.Name = "Arial";
|
||||||
|
normalStyle.Font.Size = 12;
|
||||||
|
|
||||||
|
// Создаем стиль для жирного заголовка
|
||||||
|
var boldStyle = _document.Styles.AddStyle("NormalBold", "Normal");
|
||||||
|
boldStyle.Font.Bold = true;
|
||||||
|
boldStyle.Font.Size = 14; // Например, чуть больше стандартного текста
|
||||||
|
boldStyle.ParagraphFormat.Alignment = ParagraphAlignment.Center; // Опционально, выравнивание по центру
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
40
ProjectSellPC/ProjectSellPC/Reports/QueryBuilder.cs
Normal file
40
ProjectSellPC/ProjectSellPC/Reports/QueryBuilder.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Reports
|
||||||
|
{
|
||||||
|
public class QueryBuilder
|
||||||
|
{
|
||||||
|
private readonly StringBuilder _builder;
|
||||||
|
|
||||||
|
public QueryBuilder()
|
||||||
|
{
|
||||||
|
_builder = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryBuilder AddCondition(string condition)
|
||||||
|
{
|
||||||
|
if (_builder.Length > 0)
|
||||||
|
{
|
||||||
|
_builder.Append(" AND ");
|
||||||
|
}
|
||||||
|
|
||||||
|
_builder.Append(condition);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Build()
|
||||||
|
{
|
||||||
|
if (_builder.Length == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"WHERE {_builder}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
96
ProjectSellPC/ProjectSellPC/Reports/TableReport.cs
Normal file
96
ProjectSellPC/ProjectSellPC/Reports/TableReport.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.DocBuilder
|
||||||
|
{
|
||||||
|
internal class TableReport
|
||||||
|
{
|
||||||
|
private readonly IChequeRepository _chequeRepository;
|
||||||
|
private readonly IClientRepository _clientRepository;
|
||||||
|
private readonly IProductInChequeRepository _productInChequeRepository;
|
||||||
|
private readonly ILogger<TableReport> _logger;
|
||||||
|
|
||||||
|
internal static readonly string[] Headers = { "Клиент", "Дата", "Количество" };
|
||||||
|
|
||||||
|
public TableReport(IChequeRepository chequeRepository, IClientRepository clientRepository, IProductInChequeRepository productInChequeRepository, ILoggerFactory loggerFactory)
|
||||||
|
{
|
||||||
|
_chequeRepository = chequeRepository ?? throw new ArgumentNullException(nameof(chequeRepository));
|
||||||
|
_clientRepository = clientRepository ?? throw new ArgumentNullException(nameof(clientRepository));
|
||||||
|
_productInChequeRepository = productInChequeRepository ?? throw new ArgumentNullException(nameof(productInChequeRepository));
|
||||||
|
_logger = loggerFactory.CreateLogger<TableReport>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CreateTable(string filePath, int productId, DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
new ExcelBuilder(filePath)
|
||||||
|
.AddHeader("Отчет по продажам товара", 0, 3)
|
||||||
|
.AddParagraph($"за период с {startDate.ToShortDateString()} по {endDate.ToShortDateString()}", 0)
|
||||||
|
.AddTable(new[] { 20, 20, 15 }, GetData(productId, startDate, endDate))
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при формировании отчета");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private List<string[]> GetData(int productId, DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
// Получение данных о товарах в чеках, содержащих указанный товар
|
||||||
|
var productsInChecks = _productInChequeRepository.ReadAll()
|
||||||
|
.Where(p => p.ProductID == productId) // Фильтр по товару
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
// Получение данных о чеках, содержащих указанный товар
|
||||||
|
var checksWithProduct = _chequeRepository
|
||||||
|
.ReadAll()
|
||||||
|
.Where(c => c.PurchaseDate >= startDate && c.PurchaseDate <= endDate
|
||||||
|
&& c.Products.Any(p => p.ProductID == productId))
|
||||||
|
.Select(c => new
|
||||||
|
{
|
||||||
|
CheckId = c.Id, // Номер чека
|
||||||
|
ClientId = c.Client?.Id ?? 0, // Получаем ClientId или 0, если клиент неизвестен
|
||||||
|
Date = c.PurchaseDate,
|
||||||
|
Quantity = c.Products
|
||||||
|
.Where(p => p.ProductID == productId)
|
||||||
|
.Sum(p => p.Count)
|
||||||
|
})
|
||||||
|
.OrderBy(x => x.Date)
|
||||||
|
.ToList(); // Добавляем ToList() для выполнения запроса
|
||||||
|
|
||||||
|
// Получение имен клиентов по ClientId
|
||||||
|
var clientIds = checksWithProduct.Select(x => x.ClientId).Distinct().ToList();
|
||||||
|
var clients = _clientRepository.ReadAll()
|
||||||
|
.Where(c => clientIds.Contains(c.Id)) // Фильтруем клиентов по ClientId
|
||||||
|
.ToDictionary(c => c.Id, c => c.Name); // Создаем словарь клиентов
|
||||||
|
|
||||||
|
// Формирование итоговой таблицы
|
||||||
|
return new List<string[]> { Headers }
|
||||||
|
.Union(
|
||||||
|
checksWithProduct.Select(x => new string[]
|
||||||
|
{
|
||||||
|
clients.ContainsKey(x.ClientId) ? clients[x.ClientId] : "Неизвестно", // Имя клиента
|
||||||
|
x.Date.ToShortDateString(),
|
||||||
|
x.Quantity.ToString()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.Union(new[]
|
||||||
|
{
|
||||||
|
new string[]
|
||||||
|
{
|
||||||
|
"Всего",
|
||||||
|
"",
|
||||||
|
checksWithProduct.Sum(x => x.Quantity).ToString()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
146
ProjectSellPC/ProjectSellPC/Reports/WordBuilder.cs
Normal file
146
ProjectSellPC/ProjectSellPC/Reports/WordBuilder.cs
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
using DocumentFormat.OpenXml;
|
||||||
|
using DocumentFormat.OpenXml.Packaging;
|
||||||
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.DocBuilder
|
||||||
|
{
|
||||||
|
internal class WordBuilder
|
||||||
|
{
|
||||||
|
private readonly string _filePath;
|
||||||
|
private readonly Document _document;
|
||||||
|
private readonly Body _body;
|
||||||
|
public WordBuilder(string filePath)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(filePath))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
{
|
||||||
|
File.Delete(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
_filePath = filePath;
|
||||||
|
_document = new Document();
|
||||||
|
_body = _document.AppendChild(new Body());
|
||||||
|
}
|
||||||
|
|
||||||
|
public WordBuilder AddHeader(string header)
|
||||||
|
{
|
||||||
|
var paragraph = _body.AppendChild(new Paragraph());
|
||||||
|
var run = paragraph.AppendChild(new Run());
|
||||||
|
|
||||||
|
// Добавляем свойства для жирного текста
|
||||||
|
var runProperties = new RunProperties();
|
||||||
|
runProperties.AppendChild(new Bold());
|
||||||
|
run.PrependChild(runProperties);
|
||||||
|
|
||||||
|
// Добавляем текст заголовка
|
||||||
|
run.AppendChild(new Text(header));
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public WordBuilder AddParagraph(string text)
|
||||||
|
{
|
||||||
|
var paragraph = _body.AppendChild(new Paragraph());
|
||||||
|
var run = paragraph.AppendChild(new Run());
|
||||||
|
run.AppendChild(new Text(text));
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WordBuilder AddTable(int[] widths, List<string[]> data)
|
||||||
|
{
|
||||||
|
if (widths == null || widths.Length == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(widths));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data == null || data.Count == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.Any(x => x.Length != widths.Length))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("widths.Length != data.Length");
|
||||||
|
}
|
||||||
|
|
||||||
|
var table = new Table();
|
||||||
|
table.AppendChild(new TableProperties(
|
||||||
|
new TableBorders(
|
||||||
|
new TopBorder()
|
||||||
|
{
|
||||||
|
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||||
|
Size = 12
|
||||||
|
},
|
||||||
|
new BottomBorder()
|
||||||
|
{
|
||||||
|
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||||
|
Size = 12
|
||||||
|
},
|
||||||
|
new LeftBorder()
|
||||||
|
{
|
||||||
|
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||||
|
Size = 12
|
||||||
|
},
|
||||||
|
new RightBorder()
|
||||||
|
{
|
||||||
|
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||||
|
Size = 12
|
||||||
|
},
|
||||||
|
new InsideHorizontalBorder()
|
||||||
|
{
|
||||||
|
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||||
|
Size = 12
|
||||||
|
},
|
||||||
|
new InsideVerticalBorder()
|
||||||
|
{
|
||||||
|
Val = new EnumValue<BorderValues>(BorderValues.Single),
|
||||||
|
Size = 12
|
||||||
|
}
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
// Заголовок
|
||||||
|
var tr = new TableRow();
|
||||||
|
for (var j = 0; j < widths.Length; ++j)
|
||||||
|
{
|
||||||
|
tr.Append(new TableCell(
|
||||||
|
new TableCellProperties(new TableCellWidth()
|
||||||
|
{
|
||||||
|
Width =
|
||||||
|
widths[j].ToString()
|
||||||
|
}),
|
||||||
|
new Paragraph(new Run(new RunProperties(new Bold()), new
|
||||||
|
Text(data.First()[j])))));
|
||||||
|
}
|
||||||
|
table.Append(tr);
|
||||||
|
|
||||||
|
// Данные
|
||||||
|
table.Append(data.Skip(1).Select(x =>
|
||||||
|
new TableRow(x.Select(y => new TableCell(new Paragraph(new
|
||||||
|
Run(new Text(y))))))));
|
||||||
|
|
||||||
|
_body.Append(table);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Build()
|
||||||
|
{
|
||||||
|
using var wordDocument = WordprocessingDocument.Create(_filePath,
|
||||||
|
WordprocessingDocumentType.Document);
|
||||||
|
var mainPart = wordDocument.AddMainDocumentPart();
|
||||||
|
mainPart.Document = _document;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
ProjectSellPC/ProjectSellPC/Repos/IChequeRepository.cs
Normal file
11
ProjectSellPC/ProjectSellPC/Repos/IChequeRepository.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos
|
||||||
|
{
|
||||||
|
public interface IChequeRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Cheque> ReadAll(DateTime? startDate = null, DateTime? endDate = null, int? productId = null, int? clientId = null);
|
||||||
|
Cheque Read(int id);
|
||||||
|
void Create(Cheque Cheque);
|
||||||
|
}
|
||||||
|
}
|
13
ProjectSellPC/ProjectSellPC/Repos/IClientRepository.cs
Normal file
13
ProjectSellPC/ProjectSellPC/Repos/IClientRepository.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos
|
||||||
|
{
|
||||||
|
public interface IClientRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Client> ReadAll();
|
||||||
|
Client Read(int id);
|
||||||
|
void Create(Client client);
|
||||||
|
Client Update(Client client);
|
||||||
|
void Delete(int id);
|
||||||
|
}
|
||||||
|
}
|
13
ProjectSellPC/ProjectSellPC/Repos/IConnectionString.cs
Normal file
13
ProjectSellPC/ProjectSellPC/Repos/IConnectionString.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos
|
||||||
|
{
|
||||||
|
public interface IConnectionString
|
||||||
|
{
|
||||||
|
string ConnectionString { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectSellPC.Entites;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos
|
||||||
|
{
|
||||||
|
public interface IProductInChequeRepository
|
||||||
|
{
|
||||||
|
IEnumerable<ProductInCheque> ReadAll();
|
||||||
|
ProductInCheque Read(int id);
|
||||||
|
void Create(ProductInCheque ps);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
namespace ProjectSellPC.Repos
|
||||||
|
{
|
||||||
|
public interface IProductOnWarehouseRepository
|
||||||
|
{
|
||||||
|
IEnumerable<ProductsOnWarehouse> ReadAll();
|
||||||
|
ProductsOnWarehouse Read(int id);
|
||||||
|
void Create(ProductsOnWarehouse ps);
|
||||||
|
void Delete(int id);
|
||||||
|
}
|
||||||
|
}
|
13
ProjectSellPC/ProjectSellPC/Repos/IProductRepository.cs
Normal file
13
ProjectSellPC/ProjectSellPC/Repos/IProductRepository.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos
|
||||||
|
{
|
||||||
|
public interface IProductRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Product> ReadAll();
|
||||||
|
Product Read(int id);
|
||||||
|
void Create(Product product);
|
||||||
|
Product Update(Product product);
|
||||||
|
void Delete(int id);
|
||||||
|
}
|
||||||
|
}
|
13
ProjectSellPC/ProjectSellPC/Repos/IWarehouseRepository.cs
Normal file
13
ProjectSellPC/ProjectSellPC/Repos/IWarehouseRepository.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos
|
||||||
|
{
|
||||||
|
public interface IWarehouseRepository
|
||||||
|
{
|
||||||
|
IEnumerable<Warehouse> ReadAll();
|
||||||
|
Warehouse Read(int id);
|
||||||
|
void Create(Warehouse Warehouse);
|
||||||
|
Warehouse Update(Warehouse Warehouse);
|
||||||
|
void Delete(int id);
|
||||||
|
}
|
||||||
|
}
|
173
ProjectSellPC/ProjectSellPC/Repos/Impements/ChequeRepo.cs
Normal file
173
ProjectSellPC/ProjectSellPC/Repos/Impements/ChequeRepo.cs
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using ProjectSellPC.Reports;
|
||||||
|
using Dapper;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using DocumentFormat.OpenXml.Drawing.Charts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Npgsql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos.Impements
|
||||||
|
{
|
||||||
|
public class ChequeRepo : IChequeRepository
|
||||||
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<ChequeRepo> _logger;
|
||||||
|
private readonly IClientRepository _clientRepository;
|
||||||
|
private readonly IProductRepository _productRepository; // Добавляем зависимость
|
||||||
|
|
||||||
|
public ChequeRepo(IConnectionString connectionString, ILoggerFactory loggerFactory,
|
||||||
|
IClientRepository clientRepository, IProductRepository productRepository)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
|
||||||
|
_logger = loggerFactory.CreateLogger<ChequeRepo>();
|
||||||
|
_clientRepository = clientRepository ?? throw new ArgumentNullException(nameof(clientRepository));
|
||||||
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository)); // Инициализация
|
||||||
|
}
|
||||||
|
private IDbConnection CreateConnection() => new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
public void Create(Cheque cheque)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Создание чека");
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
using (var transaction = connection.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Убедитесь, что ClientId установлен
|
||||||
|
if (cheque.Client == null || cheque.Client.Id == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("ClientId не может быть пустым или равным 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
var chequeSql = "INSERT INTO \"cheque\" (\"clientid\", \"purchasedate\") VALUES (@ClientId, @PurchaseDate) RETURNING \"id\"";
|
||||||
|
cheque.Id = connection.ExecuteScalar<int>(chequeSql, new
|
||||||
|
{
|
||||||
|
ClientId = cheque.Client.Id,
|
||||||
|
PurchaseDate = cheque.PurchaseDate
|
||||||
|
}, transaction);
|
||||||
|
|
||||||
|
var productSql = "INSERT INTO \"productincheque\" (\"chequeid\", \"productid\", \"count\") VALUES (@ChequeId, @ProductID, @Count)";
|
||||||
|
foreach (var productInCheque in cheque.Products)
|
||||||
|
{
|
||||||
|
connection.Execute(productSql, new
|
||||||
|
{
|
||||||
|
ChequeId = cheque.Id,
|
||||||
|
ProductID = productInCheque.ProductID,
|
||||||
|
Count = productInCheque.Count
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
_logger.LogError(ex, "Ошибка при создании чека");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cheque Read(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Чтение чека по ID: {id}", id);
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var ChequeSql = "SELECT * FROM \"cheque\" WHERE \"id\" = @Id";
|
||||||
|
var Cheque = connection.QuerySingleOrDefault<Cheque>(ChequeSql, new { Id = id });
|
||||||
|
|
||||||
|
if (Cheque == null) return null;
|
||||||
|
|
||||||
|
Cheque.Client = _clientRepository.Read(Cheque.Client.Id);
|
||||||
|
|
||||||
|
var productSql = "SELECT * FROM \"productincheque\" WHERE \"chequeid\" = @ChequeId";
|
||||||
|
Cheque.Products = connection.Query<ProductInCheque>(productSql, new { ChequeId = Cheque.Id }).ToList();
|
||||||
|
|
||||||
|
return Cheque;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении чека");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IEnumerable<Cheque> ReadAll(DateTime? startDate = null, DateTime? endDate = null, int? productId = null, int? clientId = null)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Чтение всех чеков с использованием фильтров");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
|
||||||
|
// Добавляем условия фильтрации, если параметры заданы
|
||||||
|
if (startDate.HasValue)
|
||||||
|
builder.AddCondition("\"cheque\".\"purchasedate\" >= @StartDate");
|
||||||
|
if (endDate.HasValue)
|
||||||
|
builder.AddCondition("\"cheque\".\"purchasedate\" <= @EndDate");
|
||||||
|
if (productId.HasValue)
|
||||||
|
builder.AddCondition("\"productincheque\".\"productid\" = @ProductId");
|
||||||
|
if (clientId.HasValue)
|
||||||
|
builder.AddCondition("\"cheque\".\"clientid\" = @ClientId");
|
||||||
|
|
||||||
|
// Формируем основной SQL-запрос
|
||||||
|
var query = $"SELECT \"cheque\".*, \"client\".\"id\" AS \"clientid\", \"client\".\"name\" AS \"clientname\" " +
|
||||||
|
$"FROM \"cheque\" " +
|
||||||
|
$"LEFT JOIN \"client\" ON \"cheque\".\"clientid\" = \"client\".\"id\" " +
|
||||||
|
$"LEFT JOIN \"productincheque\" ON \"productincheque\".\"chequeid\" = \"cheque\".\"id\" " +
|
||||||
|
$"{builder.Build()} " +
|
||||||
|
$"ORDER BY \"cheque\".\"purchasedate\"";
|
||||||
|
|
||||||
|
// Выполняем запрос
|
||||||
|
using var connection = CreateConnection();
|
||||||
|
var cheques = connection.Query<Cheque, int, string, Cheque>(
|
||||||
|
query,
|
||||||
|
(cheque, clientId, clientName) =>
|
||||||
|
{
|
||||||
|
cheque.Client = new Client { Id = clientId, Name = clientName ?? "Неизвестно" };
|
||||||
|
return cheque;
|
||||||
|
},
|
||||||
|
new { StartDate = startDate, EndDate = endDate, ProductId = productId, ClientId = clientId },
|
||||||
|
splitOn: "clientid,clientname"
|
||||||
|
).ToList();
|
||||||
|
|
||||||
|
// Загружаем товары для каждого чека
|
||||||
|
foreach (var cheque in cheques)
|
||||||
|
{
|
||||||
|
var productQuery = "SELECT * FROM \"productincheque\" WHERE \"chequeid\" = @ChequeId";
|
||||||
|
cheque.Products = connection.Query<ProductInCheque>(productQuery, new { ChequeId = cheque.Id }).ToList();
|
||||||
|
|
||||||
|
// Загружаем названия товаров
|
||||||
|
foreach (var productInCheque in cheque.Products)
|
||||||
|
{
|
||||||
|
var product = _productRepository.Read(productInCheque.ProductID);
|
||||||
|
if (product != null)
|
||||||
|
{
|
||||||
|
productInCheque.ProductName = product.Name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
productInCheque.ProductName = "Неизвестный товар";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cheques;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении всех чеков");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
141
ProjectSellPC/ProjectSellPC/Repos/Impements/ClientRepo.cs
Normal file
141
ProjectSellPC/ProjectSellPC/Repos/Impements/ClientRepo.cs
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using ProjectSellPC.Entites.Enums;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos.Impements
|
||||||
|
{
|
||||||
|
public class ClientRepo : IClientRepository
|
||||||
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<ClientRepo> _logger;
|
||||||
|
|
||||||
|
public ClientRepo(IConnectionString connectionString, ILoggerFactory loggerFactory)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = loggerFactory.CreateLogger<ClientRepo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IDbConnection CreateConnection() => new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
public void Create(Client client)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Добавление клиента");
|
||||||
|
_logger.LogDebug("Клиент: {json}", JsonConvert.SerializeObject(client));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "INSERT INTO \"client\" (\"name\", \"phonenumber\", \"clienttype\") " +
|
||||||
|
"VALUES (@Name, @PhoneNumber, @ClientType)";
|
||||||
|
|
||||||
|
connection.Execute(sql, new
|
||||||
|
{
|
||||||
|
Name = client.Name,
|
||||||
|
PhoneNumber = client.PhoneNumber,
|
||||||
|
ClientType = (int)client.ClientType
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении клиента");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление клиента");
|
||||||
|
_logger.LogDebug("Клиент ID: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "DELETE FROM \"client\" WHERE \"id\" = @Id";
|
||||||
|
connection.Execute(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении клиента");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Client Read(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение клиента по ID");
|
||||||
|
_logger.LogDebug("Клиент ID: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "SELECT * FROM \"client\" WHERE \"id\" = @Id";
|
||||||
|
return connection.QuerySingleOrDefault<Client>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при получении клиента");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Client> ReadAll()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение всех клиентов");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "SELECT * FROM \"client\"";
|
||||||
|
return connection.Query<Client>(sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при получении списка клиентов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Client Update(Client client)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Обновление информации о клиенте");
|
||||||
|
_logger.LogDebug("Клиент: {json}", JsonConvert.SerializeObject(client));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "UPDATE \"client\" SET \"name\" = @Name, \"phonenumber\" = @PhoneNumber, \"clienttype\" = @ClientType " +
|
||||||
|
"WHERE \"id\" = @Id";
|
||||||
|
|
||||||
|
connection.Execute(sql, new
|
||||||
|
{
|
||||||
|
Id = client.Id,
|
||||||
|
Name = client.Name,
|
||||||
|
PhoneNumber = client.PhoneNumber,
|
||||||
|
ClientType = (int)client.ClientType
|
||||||
|
});
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при обновлении информации о клиенте");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectSellPC.Repos;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos.Impements
|
||||||
|
{
|
||||||
|
public class ConnectionString : IConnectionString
|
||||||
|
{
|
||||||
|
string IConnectionString.ConnectionString => "Host=localhost;Username=postgres;Password=78oripop;Database=otp2";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,136 @@
|
|||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos.Impements
|
||||||
|
{
|
||||||
|
public class ProductInChequeRepo : IProductInChequeRepository
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly IProductRepository _productRepository;
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<ProductInChequeRepo> _logger;
|
||||||
|
|
||||||
|
public ProductInChequeRepo(IConnectionString connectionString, ILoggerFactory loggerFactory, IProductRepository productRepository)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = loggerFactory.CreateLogger<ProductInChequeRepo>();
|
||||||
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IDbConnection CreateConnection() => new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
|
||||||
|
public void Create(ProductInCheque productInCheque)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Добавление товара в чек");
|
||||||
|
_logger.LogDebug("Товар в чеке: {json}", Newtonsoft.Json.JsonConvert.SerializeObject(productInCheque));
|
||||||
|
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
using (var transaction = connection.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sql = "INSERT INTO \"productincheque\" (\"productid\", \"count\") " +
|
||||||
|
"VALUES (@ProductID, @Count) RETURNING \"ID\"";
|
||||||
|
|
||||||
|
productInCheque.ID = connection.ExecuteScalar<int>(sql, new
|
||||||
|
{
|
||||||
|
ProductID = productInCheque.ProductID,
|
||||||
|
Count = productInCheque.Count
|
||||||
|
}, transaction);
|
||||||
|
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении товара в чек");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductInCheque Read(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение товара в чеке по ID");
|
||||||
|
_logger.LogDebug("ID товара в чеке: {id}", id);
|
||||||
|
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sql = "SELECT * FROM \"productincheque\" WHERE \"id\" = @ID";
|
||||||
|
var productInCheque = connection.QuerySingleOrDefault<ProductInCheque>(sql, new { ID = id });
|
||||||
|
if (productInCheque != null)
|
||||||
|
{
|
||||||
|
// Загрузка дополнительной информации о продукте при необходимости
|
||||||
|
var product = _productRepository.Read(productInCheque.ProductID);
|
||||||
|
productInCheque.ProductID = product?.ID ?? 0;
|
||||||
|
}
|
||||||
|
return productInCheque;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при получении товара в чеке");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<ProductInCheque> ReadAll()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение всех товаров в чеках");
|
||||||
|
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sql = "SELECT * FROM \"productincheque\"";
|
||||||
|
var productsInCheque = connection.Query<ProductInCheque>(sql).ToList();
|
||||||
|
|
||||||
|
foreach (var productInCheque in productsInCheque)
|
||||||
|
{
|
||||||
|
var product = _productRepository.Read(productInCheque.ProductID);
|
||||||
|
productInCheque.ProductID = product?.ID ?? 0;
|
||||||
|
}
|
||||||
|
return productsInCheque;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при получении списка товаров в чеках");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление товара из чека");
|
||||||
|
_logger.LogDebug("ID товара в чеке: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "DELETE FROM \"productincheque\" WHERE \"id\" = @ID";
|
||||||
|
connection.Execute(sql, new { ID = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении товара из чека");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
150
ProjectSellPC/ProjectSellPC/Repos/Impements/ProductRepo.cs
Normal file
150
ProjectSellPC/ProjectSellPC/Repos/Impements/ProductRepo.cs
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using ProjectSellPC.Entites.Enums;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos.Impements
|
||||||
|
{
|
||||||
|
public class ProductRepo : IProductRepository
|
||||||
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<ProductRepo> _logger;
|
||||||
|
|
||||||
|
public ProductRepo(IConnectionString connectionString, ILoggerFactory loggerFactory)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
|
||||||
|
_logger = loggerFactory.CreateLogger<ProductRepo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IDbConnection CreateConnection() => new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
public void Create(Product product)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "INSERT INTO \"product\" (\"name\", \"description\", \"price\", \"producttype\") " +
|
||||||
|
"VALUES (@Name, @Description, @Price, @ProductType)";
|
||||||
|
|
||||||
|
connection.Execute(sql, new
|
||||||
|
{
|
||||||
|
Name = product.Name,
|
||||||
|
Description = product.Description,
|
||||||
|
Price = product.Price,
|
||||||
|
ProductType = (int)product.ProductType
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "DELETE FROM \"product\" WHERE \"id\" = @Id";
|
||||||
|
connection.Execute(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Product Read(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = $"SELECT * FROM \"product\" WHERE \"id\" = {id}";
|
||||||
|
return connection.QuerySingleOrDefault<Product>(sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Product> ReadAll()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "SELECT * FROM \"product\"";
|
||||||
|
return connection.Query<Product>(sql).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Product Update(Product product)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "UPDATE \"product\" " +
|
||||||
|
"SET \"name\" = @Name, " +
|
||||||
|
"\"description\" = @Description, " +
|
||||||
|
"\"price\" = @Price," +
|
||||||
|
"\"producttype\" = @ProductType" +
|
||||||
|
" WHERE \"id\" = @Id";
|
||||||
|
|
||||||
|
connection.Execute(sql, new
|
||||||
|
{
|
||||||
|
Id = product.ID,
|
||||||
|
Name = product.Name,
|
||||||
|
Description = product.Description,
|
||||||
|
Price = product.Price,
|
||||||
|
ProductType = (int)product.ProductType
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при изменении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return product;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,135 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos.Impements
|
||||||
|
{
|
||||||
|
public class ProductsOnWarehouseRepo : IProductOnWarehouseRepository
|
||||||
|
{
|
||||||
|
private readonly IProductRepository _productRepository;
|
||||||
|
private readonly IWarehouseRepository _warehouseRepository;
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<ProductsOnWarehouseRepo> _logger;
|
||||||
|
public ProductsOnWarehouseRepo(IConnectionString connectionString, ILoggerFactory loggerFactory,
|
||||||
|
IProductRepository productRepository,
|
||||||
|
IWarehouseRepository warehouseRepository)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = loggerFactory.CreateLogger<ProductsOnWarehouseRepo>();
|
||||||
|
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
|
||||||
|
_warehouseRepository = warehouseRepository ?? throw new ArgumentNullException(nameof(warehouseRepository));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IDbConnection CreateConnection() => new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
|
||||||
|
public void Create(ProductsOnWarehouse productsOnWarehouse)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Добавление продукта на склад");
|
||||||
|
_logger.LogDebug("Продукт на складе: {json}", JsonConvert.SerializeObject(productsOnWarehouse));
|
||||||
|
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
using (var transaction = connection.BeginTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sql = "INSERT INTO \"productsonwarehouse\" (\"productid\", \"warehouseid\", \"count\") " +
|
||||||
|
"VALUES (@ProductId, @WarehouseId, @Count) RETURNING \"id\"";
|
||||||
|
|
||||||
|
productsOnWarehouse.Id = connection.ExecuteScalar<int>(sql, new
|
||||||
|
{
|
||||||
|
ProductId = productsOnWarehouse.Product.ID,
|
||||||
|
WarehouseId = productsOnWarehouse.Warehouse.Id,
|
||||||
|
Count = productsOnWarehouse.Count
|
||||||
|
}, transaction);
|
||||||
|
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении продукта на склад");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductsOnWarehouse Read(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение продукта на складе по ID");
|
||||||
|
_logger.LogDebug("ID продукта на складе: {id}", id);
|
||||||
|
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sql = "SELECT * FROM \"productsonwarehouse\" WHERE \"id\" = @Id";
|
||||||
|
var productOnWarehouse = connection.QuerySingleOrDefault<ProductsOnWarehouse>(sql, new { Id = id });
|
||||||
|
productOnWarehouse.Warehouse = _warehouseRepository.Read(productOnWarehouse.WarehouseId);
|
||||||
|
productOnWarehouse.Product = _productRepository.Read(productOnWarehouse.ProductId);
|
||||||
|
|
||||||
|
return productOnWarehouse;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при получении продукта на складе");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<ProductsOnWarehouse> ReadAll()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение всех продуктов на складе");
|
||||||
|
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sql = "SELECT * FROM \"productsonwarehouse\"";
|
||||||
|
var answer = connection.Query<ProductsOnWarehouse>(sql).ToList();
|
||||||
|
foreach (var productOnWarehouse in answer)
|
||||||
|
{
|
||||||
|
productOnWarehouse.Product = _productRepository.Read(productOnWarehouse.ProductId);
|
||||||
|
productOnWarehouse.Warehouse = _warehouseRepository.Read(productOnWarehouse.WarehouseId);
|
||||||
|
}
|
||||||
|
return answer;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при получении списка продуктов на складе");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление товара со склада");
|
||||||
|
_logger.LogDebug("Склад ID: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "DELETE FROM \"productsonwarehouse\" WHERE \"id\" = @Id";
|
||||||
|
connection.Execute(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
140
ProjectSellPC/ProjectSellPC/Repos/Impements/WarehouseRepo.cs
Normal file
140
ProjectSellPC/ProjectSellPC/Repos/Impements/WarehouseRepo.cs
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
using ProjectSellPC.Entites;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ProjectSellPC.Repos.Impements
|
||||||
|
{
|
||||||
|
public class WarehouseRepo: IWarehouseRepository
|
||||||
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<WarehouseRepo> _logger;
|
||||||
|
|
||||||
|
public WarehouseRepo(IConnectionString connectionString, ILoggerFactory loggerFactory)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = loggerFactory.CreateLogger<WarehouseRepo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IDbConnection CreateConnection() => new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
|
||||||
|
public void Create(Warehouse warehouse)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Добавление склада");
|
||||||
|
_logger.LogDebug("Склад: {json}", JsonConvert.SerializeObject(warehouse));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "INSERT INTO \"warehouse\" (\"size\", \"adress\") " +
|
||||||
|
"VALUES (@Size, @Adress)";
|
||||||
|
|
||||||
|
connection.Execute(sql, new
|
||||||
|
{
|
||||||
|
Size = warehouse.Size,
|
||||||
|
Adress = warehouse.Adress
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении склада");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление склада");
|
||||||
|
_logger.LogDebug("Склад ID: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "DELETE FROM \"warehouse\" WHERE \"id\" = @Id";
|
||||||
|
connection.Execute(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении склада");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Warehouse Read(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение склада по ID");
|
||||||
|
_logger.LogDebug("Склад ID: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "SELECT * FROM \"warehouse\" WHERE \"id\" = @Id";
|
||||||
|
return connection.QuerySingleOrDefault<Warehouse>(sql, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при получении склада");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Warehouse> ReadAll()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение всех складов");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "SELECT * FROM \"warehouse\"";
|
||||||
|
return connection.Query<Warehouse>(sql).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при получении списка складов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Warehouse Update(Warehouse warehouse)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Обновление информации о складе");
|
||||||
|
_logger.LogDebug("Склад: {json}", JsonConvert.SerializeObject(warehouse));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var connection = CreateConnection())
|
||||||
|
{
|
||||||
|
var sql = "UPDATE \"warehouse\" SET \"size\" = @Size, \"adress\" = @Adress " +
|
||||||
|
"WHERE \"id\" = @Id";
|
||||||
|
|
||||||
|
connection.Execute(sql, new
|
||||||
|
{
|
||||||
|
Id = warehouse.Id,
|
||||||
|
Size = warehouse.Size,
|
||||||
|
Adress = warehouse.Adress
|
||||||
|
});
|
||||||
|
|
||||||
|
return warehouse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при обновлении информации о складе");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
ProjectSellPC/ProjectSellPC/appsettings.json
Normal file
15
ProjectSellPC/ProjectSellPC/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "Logs/log.txt",
|
||||||
|
"rollingInterval": "Day"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
BIN
ProjectSellPC/ProjectSellPC/large_KPq-qORcEv8-1.jpg
Normal file
BIN
ProjectSellPC/ProjectSellPC/large_KPq-qORcEv8-1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 101 KiB |
Loading…
x
Reference in New Issue
Block a user