Отчёт по магазинам в word

This commit is contained in:
ujijrujijr 2024-06-14 16:14:36 +04:00
parent 1f48e676f2
commit 2e66e6e59f
11 changed files with 395 additions and 140 deletions

View File

@ -1,26 +1,26 @@
namespace GarmentFactoryView
{
partial class FormMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
partial class FormMain
{
/// <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);
}
/// <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
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
@ -46,6 +46,7 @@
textilesToolStripMenuItem = new ToolStripMenuItem();
textileComponentsToolStripMenuItem = new ToolStripMenuItem();
ordersToolStripMenuItem = new ToolStripMenuItem();
магазиныВDocToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip1.SuspendLayout();
SuspendLayout();
@ -182,7 +183,7 @@
//
// отчётыToolStripMenuItem
//
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { textilesToolStripMenuItem, textileComponentsToolStripMenuItem, ordersToolStripMenuItem });
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { textilesToolStripMenuItem, textileComponentsToolStripMenuItem, ordersToolStripMenuItem, магазиныВDocToolStripMenuItem });
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
отчётыToolStripMenuItem.Size = new Size(73, 24);
отчётыToolStripMenuItem.Text = "Отчёты";
@ -208,6 +209,13 @@
ordersToolStripMenuItem.Text = "Заказы";
ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
//
// магазиныВDocToolStripMenuItem
//
магазиныВDocToolStripMenuItem.Name = агазиныВDocToolStripMenuItem";
магазиныВDocToolStripMenuItem.Size = new Size(274, 26);
магазиныВDocToolStripMenuItem.Text = "Магазины в doc";
магазиныВDocToolStripMenuItem.Click += магазиныВDocToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -231,7 +239,7 @@
PerformLayout();
}
#endregion
#endregion
private DataGridView dataGridView;
private Button buttonCreateOrder;
@ -251,5 +259,6 @@
private ToolStripMenuItem textilesToolStripMenuItem;
private ToolStripMenuItem textileComponentsToolStripMenuItem;
private ToolStripMenuItem ordersToolStripMenuItem;
private ToolStripMenuItem магазиныВDocToolStripMenuItem;
}
}

View File

@ -52,15 +52,15 @@ namespace GarmentFactoryView
LoadData();
}
private void компонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
private void компонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
}
private void текстилиToolStripMenuItem_Click(object sender, EventArgs e)
{
@ -102,114 +102,124 @@ namespace GarmentFactoryView
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonCompletedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonRefresh_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonCompletedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonRefresh_Click(object sender, EventArgs e)
{
LoadData();
}
private void пополнениеМагазинаToolStripMenuItem1_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddTextile));
private void пополнениеМагазинаToolStripMenuItem1_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddTextile));
if (service is FormAddTextile form)
{
form.ShowDialog();
}
}
if (service is FormAddTextile form)
{
form.ShowDialog();
}
}
private void продажаТовараToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellTextile));
if (service is FormSellTextile form)
{
form.ShowDialog();
}
}
}
private void продажаТовараToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellTextile));
if (service is FormSellTextile form)
{
form.ShowDialog();
}
}
private void магазиныВDocToolStripMenuItem_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);
}
}
}
}

View File

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GarmentFactoryContracts.ViewModels;
namespace GarmentFactoryBusinessLogic.BusinessLogics
{
@ -18,16 +19,18 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics
private readonly IComponentStorage _componentStorage;
private readonly ITextileStorage _textileStorage;
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(ITextileStorage textileStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
public ReportLogic(ITextileStorage textileStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_textileStorage = textileStorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage;
_shopStorage = shopStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
@ -106,5 +109,55 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics
Orders = GetOrders(model)
});
}
public List<ReportShopsViewModel> GetShops()
{
return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel
{
ShopName = x.ShopName,
Textiles = x.ShopTextiles.Select(x => (x.Value.Item1.TextileName, x.Value.Item2)).ToList(),
TotalCount = x.ShopTextiles.Select(x => x.Value.Item2).Sum()
}).ToList();
}
//public List<ReportGroupOrdersViewModel> GetGroupedOrders()
//{
// return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupOrdersViewModel
// {
// Date = x.Key,
// OrdersCount = x.Count(),
// OrdersSum = x.Select(y => y.Sum).Sum()
// }).ToList();
//}
public void SaveShopsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateShopsDoc(new WordShopInfo
{
FileName = model.FileName,
Title = "Список магазинов",
Shops = _shopStorage.GetFullList()
});
}
//public void SaveShopsToExcelFile(ReportBindingModel model)
//{
// _saveToExcel.CreateShopTextilesReport(new ExcelShop
// {
// FileName = model.FileName,
// Title = "Наполненость магазинов",
// ShopTextiles = GetShops()
// });
//}
//public void SaveGroupedOrdersToPdfFile(ReportBindingModel model)
//{
// _saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo
// {
// FileName = model.FileName,
// Title = "Список заказов сгруппированных по дате заказов",
// GroupedOrders = GetGroupedOrders()
// });
//}
}
}

