Лаба 3, не работает таблица продаж.
This commit is contained in:
parent
33ceb7e60f
commit
3b3ab7ab9e
@ -8,7 +8,7 @@ namespace TradeAndProcurementEnterprice.Entities;
|
|||||||
|
|
||||||
public class Contract
|
public class Contract
|
||||||
{
|
{
|
||||||
public int ContractID { get; private set; }
|
public int ID { get; private set; }
|
||||||
|
|
||||||
public DateTime SaleDate { get; private set; }
|
public DateTime SaleDate { get; private set; }
|
||||||
|
|
||||||
@ -22,11 +22,24 @@ public class Contract
|
|||||||
{
|
{
|
||||||
return new Contract
|
return new Contract
|
||||||
{
|
{
|
||||||
ContractID = contractID,
|
ID = contractID,
|
||||||
SaleDate = DateTime.Now,
|
SaleDate = DateTime.Now,
|
||||||
PurchasingCompanyID = purchasingCompanyID,
|
PurchasingCompanyID = purchasingCompanyID,
|
||||||
AgentsID = agentsID,
|
AgentsID = agentsID,
|
||||||
ProductSales = productSales
|
ProductSales = productSales
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Contract CreateOperation(TempProductSales tempProductSales,
|
||||||
|
IEnumerable<ProductSales> productSales)
|
||||||
|
{
|
||||||
|
return new Contract
|
||||||
|
{
|
||||||
|
ID = tempProductSales.ID,
|
||||||
|
AgentsID = tempProductSales.AgentsId,
|
||||||
|
SaleDate = tempProductSales.SaleDate,
|
||||||
|
PurchasingCompanyID = tempProductSales.PurchasingCompanyId,
|
||||||
|
ProductSales = productSales
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace TradeAndProcurementEnterprice.Entities;
|
||||||
|
|
||||||
|
public class TempProductSales
|
||||||
|
{
|
||||||
|
public int ID { get; private set; }
|
||||||
|
|
||||||
|
public int AgentsId { get; private set; }
|
||||||
|
|
||||||
|
public DateTime SaleDate { get; private set; }
|
||||||
|
|
||||||
|
public int PurchasingCompanyId { get; private set; }
|
||||||
|
|
||||||
|
public int ProductArticle { get; private set; }
|
||||||
|
|
||||||
|
public int ProductQuantity { get; private set; }
|
||||||
|
}
|
@ -37,6 +37,8 @@
|
|||||||
contractsToolStripMenuItem1 = new ToolStripMenuItem();
|
contractsToolStripMenuItem1 = new ToolStripMenuItem();
|
||||||
delegateToAgentsToolStripMenuItem = new ToolStripMenuItem();
|
delegateToAgentsToolStripMenuItem = new ToolStripMenuItem();
|
||||||
reportToolStripMenuItem = new ToolStripMenuItem();
|
reportToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
directoryReportToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
productReportToolStripMenuItem = new ToolStripMenuItem();
|
||||||
menuStrip1.SuspendLayout();
|
menuStrip1.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -46,8 +48,7 @@
|
|||||||
menuStrip1.Items.AddRange(new ToolStripItem[] { catalogToolStripMenuItem, operationToolStripMenuItem, reportToolStripMenuItem });
|
menuStrip1.Items.AddRange(new ToolStripItem[] { catalogToolStripMenuItem, operationToolStripMenuItem, reportToolStripMenuItem });
|
||||||
menuStrip1.Location = new Point(0, 0);
|
menuStrip1.Location = new Point(0, 0);
|
||||||
menuStrip1.Name = "menuStrip1";
|
menuStrip1.Name = "menuStrip1";
|
||||||
menuStrip1.Padding = new Padding(3, 1, 0, 1);
|
menuStrip1.Size = new Size(1207, 42);
|
||||||
menuStrip1.Size = new Size(650, 24);
|
|
||||||
menuStrip1.TabIndex = 0;
|
menuStrip1.TabIndex = 0;
|
||||||
menuStrip1.Text = "menuStrip1";
|
menuStrip1.Text = "menuStrip1";
|
||||||
//
|
//
|
||||||
@ -55,27 +56,27 @@
|
|||||||
//
|
//
|
||||||
catalogToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { agentsToolStripMenuItem, nomenclatureToolStripMenuItem, purchasingCompanyToolStripMenuItem });
|
catalogToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { agentsToolStripMenuItem, nomenclatureToolStripMenuItem, purchasingCompanyToolStripMenuItem });
|
||||||
catalogToolStripMenuItem.Name = "catalogToolStripMenuItem";
|
catalogToolStripMenuItem.Name = "catalogToolStripMenuItem";
|
||||||
catalogToolStripMenuItem.Size = new Size(94, 22);
|
catalogToolStripMenuItem.Size = new Size(184, 38);
|
||||||
catalogToolStripMenuItem.Text = "Справочники";
|
catalogToolStripMenuItem.Text = "Справочники";
|
||||||
//
|
//
|
||||||
// agentsToolStripMenuItem
|
// agentsToolStripMenuItem
|
||||||
//
|
//
|
||||||
agentsToolStripMenuItem.Name = "agentsToolStripMenuItem";
|
agentsToolStripMenuItem.Name = "agentsToolStripMenuItem";
|
||||||
agentsToolStripMenuItem.Size = new Size(195, 22);
|
agentsToolStripMenuItem.Size = new Size(388, 44);
|
||||||
agentsToolStripMenuItem.Text = "Агенты-реализаторы";
|
agentsToolStripMenuItem.Text = "Агенты-реализаторы";
|
||||||
agentsToolStripMenuItem.Click += AgentsToolStripMenuItem_Click;
|
agentsToolStripMenuItem.Click += AgentsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// nomenclatureToolStripMenuItem
|
// nomenclatureToolStripMenuItem
|
||||||
//
|
//
|
||||||
nomenclatureToolStripMenuItem.Name = "nomenclatureToolStripMenuItem";
|
nomenclatureToolStripMenuItem.Name = "nomenclatureToolStripMenuItem";
|
||||||
nomenclatureToolStripMenuItem.Size = new Size(195, 22);
|
nomenclatureToolStripMenuItem.Size = new Size(388, 44);
|
||||||
nomenclatureToolStripMenuItem.Text = "Номенклатура";
|
nomenclatureToolStripMenuItem.Text = "Номенклатура";
|
||||||
nomenclatureToolStripMenuItem.Click += NomenclatureToolStripMenuItem_Click;
|
nomenclatureToolStripMenuItem.Click += NomenclatureToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// purchasingCompanyToolStripMenuItem
|
// purchasingCompanyToolStripMenuItem
|
||||||
//
|
//
|
||||||
purchasingCompanyToolStripMenuItem.Name = "purchasingCompanyToolStripMenuItem";
|
purchasingCompanyToolStripMenuItem.Name = "purchasingCompanyToolStripMenuItem";
|
||||||
purchasingCompanyToolStripMenuItem.Size = new Size(195, 22);
|
purchasingCompanyToolStripMenuItem.Size = new Size(388, 44);
|
||||||
purchasingCompanyToolStripMenuItem.Text = "Компании закупщики";
|
purchasingCompanyToolStripMenuItem.Text = "Компании закупщики";
|
||||||
purchasingCompanyToolStripMenuItem.Click += PurchasingCompanyToolStripMenuItem_Click;
|
purchasingCompanyToolStripMenuItem.Click += PurchasingCompanyToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
@ -83,39 +84,56 @@
|
|||||||
//
|
//
|
||||||
operationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { contractsToolStripMenuItem1, delegateToAgentsToolStripMenuItem });
|
operationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { contractsToolStripMenuItem1, delegateToAgentsToolStripMenuItem });
|
||||||
operationToolStripMenuItem.Name = "operationToolStripMenuItem";
|
operationToolStripMenuItem.Name = "operationToolStripMenuItem";
|
||||||
operationToolStripMenuItem.Size = new Size(75, 22);
|
operationToolStripMenuItem.Size = new Size(147, 38);
|
||||||
operationToolStripMenuItem.Text = "Операции";
|
operationToolStripMenuItem.Text = "Операции";
|
||||||
//
|
//
|
||||||
// contractsToolStripMenuItem1
|
// contractsToolStripMenuItem1
|
||||||
//
|
//
|
||||||
contractsToolStripMenuItem1.Name = "contractsToolStripMenuItem1";
|
contractsToolStripMenuItem1.Name = "contractsToolStripMenuItem1";
|
||||||
contractsToolStripMenuItem1.Size = new Size(174, 22);
|
contractsToolStripMenuItem1.Size = new Size(349, 44);
|
||||||
contractsToolStripMenuItem1.Text = "Продажи";
|
contractsToolStripMenuItem1.Text = "Продажи";
|
||||||
contractsToolStripMenuItem1.Click += ContractsToolStripMenuItem1_Click;
|
contractsToolStripMenuItem1.Click += ContractsToolStripMenuItem1_Click;
|
||||||
//
|
//
|
||||||
// delegateToAgentsToolStripMenuItem
|
// delegateToAgentsToolStripMenuItem
|
||||||
//
|
//
|
||||||
delegateToAgentsToolStripMenuItem.Name = "delegateToAgentsToolStripMenuItem";
|
delegateToAgentsToolStripMenuItem.Name = "delegateToAgentsToolStripMenuItem";
|
||||||
delegateToAgentsToolStripMenuItem.Size = new Size(174, 22);
|
delegateToAgentsToolStripMenuItem.Size = new Size(349, 44);
|
||||||
delegateToAgentsToolStripMenuItem.Text = "Передача агентам";
|
delegateToAgentsToolStripMenuItem.Text = "Передача агентам";
|
||||||
delegateToAgentsToolStripMenuItem.Click += DelegateToAgentsToolStripMenuItem_Click;
|
delegateToAgentsToolStripMenuItem.Click += DelegateToAgentsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// reportToolStripMenuItem
|
// reportToolStripMenuItem
|
||||||
//
|
//
|
||||||
|
reportToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { directoryReportToolStripMenuItem, productReportToolStripMenuItem });
|
||||||
reportToolStripMenuItem.Name = "reportToolStripMenuItem";
|
reportToolStripMenuItem.Name = "reportToolStripMenuItem";
|
||||||
reportToolStripMenuItem.Size = new Size(60, 22);
|
reportToolStripMenuItem.Size = new Size(116, 38);
|
||||||
reportToolStripMenuItem.Text = "Отчёты";
|
reportToolStripMenuItem.Text = "Отчёты";
|
||||||
//
|
//
|
||||||
|
// directoryReportToolStripMenuItem
|
||||||
|
//
|
||||||
|
directoryReportToolStripMenuItem.Name = "directoryReportToolStripMenuItem";
|
||||||
|
directoryReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W;
|
||||||
|
directoryReportToolStripMenuItem.Size = new Size(559, 44);
|
||||||
|
directoryReportToolStripMenuItem.Text = "Документ со справочниками";
|
||||||
|
directoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// productReportToolStripMenuItem
|
||||||
|
//
|
||||||
|
productReportToolStripMenuItem.Name = "productReportToolStripMenuItem";
|
||||||
|
productReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.E;
|
||||||
|
productReportToolStripMenuItem.Size = new Size(559, 44);
|
||||||
|
productReportToolStripMenuItem.Text = "Движение номенклатуры";
|
||||||
|
productReportToolStripMenuItem.Click += ProductReportToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
// FormEnterprice
|
// FormEnterprice
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
BackgroundImage = Properties.Resources.photo_2024_12_03_21_34_38;
|
BackgroundImage = Properties.Resources.photo_2024_12_03_21_34_38;
|
||||||
BackgroundImageLayout = ImageLayout.Stretch;
|
BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
ClientSize = new Size(650, 339);
|
ClientSize = new Size(1207, 723);
|
||||||
Controls.Add(menuStrip1);
|
Controls.Add(menuStrip1);
|
||||||
MainMenuStrip = menuStrip1;
|
MainMenuStrip = menuStrip1;
|
||||||
Margin = new Padding(2, 1, 2, 1);
|
Margin = new Padding(4, 2, 4, 2);
|
||||||
Name = "FormEnterprice";
|
Name = "FormEnterprice";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "Торгово закупочное предприятие";
|
Text = "Торгово закупочное предприятие";
|
||||||
@ -136,5 +154,7 @@
|
|||||||
private ToolStripMenuItem purchasingCompanyToolStripMenuItem;
|
private ToolStripMenuItem purchasingCompanyToolStripMenuItem;
|
||||||
private ToolStripMenuItem contractsToolStripMenuItem1;
|
private ToolStripMenuItem contractsToolStripMenuItem1;
|
||||||
private ToolStripMenuItem delegateToAgentsToolStripMenuItem;
|
private ToolStripMenuItem delegateToAgentsToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem directoryReportToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem productReportToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -74,9 +74,28 @@ namespace TradeAndProcurementEnterprice
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormEnterprice_Load(object sender, EventArgs e)
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -45,9 +45,10 @@
|
|||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonCancel.Location = new Point(293, 306);
|
buttonCancel.Location = new Point(290, 653);
|
||||||
|
buttonCancel.Margin = new Padding(6, 6, 6, 6);
|
||||||
buttonCancel.Name = "buttonCancel";
|
buttonCancel.Name = "buttonCancel";
|
||||||
buttonCancel.Size = new Size(84, 23);
|
buttonCancel.Size = new Size(156, 49);
|
||||||
buttonCancel.TabIndex = 32;
|
buttonCancel.TabIndex = 32;
|
||||||
buttonCancel.Text = "Отмена";
|
buttonCancel.Text = "Отмена";
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
@ -56,9 +57,10 @@
|
|||||||
// buttonSave
|
// buttonSave
|
||||||
//
|
//
|
||||||
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonSave.Location = new Point(27, 306);
|
buttonSave.Location = new Point(50, 653);
|
||||||
|
buttonSave.Margin = new Padding(6, 6, 6, 6);
|
||||||
buttonSave.Name = "buttonSave";
|
buttonSave.Name = "buttonSave";
|
||||||
buttonSave.Size = new Size(84, 23);
|
buttonSave.Size = new Size(156, 49);
|
||||||
buttonSave.TabIndex = 33;
|
buttonSave.TabIndex = 33;
|
||||||
buttonSave.Text = "Сохранить";
|
buttonSave.Text = "Сохранить";
|
||||||
buttonSave.UseVisualStyleBackColor = true;
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
@ -69,9 +71,10 @@
|
|||||||
comboBoxPurchasingCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
comboBoxPurchasingCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
comboBoxPurchasingCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxPurchasingCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxPurchasingCompany.FormattingEnabled = true;
|
comboBoxPurchasingCompany.FormattingEnabled = true;
|
||||||
comboBoxPurchasingCompany.Location = new Point(119, 16);
|
comboBoxPurchasingCompany.Location = new Point(221, 34);
|
||||||
|
comboBoxPurchasingCompany.Margin = new Padding(6, 6, 6, 6);
|
||||||
comboBoxPurchasingCompany.Name = "comboBoxPurchasingCompany";
|
comboBoxPurchasingCompany.Name = "comboBoxPurchasingCompany";
|
||||||
comboBoxPurchasingCompany.Size = new Size(268, 23);
|
comboBoxPurchasingCompany.Size = new Size(240, 40);
|
||||||
comboBoxPurchasingCompany.TabIndex = 29;
|
comboBoxPurchasingCompany.TabIndex = 29;
|
||||||
//
|
//
|
||||||
// comboBoxAgent
|
// comboBoxAgent
|
||||||
@ -79,24 +82,27 @@
|
|||||||
comboBoxAgent.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
comboBoxAgent.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
comboBoxAgent.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxAgent.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxAgent.FormattingEnabled = true;
|
comboBoxAgent.FormattingEnabled = true;
|
||||||
comboBoxAgent.Location = new Point(119, 59);
|
comboBoxAgent.Location = new Point(221, 126);
|
||||||
|
comboBoxAgent.Margin = new Padding(6, 6, 6, 6);
|
||||||
comboBoxAgent.Name = "comboBoxAgent";
|
comboBoxAgent.Name = "comboBoxAgent";
|
||||||
comboBoxAgent.Size = new Size(268, 23);
|
comboBoxAgent.Size = new Size(240, 40);
|
||||||
comboBoxAgent.TabIndex = 30;
|
comboBoxAgent.TabIndex = 30;
|
||||||
//
|
//
|
||||||
// labelAgent
|
// labelAgent
|
||||||
//
|
//
|
||||||
labelAgent.Location = new Point(21, 52);
|
labelAgent.Location = new Point(39, 111);
|
||||||
|
labelAgent.Margin = new Padding(6, 0, 6, 0);
|
||||||
labelAgent.Name = "labelAgent";
|
labelAgent.Name = "labelAgent";
|
||||||
labelAgent.Size = new Size(90, 36);
|
labelAgent.Size = new Size(167, 77);
|
||||||
labelAgent.TabIndex = 27;
|
labelAgent.TabIndex = 27;
|
||||||
labelAgent.Text = "Агент-\r\nреализатор";
|
labelAgent.Text = "Агент-\r\nреализатор";
|
||||||
//
|
//
|
||||||
// labelPurchatingCompany
|
// labelPurchatingCompany
|
||||||
//
|
//
|
||||||
labelPurchatingCompany.Location = new Point(23, 11);
|
labelPurchatingCompany.Location = new Point(43, 23);
|
||||||
|
labelPurchatingCompany.Margin = new Padding(6, 0, 6, 0);
|
||||||
labelPurchatingCompany.Name = "labelPurchatingCompany";
|
labelPurchatingCompany.Name = "labelPurchatingCompany";
|
||||||
labelPurchatingCompany.Size = new Size(88, 32);
|
labelPurchatingCompany.Size = new Size(163, 68);
|
||||||
labelPurchatingCompany.TabIndex = 28;
|
labelPurchatingCompany.TabIndex = 28;
|
||||||
labelPurchatingCompany.Text = "Компания закупщик";
|
labelPurchatingCompany.Text = "Компания закупщик";
|
||||||
//
|
//
|
||||||
@ -104,9 +110,11 @@
|
|||||||
//
|
//
|
||||||
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
groupBox1.Controls.Add(dataGridViewProduct);
|
groupBox1.Controls.Add(dataGridViewProduct);
|
||||||
groupBox1.Location = new Point(23, 102);
|
groupBox1.Location = new Point(43, 218);
|
||||||
|
groupBox1.Margin = new Padding(6, 6, 6, 6);
|
||||||
groupBox1.Name = "groupBox1";
|
groupBox1.Name = "groupBox1";
|
||||||
groupBox1.Size = new Size(363, 198);
|
groupBox1.Padding = new Padding(6, 6, 6, 6);
|
||||||
|
groupBox1.Size = new Size(420, 422);
|
||||||
groupBox1.TabIndex = 34;
|
groupBox1.TabIndex = 34;
|
||||||
groupBox1.TabStop = false;
|
groupBox1.TabStop = false;
|
||||||
groupBox1.Text = "Продукт";
|
groupBox1.Text = "Продукт";
|
||||||
@ -118,14 +126,15 @@
|
|||||||
dataGridViewProduct.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
dataGridViewProduct.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
dataGridViewProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridViewProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridViewProduct.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnQuantity });
|
dataGridViewProduct.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnQuantity });
|
||||||
dataGridViewProduct.Location = new Point(3, 19);
|
dataGridViewProduct.Location = new Point(6, 41);
|
||||||
|
dataGridViewProduct.Margin = new Padding(6, 6, 6, 6);
|
||||||
dataGridViewProduct.MultiSelect = false;
|
dataGridViewProduct.MultiSelect = false;
|
||||||
dataGridViewProduct.Name = "dataGridViewProduct";
|
dataGridViewProduct.Name = "dataGridViewProduct";
|
||||||
dataGridViewProduct.RowHeadersVisible = false;
|
dataGridViewProduct.RowHeadersVisible = false;
|
||||||
dataGridViewProduct.RowHeadersWidth = 82;
|
dataGridViewProduct.RowHeadersWidth = 82;
|
||||||
dataGridViewProduct.RowTemplate.Height = 25;
|
dataGridViewProduct.RowTemplate.Height = 25;
|
||||||
dataGridViewProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridViewProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridViewProduct.Size = new Size(354, 176);
|
dataGridViewProduct.Size = new Size(403, 375);
|
||||||
dataGridViewProduct.TabIndex = 0;
|
dataGridViewProduct.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// ColumnProduct
|
// ColumnProduct
|
||||||
@ -144,9 +153,9 @@
|
|||||||
//
|
//
|
||||||
// FormContract
|
// FormContract
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(404, 341);
|
ClientSize = new Size(496, 727);
|
||||||
Controls.Add(groupBox1);
|
Controls.Add(groupBox1);
|
||||||
Controls.Add(buttonCancel);
|
Controls.Add(buttonCancel);
|
||||||
Controls.Add(buttonSave);
|
Controls.Add(buttonSave);
|
||||||
@ -154,7 +163,8 @@
|
|||||||
Controls.Add(comboBoxAgent);
|
Controls.Add(comboBoxAgent);
|
||||||
Controls.Add(labelAgent);
|
Controls.Add(labelAgent);
|
||||||
Controls.Add(labelPurchatingCompany);
|
Controls.Add(labelPurchatingCompany);
|
||||||
MinimumSize = new Size(266, 363);
|
Margin = new Padding(6, 6, 6, 6);
|
||||||
|
MinimumSize = new Size(472, 694);
|
||||||
Name = "FormContract";
|
Name = "FormContract";
|
||||||
StartPosition = FormStartPosition.CenterParent;
|
StartPosition = FormStartPosition.CenterParent;
|
||||||
Text = "Контракт";
|
Text = "Контракт";
|
||||||
|
@ -70,7 +70,8 @@ namespace TradeAndProcurementEnterprice.Forms
|
|||||||
|
|
||||||
list.Add(ProductSales.CreateElement(0, Convert.ToInt32(row.Cells["ColumnProduct"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value)));
|
list.Add(ProductSales.CreateElement(0, Convert.ToInt32(row.Cells["ColumnProduct"].Value), Convert.ToInt32(row.Cells["ColumnQuantity"].Value)));
|
||||||
}
|
}
|
||||||
return list;
|
return list.GroupBy(x => x.ProductArticle, x => x.ProductQuantity, (id, quantity) =>
|
||||||
|
ProductSales.CreateElement(0, id, quantity.Sum())).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
101
TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormDirectoryReport.Designer.cs
generated
Normal file
101
TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormDirectoryReport.Designer.cs
generated
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
namespace TradeAndProcurementEnterprice.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();
|
||||||
|
checkBoxAgents = new CheckBox();
|
||||||
|
checkBoxCompanies = new CheckBox();
|
||||||
|
buttonCreate = new Button();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// checkBoxProducts
|
||||||
|
//
|
||||||
|
checkBoxProducts.AutoSize = true;
|
||||||
|
checkBoxProducts.Location = new Point(35, 52);
|
||||||
|
checkBoxProducts.Name = "checkBoxProducts";
|
||||||
|
checkBoxProducts.Size = new Size(206, 36);
|
||||||
|
checkBoxProducts.TabIndex = 0;
|
||||||
|
checkBoxProducts.Text = "Номенклатура";
|
||||||
|
checkBoxProducts.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxAgents
|
||||||
|
//
|
||||||
|
checkBoxAgents.AutoSize = true;
|
||||||
|
checkBoxAgents.Location = new Point(35, 121);
|
||||||
|
checkBoxAgents.Name = "checkBoxAgents";
|
||||||
|
checkBoxAgents.Size = new Size(278, 36);
|
||||||
|
checkBoxAgents.TabIndex = 0;
|
||||||
|
checkBoxAgents.Text = "Агенты-реализаторы";
|
||||||
|
checkBoxAgents.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBoxCompanies
|
||||||
|
//
|
||||||
|
checkBoxCompanies.AutoSize = true;
|
||||||
|
checkBoxCompanies.Location = new Point(35, 191);
|
||||||
|
checkBoxCompanies.Name = "checkBoxCompanies";
|
||||||
|
checkBoxCompanies.Size = new Size(290, 36);
|
||||||
|
checkBoxCompanies.TabIndex = 0;
|
||||||
|
checkBoxCompanies.Text = "Компании-закупщики";
|
||||||
|
checkBoxCompanies.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// buttonCreate
|
||||||
|
//
|
||||||
|
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonCreate.Location = new Point(35, 261);
|
||||||
|
buttonCreate.Name = "buttonCreate";
|
||||||
|
buttonCreate.Size = new Size(458, 46);
|
||||||
|
buttonCreate.TabIndex = 1;
|
||||||
|
buttonCreate.Text = "Сформировать";
|
||||||
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreate.Click += ButtonCreate_Click;
|
||||||
|
//
|
||||||
|
// FormDirectoryReport
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(529, 339);
|
||||||
|
Controls.Add(buttonCreate);
|
||||||
|
Controls.Add(checkBoxCompanies);
|
||||||
|
Controls.Add(checkBoxAgents);
|
||||||
|
Controls.Add(checkBoxProducts);
|
||||||
|
MinimumSize = new Size(555, 410);
|
||||||
|
Name = "FormDirectoryReport";
|
||||||
|
Text = "Выгрузка справочников";
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private CheckBox checkBoxProducts;
|
||||||
|
private CheckBox checkBoxAgents;
|
||||||
|
private CheckBox checkBoxCompanies;
|
||||||
|
private Button buttonCreate;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
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 TradeAndProcurementEnterprice.Reports;
|
||||||
|
using Unity;
|
||||||
|
|
||||||
|
namespace TradeAndProcurementEnterprice.Forms
|
||||||
|
{
|
||||||
|
public partial class FormDirectoryReport : Form
|
||||||
|
{
|
||||||
|
private readonly IUnityContainer _container;
|
||||||
|
|
||||||
|
public FormDirectoryReport(IUnityContainer container)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_container = container ??
|
||||||
|
throw new ArgumentNullException(nameof(container));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!checkBoxProducts.Checked && !checkBoxProducts.Checked && !checkBoxCompanies.Checked)
|
||||||
|
{
|
||||||
|
throw new Exception("Не выбран ни один справочник для выгрузки!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var saveFileDialog = new SaveFileDialog()
|
||||||
|
{
|
||||||
|
Filter = "Docx Files | *.docx"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
||||||
|
{
|
||||||
|
throw new Exception("Не выбран файл для отчёта!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_container.Resolve<DocReport>().CreateDoc(saveFileDialog.FileName, checkBoxProducts.Checked,
|
||||||
|
checkBoxAgents.Checked, checkBoxCompanies.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>
|
170
TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProductReport.Designer.cs
generated
Normal file
170
TradeAndProcurementEnterprice/TradeAndProcurementEnterprice/Forms/FormProductReport.Designer.cs
generated
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
namespace TradeAndProcurementEnterprice.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()
|
||||||
|
{
|
||||||
|
dateTimePickerStart = new DateTimePicker();
|
||||||
|
labelPath = new Label();
|
||||||
|
buttonSelectFilePath = new Button();
|
||||||
|
textBoxFilePath = new TextBox();
|
||||||
|
comboBoxProduct = new ComboBox();
|
||||||
|
labelProduct = new Label();
|
||||||
|
dateTimePickerEnd = new DateTimePicker();
|
||||||
|
labelDateStart = new Label();
|
||||||
|
labelDateEnd = new Label();
|
||||||
|
buttonBuild = new Button();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// dateTimePickerStart
|
||||||
|
//
|
||||||
|
dateTimePickerStart.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
dateTimePickerStart.Location = new Point(241, 189);
|
||||||
|
dateTimePickerStart.Name = "dateTimePickerStart";
|
||||||
|
dateTimePickerStart.Size = new Size(496, 39);
|
||||||
|
dateTimePickerStart.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// labelPath
|
||||||
|
//
|
||||||
|
labelPath.AutoSize = true;
|
||||||
|
labelPath.Location = new Point(40, 41);
|
||||||
|
labelPath.Name = "labelPath";
|
||||||
|
labelPath.Size = new Size(173, 32);
|
||||||
|
labelPath.TabIndex = 1;
|
||||||
|
labelPath.Text = "Путь до файла";
|
||||||
|
//
|
||||||
|
// buttonSelectFilePath
|
||||||
|
//
|
||||||
|
buttonSelectFilePath.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonSelectFilePath.Location = new Point(692, 41);
|
||||||
|
buttonSelectFilePath.Name = "buttonSelectFilePath";
|
||||||
|
buttonSelectFilePath.Size = new Size(45, 39);
|
||||||
|
buttonSelectFilePath.TabIndex = 2;
|
||||||
|
buttonSelectFilePath.Text = "..";
|
||||||
|
buttonSelectFilePath.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectFilePath.Click += ButtonSelectFilePath_Click;
|
||||||
|
//
|
||||||
|
// textBoxFilePath
|
||||||
|
//
|
||||||
|
textBoxFilePath.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
textBoxFilePath.Location = new Point(241, 41);
|
||||||
|
textBoxFilePath.Name = "textBoxFilePath";
|
||||||
|
textBoxFilePath.ReadOnly = true;
|
||||||
|
textBoxFilePath.Size = new Size(445, 39);
|
||||||
|
textBoxFilePath.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// comboBoxProduct
|
||||||
|
//
|
||||||
|
comboBoxProduct.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
comboBoxProduct.FormattingEnabled = true;
|
||||||
|
comboBoxProduct.Location = new Point(241, 113);
|
||||||
|
comboBoxProduct.Name = "comboBoxProduct";
|
||||||
|
comboBoxProduct.Size = new Size(496, 40);
|
||||||
|
comboBoxProduct.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// labelProduct
|
||||||
|
//
|
||||||
|
labelProduct.AutoSize = true;
|
||||||
|
labelProduct.Location = new Point(40, 116);
|
||||||
|
labelProduct.Name = "labelProduct";
|
||||||
|
labelProduct.Size = new Size(174, 32);
|
||||||
|
labelProduct.TabIndex = 1;
|
||||||
|
labelProduct.Text = "Номенклатура";
|
||||||
|
//
|
||||||
|
// dateTimePickerEnd
|
||||||
|
//
|
||||||
|
dateTimePickerEnd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
dateTimePickerEnd.Location = new Point(241, 262);
|
||||||
|
dateTimePickerEnd.Name = "dateTimePickerEnd";
|
||||||
|
dateTimePickerEnd.Size = new Size(496, 39);
|
||||||
|
dateTimePickerEnd.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// labelDateStart
|
||||||
|
//
|
||||||
|
labelDateStart.AutoSize = true;
|
||||||
|
labelDateStart.Location = new Point(40, 194);
|
||||||
|
labelDateStart.Name = "labelDateStart";
|
||||||
|
labelDateStart.Size = new Size(149, 32);
|
||||||
|
labelDateStart.TabIndex = 1;
|
||||||
|
labelDateStart.Text = "Дата начала";
|
||||||
|
//
|
||||||
|
// labelDateEnd
|
||||||
|
//
|
||||||
|
labelDateEnd.AutoSize = true;
|
||||||
|
labelDateEnd.Location = new Point(40, 267);
|
||||||
|
labelDateEnd.Name = "labelDateEnd";
|
||||||
|
labelDateEnd.Size = new Size(199, 32);
|
||||||
|
labelDateEnd.TabIndex = 1;
|
||||||
|
labelDateEnd.Text = "Дата окончания ";
|
||||||
|
//
|
||||||
|
// buttonBuild
|
||||||
|
//
|
||||||
|
buttonBuild.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonBuild.Location = new Point(229, 343);
|
||||||
|
buttonBuild.Name = "buttonBuild";
|
||||||
|
buttonBuild.Size = new Size(306, 46);
|
||||||
|
buttonBuild.TabIndex = 5;
|
||||||
|
buttonBuild.Text = "Сформировать";
|
||||||
|
buttonBuild.UseVisualStyleBackColor = true;
|
||||||
|
buttonBuild.Click += ButtonBuild_Click;
|
||||||
|
//
|
||||||
|
// FormProductReport
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(769, 414);
|
||||||
|
Controls.Add(buttonBuild);
|
||||||
|
Controls.Add(comboBoxProduct);
|
||||||
|
Controls.Add(textBoxFilePath);
|
||||||
|
Controls.Add(buttonSelectFilePath);
|
||||||
|
Controls.Add(labelDateEnd);
|
||||||
|
Controls.Add(labelDateStart);
|
||||||
|
Controls.Add(labelProduct);
|
||||||
|
Controls.Add(labelPath);
|
||||||
|
Controls.Add(dateTimePickerEnd);
|
||||||
|
Controls.Add(dateTimePickerStart);
|
||||||
|
MinimumSize = new Size(795, 485);
|
||||||
|
Name = "FormProductReport";
|
||||||
|
Text = "FormProductReport";
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DateTimePicker dateTimePickerStart;
|
||||||
|
private Label labelPath;
|
||||||
|
private Button buttonSelectFilePath;
|
||||||
|
private TextBox textBoxFilePath;
|
||||||
|
private ComboBox comboBoxProduct;
|
||||||
|
private Label labelProduct;
|
||||||
|
private DateTimePicker dateTimePickerEnd;
|
||||||
|
private Label labelDateStart;
|
||||||
|
private Label labelDateEnd;
|
||||||
|
private Button buttonBuild;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
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 TradeAndProcurementEnterprice.Reports;
|
||||||
|
using TradeAndProcurementEnterprice.Repositories;
|
||||||
|
using Unity;
|
||||||
|
|
||||||
|
namespace TradeAndProcurementEnterprice.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.ReadProducts();
|
||||||
|
comboBoxProduct.DisplayMember = "Name";
|
||||||
|
comboBoxProduct.ValueMember = "Article";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSelectFilePath_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var saveFileDialog = new SaveFileDialog()
|
||||||
|
{
|
||||||
|
Filter = "Excel Files | *.xlsx"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
textBoxFilePath.Text = saveFileDialog.FileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonBuild_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(textBoxFilePath.Text))
|
||||||
|
{
|
||||||
|
throw new Exception("Отсутствует имя файла для отчета!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comboBoxProduct.SelectedIndex < 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Не выбранф номенклатура!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dateTimePickerEnd.Value <= dateTimePickerStart.Value)
|
||||||
|
{
|
||||||
|
throw new Exception("Дата начала должна быть раньше даты окончания!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text,
|
||||||
|
(int)comboBoxProduct.SelectedValue!, dateTimePickerStart.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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>
|
@ -12,14 +12,80 @@ internal class DocReport
|
|||||||
{
|
{
|
||||||
private readonly IProductRepository _productRepository;
|
private readonly IProductRepository _productRepository;
|
||||||
private readonly IAgentsRepository _agentsRepository;
|
private readonly IAgentsRepository _agentsRepository;
|
||||||
private readonly IPurchasingCompanyRepository _purchaseCompanyRepository;
|
private readonly IPurchasingCompanyRepository _purchasingCompanyRepository;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public DocReport(IProductRepository productRepository, IAgentsRepository agentsRepository, IPurchasingCompanyRepository purchaseCompanyRepository, ILogger logger)
|
public DocReport(IProductRepository productRepository, IAgentsRepository agentsRepository, IPurchasingCompanyRepository purchasingCompanyRepository, ILogger logger)
|
||||||
{
|
{
|
||||||
_productRepository = productRepository;
|
_productRepository = productRepository ??
|
||||||
_agentsRepository = agentsRepository;
|
throw new ArgumentNullException(nameof(productRepository));
|
||||||
_purchaseCompanyRepository = purchaseCompanyRepository;
|
_agentsRepository = agentsRepository ??
|
||||||
_logger = logger;
|
throw new ArgumentNullException(nameof(agentsRepository));
|
||||||
|
_purchasingCompanyRepository = purchasingCompanyRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(purchasingCompanyRepository));
|
||||||
|
_logger = logger ??
|
||||||
|
throw new ArgumentNullException(nameof(logger));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CreateDoc(string filePath, bool includeProducts, bool includeAgents, bool includePurchasingCompany)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var builder = new WordBuilder(filePath)
|
||||||
|
.AddHeader("Документ со справочниками.");
|
||||||
|
if (includeProducts)
|
||||||
|
{
|
||||||
|
builder.AddParagraph("Номенклатура")
|
||||||
|
.AddTable([2400, 1200, 2400, 2400, 1200], GetProducts());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeAgents)
|
||||||
|
{
|
||||||
|
builder.AddParagraph("Агенты-реализаторы")
|
||||||
|
.AddTable([3400, 2400, 2400], GetAgents());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includePurchasingCompany)
|
||||||
|
{
|
||||||
|
builder.AddParagraph("Компании-закупщики.")
|
||||||
|
.AddTable([4800], GetCompanies());
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.Build();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при формировании документа!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<string[]> GetProducts()
|
||||||
|
{
|
||||||
|
return [["Номенклатура", "Цена", "Единица изменерия", "Категория", "Количество на складе"],
|
||||||
|
.. _productRepository
|
||||||
|
.ReadProducts()
|
||||||
|
.Select(x => new string[] { x.Name, x.SellingPrice.ToString(), x.Unit.ToString(), x.Category.ToString(), x.InventoryQuantity.ToString()})
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<string[]> GetAgents()
|
||||||
|
{
|
||||||
|
return [["Имя", "Квалификация", "Категория"],
|
||||||
|
.. _agentsRepository
|
||||||
|
.ReadAgents()
|
||||||
|
.Select(x => new string[] { x.Name, x.Qualification.ToString(), x.Category.ToString()})
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<string[]> GetCompanies()
|
||||||
|
{
|
||||||
|
return [["Наименование компании"],
|
||||||
|
.. _purchasingCompanyRepository
|
||||||
|
.ReadCompanies()
|
||||||
|
.Select(x => new string[] { x.Name})
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,271 @@
|
|||||||
|
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 TradeAndProcurementEnterprice.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 cnt)
|
||||||
|
{
|
||||||
|
CreateCell(startIndex, _rowIndex, header, StyleIndex.SimpleTextWithoutBorder);
|
||||||
|
for (int i = startIndex + 1; i < startIndex + cnt; ++i)
|
||||||
|
{
|
||||||
|
CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder);
|
||||||
|
}
|
||||||
|
|
||||||
|
_mergeCells.Append(new MergeCell()
|
||||||
|
{
|
||||||
|
Reference = new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + cnt - 1)}{_rowIndex}")
|
||||||
|
}); _rowIndex++;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public ExcelBuilder AddParagraph(string text, int columnIndex)
|
||||||
|
{
|
||||||
|
CreateCell(columnIndex, _rowIndex++, text, StyleIndex.SimpleTextWithoutBorder);
|
||||||
|
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.SimpleTextWithoutBorder);
|
||||||
|
}
|
||||||
|
|
||||||
|
_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.SimpleTextWithoutBorder);
|
||||||
|
}
|
||||||
|
|
||||||
|
_rowIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var j = 0; j < data.Last().Length; ++j)
|
||||||
|
{
|
||||||
|
CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.SimpleTextWithoutBorder);
|
||||||
|
}
|
||||||
|
|
||||||
|
_rowIndex++;
|
||||||
|
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) }
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO добавить шрифт с жирным.
|
||||||
|
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()
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO добавить настройку с границами.
|
||||||
|
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 дополнить форматы.
|
||||||
|
workbookStylesPart.Stylesheet.Append(cellFormats);
|
||||||
|
}
|
||||||
|
private enum StyleIndex
|
||||||
|
{
|
||||||
|
SimpleTextWithoutBorder = 0,
|
||||||
|
// TODO дополнить стили.
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TradeAndProcurementEnterprice.Repositories;
|
||||||
|
|
||||||
|
namespace TradeAndProcurementEnterprice.Reports;
|
||||||
|
|
||||||
|
internal class TableReport
|
||||||
|
{
|
||||||
|
private readonly IContractRepository _contractRepository;
|
||||||
|
|
||||||
|
private readonly IDelegateToAgentRepository _delegateToAgentRepository;
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
internal static readonly string[] item = ["Агент-реализатор", "Дата", "Продано", "Получено"];
|
||||||
|
|
||||||
|
public TableReport(IContractRepository contractRepository, IDelegateToAgentRepository
|
||||||
|
delegateToAgentRepository, ILogger<TableReport> logger)
|
||||||
|
{
|
||||||
|
_contractRepository = contractRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(contractRepository));
|
||||||
|
_delegateToAgentRepository = delegateToAgentRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(delegateToAgentRepository));
|
||||||
|
_logger = logger ??
|
||||||
|
throw new ArgumentNullException(nameof(_logger));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CreateTable(string filePath, int productArticle, DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
new ExcelBuilder(filePath)
|
||||||
|
.AddHeader("Сводка по передвижению товара", 0, 4)
|
||||||
|
.AddParagraph("За период", 0)
|
||||||
|
.AddTable([10, 10, 15, 15], GetData(productArticle, startDate, endDate))
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при форматировании документа!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<string[]> GetData(int productArticle, DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
var data = _contractRepository
|
||||||
|
.ReadContracts()
|
||||||
|
.Where(x => x.SaleDate >= startDate && x.SaleDate <= endDate && x.ProductSales.Any(y => y.ProductArticle == productArticle))
|
||||||
|
.Select(x => new
|
||||||
|
{
|
||||||
|
x.AgentsID,
|
||||||
|
CurrentDate = x.SaleDate,
|
||||||
|
CountIn = (int?)null,
|
||||||
|
CountOut = x.ProductSales.FirstOrDefault(y => y.ProductArticle == productArticle)?.ProductQuantity
|
||||||
|
})
|
||||||
|
.Union(
|
||||||
|
_delegateToAgentRepository
|
||||||
|
.ReadDelegatesToAgent()
|
||||||
|
.Where(x => x.Date >= startDate && x.Date <= endDate && x.ProductArticle == productArticle)
|
||||||
|
.Select(x => new { x.AgentsID, CurrentDate = x.Date, CountIn = (int?)x.Quantity, CountOut = (int?)null }))
|
||||||
|
.OrderBy(x => x.CurrentDate);
|
||||||
|
|
||||||
|
return
|
||||||
|
new List<string[]>() { item }
|
||||||
|
.Union(
|
||||||
|
data
|
||||||
|
.Select(x => new string[] { x.AgentsID.ToString(), x.CurrentDate.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();
|
||||||
|
}
|
||||||
|
}
|
@ -36,16 +36,16 @@ internal class ContractRepository : IContractRepository
|
|||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Contracts (SaleDate, PurchasingCompanyID, AgentsID)
|
INSERT INTO Contracts (SaleDate, PurchasingCompanyID, AgentsID)
|
||||||
VALUES (@SaleDate, @PurchasingCompanyID, @AgentsID);
|
VALUES (@SaleDate, @PurchasingCompanyID, @AgentsID);
|
||||||
SELECT MAX(contractid) FROM Contracts";
|
SELECT MAX(ID) FROM Contracts";
|
||||||
var contractId = connection.QueryFirst<int>(queryInsert, contract, transaction);
|
var id = connection.QueryFirst<int>(queryInsert, contract, transaction);
|
||||||
|
|
||||||
var querySubInsert = @"
|
var querySubInsert = @"
|
||||||
INSERT INTO ProductSales (ContractId, ProductArticle, ProductQuantity)
|
INSERT INTO ProductSales (ID, ProductArticle, ProductQuantity)
|
||||||
VALUES (@ContractId, @ProductArticle, @ProductQuantity)";
|
VALUES (@ID, @ProductArticle, @ProductQuantity)";
|
||||||
|
|
||||||
foreach (var elem in contract.ProductSales)
|
foreach (var elem in contract.ProductSales)
|
||||||
{
|
{
|
||||||
connection.Execute(querySubInsert, new { contractId, elem.ProductArticle, elem.ProductQuantity }, transaction);
|
connection.Execute(querySubInsert, new { id, elem.ProductArticle, elem.ProductQuantity }, transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
@ -63,10 +63,14 @@ VALUES (@ContractId, @ProductArticle, @ProductQuantity)";
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = "SELECT * FROM Contracts";
|
var querySelect = @"
|
||||||
var contracts = connection.Query<Contract>(querySelect);
|
SELECT c.*, ps.ProductArticle, ps.ProductQuantity FROM Contracts c
|
||||||
|
INNER JOIN ProductSales ps ON ps.ID = c.ID";
|
||||||
|
var contracts = connection.Query<TempProductSales>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
||||||
return contracts;
|
return contracts.GroupBy(x => x.ID, y => y,
|
||||||
|
(key, value) => Contract.CreateOperation(value.First(),
|
||||||
|
value.Select(z => ProductSales.CreateElement(0, z.ProductArticle, z.ProductQuantity))));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user