Усложнённая лабораторная №4: Вроде готова

This commit is contained in:
Сергей Полевой 2023-04-23 20:25:00 +04:00
parent 6d72d41af2
commit da6b1d58c8
24 changed files with 1307 additions and 24 deletions

View File

@ -38,11 +38,14 @@
this.guidesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.guidesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.bouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.listOfBouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listOfBouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentsByBouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentsByBouquetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.listOfOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listOfOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.shopListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bouquetsInShopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ordersByDateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonSupplyShop = new System.Windows.Forms.Button(); this.buttonSupplyShop = new System.Windows.Forms.Button();
this.buttonSellBouquets = new System.Windows.Forms.Button(); this.buttonSellBouquets = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
@ -152,12 +155,22 @@
this.bouquetsToolStripMenuItem.Text = "Букеты"; this.bouquetsToolStripMenuItem.Text = "Букеты";
this.bouquetsToolStripMenuItem.Click += new System.EventHandler(this.bouquetsToolStripMenuItem_Click); this.bouquetsToolStripMenuItem.Click += new System.EventHandler(this.bouquetsToolStripMenuItem_Click);
// //
// shopsToolStripMenuItem
//
this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem";
this.shopsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.shopsToolStripMenuItem.Text = "Магазины";
this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click);
//
// reportsToolStripMenuItem // reportsToolStripMenuItem
// //
this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.listOfBouquetsToolStripMenuItem, this.listOfBouquetsToolStripMenuItem,
this.componentsByBouquetsToolStripMenuItem, this.componentsByBouquetsToolStripMenuItem,
this.listOfOrdersToolStripMenuItem}); this.listOfOrdersToolStripMenuItem,
this.shopListToolStripMenuItem,
this.bouquetsInShopsToolStripMenuItem,
this.ordersByDateToolStripMenuItem});
this.reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; this.reportsToolStripMenuItem.Name = "reportsToolStripMenuItem";
this.reportsToolStripMenuItem.Size = new System.Drawing.Size(60, 22); this.reportsToolStripMenuItem.Size = new System.Drawing.Size(60, 22);
this.reportsToolStripMenuItem.Text = "Отчёты"; this.reportsToolStripMenuItem.Text = "Отчёты";
@ -183,12 +196,26 @@
this.listOfOrdersToolStripMenuItem.Text = "Список заказов"; this.listOfOrdersToolStripMenuItem.Text = "Список заказов";
this.listOfOrdersToolStripMenuItem.Click += new System.EventHandler(this.listOfOrdersToolStripMenuItem_Click); this.listOfOrdersToolStripMenuItem.Click += new System.EventHandler(this.listOfOrdersToolStripMenuItem_Click);
// //
// shopsToolStripMenuItem // shopListToolStripMenuItem
// //
this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; this.shopListToolStripMenuItem.Name = "shopListToolStripMenuItem";
this.shopsToolStripMenuItem.Size = new System.Drawing.Size(145, 22); this.shopListToolStripMenuItem.Size = new System.Drawing.Size(210, 22);
this.shopsToolStripMenuItem.Text = "Магазины"; this.shopListToolStripMenuItem.Text = "Список магазинов";
this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click); this.shopListToolStripMenuItem.Click += new System.EventHandler(this.shopListToolStripMenuItem_Click);
//
// bouquetsInShopsToolStripMenuItem
//
this.bouquetsInShopsToolStripMenuItem.Name = "bouquetsInShopsToolStripMenuItem";
this.bouquetsInShopsToolStripMenuItem.Size = new System.Drawing.Size(210, 22);
this.bouquetsInShopsToolStripMenuItem.Text = "Букеты в магазинах";
this.bouquetsInShopsToolStripMenuItem.Click += new System.EventHandler(this.bouquetsInShopsToolStripMenuItem_Click);
//
// ordersByDateToolStripMenuItem
//
this.ordersByDateToolStripMenuItem.Name = "ordersByDateToolStripMenuItem";
this.ordersByDateToolStripMenuItem.Size = new System.Drawing.Size(210, 22);
this.ordersByDateToolStripMenuItem.Text = "Список заказов по дате";
this.ordersByDateToolStripMenuItem.Click += new System.EventHandler(this.ordersByDateToolStripMenuItem_Click);
// //
// buttonSupplyShop // buttonSupplyShop
// //
@ -256,5 +283,8 @@
private ToolStripMenuItem shopsToolStripMenuItem; private ToolStripMenuItem shopsToolStripMenuItem;
private Button buttonSupplyShop; private Button buttonSupplyShop;
private Button buttonSellBouquets; private Button buttonSellBouquets;
private ToolStripMenuItem shopListToolStripMenuItem;
private ToolStripMenuItem bouquetsInShopsToolStripMenuItem;
private ToolStripMenuItem ordersByDateToolStripMenuItem;
} }
} }

