diff --git a/TransportCompany/TransportCompany/FormMain.Designer.cs b/TransportCompany/TransportCompany/FormMain.Designer.cs index 6f4ae84..6708384 100644 --- a/TransportCompany/TransportCompany/FormMain.Designer.cs +++ b/TransportCompany/TransportCompany/FormMain.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/TransportCompany/TransportCompany/FormMain.cs b/TransportCompany/TransportCompany/FormMain.cs index d39e2c2..c97a7ee 100644 --- a/TransportCompany/TransportCompany/FormMain.cs +++ b/TransportCompany/TransportCompany/FormMain.cs @@ -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 logger, ITransportationLogic transportationLogic) + public FormMain(ILogger 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); + } + } + } + } \ No newline at end of file diff --git a/TransportCompany/TransportCompany/Program.cs b/TransportCompany/TransportCompany/Program.cs index 8a6b373..104479f 100644 --- a/TransportCompany/TransportCompany/Program.cs +++ b/TransportCompany/TransportCompany/Program.cs @@ -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(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -58,6 +61,8 @@ namespace TransportCompanyView services.AddTransient(); services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/AbstractSaveToWord.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/AbstractSaveToWord.cs new file mode 100644 index 0000000..fe43d37 --- /dev/null +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/AbstractSaveToWord.cs @@ -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); + } +} diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperEnums/WordJustificationType.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..d22aad3 --- /dev/null +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,8 @@ +namespace TransportCompanyBusinessLogic.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + Both + } +} diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperModels/WordInfo.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..ccbdf77 --- /dev/null +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperModels/WordInfo.cs @@ -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 Transportations { get; set; } = new(); + } +} diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperModels/WordParagraph.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..f657b32 --- /dev/null +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperModels/WordParagraph.cs @@ -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; } + } +} diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperModels/WordTextProperties.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..db7b356 --- /dev/null +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/HelperModels/WordTextProperties.cs @@ -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; } + } +} diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/Implements/SaveToWord.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/Implements/SaveToWord.cs new file mode 100644 index 0000000..0871bd3 --- /dev/null +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/OfficePackage/Implements/SaveToWord.cs @@ -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(); + } + } +} diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/ReportLogic.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..1b82cf9 --- /dev/null +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/ReportLogic.cs @@ -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 +{ + /// + /// Реализация интерфейса бизнес-логики для создания отчетов + /// + public class ReportLogic : IReportLogic + { + /// + /// Хранилище компонентов + /// + + /// Хранилище заказов + /// + private readonly ITransportationStorage _transportationStorage; + + /// + /// Взаимодействие с отчетами в Excel-формате + /// + + /// Взаимодействие с отчетами в Word-формате + /// + private readonly AbstractSaveToWord _saveToWord; + + /// + /// Взаимодействие с отчетами в Pdf-формате + /// + + + /// + /// Конструктор + /// + /// + /// + /// + /// + /// + /// + public ReportLogic(ITransportationStorage transportationStorage + , AbstractSaveToWord saveToWord) + { + + _transportationStorage = transportationStorage; + + + _saveToWord = saveToWord; + + } + + /// + /// Получение списка изделий с расшифровкой по компонентам + /// + /// + + + /// + /// Получение списка заказов за определенный период + /// + /// + /// + public List 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(); + } + + /// + /// Сохранение изделий в Word-файл + /// + /// + public void SaveTransportationsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDoc(new WordInfo + { + FileName = model.FileName, + Title = "Информация по транспортировкам", + Transportations = _transportationStorage.GetFullList() + }); + } + + /// + /// Сохранение изделий с расшифровкой по компонентам в Excel-файл + /// + /// + + + /// + /// Сохранение заказов в Pdf-файл + /// + /// + + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyContracts/BindingModels/ReportBindingModel.cs b/TransportCompany/TransportCompanyContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..1310a1b --- /dev/null +++ b/TransportCompany/TransportCompanyContracts/BindingModels/ReportBindingModel.cs @@ -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; } + } +} diff --git a/TransportCompany/TransportCompanyContracts/BusinessLogicsContracts/IReportLogic.cs b/TransportCompany/TransportCompanyContracts/BusinessLogicsContracts/IReportLogic.cs new file mode 100644 index 0000000..4f2c7cf --- /dev/null +++ b/TransportCompany/TransportCompanyContracts/BusinessLogicsContracts/IReportLogic.cs @@ -0,0 +1,11 @@ +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.ViewModels; + +namespace TransportCompanyContracts.BusinessLogicsContracts +{ + public interface IReportLogic + { + List GetTransportations(ReportBindingModel model); + void SaveTransportationsToWordFile(ReportBindingModel model); + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompanyContracts/ViewModels/ReportTransportationViewModel.cs b/TransportCompany/TransportCompanyContracts/ViewModels/ReportTransportationViewModel.cs new file mode 100644 index 0000000..2949808 --- /dev/null +++ b/TransportCompany/TransportCompanyContracts/ViewModels/ReportTransportationViewModel.cs @@ -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; } + } +}