отчет есть

This commit is contained in:
Allllen4a 2024-04-16 19:46:28 +04:00
parent 095e4a25e6
commit c8bfa62c84
13 changed files with 446 additions and 15 deletions

View File

@ -40,6 +40,8 @@
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
отчетToolStripMenuItem = new ToolStripMenuItem();
транспортировкиToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -47,11 +49,11 @@
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { bookToolStripMenuItem });
menuStrip1.Items.AddRange(new ToolStripItem[] { bookToolStripMenuItem, отчетToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(8, 4, 0, 4);
menuStrip1.Size = new Size(1924, 37);
menuStrip1.Size = new Size(1828, 37);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1";
//
@ -65,28 +67,28 @@
// ingridientsToolStripMenuItem
//
ingridientsToolStripMenuItem.Name = "ingridientsToolStripMenuItem";
ingridientsToolStripMenuItem.Size = new Size(190, 34);
ingridientsToolStripMenuItem.Size = new Size(270, 34);
ingridientsToolStripMenuItem.Text = "Грузы";
ingridientsToolStripMenuItem.Click += CargosToolStripMenuItem_Click;
//
// pizzasToolStripMenuItem
//
pizzasToolStripMenuItem.Name = "pizzasToolStripMenuItem";
pizzasToolStripMenuItem.Size = new Size(190, 34);
pizzasToolStripMenuItem.Size = new Size(270, 34);
pizzasToolStripMenuItem.Text = "Водители";
pizzasToolStripMenuItem.Click += DriversToolStripMenuItem_Click;
//
// машиныToolStripMenuItem
//
машиныToolStripMenuItem.Name = ашиныToolStripMenuItem";
машиныToolStripMenuItem.Size = new Size(190, 34);
машиныToolStripMenuItem.Size = new Size(270, 34);
машиныToolStripMenuItem.Text = "Машины";
машиныToolStripMenuItem.Click += TransportsToolStripMenuItem_Click;
//
// пунктыToolStripMenuItem
//
пунктыToolStripMenuItem.Name = "пунктыToolStripMenuItem";
пунктыToolStripMenuItem.Size = new Size(190, 34);
пунктыToolStripMenuItem.Size = new Size(270, 34);
пунктыToolStripMenuItem.Text = "Пункты";
пунктыToolStripMenuItem.Click += PointsToolStripMenuItem_Click;
//
@ -106,7 +108,7 @@
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(1505, 92);
buttonCreateOrder.Location = new Point(1449, 92);
buttonCreateOrder.Margin = new Padding(4);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(309, 36);
@ -117,7 +119,7 @@
//
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(1505, 152);
buttonTakeOrderInWork.Location = new Point(1449, 148);
buttonTakeOrderInWork.Margin = new Padding(4);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(309, 36);
@ -128,7 +130,7 @@
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(1505, 209);
buttonOrderReady.Location = new Point(1449, 202);
buttonOrderReady.Margin = new Padding(4);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(309, 36);
@ -139,7 +141,7 @@
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(1505, 265);
buttonIssuedOrder.Location = new Point(1449, 255);
buttonIssuedOrder.Margin = new Padding(4);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(309, 36);
@ -150,7 +152,7 @@
//
// buttonRef
//
buttonRef.Location = new Point(1505, 325);
buttonRef.Location = new Point(1449, 308);
buttonRef.Margin = new Padding(4);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(309, 36);
@ -159,11 +161,25 @@
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// отчетToolStripMenuItem
//
отчетToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { транспортировкиToolStripMenuItem });
отчетToolStripMenuItem.Name = "отчетToolStripMenuItem";
отчетToolStripMenuItem.Size = new Size(75, 29);
отчетToolStripMenuItem.Text = "Отчет";
//
// транспортировкиToolStripMenuItem
//
транспортировкиToolStripMenuItem.Name = ранспортировкиToolStripMenuItem";
транспортировкиToolStripMenuItem.Size = new Size(270, 34);
транспортировкиToolStripMenuItem.Text = "Транспортировки";
транспортировкиToolStripMenuItem.Click += транспортировкиToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1924, 839);
ClientSize = new Size(1828, 694);
Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
@ -197,5 +213,7 @@
private Button buttonRef;
private ToolStripMenuItem машиныToolStripMenuItem;
private ToolStripMenuItem пунктыToolStripMenuItem;
private ToolStripMenuItem отчетToolStripMenuItem;
private ToolStripMenuItem транспортировкиToolStripMenuItem;
}
}

View File

