Реализовано сохранения магазинов в excel файл

This commit is contained in:
Данияр Аглиуллов 2023-03-02 03:15:42 +04:00
parent bb405202d7
commit a6715682eb
12 changed files with 82 additions and 68 deletions

View File

@ -33,24 +33,24 @@ namespace ConfectioneryBusinessLogic.OfficePackage
}); });
uint rowIndex = 2; uint rowIndex = 2;
foreach (var pc in info.PastryComponents) foreach (var pc in info.ShopPastries)
{ {
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
{ {
ColumnName = "A", ColumnName = "A",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = pc.PastryName, Text = pc.ShopName,
StyleInfo = ExcelStyleInfoType.Text StyleInfo = ExcelStyleInfoType.Text
}); });
rowIndex++; rowIndex++;
foreach (var (Pastry, Count) in pc.Components) foreach (var (Shop, Count) in pc.Pastries)
{ {
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
{ {
ColumnName = "B", ColumnName = "B",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = Pastry, Text = Shop,
StyleInfo = ExcelStyleInfoType.TextWithBroder StyleInfo = ExcelStyleInfoType.TextWithBroder
}); });
@ -80,6 +80,21 @@ namespace ConfectioneryBusinessLogic.OfficePackage
StyleInfo = ExcelStyleInfoType.Text StyleInfo = ExcelStyleInfoType.Text
}); });
rowIndex++; rowIndex++;
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Загруженность",
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = pc.Workload.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
} }
SaveExcel(info); SaveExcel(info);

View File

