From f4af6dafbccd068667c19716838f4e44494b22a7 Mon Sep 17 00:00:00 2001 From: Ctepa Date: Mon, 16 Dec 2024 20:18:06 +0400 Subject: [PATCH 1/9] =?UTF-8?q?=D0=A5=D0=AD=D0=9B=D0=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Publication/Entites/PrintingHouseOrders.cs | 4 +- Publication/Entites/PrintingHouses.cs | 2 + Publication/Forms/FormCountReport.Designer.cs | 163 +++++++++ Publication/Forms/FormCountReport.cs | 20 ++ Publication/Forms/FormCountReport.resx | 120 +++++++ .../Forms/FormDirectoryReport.Designer.cs | 100 ++++++ Publication/Forms/FormDirectoryReport.cs | 58 ++++ Publication/Forms/FormDirectoryReport.resx | 120 +++++++ Publication/Publication.csproj | 1 + Publication/Reports/DocReport.cs | 86 +++++ Publication/Reports/ExcelBuilder.cs | 308 ++++++++++++++++++ Publication/Reports/TableReport.cs | 65 ++++ Publication/Reports/WordBuilder.cs | 97 ++++++ 13 files changed, 1142 insertions(+), 2 deletions(-) create mode 100644 Publication/Forms/FormCountReport.Designer.cs create mode 100644 Publication/Forms/FormCountReport.cs create mode 100644 Publication/Forms/FormCountReport.resx create mode 100644 Publication/Forms/FormDirectoryReport.Designer.cs create mode 100644 Publication/Forms/FormDirectoryReport.cs create mode 100644 Publication/Forms/FormDirectoryReport.resx create mode 100644 Publication/Reports/DocReport.cs create mode 100644 Publication/Reports/ExcelBuilder.cs create mode 100644 Publication/Reports/TableReport.cs create mode 100644 Publication/Reports/WordBuilder.cs diff --git a/Publication/Entites/PrintingHouseOrders.cs b/Publication/Entites/PrintingHouseOrders.cs index af3a013..68923cf 100644 --- a/Publication/Entites/PrintingHouseOrders.cs +++ b/Publication/Entites/PrintingHouseOrders.cs @@ -2,11 +2,11 @@ public class PrintingHouseOrders { - public int Id { get; set; } + public int PrintingHouseId { get; set; } public int OrderId { get; set; } public int Count { get; set; } public static PrintingHouseOrders CreateEntity(int id, int orderId, int count) { - return new PrintingHouseOrders { Id = id, OrderId = orderId, Count = count }; + return new PrintingHouseOrders { PrintingHouseId = id, OrderId = orderId, Count = count }; } } diff --git a/Publication/Entites/PrintingHouses.cs b/Publication/Entites/PrintingHouses.cs index 5731021..cfb1d8b 100644 --- a/Publication/Entites/PrintingHouses.cs +++ b/Publication/Entites/PrintingHouses.cs @@ -9,6 +9,8 @@ public class PrintingHouses public int MaterialsId { get; set; } + public DateTime Date { get; set; } + public IEnumerable printingHouseOrder { get; set; } = []; public static PrintingHouses CreateEntity(int id, string title, string phone, string address,int materialsId,IEnumerable printingHouseOrders) diff --git a/Publication/Forms/FormCountReport.Designer.cs b/Publication/Forms/FormCountReport.Designer.cs new file mode 100644 index 0000000..ff36846 --- /dev/null +++ b/Publication/Forms/FormCountReport.Designer.cs @@ -0,0 +1,163 @@ +namespace Publication.Forms +{ + partial class FormCountReport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + textBoxFilePath = new TextBox(); + dateTimePickerStartDate = new DateTimePicker(); + dateTimePickerEndDate = new DateTimePicker(); + buttonSelectFilePath = new Button(); + comboBoxProducts = new ComboBox(); + buttonMakeReport = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(22, 20); + label1.Name = "label1"; + label1.Size = new Size(112, 20); + label1.TabIndex = 0; + label1.Text = "Путь до файла:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(22, 72); + label2.Name = "label2"; + label2.Size = new Size(69, 20); + label2.TabIndex = 1; + label2.Text = "Продукт:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(22, 127); + label3.Name = "label3"; + label3.Size = new Size(97, 20); + label3.TabIndex = 2; + label3.Text = "Дата начала:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(22, 178); + label4.Name = "label4"; + label4.Size = new Size(90, 20); + label4.TabIndex = 3; + label4.Text = "Дата конца:"; + // + // textBoxFilePath + // + textBoxFilePath.Location = new Point(188, 20); + textBoxFilePath.Name = "textBoxFilePath"; + textBoxFilePath.ReadOnly = true; + textBoxFilePath.Size = new Size(147, 27); + textBoxFilePath.TabIndex = 4; + // + // dateTimePickerStartDate + // + dateTimePickerStartDate.Location = new Point(188, 127); + dateTimePickerStartDate.Name = "dateTimePickerStartDate"; + dateTimePickerStartDate.Size = new Size(181, 27); + dateTimePickerStartDate.TabIndex = 5; + // + // dateTimePickerEndDate + // + dateTimePickerEndDate.Location = new Point(188, 173); + dateTimePickerEndDate.Name = "dateTimePickerEndDate"; + dateTimePickerEndDate.Size = new Size(181, 27); + dateTimePickerEndDate.TabIndex = 6; + // + // buttonSelectFilePath + // + buttonSelectFilePath.BackColor = Color.FromArgb(192, 192, 255); + buttonSelectFilePath.Location = new Point(341, 20); + buttonSelectFilePath.Name = "buttonSelectFilePath"; + buttonSelectFilePath.Size = new Size(28, 29); + buttonSelectFilePath.TabIndex = 7; + buttonSelectFilePath.Text = ".."; + buttonSelectFilePath.UseVisualStyleBackColor = false; + // + // comboBoxProducts + // + comboBoxProducts.FormattingEnabled = true; + comboBoxProducts.Location = new Point(188, 72); + comboBoxProducts.Name = "comboBoxProducts"; + comboBoxProducts.Size = new Size(181, 28); + comboBoxProducts.TabIndex = 8; + // + // buttonMakeReport + // + buttonMakeReport.BackColor = Color.FromArgb(192, 192, 255); + buttonMakeReport.Location = new Point(22, 234); + buttonMakeReport.Name = "buttonMakeReport"; + buttonMakeReport.Size = new Size(347, 29); + buttonMakeReport.TabIndex = 9; + buttonMakeReport.Text = "Сформировать"; + buttonMakeReport.UseVisualStyleBackColor = false; + // + // FormProductReport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(409, 302); + Controls.Add(buttonMakeReport); + Controls.Add(comboBoxProducts); + Controls.Add(buttonSelectFilePath); + Controls.Add(dateTimePickerEndDate); + Controls.Add(dateTimePickerStartDate); + Controls.Add(textBoxFilePath); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormProductReport"; + Text = "FormProductReport"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private TextBox textBoxFilePath; + private DateTimePicker dateTimePickerStartDate; + private DateTimePicker dateTimePickerEndDate; + private Button buttonSelectFilePath; + private ComboBox comboBoxProducts; + private Button buttonMakeReport; + } +} \ No newline at end of file diff --git a/Publication/Forms/FormCountReport.cs b/Publication/Forms/FormCountReport.cs new file mode 100644 index 0000000..6e906d9 --- /dev/null +++ b/Publication/Forms/FormCountReport.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Publication.Forms +{ + public partial class FormCountReport : Form + { + public FormCountReport() + { + InitializeComponent(); + } + } +} diff --git a/Publication/Forms/FormCountReport.resx b/Publication/Forms/FormCountReport.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Publication/Forms/FormCountReport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Publication/Forms/FormDirectoryReport.Designer.cs b/Publication/Forms/FormDirectoryReport.Designer.cs new file mode 100644 index 0000000..15ba2cd --- /dev/null +++ b/Publication/Forms/FormDirectoryReport.Designer.cs @@ -0,0 +1,100 @@ +namespace Publication.Forms +{ + partial class FormDirectoryReport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + checkBoxCustomers = new CheckBox(); + checkBoxMaterials = new CheckBox(); + checkBoxPublishingHouse = new CheckBox(); + buttonCreate = new Button(); + SuspendLayout(); + // + // checkBoxCustomers + // + checkBoxCustomers.AutoSize = true; + checkBoxCustomers.Location = new Point(54, 34); + checkBoxCustomers.Name = "checkBoxCustomers"; + checkBoxCustomers.Size = new Size(102, 24); + checkBoxCustomers.TabIndex = 0; + checkBoxCustomers.Text = "Заказчики"; + checkBoxCustomers.UseVisualStyleBackColor = true; + // + // checkBoxMaterials + // + checkBoxMaterials.AutoSize = true; + checkBoxMaterials.Location = new Point(54, 101); + checkBoxMaterials.Name = "checkBoxMaterials"; + checkBoxMaterials.Size = new Size(111, 24); + checkBoxMaterials.TabIndex = 1; + checkBoxMaterials.Text = "Материалы"; + checkBoxMaterials.UseVisualStyleBackColor = true; + // + // checkBoxPublishingHouse + // + checkBoxPublishingHouse.AutoSize = true; + checkBoxPublishingHouse.Location = new Point(54, 170); + checkBoxPublishingHouse.Name = "checkBoxPublishingHouse"; + checkBoxPublishingHouse.Size = new Size(124, 24); + checkBoxPublishingHouse.TabIndex = 2; + checkBoxPublishingHouse.Text = "Издательства"; + checkBoxPublishingHouse.UseVisualStyleBackColor = true; + // + // buttonCreate + // + buttonCreate.BackColor = SystemColors.Control; + buttonCreate.Location = new Point(278, 101); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(133, 29); + buttonCreate.TabIndex = 3; + buttonCreate.Text = "Сформировать"; + buttonCreate.UseVisualStyleBackColor = false; + buttonCreate.Click += ButtonCreate_Click; + // + // FormDirectoryReport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(484, 236); + Controls.Add(buttonCreate); + Controls.Add(checkBoxPublishingHouse); + Controls.Add(checkBoxMaterials); + Controls.Add(checkBoxCustomers); + Name = "FormDirectoryReport"; + Text = "Выгрузка справочников"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox checkBoxCustomers; + private CheckBox checkBoxMaterials; + private CheckBox checkBoxPublishingHouse; + private Button buttonCreate; + } +} \ No newline at end of file diff --git a/Publication/Forms/FormDirectoryReport.cs b/Publication/Forms/FormDirectoryReport.cs new file mode 100644 index 0000000..90b979e --- /dev/null +++ b/Publication/Forms/FormDirectoryReport.cs @@ -0,0 +1,58 @@ +using Publication.Reports; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace Publication.Forms +{ + public partial class FormDirectoryReport : Form + { + private readonly IUnityContainer _container; + public FormDirectoryReport(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + try + { + if (!checkBoxCustomers.Checked && !checkBoxMaterials.Checked && !checkBoxPublishingHouse.Checked) + { + throw new Exception("Не выбран ни один справочник для выгрузки"); + } + var sfd = new SaveFileDialog() + { + Filter = "Docx Files | *.docx" + }; + if (sfd.ShowDialog() != DialogResult.OK) + { + throw new Exception("Не выбран файла для отчета"); + } + if (_container.Resolve().CreateDoc(sfd.FileName, checkBoxCustomers.Checked, + checkBoxMaterials.Checked, checkBoxPublishingHouse.Checked)) + { + MessageBox.Show("Документ сформирован", "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", + "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/Publication/Forms/FormDirectoryReport.resx b/Publication/Forms/FormDirectoryReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Publication/Forms/FormDirectoryReport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Publication/Publication.csproj b/Publication/Publication.csproj index 0307ec6..7eadc6a 100644 --- a/Publication/Publication.csproj +++ b/Publication/Publication.csproj @@ -10,6 +10,7 @@ + diff --git a/Publication/Reports/DocReport.cs b/Publication/Reports/DocReport.cs new file mode 100644 index 0000000..9c7be25 --- /dev/null +++ b/Publication/Reports/DocReport.cs @@ -0,0 +1,86 @@ +using Microsoft.Extensions.Logging; +using Publication.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Publication.Reports; + +public class DocReport +{ + private readonly ICustomerRepository _customerRepository; + private readonly IMaterialRepository _materialRepository; + private readonly IPublisingHouseRepository _publisingHouseRepository; + + private readonly ILogger _logger; + + public DocReport(ICustomerRepository customerRepository, IMaterialRepository materialRepository, + IPublisingHouseRepository publisingHouseRepository, ILogger logger) + { + _customerRepository = customerRepository ?? throw new ArgumentNullException(nameof(customerRepository)); + _materialRepository = materialRepository ?? throw new ArgumentNullException(nameof(materialRepository)); + _publisingHouseRepository = publisingHouseRepository ?? throw new ArgumentNullException(nameof(publisingHouseRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateDoc(string filePath, bool includeClients, bool includeManufacturers, bool includeProducts) + { + try + { + var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками"); + if (includeClients) + { + builder.AddParagraph("Заказчики").AddTable([2400, 1200, 2400, 2400, 2400], GetClients()); + } + if (includeManufacturers) + { + builder.AddParagraph("Материалы").AddTable([2400], GetManufacturers()); + } + if (includeProducts) + { + builder.AddParagraph("Издательства").AddTable([2400, 2400, 2400, 2400], GetProducts()); + } + builder.Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List GetClients() + { + return [ + ["ФИО клиента", "Тип клиента", "Оптовик"], + .. _customerRepository + .ReadCustomers() + .Select(x => new string[] { x.FullName, x.Age.ToString(), x.TypeCustomer.ToString(), x.Phone.ToString(), x.Email}), + ]; + } + + + private List GetManufacturers() + { + return [ + ["Название"], + .. _materialRepository + .ReadMaterials() + .Select(x => new string[] { x.DateMaterials.ToString(), x.Count.ToString(), x.Material.ToString()}), + ]; + } + + + private List GetProducts() + { + return [ + ["Название", "Производитель", "Категория", "Начальная цена"], + .._publisingHouseRepository + .ReadPublishingHouses() + .Select(x => new string[] {x.Title, x.Address, x.WorkPhone.ToString()}), + ]; + } +} diff --git a/Publication/Reports/ExcelBuilder.cs b/Publication/Reports/ExcelBuilder.cs new file mode 100644 index 0000000..01cf409 --- /dev/null +++ b/Publication/Reports/ExcelBuilder.cs @@ -0,0 +1,308 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Publication.Reports; + +public class ExcelBuilder +{ + private readonly string _filePath; + private readonly SheetData _sheetData; + private readonly MergeCells _mergeCells; + private readonly Columns _columns; + private uint _rowIndex = 0; + + public ExcelBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _sheetData = new SheetData(); + _mergeCells = new MergeCells(); + _columns = new Columns(); + _rowIndex = 1; + } + + public ExcelBuilder AddHeader(string header, int startIndex, int count) + { + CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithBorder); + for (int i = startIndex + 1; i < startIndex + count; ++i) + { + CreateCell(i, _rowIndex, "", StyleIndex.BoldTextWithBorder); + } + _mergeCells.Append(new MergeCell() + { + Reference = new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}") + }); + _rowIndex++; + return this; + } + + public ExcelBuilder AddParagraph(string text, int columnIndex) + { + CreateCell(columnIndex, _rowIndex++, text, StyleIndex.SimpleTextWithoutBorder); + return this; + } + public ExcelBuilder AddTable(int[] columnsWidths, List data) + { + if (columnsWidths == null || columnsWidths.Length == 0) + { + throw new ArgumentNullException(nameof(columnsWidths)); + } + if (data == null || data.Count == 0) + { + throw new ArgumentNullException(nameof(data)); + } + if (data.Any(x => x.Length != columnsWidths.Length)) + { + throw new InvalidOperationException("widths.Length != data.Length"); + } + uint counter = 1; + int coef = 2; + _columns.Append(columnsWidths.Select(x => new Column + { + Min = counter, + Max = counter++, + Width = x * coef, + CustomWidth = true + })); + for (var j = 0; j < data.First().Length; ++j) + { + CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder); + } + _rowIndex++; + for (var i = 1; i < data.Count - 1; ++i) + { + for (var j = 0; j < data[i].Length; ++j) + { + CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder); + } + _rowIndex++; + } + for (var j = 0; j < data.Last().Length; ++j) + { + CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder); + } + _rowIndex++; + return this; + } + + public void Build() + { + using var spreadsheetDocument = SpreadsheetDocument.Create(_filePath, SpreadsheetDocumentType.Workbook); + var workbookpart = spreadsheetDocument.AddWorkbookPart(); + GenerateStyle(workbookpart); + workbookpart.Workbook = new Workbook(); + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(); + if (_columns.HasChildren) + { + worksheetPart.Worksheet.Append(_columns); + } + worksheetPart.Worksheet.Append(_sheetData); + var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист 1" + }; + sheets.Append(sheet); + if (_mergeCells.HasChildren) + { + worksheetPart.Worksheet.InsertAfter(_mergeCells, worksheetPart.Worksheet.Elements().First()); + } + } + + private static void GenerateStyle(WorkbookPart workbookPart) + { + var workbookStylesPart = workbookPart.AddNewPart(); + workbookStylesPart.Stylesheet = new Stylesheet(); + var fonts = new Fonts() + { + Count = 2, + KnownFonts = BooleanValue.FromBoolean(true) + }; + fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font + { + FontSize = new FontSize() { Val = 11 }, + FontName = new FontName() { Val = "Calibri" }, + FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }, + FontScheme = new FontScheme() + { + Val = new EnumValue(FontSchemeValues.Minor) + } + }); + + fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font + { + FontSize = new FontSize() { Val = 11 }, + FontName = new FontName() { Val = "Calibri" }, + Bold = new Bold(), + FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }, + FontScheme = new FontScheme() + { + Val = new EnumValue(FontSchemeValues.Minor) + } + }); + workbookStylesPart.Stylesheet.Append(fonts); + // Default Fill + var fills = new Fills() { Count = 1 }; + fills.Append(new Fill + { + PatternFill = new PatternFill() + { + PatternType = new EnumValue(PatternValues.None) + } + }); + workbookStylesPart.Stylesheet.Append(fills); + // Default Border + var borders = new Borders() { Count = 2 }; + borders.Append(new Border + { + LeftBorder = new LeftBorder(), + RightBorder = new RightBorder(), + TopBorder = new TopBorder(), + BottomBorder = new BottomBorder(), + DiagonalBorder = new DiagonalBorder() + }); + + borders.Append(new Border + { + LeftBorder = new LeftBorder() { Style = BorderStyleValues.Medium }, + RightBorder = new RightBorder() { Style = BorderStyleValues.Medium }, + TopBorder = new TopBorder() { Style = BorderStyleValues.Medium }, + BottomBorder = new BottomBorder() { Style = BorderStyleValues.Medium }, + DiagonalBorder = new DiagonalBorder() { Style = BorderStyleValues.Medium }, + }); + workbookStylesPart.Stylesheet.Append(borders); + // Default cell format and a date cell format + var cellFormats = new CellFormats() { Count = 4 }; + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 0, + BorderId = 0, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Left, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + + cellFormats.Append(new CellFormat + { + NumberFormatId = 1, + FormatId = 0, + FontId = 0, + BorderId = 1, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Left, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + cellFormats.Append(new CellFormat + { + NumberFormatId = 2, + FormatId = 0, + FontId = 1, + BorderId = 0, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Left, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + cellFormats.Append(new CellFormat + { + NumberFormatId = 3, + FormatId = 0, + FontId = 1, + BorderId = 1, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Left, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + workbookStylesPart.Stylesheet.Append(cellFormats); + } + + private enum StyleIndex + { + SimpleTextWithoutBorder = 0, + SimpleTextWithBorder = 1, + BoldTextWithoutBorder = 2, + BoldTextWithBorder = 3, + } + + private void CreateCell(int columnIndex, uint rowIndex, string text, StyleIndex styleIndex) + { + var columnName = GetExcelColumnName(columnIndex); + var cellReference = columnName + rowIndex; + var row = _sheetData.Elements().FirstOrDefault(r => r.RowIndex! == rowIndex); + if (row == null) + { + row = new Row() { RowIndex = rowIndex }; + _sheetData.Append(row); + } + var newCell = row.Elements().FirstOrDefault(c => c.CellReference != null && c.CellReference.Value == columnName + rowIndex); + if (newCell == null) + { + Cell? refCell = null; + foreach (Cell cell in row.Elements()) + { + if (cell.CellReference?.Value != null && cell.CellReference.Value.Length == cellReference.Length) + { + if (string.Compare(cell.CellReference.Value, cellReference, true) > 0) + { + refCell = cell; + break; + } + } + } + newCell = new Cell() { CellReference = cellReference }; + row.InsertBefore(newCell, refCell); + } + newCell.CellValue = new CellValue(text); + newCell.DataType = CellValues.String; + newCell.StyleIndex = (uint)styleIndex; + } + + private static string GetExcelColumnName(int columnNumber) + { + columnNumber += 1; + int dividend = columnNumber; + string columnName = string.Empty; + int modulo; + while (dividend > 0) + { + modulo = (dividend - 1) % 26; + columnName = Convert.ToChar(65 + modulo).ToString() + + columnName; + dividend = (dividend - modulo) / 26; + } + return columnName; + } +} diff --git a/Publication/Reports/TableReport.cs b/Publication/Reports/TableReport.cs new file mode 100644 index 0000000..3813dc5 --- /dev/null +++ b/Publication/Reports/TableReport.cs @@ -0,0 +1,65 @@ +using Microsoft.Extensions.Logging; +using Publication.Repositories; +using Publication.Repositories.Implementations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Publication.Reports; + +public class TableReport +{ + private readonly IMaterialRepository _materialRepository; + private readonly IPrintingHouseRepository _printingHouseRepository; + private readonly ILogger _logger; + internal static readonly string[] item = ["Дата", "Количество пришло", "Количество ушло"]; + + public TableReport(IPrintingHouseRepository printingHouseRepository, IMaterialRepository materialRepository, ILogger logger) + { + _printingHouseRepository = printingHouseRepository ?? throw new ArgumentNullException(nameof(printingHouseRepository)); + _materialRepository = materialRepository ?? throw new ArgumentNullException(nameof(materialRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateTable(string filePath, DateTime startDate, DateTime endDate) + { + try + { + new ExcelBuilder(filePath) + .AddHeader("Сводка", 0, 4) + .AddParagraph("за период", 0) + .AddTable([10, 15, 15], GetData(startDate, endDate)) + .Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List GetData(DateTime startDate, DateTime endDate) + { + var data = _printingHouseRepository + .ReadPrintingHouses() + .Where(x => x.Date >= startDate && x.Date <= endDate && x.printingHouseOrder.Any(y => y.PrintingHouseId == x.Id)) + .Select(x => new {Date = x.Date, CountIn = (int?)null, CountOut = (int?)x.printingHouseOrder.FirstOrDefault(y => y.PrintingHouseId == x.Id).Count }) + .Union( + _materialRepository + .ReadMaterials() + .Where(x => x.DateMaterials >= startDate && x.DateMaterials <= endDate) + .Select(x => new {Date = x.DateMaterials, CountIn = (int?)x.Count, CountOut = (int?)null })) + .OrderBy(x => x.Date); + return + new List() { item } + .Union( + data + .Select(x => new string[] {x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) + .Union([["Всего", "", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]]) + .ToList(); + } + +} diff --git a/Publication/Reports/WordBuilder.cs b/Publication/Reports/WordBuilder.cs new file mode 100644 index 0000000..c2eca7b --- /dev/null +++ b/Publication/Reports/WordBuilder.cs @@ -0,0 +1,97 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace Publication.Reports; + +public class WordBuilder +{ + private readonly string _filePath; + private readonly Document _document; + private readonly Body _body; + + public WordBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + + _filePath = filePath; + _document = new Document(); + _body = _document.AppendChild(new Body()); + } + + public WordBuilder AddHeader(string header) + { + var paragraph = _body.AppendChild(new Paragraph()); + var run = paragraph.AppendChild(new Run()); + run.PrependChild(new RunProperties()); + run.AddChild(new Bold()); + run.AppendChild(new Text(header)); + + return this; + } + + public WordBuilder AddParagraph(string text) + { + var paragraph = _body.AppendChild(new Paragraph()); + var run = paragraph.AppendChild(new Run()); + run.AppendChild(new Text(text)); + + return this; + } + + public WordBuilder AddTable(int[] widths, List data) + { + if (widths == null || widths.Length == 0) + { + throw new ArgumentNullException(nameof(widths)); + } + + if (data == null || data.Count == 0) + { + throw new ArgumentNullException(nameof(data)); + } + + if (data.Any(x => x.Length != widths.Length)) + { + throw new InvalidOperationException("widths.Length != data.Length"); + } + + var table = new Table(); + table.AppendChild(new TableProperties( + new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.Single), Size = 12 }, + new BottomBorder() { Val = new EnumValue(BorderValues.Single), Size = 12 }, + new LeftBorder() { Val = new EnumValue(BorderValues.Single), Size = 12 }, + new RightBorder() { Val = new EnumValue(BorderValues.Single), Size = 12 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.Single), Size = 12 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.Single), Size = 12 }))); + + // Заголовок + var tr = new TableRow(); + for (var j = 0; j < widths.Length; ++j) + { + tr.Append(new TableCell(new TableCellProperties(new TableCellWidth() { Width = widths[j].ToString() }), + new Paragraph(new Run(new RunProperties(new Bold()), new Text(data.First()[j]))))); + } + table.Append(tr); + // Данные + table.Append(data.Skip(1).Select(x => new TableRow(x.Select(y => new TableCell(new Paragraph(new Run(new Text(y)))))))); + _body.Append(table); + return this; + } + public void Build() + { + using var wordDocument = WordprocessingDocument.Create(_filePath, + WordprocessingDocumentType.Document); + var mainPart = wordDocument.AddMainDocumentPart(); + mainPart.Document = _document; + } +} -- 2.25.1 From b44919089b8bede38f92f1d29301c754ff2b7fc7 Mon Sep 17 00:00:00 2001 From: Ctepa Date: Mon, 16 Dec 2024 21:03:03 +0400 Subject: [PATCH 2/9] =?UTF-8?q?=D0=90=D0=90=D0=90=D0=90=D0=90=D0=90=D0=90?= =?UTF-8?q?=D0=90=D0=90=D0=90=D0=90=D0=90=D0=90=D0=90=D0=90=D0=90=D0=90?= =?UTF-8?q?=D0=90=D0=90=D0=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Publication/Entites/PrintingHouses.cs | 22 ++++- .../Entites/TempPrintingHouseOrders.cs | 22 +++++ Publication/Forms/FormCountReport.Designer.cs | 43 +++------- Publication/Forms/FormCountReport.cs | 50 ++++++++++- Publication/Forms/FormCountReport.resx | 50 +++++------ Publication/Forms/FormPrintingHouse.cs | 3 +- Publication/Forms/Publication.Designer.cs | 17 ++++ Publication/Forms/Publication.cs | 24 ++++++ Publication/Forms/Publication.resx | 60 +++++++++---- Publication/Reports/PdfBuilder.cs | 86 +++++++++++++++++++ .../PrintingHouseRepository.cs | 12 ++- 11 files changed, 309 insertions(+), 80 deletions(-) create mode 100644 Publication/Entites/TempPrintingHouseOrders.cs create mode 100644 Publication/Reports/PdfBuilder.cs diff --git a/Publication/Entites/PrintingHouses.cs b/Publication/Entites/PrintingHouses.cs index cfb1d8b..bccce91 100644 --- a/Publication/Entites/PrintingHouses.cs +++ b/Publication/Entites/PrintingHouses.cs @@ -1,4 +1,7 @@ -namespace Publication.Entites; +using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing; +using Unity; + +namespace Publication.Entites; public class PrintingHouses { @@ -13,7 +16,7 @@ public class PrintingHouses public IEnumerable printingHouseOrder { get; set; } = []; - public static PrintingHouses CreateEntity(int id, string title, string phone, string address,int materialsId,IEnumerable printingHouseOrders) + public static PrintingHouses CreateEntity(int id, string title, string phone, string address,int materialsId, IEnumerable printingHouseOrders) { return new PrintingHouses @@ -23,7 +26,22 @@ public class PrintingHouses Phone = phone, Address = address, MaterialsId=materialsId, + Date = DateTime.Now, printingHouseOrder = printingHouseOrders }; } + + public static PrintingHouses CreateEntity(TempPrintingHouseOrders tempPrintingHouseOrders, IEnumerable _printingHouseOrders) + { + return new PrintingHouses + { + Id = tempPrintingHouseOrders.Id, + Title = tempPrintingHouseOrders.Title, + Phone = tempPrintingHouseOrders.Phone, + Address = tempPrintingHouseOrders.Address, + MaterialsId = tempPrintingHouseOrders.MaterialsId, + Date = tempPrintingHouseOrders.Date, + printingHouseOrder = _printingHouseOrders + }; + } } diff --git a/Publication/Entites/TempPrintingHouseOrders.cs b/Publication/Entites/TempPrintingHouseOrders.cs new file mode 100644 index 0000000..0e58ac8 --- /dev/null +++ b/Publication/Entites/TempPrintingHouseOrders.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Publication.Entites; + +public class TempPrintingHouseOrders +{ + public int Id { get; set; } + public string Title { get; set; } + public string Phone { get; set; } + public string Address { get; set; } + + public int MaterialsId { get; set; } + + public DateTime Date { get; set; } + + public int OrderId { get; set; } + public int Count { get; set; } +} diff --git a/Publication/Forms/FormCountReport.Designer.cs b/Publication/Forms/FormCountReport.Designer.cs index ff36846..40707cd 100644 --- a/Publication/Forms/FormCountReport.Designer.cs +++ b/Publication/Forms/FormCountReport.Designer.cs @@ -29,14 +29,12 @@ private void InitializeComponent() { label1 = new Label(); - label2 = new Label(); label3 = new Label(); label4 = new Label(); textBoxFilePath = new TextBox(); dateTimePickerStartDate = new DateTimePicker(); dateTimePickerEndDate = new DateTimePicker(); buttonSelectFilePath = new Button(); - comboBoxProducts = new ComboBox(); buttonMakeReport = new Button(); SuspendLayout(); // @@ -49,19 +47,10 @@ label1.TabIndex = 0; label1.Text = "Путь до файла:"; // - // label2 - // - label2.AutoSize = true; - label2.Location = new Point(22, 72); - label2.Name = "label2"; - label2.Size = new Size(69, 20); - label2.TabIndex = 1; - label2.Text = "Продукт:"; - // // label3 // label3.AutoSize = true; - label3.Location = new Point(22, 127); + label3.Location = new Point(22, 79); label3.Name = "label3"; label3.Size = new Size(97, 20); label3.TabIndex = 2; @@ -70,7 +59,7 @@ // label4 // label4.AutoSize = true; - label4.Location = new Point(22, 178); + label4.Location = new Point(22, 130); label4.Name = "label4"; label4.Size = new Size(90, 20); label4.TabIndex = 3; @@ -86,14 +75,14 @@ // // dateTimePickerStartDate // - dateTimePickerStartDate.Location = new Point(188, 127); + dateTimePickerStartDate.Location = new Point(188, 79); dateTimePickerStartDate.Name = "dateTimePickerStartDate"; dateTimePickerStartDate.Size = new Size(181, 27); dateTimePickerStartDate.TabIndex = 5; // // dateTimePickerEndDate // - dateTimePickerEndDate.Location = new Point(188, 173); + dateTimePickerEndDate.Location = new Point(188, 125); dateTimePickerEndDate.Name = "dateTimePickerEndDate"; dateTimePickerEndDate.Size = new Size(181, 27); dateTimePickerEndDate.TabIndex = 6; @@ -107,42 +96,34 @@ buttonSelectFilePath.TabIndex = 7; buttonSelectFilePath.Text = ".."; buttonSelectFilePath.UseVisualStyleBackColor = false; - // - // comboBoxProducts - // - comboBoxProducts.FormattingEnabled = true; - comboBoxProducts.Location = new Point(188, 72); - comboBoxProducts.Name = "comboBoxProducts"; - comboBoxProducts.Size = new Size(181, 28); - comboBoxProducts.TabIndex = 8; + buttonSelectFilePath.Click += ButtonSelectFilePath_Click; // // buttonMakeReport // buttonMakeReport.BackColor = Color.FromArgb(192, 192, 255); - buttonMakeReport.Location = new Point(22, 234); + buttonMakeReport.Location = new Point(22, 186); buttonMakeReport.Name = "buttonMakeReport"; buttonMakeReport.Size = new Size(347, 29); buttonMakeReport.TabIndex = 9; buttonMakeReport.Text = "Сформировать"; buttonMakeReport.UseVisualStyleBackColor = false; + buttonMakeReport.Click += ButtonMakeReport_Click; // - // FormProductReport + // FormCountReport // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(409, 302); + ClientSize = new Size(409, 249); Controls.Add(buttonMakeReport); - Controls.Add(comboBoxProducts); Controls.Add(buttonSelectFilePath); Controls.Add(dateTimePickerEndDate); Controls.Add(dateTimePickerStartDate); Controls.Add(textBoxFilePath); Controls.Add(label4); Controls.Add(label3); - Controls.Add(label2); Controls.Add(label1); - Name = "FormProductReport"; - Text = "FormProductReport"; + Name = "FormCountReport"; + Text = "FormCountReport"; ResumeLayout(false); PerformLayout(); } @@ -150,14 +131,12 @@ #endregion private Label label1; - private Label label2; private Label label3; private Label label4; private TextBox textBoxFilePath; private DateTimePicker dateTimePickerStartDate; private DateTimePicker dateTimePickerEndDate; private Button buttonSelectFilePath; - private ComboBox comboBoxProducts; private Button buttonMakeReport; } } \ No newline at end of file diff --git a/Publication/Forms/FormCountReport.cs b/Publication/Forms/FormCountReport.cs index 6e906d9..7c56465 100644 --- a/Publication/Forms/FormCountReport.cs +++ b/Publication/Forms/FormCountReport.cs @@ -1,4 +1,5 @@ -using System; +using Publication.Reports; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,14 +8,59 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Unity; namespace Publication.Forms { public partial class FormCountReport : Form { - public FormCountReport() + IUnityContainer _container; + + public FormCountReport(IUnityContainer container) { InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void ButtonSelectFilePath_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Excel Files | *.xlsx" + }; + if (sfd.ShowDialog() != DialogResult.OK) + { + return; + } + textBoxFilePath.Text = sfd.FileName; + } + + private void ButtonMakeReport_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFilePath.Text)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + if (dateTimePickerEndDate.Value <= dateTimePickerStartDate.Value) + { + throw new Exception("Дата начала должна быть раньше даты окончания"); + } + if (_container.Resolve().CreateTable(textBoxFilePath.Text, dateTimePickerStartDate.Value, dateTimePickerEndDate.Value)) + { + MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании очета", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } } diff --git a/Publication/Forms/FormCountReport.resx b/Publication/Forms/FormCountReport.resx index 1af7de1..af32865 100644 --- a/Publication/Forms/FormCountReport.resx +++ b/Publication/Forms/FormCountReport.resx @@ -1,17 +1,17 @@  - diff --git a/Publication/Forms/FormPrintingHouse.cs b/Publication/Forms/FormPrintingHouse.cs index 5d2f30d..66fe4cf 100644 --- a/Publication/Forms/FormPrintingHouse.cs +++ b/Publication/Forms/FormPrintingHouse.cs @@ -82,7 +82,8 @@ MessageBoxButtons.OK, MessageBoxIcon.Error); ) ); } - return list; + return list.GroupBy(x => x.OrderId, x => x.Count, (id, counts) => + PrintingHouseOrders.CreateEntity(0, id, counts.Sum())).ToList(); } private void ButtonBreak_Click(object sender, EventArgs e) => Close(); diff --git a/Publication/Forms/Publication.Designer.cs b/Publication/Forms/Publication.Designer.cs index 0f5455e..af60789 100644 --- a/Publication/Forms/Publication.Designer.cs +++ b/Publication/Forms/Publication.Designer.cs @@ -38,6 +38,8 @@ CreateOrderToolStripMenuItem = new ToolStripMenuItem(); PrintingToolStripMenuItem = new ToolStripMenuItem(); ReportsToolStripMenuItem = new ToolStripMenuItem(); + DirectoryReportToolStripMenuItem = new ToolStripMenuItem(); + CountReportToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -92,9 +94,22 @@ // // ReportsToolStripMenuItem // + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, CountReportToolStripMenuItem }); ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; resources.ApplyResources(ReportsToolStripMenuItem, "ReportsToolStripMenuItem"); // + // DirectoryReportToolStripMenuItem + // + DirectoryReportToolStripMenuItem.Name = "DirectoryReportToolStripMenuItem"; + resources.ApplyResources(DirectoryReportToolStripMenuItem, "DirectoryReportToolStripMenuItem"); + DirectoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click; + // + // CountReportToolStripMenuItem + // + CountReportToolStripMenuItem.Name = "CountReportToolStripMenuItem"; + resources.ApplyResources(CountReportToolStripMenuItem, "CountReportToolStripMenuItem"); + CountReportToolStripMenuItem.Click += CountReportToolStripMenuItem_Click; + // // Publication // resources.ApplyResources(this, "$this"); @@ -119,5 +134,7 @@ private ToolStripMenuItem CreateOrderToolStripMenuItem; private ToolStripMenuItem PrintingToolStripMenuItem; private ToolStripMenuItem ReportsToolStripMenuItem; + private ToolStripMenuItem DirectoryReportToolStripMenuItem; + private ToolStripMenuItem CountReportToolStripMenuItem; } } diff --git a/Publication/Forms/Publication.cs b/Publication/Forms/Publication.cs index 1840d63..00569c7 100644 --- a/Publication/Forms/Publication.cs +++ b/Publication/Forms/Publication.cs @@ -81,4 +81,28 @@ public partial class Publication : Form MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void DirectoryReportToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + unityContainer.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CountReportToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + unityContainer.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } diff --git a/Publication/Forms/Publication.resx b/Publication/Forms/Publication.resx index 230ba5a..9d79e54 100644 --- a/Publication/Forms/Publication.resx +++ b/Publication/Forms/Publication.resx @@ -127,24 +127,31 @@ Справочники - - 224, 26 - - - Создать заказ - - - 224, 26 - - - Печать - 95, 24 Операции + + + Ctrl+W + + + 350, 26 + + + Документ со справочниками + + + Ctrl+E + + + 350, 26 + + + Движение заказов + 73, 24 @@ -183,17 +190,29 @@ Заказчики - 224, 26 + 185, 26 Материалы - 224, 26 + 185, 26 Издательства + + 188, 26 + + + Создать заказ + + + 188, 26 + + + Печать + True @@ -2156,7 +2175,6 @@ Gg8Vxln/2Q== - Stretch @@ -2217,6 +2235,18 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + DirectoryReportToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + CountReportToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Publication diff --git a/Publication/Reports/PdfBuilder.cs b/Publication/Reports/PdfBuilder.cs new file mode 100644 index 0000000..dd8d965 --- /dev/null +++ b/Publication/Reports/PdfBuilder.cs @@ -0,0 +1,86 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Publication.Reports; + +public class PdfBuilder +{ + /*private readonly string _filePath; + private readonly Document _document; + public PdfBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + _filePath = filePath; + _document = new Document(); + DefineStyles(); + } + public PdfBuilder AddHeader(string header) + { + _document.AddSection().AddParagraph(header, "NormalBold"); + return this; + } + + public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data) + { + if (data == null || data.Count == 0) + { + return this; + } + var chart = new Chart(ChartType.Pie2D); + var series = chart.SeriesCollection.AddSeries(); + series.Add(data.Select(x => x.Value).ToArray()); + + var xseries = chart.XValues.AddXSeries(); + xseries.Add(data.Select(x => x.Caption).ToArray()); + + chart.DataLabel.Type = DataLabelType.Percent; + chart.DataLabel.Position = DataLabelPosition.OutsideEnd; + + chart.Width = Unit.FromCentimeter(16); + chart.Height = Unit.FromCentimeter(12); + + chart.TopArea.AddParagraph(title); + + chart.XAxis.MajorTickMark = TickMarkType.Outside; + + chart.YAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.HasMajorGridlines = true; + + chart.PlotArea.LineFormat.Width = 1; + chart.PlotArea.LineFormat.Visible = true; + + chart.TopArea.AddLegend(); + + _document.LastSection.Add(chart); + return this; + } + + public void Build() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(_filePath); + } + private void DefineStyles() + { + var headerStyle = _document.AddStyle("NormalBold", "Normal"); + headerStyle.Font.Bold = true; + headerStyle.Font.Size = 14; + headerStyle.Font.Color = Colors.DeepPink; + }*/ +} diff --git a/Publication/Repositories/Implementations/PrintingHouseRepository.cs b/Publication/Repositories/Implementations/PrintingHouseRepository.cs index 48a4870..baa948d 100644 --- a/Publication/Repositories/Implementations/PrintingHouseRepository.cs +++ b/Publication/Repositories/Implementations/PrintingHouseRepository.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using Npgsql; using Publication.Entites; using Dapper; +using Unity; namespace Publication.Repositories.Implementations; @@ -75,10 +76,15 @@ public class PrintingHouseRepository : IPrintingHouseRepository try { using var connection = new NpgsqlConnection(connectionRepository.GetConnection); - var querySelect = "SELECT * FROM PrintingHouses"; - var printingHouses = connection.Query(querySelect); + var querySelect = @"SELECT ph.*, pho.OrderId, pho.Count + FROM PrintingHouses ph + INNER JOIN PrintingHouseOrders pho ON pho.PrintingHouseId = ph.Id"; + var printingHouses = connection.Query(querySelect); logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(printingHouses)); - return printingHouses; + return printingHouses.GroupBy(x => x.Id, y => y, + (key, value) => PrintingHouses.CreateEntity(value.First(), + value.Select(z => PrintingHouseOrders.CreateEntity(0, z.OrderId, z.Count)))).ToList(); + } catch (Exception ex) { -- 2.25.1 From 6533461c8af6f82bc949052eaf66442c37d4941d Mon Sep 17 00:00:00 2001 From: Anitonchik Date: Tue, 17 Dec 2024 21:33:48 +0400 Subject: [PATCH 3/9] chek --- Publication/Reports/DocReport.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Publication/Reports/DocReport.cs b/Publication/Reports/DocReport.cs index 9c7be25..aa8a787 100644 --- a/Publication/Reports/DocReport.cs +++ b/Publication/Reports/DocReport.cs @@ -13,7 +13,6 @@ public class DocReport private readonly ICustomerRepository _customerRepository; private readonly IMaterialRepository _materialRepository; private readonly IPublisingHouseRepository _publisingHouseRepository; - private readonly ILogger _logger; public DocReport(ICustomerRepository customerRepository, IMaterialRepository materialRepository, -- 2.25.1 From 37b2681290cfd3e2144fff10c1923cbce2109ea3 Mon Sep 17 00:00:00 2001 From: shaman_stepan Date: Tue, 17 Dec 2024 21:44:13 +0400 Subject: [PATCH 4/9] Chekk --- Publication/Reports/DocReport.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Publication/Reports/DocReport.cs b/Publication/Reports/DocReport.cs index aa8a787..9c7be25 100644 --- a/Publication/Reports/DocReport.cs +++ b/Publication/Reports/DocReport.cs @@ -13,6 +13,7 @@ public class DocReport private readonly ICustomerRepository _customerRepository; private readonly IMaterialRepository _materialRepository; private readonly IPublisingHouseRepository _publisingHouseRepository; + private readonly ILogger _logger; public DocReport(ICustomerRepository customerRepository, IMaterialRepository materialRepository, -- 2.25.1 From 3d6e4a06f29ebc709390f18737d0e35f620407f5 Mon Sep 17 00:00:00 2001 From: Ctepa Date: Wed, 18 Dec 2024 19:11:56 +0400 Subject: [PATCH 5/9] =?UTF-8?q?2=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0=20?= =?UTF-8?q?=D0=98=D0=98=D0=98=D0=98=D0=98=D0=A3=D0=A3=D0=A3=D0=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/FormPrintingHouses.Designer.cs | 6 +-- Publication/Publication.csproj | 2 + Publication/Reports/ChartReport.cs | 45 +++++++++++++++++++ Publication/Reports/DocReport.cs | 20 ++++----- Publication/Reports/PdfBuilder.cs | 9 ++-- Publication/Reports/TableReport.cs | 6 +-- Publication/Reports/WordBuilder.cs | 2 +- .../PrintingHouseRepository.cs | 6 +-- 8 files changed, 72 insertions(+), 24 deletions(-) create mode 100644 Publication/Reports/ChartReport.cs diff --git a/Publication/Forms/FormPrintingHouses.Designer.cs b/Publication/Forms/FormPrintingHouses.Designer.cs index 2563676..2295200 100644 --- a/Publication/Forms/FormPrintingHouses.Designer.cs +++ b/Publication/Forms/FormPrintingHouses.Designer.cs @@ -42,7 +42,7 @@ panel1.Controls.Add(buttonDelete); panel1.Controls.Add(buttonAdd); panel1.Dock = DockStyle.Right; - panel1.Location = new Point(603, 0); + panel1.Location = new Point(856, 0); panel1.Name = "panel1"; panel1.Size = new Size(197, 450); panel1.TabIndex = 2; @@ -85,14 +85,14 @@ dataGridView1.RowHeadersVisible = false; dataGridView1.RowHeadersWidth = 51; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView1.Size = new Size(603, 450); + dataGridView1.Size = new Size(856, 450); dataGridView1.TabIndex = 3; // // FormPrintingHouses // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(1053, 450); Controls.Add(dataGridView1); Controls.Add(panel1); Name = "FormPrintingHouses"; diff --git a/Publication/Publication.csproj b/Publication/Publication.csproj index 7eadc6a..245adf8 100644 --- a/Publication/Publication.csproj +++ b/Publication/Publication.csproj @@ -11,11 +11,13 @@ + + diff --git a/Publication/Reports/ChartReport.cs b/Publication/Reports/ChartReport.cs new file mode 100644 index 0000000..803fc7b --- /dev/null +++ b/Publication/Reports/ChartReport.cs @@ -0,0 +1,45 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Publication.Reports; + +public class ChartReport +{ + /*private readonly IOrderRepository _invoiceRepository; + private readonly ILogger _logger; + public ChartReport(IInvoiceRepository invoiceRepository, ILogger logger) + { + _invoiceRepository = invoiceRepository ?? throw new ArgumentNullException(nameof(invoiceRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + public bool CreateChart(string filePath, DateTime dateTime) + { + try + { + new PdfBuilder(filePath) + .AddHeader("Сумма покупки каждого клиента") + .AddPieChart("Клиенты", GetData(dateTime)) + .Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List<(string Caption, double Value)> GetData(DateTime dateTime) + { + return _invoiceRepository + .ReadInvoices() + .Where(x => x.DateInvoice.Date == dateTime.Date) + .GroupBy(x => x.ClientID, (key, group) => new { ID = key, Count = group.Sum(y => y.SellingPrice) }) + .Select(x => (x.ID.ToString(), (double)x.Count)) + .ToList(); + }*/ +} diff --git a/Publication/Reports/DocReport.cs b/Publication/Reports/DocReport.cs index 9c7be25..ec39160 100644 --- a/Publication/Reports/DocReport.cs +++ b/Publication/Reports/DocReport.cs @@ -32,15 +32,15 @@ public class DocReport var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками"); if (includeClients) { - builder.AddParagraph("Заказчики").AddTable([2400, 1200, 2400, 2400, 2400], GetClients()); + builder.AddParagraph("Заказчики").AddTable([2400, 1200, 2400, 2400, 2400], GetCustomers()); } if (includeManufacturers) { - builder.AddParagraph("Материалы").AddTable([2400], GetManufacturers()); + builder.AddParagraph("Материалы").AddTable([1200, 2400, 2400], GetMaterials()); } if (includeProducts) { - builder.AddParagraph("Издательства").AddTable([2400, 2400, 2400, 2400], GetProducts()); + builder.AddParagraph("Издательства").AddTable([2400, 2400, 2400], GetPublishingHouse()); } builder.Build(); return true; @@ -52,10 +52,10 @@ public class DocReport } } - private List GetClients() + private List GetCustomers() { return [ - ["ФИО клиента", "Тип клиента", "Оптовик"], + ["ФИО заказчика", "Возраст", "Тип заказчика", "Телефон", "Email"], .. _customerRepository .ReadCustomers() .Select(x => new string[] { x.FullName, x.Age.ToString(), x.TypeCustomer.ToString(), x.Phone.ToString(), x.Email}), @@ -63,21 +63,21 @@ public class DocReport } - private List GetManufacturers() + private List GetMaterials() { return [ - ["Название"], + [ "Материал", "Количество", "Дата"], .. _materialRepository .ReadMaterials() - .Select(x => new string[] { x.DateMaterials.ToString(), x.Count.ToString(), x.Material.ToString()}), + .Select(x => new string[] {x.Material.ToString(), x.Count.ToString(), x.DateMaterials.ToString()}), ]; } - private List GetProducts() + private List GetPublishingHouse() { return [ - ["Название", "Производитель", "Категория", "Начальная цена"], + ["Название", "Адрес", "Рабочик телефон"], .._publisingHouseRepository .ReadPublishingHouses() .Select(x => new string[] {x.Title, x.Address, x.WorkPhone.ToString()}), diff --git a/Publication/Reports/PdfBuilder.cs b/Publication/Reports/PdfBuilder.cs index dd8d965..23457a2 100644 --- a/Publication/Reports/PdfBuilder.cs +++ b/Publication/Reports/PdfBuilder.cs @@ -1,4 +1,6 @@ - +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Shapes.Charts; +using MigraDoc.Rendering; using System; using System.Collections.Generic; using System.Linq; @@ -9,7 +11,7 @@ namespace Publication.Reports; public class PdfBuilder { - /*private readonly string _filePath; + private readonly string _filePath; private readonly Document _document; public PdfBuilder(string filePath) { @@ -81,6 +83,5 @@ public class PdfBuilder var headerStyle = _document.AddStyle("NormalBold", "Normal"); headerStyle.Font.Bold = true; headerStyle.Font.Size = 14; - headerStyle.Font.Color = Colors.DeepPink; - }*/ + } } diff --git a/Publication/Reports/TableReport.cs b/Publication/Reports/TableReport.cs index 3813dc5..21f71fc 100644 --- a/Publication/Reports/TableReport.cs +++ b/Publication/Reports/TableReport.cs @@ -42,11 +42,11 @@ public class TableReport } private List GetData(DateTime startDate, DateTime endDate) - { + { var data = _printingHouseRepository .ReadPrintingHouses() .Where(x => x.Date >= startDate && x.Date <= endDate && x.printingHouseOrder.Any(y => y.PrintingHouseId == x.Id)) - .Select(x => new {Date = x.Date, CountIn = (int?)null, CountOut = (int?)x.printingHouseOrder.FirstOrDefault(y => y.PrintingHouseId == x.Id).Count }) + .Select(x => new { x.Date, CountIn = (int?)null, CountOut = (int?)x.printingHouseOrder.First(y => y.PrintingHouseId == x.Id).Count }) .Union( _materialRepository .ReadMaterials() @@ -58,7 +58,7 @@ public class TableReport .Union( data .Select(x => new string[] {x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) - .Union([["Всего", "", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]]) + .Union([["Всего", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]]) .ToList(); } diff --git a/Publication/Reports/WordBuilder.cs b/Publication/Reports/WordBuilder.cs index c2eca7b..59d57de 100644 --- a/Publication/Reports/WordBuilder.cs +++ b/Publication/Reports/WordBuilder.cs @@ -32,7 +32,7 @@ public class WordBuilder var paragraph = _body.AppendChild(new Paragraph()); var run = paragraph.AppendChild(new Run()); run.PrependChild(new RunProperties()); - run.AddChild(new Bold()); + run.RunProperties.AddChild(new Bold()); run.AppendChild(new Text(header)); return this; diff --git a/Publication/Repositories/Implementations/PrintingHouseRepository.cs b/Publication/Repositories/Implementations/PrintingHouseRepository.cs index baa948d..b543e66 100644 --- a/Publication/Repositories/Implementations/PrintingHouseRepository.cs +++ b/Publication/Repositories/Implementations/PrintingHouseRepository.cs @@ -27,8 +27,8 @@ public class PrintingHouseRepository : IPrintingHouseRepository using var connection = new NpgsqlConnection(connectionRepository.GetConnection); connection.Open(); using var transaction=connection.BeginTransaction(); - var queryInsert = @"INSERT INTO PrintingHouses (Title, Phone, Address, MaterialsId) - VALUES (@Title, @Phone, @Address, @MaterialsId); + var queryInsert = @"INSERT INTO PrintingHouses (Title, Phone, Address, Date, MaterialsId) + VALUES (@Title, @Phone, @Address, @Date, @MaterialsId); SELECT MAX(Id) FROM PrintingHouses"; var PrintingHouseId = connection.QueryFirst(queryInsert, printerHouse, transaction); var querySubInsert = @" @@ -83,7 +83,7 @@ public class PrintingHouseRepository : IPrintingHouseRepository logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(printingHouses)); return printingHouses.GroupBy(x => x.Id, y => y, (key, value) => PrintingHouses.CreateEntity(value.First(), - value.Select(z => PrintingHouseOrders.CreateEntity(0, z.OrderId, z.Count)))).ToList(); + value.Select(z => PrintingHouseOrders.CreateEntity(z.Id, z.OrderId, z.Count)))).ToList(); } catch (Exception ex) -- 2.25.1 From 462e623bc49ec777ab4b249ccab7a00e8f34f15c Mon Sep 17 00:00:00 2001 From: Ctepa Date: Wed, 18 Dec 2024 19:39:16 +0400 Subject: [PATCH 6/9] =?UTF-8?q?=D0=93=D0=9E=D0=A2=D0=9E=D0=92=D0=9E=D0=9E?= =?UTF-8?q?=D0=9E=D0=9E=D0=9E=D0=9E=D0=9E=D0=9E=D0=9E=D0=9E=D0=9E=D0=9E?= =?UTF-8?q?=D0=9E=D0=9E=D0=9E=D0=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ormMaterialsDistributionReport.Designer.cs | 109 ++++++++++++++++ .../Forms/FormMaterialsDistributionReport.cs | 65 ++++++++++ .../FormMaterialsDistributionReport.resx | 120 ++++++++++++++++++ Publication/Forms/Publication.Designer.cs | 10 +- Publication/Forms/Publication.cs | 12 ++ Publication/Forms/Publication.resx | 72 ++++++----- Publication/Reports/ChartReport.cs | 22 ++-- 7 files changed, 369 insertions(+), 41 deletions(-) create mode 100644 Publication/Forms/FormMaterialsDistributionReport.Designer.cs create mode 100644 Publication/Forms/FormMaterialsDistributionReport.cs create mode 100644 Publication/Forms/FormMaterialsDistributionReport.resx diff --git a/Publication/Forms/FormMaterialsDistributionReport.Designer.cs b/Publication/Forms/FormMaterialsDistributionReport.Designer.cs new file mode 100644 index 0000000..3d7af08 --- /dev/null +++ b/Publication/Forms/FormMaterialsDistributionReport.Designer.cs @@ -0,0 +1,109 @@ +namespace Publication.Forms +{ + partial class FormMaterialsDistributionReport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonSelectFileName = new Button(); + labelFileName = new Label(); + label1 = new Label(); + dateTimePicker = new DateTimePicker(); + buttonCreate = new Button(); + SuspendLayout(); + // + // buttonSelectFileName + // + buttonSelectFileName.BackColor = Color.FromArgb(192, 255, 192); + buttonSelectFileName.Location = new Point(12, 23); + buttonSelectFileName.Name = "buttonSelectFileName"; + buttonSelectFileName.Size = new Size(129, 29); + buttonSelectFileName.TabIndex = 0; + buttonSelectFileName.Text = "Выбрать"; + buttonSelectFileName.UseVisualStyleBackColor = false; + buttonSelectFileName.Click += ButtonSelectFileName_Click; + // + // labelFileName + // + labelFileName.AutoSize = true; + labelFileName.Location = new Point(179, 27); + labelFileName.Name = "labelFileName"; + labelFileName.Size = new Size(45, 20); + labelFileName.TabIndex = 1; + labelFileName.Text = "Файл"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 81); + label1.Name = "label1"; + label1.Size = new Size(44, 20); + label1.TabIndex = 2; + label1.Text = "Дата:"; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(179, 76); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(183, 27); + dateTimePicker.TabIndex = 3; + // + // buttonCreate + // + buttonCreate.BackColor = Color.FromArgb(192, 255, 192); + buttonCreate.Location = new Point(12, 146); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(350, 29); + buttonCreate.TabIndex = 4; + buttonCreate.Text = "Сформировать"; + buttonCreate.UseVisualStyleBackColor = false; + buttonCreate.Click += ButtonCreate_Click; + // + // FormMaterialsDistributionReport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(395, 227); + Controls.Add(buttonCreate); + Controls.Add(dateTimePicker); + Controls.Add(label1); + Controls.Add(labelFileName); + Controls.Add(buttonSelectFileName); + Name = "FormMaterialsDistributionReport"; + Text = "FormInvoiceDistributionReport"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSelectFileName; + private Label labelFileName; + private Label label1; + private DateTimePicker dateTimePicker; + private Button buttonCreate; + } +} diff --git a/Publication/Forms/FormMaterialsDistributionReport.cs b/Publication/Forms/FormMaterialsDistributionReport.cs new file mode 100644 index 0000000..5ec465f --- /dev/null +++ b/Publication/Forms/FormMaterialsDistributionReport.cs @@ -0,0 +1,65 @@ +using Publication.Reports; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace Publication.Forms; + +public partial class FormMaterialsDistributionReport : Form +{ + private string _fileName = string.Empty; + + private readonly IUnityContainer _container; + + public FormMaterialsDistributionReport(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void ButtonSelectFileName_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Pdf Files | *.pdf" + }; + if (sfd.ShowDialog() == DialogResult.OK) + { + _fileName = sfd.FileName; + labelFileName.Text = Path.GetFileName(_fileName); + } + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(_fileName)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + if + (_container.Resolve().CreateChart(_fileName, dateTimePicker.Value)) + { + MessageBox.Show("Документ сформирован", "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", + "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании очета", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } +} diff --git a/Publication/Forms/FormMaterialsDistributionReport.resx b/Publication/Forms/FormMaterialsDistributionReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Publication/Forms/FormMaterialsDistributionReport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Publication/Forms/Publication.Designer.cs b/Publication/Forms/Publication.Designer.cs index af60789..20e6bde 100644 --- a/Publication/Forms/Publication.Designer.cs +++ b/Publication/Forms/Publication.Designer.cs @@ -40,6 +40,7 @@ ReportsToolStripMenuItem = new ToolStripMenuItem(); DirectoryReportToolStripMenuItem = new ToolStripMenuItem(); CountReportToolStripMenuItem = new ToolStripMenuItem(); + MaterialDistributionToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -94,7 +95,7 @@ // // ReportsToolStripMenuItem // - ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, CountReportToolStripMenuItem }); + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, CountReportToolStripMenuItem, MaterialDistributionToolStripMenuItem }); ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; resources.ApplyResources(ReportsToolStripMenuItem, "ReportsToolStripMenuItem"); // @@ -110,6 +111,12 @@ resources.ApplyResources(CountReportToolStripMenuItem, "CountReportToolStripMenuItem"); CountReportToolStripMenuItem.Click += CountReportToolStripMenuItem_Click; // + // MaterialDistributionToolStripMenuItem + // + MaterialDistributionToolStripMenuItem.Name = "MaterialDistributionToolStripMenuItem"; + resources.ApplyResources(MaterialDistributionToolStripMenuItem, "MaterialDistributionToolStripMenuItem"); + MaterialDistributionToolStripMenuItem.Click += MaterialDistributionToolStripMenuItem_Click; + // // Publication // resources.ApplyResources(this, "$this"); @@ -136,5 +143,6 @@ private ToolStripMenuItem ReportsToolStripMenuItem; private ToolStripMenuItem DirectoryReportToolStripMenuItem; private ToolStripMenuItem CountReportToolStripMenuItem; + private ToolStripMenuItem MaterialDistributionToolStripMenuItem; } } diff --git a/Publication/Forms/Publication.cs b/Publication/Forms/Publication.cs index 00569c7..fad35d2 100644 --- a/Publication/Forms/Publication.cs +++ b/Publication/Forms/Publication.cs @@ -105,4 +105,16 @@ public partial class Publication : Form MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void MaterialDistributionToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + unityContainer.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } diff --git a/Publication/Forms/Publication.resx b/Publication/Forms/Publication.resx index 9d79e54..2ecd179 100644 --- a/Publication/Forms/Publication.resx +++ b/Publication/Forms/Publication.resx @@ -121,12 +121,42 @@ 17, 17 + + 185, 26 + + + Заказчики + + + 185, 26 + + + Материалы + + + 185, 26 + + + Издательства + 117, 24 Справочники + + 188, 26 + + + Создать заказ + + + 188, 26 + + + Печать + 95, 24 @@ -152,6 +182,12 @@ Движение заказов + + 350, 26 + + + Распределение материалов + 73, 24 @@ -183,36 +219,6 @@ 0 - - 185, 26 - - - Заказчики - - - 185, 26 - - - Материалы - - - 185, 26 - - - Издательства - - - 188, 26 - - - Создать заказ - - - 188, 26 - - - Печать - True @@ -2247,6 +2253,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + MaterialDistributionToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Publication diff --git a/Publication/Reports/ChartReport.cs b/Publication/Reports/ChartReport.cs index 803fc7b..64fe62b 100644 --- a/Publication/Reports/ChartReport.cs +++ b/Publication/Reports/ChartReport.cs @@ -1,4 +1,6 @@ using Microsoft.Extensions.Logging; +using Publication.Repositories; +using Publication.Repositories.Implementations; using System; using System.Collections.Generic; using System.Linq; @@ -9,11 +11,11 @@ namespace Publication.Reports; public class ChartReport { - /*private readonly IOrderRepository _invoiceRepository; + private readonly IMaterialRepository _materialRepository; private readonly ILogger _logger; - public ChartReport(IInvoiceRepository invoiceRepository, ILogger logger) + public ChartReport(IMaterialRepository materialRepository, ILogger logger) { - _invoiceRepository = invoiceRepository ?? throw new ArgumentNullException(nameof(invoiceRepository)); + _materialRepository = materialRepository ?? throw new ArgumentNullException(nameof(materialRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } public bool CreateChart(string filePath, DateTime dateTime) @@ -21,8 +23,8 @@ public class ChartReport try { new PdfBuilder(filePath) - .AddHeader("Сумма покупки каждого клиента") - .AddPieChart("Клиенты", GetData(dateTime)) + .AddHeader("Количество материалов") + .AddPieChart("Материалы", GetData(dateTime)) .Build(); return true; } @@ -35,11 +37,11 @@ public class ChartReport private List<(string Caption, double Value)> GetData(DateTime dateTime) { - return _invoiceRepository - .ReadInvoices() - .Where(x => x.DateInvoice.Date == dateTime.Date) - .GroupBy(x => x.ClientID, (key, group) => new { ID = key, Count = group.Sum(y => y.SellingPrice) }) + return _materialRepository + .ReadMaterials() + .Where(x => x.DateMaterials.Date == dateTime.Date) + .GroupBy(x => x.Id, (key, group) => new { ID = key, Count = group.Sum(y => y.Count) }) .Select(x => (x.ID.ToString(), (double)x.Count)) .ToList(); - }*/ + } } -- 2.25.1 From c4150d9536c39cabbe95a007f08b41909676a519 Mon Sep 17 00:00:00 2001 From: Ctepa Date: Wed, 18 Dec 2024 19:55:01 +0400 Subject: [PATCH 7/9] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Publication/Forms/FormCountReport.Designer.cs | 6 +++--- Publication/Forms/FormMaterial.Designer.cs | 2 +- Publication/Forms/FormMaterials.Designer.cs | 2 +- Publication/Forms/FormMaterials.resx | 4 ++-- .../Forms/FormMaterialsDistributionReport.Designer.cs | 6 +++--- Publication/Forms/FormOrder.Designer.cs | 2 +- Publication/Forms/FormOrders.Designer.cs | 2 +- Publication/Forms/FormPrintingHouse.Designer.cs | 2 +- Publication/Forms/FormPrintingHouse.resx | 6 ++++++ Publication/Forms/FormPrintingHouses.Designer.cs | 2 +- Publication/Forms/FormPublishingHouses.Designer.cs | 2 +- 11 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Publication/Forms/FormCountReport.Designer.cs b/Publication/Forms/FormCountReport.Designer.cs index 40707cd..6f62495 100644 --- a/Publication/Forms/FormCountReport.Designer.cs +++ b/Publication/Forms/FormCountReport.Designer.cs @@ -89,7 +89,7 @@ // // buttonSelectFilePath // - buttonSelectFilePath.BackColor = Color.FromArgb(192, 192, 255); + buttonSelectFilePath.BackColor = SystemColors.Control; buttonSelectFilePath.Location = new Point(341, 20); buttonSelectFilePath.Name = "buttonSelectFilePath"; buttonSelectFilePath.Size = new Size(28, 29); @@ -100,7 +100,7 @@ // // buttonMakeReport // - buttonMakeReport.BackColor = Color.FromArgb(192, 192, 255); + buttonMakeReport.BackColor = SystemColors.Control; buttonMakeReport.Location = new Point(22, 186); buttonMakeReport.Name = "buttonMakeReport"; buttonMakeReport.Size = new Size(347, 29); @@ -123,7 +123,7 @@ Controls.Add(label3); Controls.Add(label1); Name = "FormCountReport"; - Text = "FormCountReport"; + Text = "Отчет движения заказов"; ResumeLayout(false); PerformLayout(); } diff --git a/Publication/Forms/FormMaterial.Designer.cs b/Publication/Forms/FormMaterial.Designer.cs index 9d04f34..826ba97 100644 --- a/Publication/Forms/FormMaterial.Designer.cs +++ b/Publication/Forms/FormMaterial.Designer.cs @@ -125,7 +125,7 @@ Controls.Add(labelDateMaterials); Name = "FormMaterial"; StartPosition = FormStartPosition.CenterScreen; - Text = "FormMaterials"; + Text = "Материал"; ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); ResumeLayout(false); PerformLayout(); diff --git a/Publication/Forms/FormMaterials.Designer.cs b/Publication/Forms/FormMaterials.Designer.cs index b34b185..bfa8229 100644 --- a/Publication/Forms/FormMaterials.Designer.cs +++ b/Publication/Forms/FormMaterials.Designer.cs @@ -110,7 +110,7 @@ Controls.Add(panel1); Name = "FormMaterials"; StartPosition = FormStartPosition.CenterScreen; - Text = "FormMaterials"; + Text = "Материалы"; Load += FormMaterials_Load; panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); diff --git a/Publication/Forms/FormMaterials.resx b/Publication/Forms/FormMaterials.resx index 283b68e..36c1675 100644 --- a/Publication/Forms/FormMaterials.resx +++ b/Publication/Forms/FormMaterials.resx @@ -121,7 +121,7 @@ iVBORw0KGgoAAAANSUhEUgAABMYAAAOhCAIAAACSOT73AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAA/7JJREFUeF7svQeAHMWZ9j8zq7uzTdCKu++7/zmAnOMZgbN9ZwQ+R2xjbJ/D3Wcj + vQAADr0BR/uQrQAA/7JJREFUeF7svQeAHMWZ9j8zq7uzTdCKu++7/zmAnOMZgbN9ZwQ+R2xjbJ/D3Wcj 4WyMJZLDGRDBRzA52IANknAAmyTCrqTdVQZFUBYoaxVWWRuUpV3t7v8N3bU97+yqZ3p6Zmdmn0c/9db0 VFX3pK736aquTnRDEARBEARBEARBUCTBUkIQBEEQBEEQBEERBUsJQRAEQRAEQRAERRQsJQRBEARBEARB EBRRsJQQBEEQBEEQBEFQRMFSQhAEQRAEQRAEQREFSwlBEARBEARBEARFFCwlBEEQBEEQBEEQFFGwlBAE @@ -2360,7 +2360,7 @@ iVBORw0KGgoAAAANSUhEUgAAA+gAAAPoCAYAAABNo9TkAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAj - kwAAI5MB76VwKAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAALoxSURBVHhe7N13 + kgAAI5IBPeKSzAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAALoxSURBVHhe7N13 gBTl/cfxn70nsZvEksQkliTG3nvBXqLGEnvvvfeuKIgiKtWOoFQbiIqI2LGj9OOOdvTeQeT5fZ/ZnWNu 73vH3s7u7Dwz7z9e2b3PbtgF7mZ4e2X/zxgDAAAAAA1a9uST64vdxRniHvHKr08++aWY5HniiTFiuPhx 6RNPfCUGiPdE+6UtWlwrmvzSosXm2q8NIEMdAQAAAMC0bLnOspYtz5EY/1iYIIny5Z54ooYEeW0tWngk diff --git a/Publication/Forms/FormMaterialsDistributionReport.Designer.cs b/Publication/Forms/FormMaterialsDistributionReport.Designer.cs index 3d7af08..5225ef9 100644 --- a/Publication/Forms/FormMaterialsDistributionReport.Designer.cs +++ b/Publication/Forms/FormMaterialsDistributionReport.Designer.cs @@ -37,7 +37,7 @@ // // buttonSelectFileName // - buttonSelectFileName.BackColor = Color.FromArgb(192, 255, 192); + buttonSelectFileName.BackColor = SystemColors.Control; buttonSelectFileName.Location = new Point(12, 23); buttonSelectFileName.Name = "buttonSelectFileName"; buttonSelectFileName.Size = new Size(129, 29); @@ -73,7 +73,7 @@ // // buttonCreate // - buttonCreate.BackColor = Color.FromArgb(192, 255, 192); + buttonCreate.BackColor = SystemColors.Control; buttonCreate.Location = new Point(12, 146); buttonCreate.Name = "buttonCreate"; buttonCreate.Size = new Size(350, 29); @@ -93,7 +93,7 @@ Controls.Add(labelFileName); Controls.Add(buttonSelectFileName); Name = "FormMaterialsDistributionReport"; - Text = "FormInvoiceDistributionReport"; + Text = "Распределение материалов"; ResumeLayout(false); PerformLayout(); } diff --git a/Publication/Forms/FormOrder.Designer.cs b/Publication/Forms/FormOrder.Designer.cs index 636d726..98e1e49 100644 --- a/Publication/Forms/FormOrder.Designer.cs +++ b/Publication/Forms/FormOrder.Designer.cs @@ -127,7 +127,7 @@ Controls.Add(labelCustomer); Name = "FormOrder"; StartPosition = FormStartPosition.CenterScreen; - Text = "FormOrder"; + Text = "Заказ"; ResumeLayout(false); PerformLayout(); } diff --git a/Publication/Forms/FormOrders.Designer.cs b/Publication/Forms/FormOrders.Designer.cs index 3599e78..b984d99 100644 --- a/Publication/Forms/FormOrders.Designer.cs +++ b/Publication/Forms/FormOrders.Designer.cs @@ -84,7 +84,7 @@ Controls.Add(panel1); Name = "FormOrders"; StartPosition = FormStartPosition.CenterScreen; - Text = "FormOrders"; + Text = "Заказы"; Load += FormOrders_Load; panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); diff --git a/Publication/Forms/FormPrintingHouse.Designer.cs b/Publication/Forms/FormPrintingHouse.Designer.cs index a62e4e7..94391ca 100644 --- a/Publication/Forms/FormPrintingHouse.Designer.cs +++ b/Publication/Forms/FormPrintingHouse.Designer.cs @@ -189,7 +189,7 @@ Controls.Add(labelTitle); Name = "FormPrintingHouse"; StartPosition = FormStartPosition.CenterScreen; - Text = "FormPrintingHousecs"; + Text = "Печать"; groupBoxGridView.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); ResumeLayout(false); diff --git a/Publication/Forms/FormPrintingHouse.resx b/Publication/Forms/FormPrintingHouse.resx index 731849c..6f4b579 100644 --- a/Publication/Forms/FormPrintingHouse.resx +++ b/Publication/Forms/FormPrintingHouse.resx @@ -123,4 +123,10 @@ True + + True + + + True + \ No newline at end of file diff --git a/Publication/Forms/FormPrintingHouses.Designer.cs b/Publication/Forms/FormPrintingHouses.Designer.cs index 2295200..f0f0e4f 100644 --- a/Publication/Forms/FormPrintingHouses.Designer.cs +++ b/Publication/Forms/FormPrintingHouses.Designer.cs @@ -97,7 +97,7 @@ Controls.Add(panel1); Name = "FormPrintingHouses"; StartPosition = FormStartPosition.CenterScreen; - Text = "FormPrintingHouses"; + Text = "Печати"; Load += FormPrintingHouses_Load; panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); diff --git a/Publication/Forms/FormPublishingHouses.Designer.cs b/Publication/Forms/FormPublishingHouses.Designer.cs index 460a3ff..ad4594a 100644 --- a/Publication/Forms/FormPublishingHouses.Designer.cs +++ b/Publication/Forms/FormPublishingHouses.Designer.cs @@ -110,7 +110,7 @@ Controls.Add(panel1); Name = "FormPublishingHouses"; StartPosition = FormStartPosition.CenterScreen; - Text = "FormPublishingHouses"; + Text = "Издательства"; Load += FormPublishingHouses_Load; panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); -- 2.25.1 From e216a9884aae9c0e6cb0a49d484749c3f03ac6d0 Mon Sep 17 00:00:00 2001 From: Ctepa Date: Fri, 20 Dec 2024 13:36:31 +0400 Subject: [PATCH 8/9] =?UTF-8?q?=D0=BF=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Publication/Reports/TableReport.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Publication/Reports/TableReport.cs b/Publication/Reports/TableReport.cs index 21f71fc..69e62f1 100644 --- a/Publication/Reports/TableReport.cs +++ b/Publication/Reports/TableReport.cs @@ -14,7 +14,7 @@ public class TableReport private readonly IMaterialRepository _materialRepository; private readonly IPrintingHouseRepository _printingHouseRepository; private readonly ILogger _logger; - internal static readonly string[] item = ["Дата", "Количество пришло", "Количество ушло"]; + internal static readonly string[] item = ["Id","Дата", "Количество заказов пришло", "Количество заказов ушло"]; public TableReport(IPrintingHouseRepository printingHouseRepository, IMaterialRepository materialRepository, ILogger logger) { @@ -28,9 +28,9 @@ public class TableReport try { new ExcelBuilder(filePath) - .AddHeader("Сводка", 0, 4) + .AddHeader("Сводка заказов", 0, 4) .AddParagraph("за период", 0) - .AddTable([10, 15, 15], GetData(startDate, endDate)) + .AddTable([10, 10, 15, 15], GetData(startDate, endDate)) .Build(); return true; } @@ -46,19 +46,19 @@ public class TableReport var data = _printingHouseRepository .ReadPrintingHouses() .Where(x => x.Date >= startDate && x.Date <= endDate && x.printingHouseOrder.Any(y => y.PrintingHouseId == x.Id)) - .Select(x => new { x.Date, CountIn = (int?)null, CountOut = (int?)x.printingHouseOrder.First(y => y.PrintingHouseId == x.Id).Count }) + .Select(x => new {x.Id, x.Date, CountIn = (int?)null, CountOut = (int?)x.printingHouseOrder.First(y => y.PrintingHouseId == x.Id).Count }) .Union( _materialRepository .ReadMaterials() .Where(x => x.DateMaterials >= startDate && x.DateMaterials <= endDate) - .Select(x => new {Date = x.DateMaterials, CountIn = (int?)x.Count, CountOut = (int?)null })) + .Select(x => new {x.Id, Date = x.DateMaterials, CountIn = (int?)x.Count, CountOut = (int?)null })) .OrderBy(x => x.Date); return new List() { item } .Union( data - .Select(x => new string[] {x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) - .Union([["Всего", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]]) + .Select(x => new string[] {x.Id.ToString(), x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) + .Union([["", "Всего", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]]) .ToList(); } -- 2.25.1 From fee5958c8944ee6e88e72cec8267a6e9522a0a18 Mon Sep 17 00:00:00 2001 From: Ctepa Date: Fri, 20 Dec 2024 18:56:52 +0400 Subject: [PATCH 9/9] =?UTF-8?q?=D0=BD=D0=B0=D0=B4=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Publication/Forms/FormMaterial.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Publication/Forms/FormMaterial.cs b/Publication/Forms/FormMaterial.cs index 17adc78..55d2d3f 100644 --- a/Publication/Forms/FormMaterial.cs +++ b/Publication/Forms/FormMaterial.cs @@ -69,7 +69,7 @@ MessageBoxButtons.OK, MessageBoxIcon.Error); { try { - if (int.Parse(numericUpDownCount.Value.ToString()) <= 0 || dateTimePickerDateMaterial.Value.Date <= DateTime.Now || checkedListBox1.SelectedItems.Count == 0) + if (int.Parse(numericUpDownCount.Value.ToString()) <= 0 || dateTimePickerDateMaterial.Value.Date <= DateTime.Now || checkedListBox.SelectedItems.Count == 0) { throw new Exception("Имеются незаполненные поля"); } -- 2.25.1