@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging;
using System.Windows.Forms;
using TransportCompanyBusinessLogic.BusinessLogics;
using TransportCompanyContracts.BindingModels;
using TransportCompanyContracts.BusinessLogicsContracts;
@ -7,12 +9,14 @@ namespace TransportCompanyView
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IReportLogic _reportLogic;
private readonly ITransportationLogic _transportationLogic;
public FormMain(ILogger<FormMain> logger, ITransportationLogic transportationLogic)
public FormMain(ILogger<FormMain> logger, IReportLogic reportLogic, ITransportationLogic transportationLogic)
{
InitializeComponent();
_logger = logger;
_reportLogic = reportLogic;
_transportationLogic = transportationLogic;
}
@ -179,5 +183,15 @@ namespace TransportCompanyView
{
LoadData();
}
}
}
private void транспортировкиToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveTransportationsToWordFile(new ReportBindingModel { FileName = dialog.FileName });
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}

View File

@ -6,6 +6,8 @@ using TransportCompanyBusinessLogic.BusinessLogics;
using TransportCompanyContracts.BusinessLogicsContracts;
using TransportCompanyContracts.StoragesContracts;
using TransportCompanyDatabaseImplement.Implements;
using TransportCompanyBusinessLogic.OfficePackage.Implements;
using TransportCompanyBusinessLogic.OfficePackage;
using TransportCompanyView;
namespace TransportCompanyView
@ -45,6 +47,7 @@ namespace TransportCompanyView
services.AddTransient<ICargoLogic, CargoLogic>();
services.AddTransient<IDriverLogic, DriverLogic>();
services.AddTransient<IPointLogic, PointLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<ITransportationLogic, TransportationLogic>();
services.AddTransient<ITransportLogic, TransportLogic>();
services.AddTransient<FormCargo>();
@ -58,6 +61,8 @@ namespace TransportCompanyView
services.AddTransient<FormCreateTransportation>();
services.AddTransient<FormMain>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
}
}
}

View File

@ -0,0 +1,49 @@
using TransportCompanyBusinessLogic.OfficePackage.HelperEnums;
using TransportCompanyBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TransportCompanyBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWord
{
public void CreateDoc(WordInfo 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
}
});
foreach (var transportation in info.Transportations)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(transportation.DriverFio, new WordTextProperties { Size = "12", Bold = true}),
("\t"+transportation.Model.ToString(), new WordTextProperties{Size = "12"}), ("\t"+transportation.PointNameFrom.ToString(), new WordTextProperties{Size = "12"}), ("\t"+transportation.PointNameTo.ToString(), new WordTextProperties{Size = "12"}), ("\t"+transportation.DepartureDate.ToString(), new WordTextProperties{Size = "12"}), ("\t"+transportation.ArrivalDate.ToString(), new WordTextProperties{Size = "12"}),
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(info);
}
protected abstract void CreateWord(WordInfo info);
protected abstract void CreateParagraph(WordParagraph paragraph);
protected abstract void SaveWord(WordInfo info);
}
}

View File

@ -0,0 +1,8 @@
namespace TransportCompanyBusinessLogic.OfficePackage.HelperEnums
{
public enum WordJustificationType
{
Center,
Both
}
}

View File

@ -0,0 +1,11 @@
using TransportCompanyContracts.ViewModels;
namespace TransportCompanyBusinessLogic.OfficePackage.HelperModels
{
public class WordInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<TransportationViewModel> Transportations { get; set; } = new();
}
}

View File

@ -0,0 +1,10 @@
using TransportCompanyBusinessLogic.OfficePackage.HelperModels;
namespace TransportCompanyBusinessLogic.OfficePackage.HelperModels
{
public class WordParagraph
{
public List<(string, WordTextProperties)> Texts { get; set; } = new();
public WordTextProperties? TextProperties { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using TransportCompanyBusinessLogic.OfficePackage.HelperEnums;
namespace TransportCompanyBusinessLogic.OfficePackage.HelperModels
{
public class WordTextProperties
{
public string Size { get; set; } = string.Empty;
public bool Bold { get; set; }
public WordJustificationType JustificationType { get; set; }
}
}

View File

@ -0,0 +1,116 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using TransportCompanyBusinessLogic.OfficePackage;
using TransportCompanyBusinessLogic.OfficePackage.HelperEnums;
using TransportCompanyBusinessLogic.OfficePackage.HelperModels;
namespace TransportCompanyBusinessLogic.OfficePackage.Implements
{
public class SaveToWord : AbstractSaveToWord
{
private WordprocessingDocument? _wordDocument;
private Body? _docBody;
private static JustificationValues GetJustificationValues(WordJustificationType type)
{
return type switch
{
WordJustificationType.Both => JustificationValues.Both,
WordJustificationType.Center => JustificationValues.Center,
_ => JustificationValues.Left,
};
}
private static SectionProperties CreateSectionProperties()
{
var properties = new SectionProperties();
var pageSize = new PageSize
{
Orient = PageOrientationValues.Portrait
};
properties.AppendChild(pageSize);
return properties;
}
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
{
if (paragraphProperties == null)
{
return null;
}
var properties = new ParagraphProperties();
properties.AppendChild(new Justification()
{
Val = GetJustificationValues(paragraphProperties.JustificationType)
});
properties.AppendChild(new SpacingBetweenLines
{
LineRule = LineSpacingRuleValues.Auto
});
properties.AppendChild(new Indentation());
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
if (!string.IsNullOrEmpty(paragraphProperties.Size))
{
paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size });
}
properties.AppendChild(paragraphMarkRunProperties);
return properties;
}
protected override void CreateWord(WordInfo info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());
}
protected override void CreateParagraph(WordParagraph paragraph)
{
if (_docBody == null || paragraph == null)
{
return;
}
var docParagraph = new Paragraph();
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);
}
_docBody.AppendChild(docParagraph);
}
protected override void SaveWord(WordInfo info)
{
if (_docBody == null || _wordDocument == null)
{
return;
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Dispose();
}
}
}