@ -6,7 +6,7 @@ namespace ConfectioneryBusinessLogic.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<ReportPastryComponentViewModel> PastryComponents public List<ReportShopPastrytViewModel> ShopPastries
{ {
get; get;
set; set;

View File

@ -10,8 +10,6 @@ namespace ConfectioneryBusinessLogic
{ {
public class ReportLogic : IReportLogic public class ReportLogic : IReportLogic
{ {
private readonly IComponentStorage _componentStorage;
private readonly IPastryStorage _pastryStorage; private readonly IPastryStorage _pastryStorage;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
@ -24,11 +22,10 @@ namespace ConfectioneryBusinessLogic
private readonly AbstractSaveToPdf _saveToPdf; private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IPastryStorage PastryStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, public ReportLogic(IPastryStorage PastryStorage, IOrderStorage orderStorage, IShopStorage shopStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{ {
_pastryStorage = PastryStorage; _pastryStorage = PastryStorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_shopStorage = shopStorage; _shopStorage = shopStorage;
@ -38,34 +35,34 @@ namespace ConfectioneryBusinessLogic
} }
/// <summary> /// <summary>
/// Получение списка компонент с указанием, в каких изделиях используются /// Получение списка магазинов с изделиями
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public List<ReportPastryComponentViewModel> GetPastryComponent() public List<ReportShopPastrytViewModel> GetShopPastries()
{ {
var components = _componentStorage.GetFullList(); var shops = _shopStorage.GetFullList();
var pastries = _pastryStorage.GetFullList(); var pastries = _pastryStorage.GetFullList();
var list = new List<ReportPastryComponentViewModel>(); var list = new List<ReportShopPastrytViewModel>();
foreach (var pastry in pastries) foreach (var shop in shops)
{ {
var record = new ReportPastryComponentViewModel var record = new ReportShopPastrytViewModel
{ {
PastryName = pastry.PastryName, ShopName = shop.Name,
Components = new List<Tuple<string, int>>(), Pastries = new List<Tuple<string, int>>(),
TotalCount = 0 TotalCount = 0
}; };
foreach (var component in components) foreach (var pastry in pastries)
{ {
if (pastry.PastryComponents.ContainsKey(component.Id)) if (shop.Pastries.ContainsKey(pastry.Id))
{ {
record.Components.Add(new(component.ComponentName, pastry.PastryComponents[component.Id].Item2)); record.Pastries.Add(new(pastry.PastryName, shop.Pastries[pastry.Id].Item2));
record.TotalCount += pastry.PastryComponents[component.Id].Item2; record.TotalCount += shop.Pastries[pastry.Id].Item2;
} }
} }
record.Workload = record.TotalCount / (double)shop.MaxCountPastries;
list.Add(record); list.Add(record);
} }
@ -106,16 +103,16 @@ namespace ConfectioneryBusinessLogic
} }
/// <summary> /// <summary>
/// Сохранение изделий с указаеним продуктов в файл-Excel /// Сохранение магазинов с указаеним продуктов в файл-Excel
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
public void SavePastryComponentToExcelFile(ReportBindingModel model) public void SaveShopPastryToExcelFile(ReportBindingModel model)
{ {
_saveToExcel.CreateReport(new ExcelInfo _saveToExcel.CreateReport(new ExcelInfo
{ {
FileName = model.FileName, FileName = model.FileName,
Title = "Список изделий", Title = "Список магазинов",
PastryComponents = GetPastryComponent() ShopPastries = GetShopPastries()
}); });
} }

View File

@ -35,7 +35,7 @@
ShopsToolStripMenuItem = new ToolStripMenuItem(); ShopsToolStripMenuItem = new ToolStripMenuItem();
reportsToolStripMenuItem = new ToolStripMenuItem(); reportsToolStripMenuItem = new ToolStripMenuItem();
reportShopsToolStripMenuItem = new ToolStripMenuItem(); reportShopsToolStripMenuItem = new ToolStripMenuItem();
pastryComponentsToolStripMenuItem = new ToolStripMenuItem(); ShopPastriesToolStripMenuItem = new ToolStripMenuItem();
ordersToolStripMenuItem = new ToolStripMenuItem(); ordersToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView(); dataGridView = new DataGridView();
buttonCreateOrder = new Button(); buttonCreateOrder = new Button();
@ -88,7 +88,7 @@
// //
// reportsToolStripMenuItem // reportsToolStripMenuItem
// //
reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { reportShopsToolStripMenuItem, pastryComponentsToolStripMenuItem, ordersToolStripMenuItem }); reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { reportShopsToolStripMenuItem, ShopPastriesToolStripMenuItem, ordersToolStripMenuItem });
reportsToolStripMenuItem.Name = "reportsToolStripMenuItem"; reportsToolStripMenuItem.Name = "reportsToolStripMenuItem";
reportsToolStripMenuItem.Size = new Size(60, 20); reportsToolStripMenuItem.Size = new Size(60, 20);
reportsToolStripMenuItem.Text = "Отчеты"; reportsToolStripMenuItem.Text = "Отчеты";
@ -96,21 +96,21 @@
// reportShopsToolStripMenuItem // reportShopsToolStripMenuItem
// //
reportShopsToolStripMenuItem.Name = "reportShopsToolStripMenuItem"; reportShopsToolStripMenuItem.Name = "reportShopsToolStripMenuItem";
reportShopsToolStripMenuItem.Size = new Size(215, 22); reportShopsToolStripMenuItem.Size = new Size(202, 22);
reportShopsToolStripMenuItem.Text = "Список магазинов"; reportShopsToolStripMenuItem.Text = "Список магазинов";
reportShopsToolStripMenuItem.Click += ReportShopsToolStripMenuItem_Click; reportShopsToolStripMenuItem.Click += ReportShopsToolStripMenuItem_Click;
// //
// pastryComponentsToolStripMenuItem // ShopPastriesToolStripMenuItem
// //
pastryComponentsToolStripMenuItem.Name = "pastryComponentsToolStripMenuItem"; ShopPastriesToolStripMenuItem.Name = "ShopPastriesToolStripMenuItem";
pastryComponentsToolStripMenuItem.Size = new Size(215, 22); ShopPastriesToolStripMenuItem.Size = new Size(202, 22);
pastryComponentsToolStripMenuItem.Text = "Изделия с компонентами"; ShopPastriesToolStripMenuItem.Text = "Магазины с изделиями";
pastryComponentsToolStripMenuItem.Click += PastryComponentsToolStripMenuItem_Click; ShopPastriesToolStripMenuItem.Click += ShopPastriesToolStripMenuItem_Click;
// //
// ordersToolStripMenuItem // ordersToolStripMenuItem
// //
ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; ordersToolStripMenuItem.Name = "ordersToolStripMenuItem";
ordersToolStripMenuItem.Size = new Size(215, 22); ordersToolStripMenuItem.Size = new Size(202, 22);
ordersToolStripMenuItem.Text = "Список заказов"; ordersToolStripMenuItem.Text = "Список заказов";
ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
// //
@ -240,7 +240,7 @@
private ToolStripMenuItem componentToolStripMenuItem; private ToolStripMenuItem componentToolStripMenuItem;
private ToolStripMenuItem reportsToolStripMenuItem; private ToolStripMenuItem reportsToolStripMenuItem;
private ToolStripMenuItem reportShopsToolStripMenuItem; private ToolStripMenuItem reportShopsToolStripMenuItem;
private ToolStripMenuItem pastryComponentsToolStripMenuItem; private ToolStripMenuItem ShopPastriesToolStripMenuItem;
private ToolStripMenuItem ordersToolStripMenuItem; private ToolStripMenuItem ordersToolStripMenuItem;
private ToolStripMenuItem ShopsToolStripMenuItem; private ToolStripMenuItem ShopsToolStripMenuItem;
private Button buttonAddPastryInShop; private Button buttonAddPastryInShop;

View File

@ -166,10 +166,10 @@ namespace ConfectioneryView
} }
} }
private void PastryComponentsToolStripMenuItem_Click(object sender, EventArgs e) private void ShopPastriesToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormReportPastryComponents)); var service = Program.ServiceProvider?.GetService(typeof(FormReportShopPastries));
if (service is FormReportPastryComponents form) if (service is FormReportShopPastries form)
{ {
form.ShowDialog(); form.ShowDialog();
} }