View File

@ -211,5 +211,36 @@ namespace FlowerShop
form.ShowDialog(); form.ShowDialog();
} }
} }
private void shopListToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveShopsToWordFile(new ReportBindingModel
{
FileName = dialog.FileName
});
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void bouquetsInShopsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportShopBouquets));
if (service is FormReportShopBouquets form)
{
form.ShowDialog();
}
}
private void ordersByDateToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportDateOrders));
if (service is FormReportDateOrders form)
{
form.ShowDialog();
}
}
} }
} }

View File

@ -0,0 +1,90 @@
namespace FlowerShop
{
partial class FormReportDateOrders
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel = new System.Windows.Forms.Panel();
this.buttonCreateToPdf = new System.Windows.Forms.Button();
this.buttonCreateReport = new System.Windows.Forms.Button();
this.panel.SuspendLayout();
this.SuspendLayout();
//
// panel
//
this.panel.Controls.Add(this.buttonCreateToPdf);
this.panel.Controls.Add(this.buttonCreateReport);
this.panel.Dock = System.Windows.Forms.DockStyle.Top;
this.panel.Location = new System.Drawing.Point(0, 0);
this.panel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.panel.Name = "panel";
this.panel.Size = new System.Drawing.Size(856, 52);
this.panel.TabIndex = 1;
//
// buttonCreateToPdf
//
this.buttonCreateToPdf.Location = new System.Drawing.Point(678, 11);
this.buttonCreateToPdf.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreateToPdf.Name = "buttonCreateToPdf";
this.buttonCreateToPdf.Size = new System.Drawing.Size(166, 29);
this.buttonCreateToPdf.TabIndex = 5;
this.buttonCreateToPdf.Text = "PDF";
this.buttonCreateToPdf.UseVisualStyleBackColor = true;
this.buttonCreateToPdf.Click += new System.EventHandler(this.buttonCreateToPdf_Click);
//
// buttonCreateReport
//
this.buttonCreateReport.Location = new System.Drawing.Point(485, 11);
this.buttonCreateReport.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreateReport.Name = "buttonCreateReport";
this.buttonCreateReport.Size = new System.Drawing.Size(166, 29);
this.buttonCreateReport.TabIndex = 4;
this.buttonCreateReport.Text = "Сформировать";
this.buttonCreateReport.UseVisualStyleBackColor = true;
this.buttonCreateReport.Click += new System.EventHandler(this.buttonCreateReport_Click);
//
// FormReportDateOrders
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(856, 338);
this.Controls.Add(this.panel);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormReportDateOrders";
this.Text = "Заказы по датам";
this.panel.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private Panel panel;
private Button buttonCreateToPdf;
private Button buttonCreateReport;
}
}

View File

