Реализовано сохранения магазинов в 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;
foreach (var pc in info.PastryComponents)
foreach (var pc in info.ShopPastries)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.PastryName,
Text = pc.ShopName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var (Pastry, Count) in pc.Components)
foreach (var (Shop, Count) in pc.Pastries)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = Pastry,
Text = Shop,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
@ -80,6 +80,21 @@ namespace ConfectioneryBusinessLogic.OfficePackage
StyleInfo = ExcelStyleInfoType.Text
});
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);

View File

@ -6,7 +6,7 @@ namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportPastryComponentViewModel> PastryComponents
public List<ReportShopPastrytViewModel> ShopPastries
{
get;
set;

View File

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

View File

@ -35,7 +35,7 @@
ShopsToolStripMenuItem = new ToolStripMenuItem();
reportsToolStripMenuItem = new ToolStripMenuItem();
reportShopsToolStripMenuItem = new ToolStripMenuItem();
pastryComponentsToolStripMenuItem = new ToolStripMenuItem();
ShopPastriesToolStripMenuItem = new ToolStripMenuItem();
ordersToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
@ -88,7 +88,7 @@
//
// reportsToolStripMenuItem
//
reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { reportShopsToolStripMenuItem, pastryComponentsToolStripMenuItem, ordersToolStripMenuItem });
reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { reportShopsToolStripMenuItem, ShopPastriesToolStripMenuItem, ordersToolStripMenuItem });
reportsToolStripMenuItem.Name = "reportsToolStripMenuItem";
reportsToolStripMenuItem.Size = new Size(60, 20);
reportsToolStripMenuItem.Text = "Отчеты";
@ -96,21 +96,21 @@
// reportShopsToolStripMenuItem
//
reportShopsToolStripMenuItem.Name = "reportShopsToolStripMenuItem";
reportShopsToolStripMenuItem.Size = new Size(215, 22);
reportShopsToolStripMenuItem.Size = new Size(202, 22);
reportShopsToolStripMenuItem.Text = "Список магазинов";
reportShopsToolStripMenuItem.Click += ReportShopsToolStripMenuItem_Click;
//
// pastryComponentsToolStripMenuItem
// ShopPastriesToolStripMenuItem
//
pastryComponentsToolStripMenuItem.Name = "pastryComponentsToolStripMenuItem";
pastryComponentsToolStripMenuItem.Size = new Size(215, 22);
pastryComponentsToolStripMenuItem.Text = "Изделия с компонентами";
pastryComponentsToolStripMenuItem.Click += PastryComponentsToolStripMenuItem_Click;
ShopPastriesToolStripMenuItem.Name = "ShopPastriesToolStripMenuItem";
ShopPastriesToolStripMenuItem.Size = new Size(202, 22);
ShopPastriesToolStripMenuItem.Text = "Магазины с изделиями";
ShopPastriesToolStripMenuItem.Click += ShopPastriesToolStripMenuItem_Click;
//
// ordersToolStripMenuItem
//
ordersToolStripMenuItem.Name = "ordersToolStripMenuItem";
ordersToolStripMenuItem.Size = new Size(215, 22);
ordersToolStripMenuItem.Size = new Size(202, 22);
ordersToolStripMenuItem.Text = "Список заказов";
ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
//
@ -240,7 +240,7 @@
private ToolStripMenuItem componentToolStripMenuItem;
private ToolStripMenuItem reportsToolStripMenuItem;
private ToolStripMenuItem reportShopsToolStripMenuItem;
private ToolStripMenuItem pastryComponentsToolStripMenuItem;
private ToolStripMenuItem ShopPastriesToolStripMenuItem;
private ToolStripMenuItem ordersToolStripMenuItem;
private ToolStripMenuItem ShopsToolStripMenuItem;
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));
if (service is FormReportPastryComponents form)
var service = Program.ServiceProvider?.GetService(typeof(FormReportShopPastries));
if (service is FormReportShopPastries form)
{
form.ShowDialog();
}

View File

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

View File

@ -13,35 +13,36 @@ using System.Windows.Forms;
namespace ConfectioneryView
{
public partial class FormReportPastryComponents : Form
public partial class FormReportShopPastries : Form
{
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportPastryComponents(ILogger<FormReportPastryComponents> logger, IReportLogic logic)
public FormReportShopPastries(ILogger<FormReportShopPastries> logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormReportPastryComponents_Load(object sender, EventArgs e)
private void FormReportShopPastry_Load(object sender, EventArgs e)
{
try
{
var dict = _logic.GetPastryComponent();
var dict = _logic.GetShopPastries();
if (dict != null)
{
dataGridView.Rows.Clear();
foreach (var elem in dict)
{
dataGridView.Rows.Add(new object[] { elem.PastryName, "", "" });
foreach (var listElem in elem.Components)
dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" });
foreach (var listElem in elem.Pastries)
{
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
}
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>());
}
}
@ -61,7 +62,7 @@ namespace ConfectioneryView
{
try
{
_logic.SavePastryComponentToExcelFile(new ReportBindingModel
_logic.SaveShopPastryToExcelFile(new ReportBindingModel
{
FileName = dialog.FileName
});

View File

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

View File

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

View File

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

View File

@ -6,10 +6,11 @@ using System.Threading.Tasks;
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 List<Tuple<string, int>> Components { get; set; } = new();
public List<Tuple<string, int>> Pastries { get; set; } = new();
public double Workload { get; set; }
}
}