View File

@ -1,6 +1,6 @@
namespace ConfectioneryView namespace ConfectioneryView
{ {
partial class FormReportPastryComponents partial class FormReportShopPastries
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@ -30,8 +30,8 @@
{ {
dataGridView = new DataGridView(); dataGridView = new DataGridView();
buttonSaveToExcel = new Button(); buttonSaveToExcel = new Button();
ColumnShop = new DataGridViewTextBoxColumn();
ColumnPastry = new DataGridViewTextBoxColumn(); ColumnPastry = new DataGridViewTextBoxColumn();
ColumnComponent = new DataGridViewTextBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn(); ColumnCount = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
@ -45,7 +45,7 @@
dataGridView.AllowUserToResizeRows = false; dataGridView.AllowUserToResizeRows = false;
dataGridView.BackgroundColor = SystemColors.ControlLightLight; dataGridView.BackgroundColor = SystemColors.ControlLightLight;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnPastry, ColumnComponent, ColumnCount }); dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnShop, ColumnPastry, ColumnCount });
dataGridView.Dock = DockStyle.Bottom; dataGridView.Dock = DockStyle.Bottom;
dataGridView.Location = new Point(0, 47); dataGridView.Location = new Point(0, 47);
dataGridView.Margin = new Padding(4, 3, 4, 3); dataGridView.Margin = new Padding(4, 3, 4, 3);
@ -67,6 +67,13 @@
buttonSaveToExcel.UseVisualStyleBackColor = true; buttonSaveToExcel.UseVisualStyleBackColor = true;
buttonSaveToExcel.Click += ButtonSaveToExcel_Click; buttonSaveToExcel.Click += ButtonSaveToExcel_Click;
// //
// ColumnShop
//
ColumnShop.HeaderText = "Магазин";
ColumnShop.Name = "ColumnShop";
ColumnShop.ReadOnly = true;
ColumnShop.Width = 200;
//
// ColumnPastry // ColumnPastry
// //
ColumnPastry.HeaderText = "Изделие"; ColumnPastry.HeaderText = "Изделие";
@ -74,20 +81,13 @@
ColumnPastry.ReadOnly = true; ColumnPastry.ReadOnly = true;
ColumnPastry.Width = 200; ColumnPastry.Width = 200;
// //
// ColumnComponent
//
ColumnComponent.HeaderText = "Компонент";
ColumnComponent.Name = "ColumnComponent";
ColumnComponent.ReadOnly = true;
ColumnComponent.Width = 200;
//
// ColumnCount // ColumnCount
// //
ColumnCount.HeaderText = "Количество"; ColumnCount.HeaderText = "Количество";
ColumnCount.Name = "ColumnCount"; ColumnCount.Name = "ColumnCount";
ColumnCount.ReadOnly = true; ColumnCount.ReadOnly = true;
// //
// FormReportPastryComponents // FormReportShopPastries
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
@ -95,9 +95,9 @@
Controls.Add(buttonSaveToExcel); Controls.Add(buttonSaveToExcel);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Margin = new Padding(4, 3, 4, 3); Margin = new Padding(4, 3, 4, 3);
Name = "FormReportPastryComponents"; Name = "FormReportShopPastries";
Text = "Изделия с компонентами"; Text = "Изделия с компонентами";
Load += FormReportPastryComponents_Load; Load += FormReportShopPastry_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
@ -106,8 +106,8 @@
private System.Windows.Forms.DataGridView dataGridView; private System.Windows.Forms.DataGridView dataGridView;
private System.Windows.Forms.Button buttonSaveToExcel; private System.Windows.Forms.Button buttonSaveToExcel;
private DataGridViewTextBoxColumn ColumnShop;
private DataGridViewTextBoxColumn ColumnPastry; private DataGridViewTextBoxColumn ColumnPastry;
private DataGridViewTextBoxColumn ColumnComponent;
private DataGridViewTextBoxColumn ColumnCount; private DataGridViewTextBoxColumn ColumnCount;
} }
} }