View File

@ -1,5 +1,7 @@
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
using GarmentFactoryBusinessLogic.OfficePackage;
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
@ -43,11 +45,52 @@ namespace GarmentFactoryBusinessLogic.OfficePackage
SaveWord(info);
}
public void CreateShopsDoc(WordShopInfo info)
{
CreateWord(info);
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
CreateTable(new List<string> { "3000", "3000", "3000" });
CreateRow(new WordRowParameters
{
Texts = new List<string> { "Название", "Адрес", "Дата открытия" },
TextProperties = new WordTextProperties
{
Size = "24",
Bold = true,
JustificationType = WordJustificationType.Center
}
});
foreach (var shop in info.Shops)
{
CreateRow(new WordRowParameters
{
Texts = new List<string> { shop.ShopName, shop.Address, shop.DateOpen.ToString() },
TextProperties = new WordTextProperties
{
Size = "22",
JustificationType = WordJustificationType.Center
}
});
}
SaveWord(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateWord(WordInfo info);
protected abstract void CreateWord(IDocumentInfo info);
/// <summary>
/// Создание абзаца с текстом
@ -60,6 +103,9 @@ namespace GarmentFactoryBusinessLogic.OfficePackage
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveWord(WordInfo info);
protected abstract void SaveWord(IDocumentInfo info);
protected abstract void CreateTable(List<string> colums);
protected abstract void CreateRow(WordRowParameters rowParameters);
}
}

View File

@ -1,4 +1,5 @@
using GarmentFactoryContracts.ViewModels;
using GarmentFactoryBusinessLogic.OfficePackage;
using System;
using System.Collections.Generic;
using System.Linq;
@ -7,7 +8,7 @@ using System.Threading.Tasks;
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
{
public class WordInfo
public class WordInfo : IDocumentInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;

View File

@ -0,0 +1,15 @@
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
{
public class WordRowParameters
{
public List<string> Texts { get; set; } = new();
public WordTextProperties TextProperties { get; set; } = new();
}
}

View File

@ -0,0 +1,16 @@
using GarmentFactoryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GarmentFactoryBusinessLogic.OfficePackage.HelperModels
{
public class WordShopInfo : IDocumentInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ShopViewModel> Shops { get; set; } = new();
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GarmentFactoryBusinessLogic.OfficePackage
{
public interface IDocumentInfo
{
public string FileName { get; set; }
public string Title { get; set; }
}
}

View File

@ -85,7 +85,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements
return properties;
}
protected override void CreateWord(WordInfo info)
protected override void CreateWord(IDocumentInfo info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
@ -123,7 +123,7 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements
_docBody.AppendChild(docParagraph);
}
protected override void SaveWord(WordInfo info)
protected override void SaveWord(IDocumentInfo info)
{
if (_docBody == null || _wordDocument == null)
{
@ -135,5 +135,77 @@ namespace GarmentFactoryBusinessLogic.OfficePackage.Implements
_wordDocument.Close();
}
private Table? _lastTable;
protected override void CreateTable(List<string> columns)
{
if (_docBody == null)
return;
_lastTable = new Table();
var tableProp = new TableProperties();
tableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed });
tableProp.AppendChild(new TableBorders(
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 }
));
tableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto });
_lastTable.AppendChild(tableProp);
TableGrid tableGrid = new TableGrid();
foreach (var column in columns)
{
tableGrid.AppendChild(new GridColumn() { Width = column });
}
_lastTable.AppendChild(tableGrid);
_docBody.AppendChild(_lastTable);
}
protected override void CreateRow(WordRowParameters rowParameters)
{
if (_docBody == null || _lastTable == null)
return;
TableRow docRow = new TableRow();
foreach (var column in rowParameters.Texts)
{
var docParagraph = new Paragraph();
WordParagraph paragraph = new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (column, rowParameters.TextProperties) },
TextProperties = rowParameters.TextProperties
};
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
foreach (var run in paragraph.Texts)
{
var docRun = new Run();
var properties = new RunProperties();
properties.AppendChild(new FontSize { Val = run.Item2.Size });
if (run.Item2.Bold)
{
properties.AppendChild(new Bold());
}
docRun.AppendChild(properties);
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
docParagraph.AppendChild(docRun);
}
TableCell docCell = new TableCell();
docCell.AppendChild(docParagraph);
docRow.AppendChild(docCell);
}
_lastTable.AppendChild(docRow);
}
}
}

View File

@ -20,5 +20,9 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts
void SaveOrdersToPdfFile(ReportBindingModel model);
void SaveShopsToWordFile(ReportBindingModel model);
//void SaveShopsToExcelFile(ReportBindingModel model);
//void SaveGroupedOrdersToPdfFile(ReportBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GarmentFactoryContracts.ViewModels
{
public class ReportShopsViewModel
{
public string ShopName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<(string textile, int count)> Textiles { get; set; } = new();
}
}