@ -0,0 +1,73 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using Microsoft.Reporting.WinForms;
namespace FlowerShop
{
public partial class FormReportDateOrders : Form
{
private readonly ReportViewer reportViewer;
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportDateOrders(ILogger<FormReportDateOrders> logger, IReportLogic reportLogic)
{
InitializeComponent();
_logger = logger;
_logic = reportLogic;
reportViewer = new ReportViewer
{
Dock = DockStyle.Fill
};
reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrdersByDate.rdlc", FileMode.Open));
Controls.Clear();
Controls.Add(reportViewer);
Controls.Add(panel);
}
private void buttonCreateReport_Click(object sender, EventArgs e)
{
try
{
var dataSource = _logic.GetDateOrders();
var source = new ReportDataSource("DataSetOrders", dataSource);
reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.DataSources.Add(source);
reportViewer.RefreshReport();
_logger.LogInformation("Loading list of orders by date");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of orders by date");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCreateToPdf_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" };
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveDateOrdersToPdfFile(new ReportBindingModel
{
FileName = dialog.FileName
});
_logger.LogInformation("Saving list of orders by date");
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during saving list of orders by date");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,110 @@
namespace FlowerShop
{
partial class FormReportShopBouquets
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonSaveToExcel = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.Shop = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Bouquet = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// buttonSaveToExcel
//
this.buttonSaveToExcel.Location = new System.Drawing.Point(10, 6);
this.buttonSaveToExcel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSaveToExcel.Name = "buttonSaveToExcel";
this.buttonSaveToExcel.Size = new System.Drawing.Size(154, 35);
this.buttonSaveToExcel.TabIndex = 0;
this.buttonSaveToExcel.Text = "Сохранить в Excel";
this.buttonSaveToExcel.UseVisualStyleBackColor = true;
this.buttonSaveToExcel.Click += new System.EventHandler(this.buttonSaveToExcel_Click);
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Shop,
this.Bouquet,
this.Count});
this.dataGridView.Location = new System.Drawing.Point(10, 45);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(679, 283);
this.dataGridView.TabIndex = 1;
//
// Shop
//
this.Shop.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.Shop.HeaderText = "Магазин";
this.Shop.MinimumWidth = 6;
this.Shop.Name = "Shop";
//
// Bouquet
//
this.Bouquet.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.Bouquet.HeaderText = "Букет";
this.Bouquet.MinimumWidth = 6;
this.Bouquet.Name = "Bouquet";
//
// Count
//
this.Count.HeaderText = "Количество";
this.Count.MinimumWidth = 6;
this.Count.Name = "Count";
this.Count.Width = 125;
//
// FormReportShopBouquets
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(700, 338);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.buttonSaveToExcel);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormReportShopBouquets";
this.Text = "Букеты в магазинах";
this.Load += new System.EventHandler(this.FormReportShopBouquets_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button buttonSaveToExcel;
private DataGridView dataGridView;
private DataGridViewTextBoxColumn Shop;
private DataGridViewTextBoxColumn Bouquet;
private DataGridViewTextBoxColumn Count;
}
}

View File

@ -0,0 +1,78 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace FlowerShop
{
public partial class FormReportShopBouquets : Form
{
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportShopBouquets(ILogger<FormReportShopBouquets> logger, IReportLogic reportLogic)
{
InitializeComponent();
_logger = logger;
_logic = reportLogic;
}
private void buttonSaveToExcel_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveShopBouquetsToExcelFile(new ReportBindingModel
{
FileName = dialog.FileName
});
_logger.LogInformation("Saving list of shops with bouquets");
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during saving list of shops with bouquets");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void FormReportShopBouquets_Load(object sender, EventArgs e)
{
try
{
var dict = _logic.GetShopBouquets();
if (dict != null)
{
dataGridView.Rows.Clear();
foreach (var elem in dict)
{
dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" });
foreach (var listElem in elem.Bouquets)
{
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
}
dataGridView.Rows.Add(new object[] { "Всего:", "", elem.Count });
dataGridView.Rows.Add(Array.Empty<object>());
}
}
_logger.LogInformation("Loading list of shops with bouquets");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of shops with bouquets");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,66 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="Shop.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -59,6 +59,8 @@ namespace FlowerShop
services.AddTransient<FormShopSell>(); services.AddTransient<FormShopSell>();
services.AddTransient<FormReportBouquetComponents>(); services.AddTransient<FormReportBouquetComponents>();
services.AddTransient<FormReportOrder>(); services.AddTransient<FormReportOrder>();
services.AddTransient<FormReportShopBouquets>();
services.AddTransient<FormReportDateOrders>();
} }
} }
} }

View File

@ -297,7 +297,6 @@
<PaddingBottom>2pt</PaddingBottom> <PaddingBottom>2pt</PaddingBottom>
</Style> </Style>
</Textbox> </Textbox>
<rd:Selected>true</rd:Selected>
</CellContents> </CellContents>
</TablixCell> </TablixCell>
</TablixCells> </TablixCells>

View File