View File

@ -13,35 +13,36 @@ using System.Windows.Forms;
namespace ConfectioneryView namespace ConfectioneryView
{ {
public partial class FormReportPastryComponents : Form public partial class FormReportShopPastries : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IReportLogic _logic; private readonly IReportLogic _logic;
public FormReportPastryComponents(ILogger<FormReportPastryComponents> logger, IReportLogic logic) public FormReportShopPastries(ILogger<FormReportShopPastries> logger, IReportLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
} }
private void FormReportPastryComponents_Load(object sender, EventArgs e) private void FormReportShopPastry_Load(object sender, EventArgs e)
{ {
try try
{ {
var dict = _logic.GetPastryComponent(); var dict = _logic.GetShopPastries();
if (dict != null) if (dict != null)
{ {
dataGridView.Rows.Clear(); dataGridView.Rows.Clear();
foreach (var elem in dict) foreach (var elem in dict)
{ {
dataGridView.Rows.Add(new object[] { elem.PastryName, "", "" }); dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" });
foreach (var listElem in elem.Components) foreach (var listElem in elem.Pastries)
{ {
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
} }
dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount });
dataGridView.Rows.Add(new object[] { "Загруженность", "", Math.Round(elem.Workload * 100, 2).ToString() + "%" });
dataGridView.Rows.Add(Array.Empty<object>()); dataGridView.Rows.Add(Array.Empty<object>());
} }
} }
@ -61,7 +62,7 @@ namespace ConfectioneryView
{ {
try try
{ {
_logic.SavePastryComponentToExcelFile(new ReportBindingModel _logic.SaveShopPastryToExcelFile(new ReportBindingModel
{ {
FileName = dialog.FileName FileName = dialog.FileName
}); });

View File

@ -28,7 +28,7 @@ namespace ConfectioneryView
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Shops"].Visible = false; dataGridView.Columns["Pastries"].Visible = false;
dataGridView.Columns["Name"].AutoSizeMode = dataGridView.Columns["Name"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill; DataGridViewAutoSizeColumnMode.Fill;
} }

View File

@ -62,7 +62,7 @@ namespace ConfectioneryView
services.AddTransient<FormViewShops>(); services.AddTransient<FormViewShops>();
services.AddTransient<FormShop>(); services.AddTransient<FormShop>();
services.AddTransient<FormSellPastry>(); services.AddTransient<FormSellPastry>();
services.AddTransient<FormReportPastryComponents>(); services.AddTransient<FormReportShopPastries>();
services.AddTransient<FormReportOrders>(); services.AddTransient<FormReportOrders>();
} }
} }

View File

@ -11,10 +11,10 @@ namespace ConfectioneryContracts.BusinessLogicsContracts
public interface IReportLogic public interface IReportLogic
{ {
/// <summary> /// <summary>
/// Получение списка компонент с указанием, в каких изделиях используются /// Получение списка магазинов с указанием, в каких изделиях используются
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
List<ReportPastryComponentViewModel> GetPastryComponent(); List<ReportShopPastrytViewModel> GetShopPastries();
/// <summary> /// <summary>
/// Получение списка заказов за определенный период /// Получение списка заказов за определенный период
/// </summary> /// </summary>
@ -30,7 +30,7 @@ namespace ConfectioneryContracts.BusinessLogicsContracts
/// Сохранение компонент с указаеним продуктов в файл-Excel /// Сохранение компонент с указаеним продуктов в файл-Excel
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
void SavePastryComponentToExcelFile(ReportBindingModel model); void SaveShopPastryToExcelFile(ReportBindingModel model);
/// <summary> /// <summary>
/// Сохранение заказов в файл-Pdf /// Сохранение заказов в файл-Pdf
/// </summary> /// </summary>

View File

@ -6,10 +6,11 @@ using System.Threading.Tasks;
namespace ConfectioneryContracts.ViewModels namespace ConfectioneryContracts.ViewModels
{ {
public class ReportPastryComponentViewModel public class ReportShopPastrytViewModel
{ {
public string PastryName { get; set; } = string.Empty; public string ShopName { get; set; } = string.Empty;
public int TotalCount { get; set; } public int TotalCount { get; set; }
public List<Tuple<string, int>> Components { get; set; } = new(); public List<Tuple<string, int>> Pastries { get; set; } = new();
public double Workload { get; set; }
} }
} }