View File

@ -0,0 +1,114 @@
using TransportCompanyBusinessLogic.OfficePackage.HelperModels;
using TransportCompanyBusinessLogic.OfficePackage;
using TransportCompanyContracts.BindingModels;
using TransportCompanyContracts.BusinessLogicsContracts;
using TransportCompanyContracts.SearchModels;
using TransportCompanyContracts.StoragesContracts;
using TransportCompanyContracts.ViewModels;
namespace TransportCompanyBusinessLogic.BusinessLogics
{
/// <summary>
/// Реализация интерфейса бизнес-логики для создания отчетов
/// </summary>
public class ReportLogic : IReportLogic
{
/// <summary>
/// Хранилище компонентов
/// </summary>
/// Хранилище заказов
/// </summary>
private readonly ITransportationStorage _transportationStorage;
/// <summary>
/// Взаимодействие с отчетами в Excel-формате
/// </summary>
/// Взаимодействие с отчетами в Word-формате
/// </summary>
private readonly AbstractSaveToWord _saveToWord;
/// <summary>
/// Взаимодействие с отчетами в Pdf-формате
/// </summary>
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pizzaStorage"></param>
/// <param name="componentStorage"></param>
/// <param name="orderStorage"></param>
/// <param name="saveToExcel"></param>
/// <param name="saveToWord"></param>
/// <param name="saveToPdf"></param>
public ReportLogic(ITransportationStorage transportationStorage
, AbstractSaveToWord saveToWord)
{
_transportationStorage = transportationStorage;
_saveToWord = saveToWord;
}
/// <summary>
/// Получение списка изделий с расшифровкой по компонентам
/// </summary>
/// <returns></returns>
/// <summary>
/// Получение списка заказов за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ReportTransportationViewModel> GetTransportations(ReportBindingModel model)
{
return _transportationStorage.GetFilteredList(new TransportationSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo })
.Select(x => new ReportTransportationViewModel
{
Id = x.Id,
CargoName = x.CargoName,
Count = x.Count,
DriverFio = x.DriverFio,
Model = x.Model,
DepartureDate = x.DepartureDate,
ArrivalDate = x.ArrivalDate,
PointNameFrom = x.PointNameFrom,
PointNameTo = x.PointNameTo,
Status = x.Status,
})
.ToList();
}
/// <summary>
/// Сохранение изделий в Word-файл
/// </summary>
/// <param name="model"></param>
public void SaveTransportationsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Информация по транспортировкам",
Transportations = _transportationStorage.GetFullList()
});
}
/// <summary>
/// Сохранение изделий с расшифровкой по компонентам в Excel-файл
/// </summary>
/// <param name="model"></param>
/// <summary>
/// Сохранение заказов в Pdf-файл
/// </summary>
/// <param name="model"></param>
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TransportCompanyContracts.BindingModels
{
public class ReportBindingModel
{
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using TransportCompanyContracts.BindingModels;
using TransportCompanyContracts.ViewModels;
namespace TransportCompanyContracts.BusinessLogicsContracts
{
public interface IReportLogic
{
List<ReportTransportationViewModel> GetTransportations(ReportBindingModel model);
void SaveTransportationsToWordFile(ReportBindingModel model);
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TransportCompanyDataModels.Enums;
namespace TransportCompanyContracts.ViewModels
{
public class ReportTransportationViewModel
{
public int Id { get; set; }
public DateTime DateCreate { get; set; }
[DisplayName("Водитель")]
public string DriverFio { get; set; } = string.Empty;
[DisplayName("Машина")]
public string Model { get; set; } = string.Empty;
public int CargoId { get; set; }
[DisplayName("Груз")]
public string CargoName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
public int PointFromId { get; set; }
[DisplayName("Откуда")]
public string PointNameFrom { get; set; } = string.Empty;
public int PointToId { get; set; }
[DisplayName("Куда")]
public string PointNameTo { get; set; } = string.Empty;
[DisplayName("Статус")]
public TransportationStatus Status { get; set; } = TransportationStatus.Неизвестен;
[DisplayName("Дата отбытия")]
public DateTime DepartureDate { get; set; } = DateTime.Now;
[DisplayName("Дата прибытия")]
public DateTime? ArrivalDate { get; set; }
}
}