@ -0,0 +1,424 @@
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<AutoRefresh>0</AutoRefresh>
<DataSources>
<DataSource Name="FlowerShopContractsViewModels">
<ConnectionProperties>
<DataProvider>System.Data.DataSet</DataProvider>
<ConnectString>/* Local Connection */</ConnectString>
</ConnectionProperties>
<rd:DataSourceID>10791c83-cee8-4a38-bbd0-245fc17cefb3</rd:DataSourceID>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name="DataSetOrders">
<Query>
<DataSourceName>FlowerShopContractsViewModels</DataSourceName>
<CommandText>/* Local Query */</CommandText>
</Query>
<Fields>
<Field Name="DateCreate">
<DataField>DateCreate</DataField>
<rd:TypeName>System.DateTime</rd:TypeName>
</Field>
<Field Name="CountOrders">
<DataField>CountOrders</DataField>
<rd:TypeName>System.Decimal</rd:TypeName>
</Field>
<Field Name="SumOrders">
<DataField>SumOrders</DataField>
<rd:TypeName>System.Double</rd:TypeName>
</Field>
</Fields>
<rd:DataSetInfo>
<rd:DataSetName>FlowerShopContracts.ViewModels</rd:DataSetName>
<rd:TableName>ReportDateOrdersViewModel</rd:TableName>
<rd:ObjectDataSourceType>FlowerShopContracts.ViewModels.ReportDateOrdersViewModel, FlowerShopContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>
</rd:DataSetInfo>
</DataSet>
</DataSets>
<ReportSections>
<ReportSection>
<Body>
<ReportItems>
<Textbox Name="TextboxTitle">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Заказы</Value>
<Style>
<FontSize>16pt</FontSize>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style>
<TextAlign>Center</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<Height>1cm</Height>
<Width>21cm</Width>
<Style>
<Border>
<Style>None</Style>
</Border>
<VerticalAlign>Middle</VerticalAlign>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
<Tablix Name="Tablix1">
<TablixBody>
<TablixColumns>
<TablixColumn>
<Width>3cm</Width>
</TablixColumn>
<TablixColumn>
<Width>3cm</Width>
</TablixColumn>
<TablixColumn>
<Width>7cm</Width>
</TablixColumn>
</TablixColumns>
<TablixRows>
<TablixRow>
<Height>0.6cm</Height>
<TablixCells>
<TablixCell>
<CellContents>
<Textbox Name="Textbox1">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Дата</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox1</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Textbox3">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Количество</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox3</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Textbox2">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Сумма</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox2</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
</TablixCells>
</TablixRow>
<TablixRow>
<Height>0.6cm</Height>
<TablixCells>
<TablixCell>
<CellContents>
<Textbox Name="DateCreate">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!DateCreate.Value</Value>
<Style>
<Format>d</Format>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>DateCreate</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="CountOrders">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!CountOrders.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>CountOrders</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="SumOrders">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!SumOrders.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>SumOrders</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
</TablixCells>
</TablixRow>
</TablixRows>
</TablixBody>
<TablixColumnHierarchy>
<TablixMembers>
<TablixMember />
<TablixMember />
<TablixMember />
</TablixMembers>
</TablixColumnHierarchy>
<TablixRowHierarchy>
<TablixMembers>
<TablixMember>
<KeepWithGroup>After</KeepWithGroup>
</TablixMember>
<TablixMember>
<Group Name="Подробности" />
</TablixMember>
</TablixMembers>
</TablixRowHierarchy>
<DataSetName>DataSetOrders</DataSetName>
<Top>2.48391cm</Top>
<Left>0.55245cm</Left>
<Height>1.2cm</Height>
<Width>13cm</Width>
<ZIndex>1</ZIndex>
<Style>
<Border>
<Style>Double</Style>
</Border>
</Style>
</Tablix>
<Textbox Name="TextboxTotalSum">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Всего:</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style>
<TextAlign>Right</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<Top>4cm</Top>
<Left>8.55245cm</Left>
<Height>0.6cm</Height>
<Width>2.5cm</Width>
<ZIndex>2</ZIndex>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
<Textbox Name="SumTotal">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Sum(Fields!SumOrders.Value, "DataSetOrders")</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style>
<TextAlign>Right</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<Top>4cm</Top>
<Left>11.05245cm</Left>
<Height>0.6cm</Height>
<Width>2.5cm</Width>
<ZIndex>3</ZIndex>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</ReportItems>
<Height>5.72875cm</Height>
<Style />
</Body>
<Width>21cm</Width>
<Page>
<PageHeight>29.7cm</PageHeight>
<PageWidth>21cm</PageWidth>
<LeftMargin>2cm</LeftMargin>
<RightMargin>2cm</RightMargin>
<TopMargin>2cm</TopMargin>
<BottomMargin>2cm</BottomMargin>
<ColumnSpacing>0.13cm</ColumnSpacing>
<Style />
</Page>
</ReportSection>
</ReportSections>
<ReportParameters>
<ReportParameter Name="ReportParameterPeriod">
<DataType>String</DataType>
<Nullable>true</Nullable>
<Prompt>ReportParameter1</Prompt>
</ReportParameter>
</ReportParameters>
<ReportParametersLayout>
<GridLayoutDefinition>
<NumberOfColumns>4</NumberOfColumns>
<NumberOfRows>2</NumberOfRows>
<CellDefinitions>
<CellDefinition>
<ColumnIndex>0</ColumnIndex>
<RowIndex>0</RowIndex>
<ParameterName>ReportParameterPeriod</ParameterName>
</CellDefinition>
</CellDefinitions>
</GridLayoutDefinition>
</ReportParametersLayout>
<rd:ReportUnitType>Cm</rd:ReportUnitType>
<rd:ReportID>2de0031a-4d17-449d-922d-d9fc54572312</rd:ReportID>
</Report>

