Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1f7a787a98 | ||
|
e5f63e0d71 | ||
|
553ddc7711 |
BIN
ProjectGasStation.zip
Normal file
BIN
ProjectGasStation.zip
Normal file
Binary file not shown.
25
ProjectGasStation/ProjectGasStation.sln
Normal file
25
ProjectGasStation/ProjectGasStation.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34525.116
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectGasStation", "ProjectGasStation\ProjectGasStation.csproj", "{4C4A42F9-B3C9-4BC4-A2DF-B24467227150}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4C4A42F9-B3C9-4BC4-A2DF-B24467227150}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4C4A42F9-B3C9-4BC4-A2DF-B24467227150}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4C4A42F9-B3C9-4BC4-A2DF-B24467227150}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4C4A42F9-B3C9-4BC4-A2DF-B24467227150}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {2AE1223C-095E-4AD1-BD25-D734E57F3D98}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Entities.Enums;
|
||||
|
||||
[Flags]
|
||||
public enum Category
|
||||
{
|
||||
None = 0,
|
||||
Fuel = 1,
|
||||
Oils = 2,
|
||||
Chemicals = 4,
|
||||
Gas = 8,
|
||||
LiquidFuel = 16,
|
||||
CareProducts = 32,
|
||||
CareForInterior = 64,
|
||||
CareForBody = 128,
|
||||
MineralOils = 256,
|
||||
SyntheticOils = 512
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Entities.Enums;
|
||||
public enum JobTitle
|
||||
{
|
||||
None = 0,
|
||||
|
||||
Ordinary = 1,
|
||||
|
||||
Senior = 2,
|
||||
|
||||
Head = 3
|
||||
}
|
29
ProjectGasStation/ProjectGasStation/Entities/Product.cs
Normal file
29
ProjectGasStation/ProjectGasStation/Entities/Product.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using ProjectGasStation.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Entities;
|
||||
|
||||
public class Product
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public decimal Price { get; private set; }
|
||||
public Category Category { get; private set; }
|
||||
|
||||
public static Product CreatEntity(int id, string name, decimal price, Category category)
|
||||
{
|
||||
return new Product
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Price = price,
|
||||
Category = category
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
43
ProjectGasStation/ProjectGasStation/Entities/Receipt.cs
Normal file
43
ProjectGasStation/ProjectGasStation/Entities/Receipt.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.Pkcs;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Entities;
|
||||
|
||||
public class Receipt
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public int SupplierId { get; set; }
|
||||
|
||||
public IEnumerable<SaleReceiptProduct> ReceiptProducts { get; set; } = [];
|
||||
|
||||
public static Receipt CreateOperation (int id, int supplierID, IEnumerable<SaleReceiptProduct> receiptProducts)
|
||||
{
|
||||
return new Receipt
|
||||
{
|
||||
Id = id,
|
||||
DateTime = DateTime.Now,
|
||||
SupplierId = supplierID,
|
||||
ReceiptProducts = receiptProducts
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public static Receipt CreateOperation(TempSaleReceiptProduct tempSaleReceiptProduct, IEnumerable<SaleReceiptProduct> receiptProducts)
|
||||
{
|
||||
return new Receipt
|
||||
{
|
||||
Id = tempSaleReceiptProduct.Id,
|
||||
DateTime = tempSaleReceiptProduct.DateTime,
|
||||
SupplierId = tempSaleReceiptProduct.SupplierId,
|
||||
ReceiptProducts = receiptProducts
|
||||
};
|
||||
}
|
||||
|
||||
}
|
39
ProjectGasStation/ProjectGasStation/Entities/Sale.cs
Normal file
39
ProjectGasStation/ProjectGasStation/Entities/Sale.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Entities;
|
||||
|
||||
public class Sale
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public int WorkerId { get; set; }
|
||||
public IEnumerable<SaleReceiptProduct> SaleProducts { get; set; } = [];
|
||||
|
||||
|
||||
public static Sale CreateOperation(int id, int workerId, IEnumerable<SaleReceiptProduct> saleProduct)
|
||||
{
|
||||
return new Sale
|
||||
{
|
||||
Id = id,
|
||||
DateTime = DateTime.Now,
|
||||
WorkerId = workerId,
|
||||
SaleProducts = saleProduct
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public static Sale CreateOperation(TempSaleReceiptProduct tempSaleReceiptProduct, IEnumerable<SaleReceiptProduct> saleProducts)
|
||||
{
|
||||
return new Sale
|
||||
{
|
||||
Id = tempSaleReceiptProduct.Id,
|
||||
DateTime = tempSaleReceiptProduct.DateTime,
|
||||
WorkerId = tempSaleReceiptProduct.WorkerId,
|
||||
SaleProducts = saleProducts
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Entities;
|
||||
|
||||
public class SaleReceiptProduct
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
public static SaleReceiptProduct CreateElement(int id, int productId, int quantity)
|
||||
{
|
||||
return new SaleReceiptProduct
|
||||
{
|
||||
Id = id,
|
||||
ProductId = productId,
|
||||
Quantity = quantity
|
||||
};
|
||||
}
|
||||
}
|
26
ProjectGasStation/ProjectGasStation/Entities/Supplier.cs
Normal file
26
ProjectGasStation/ProjectGasStation/Entities/Supplier.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Entities;
|
||||
|
||||
public class Supplier
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public string PhoneNumber { get; private set; }
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
public static Supplier CreateEntity(int id, string name, string phoneNumber, string address)
|
||||
{
|
||||
return new Supplier
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
PhoneNumber = phoneNumber,
|
||||
Address = address
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Entities;
|
||||
|
||||
public class TempSaleReceiptProduct
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public DateTime DateTime { get; private set; }
|
||||
public int SupplierId { get; private set; }
|
||||
|
||||
public int WorkerId { get; private set; }
|
||||
public int ProductId { get; private set; }
|
||||
|
||||
public int Quantity { get; private set; }
|
||||
}
|
26
ProjectGasStation/ProjectGasStation/Entities/Worker.cs
Normal file
26
ProjectGasStation/ProjectGasStation/Entities/Worker.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using ProjectGasStation.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Entities;
|
||||
|
||||
public class Worker
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public JobTitle JobTitle { get; private set; }
|
||||
|
||||
public static Worker CreateEntity (int id, string name, JobTitle jobTitle)
|
||||
{
|
||||
return new Worker
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
JobTitle = jobTitle
|
||||
};
|
||||
}
|
||||
}
|
170
ProjectGasStation/ProjectGasStation/FormGasStation.Designer.cs
generated
Normal file
170
ProjectGasStation/ProjectGasStation/FormGasStation.Designer.cs
generated
Normal file
@ -0,0 +1,170 @@
|
||||
namespace ProjectGasStation
|
||||
{
|
||||
partial class FormGasStation
|
||||
{
|
||||
/// <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(FormGasStation));
|
||||
menuStrip1 = new MenuStrip();
|
||||
ListsToolStripMenuItem = new ToolStripMenuItem();
|
||||
ProductToolStripMenuItem = new ToolStripMenuItem();
|
||||
WorkerToolStripMenuItem = new ToolStripMenuItem();
|
||||
SupplierToolStripMenuItem = new ToolStripMenuItem();
|
||||
OperationsToolStripMenuItem = new ToolStripMenuItem();
|
||||
ReceiptToolStripMenuItem = new ToolStripMenuItem();
|
||||
SaleToolStripMenuItem = new ToolStripMenuItem();
|
||||
ReportsToolStripMenuItem = new ToolStripMenuItem();
|
||||
DirectoryReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
productReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
SalesToolStripMenuItem = new ToolStripMenuItem();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { ListsToolStripMenuItem, OperationsToolStripMenuItem, ReportsToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(782, 28);
|
||||
menuStrip1.TabIndex = 0;
|
||||
menuStrip1.Text = "menuStrip";
|
||||
//
|
||||
// ListsToolStripMenuItem
|
||||
//
|
||||
ListsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ProductToolStripMenuItem, WorkerToolStripMenuItem, SupplierToolStripMenuItem });
|
||||
ListsToolStripMenuItem.Name = "ListsToolStripMenuItem";
|
||||
ListsToolStripMenuItem.Size = new Size(117, 24);
|
||||
ListsToolStripMenuItem.Text = "Справочники";
|
||||
//
|
||||
// ProductToolStripMenuItem
|
||||
//
|
||||
ProductToolStripMenuItem.Name = "ProductToolStripMenuItem";
|
||||
ProductToolStripMenuItem.Size = new Size(224, 26);
|
||||
ProductToolStripMenuItem.Text = "Товары";
|
||||
ProductToolStripMenuItem.Click += ProductToolStripMenuItem_Click;
|
||||
//
|
||||
// WorkerToolStripMenuItem
|
||||
//
|
||||
WorkerToolStripMenuItem.Name = "WorkerToolStripMenuItem";
|
||||
WorkerToolStripMenuItem.Size = new Size(224, 26);
|
||||
WorkerToolStripMenuItem.Text = "Работники";
|
||||
WorkerToolStripMenuItem.Click += WorkerToolStripMenuItem_Click;
|
||||
//
|
||||
// SupplierToolStripMenuItem
|
||||
//
|
||||
SupplierToolStripMenuItem.Name = "SupplierToolStripMenuItem";
|
||||
SupplierToolStripMenuItem.Size = new Size(224, 26);
|
||||
SupplierToolStripMenuItem.Text = "Поставщики";
|
||||
SupplierToolStripMenuItem.Click += SupplierToolStripMenuItem_Click;
|
||||
//
|
||||
// OperationsToolStripMenuItem
|
||||
//
|
||||
OperationsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ReceiptToolStripMenuItem, SaleToolStripMenuItem });
|
||||
OperationsToolStripMenuItem.Name = "OperationsToolStripMenuItem";
|
||||
OperationsToolStripMenuItem.Size = new Size(95, 24);
|
||||
OperationsToolStripMenuItem.Text = "Операции";
|
||||
//
|
||||
// ReceiptToolStripMenuItem
|
||||
//
|
||||
ReceiptToolStripMenuItem.Name = "ReceiptToolStripMenuItem";
|
||||
ReceiptToolStripMenuItem.Size = new Size(244, 26);
|
||||
ReceiptToolStripMenuItem.Text = "Поступление товаров";
|
||||
ReceiptToolStripMenuItem.Click += ReceiptToolStripMenuItem_Click;
|
||||
//
|
||||
// SaleToolStripMenuItem
|
||||
//
|
||||
SaleToolStripMenuItem.Name = "SaleToolStripMenuItem";
|
||||
SaleToolStripMenuItem.Size = new Size(244, 26);
|
||||
SaleToolStripMenuItem.Text = "Продажи";
|
||||
SaleToolStripMenuItem.Click += SaleToolStripMenuItem_Click;
|
||||
//
|
||||
// ReportsToolStripMenuItem
|
||||
//
|
||||
ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, productReportToolStripMenuItem, SalesToolStripMenuItem });
|
||||
ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem";
|
||||
ReportsToolStripMenuItem.Size = new Size(73, 24);
|
||||
ReportsToolStripMenuItem.Text = "Отчеты";
|
||||
//
|
||||
// DirectoryReportToolStripMenuItem
|
||||
//
|
||||
DirectoryReportToolStripMenuItem.Name = "DirectoryReportToolStripMenuItem";
|
||||
DirectoryReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W;
|
||||
DirectoryReportToolStripMenuItem.Size = new Size(344, 26);
|
||||
DirectoryReportToolStripMenuItem.Text = "Докумен со справочниками";
|
||||
DirectoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click;
|
||||
//
|
||||
// productReportToolStripMenuItem
|
||||
//
|
||||
productReportToolStripMenuItem.Name = "productReportToolStripMenuItem";
|
||||
productReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.E;
|
||||
productReportToolStripMenuItem.Size = new Size(344, 26);
|
||||
productReportToolStripMenuItem.Text = "Движение товара";
|
||||
productReportToolStripMenuItem.Click += productReportToolStripMenuItem_Click;
|
||||
//
|
||||
// SalesToolStripMenuItem
|
||||
//
|
||||
SalesToolStripMenuItem.Name = "SalesToolStripMenuItem";
|
||||
SalesToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P;
|
||||
SalesToolStripMenuItem.Size = new Size(344, 26);
|
||||
SalesToolStripMenuItem.Text = "Продажи";
|
||||
SalesToolStripMenuItem.Click += SalesToolStripMenuItem_Click;
|
||||
//
|
||||
// FormGasStation
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
BackgroundImage = (Image)resources.GetObject("$this.BackgroundImage");
|
||||
BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ClientSize = new Size(782, 453);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Name = "FormGasStation";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "АЗС";
|
||||
menuStrip1.ResumeLayout(false);
|
||||
menuStrip1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem ListsToolStripMenuItem;
|
||||
private ToolStripMenuItem OperationsToolStripMenuItem;
|
||||
private ToolStripMenuItem ReportsToolStripMenuItem;
|
||||
private ToolStripMenuItem ProductToolStripMenuItem;
|
||||
private ToolStripMenuItem WorkerToolStripMenuItem;
|
||||
private ToolStripMenuItem SupplierToolStripMenuItem;
|
||||
private ToolStripMenuItem ReceiptToolStripMenuItem;
|
||||
private ToolStripMenuItem SaleToolStripMenuItem;
|
||||
private ToolStripMenuItem DirectoryReportToolStripMenuItem;
|
||||
private ToolStripMenuItem productReportToolStripMenuItem;
|
||||
private ToolStripMenuItem SalesToolStripMenuItem;
|
||||
}
|
||||
}
|
128
ProjectGasStation/ProjectGasStation/FormGasStation.cs
Normal file
128
ProjectGasStation/ProjectGasStation/FormGasStation.cs
Normal file
@ -0,0 +1,128 @@
|
||||
using ProjectGasStation.Forms;
|
||||
using System.ComponentModel;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectGasStation
|
||||
{
|
||||
public partial class FormGasStation : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
public FormGasStation(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
|
||||
}
|
||||
|
||||
private void ProductToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormProducts>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void WorkerToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormWorkers>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SupplierToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormSuppliers>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ReceiptToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormReceipts>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SaleToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormSales>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DirectoryReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormDirectoryReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void productReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormProductReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void SalesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormSaleDistributionReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1690
ProjectGasStation/ProjectGasStation/FormGasStation.resx
Normal file
1690
ProjectGasStation/ProjectGasStation/FormGasStation.resx
Normal file
File diff suppressed because it is too large
Load Diff
99
ProjectGasStation/ProjectGasStation/Forms/FormDirectoryReport.Designer.cs
generated
Normal file
99
ProjectGasStation/ProjectGasStation/Forms/FormDirectoryReport.Designer.cs
generated
Normal file
@ -0,0 +1,99 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormDirectoryReport
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
checkBoxProducts = new CheckBox();
|
||||
checkBoxWorkers = new CheckBox();
|
||||
checkBoxSuppliers = new CheckBox();
|
||||
buttonBuild = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// checkBoxProducts
|
||||
//
|
||||
checkBoxProducts.AutoSize = true;
|
||||
checkBoxProducts.Location = new Point(28, 29);
|
||||
checkBoxProducts.Name = "checkBoxProducts";
|
||||
checkBoxProducts.Size = new Size(84, 24);
|
||||
checkBoxProducts.TabIndex = 0;
|
||||
checkBoxProducts.Text = "Товары";
|
||||
checkBoxProducts.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxWorkers
|
||||
//
|
||||
checkBoxWorkers.AutoSize = true;
|
||||
checkBoxWorkers.Location = new Point(28, 77);
|
||||
checkBoxWorkers.Name = "checkBoxWorkers";
|
||||
checkBoxWorkers.Size = new Size(113, 24);
|
||||
checkBoxWorkers.TabIndex = 1;
|
||||
checkBoxWorkers.Text = "Сотрудники";
|
||||
checkBoxWorkers.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxSuppliers
|
||||
//
|
||||
checkBoxSuppliers.AutoSize = true;
|
||||
checkBoxSuppliers.Location = new Point(28, 125);
|
||||
checkBoxSuppliers.Name = "checkBoxSuppliers";
|
||||
checkBoxSuppliers.Size = new Size(117, 24);
|
||||
checkBoxSuppliers.TabIndex = 2;
|
||||
checkBoxSuppliers.Text = "Поставщики";
|
||||
checkBoxSuppliers.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonBuild
|
||||
//
|
||||
buttonBuild.Location = new Point(207, 55);
|
||||
buttonBuild.Name = "buttonBuild";
|
||||
buttonBuild.Size = new Size(129, 66);
|
||||
buttonBuild.TabIndex = 3;
|
||||
buttonBuild.Text = "Сформировать отчет";
|
||||
buttonBuild.UseVisualStyleBackColor = true;
|
||||
buttonBuild.Click += buttonBuild_Click;
|
||||
//
|
||||
// FormDirectoryReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(383, 196);
|
||||
Controls.Add(buttonBuild);
|
||||
Controls.Add(checkBoxSuppliers);
|
||||
Controls.Add(checkBoxWorkers);
|
||||
Controls.Add(checkBoxProducts);
|
||||
Name = "FormDirectoryReport";
|
||||
Text = "FormDirectoryReport";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CheckBox checkBoxProducts;
|
||||
private CheckBox checkBoxWorkers;
|
||||
private CheckBox checkBoxSuppliers;
|
||||
private Button buttonBuild;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
using ProjectGasStation.Reports;
|
||||
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 ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormDirectoryReport : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
public FormDirectoryReport(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
}
|
||||
|
||||
private void buttonBuild_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!checkBoxProducts.Checked &&
|
||||
!checkBoxWorkers.Checked && !checkBoxSuppliers.Checked)
|
||||
{
|
||||
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, checkBoxProducts.Checked,
|
||||
checkBoxWorkers.Checked, checkBoxSuppliers.Checked))
|
||||
{
|
||||
MessageBox.Show("Документ сформирован",
|
||||
"Формирование документа",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах",
|
||||
"Формирование документа",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
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>
|
146
ProjectGasStation/ProjectGasStation/Forms/FormProduct.Designer.cs
generated
Normal file
146
ProjectGasStation/ProjectGasStation/Forms/FormProduct.Designer.cs
generated
Normal file
@ -0,0 +1,146 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormProduct
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
checkedListBoxCategory = new CheckedListBox();
|
||||
labelName = new Label();
|
||||
labelCategory = new Label();
|
||||
labelPrice = new Label();
|
||||
numericUpDownPrice = new NumericUpDown();
|
||||
textBoxName = new TextBox();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// checkedListBoxCategory
|
||||
//
|
||||
checkedListBoxCategory.FormattingEnabled = true;
|
||||
checkedListBoxCategory.Location = new Point(172, 76);
|
||||
checkedListBoxCategory.Name = "checkedListBoxCategory";
|
||||
checkedListBoxCategory.Size = new Size(205, 114);
|
||||
checkedListBoxCategory.TabIndex = 0;
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(28, 30);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(120, 20);
|
||||
labelName.TabIndex = 1;
|
||||
labelName.Text = "Наименование ";
|
||||
//
|
||||
// labelCategory
|
||||
//
|
||||
labelCategory.AutoSize = true;
|
||||
labelCategory.Location = new Point(28, 76);
|
||||
labelCategory.Name = "labelCategory";
|
||||
labelCategory.Size = new Size(81, 20);
|
||||
labelCategory.TabIndex = 2;
|
||||
labelCategory.Text = "Категория";
|
||||
//
|
||||
// labelPrice
|
||||
//
|
||||
labelPrice.AutoSize = true;
|
||||
labelPrice.Location = new Point(28, 207);
|
||||
labelPrice.Name = "labelPrice";
|
||||
labelPrice.Size = new Size(45, 20);
|
||||
labelPrice.TabIndex = 3;
|
||||
labelPrice.Text = "Цена";
|
||||
//
|
||||
// numericUpDownPrice
|
||||
//
|
||||
numericUpDownPrice.DecimalPlaces = 2;
|
||||
numericUpDownPrice.Location = new Point(172, 207);
|
||||
numericUpDownPrice.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
|
||||
numericUpDownPrice.Minimum = new decimal(new int[] { 10, 0, 0, 0 });
|
||||
numericUpDownPrice.Name = "numericUpDownPrice";
|
||||
numericUpDownPrice.Size = new Size(205, 27);
|
||||
numericUpDownPrice.TabIndex = 4;
|
||||
numericUpDownPrice.Value = new decimal(new int[] { 10, 0, 0, 0 });
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(172, 30);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(205, 27);
|
||||
textBoxName.TabIndex = 5;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(28, 259);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(157, 48);
|
||||
buttonSave.TabIndex = 6;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(220, 259);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(157, 48);
|
||||
buttonCancel.TabIndex = 7;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// FormProduct
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(402, 332);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(numericUpDownPrice);
|
||||
Controls.Add(labelPrice);
|
||||
Controls.Add(labelCategory);
|
||||
Controls.Add(labelName);
|
||||
Controls.Add(checkedListBoxCategory);
|
||||
Name = "FormProduct";
|
||||
Text = "Товар";
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CheckedListBox checkedListBoxCategory;
|
||||
private Label labelName;
|
||||
private Label labelCategory;
|
||||
private Label labelPrice;
|
||||
private NumericUpDown numericUpDownPrice;
|
||||
private TextBox textBoxName;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
108
ProjectGasStation/ProjectGasStation/Forms/FormProduct.cs
Normal file
108
ProjectGasStation/ProjectGasStation/Forms/FormProduct.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
using ProjectGasStation.Entities;
|
||||
using ProjectGasStation.Entities.Enums;
|
||||
using ProjectGasStation.Repositories;
|
||||
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 ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormProduct : Form
|
||||
{
|
||||
private readonly IProductRepository _productRepository;
|
||||
private int? _productId;
|
||||
|
||||
public int Id
|
||||
{
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
var product = _productRepository.ReadProductById(value);
|
||||
if (product == null)
|
||||
{
|
||||
throw new
|
||||
InvalidDataException(nameof(product));
|
||||
}
|
||||
foreach (Category elem in Enum.GetValues(typeof(Category)))
|
||||
{
|
||||
if ((elem & product.Category) != 0)
|
||||
{
|
||||
checkedListBoxCategory.SetItemChecked(checkedListBoxCategory.Items.IndexOf(elem), true);
|
||||
}
|
||||
}
|
||||
textBoxName.Text = product.Name;
|
||||
numericUpDownPrice.Value = product.Price;
|
||||
_productId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public FormProduct(IProductRepository productRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_productRepository = productRepository ??
|
||||
throw new ArgumentNullException(nameof(productRepository));
|
||||
foreach (var elem in Enum.GetValues(typeof(Category)))
|
||||
{
|
||||
checkedListBoxCategory.Items.Add(elem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxName.Text) ||
|
||||
checkedListBoxCategory.CheckedItems.Count == 0)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
if (_productId.HasValue)
|
||||
{
|
||||
_productRepository.UpdateProduct(CreateProduct(_productId.Value));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
_productRepository.CreateProduct(CreateProduct(0));
|
||||
}
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
private Product CreateProduct(int id)
|
||||
{
|
||||
Category category = Category.None;
|
||||
foreach (var elem in checkedListBoxCategory.CheckedItems)
|
||||
{
|
||||
category |= (Category)elem;
|
||||
}
|
||||
return Product.CreatEntity(id, textBoxName.Text, numericUpDownPrice.Value, category);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
120
ProjectGasStation/ProjectGasStation/Forms/FormProduct.resx
Normal file
120
ProjectGasStation/ProjectGasStation/Forms/FormProduct.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>
|
163
ProjectGasStation/ProjectGasStation/Forms/FormProductReport.Designer.cs
generated
Normal file
163
ProjectGasStation/ProjectGasStation/Forms/FormProductReport.Designer.cs
generated
Normal file
@ -0,0 +1,163 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormProductReport
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
dateTimePickerBegin = new DateTimePicker();
|
||||
dateTimePickerEnd = new DateTimePicker();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
label3 = new Label();
|
||||
label4 = new Label();
|
||||
buttonMakeReport = new Button();
|
||||
buttonSelectPathFile = new Button();
|
||||
textBoxFilePath = new TextBox();
|
||||
comboBoxProduct = new ComboBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dateTimePickerBegin
|
||||
//
|
||||
dateTimePickerBegin.Location = new Point(175, 148);
|
||||
dateTimePickerBegin.Name = "dateTimePickerBegin";
|
||||
dateTimePickerBegin.Size = new Size(250, 27);
|
||||
dateTimePickerBegin.TabIndex = 0;
|
||||
//
|
||||
// dateTimePickerEnd
|
||||
//
|
||||
dateTimePickerEnd.Location = new Point(175, 200);
|
||||
dateTimePickerEnd.Name = "dateTimePickerEnd";
|
||||
dateTimePickerEnd.Size = new Size(250, 27);
|
||||
dateTimePickerEnd.TabIndex = 1;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(24, 36);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(109, 20);
|
||||
label1.TabIndex = 2;
|
||||
label1.Text = "Путь до файла";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(24, 91);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(51, 20);
|
||||
label2.TabIndex = 3;
|
||||
label2.Text = "Товар";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(24, 148);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(98, 20);
|
||||
label3.TabIndex = 4;
|
||||
label3.Text = "Дата начала ";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(24, 205);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(125, 20);
|
||||
label4.TabIndex = 5;
|
||||
label4.Text = "Дата окончания ";
|
||||
//
|
||||
// buttonMakeReport
|
||||
//
|
||||
buttonMakeReport.Location = new Point(110, 243);
|
||||
buttonMakeReport.Name = "buttonMakeReport";
|
||||
buttonMakeReport.Size = new Size(211, 43);
|
||||
buttonMakeReport.TabIndex = 6;
|
||||
buttonMakeReport.Text = "Сформировать отчет";
|
||||
buttonMakeReport.UseVisualStyleBackColor = true;
|
||||
buttonMakeReport.Click += buttonMakeReport_Click;
|
||||
//
|
||||
// buttonSelectPathFile
|
||||
//
|
||||
buttonSelectPathFile.Location = new Point(389, 36);
|
||||
buttonSelectPathFile.Name = "buttonSelectPathFile";
|
||||
buttonSelectPathFile.Size = new Size(36, 29);
|
||||
buttonSelectPathFile.TabIndex = 7;
|
||||
buttonSelectPathFile.Text = "...";
|
||||
buttonSelectPathFile.UseVisualStyleBackColor = true;
|
||||
buttonSelectPathFile.Click += buttonSelectPathFile_Click;
|
||||
//
|
||||
// textBoxFilePath
|
||||
//
|
||||
textBoxFilePath.Location = new Point(175, 36);
|
||||
textBoxFilePath.Name = "textBoxFilePath";
|
||||
textBoxFilePath.ReadOnly = true;
|
||||
textBoxFilePath.Size = new Size(209, 27);
|
||||
textBoxFilePath.TabIndex = 8;
|
||||
//
|
||||
// comboBoxProduct
|
||||
//
|
||||
comboBoxProduct.FormattingEnabled = true;
|
||||
comboBoxProduct.Location = new Point(175, 91);
|
||||
comboBoxProduct.Name = "comboBoxProduct";
|
||||
comboBoxProduct.Size = new Size(250, 28);
|
||||
comboBoxProduct.TabIndex = 9;
|
||||
//
|
||||
// FormProductReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(458, 309);
|
||||
Controls.Add(comboBoxProduct);
|
||||
Controls.Add(textBoxFilePath);
|
||||
Controls.Add(buttonSelectPathFile);
|
||||
Controls.Add(buttonMakeReport);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(dateTimePickerEnd);
|
||||
Controls.Add(dateTimePickerBegin);
|
||||
Name = "FormProductReport";
|
||||
Text = "FormProductReport";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DateTimePicker dateTimePickerBegin;
|
||||
private DateTimePicker dateTimePickerEnd;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Label label3;
|
||||
private Label label4;
|
||||
private Button buttonMakeReport;
|
||||
private Button buttonSelectPathFile;
|
||||
private TextBox textBoxFilePath;
|
||||
private ComboBox comboBoxProduct;
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
using ProjectGasStation.Reports;
|
||||
using ProjectGasStation.Repositories;
|
||||
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 ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormProductReport : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
public FormProductReport(IUnityContainer container, IProductRepository productRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
comboBoxProduct.DataSource = productRepository.ReadProduct();
|
||||
comboBoxProduct.DisplayMember = "Name";
|
||||
comboBoxProduct.ValueMember = "Id";
|
||||
}
|
||||
|
||||
private void buttonSelectPathFile_Click(object sender, EventArgs e)
|
||||
{
|
||||
var sfd = new SaveFileDialog()
|
||||
{
|
||||
Filter = "Excel Files | *.xlsx"
|
||||
};
|
||||
if (sfd.ShowDialog() != DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
textBoxFilePath.Text = sfd.FileName;
|
||||
}
|
||||
|
||||
private void buttonMakeReport_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxFilePath.Text))
|
||||
{
|
||||
throw new Exception("Отсутствует имя файла для отчета");
|
||||
}
|
||||
if (comboBoxProduct.SelectedIndex < 0)
|
||||
{
|
||||
throw new Exception("Не выбран товар");
|
||||
}
|
||||
if (dateTimePickerEnd.Value <= dateTimePickerBegin.Value)
|
||||
{
|
||||
throw new Exception("Дата начала должна быть раньше даты окончания");
|
||||
}
|
||||
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, (int)comboBoxProduct.SelectedValue!,
|
||||
dateTimePickerBegin.Value, dateTimePickerEnd.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
ProjectGasStation/ProjectGasStation/Forms/FormProductReport.resx
Normal file
120
ProjectGasStation/ProjectGasStation/Forms/FormProductReport.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>
|
127
ProjectGasStation/ProjectGasStation/Forms/FormProducts.Designer.cs
generated
Normal file
127
ProjectGasStation/ProjectGasStation/Forms/FormProducts.Designer.cs
generated
Normal file
@ -0,0 +1,127 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormProducts
|
||||
{
|
||||
/// <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(FormProducts));
|
||||
panel = new Panel();
|
||||
buttonUpd = new Button();
|
||||
buttonDel = new Button();
|
||||
buttonAdd = new Button();
|
||||
dataGridViewData = new DataGridView();
|
||||
panel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel
|
||||
//
|
||||
panel.Controls.Add(buttonUpd);
|
||||
panel.Controls.Add(buttonDel);
|
||||
panel.Controls.Add(buttonAdd);
|
||||
panel.Dock = DockStyle.Right;
|
||||
panel.Location = new Point(690, 0);
|
||||
panel.Name = "panel";
|
||||
panel.Size = new Size(110, 450);
|
||||
panel.TabIndex = 9;
|
||||
//
|
||||
// buttonUpd
|
||||
//
|
||||
buttonUpd.BackgroundImage = (Image)resources.GetObject("buttonUpd.BackgroundImage");
|
||||
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUpd.Location = new Point(13, 192);
|
||||
buttonUpd.Name = "buttonUpd";
|
||||
buttonUpd.Size = new Size(85, 82);
|
||||
buttonUpd.TabIndex = 2;
|
||||
buttonUpd.UseVisualStyleBackColor = true;
|
||||
buttonUpd.Click += buttonUpd_Click;
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
buttonDel.BackgroundImage = (Image)resources.GetObject("buttonDel.BackgroundImage");
|
||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDel.Location = new Point(13, 104);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(85, 82);
|
||||
buttonDel.TabIndex = 1;
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += buttonDel_Click;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackgroundImage = (Image)resources.GetObject("buttonAdd.BackgroundImage");
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(13, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(85, 86);
|
||||
buttonAdd.TabIndex = 0;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// dataGridViewData
|
||||
//
|
||||
dataGridViewData.AllowUserToAddRows = false;
|
||||
dataGridViewData.AllowUserToDeleteRows = false;
|
||||
dataGridViewData.AllowUserToResizeColumns = false;
|
||||
dataGridViewData.AllowUserToResizeRows = false;
|
||||
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 51;
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(690, 450);
|
||||
dataGridViewData.TabIndex = 10;
|
||||
//
|
||||
// FormProducts
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel);
|
||||
Name = "FormProducts";
|
||||
Text = "Товар";
|
||||
Load += FormProducts_Load;
|
||||
panel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel panel;
|
||||
private Button buttonUpd;
|
||||
private Button buttonDel;
|
||||
private Button buttonAdd;
|
||||
private DataGridView dataGridViewData;
|
||||
}
|
||||
}
|
118
ProjectGasStation/ProjectGasStation/Forms/FormProducts.cs
Normal file
118
ProjectGasStation/ProjectGasStation/Forms/FormProducts.cs
Normal file
@ -0,0 +1,118 @@
|
||||
using ProjectGasStation.Repositories;
|
||||
using ProjectGasStation.Repositories.Implementations;
|
||||
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 ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormProducts : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
private readonly IProductRepository _productRepository;
|
||||
|
||||
public FormProducts(IUnityContainer container, IProductRepository productRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
_productRepository = productRepository ??
|
||||
throw new ArgumentNullException(nameof(productRepository));
|
||||
}
|
||||
private void FormProducts_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormProduct>().ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить запись?", "Удаление",
|
||||
MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_productRepository.DeleteProduct(findId);
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var form = _container.Resolve<FormProduct>();
|
||||
form.Id = findId;
|
||||
form.ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при изменении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _productRepository.ReadProduct();
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridViewData.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
3015
ProjectGasStation/ProjectGasStation/Forms/FormProducts.resx
Normal file
3015
ProjectGasStation/ProjectGasStation/Forms/FormProducts.resx
Normal file
File diff suppressed because it is too large
Load Diff
152
ProjectGasStation/ProjectGasStation/Forms/FormReceipt.Designer.cs
generated
Normal file
152
ProjectGasStation/ProjectGasStation/Forms/FormReceipt.Designer.cs
generated
Normal file
@ -0,0 +1,152 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormReceipt
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
comboBoxSupplier = new ComboBox();
|
||||
labelSupplier = new Label();
|
||||
groupBoxProducts = new GroupBox();
|
||||
dataGridViewProducts = new DataGridView();
|
||||
ColumnProduct = new DataGridViewComboBoxColumn();
|
||||
ColumnQuantity = new DataGridViewTextBoxColumn();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
groupBoxProducts.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBoxSupplier
|
||||
//
|
||||
comboBoxSupplier.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSupplier.FormattingEnabled = true;
|
||||
comboBoxSupplier.Location = new Point(160, 28);
|
||||
comboBoxSupplier.Name = "comboBoxSupplier";
|
||||
comboBoxSupplier.Size = new Size(243, 28);
|
||||
comboBoxSupplier.TabIndex = 6;
|
||||
//
|
||||
// labelSupplier
|
||||
//
|
||||
labelSupplier.AutoSize = true;
|
||||
labelSupplier.Location = new Point(29, 28);
|
||||
labelSupplier.Name = "labelSupplier";
|
||||
labelSupplier.Size = new Size(86, 20);
|
||||
labelSupplier.TabIndex = 5;
|
||||
labelSupplier.Text = "Поставщик";
|
||||
//
|
||||
// groupBoxProducts
|
||||
//
|
||||
groupBoxProducts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBoxProducts.Controls.Add(dataGridViewProducts);
|
||||
groupBoxProducts.Location = new Point(29, 79);
|
||||
groupBoxProducts.Name = "groupBoxProducts";
|
||||
groupBoxProducts.Size = new Size(377, 465);
|
||||
groupBoxProducts.TabIndex = 7;
|
||||
groupBoxProducts.TabStop = false;
|
||||
groupBoxProducts.Text = "Товары";
|
||||
//
|
||||
// dataGridViewProducts
|
||||
//
|
||||
dataGridViewProducts.AllowUserToResizeColumns = false;
|
||||
dataGridViewProducts.AllowUserToResizeRows = false;
|
||||
dataGridViewProducts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewProducts.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnQuantity });
|
||||
dataGridViewProducts.Dock = DockStyle.Fill;
|
||||
dataGridViewProducts.Location = new Point(3, 23);
|
||||
dataGridViewProducts.MultiSelect = false;
|
||||
dataGridViewProducts.Name = "dataGridViewProducts";
|
||||
dataGridViewProducts.RowHeadersVisible = false;
|
||||
dataGridViewProducts.RowHeadersWidth = 51;
|
||||
dataGridViewProducts.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewProducts.Size = new Size(371, 439);
|
||||
dataGridViewProducts.TabIndex = 0;
|
||||
//
|
||||
// ColumnProduct
|
||||
//
|
||||
ColumnProduct.HeaderText = "Товар";
|
||||
ColumnProduct.MinimumWidth = 6;
|
||||
ColumnProduct.Name = "ColumnProduct";
|
||||
//
|
||||
// ColumnQuantity
|
||||
//
|
||||
ColumnQuantity.HeaderText = "Количество";
|
||||
ColumnQuantity.MinimumWidth = 6;
|
||||
ColumnQuantity.Name = "ColumnQuantity";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonSave.Location = new Point(32, 559);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(142, 45);
|
||||
buttonSave.TabIndex = 8;
|
||||
buttonSave.Text = "Сохранение";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCancel.Location = new Point(261, 559);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(142, 42);
|
||||
buttonCancel.TabIndex = 9;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// FormReceipts
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(439, 622);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(groupBoxProducts);
|
||||
Controls.Add(comboBoxSupplier);
|
||||
Controls.Add(labelSupplier);
|
||||
Name = "FormReceipts";
|
||||
Text = "Поставка";
|
||||
groupBoxProducts.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxSupplier;
|
||||
private Label labelSupplier;
|
||||
private GroupBox groupBoxProducts;
|
||||
private DataGridView dataGridViewProducts;
|
||||
private DataGridViewComboBoxColumn ColumnProduct;
|
||||
private DataGridViewTextBoxColumn ColumnQuantity;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
77
ProjectGasStation/ProjectGasStation/Forms/FormReceipt.cs
Normal file
77
ProjectGasStation/ProjectGasStation/Forms/FormReceipt.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using ProjectGasStation.Entities;
|
||||
using ProjectGasStation.Repositories;
|
||||
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.Xml.Linq;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormReceipt : Form
|
||||
{
|
||||
|
||||
private readonly IReceiptRepository _receiptRepository;
|
||||
|
||||
|
||||
public FormReceipt(IReceiptRepository receiptRepository, ISupplierRepository supplierRepository, IProductRepository productRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_receiptRepository = receiptRepository ??
|
||||
throw new ArgumentNullException(nameof(receiptRepository));
|
||||
comboBoxSupplier.DataSource = supplierRepository.ReadSupplier();
|
||||
comboBoxSupplier.DisplayMember = "Name";
|
||||
comboBoxSupplier.ValueMember = "Id";
|
||||
ColumnProduct.DataSource = productRepository.ReadProduct();
|
||||
ColumnProduct.DisplayMember = "Name";
|
||||
ColumnProduct.ValueMember = "Id";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dataGridViewProducts.RowCount < 1 ||
|
||||
comboBoxSupplier.SelectedIndex < 0)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
_receiptRepository.CreateReceipt(Receipt.CreateOperation(0, (int)comboBoxSupplier.SelectedValue!, CreateListReceiptFromDataGrid()));
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
private List<SaleReceiptProduct> CreateListReceiptFromDataGrid()
|
||||
{
|
||||
var list = new List<SaleReceiptProduct>();
|
||||
foreach (DataGridViewRow row in dataGridViewProducts.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnProduct"].Value == null || row.Cells["ColumnQuantity"].Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.Add(SaleReceiptProduct.CreateElement(0, Convert.ToInt32(row.Cells["ColumnProduct"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value)));
|
||||
}
|
||||
return list.GroupBy(x => x.ProductId, x => x.Quantity, (id, counts) =>
|
||||
SaleReceiptProduct.CreateElement(0, id, counts.Sum())).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
126
ProjectGasStation/ProjectGasStation/Forms/FormReceipt.resx
Normal file
126
ProjectGasStation/ProjectGasStation/Forms/FormReceipt.resx
Normal file
@ -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="ColumnProduct.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnQuantity.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
113
ProjectGasStation/ProjectGasStation/Forms/FormReceipts.Designer.cs
generated
Normal file
113
ProjectGasStation/ProjectGasStation/Forms/FormReceipts.Designer.cs
generated
Normal file
@ -0,0 +1,113 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormReceipts
|
||||
{
|
||||
/// <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(FormReceipts));
|
||||
panel = new Panel();
|
||||
buttonDel = new Button();
|
||||
buttonAdd = new Button();
|
||||
dataGridViewData = new DataGridView();
|
||||
panel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel
|
||||
//
|
||||
panel.Controls.Add(buttonDel);
|
||||
panel.Controls.Add(buttonAdd);
|
||||
panel.Dock = DockStyle.Right;
|
||||
panel.Location = new Point(690, 0);
|
||||
panel.Name = "panel";
|
||||
panel.Size = new Size(110, 450);
|
||||
panel.TabIndex = 9;
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
buttonDel.BackgroundImage = (Image)resources.GetObject("buttonDel.BackgroundImage");
|
||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDel.Location = new Point(13, 104);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(85, 82);
|
||||
buttonDel.TabIndex = 1;
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += buttonDel_Click;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackgroundImage = (Image)resources.GetObject("buttonAdd.BackgroundImage");
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(13, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(85, 86);
|
||||
buttonAdd.TabIndex = 0;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// dataGridViewData
|
||||
//
|
||||
dataGridViewData.AllowUserToAddRows = false;
|
||||
dataGridViewData.AllowUserToDeleteRows = false;
|
||||
dataGridViewData.AllowUserToResizeColumns = false;
|
||||
dataGridViewData.AllowUserToResizeRows = false;
|
||||
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 51;
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(690, 450);
|
||||
dataGridViewData.TabIndex = 10;
|
||||
//
|
||||
// FormReceipts
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel);
|
||||
Name = "FormReceipts";
|
||||
Text = "FormReceipts";
|
||||
Load += FormReceipts_Load;
|
||||
panel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel panel;
|
||||
private Button buttonDel;
|
||||
private Button buttonAdd;
|
||||
private DataGridView dataGridViewData;
|
||||
}
|
||||
}
|
108
ProjectGasStation/ProjectGasStation/Forms/FormReceipts.cs
Normal file
108
ProjectGasStation/ProjectGasStation/Forms/FormReceipts.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using Npgsql;
|
||||
using ProjectGasStation.Repositories;
|
||||
using ProjectGasStation.Repositories.Implementations;
|
||||
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 ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormReceipts : Form
|
||||
{
|
||||
|
||||
private readonly IUnityContainer _container;
|
||||
private readonly IReceiptRepository _receiptRepository;
|
||||
|
||||
|
||||
public FormReceipts(IUnityContainer container, IReceiptRepository receiptRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
_receiptRepository = receiptRepository ??
|
||||
throw new ArgumentNullException(nameof(receiptRepository));
|
||||
}
|
||||
|
||||
private void FormReceipts_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormReceipt>().ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void buttonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить запись?", "Удаление",
|
||||
MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
_receiptRepository.DeleteReceipt(findId);
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _receiptRepository.ReadReceipt();
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridViewData.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
id =
|
||||
Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
2973
ProjectGasStation/ProjectGasStation/Forms/FormReceipts.resx
Normal file
2973
ProjectGasStation/ProjectGasStation/Forms/FormReceipts.resx
Normal file
File diff suppressed because it is too large
Load Diff
152
ProjectGasStation/ProjectGasStation/Forms/FormSale.Designer.cs
generated
Normal file
152
ProjectGasStation/ProjectGasStation/Forms/FormSale.Designer.cs
generated
Normal file
@ -0,0 +1,152 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormSale
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
buttonCancel = new Button();
|
||||
buttonSave = new Button();
|
||||
groupBoxProducts = new GroupBox();
|
||||
dataGridViewProducts = new DataGridView();
|
||||
ColumnProduct = new DataGridViewComboBoxColumn();
|
||||
ColumnQuantity = new DataGridViewTextBoxColumn();
|
||||
comboBoxWorker = new ComboBox();
|
||||
labelWorker = new Label();
|
||||
groupBoxProducts.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCancel.Location = new Point(256, 457);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(142, 42);
|
||||
buttonCancel.TabIndex = 14;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonSave.Location = new Point(27, 457);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(142, 45);
|
||||
buttonSave.TabIndex = 13;
|
||||
buttonSave.Text = "Сохранение";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// groupBoxProducts
|
||||
//
|
||||
groupBoxProducts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBoxProducts.Controls.Add(dataGridViewProducts);
|
||||
groupBoxProducts.Location = new Point(24, 92);
|
||||
groupBoxProducts.Name = "groupBoxProducts";
|
||||
groupBoxProducts.Size = new Size(377, 350);
|
||||
groupBoxProducts.TabIndex = 12;
|
||||
groupBoxProducts.TabStop = false;
|
||||
groupBoxProducts.Text = "Товары";
|
||||
//
|
||||
// dataGridViewProducts
|
||||
//
|
||||
dataGridViewProducts.AllowUserToResizeColumns = false;
|
||||
dataGridViewProducts.AllowUserToResizeRows = false;
|
||||
dataGridViewProducts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewProducts.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnQuantity });
|
||||
dataGridViewProducts.Dock = DockStyle.Fill;
|
||||
dataGridViewProducts.Location = new Point(3, 23);
|
||||
dataGridViewProducts.MultiSelect = false;
|
||||
dataGridViewProducts.Name = "dataGridViewProducts";
|
||||
dataGridViewProducts.RowHeadersVisible = false;
|
||||
dataGridViewProducts.RowHeadersWidth = 51;
|
||||
dataGridViewProducts.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewProducts.Size = new Size(371, 324);
|
||||
dataGridViewProducts.TabIndex = 0;
|
||||
//
|
||||
// ColumnProduct
|
||||
//
|
||||
ColumnProduct.HeaderText = "Товар";
|
||||
ColumnProduct.MinimumWidth = 6;
|
||||
ColumnProduct.Name = "ColumnProduct";
|
||||
//
|
||||
// ColumnQuantity
|
||||
//
|
||||
ColumnQuantity.HeaderText = "Количество";
|
||||
ColumnQuantity.MinimumWidth = 6;
|
||||
ColumnQuantity.Name = "ColumnQuantity";
|
||||
//
|
||||
// comboBoxWorker
|
||||
//
|
||||
comboBoxWorker.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxWorker.FormattingEnabled = true;
|
||||
comboBoxWorker.Location = new Point(155, 41);
|
||||
comboBoxWorker.Name = "comboBoxWorker";
|
||||
comboBoxWorker.Size = new Size(243, 28);
|
||||
comboBoxWorker.TabIndex = 11;
|
||||
//
|
||||
// labelWorker
|
||||
//
|
||||
labelWorker.AutoSize = true;
|
||||
labelWorker.Location = new Point(24, 41);
|
||||
labelWorker.Name = "labelWorker";
|
||||
labelWorker.Size = new Size(74, 20);
|
||||
labelWorker.TabIndex = 10;
|
||||
labelWorker.Text = "Работник";
|
||||
//
|
||||
// FormSale
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(425, 542);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(groupBoxProducts);
|
||||
Controls.Add(comboBoxWorker);
|
||||
Controls.Add(labelWorker);
|
||||
Name = "FormSale";
|
||||
Text = "FormSale";
|
||||
groupBoxProducts.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
private GroupBox groupBoxProducts;
|
||||
private DataGridView dataGridViewProducts;
|
||||
private DataGridViewComboBoxColumn ColumnProduct;
|
||||
private DataGridViewTextBoxColumn ColumnQuantity;
|
||||
private ComboBox comboBoxWorker;
|
||||
private Label labelWorker;
|
||||
}
|
||||
}
|
70
ProjectGasStation/ProjectGasStation/Forms/FormSale.cs
Normal file
70
ProjectGasStation/ProjectGasStation/Forms/FormSale.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using ProjectGasStation.Entities;
|
||||
using ProjectGasStation.Repositories;
|
||||
using ProjectGasStation.Repositories.Implementations;
|
||||
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 ProjectGasStation.Forms
|
||||
{
|
||||
|
||||
public partial class FormSale : Form
|
||||
{
|
||||
|
||||
private readonly ISaleRepository _saleRepository;
|
||||
|
||||
public FormSale(ISaleRepository saleRepository, IWorkerRepository workerRepository, IProductRepository productRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_saleRepository = saleRepository ??
|
||||
throw new ArgumentNullException(nameof(saleRepository));
|
||||
comboBoxWorker.DataSource = workerRepository.ReadWorker();
|
||||
comboBoxWorker.DisplayMember = "Name";
|
||||
comboBoxWorker.ValueMember = "Id";
|
||||
ColumnProduct.DataSource = productRepository.ReadProduct();
|
||||
ColumnProduct.DisplayMember = "Name";
|
||||
ColumnProduct.ValueMember = "Id";
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dataGridViewProducts.RowCount < 1 ||
|
||||
comboBoxWorker.SelectedIndex < 0)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
_saleRepository.CreateSale(Sale.CreateOperation(0, (int)comboBoxWorker.SelectedValue!, CreateListSaleFromDataGrid()));
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
private List<SaleReceiptProduct> CreateListSaleFromDataGrid()
|
||||
{
|
||||
var list = new List<SaleReceiptProduct>();
|
||||
foreach (DataGridViewRow row in dataGridViewProducts.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnProduct"].Value == null || row.Cells["ColumnQuantity"].Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
list.Add(SaleReceiptProduct.CreateElement(0, Convert.ToInt32(row.Cells["ColumnProduct"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value)));
|
||||
}
|
||||
return list.GroupBy(x => x.ProductId, x => x.Quantity, (id, counts) =>
|
||||
SaleReceiptProduct.CreateElement(0, id, counts.Sum())).ToList();
|
||||
}
|
||||
}
|
||||
}
|
132
ProjectGasStation/ProjectGasStation/Forms/FormSale.resx
Normal file
132
ProjectGasStation/ProjectGasStation/Forms/FormSale.resx
Normal file
@ -0,0 +1,132 @@
|
||||
<?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="ColumnProduct.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnQuantity.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnProduct.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnQuantity.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
107
ProjectGasStation/ProjectGasStation/Forms/FormSaleDistributionReport.Designer.cs
generated
Normal file
107
ProjectGasStation/ProjectGasStation/Forms/FormSaleDistributionReport.Designer.cs
generated
Normal file
@ -0,0 +1,107 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormSaleDistributionReport
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
buttonSelectFileName = new Button();
|
||||
buttonMakeReport = new Button();
|
||||
labelFileName = new Label();
|
||||
label2 = new Label();
|
||||
dateTimePicker = new DateTimePicker();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonSelectFileName
|
||||
//
|
||||
buttonSelectFileName.Location = new Point(30, 34);
|
||||
buttonSelectFileName.Name = "buttonSelectFileName";
|
||||
buttonSelectFileName.Size = new Size(94, 29);
|
||||
buttonSelectFileName.TabIndex = 0;
|
||||
buttonSelectFileName.Text = "Выбрать";
|
||||
buttonSelectFileName.UseVisualStyleBackColor = true;
|
||||
buttonSelectFileName.Click += buttonSelectFileName_Click;
|
||||
//
|
||||
// buttonMakeReport
|
||||
//
|
||||
buttonMakeReport.Location = new Point(119, 137);
|
||||
buttonMakeReport.Name = "buttonMakeReport";
|
||||
buttonMakeReport.Size = new Size(153, 37);
|
||||
buttonMakeReport.TabIndex = 1;
|
||||
buttonMakeReport.Text = "Сформировать";
|
||||
buttonMakeReport.UseVisualStyleBackColor = true;
|
||||
buttonMakeReport.Click += buttonMakeReport_Click;
|
||||
//
|
||||
// labelFileName
|
||||
//
|
||||
labelFileName.AutoSize = true;
|
||||
labelFileName.Location = new Point(152, 38);
|
||||
labelFileName.Name = "labelFileName";
|
||||
labelFileName.Size = new Size(45, 20);
|
||||
labelFileName.TabIndex = 2;
|
||||
labelFileName.Text = "Файл";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(30, 92);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(41, 20);
|
||||
label2.TabIndex = 3;
|
||||
label2.Text = "Дата";
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
dateTimePicker.Location = new Point(96, 87);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(258, 27);
|
||||
dateTimePicker.TabIndex = 4;
|
||||
//
|
||||
// FormSaleDistributionReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(387, 186);
|
||||
Controls.Add(dateTimePicker);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(labelFileName);
|
||||
Controls.Add(buttonMakeReport);
|
||||
Controls.Add(buttonSelectFileName);
|
||||
Name = "FormSaleDistributionReport";
|
||||
Text = "FormSaleDistributionReport";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonSelectFileName;
|
||||
private Button buttonMakeReport;
|
||||
private Label labelFileName;
|
||||
private Label label2;
|
||||
private DateTimePicker dateTimePicker;
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
using ProjectGasStation.Reports;
|
||||
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 ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormSaleDistributionReport : Form
|
||||
{
|
||||
|
||||
private string _fileName = string.Empty;
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
public FormSaleDistributionReport(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
|
||||
}
|
||||
|
||||
private void buttonSelectFileName_Click(object sender, EventArgs e)
|
||||
{
|
||||
var sfd = new SaveFileDialog()
|
||||
{
|
||||
Filter = "Pdf Files | *.pdf"
|
||||
};
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_fileName = sfd.FileName;
|
||||
labelFileName.Text = Path.GetFileName(_fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonMakeReport_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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
113
ProjectGasStation/ProjectGasStation/Forms/FormSales.Designer.cs
generated
Normal file
113
ProjectGasStation/ProjectGasStation/Forms/FormSales.Designer.cs
generated
Normal file
@ -0,0 +1,113 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormSales
|
||||
{
|
||||
/// <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(FormSales));
|
||||
panel = new Panel();
|
||||
buttonDel = new Button();
|
||||
buttonAdd = new Button();
|
||||
dataGridViewData = new DataGridView();
|
||||
panel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel
|
||||
//
|
||||
panel.Controls.Add(buttonDel);
|
||||
panel.Controls.Add(buttonAdd);
|
||||
panel.Dock = DockStyle.Right;
|
||||
panel.Location = new Point(690, 0);
|
||||
panel.Name = "panel";
|
||||
panel.Size = new Size(110, 450);
|
||||
panel.TabIndex = 10;
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
buttonDel.BackgroundImage = (Image)resources.GetObject("buttonDel.BackgroundImage");
|
||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDel.Location = new Point(13, 104);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(85, 82);
|
||||
buttonDel.TabIndex = 1;
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += buttonDel_Click;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackgroundImage = (Image)resources.GetObject("buttonAdd.BackgroundImage");
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(13, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(85, 86);
|
||||
buttonAdd.TabIndex = 0;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// dataGridViewData
|
||||
//
|
||||
dataGridViewData.AllowUserToAddRows = false;
|
||||
dataGridViewData.AllowUserToDeleteRows = false;
|
||||
dataGridViewData.AllowUserToResizeColumns = false;
|
||||
dataGridViewData.AllowUserToResizeRows = false;
|
||||
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 51;
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(690, 450);
|
||||
dataGridViewData.TabIndex = 11;
|
||||
//
|
||||
// FormSales
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel);
|
||||
Name = "FormSales";
|
||||
Text = "FormSales";
|
||||
Load += FormSales_Load;
|
||||
panel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel panel;
|
||||
private Button buttonDel;
|
||||
private Button buttonAdd;
|
||||
private DataGridView dataGridViewData;
|
||||
}
|
||||
}
|
96
ProjectGasStation/ProjectGasStation/Forms/FormSales.cs
Normal file
96
ProjectGasStation/ProjectGasStation/Forms/FormSales.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using ProjectGasStation.Repositories;
|
||||
using ProjectGasStation.Repositories.Implementations;
|
||||
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 ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormSales : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
private readonly ISaleRepository _saleRepository;
|
||||
|
||||
public FormSales(IUnityContainer container, ISaleRepository saleRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
_saleRepository = saleRepository ??
|
||||
throw new ArgumentNullException(nameof(saleRepository));
|
||||
}
|
||||
|
||||
private void FormSales_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormSale>().ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить запись?", "Удаление",
|
||||
MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_saleRepository.DeleteSale(findId);
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _saleRepository.ReadSale();
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridViewData.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
id =
|
||||
Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
2973
ProjectGasStation/ProjectGasStation/Forms/FormSales.resx
Normal file
2973
ProjectGasStation/ProjectGasStation/Forms/FormSales.resx
Normal file
File diff suppressed because it is too large
Load Diff
140
ProjectGasStation/ProjectGasStation/Forms/FormSupplier.Designer.cs
generated
Normal file
140
ProjectGasStation/ProjectGasStation/Forms/FormSupplier.Designer.cs
generated
Normal file
@ -0,0 +1,140 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormSupplier
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
labelName = new Label();
|
||||
labelPhoneNumber = new Label();
|
||||
labelAddress = new Label();
|
||||
buttonCancel = new Button();
|
||||
buttonSave = new Button();
|
||||
textBoxSupplierName = new TextBox();
|
||||
textBoxSupplierPhoneNumber = new TextBox();
|
||||
textBoxSupplierAddress = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(37, 35);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(42, 20);
|
||||
labelName.TabIndex = 0;
|
||||
labelName.Text = "ФИО";
|
||||
//
|
||||
// labelPhoneNumber
|
||||
//
|
||||
labelPhoneNumber.AutoSize = true;
|
||||
labelPhoneNumber.Location = new Point(37, 95);
|
||||
labelPhoneNumber.Name = "labelPhoneNumber";
|
||||
labelPhoneNumber.Size = new Size(86, 20);
|
||||
labelPhoneNumber.TabIndex = 1;
|
||||
labelPhoneNumber.Text = "Тел. номер";
|
||||
//
|
||||
// labelAddress
|
||||
//
|
||||
labelAddress.AutoSize = true;
|
||||
labelAddress.Location = new Point(37, 164);
|
||||
labelAddress.Name = "labelAddress";
|
||||
labelAddress.Size = new Size(51, 20);
|
||||
labelAddress.TabIndex = 2;
|
||||
labelAddress.Text = "Адрес";
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(244, 220);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(180, 46);
|
||||
buttonCancel.TabIndex = 3;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(37, 220);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(180, 46);
|
||||
buttonSave.TabIndex = 4;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// textBoxSupplierName
|
||||
//
|
||||
textBoxSupplierName.Location = new Point(161, 32);
|
||||
textBoxSupplierName.Name = "textBoxSupplierName";
|
||||
textBoxSupplierName.Size = new Size(263, 27);
|
||||
textBoxSupplierName.TabIndex = 5;
|
||||
//
|
||||
// textBoxSupplierPhoneNumber
|
||||
//
|
||||
textBoxSupplierPhoneNumber.Location = new Point(161, 88);
|
||||
textBoxSupplierPhoneNumber.Name = "textBoxSupplierPhoneNumber";
|
||||
textBoxSupplierPhoneNumber.Size = new Size(263, 27);
|
||||
textBoxSupplierPhoneNumber.TabIndex = 6;
|
||||
//
|
||||
// textBoxSupplierAddress
|
||||
//
|
||||
textBoxSupplierAddress.Location = new Point(161, 157);
|
||||
textBoxSupplierAddress.Name = "textBoxSupplierAddress";
|
||||
textBoxSupplierAddress.Size = new Size(263, 27);
|
||||
textBoxSupplierAddress.TabIndex = 7;
|
||||
//
|
||||
// FormSupplier
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(467, 298);
|
||||
Controls.Add(textBoxSupplierAddress);
|
||||
Controls.Add(textBoxSupplierPhoneNumber);
|
||||
Controls.Add(textBoxSupplierName);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(labelAddress);
|
||||
Controls.Add(labelPhoneNumber);
|
||||
Controls.Add(labelName);
|
||||
Name = "FormSupplier";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Поставщик";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelName;
|
||||
private Label labelPhoneNumber;
|
||||
private Label labelAddress;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
private TextBox textBoxSupplierName;
|
||||
private TextBox textBoxSupplierPhoneNumber;
|
||||
private TextBox textBoxSupplierAddress;
|
||||
}
|
||||
}
|
86
ProjectGasStation/ProjectGasStation/Forms/FormSupplier.cs
Normal file
86
ProjectGasStation/ProjectGasStation/Forms/FormSupplier.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using ProjectGasStation.Entities.Enums;
|
||||
using ProjectGasStation.Entities;
|
||||
using ProjectGasStation.Repositories;
|
||||
using ProjectGasStation.Repositories.Implementations;
|
||||
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 ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormSupplier : Form
|
||||
{
|
||||
private readonly ISupplierRepository _supplierRepository;
|
||||
private int? _supplierId;
|
||||
|
||||
public int Id
|
||||
{
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
var supplier = _supplierRepository.ReadSupplierById(value);
|
||||
if (supplier == null)
|
||||
{
|
||||
throw new InvalidDataException(nameof(supplier));
|
||||
}
|
||||
|
||||
textBoxSupplierName.Text = supplier.Name;
|
||||
textBoxSupplierPhoneNumber.Text = supplier.PhoneNumber;
|
||||
textBoxSupplierAddress.Text = supplier.Address;
|
||||
_supplierId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public FormSupplier(ISupplierRepository supplierRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_supplierRepository = supplierRepository ??
|
||||
throw new ArgumentNullException(nameof(supplierRepository));
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxSupplierName.Text) ||
|
||||
string.IsNullOrWhiteSpace(textBoxSupplierPhoneNumber.Text) ||
|
||||
string.IsNullOrWhiteSpace(textBoxSupplierAddress.Text))
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
|
||||
if (_supplierId.HasValue)
|
||||
{
|
||||
_supplierRepository.UpdateSupplier(CreateSupplier(_supplierId.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
_supplierRepository.CreateSupplier(CreateSupplier(0));
|
||||
}
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
||||
private Supplier CreateSupplier(int id) => Supplier.CreateEntity(id,
|
||||
textBoxSupplierName.Text, textBoxSupplierPhoneNumber.Text, textBoxSupplierAddress.Text);
|
||||
}
|
||||
}
|
120
ProjectGasStation/ProjectGasStation/Forms/FormSupplier.resx
Normal file
120
ProjectGasStation/ProjectGasStation/Forms/FormSupplier.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>
|
127
ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.Designer.cs
generated
Normal file
127
ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.Designer.cs
generated
Normal file
@ -0,0 +1,127 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormSuppliers
|
||||
{
|
||||
/// <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(FormSuppliers));
|
||||
panel = new Panel();
|
||||
buttonUpd = new Button();
|
||||
buttonDel = new Button();
|
||||
buttonAdd = new Button();
|
||||
dataGridViewData = new DataGridView();
|
||||
panel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel
|
||||
//
|
||||
panel.Controls.Add(buttonUpd);
|
||||
panel.Controls.Add(buttonDel);
|
||||
panel.Controls.Add(buttonAdd);
|
||||
panel.Dock = DockStyle.Right;
|
||||
panel.Location = new Point(626, 0);
|
||||
panel.Name = "panel";
|
||||
panel.Size = new Size(110, 477);
|
||||
panel.TabIndex = 8;
|
||||
//
|
||||
// buttonUpd
|
||||
//
|
||||
buttonUpd.BackgroundImage = (Image)resources.GetObject("buttonUpd.BackgroundImage");
|
||||
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUpd.Location = new Point(13, 192);
|
||||
buttonUpd.Name = "buttonUpd";
|
||||
buttonUpd.Size = new Size(85, 82);
|
||||
buttonUpd.TabIndex = 2;
|
||||
buttonUpd.UseVisualStyleBackColor = true;
|
||||
buttonUpd.Click += buttonUpd_Click;
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
buttonDel.BackgroundImage = (Image)resources.GetObject("buttonDel.BackgroundImage");
|
||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDel.Location = new Point(13, 104);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(85, 82);
|
||||
buttonDel.TabIndex = 1;
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += buttonDel_Click;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackgroundImage = (Image)resources.GetObject("buttonAdd.BackgroundImage");
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(13, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(85, 86);
|
||||
buttonAdd.TabIndex = 0;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// dataGridViewData
|
||||
//
|
||||
dataGridViewData.AllowUserToAddRows = false;
|
||||
dataGridViewData.AllowUserToDeleteRows = false;
|
||||
dataGridViewData.AllowUserToResizeColumns = false;
|
||||
dataGridViewData.AllowUserToResizeRows = false;
|
||||
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 51;
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(626, 477);
|
||||
dataGridViewData.TabIndex = 9;
|
||||
//
|
||||
// FormSuppliers
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(736, 477);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel);
|
||||
Name = "FormSuppliers";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Поставщик";
|
||||
Load += FormSuppliers_Load;
|
||||
panel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
private Panel panel;
|
||||
private Button buttonUpd;
|
||||
private Button buttonAdd;
|
||||
private Button buttonDel;
|
||||
private DataGridView dataGridViewData;
|
||||
}
|
||||
}
|
120
ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.cs
Normal file
120
ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.cs
Normal file
@ -0,0 +1,120 @@
|
||||
using ProjectGasStation.Entities;
|
||||
using ProjectGasStation.Repositories;
|
||||
using ProjectGasStation.Repositories.Implementations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormSuppliers : Form
|
||||
{
|
||||
|
||||
private readonly IUnityContainer _container;
|
||||
private readonly ISupplierRepository _supplierRepository;
|
||||
|
||||
|
||||
|
||||
|
||||
public FormSuppliers(IUnityContainer container, ISupplierRepository supplierRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
_supplierRepository = supplierRepository ??
|
||||
throw new ArgumentNullException(nameof(supplierRepository));
|
||||
}
|
||||
|
||||
private void FormSuppliers_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormSupplier>().ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_supplierRepository.DeleteSupplier(findId);
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var form = _container.Resolve<FormSupplier>();
|
||||
form.Id = findId;
|
||||
form.ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _supplierRepository.ReadSupplier();
|
||||
|
||||
private bool TryGetIdentifierFromSelectRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridViewData.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
3015
ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.resx
Normal file
3015
ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.resx
Normal file
File diff suppressed because it is too large
Load Diff
119
ProjectGasStation/ProjectGasStation/Forms/FormWorker.Designer.cs
generated
Normal file
119
ProjectGasStation/ProjectGasStation/Forms/FormWorker.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormWorker
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
comboBoxJobTitle = new ComboBox();
|
||||
labelName = new Label();
|
||||
labelJobTitle = new Label();
|
||||
textBoxName = new TextBox();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBoxJobTitle
|
||||
//
|
||||
comboBoxJobTitle.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxJobTitle.FormattingEnabled = true;
|
||||
comboBoxJobTitle.Location = new Point(164, 92);
|
||||
comboBoxJobTitle.Name = "comboBoxJobTitle";
|
||||
comboBoxJobTitle.Size = new Size(151, 28);
|
||||
comboBoxJobTitle.TabIndex = 0;
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(30, 31);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(42, 20);
|
||||
labelName.TabIndex = 1;
|
||||
labelName.Text = "ФИО";
|
||||
//
|
||||
// labelJobTitle
|
||||
//
|
||||
labelJobTitle.AutoSize = true;
|
||||
labelJobTitle.Location = new Point(30, 95);
|
||||
labelJobTitle.Name = "labelJobTitle";
|
||||
labelJobTitle.Size = new Size(86, 20);
|
||||
labelJobTitle.TabIndex = 2;
|
||||
labelJobTitle.Text = "Должность";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(164, 24);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(151, 27);
|
||||
textBoxName.TabIndex = 4;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(30, 149);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(119, 46);
|
||||
buttonSave.TabIndex = 5;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(196, 149);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(119, 46);
|
||||
buttonCancel.TabIndex = 6;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// FormWorker
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(352, 228);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(labelJobTitle);
|
||||
Controls.Add(labelName);
|
||||
Controls.Add(comboBoxJobTitle);
|
||||
Name = "FormWorker";
|
||||
Text = "Работник";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxJobTitle;
|
||||
private Label labelName;
|
||||
private Label labelJobTitle;
|
||||
private TextBox textBoxName;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
87
ProjectGasStation/ProjectGasStation/Forms/FormWorker.cs
Normal file
87
ProjectGasStation/ProjectGasStation/Forms/FormWorker.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using ProjectGasStation.Entities;
|
||||
using ProjectGasStation.Entities.Enums;
|
||||
using ProjectGasStation.Repositories;
|
||||
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 ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormWorker : Form
|
||||
{
|
||||
|
||||
private readonly IWorkerRepository _workerRepository;
|
||||
private int? _workerId;
|
||||
|
||||
public int Id
|
||||
{
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
var worker = _workerRepository.ReadWorkerById(value);
|
||||
if (worker == null)
|
||||
{
|
||||
throw new
|
||||
InvalidDataException(nameof(worker));
|
||||
}
|
||||
textBoxName.Text = worker.Name;
|
||||
comboBoxJobTitle.SelectedItem = worker.JobTitle;
|
||||
_workerId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public FormWorker(IWorkerRepository workerRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_workerRepository = workerRepository ??
|
||||
throw new ArgumentNullException(nameof(workerRepository));
|
||||
comboBoxJobTitle.DataSource = Enum.GetValues(typeof(JobTitle));
|
||||
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxName.Text)
|
||||
|| comboBoxJobTitle.SelectedIndex < 1)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
if (_workerId.HasValue)
|
||||
{
|
||||
_workerRepository.UpdateWorker(CreateWorker(_workerId.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
_workerRepository.CreateWorker(CreateWorker(0));
|
||||
}
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
||||
|
||||
private Worker CreateWorker(int id) => Worker.CreateEntity(id, textBoxName.Text, (JobTitle)comboBoxJobTitle.SelectedItem!);
|
||||
}
|
||||
}
|
120
ProjectGasStation/ProjectGasStation/Forms/FormWorker.resx
Normal file
120
ProjectGasStation/ProjectGasStation/Forms/FormWorker.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>
|
127
ProjectGasStation/ProjectGasStation/Forms/FormWorkers.Designer.cs
generated
Normal file
127
ProjectGasStation/ProjectGasStation/Forms/FormWorkers.Designer.cs
generated
Normal file
@ -0,0 +1,127 @@
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
partial class FormWorkers
|
||||
{
|
||||
/// <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(FormWorkers));
|
||||
panel = new Panel();
|
||||
buttonUpd = new Button();
|
||||
buttonDel = new Button();
|
||||
buttonAdd = new Button();
|
||||
dataGridViewData = new DataGridView();
|
||||
panel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel
|
||||
//
|
||||
panel.Controls.Add(buttonUpd);
|
||||
panel.Controls.Add(buttonDel);
|
||||
panel.Controls.Add(buttonAdd);
|
||||
panel.Dock = DockStyle.Right;
|
||||
panel.Location = new Point(690, 0);
|
||||
panel.Name = "panel";
|
||||
panel.Size = new Size(110, 450);
|
||||
panel.TabIndex = 0;
|
||||
//
|
||||
// buttonUpd
|
||||
//
|
||||
buttonUpd.BackgroundImage = (Image)resources.GetObject("buttonUpd.BackgroundImage");
|
||||
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUpd.Location = new Point(13, 192);
|
||||
buttonUpd.Name = "buttonUpd";
|
||||
buttonUpd.Size = new Size(85, 82);
|
||||
buttonUpd.TabIndex = 3;
|
||||
buttonUpd.UseVisualStyleBackColor = true;
|
||||
buttonUpd.Click += buttonUpd_Click;
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
buttonDel.BackgroundImage = (Image)resources.GetObject("buttonDel.BackgroundImage");
|
||||
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDel.Location = new Point(13, 104);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(85, 82);
|
||||
buttonDel.TabIndex = 2;
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += buttonDel_Click;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.BackgroundImage = (Image)resources.GetObject("buttonAdd.BackgroundImage");
|
||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonAdd.Location = new Point(13, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(85, 86);
|
||||
buttonAdd.TabIndex = 1;
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// dataGridViewData
|
||||
//
|
||||
dataGridViewData.AllowUserToAddRows = false;
|
||||
dataGridViewData.AllowUserToDeleteRows = false;
|
||||
dataGridViewData.AllowUserToResizeColumns = false;
|
||||
dataGridViewData.AllowUserToResizeRows = false;
|
||||
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewData.Dock = DockStyle.Fill;
|
||||
dataGridViewData.Location = new Point(0, 0);
|
||||
dataGridViewData.MultiSelect = false;
|
||||
dataGridViewData.Name = "dataGridViewData";
|
||||
dataGridViewData.ReadOnly = true;
|
||||
dataGridViewData.RowHeadersVisible = false;
|
||||
dataGridViewData.RowHeadersWidth = 51;
|
||||
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewData.Size = new Size(690, 450);
|
||||
dataGridViewData.TabIndex = 10;
|
||||
//
|
||||
// FormWorkers
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(dataGridViewData);
|
||||
Controls.Add(panel);
|
||||
Name = "FormWorkers";
|
||||
Text = "Работник";
|
||||
Load += FormWorkers_Load;
|
||||
panel.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel panel;
|
||||
private Button buttonAdd;
|
||||
private Button buttonDel;
|
||||
private Button buttonUpd;
|
||||
private DataGridView dataGridViewData;
|
||||
}
|
||||
}
|
116
ProjectGasStation/ProjectGasStation/Forms/FormWorkers.cs
Normal file
116
ProjectGasStation/ProjectGasStation/Forms/FormWorkers.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using ProjectGasStation.Repositories;
|
||||
using ProjectGasStation.Repositories.Implementations;
|
||||
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.Xml.Linq;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectGasStation.Forms
|
||||
{
|
||||
public partial class FormWorkers : Form
|
||||
{
|
||||
|
||||
private readonly IUnityContainer _container;
|
||||
private readonly IWorkerRepository _workerRepository;
|
||||
|
||||
public FormWorkers(IUnityContainer container, IWorkerRepository workerRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
_workerRepository = workerRepository ??
|
||||
throw new ArgumentNullException(nameof(workerRepository));
|
||||
}
|
||||
|
||||
private void FormWorkers_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormWorker>().ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_workerRepository.DeleteWorker(findId);
|
||||
LoadList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonUpd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectRow(out var findId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var form = _container.Resolve<FormWorker>();
|
||||
form.Id = findId;
|
||||
form.ShowDialog();
|
||||
LoadList();
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _workerRepository.ReadWorker();
|
||||
|
||||
private bool TryGetIdentifierFromSelectRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridViewData.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
3015
ProjectGasStation/ProjectGasStation/Forms/FormWorkers.resx
Normal file
3015
ProjectGasStation/ProjectGasStation/Forms/FormWorkers.resx
Normal file
File diff suppressed because it is too large
Load Diff
60
ProjectGasStation/ProjectGasStation/Program.cs
Normal file
60
ProjectGasStation/ProjectGasStation/Program.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectGasStation.Repositories;
|
||||
using ProjectGasStation.Repositories.Implementations;
|
||||
using Serilog;
|
||||
using Unity;
|
||||
using Unity.Lifetime;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
namespace ProjectGasStation
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(CreateUnityContainer().Resolve<FormGasStation>());
|
||||
}
|
||||
|
||||
private static IUnityContainer CreateUnityContainer()
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||
|
||||
container.RegisterType<IProductRepository, ProductRepository>();
|
||||
container.RegisterType<IReceiptRepository, ReceiptRepository>();
|
||||
container.RegisterType<ISaleRepository, SaleRepository>();
|
||||
container.RegisterType<ISupplierRepository, SupplierRepository>();
|
||||
container.RegisterType<IWorkerRepository, WorkerRepository>();
|
||||
|
||||
container.RegisterType<IConectionString, ConectionString>(new SingletonLifetimeManager());
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
50
ProjectGasStation/ProjectGasStation/ProjectGasStation.csproj
Normal file
50
ProjectGasStation/ProjectGasStation/ProjectGasStation.csproj
Normal file
@ -0,0 +1,50 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</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.Configuration.Json" 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.Standard" Version="1.51.15" />
|
||||
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
63
ProjectGasStation/ProjectGasStation/Properties/Resources.Designer.cs
generated
Normal file
63
ProjectGasStation/ProjectGasStation/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ProjectGasStation.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("ProjectGasStation.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
ProjectGasStation/ProjectGasStation/Properties/Resources.resx
Normal file
120
ProjectGasStation/ProjectGasStation/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>
|
47
ProjectGasStation/ProjectGasStation/Reports/ChartReport.cs
Normal file
47
ProjectGasStation/ProjectGasStation/Reports/ChartReport.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectGasStation.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Reports;
|
||||
|
||||
internal class ChartReport
|
||||
{
|
||||
private readonly ISaleRepository _saleRepository;
|
||||
private readonly ILogger<ChartReport> _logger;
|
||||
public ChartReport(ISaleRepository saleRepository, ILogger<ChartReport> logger)
|
||||
{
|
||||
_saleRepository = saleRepository
|
||||
?? throw new ArgumentNullException(nameof(saleRepository));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
public bool CreateChart(string filePath, DateTime dateTime)
|
||||
{
|
||||
try
|
||||
{
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Количество продаж каждого работника")
|
||||
.AddPieChart("Работники", GetData(dateTime))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
return _saleRepository
|
||||
.ReadSale()
|
||||
.Where(x => x.DateTime.Date == dateTime.Date)
|
||||
.GroupBy(x => x.WorkerId, (key, group) => new { Id = key, Count = group.Sum(y => y.SaleProducts.Count()) })
|
||||
.Select(x => (x.Id.ToString(), (double)x.Count))
|
||||
.ToList();
|
||||
}
|
||||
}
|
96
ProjectGasStation/ProjectGasStation/Reports/DocReport.cs
Normal file
96
ProjectGasStation/ProjectGasStation/Reports/DocReport.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectGasStation.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Reports;
|
||||
|
||||
internal class DocReport
|
||||
{
|
||||
private readonly IProductRepository _productRepository;
|
||||
private readonly IWorkerRepository _workerRepository;
|
||||
private readonly ISupplierRepository _supplierRepository;
|
||||
private readonly ILogger<DocReport> _logger;
|
||||
public DocReport(IProductRepository productRepository, IWorkerRepository
|
||||
workerRepository, ISupplierRepository supplierRepository, ILogger<DocReport> logger)
|
||||
{
|
||||
_productRepository = productRepository ??
|
||||
throw new ArgumentNullException(nameof(productRepository));
|
||||
_workerRepository = workerRepository ??
|
||||
throw new ArgumentNullException(nameof(workerRepository));
|
||||
_supplierRepository = supplierRepository ??
|
||||
throw new ArgumentNullException(nameof(supplierRepository));
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public bool CreateDoc(string filePath, bool includeProducts, bool includeWorkers, bool includeSuppliers)
|
||||
{
|
||||
try
|
||||
{
|
||||
var builder = new WordBuilder(filePath)
|
||||
.AddHeader("Документ со справочниками");
|
||||
if (includeProducts)
|
||||
{
|
||||
builder.AddParagraph("Продукты")
|
||||
.AddTable([2400, 2400, 1200],
|
||||
GetProducts());
|
||||
}
|
||||
if (includeWorkers)
|
||||
{
|
||||
builder.AddParagraph("Сотрудники")
|
||||
.AddTable([2400, 2400],
|
||||
GetWorkers());
|
||||
}
|
||||
if (includeSuppliers)
|
||||
{
|
||||
builder.AddParagraph("Поставщики")
|
||||
.AddTable([2400, 2400, 2400],
|
||||
GetSuppliers());
|
||||
}
|
||||
builder.Build();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<string[]> GetProducts()
|
||||
{
|
||||
return [
|
||||
["Название", "Цена", "Категория"],
|
||||
.. _productRepository
|
||||
.ReadProduct()
|
||||
.Select(x => new string[] { x.Name, x.Price.ToString(), x.Category.ToString() }),
|
||||
];
|
||||
}
|
||||
|
||||
private List<string[]> GetWorkers()
|
||||
{
|
||||
return [
|
||||
["ФИО", "Должность"],
|
||||
.. _workerRepository
|
||||
.ReadWorker()
|
||||
.Select(x => new string[] { x.Name, x.JobTitle.ToString()}),
|
||||
];
|
||||
}
|
||||
|
||||
private List<string[]> GetSuppliers()
|
||||
{
|
||||
return [
|
||||
["Название" +
|
||||
"ФИО", "Номер телефона", "Адрес"],
|
||||
.. _supplierRepository
|
||||
.ReadSupplier()
|
||||
.Select(x => new string[] { x.Name, x.PhoneNumber.ToString(), x.Address.ToString() }),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
342
ProjectGasStation/ProjectGasStation/Reports/ExcelBuilder.cs
Normal file
342
ProjectGasStation/ProjectGasStation/Reports/ExcelBuilder.cs
Normal file
@ -0,0 +1,342 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Reports;
|
||||
|
||||
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.SimpleTextWithBorder);
|
||||
for (int i = startIndex + 1; i < startIndex + count; ++i)
|
||||
{
|
||||
CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder);
|
||||
}
|
||||
_mergeCells.Append(new MergeCell()
|
||||
{
|
||||
Reference = new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}")
|
||||
});
|
||||
_rowIndex++;
|
||||
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 (var j = 0; j < data.First().Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data.First()[j],
|
||||
StyleIndex.BoldTextWithBorder);
|
||||
}
|
||||
_rowIndex++;
|
||||
|
||||
for (var i = 1; i < data.Count - 1; ++i)
|
||||
{
|
||||
for (var j = 0; j < data[i].Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data[i][j],
|
||||
StyleIndex.BoldTextWithoutBorder);
|
||||
}
|
||||
_rowIndex++;
|
||||
}
|
||||
for (var j = 0; j < data.Last().Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data.Last()[j],
|
||||
StyleIndex.BoldTextWithoutBorder);
|
||||
}
|
||||
_rowIndex++;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExcelBuilder AddParagraph(string text, int columnIndex)
|
||||
{
|
||||
CreateCell(columnIndex, _rowIndex++, text,
|
||||
StyleIndex.SimpleTextWithoutBorder);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
KnownFonts =
|
||||
BooleanValue.FromBoolean(true)
|
||||
};
|
||||
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
|
||||
{
|
||||
FontSize = new FontSize() { Val = 11 },
|
||||
FontName = new FontName() { Val = "Calibri" },
|
||||
FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
|
||||
FontScheme = new FontScheme()
|
||||
{
|
||||
Val = new
|
||||
EnumValue<FontSchemeValues>(FontSchemeValues.Minor)
|
||||
}
|
||||
});
|
||||
// шрифт с жирным
|
||||
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
|
||||
{
|
||||
FontSize = new FontSize() { Val = 11 },
|
||||
FontName = new FontName() { Val = "Calibri" },
|
||||
Bold = new Bold(),
|
||||
FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
|
||||
FontScheme = new FontScheme()
|
||||
{
|
||||
Val = new EnumValue<FontSchemeValues>(FontSchemeValues.Minor)
|
||||
}
|
||||
});
|
||||
|
||||
workbookStylesPart.Stylesheet.Append(fonts);
|
||||
// Default Fill
|
||||
var fills = new Fills() { Count = 1 };
|
||||
fills.Append(new Fill
|
||||
{
|
||||
PatternFill = new PatternFill()
|
||||
{
|
||||
PatternType = new
|
||||
EnumValue<PatternValues>(PatternValues.None)
|
||||
}
|
||||
});
|
||||
workbookStylesPart.Stylesheet.Append(fills);
|
||||
// Default Border
|
||||
var borders = new Borders() { Count = 2 };
|
||||
borders.Append(new Border
|
||||
{
|
||||
LeftBorder = new LeftBorder(),
|
||||
RightBorder = new RightBorder(),
|
||||
TopBorder = new TopBorder(),
|
||||
BottomBorder = new BottomBorder(),
|
||||
DiagonalBorder = new DiagonalBorder()
|
||||
});
|
||||
// настройкa с границами
|
||||
borders.Append(new Border
|
||||
{
|
||||
LeftBorder = new LeftBorder() { Style = BorderStyleValues.Medium },
|
||||
RightBorder = new RightBorder() { Style = BorderStyleValues.Medium },
|
||||
TopBorder = new TopBorder() { Style = BorderStyleValues.Medium },
|
||||
BottomBorder = new BottomBorder() { Style = BorderStyleValues.Medium },
|
||||
DiagonalBorder = new DiagonalBorder() { Style = BorderStyleValues.Medium },
|
||||
});
|
||||
|
||||
workbookStylesPart.Stylesheet.Append(borders);
|
||||
|
||||
// Default cell format and a date cell format
|
||||
var cellFormats = new CellFormats() { Count = 4 };
|
||||
cellFormats.Append(new CellFormat
|
||||
{
|
||||
NumberFormatId = 0,
|
||||
FormatId = 0,
|
||||
FontId = 0,
|
||||
BorderId = 0,
|
||||
FillId = 0,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Horizontal = HorizontalAlignmentValues.Left,
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true
|
||||
}
|
||||
});
|
||||
// TODO дополнить форматы
|
||||
|
||||
cellFormats.Append(new CellFormat
|
||||
{
|
||||
NumberFormatId = 1,
|
||||
FormatId = 0,
|
||||
FontId = 1,
|
||||
BorderId = 0,
|
||||
FillId = 0,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Horizontal = HorizontalAlignmentValues.Left,
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true
|
||||
}
|
||||
});
|
||||
cellFormats.Append(new CellFormat
|
||||
{
|
||||
NumberFormatId = 2,
|
||||
FormatId = 0,
|
||||
FontId = 0,
|
||||
BorderId = 1,
|
||||
FillId = 0,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Horizontal = HorizontalAlignmentValues.Left,
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true
|
||||
}
|
||||
});
|
||||
cellFormats.Append(new CellFormat
|
||||
{
|
||||
NumberFormatId = 3,
|
||||
FormatId = 0,
|
||||
FontId = 1,
|
||||
BorderId = 1,
|
||||
FillId = 0,
|
||||
Alignment = new Alignment()
|
||||
{
|
||||
Horizontal = HorizontalAlignmentValues.Left,
|
||||
Vertical = VerticalAlignmentValues.Center,
|
||||
WrapText = true
|
||||
}
|
||||
});
|
||||
workbookStylesPart.Stylesheet.Append(cellFormats);
|
||||
}
|
||||
|
||||
private enum StyleIndex
|
||||
{
|
||||
SimpleTextWithoutBorder = 0,
|
||||
SimpleTextWithBorder = 1,
|
||||
BoldTextWithoutBorder = 2,
|
||||
BoldTextWithBorder = 3,
|
||||
}
|
||||
|
||||
|
||||
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 newCell = row.Elements<Cell>()
|
||||
.FirstOrDefault(c => c.CellReference != null &&
|
||||
c.CellReference.Value == columnName + rowIndex);
|
||||
if (newCell == null)
|
||||
{
|
||||
Cell? refCell = null;
|
||||
foreach (Cell cell in row.Elements<Cell>())
|
||||
{
|
||||
if (cell.CellReference?.Value != null &&
|
||||
cell.CellReference.Value.Length == cellReference.Length)
|
||||
{
|
||||
if (string.Compare(cell.CellReference.Value,
|
||||
cellReference, true) > 0)
|
||||
{
|
||||
refCell = cell;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
newCell = new Cell() { CellReference = cellReference };
|
||||
row.InsertBefore(newCell, refCell);
|
||||
}
|
||||
newCell.CellValue = new CellValue(text);
|
||||
newCell.DataType = CellValues.String;
|
||||
newCell.StyleIndex = (uint)styleIndex;
|
||||
}
|
||||
|
||||
|
||||
private static string GetExcelColumnName(int columnNumber)
|
||||
{
|
||||
columnNumber += 1;
|
||||
int dividend = columnNumber;
|
||||
string columnName = string.Empty;
|
||||
int modulo;
|
||||
while (dividend > 0)
|
||||
{
|
||||
modulo = (dividend - 1) % 26;
|
||||
columnName = Convert.ToChar(65 + modulo).ToString() +
|
||||
columnName;
|
||||
dividend = (dividend - modulo) / 26;
|
||||
}
|
||||
return columnName;
|
||||
}
|
||||
|
||||
}
|
89
ProjectGasStation/ProjectGasStation/Reports/PdfBuilder.cs
Normal file
89
ProjectGasStation/ProjectGasStation/Reports/PdfBuilder.cs
Normal file
@ -0,0 +1,89 @@
|
||||
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 Color = MigraDoc.DocumentObjectModel.Color;
|
||||
|
||||
namespace ProjectGasStation.Reports;
|
||||
|
||||
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 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()
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(_filePath);
|
||||
}
|
||||
private void DefineStyles()
|
||||
{
|
||||
var headerStyle = _document.AddStyle("NormalBold", "Normal");
|
||||
headerStyle.Font.Bold = true;
|
||||
headerStyle.Font.Size = 14;
|
||||
headerStyle.Font.Color = Colors.DarkRed;
|
||||
}
|
||||
}
|
77
ProjectGasStation/ProjectGasStation/Reports/TableReport.cs
Normal file
77
ProjectGasStation/ProjectGasStation/Reports/TableReport.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectGasStation.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Reports;
|
||||
|
||||
internal class TableReport
|
||||
{
|
||||
private readonly IReceiptRepository _receiptRepository;
|
||||
private readonly ISaleRepository _saleRepository;
|
||||
private readonly ILogger<TableReport> _logger;
|
||||
|
||||
internal static readonly string[] item = ["Сотрудник", "Поставщик", "Дата", "Количество пришло", "Количество ушло"];
|
||||
|
||||
|
||||
public TableReport(IReceiptRepository receiptRepository, ISaleRepository saleRepository, ILogger<TableReport> logger)
|
||||
{
|
||||
_receiptRepository = receiptRepository ??
|
||||
throw new ArgumentNullException(nameof(receiptRepository));
|
||||
_saleRepository = saleRepository ??
|
||||
throw new ArgumentNullException(nameof(saleRepository));
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
|
||||
public bool CreateTable(string filePath, int productId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по движению товара", 0, 4)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddTable([10, 10, 15, 15, 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 data = _receiptRepository
|
||||
.ReadReceipt()
|
||||
.Where(x => x.DateTime >= startDate && x.DateTime <= endDate && x.ReceiptProducts.Any(y => y.ProductId == productId))
|
||||
.Select(x => new { WorkerId = (int?)null, SupplierId = (int?)null, Date = x.DateTime, CountIn = x.ReceiptProducts.FirstOrDefault(y => y.ProductId == productId)?.Quantity, CountOut = (int?)null })
|
||||
.Union(
|
||||
_saleRepository
|
||||
.ReadSale()
|
||||
.Where(x => x.DateTime >= startDate && x.DateTime <= endDate && x.SaleProducts.Any(y => y.ProductId == productId))
|
||||
.Select(x => new { WorkerId = (int?)null, SupplierId = (int?)null, Date = x.DateTime, CountIn = (int?)null, CountOut = x.SaleProducts.FirstOrDefault(y => y.ProductId == productId)?.Quantity }))
|
||||
.OrderBy(x => x.Date);
|
||||
|
||||
|
||||
_logger.LogInformation("Объединенные данные: {0}", string.Join(", ", data.Select(d => d.Date.ToString())));
|
||||
|
||||
return
|
||||
new List<string[]>() { item }
|
||||
.Union(
|
||||
data
|
||||
.Select(x => new string[] {x.WorkerId.ToString(), x.SupplierId.ToString(), x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty}))
|
||||
.Union(
|
||||
[["Всего", "", "", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]])
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
}
|
137
ProjectGasStation/ProjectGasStation/Reports/WordBuilder.cs
Normal file
137
ProjectGasStation/ProjectGasStation/Reports/WordBuilder.cs
Normal file
@ -0,0 +1,137 @@
|
||||
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 ProjectGasStation.Reports;
|
||||
|
||||
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());
|
||||
|
||||
//настройки под жирный текст??
|
||||
run.PrependChild(new RunProperties());
|
||||
run.RunProperties.AddChild(new Bold());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories;
|
||||
|
||||
public interface IConectionString
|
||||
{
|
||||
public string ConectionString { get; }
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using ProjectGasStation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories;
|
||||
|
||||
public interface IProductRepository
|
||||
{
|
||||
IEnumerable<Product> ReadProduct();
|
||||
Product ReadProductById(int id);
|
||||
void CreateProduct (Product product);
|
||||
void UpdateProduct (Product product);
|
||||
void DeleteProduct (int id);
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using ProjectGasStation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories;
|
||||
|
||||
public interface IReceiptRepository
|
||||
{
|
||||
IEnumerable<Receipt> ReadReceipt(DateTime? dateForm = null, DateTime? dateTo = null, int? productId = null, int? supplierId = null);
|
||||
|
||||
void CreateReceipt(Receipt receipt);
|
||||
|
||||
void DeleteReceipt(int id);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using ProjectGasStation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories;
|
||||
|
||||
public interface ISaleRepository
|
||||
{
|
||||
IEnumerable<Sale> ReadSale(DateTime? dateForm = null, DateTime? dateTo = null, int? productId = null, int? workerId = null);
|
||||
|
||||
void CreateSale(Sale sale);
|
||||
|
||||
void DeleteSale(int id);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using ProjectGasStation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories;
|
||||
|
||||
public interface ISupplierRepository
|
||||
{
|
||||
IEnumerable<Supplier> ReadSupplier();
|
||||
|
||||
Supplier ReadSupplierById(int id);
|
||||
|
||||
void CreateSupplier(Supplier supplier);
|
||||
|
||||
void UpdateSupplier(Supplier supplier);
|
||||
|
||||
void DeleteSupplier(int id);
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using ProjectGasStation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories;
|
||||
public interface IWorkerRepository
|
||||
{
|
||||
IEnumerable<Worker> ReadWorker();
|
||||
|
||||
Worker ReadWorkerById(int id);
|
||||
|
||||
void CreateWorker(Worker worker);
|
||||
|
||||
void UpdateWorker(Worker worker);
|
||||
|
||||
void DeleteWorker(int id);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories.Implementations;
|
||||
|
||||
internal class ConectionString : IConectionString
|
||||
{
|
||||
string IConectionString.ConectionString => "Server=localhost, 5432;Database=gas_station;Uid=postgres;Pwd=13081306";
|
||||
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectGasStation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories.Implementations;
|
||||
|
||||
internal class ProductRepository : IProductRepository
|
||||
{
|
||||
|
||||
public readonly IConectionString _conectionString;
|
||||
private readonly ILogger<ProductRepository> _logger;
|
||||
|
||||
public ProductRepository(IConectionString conectionString, ILogger<ProductRepository> logger)
|
||||
{
|
||||
_conectionString = conectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateProduct(Product product)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryInsert = @" INSERT INTO Products (Name, Price, Category)
|
||||
VALUES (@Name, @Price, @Category)";
|
||||
connection.Execute(queryInsert, product);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateProduct(Product product)
|
||||
{
|
||||
_logger.LogInformation("Редакитрование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryUpdate = @" UPDATE Products
|
||||
SET
|
||||
Name = @Name,
|
||||
Price = @Price,
|
||||
Category = @Category
|
||||
WHERE ID = @Id";
|
||||
connection.Execute(queryUpdate, product);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteProduct(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryDelete = @" DELETE FROM Products
|
||||
WHERE ID = @id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Product ReadProductById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
|
||||
|
||||
var querySelect = @" SELECT * FROM Products
|
||||
WHERE ID = @id";
|
||||
var product = connection.QueryFirst<Product>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(product));
|
||||
|
||||
return product;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<Product> ReadProduct()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelect = @" SELECT * FROM Products";
|
||||
var products = connection.Query<Product>(querySelect);
|
||||
_logger.LogDebug("Получены объекты: {json}", JsonConvert.SerializeObject(products));
|
||||
|
||||
return products;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectGasStation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories.Implementations;
|
||||
|
||||
internal class ReceiptRepository : IReceiptRepository
|
||||
{
|
||||
public readonly IConectionString _conectionString;
|
||||
private readonly ILogger<ReceiptRepository> _logger;
|
||||
|
||||
public ReceiptRepository(IConectionString conectionString, ILogger<ReceiptRepository> logger)
|
||||
{
|
||||
_conectionString = conectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateReceipt(Receipt receipt)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(receipt));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO Receipt (DateTime, SupplierID)
|
||||
VALUES (@DateTime, @SupplierID);
|
||||
SELECT MAX(Id) FROM Receipt";
|
||||
var receiptId = connection.QueryFirst<int>(queryInsert, receipt, transaction);
|
||||
|
||||
var querySubInsert = @"
|
||||
INSERT INTO ReceiptProducts(ProductID, ReceiptID, Quantity)
|
||||
VALUES (@ProductID, @ReceiptID, @Quantity)";
|
||||
foreach (var elem in receipt.ReceiptProducts)
|
||||
{
|
||||
connection.Execute(querySubInsert, new { elem.ProductId, receiptId, elem.Quantity }, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteReceipt(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
// Удаляем записи из таблицы ReceiptProducts, связанные с текущим Receipt
|
||||
var queryDeleteReceiptProducts = @" DELETE FROM ReceiptProducts
|
||||
WHERE ReceiptId = @id";
|
||||
connection.Execute(queryDeleteReceiptProducts, new { id });
|
||||
|
||||
// Удаляем запись из таблицы Receipt
|
||||
var queryDeleteReceipt = @" DELETE FROM Receipt
|
||||
WHERE ID = @id";
|
||||
connection.Execute(queryDeleteReceipt, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Receipt> ReadReceipt(DateTime? dateForm = null, DateTime? dateTo = null, int? productId = null, int? supplierId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
var querySelect = @" SELECT fr.*, ffr.ProductId, ffr. Quantity FROM Receipt fr
|
||||
INNER JOIN ReceiptProducts ffr ON ffr.ReceiptId = fr.Id";
|
||||
var receipt = connection.Query<TempSaleReceiptProduct>(querySelect);
|
||||
_logger.LogDebug("Получены объекты: {json}", JsonConvert.SerializeObject(receipt));
|
||||
|
||||
return receipt.GroupBy(x => x.Id, y => y,
|
||||
(key, value) => Receipt.CreateOperation(value.First(),
|
||||
value.Select(z => SaleReceiptProduct.CreateElement(0, z.ProductId, z.Quantity)))).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectGasStation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories.Implementations;
|
||||
|
||||
internal class SaleRepository : ISaleRepository
|
||||
{
|
||||
|
||||
public readonly IConectionString _conectionString;
|
||||
private readonly ILogger<SaleRepository> _logger;
|
||||
|
||||
public SaleRepository(IConectionString conectionString, ILogger<SaleRepository> logger)
|
||||
{
|
||||
_conectionString = conectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateSale(Sale sale)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(sale));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO Sale (DateTime, WorkerID)
|
||||
VALUES (@DateTime, @WorkerID);
|
||||
SELECT MAX(Id) FROM Sale";
|
||||
var saleId = connection.QueryFirst<int>(queryInsert, sale, transaction);
|
||||
|
||||
var querySubInsert = @"
|
||||
INSERT INTO SaleProducts(SaleID, ProductID, Quantity)
|
||||
VALUES (@SaleID, @ProductID, @Quantity)";
|
||||
foreach (var elem in sale.SaleProducts)
|
||||
{
|
||||
connection.Execute(querySubInsert, new { saleId, elem.ProductId, elem.Quantity }, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteSale(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
// Удаляем записи из таблицы SaleProducts, связанные с текущей продажей
|
||||
var queryDeleteSaleProducts = @" DELETE FROM SaleProducts
|
||||
WHERE SaleId = @id";
|
||||
connection.Execute(queryDeleteSaleProducts, new { id });
|
||||
|
||||
// Удаляем запись из таблицы Sale
|
||||
var queryDeleteSale = @" DELETE FROM Sale
|
||||
WHERE ID = @id";
|
||||
connection.Execute(queryDeleteSale, new { id });
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Sale> ReadSale(DateTime? dateForm = null, DateTime? dateTo = null, int? productId = null, int? workerId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
var querySelect = @" SELECT fr.*, ffr.ProductId, ffr. Quantity FROM Sale fr
|
||||
INNER JOIN SaleProducts ffr ON ffr.SaleId = fr.Id";
|
||||
var sale = connection.Query<TempSaleReceiptProduct>(querySelect);
|
||||
_logger.LogDebug("Получены объекты: {json}", JsonConvert.SerializeObject(sale));
|
||||
|
||||
|
||||
return sale.GroupBy(x => x.Id, y => y,
|
||||
(key, value) => Sale.CreateOperation(value.First(),
|
||||
value.Select(z => SaleReceiptProduct.CreateElement(0, z.ProductId, z.Quantity)))).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectGasStation.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories.Implementations;
|
||||
|
||||
public class SupplierRepository : ISupplierRepository
|
||||
{
|
||||
|
||||
public readonly IConectionString _conectionString;
|
||||
private readonly ILogger<SupplierRepository> _logger;
|
||||
|
||||
public SupplierRepository(IConectionString conectionString, ILogger<SupplierRepository> logger)
|
||||
{
|
||||
_conectionString = conectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateSupplier(Supplier supplier)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(supplier));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryInsert = @" INSERT INTO Suppliers (Name, PhoneNumber, Address)
|
||||
VALUES (@Name, @PhoneNumber, @Address)";
|
||||
connection.Execute(queryInsert, supplier);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateSupplier(Supplier supplier)
|
||||
{
|
||||
_logger.LogInformation("Редакитрование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(supplier));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryUpdate = @" UPDATE Suppliers
|
||||
SET
|
||||
Name = @SupplierName,
|
||||
PhoneNumber = @PhoneNumber,
|
||||
Address = @Address
|
||||
WHERE ID = @Id";
|
||||
connection.Execute(queryUpdate, supplier);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteSupplier(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryDelete = @" DELETE FROM Suppliers
|
||||
WHERE ID = @id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public Supplier ReadSupplierById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
|
||||
|
||||
var querySelect = @" SELECT * FROM Suppliers WHERE ID = @id";
|
||||
var supplier = connection.QueryFirst<Supplier>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(supplier));
|
||||
|
||||
return supplier;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public IEnumerable<Supplier> ReadSupplier()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelect = @" SELECT * FROM Suppliers";
|
||||
var suppliers = connection.Query<Supplier>(querySelect);
|
||||
_logger.LogDebug("Получены объекты: {json}", JsonConvert.SerializeObject(suppliers));
|
||||
|
||||
return suppliers;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectGasStation.Entities;
|
||||
using ProjectGasStation.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasStation.Repositories.Implementations;
|
||||
|
||||
public class WorkerRepository : IWorkerRepository
|
||||
{
|
||||
|
||||
public readonly IConectionString _conectionString;
|
||||
private readonly ILogger<WorkerRepository> _logger;
|
||||
|
||||
public WorkerRepository(IConectionString conectionString, ILogger<WorkerRepository> logger)
|
||||
{
|
||||
_conectionString = conectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateWorker(Worker worker)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(worker));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryInsert = @" INSERT INTO Workers (Name, JobTitle)
|
||||
VALUES (@Name, @JobTitle)";
|
||||
connection.Execute(queryInsert, worker);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void UpdateWorker(Worker worker)
|
||||
{
|
||||
_logger.LogInformation("Редакитрование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(worker));
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryUpdate = @" UPDATE Workers
|
||||
SET
|
||||
Name = @Name,
|
||||
JobTitle = @JobTitle
|
||||
WHERE ID = @Id";
|
||||
connection.Execute(queryUpdate, worker);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void DeleteWorker(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var queryDelete = @" DELETE FROM Workers
|
||||
WHERE ID = @id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Worker ReadWorkerById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
|
||||
|
||||
var querySelect = @" SELECT * FROM Workers WHERE ID = @id";
|
||||
var worker = connection.QueryFirst<Worker>(querySelect, new { id });
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(worker));
|
||||
|
||||
return worker;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Worker> ReadWorker()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_conectionString.ConectionString);
|
||||
connection.Open();
|
||||
|
||||
var querySelect = @" SELECT * FROM Workers";
|
||||
var workers = connection.Query<Worker>(querySelect);
|
||||
_logger.LogDebug("Получены объекты: {json}", JsonConvert.SerializeObject(workers));
|
||||
|
||||
return workers;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
15
ProjectGasStation/ProjectGasStation/appsettings.json
Normal file
15
ProjectGasStation/ProjectGasStation/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/gs_log.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user