View File

@ -13,15 +13,17 @@ namespace FlowerShopBusinessLogic.BusinessLogics
private readonly IComponentStorage _componentStorage; private readonly IComponentStorage _componentStorage;
private readonly IBouquetStorage _bouquetStorage; private readonly IBouquetStorage _bouquetStorage;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf; private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IBouquetStorage bouquetStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) public ReportLogic(IBouquetStorage bouquetStorage, IComponentStorage componentStorage, IShopStorage shopStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{ {
_bouquetStorage = bouquetStorage; _bouquetStorage = bouquetStorage;
_componentStorage = componentStorage; _componentStorage = componentStorage;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_shopStorage = shopStorage;
_saveToExcel = saveToExcel; _saveToExcel = saveToExcel;
_saveToWord = saveToWord; _saveToWord = saveToWord;
_saveToPdf = saveToPdf; _saveToPdf = saveToPdf;
@ -29,7 +31,6 @@ namespace FlowerShopBusinessLogic.BusinessLogics
public List<ReportBouquetComponentViewModel> GetBouquetComponents() public List<ReportBouquetComponentViewModel> GetBouquetComponents()
{ {
var components = _componentStorage.GetFullList();
var bouquets = _bouquetStorage.GetFullList(); var bouquets = _bouquetStorage.GetFullList();
var list = new List<ReportBouquetComponentViewModel>(); var list = new List<ReportBouquetComponentViewModel>();
foreach (var bouquet in bouquets) foreach (var bouquet in bouquets)
@ -40,13 +41,10 @@ namespace FlowerShopBusinessLogic.BusinessLogics
Components = new List<(string Component, int Count)>(), Components = new List<(string Component, int Count)>(),
TotalCount = 0 TotalCount = 0
}; };
foreach (var component in components) foreach (var component in bouquet.BouquetComponents.Values)
{ {
if (bouquet.BouquetComponents.ContainsKey(component.Id)) record.Components.Add((component.Item1.ComponentName, component.Item2));
{ record.TotalCount += component.Item2;
record.Components.Add(new(component.ComponentName, bouquet.BouquetComponents[component.Id].Item2));
record.TotalCount += bouquet.BouquetComponents[component.Id].Item2;
}
} }
list.Add(record); list.Add(record);
} }
@ -103,5 +101,70 @@ namespace FlowerShopBusinessLogic.BusinessLogics
}); });
} }
public void SaveShopsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateTableDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список магазинов",
Shops = _shopStorage.GetFullList()
});
}
public void SaveShopBouquetsToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateShopReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Загруженность магазинов",
ShopBouquets = GetShopBouquets()
});
}
public List<ReportShopBouquetsViewModel> GetShopBouquets()
{
var shops = _shopStorage.GetFullList();
var list = new List<ReportShopBouquetsViewModel>();
foreach (var shop in shops)
{
var record = new ReportShopBouquetsViewModel
{
ShopName = shop.Name,
Bouquets = new List<(string, int)>(),
Count = 0
};
foreach (var bouquetCount in shop.ShopBouquets.Values)
{
record.Bouquets.Add((bouquetCount.Item1.BouquetName, bouquetCount.Item2));
record.Count += bouquetCount.Item2;
}
list.Add(record);
}
return list;
}
public List<ReportDateOrdersViewModel> GetDateOrders()
{
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportDateOrdersViewModel
{
DateCreate = x.Key,
CountOrders = x.Count(),
SumOrders = x.Sum(y => y.Sum)
}).ToList();
}
public void SaveDateOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateReportDateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Заказы по датам",
DateOrders = GetDateOrders()
});
}
} }
} }

View File

@ -79,6 +79,76 @@ namespace FlowerShopBusinessLogic.OfficePackage
SaveExcel(info); SaveExcel(info);
} }
public void CreateShopReport(ExcelInfo info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var pc in info.ShopBouquets)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.ShopName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var (BouquetName, Count) in pc.Bouquets)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = BouquetName,
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = Count.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Итого",
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = pc.Count.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel(info);
}
protected abstract void CreateExcel(ExcelInfo info); protected abstract void CreateExcel(ExcelInfo info);
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);

View File

@ -52,6 +52,46 @@ namespace FlowerShopBusinessLogic.OfficePackage
SavePdf(info); SavePdf(info);
} }
public void CreateReportDateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "3cm", "3cm", "7cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Дата", "Количество", "Сумма" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var order in info.DateOrders)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { order.DateCreate.ToShortDateString(), order.CountOrders.ToString(), order.SumOrders.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph
{
Text = $"Итого: {info.DateOrders.Sum(x => x.SumOrders)}\t",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
SavePdf(info);
}
protected abstract void CreatePdf(PdfInfo info); protected abstract void CreatePdf(PdfInfo info);
protected abstract void CreateParagraph(PdfParagraph paragraph); protected abstract void CreateParagraph(PdfParagraph paragraph);

View File

@ -37,10 +37,38 @@ namespace FlowerShopBusinessLogic.OfficePackage
SaveWord(info); SaveWord(info);
} }
public void CreateTableDoc(WordInfo wordInfo)
{
CreateWord(wordInfo);
var list = new List<string>();
foreach (var shop in wordInfo.Shops)
{
list.Add(shop.Name);
list.Add(shop.Address);
list.Add(shop.OpeningDate.ToString());
}
var wordTable = new WordTable
{
Headers = new List<string> {
"Название",
"Адрес",
"Дата открытия"},
Texts = list
};
CreateTable(wordTable);
SaveWord(wordInfo);
}
protected abstract void CreateWord(WordInfo info); protected abstract void CreateWord(WordInfo info);
protected abstract void CreateParagraph(WordParagraph paragraph); protected abstract void CreateParagraph(WordParagraph paragraph);
protected abstract void SaveWord(WordInfo info); protected abstract void SaveWord(WordInfo info);
protected abstract void CreateTable(WordTable info);
} }
} }

View File

@ -7,5 +7,6 @@ namespace FlowerShopBusinessLogic.OfficePackage.HelperModels
public string FileName { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public List<ReportBouquetComponentViewModel> BouquetComponents { get; set; } = new(); public List<ReportBouquetComponentViewModel> BouquetComponents { get; set; } = new();
public List<ReportShopBouquetsViewModel> ShopBouquets { get; set; } = new();
} }
} }

View File

@ -9,5 +9,6 @@ namespace FlowerShopBusinessLogic.OfficePackage.HelperModels
public DateTime DateFrom { get; set; } public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; } public DateTime DateTo { get; set; }
public List<ReportOrdersViewModel> Orders { get; set; } = new(); public List<ReportOrdersViewModel> Orders { get; set; } = new();
public List<ReportDateOrdersViewModel> DateOrders { get; set; } = new();
} }
} }

View File

@ -7,5 +7,6 @@ namespace FlowerShopBusinessLogic.OfficePackage.HelperModels
public string FileName { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public List<BouquetViewModel> Bouquets { get; set; } = new(); public List<BouquetViewModel> Bouquets { get; set; } = new();
public List<ShopViewModel> Shops { get; set; } = new();
} }
} }

View File

@ -0,0 +1,8 @@
namespace FlowerShopBusinessLogic.OfficePackage.HelperModels
{
public class WordTable
{
public List<string> Headers { get; set; } = new();
public List<string> Texts { get; set; } = new();
}
}

View File

@ -22,16 +22,14 @@ namespace FlowerShopBusinessLogic.OfficePackage.Implements
var fonts = new Fonts() { Count = 2U, KnownFonts = true }; var fonts = new Fonts() { Count = 2U, KnownFonts = true };
var fontUsual = new Font(); var fontUsual = new Font();
fontUsual.Append(new FontSize() { Val = 12D }); fontUsual.Append(new FontSize() { Val = 12D });
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
{ Theme = 1U });
fontUsual.Append(new FontName() { Val = "Times New Roman" }); fontUsual.Append(new FontName() { Val = "Times New Roman" });
fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
var fontTitle = new Font(); var fontTitle = new Font();
fontTitle.Append(new Bold()); fontTitle.Append(new Bold());
fontTitle.Append(new FontSize() { Val = 14D }); fontTitle.Append(new FontSize() { Val = 14D });
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
{ Theme = 1U });
fontTitle.Append(new FontName() { Val = "Times New Roman" }); fontTitle.Append(new FontName() { Val = "Times New Roman" });
fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
@ -125,15 +123,15 @@ namespace FlowerShopBusinessLogic.OfficePackage.Implements
}; };
cellFormats.Append(cellFormatFont); cellFormats.Append(cellFormatFont);
cellFormats.Append(cellFormatFontAndBorder); cellFormats.Append(cellFormatFontAndBorder);
cellFormats.Append(cellFormatTitle); var cellStyles = new CellStyles() { Count = 1U }; cellFormats.Append(cellFormatTitle);
var cellStyles = new CellStyles() { Count = 1U };
cellStyles.Append(new CellStyle() cellStyles.Append(new CellStyle()
{ {
Name = "Normal", Name = "Normal",
FormatId = 0U, FormatId = 0U,
BuiltinId = 0U BuiltinId = 0U
}); });
var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U };
{ Count = 0U };
var tableStyles = new TableStyles() var tableStyles = new TableStyles()
{ {

View File

@ -108,5 +108,87 @@ namespace FlowerShopBusinessLogic.OfficePackage.Implements
_wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Close(); _wordDocument.Close();
} }
protected override void CreateTable(WordTable table)
{
if (_docBody == null || table == null)
{
return;
}
Table tab = new Table();
TableProperties props = 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
}
)
);
tab.AppendChild<TableProperties>(props);
TableGrid tableGrid = new TableGrid();
for (int i = 0; i < table.Headers.Count; i++)
{
tableGrid.AppendChild(new GridColumn());
}
tab.AppendChild(tableGrid);
TableRow tableRow = new TableRow();
foreach (var text in table.Headers)
{
tableRow.AppendChild(CreateTableCell(text));
}
tab.AppendChild(tableRow);
int height = table.Texts.Count / table.Headers.Count;
int width = table.Headers.Count;
for (int i = 0; i < height; i++)
{
tableRow = new TableRow();
for (int j = 0; j < width; j++)
{
var element = table.Texts[i * table.Headers.Count + j];
tableRow.AppendChild(CreateTableCell(element));
}
tab.AppendChild(tableRow);
}
_docBody.AppendChild(tab);
}
private TableCell CreateTableCell(string element)
{
var tableParagraph = new Paragraph();
var run = new Run();
run.AppendChild(new Text { Text = element });
tableParagraph.AppendChild(run);
var tableCell = new TableCell();
tableCell.AppendChild(tableParagraph);
return tableCell;
}
} }
} }

View File

@ -14,5 +14,15 @@ namespace FlowerShopContracts.BusinessLogicsContracts
void SaveBouquetComponentToExcelFile(ReportBindingModel model); void SaveBouquetComponentToExcelFile(ReportBindingModel model);
void SaveOrdersToPdfFile(ReportBindingModel model); void SaveOrdersToPdfFile(ReportBindingModel model);
void SaveShopsToWordFile(ReportBindingModel model);
void SaveShopBouquetsToExcelFile(ReportBindingModel model);
List<ReportShopBouquetsViewModel> GetShopBouquets();
List<ReportDateOrdersViewModel> GetDateOrders();
void SaveDateOrdersToPdfFile(ReportBindingModel model);
} }
} }

View File

@ -0,0 +1,9 @@
namespace FlowerShopContracts.ViewModels
{
public class ReportDateOrdersViewModel
{
public DateTime DateCreate { get; set; }
public int CountOrders { get; set; }
public double SumOrders { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace FlowerShopContracts.ViewModels
{
public class ReportShopBouquetsViewModel
{
public string ShopName { get; set; } = string.Empty;
public int Count { get; set; }
public List<(string, int)> Bouquets { get; set; } = new();
}
}