From 0d89c1f0125ece27ae9718c3b158838f47a71fc9 Mon Sep 17 00:00:00 2001 From: nezui1 <104579567+nezui1@users.noreply.github.com> Date: Sun, 8 Dec 2024 21:14:15 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/AccessoiresOrder.cs | 6 +- .../ProjectCompRepair/Form1.Designer.cs | 32 +- ProjectCompRepair/ProjectCompRepair/Form1.cs | 16 +- .../Forms/FormDirectoryReport.Designer.cs | 99 ++++++ .../Forms/FormDirectoryReport.cs | 60 ++++ .../Forms/FormDirectoryReport.resx | 120 +++++++ .../ProjectCompRepair.csproj | 1 + .../ProjectCompRepair/Reports/DocReport.cs | 79 +++++ .../ProjectCompRepair/Reports/ExcelBuilder.cs | 317 ++++++++++++++++++ .../ProjectCompRepair/Reports/TableReport.cs | 66 ++++ .../ProjectCompRepair/Reports/WordBuilder.cs | 100 ++++++ ...rder.cs => IAccessoriesOrderRepository.cs} | 2 +- 12 files changed, 881 insertions(+), 17 deletions(-) create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.Designer.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.resx create mode 100644 ProjectCompRepair/ProjectCompRepair/Reports/DocReport.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Reports/ExcelBuilder.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Reports/WordBuilder.cs rename ProjectCompRepair/ProjectCompRepair/Repositories/{IAccessoriesOrder.cs => IAccessoriesOrderRepository.cs} (90%) diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs index 736c544..a0eed76 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs @@ -14,8 +14,10 @@ public class AccessoiresOrder public int Count { get; private set; } - public static AccessoiresOrder CreateElement(int id, int orderId, int count) + public DateTime Date { get; private set; } + + public static AccessoiresOrder CreateElement(int id, int orderId, int count, DateTime date) { - return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count}; + return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count, Date = DateTime.Now}; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs index ecf1c97..b521e9b 100644 --- a/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs @@ -36,6 +36,7 @@ операцииToolStripMenuItem = new ToolStripMenuItem(); OrderToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); + документСоСправочникамиToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -45,8 +46,7 @@ menuStrip.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Padding = new Padding(7, 3, 0, 3); - menuStrip.Size = new Size(896, 30); + menuStrip.Size = new Size(784, 24); menuStrip.TabIndex = 0; menuStrip.Text = "menuStrip1"; // @@ -54,27 +54,27 @@ // справочникToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AccossoriesToolStripMenuItem, MasterToolStripMenuItem, ServiceToolStripMenuItem }); справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; - справочникToolStripMenuItem.Size = new Size(117, 24); + справочникToolStripMenuItem.Size = new Size(94, 20); справочникToolStripMenuItem.Text = "Справочники"; // // AccossoriesToolStripMenuItem // AccossoriesToolStripMenuItem.Name = "AccossoriesToolStripMenuItem"; - AccossoriesToolStripMenuItem.Size = new Size(224, 26); + AccossoriesToolStripMenuItem.Size = new Size(180, 22); AccossoriesToolStripMenuItem.Text = "Комплектующие"; AccossoriesToolStripMenuItem.Click += AccossoriesToolStripMenuItem_Click; // // MasterToolStripMenuItem // MasterToolStripMenuItem.Name = "MasterToolStripMenuItem"; - MasterToolStripMenuItem.Size = new Size(224, 26); + MasterToolStripMenuItem.Size = new Size(180, 22); MasterToolStripMenuItem.Text = "Мастер"; MasterToolStripMenuItem.Click += MasterToolStripMenuItem_Click; // // ServiceToolStripMenuItem // ServiceToolStripMenuItem.Name = "ServiceToolStripMenuItem"; - ServiceToolStripMenuItem.Size = new Size(224, 26); + ServiceToolStripMenuItem.Size = new Size(180, 22); ServiceToolStripMenuItem.Text = "Услуга"; ServiceToolStripMenuItem.Click += ServiceToolStripMenuItem_Click; // @@ -82,32 +82,39 @@ // операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { OrderToolStripMenuItem }); операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; - операцииToolStripMenuItem.Size = new Size(95, 24); + операцииToolStripMenuItem.Size = new Size(75, 20); операцииToolStripMenuItem.Text = "Операции"; // // OrderToolStripMenuItem // OrderToolStripMenuItem.Name = "OrderToolStripMenuItem"; - OrderToolStripMenuItem.Size = new Size(224, 26); + OrderToolStripMenuItem.Size = new Size(104, 22); OrderToolStripMenuItem.Text = "Заказ"; OrderToolStripMenuItem.Click += OrderToolStripMenuItem_Click; // // отчетыToolStripMenuItem // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документСоСправочникамиToolStripMenuItem }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(73, 24); + отчетыToolStripMenuItem.Size = new Size(60, 20); отчетыToolStripMenuItem.Text = "Отчеты"; // + // документСоСправочникамиToolStripMenuItem + // + документСоСправочникамиToolStripMenuItem.Name = "документСоСправочникамиToolStripMenuItem"; + документСоСправочникамиToolStripMenuItem.Size = new Size(235, 22); + документСоСправочникамиToolStripMenuItem.Text = "Документ со справочниками"; + документСоСправочникамиToolStripMenuItem.Click += DirecotryReportToolStripMenuItem_Click; + // // FormCompRepair // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; BackgroundImage = Properties.Resources.morskie_kamni_raznocvetnaya_galka; BackgroundImageLayout = ImageLayout.Stretch; - ClientSize = new Size(896, 548); + ClientSize = new Size(784, 411); Controls.Add(menuStrip); MainMenuStrip = menuStrip; - Margin = new Padding(3, 4, 3, 4); Name = "FormCompRepair"; StartPosition = FormStartPosition.CenterScreen; Text = "Фирма по ремонту техники"; @@ -127,5 +134,6 @@ private ToolStripMenuItem OrderToolStripMenuItem; private ToolStripMenuItem MasterToolStripMenuItem; private ToolStripMenuItem ServiceToolStripMenuItem; + private ToolStripMenuItem документСоСправочникамиToolStripMenuItem; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Form1.cs b/ProjectCompRepair/ProjectCompRepair/Form1.cs index 98f10b1..f64837a 100644 --- a/ProjectCompRepair/ProjectCompRepair/Form1.cs +++ b/ProjectCompRepair/ProjectCompRepair/Form1.cs @@ -19,7 +19,7 @@ namespace ProjectCompRepair { _container.Resolve().ShowDialog(); } - catch(Exception ex) + catch (Exception ex) { MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -32,7 +32,7 @@ namespace ProjectCompRepair { _container.Resolve().ShowDialog(); } - catch(Exception ex) + catch (Exception ex) { MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -61,5 +61,17 @@ namespace ProjectCompRepair MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void DirecotryReportToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.Designer.cs new file mode 100644 index 0000000..9e28e8a --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.Designer.cs @@ -0,0 +1,99 @@ +namespace ProjectCompRepair.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() + { + checkBoxMasters = new CheckBox(); + checkBoxServices = new CheckBox(); + checkBoxAccessories = new CheckBox(); + buttonBuild = new Button(); + SuspendLayout(); + // + // checkBoxMasters + // + checkBoxMasters.AutoSize = true; + checkBoxMasters.Location = new Point(15, 24); + checkBoxMasters.Name = "checkBoxMasters"; + checkBoxMasters.Size = new Size(73, 19); + checkBoxMasters.TabIndex = 0; + checkBoxMasters.Text = "Мастера"; + checkBoxMasters.UseVisualStyleBackColor = true; + // + // checkBoxServices + // + checkBoxServices.AutoSize = true; + checkBoxServices.Location = new Point(15, 70); + checkBoxServices.Name = "checkBoxServices"; + checkBoxServices.Size = new Size(64, 19); + checkBoxServices.TabIndex = 1; + checkBoxServices.Text = "Услуги"; + checkBoxServices.UseVisualStyleBackColor = true; + // + // checkBoxAccessories + // + checkBoxAccessories.AutoSize = true; + checkBoxAccessories.Location = new Point(15, 118); + checkBoxAccessories.Name = "checkBoxAccessories"; + checkBoxAccessories.Size = new Size(120, 19); + checkBoxAccessories.TabIndex = 2; + checkBoxAccessories.Text = "Комплектующие"; + checkBoxAccessories.UseVisualStyleBackColor = true; + // + // buttonBuild + // + buttonBuild.Location = new Point(155, 66); + buttonBuild.Name = "buttonBuild"; + buttonBuild.Size = new Size(101, 23); + buttonBuild.TabIndex = 3; + buttonBuild.Text = "Сформировать"; + buttonBuild.UseVisualStyleBackColor = true; + buttonBuild.Click += ButtonBuild_Click; + // + // FormDirectoryReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(290, 166); + Controls.Add(buttonBuild); + Controls.Add(checkBoxAccessories); + Controls.Add(checkBoxServices); + Controls.Add(checkBoxMasters); + Name = "FormDirectoryReport"; + Text = "FormDirectoryReport"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckBox checkBoxMasters; + private CheckBox checkBoxServices; + private CheckBox checkBoxAccessories; + private Button buttonBuild; + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.cs new file mode 100644 index 0000000..fa7b015 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.cs @@ -0,0 +1,60 @@ +using ProjectCompRepair.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 ProjectCompRepair.Forms +{ + public partial class FormDirectoryReport : Form + { + private readonly IUnityContainer _container; + + public FormDirectoryReport(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + private void ButtonBuild_Click(object sender, EventArgs e) + { + try + { + if (!checkBoxMasters.Checked && !checkBoxServices.Checked && !checkBoxAccessories.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, checkBoxMasters.Checked, checkBoxServices.Checked, checkBoxAccessories.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/ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.resx b/ProjectCompRepair/ProjectCompRepair/Forms/FormDirectoryReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/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/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj b/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj index 0307ec6..7eadc6a 100644 --- a/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj +++ b/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj @@ -10,6 +10,7 @@ + diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/DocReport.cs b/ProjectCompRepair/ProjectCompRepair/Reports/DocReport.cs new file mode 100644 index 0000000..3905f59 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Reports/DocReport.cs @@ -0,0 +1,79 @@ +using Microsoft.Extensions.Logging; +using ProjectCompRepair.Repositories; +using ProjectCompRepair.Repositories.Implemantations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Reports; + +internal class DocReport +{ + private readonly IMasterRepository _masterRepository; + private readonly IServiceRepository _serviceRepository; + private readonly IAccessoriesRepository _accessoriesRepository; + private readonly ILogger _logger; + public DocReport(IMasterRepository masterRepository, IServiceRepository serviceRepository, IAccessoriesRepository accessoriesRepository, ILogger logger) + { + _masterRepository = masterRepository ?? + throw new ArgumentNullException(nameof(masterRepository)); + _serviceRepository = serviceRepository ?? + throw new ArgumentNullException(nameof(serviceRepository)); + _accessoriesRepository = accessoriesRepository ?? + throw new ArgumentNullException(nameof(accessoriesRepository)); + _logger = logger ?? + throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateDoc(string filePath, bool includeMaster, bool includeService, bool includeAccessories) + { + try + { + var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками"); + + if (includeMaster) + { + builder.AddParagraph("Мастера").AddTable([2400], GetMaster()); + } + if (includeService) + { + builder.AddParagraph("Услуги").AddTable([2400], GetService()); + } + if (includeAccessories) + { + builder.AddParagraph("Комплектующие").AddTable([2400], AccessoriesGet()); + } + + builder.Build(); + + return true; + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + private List GetMaster() + { + return [ + ["Имя мастера"], .. _masterRepository.ReadMaster().Select(x => new string[] {x.Name}), + ]; + } + private List GetService() + { + return [ + ["Тип услуги", "Цена"], .. _serviceRepository.ReadService().Select(x => new string[] {x.ServiceType.ToString(), x.Price.ToString()}), + ]; + } + private List AccessoriesGet() + { + return [ + ["Тип комплектующего", "Кол-во", "Цена"], .. _accessoriesRepository.ReadAccessories().Select + (x => new string[] {x.AccessoriesType.ToString(), x.Count.ToString(), x.Price.ToString()}) + ]; + } + +} diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/ExcelBuilder.cs b/ProjectCompRepair/ProjectCompRepair/Reports/ExcelBuilder.cs new file mode 100644 index 0000000..1a58bfa --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Reports/ExcelBuilder.cs @@ -0,0 +1,317 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Reports; + +internal 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.SimpleTextWithoutBorder); + for (int i = startIndex + 1; i < startIndex + count; ++i) + { + CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder); + } + _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.SimpleTextWithoutBorder); + } + _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.SimpleTextWithoutBorder); + } + _rowIndex++; + } + + for (var j = 0; j < data.Last().Length; ++j) + { + CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.SimpleTextWithoutBorder); + } + _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) } + }); + // TODO добавить шрифт с жирным + fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font + { + Bold = new Bold() { Val = true }, + FontSize = new FontSize() { Val = 11 }, + FontName = new FontName() { Val = "Calibri" }, + 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.Thin }, + RightBorder = new RightBorder { Style = BorderStyleValues.Thin }, + TopBorder = new TopBorder { Style = BorderStyleValues.Thin }, + BottomBorder = new BottomBorder { Style = BorderStyleValues.Thin }, + DiagonalBorder = new DiagonalBorder() + }); + 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 = 0, + FormatId = 0, + FontId = 0, + BorderId = 1, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Right, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 1, + BorderId = 0, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Center, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 1, + BorderId = 1, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Center, + 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/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs b/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs new file mode 100644 index 0000000..8d475cf --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs @@ -0,0 +1,66 @@ +using Microsoft.Extensions.Logging; +using ProjectCompRepair.Entities; +using ProjectCompRepair.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Reports; + +internal class TableReport +{ + private readonly IOrderRepository _orderRepository; + private readonly IAccessoriesOrderRepository _accessoriesOrdersRepository; + private readonly ILogger _logger; + + internal static readonly string[] item = ["Сотрудник", "Дата", "Тип комплектующего", "кол-во"]; + + public TableReport(IOrderRepository orderRepository, IAccessoriesOrderRepository accessoriesOrdersRepository, ILogger logger) + { + _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); + _accessoriesOrdersRepository = accessoriesOrdersRepository ?? throw new ArgumentNullException(nameof(accessoriesOrdersRepository)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateTable(string filePath, int accessoriesId, DateTime startDate, DateTime endDate) + { + try + { + new ExcelBuilder(filePath) + .AddHeader("Сводка по движению корма", 0, 4) + .AddParagraph("за период", 0) + .AddTable([10, 10, 15, 15], GetData(accessoriesId, startDate, endDate)) + .Build(); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List GetData(int accessoriesId, DateTime startDate, DateTime endDate) + { + var data = _feedReplenishmentRepository + .ReadFeedReplenishment() + .Where(x => x.DateReceipt >= startDate && x.DateReceipt <= endDate && x.FeedFeedReplenishments.Any(y => y.FeedId == feedId)) + .Select(x => new { x.EmployeeId, Date = x.DateReceipt, CountIn = x.FeedFeedReplenishments.FirstOrDefault(y => y.FeedId == feedId)?.Count, CountOut = (int?)null }) + .Union( + _feedingAnimalRepository + .ReadFeedingAnimals() + .Where(x => x.FeedingDate >= startDate && x.FeedingDate <= endDate && x.FeedId == feedId) + .Select(x => new { x.EmployeeId, Date = x.FeedingDate, CountIn = (int?)null, CountOut = (int?)x.Ration })) + .OrderBy(x => x.Date); + + return new List() { item } + .Union( + data + .Select(x => new string[] { x.EmployeeId.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(); + } +} diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/WordBuilder.cs b/ProjectCompRepair/ProjectCompRepair/Reports/WordBuilder.cs new file mode 100644 index 0000000..3699437 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Reports/WordBuilder.cs @@ -0,0 +1,100 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Metadata; +using System.Text; +using System.Threading.Tasks; +using Document = DocumentFormat.OpenXml.Wordprocessing.Document; + +namespace ProjectCompRepair.Reports; + +internal 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.AppendChild(new RunProperties(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; + + } +} diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/IAccessoriesOrder.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/IAccessoriesOrderRepository.cs similarity index 90% rename from ProjectCompRepair/ProjectCompRepair/Repositories/IAccessoriesOrder.cs rename to ProjectCompRepair/ProjectCompRepair/Repositories/IAccessoriesOrderRepository.cs index c7b61e5..bc6af51 100644 --- a/ProjectCompRepair/ProjectCompRepair/Repositories/IAccessoriesOrder.cs +++ b/ProjectCompRepair/ProjectCompRepair/Repositories/IAccessoriesOrderRepository.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace ProjectCompRepair.Repositories; -public interface IAccessoriesOrder +public interface IAccessoriesOrderRepository { void CreateAccessoriesOrder(AccessoiresOrder accessoriesOrder); -- 2.25.1 From a0db0595f10d43d135f0ca06b4e4c0c38d6f37b9 Mon Sep 17 00:00:00 2001 From: nezui1 <104579567+nezui1@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:56:16 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/AccessoiresOrder.cs | 6 +- .../ProjectCompRepair/Entities/Accessories.cs | 7 +- .../Forms/FormAccessorie.Designer.cs | 64 ++++++---- .../ProjectCompRepair/Forms/FormAccessorie.cs | 5 +- .../Forms/FormAccessoriesReport.Designer.cs | 39 ++++++ .../Forms/FormAccessoriesReport.cs | 75 +++++++++++ .../Forms/FormAccessoriesReport.resx | 120 ++++++++++++++++++ .../Forms/FormOrder.Designer.cs | 73 ++++++----- .../ProjectCompRepair.csproj | 1 + .../ProjectCompRepair/Reports/ChartReport.cs | 47 +++++++ .../ProjectCompRepair/Reports/PdfBuilder.cs | 87 +++++++++++++ .../ProjectCompRepair/Reports/TableReport.cs | 25 ++-- .../AccessoriesOrderRepository.cs | 12 ++ .../Implemantations/AccessoriesRepository.cs | 7 +- 14 files changed, 492 insertions(+), 76 deletions(-) create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.resx create mode 100644 ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Reports/PdfBuilder.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs index a0eed76..75972c4 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs @@ -14,10 +14,10 @@ public class AccessoiresOrder public int Count { get; private set; } - public DateTime Date { get; private set; } + - public static AccessoiresOrder CreateElement(int id, int orderId, int count, DateTime date) + public static AccessoiresOrder CreateElement(int id, int orderId, int count) { - return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count, Date = DateTime.Now}; + return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count}; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs b/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs index 230cfd5..382ccc8 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs @@ -17,14 +17,17 @@ public class Accessories public float Price { get; private set; } - public static Accessories CreateEntity(int id, AccessoriesType accessoriesType, int count, float price) + public DateTime Date { get; private set; } + + public static Accessories CreateEntity(int id, AccessoriesType accessoriesType, int count, float price, DateTime date) { return new Accessories { Id = id, AccessoriesType = accessoriesType, Count = count, - Price = price + Price = price, + Date = date }; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs index d9d5320..b51429f 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs @@ -28,6 +28,8 @@ buttonCreate = new Button(); buttonCancel = new Button(); comboBoxType = new ComboBox(); + labelDate = new Label(); + dateTimePickerAccessories = new DateTimePicker(); ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); SuspendLayout(); @@ -36,9 +38,9 @@ // labelType.Anchor = AnchorStyles.Right; labelType.AutoSize = true; - labelType.Location = new Point(54, 75); + labelType.Location = new Point(47, 56); labelType.Name = "labelType"; - labelType.Size = new Size(158, 20); + labelType.Size = new Size(128, 15); labelType.TabIndex = 0; labelType.Text = "Вид комплектующего"; // @@ -46,9 +48,9 @@ // labelCount.Anchor = AnchorStyles.Right; labelCount.AutoSize = true; - labelCount.Location = new Point(54, 152); + labelCount.Location = new Point(47, 114); labelCount.Name = "labelCount"; - labelCount.Size = new Size(98, 20); + labelCount.Size = new Size(79, 15); labelCount.TabIndex = 2; labelCount.Text = "Колличество"; // @@ -56,9 +58,9 @@ // labelPrice.Anchor = AnchorStyles.Right; labelPrice.AutoSize = true; - labelPrice.Location = new Point(54, 231); + labelPrice.Location = new Point(47, 173); labelPrice.Name = "labelPrice"; - labelPrice.Size = new Size(45, 20); + labelPrice.Size = new Size(35, 15); labelPrice.TabIndex = 4; labelPrice.Text = "Цена"; // @@ -66,29 +68,26 @@ // numericUpDownPrice.Anchor = AnchorStyles.Right; numericUpDownPrice.DecimalPlaces = 2; - numericUpDownPrice.Location = new Point(252, 235); - numericUpDownPrice.Margin = new Padding(3, 4, 3, 4); + numericUpDownPrice.Location = new Point(220, 176); numericUpDownPrice.Name = "numericUpDownPrice"; - numericUpDownPrice.Size = new Size(119, 27); + numericUpDownPrice.Size = new Size(104, 23); numericUpDownPrice.TabIndex = 5; // // numericUpDownCount // numericUpDownCount.Anchor = AnchorStyles.Right; - numericUpDownCount.Location = new Point(252, 156); - numericUpDownCount.Margin = new Padding(3, 4, 3, 4); + numericUpDownCount.Location = new Point(220, 117); numericUpDownCount.Name = "numericUpDownCount"; - numericUpDownCount.Size = new Size(119, 27); + numericUpDownCount.Size = new Size(104, 23); numericUpDownCount.TabIndex = 6; // // buttonCreate // buttonCreate.AllowDrop = true; buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(53, 417); - buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Location = new Point(46, 313); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(98, 33); + buttonCreate.Size = new Size(86, 25); buttonCreate.TabIndex = 8; buttonCreate.Text = "Сохранить"; buttonCreate.UseVisualStyleBackColor = true; @@ -97,10 +96,9 @@ // buttonCancel // buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(310, 416); - buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Location = new Point(271, 312); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(101, 31); + buttonCancel.Size = new Size(88, 23); buttonCancel.TabIndex = 10; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -109,19 +107,38 @@ // comboBoxType // comboBoxType.FormattingEnabled = true; - comboBoxType.Location = new Point(250, 78); + comboBoxType.Location = new Point(219, 58); + comboBoxType.Margin = new Padding(3, 2, 3, 2); comboBoxType.Name = "comboBoxType"; - comboBoxType.Size = new Size(151, 28); + comboBoxType.Size = new Size(133, 23); comboBoxType.TabIndex = 11; // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(47, 234); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(68, 15); + labelDate.TabIndex = 12; + labelDate.Text = "Поступили"; + // + // dateTimePickerAccessories + // + dateTimePickerAccessories.Location = new Point(220, 234); + dateTimePickerAccessories.Name = "dateTimePickerAccessories"; + dateTimePickerAccessories.Size = new Size(132, 23); + dateTimePickerAccessories.TabIndex = 13; + // // FormAccessorie // AllowDrop = true; - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; AutoSizeMode = AutoSizeMode.GrowAndShrink; AutoValidate = AutoValidate.EnableAllowFocusChange; - ClientSize = new Size(448, 478); + ClientSize = new Size(392, 358); + Controls.Add(dateTimePickerAccessories); + Controls.Add(labelDate); Controls.Add(comboBoxType); Controls.Add(buttonCancel); Controls.Add(buttonCreate); @@ -130,7 +147,6 @@ Controls.Add(labelPrice); Controls.Add(labelCount); Controls.Add(labelType); - Margin = new Padding(3, 4, 3, 4); Name = "FormAccessorie"; Text = "Комплектующое"; ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); @@ -150,5 +166,7 @@ private Button buttonUpdate; private Button buttonCancel; private ComboBox comboBoxType; + private Label labelDate; + private DateTimePicker dateTimePickerAccessories; } } \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs index 8e26b42..6372d92 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs @@ -31,7 +31,8 @@ namespace ProjectCompRepair.Forms { throw new InvalidOperationException(nameof(accessorie)); } - + + dateTimePickerAccessories.Value = accessorie.Date; numericUpDownCount.Value = accessorie.Count; numericUpDownPrice.Value = (int)accessorie.Price; _accessorieId = value; @@ -79,7 +80,7 @@ namespace ProjectCompRepair.Forms private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - private Accessories CreateAccessories(int id) => Accessories.CreateEntity(id, (AccessoriesType)comboBoxType.SelectedItem! , (int)numericUpDownCount.Value, (float)numericUpDownPrice.Value); + private Accessories CreateAccessories(int id) => Accessories.CreateEntity(id, (AccessoriesType)comboBoxType.SelectedItem! , (int)numericUpDownCount.Value, (float)numericUpDownPrice.Value, dateTimePickerAccessories.Value); } diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs new file mode 100644 index 0000000..52af124 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs @@ -0,0 +1,39 @@ +namespace ProjectCompRepair.Forms +{ + partial class FormAccessoriesReport + { + /// + /// 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() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "FormAccessoriesReport"; + } + + #endregion + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs new file mode 100644 index 0000000..5e0f881 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs @@ -0,0 +1,75 @@ +using ProjectCompRepair.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 ProjectCompRepair.Forms; + +public partial class FormAccessoriesReport : Form +{ + private readonly IUnityContainer _container; + public FormAccessoriesReport() + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + comboBoxFeed.DataSource = feedRepository.ReadFeeds(); + comboBoxFeed.DisplayMember = "Name"; + comboBoxFeed.ValueMember = "Id"; + + } + 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 (comboBoxFeed.SelectedIndex < 0) + { + throw new Exception("Не выбран корм"); + } + + if (dateTimePickerDateEnd.Value <= dateTimePickerDateBegin.Value) + { + throw new Exception("Дата начала должна быть раньше даты окончания"); + } + + if (_container.Resolve().CreateTable(textBoxFilePath.Text, (int)comboBoxFeed.SelectedValue!, dateTimePickerDateBegin.Value, dateTimePickerDateEnd.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/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.resx b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.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/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs index c53dc9e..a9110fd 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs @@ -55,74 +55,79 @@ // labelName // labelName.AutoSize = true; - labelName.Location = new Point(19, 35); + labelName.Location = new Point(17, 26); labelName.Name = "labelName"; - labelName.Size = new Size(77, 20); + labelName.Size = new Size(59, 15); labelName.TabIndex = 0; labelName.Text = "Название"; // // labelComent // labelComent.AutoSize = true; - labelComent.Location = new Point(19, 109); + labelComent.Location = new Point(17, 82); labelComent.Name = "labelComent"; - labelComent.Size = new Size(79, 20); + labelComent.Size = new Size(62, 15); labelComent.TabIndex = 1; labelComent.Text = "Описание"; // // textBoxComent // - textBoxComent.Location = new Point(208, 81); + textBoxComent.Location = new Point(182, 61); + textBoxComent.Margin = new Padding(3, 2, 3, 2); textBoxComent.Multiline = true; textBoxComent.Name = "textBoxComent"; - textBoxComent.Size = new Size(125, 72); + textBoxComent.Size = new Size(110, 55); textBoxComent.TabIndex = 2; // // textBoxName // - textBoxName.Location = new Point(208, 28); + textBoxName.Location = new Point(182, 21); + textBoxName.Margin = new Padding(3, 2, 3, 2); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(125, 27); + textBoxName.Size = new Size(110, 23); textBoxName.TabIndex = 3; // // labelDate // labelDate.AutoSize = true; - labelDate.Location = new Point(19, 192); + labelDate.Location = new Point(17, 144); labelDate.Name = "labelDate"; - labelDate.Size = new Size(183, 20); + labelDate.Size = new Size(142, 15); labelDate.TabIndex = 4; labelDate.Text = "Дата регистрации заказа"; // // dateTimePicker // - dateTimePicker.Location = new Point(208, 192); + dateTimePicker.Location = new Point(182, 144); + dateTimePicker.Margin = new Padding(3, 2, 3, 2); dateTimePicker.Name = "dateTimePicker"; - dateTimePicker.Size = new Size(192, 27); + dateTimePicker.Size = new Size(168, 23); dateTimePicker.TabIndex = 5; // // comboBoxMaster // comboBoxMaster.FormattingEnabled = true; - comboBoxMaster.Location = new Point(208, 254); + comboBoxMaster.Location = new Point(182, 190); + comboBoxMaster.Margin = new Padding(3, 2, 3, 2); comboBoxMaster.Name = "comboBoxMaster"; - comboBoxMaster.Size = new Size(151, 28); + comboBoxMaster.Size = new Size(133, 23); comboBoxMaster.TabIndex = 6; // // labelMaster // labelMaster.AutoSize = true; - labelMaster.Location = new Point(21, 262); + labelMaster.Location = new Point(18, 196); labelMaster.Name = "labelMaster"; - labelMaster.Size = new Size(60, 20); + labelMaster.Size = new Size(48, 15); labelMaster.TabIndex = 7; labelMaster.Text = "Мастер"; // // buttonSave // - buttonSave.Location = new Point(35, 389); + buttonSave.Location = new Point(31, 292); + buttonSave.Margin = new Padding(3, 2, 3, 2); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(94, 29); + buttonSave.Size = new Size(82, 22); buttonSave.TabIndex = 8; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; @@ -130,9 +135,10 @@ // // buttonCancel // - buttonCancel.Location = new Point(1077, 389); + buttonCancel.Location = new Point(942, 292); + buttonCancel.Margin = new Padding(3, 2, 3, 2); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(94, 29); + buttonCancel.Size = new Size(82, 22); buttonCancel.TabIndex = 9; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -141,9 +147,11 @@ // groupBox1 // groupBox1.Controls.Add(dataGridViewAccessories); - groupBox1.Location = new Point(449, 35); + groupBox1.Location = new Point(393, 26); + groupBox1.Margin = new Padding(3, 2, 3, 2); groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(309, 247); + groupBox1.Padding = new Padding(3, 2, 3, 2); + groupBox1.Size = new Size(270, 183); groupBox1.TabIndex = 10; groupBox1.TabStop = false; groupBox1.Text = "Комплектующие"; @@ -153,10 +161,11 @@ dataGridViewAccessories.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridViewAccessories.Columns.AddRange(new DataGridViewColumn[] { ColumnAccessories, ColumnCount }); dataGridViewAccessories.Dock = DockStyle.Fill; - dataGridViewAccessories.Location = new Point(3, 23); + dataGridViewAccessories.Location = new Point(3, 18); + dataGridViewAccessories.Margin = new Padding(3, 2, 3, 2); dataGridViewAccessories.Name = "dataGridViewAccessories"; dataGridViewAccessories.RowHeadersWidth = 51; - dataGridViewAccessories.Size = new Size(303, 221); + dataGridViewAccessories.Size = new Size(264, 163); dataGridViewAccessories.TabIndex = 0; // // ColumnAccessories @@ -176,9 +185,11 @@ // groupBoxServices // groupBoxServices.Controls.Add(dataGridViewServices); - groupBoxServices.Location = new Point(789, 35); + groupBoxServices.Location = new Point(690, 26); + groupBoxServices.Margin = new Padding(3, 2, 3, 2); groupBoxServices.Name = "groupBoxServices"; - groupBoxServices.Size = new Size(310, 247); + groupBoxServices.Padding = new Padding(3, 2, 3, 2); + groupBoxServices.Size = new Size(271, 185); groupBoxServices.TabIndex = 11; groupBoxServices.TabStop = false; groupBoxServices.Text = "Услуги"; @@ -188,10 +199,11 @@ dataGridViewServices.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridViewServices.Columns.AddRange(new DataGridViewColumn[] { ColumnService, ColumnCountServ }); dataGridViewServices.Dock = DockStyle.Fill; - dataGridViewServices.Location = new Point(3, 23); + dataGridViewServices.Location = new Point(3, 18); + dataGridViewServices.Margin = new Padding(3, 2, 3, 2); dataGridViewServices.Name = "dataGridViewServices"; dataGridViewServices.RowHeadersWidth = 51; - dataGridViewServices.Size = new Size(304, 221); + dataGridViewServices.Size = new Size(265, 165); dataGridViewServices.TabIndex = 0; // // ColumnService @@ -210,9 +222,9 @@ // // FormOrder // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1183, 430); + ClientSize = new Size(1035, 322); Controls.Add(groupBoxServices); Controls.Add(groupBox1); Controls.Add(buttonCancel); @@ -225,6 +237,7 @@ Controls.Add(textBoxComent); Controls.Add(labelComent); Controls.Add(labelName); + Margin = new Padding(3, 2, 3, 2); Name = "FormOrder"; Text = "Заказ"; groupBox1.ResumeLayout(false); diff --git a/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj b/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj index 7eadc6a..9c35c14 100644 --- a/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj +++ b/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj @@ -16,6 +16,7 @@ + diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs b/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs new file mode 100644 index 0000000..60c5226 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs @@ -0,0 +1,47 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Reports; + +internal class ChartReport +{ + private readonly IFeedingAnimalRepository _feedingAnimalRepository; + private readonly ILogger _logger; + + public ChartReport(IFeedingAnimalRepository feedingAnimalRepository, ILogger logger) + { + _feedingAnimalRepository = feedingAnimalRepository ?? throw new ArgumentNullException(nameof(feedingAnimalRepository)); + _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 _feedingAnimalRepository + .ReadFeedingAnimals() + .Where(x => x.FeedingDate.Date == dateTime.Date) + .GroupBy(x => x.AnimalId, (key, group) => new { Id = key, Count = group.Sum(x => x.Ration) }) + .Select(x => (x.Id.ToString(), (double)x.Count)) + .ToList(); + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/PdfBuilder.cs b/ProjectCompRepair/ProjectCompRepair/Reports/PdfBuilder.cs new file mode 100644 index 0000000..3e27b22 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Reports/PdfBuilder.cs @@ -0,0 +1,87 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Shapes.Charts; +using MigraDoc.Rendering; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Reports; + +internal 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() + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + + renderer.RenderDocument(); + renderer.PdfDocument.Save(_filePath); + } + + private void DefineStyles() + { + var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal"); + headerStyle.Font.Bold = true; + headerStyle.Font.Size = 14; + } +} diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs b/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs index 8d475cf..65a6828 100644 --- a/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs +++ b/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs @@ -12,15 +12,15 @@ namespace ProjectCompRepair.Reports; internal class TableReport { private readonly IOrderRepository _orderRepository; - private readonly IAccessoriesOrderRepository _accessoriesOrdersRepository; + private readonly IAccessoriesRepository _accessoriesRepository; private readonly ILogger _logger; - internal static readonly string[] item = ["Сотрудник", "Дата", "Тип комплектующего", "кол-во"]; + internal static readonly string[] item = ["Дата", "Тип комплектующего", "кол-во"]; - public TableReport(IOrderRepository orderRepository, IAccessoriesOrderRepository accessoriesOrdersRepository, ILogger logger) + public TableReport(IOrderRepository orderRepository, IAccessoriesRepository accessoriesRepository, ILogger logger) { _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); - _accessoriesOrdersRepository = accessoriesOrdersRepository ?? throw new ArgumentNullException(nameof(accessoriesOrdersRepository)); + _accessoriesRepository = accessoriesRepository ?? throw new ArgumentNullException(nameof(accessoriesRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } @@ -44,21 +44,20 @@ internal class TableReport private List GetData(int accessoriesId, DateTime startDate, DateTime endDate) { - var data = _feedReplenishmentRepository - .ReadFeedReplenishment() - .Where(x => x.DateReceipt >= startDate && x.DateReceipt <= endDate && x.FeedFeedReplenishments.Any(y => y.FeedId == feedId)) - .Select(x => new { x.EmployeeId, Date = x.DateReceipt, CountIn = x.FeedFeedReplenishments.FirstOrDefault(y => y.FeedId == feedId)?.Count, CountOut = (int?)null }) + var data = _orderRepository.ReadOrder() + .Where(x => x.Date >= startDate && x.Date <= endDate && x.AccessoiresOrders.Any(y => y.Id == accessoriesId)) + .Select(x => new {Date = x.Date, CountIn = x.AccessoiresOrders.FirstOrDefault(y => y.Id == accessoriesId)?.Count, CountOut = (int?)null }) .Union( - _feedingAnimalRepository - .ReadFeedingAnimals() - .Where(x => x.FeedingDate >= startDate && x.FeedingDate <= endDate && x.FeedId == feedId) - .Select(x => new { x.EmployeeId, Date = x.FeedingDate, CountIn = (int?)null, CountOut = (int?)x.Ration })) + _accessoriesRepository + .ReadAccessories() + .Where(x => x.Date >= startDate && x.Date <= endDate && x.Id == accessoriesId) + .Select(x => new {Date = x.Date, CountIn = (int?)null, CountOut = (int?)x.Count })) .OrderBy(x => x.Date); return new List() { item } .Union( data - .Select(x => new string[] { x.EmployeeId.ToString(), x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) + .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/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs new file mode 100644 index 0000000..0784b36 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Repositories.Implemantations; + +public class AccessoriesOrderRepository +{ + +} diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs index 6fbab98..aa3fbd4 100644 --- a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs +++ b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs @@ -35,8 +35,8 @@ public class AccessoriesRepository : IAccessoriesRepository connection.Open(); var queryInsert = @" -INSERT INTO Accessories (AccessoriesType, Count, Price) -VALUES (@AccessoriesType, @Count, @Price)"; +INSERT INTO Accessories (AccessoriesType, Count, Price, Date) +VALUES (@AccessoriesType, @Count, @Price, @Date)"; connection.Execute(queryInsert, accessories); } catch (Exception ex) @@ -58,7 +58,8 @@ VALUES (@AccessoriesType, @Count, @Price)"; SET AccessoriesType = @AccessoriesType, Count = @Count, - Price = @Price + Price = @Price, + Date = @Date WHERE ID = @Id;"; connection.Execute(queryUpdate, accessories); } -- 2.25.1 From 51d95da83bad82d17e0b82925993eea5449b6537 Mon Sep 17 00:00:00 2001 From: nezui1 <104579567+nezui1@users.noreply.github.com> Date: Mon, 9 Dec 2024 00:30:35 +0400 Subject: [PATCH 3/6] s --- .../Forms/FormAccessoriesReport.Designer.cs | 131 +++++++++++++++++- .../Forms/FormAccessoriesReport.cs | 13 +- .../Forms/FormAccessoriesReport.resx | 50 +++---- .../ProjectCompRepair/Reports/ChartReport.cs | 84 +++++------ 4 files changed, 201 insertions(+), 77 deletions(-) diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs index 52af124..38d455c 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs @@ -28,12 +28,135 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormAccessoriesReport"; + dateTimePickerDateEnd = new DateTimePicker(); + dateTimePickerDateBegin = new DateTimePicker(); + textBoxFilePath = new TextBox(); + buttonSelectFilePath = new Button(); + comboBoxAccessories = new ComboBox(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + buttonMakeReport = new Button(); + SuspendLayout(); + // + // dateTimePickerDateEnd + // + dateTimePickerDateEnd.Location = new Point(173, 232); + dateTimePickerDateEnd.Name = "dateTimePickerDateEnd"; + dateTimePickerDateEnd.Size = new Size(200, 23); + dateTimePickerDateEnd.TabIndex = 0; + // + // dateTimePickerDateBegin + // + dateTimePickerDateBegin.Location = new Point(173, 192); + dateTimePickerDateBegin.Name = "dateTimePickerDateBegin"; + dateTimePickerDateBegin.Size = new Size(200, 23); + dateTimePickerDateBegin.TabIndex = 1; + // + // textBoxFilePath + // + textBoxFilePath.Location = new Point(173, 81); + textBoxFilePath.Name = "textBoxFilePath"; + textBoxFilePath.Size = new Size(168, 23); + textBoxFilePath.TabIndex = 2; + // + // buttonSelectFilePath + // + buttonSelectFilePath.Location = new Point(347, 81); + buttonSelectFilePath.Name = "buttonSelectFilePath"; + buttonSelectFilePath.Size = new Size(26, 23); + buttonSelectFilePath.TabIndex = 3; + buttonSelectFilePath.Text = "button1"; + buttonSelectFilePath.UseVisualStyleBackColor = true; + buttonSelectFilePath.Click += ButtonSelectFilePath_Click; + // + // comboBoxAccessories + // + comboBoxAccessories.FormattingEnabled = true; + comboBoxAccessories.Location = new Point(173, 138); + comboBoxAccessories.Name = "comboBoxAccessories"; + comboBoxAccessories.Size = new Size(200, 23); + comboBoxAccessories.TabIndex = 4; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(60, 84); + label1.Name = "label1"; + label1.Size = new Size(38, 15); + label1.TabIndex = 5; + label1.Text = "label1"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(60, 141); + label2.Name = "label2"; + label2.Size = new Size(38, 15); + label2.TabIndex = 6; + label2.Text = "label2"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(60, 198); + label3.Name = "label3"; + label3.Size = new Size(38, 15); + label3.TabIndex = 7; + label3.Text = "label3"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(60, 238); + label4.Name = "label4"; + label4.Size = new Size(38, 15); + label4.TabIndex = 8; + label4.Text = "label4"; + // + // buttonMakeReport + // + buttonMakeReport.Location = new Point(153, 317); + buttonMakeReport.Name = "buttonMakeReport"; + buttonMakeReport.Size = new Size(75, 23); + buttonMakeReport.TabIndex = 9; + buttonMakeReport.Text = "button2"; + buttonMakeReport.UseVisualStyleBackColor = true; + buttonMakeReport.Click += ButtonMakeReport_Click; + // + // FormAccessoriesReport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonMakeReport); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(comboBoxAccessories); + Controls.Add(buttonSelectFilePath); + Controls.Add(textBoxFilePath); + Controls.Add(dateTimePickerDateBegin); + Controls.Add(dateTimePickerDateEnd); + Name = "FormAccessoriesReport"; + Text = "FormAccessoriesReport"; + ResumeLayout(false); + PerformLayout(); } #endregion + + private DateTimePicker dateTimePickerDateEnd; + private DateTimePicker dateTimePickerDateBegin; + private TextBox textBoxFilePath; + private Button buttonSelectFilePath; + private ComboBox comboBoxAccessories; + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private Button buttonMakeReport; } } \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs index 5e0f881..89e8a50 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs @@ -1,4 +1,5 @@ using ProjectCompRepair.Reports; +using ProjectCompRepair.Repositories; using System; using System.Collections.Generic; using System.ComponentModel; @@ -15,13 +16,13 @@ namespace ProjectCompRepair.Forms; public partial class FormAccessoriesReport : Form { private readonly IUnityContainer _container; - public FormAccessoriesReport() + public FormAccessoriesReport(IUnityContainer container, IAccessoriesRepository accessoriesRepository) { InitializeComponent(); _container = container ?? throw new ArgumentNullException(nameof(container)); - comboBoxFeed.DataSource = feedRepository.ReadFeeds(); - comboBoxFeed.DisplayMember = "Name"; - comboBoxFeed.ValueMember = "Id"; + comboBoxAccessories.DataSource = accessoriesRepository.ReadAccessories(); + comboBoxAccessories.DisplayMember = "Name"; + comboBoxAccessories.ValueMember = "Id"; } private void ButtonSelectFilePath_Click(object sender, EventArgs e) @@ -48,7 +49,7 @@ public partial class FormAccessoriesReport : Form throw new Exception("Отсутствует имя файла для отчета"); } - if (comboBoxFeed.SelectedIndex < 0) + if (comboBoxAccessories.SelectedIndex < 0) { throw new Exception("Не выбран корм"); } @@ -58,7 +59,7 @@ public partial class FormAccessoriesReport : Form throw new Exception("Дата начала должна быть раньше даты окончания"); } - if (_container.Resolve().CreateTable(textBoxFilePath.Text, (int)comboBoxFeed.SelectedValue!, dateTimePickerDateBegin.Value, dateTimePickerDateEnd.Value)) + if (_container.Resolve().CreateTable(textBoxFilePath.Text, (int)comboBoxAccessories.SelectedValue!, dateTimePickerDateBegin.Value, dateTimePickerDateEnd.Value)) { MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); } diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.resx b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.resx index 1af7de1..af32865 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.resx +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.resx @@ -1,17 +1,17 @@  - diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs b/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs index 60c5226..2fb579a 100644 --- a/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs +++ b/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs @@ -1,47 +1,47 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//using Microsoft.Extensions.Logging; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; -namespace ProjectCompRepair.Reports; +//namespace ProjectCompRepair.Reports; -internal class ChartReport -{ - private readonly IFeedingAnimalRepository _feedingAnimalRepository; - private readonly ILogger _logger; +//internal class ChartReport +//{ +// private readonly IFeedingAnimalRepository _feedingAnimalRepository; +// private readonly ILogger _logger; - public ChartReport(IFeedingAnimalRepository feedingAnimalRepository, ILogger logger) - { - _feedingAnimalRepository = feedingAnimalRepository ?? throw new ArgumentNullException(nameof(feedingAnimalRepository)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } +// public ChartReport(IFeedingAnimalRepository feedingAnimalRepository, ILogger logger) +// { +// _feedingAnimalRepository = feedingAnimalRepository ?? throw new ArgumentNullException(nameof(feedingAnimalRepository)); +// _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; - } - } +// 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 _feedingAnimalRepository - .ReadFeedingAnimals() - .Where(x => x.FeedingDate.Date == dateTime.Date) - .GroupBy(x => x.AnimalId, (key, group) => new { Id = key, Count = group.Sum(x => x.Ration) }) - .Select(x => (x.Id.ToString(), (double)x.Count)) - .ToList(); - } -} \ No newline at end of file +// private List<(string Caption, double Value)> GetData(DateTime dateTime) +// { +// return _feedingAnimalRepository +// .ReadFeedingAnimals() +// .Where(x => x.FeedingDate.Date == dateTime.Date) +// .GroupBy(x => x.AnimalId, (key, group) => new { Id = key, Count = group.Sum(x => x.Ration) }) +// .Select(x => (x.Id.ToString(), (double)x.Count)) +// .ToList(); +// } +//} \ No newline at end of file -- 2.25.1 From 70b60799dae1af07acf3a05535c0916c95856180 Mon Sep 17 00:00:00 2001 From: nezui1 Date: Mon, 9 Dec 2024 02:26:02 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BD=D0=B0=D0=B4=D0=BE=20=D0=BC=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20+=20=D0=BD=D0=B5=D0=BF=D0=BE=D0=BD=D1=8F=D1=82=D0=BD?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/AccessoiresOrder.cs | 2 +- .../ProjectCompRepair/Form1.Designer.cs | 35 +++-- ProjectCompRepair/ProjectCompRepair/Form1.cs | 12 ++ .../Forms/FormAccessoriesReport.Designer.cs | 51 ++++---- ...AccessorieslDistributionReport.Designer.cs | 45 +++++++ .../FormAccessorieslDistributionReport.cs | 20 +++ .../FormAccessorieslDistributionReport.resx | 120 ++++++++++++++++++ .../ProjectCompRepair/Reports/ChartReport.cs | 85 +++++++------ .../ProjectCompRepair/Reports/ExcelBuilder.cs | 8 +- .../ProjectCompRepair/Reports/TableReport.cs | 6 +- .../IAccessoriesOrderRepository.cs | 19 --- .../AccessoriesOrderRepository.cs | 12 -- 12 files changed, 300 insertions(+), 115 deletions(-) create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.Designer.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.resx delete mode 100644 ProjectCompRepair/ProjectCompRepair/Repositories/IAccessoriesOrderRepository.cs delete mode 100644 ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs index 75972c4..d5e9dff 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs @@ -18,6 +18,6 @@ public class AccessoiresOrder public static AccessoiresOrder CreateElement(int id, int orderId, int count) { - return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count}; + return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count }; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs index b521e9b..a8c5a12 100644 --- a/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs @@ -37,6 +37,7 @@ OrderToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); документСоСправочникамиToolStripMenuItem = new ToolStripMenuItem(); + excelToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -46,7 +47,8 @@ menuStrip.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(784, 24); + menuStrip.Padding = new Padding(7, 3, 0, 3); + menuStrip.Size = new Size(896, 30); menuStrip.TabIndex = 0; menuStrip.Text = "menuStrip1"; // @@ -54,27 +56,27 @@ // справочникToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AccossoriesToolStripMenuItem, MasterToolStripMenuItem, ServiceToolStripMenuItem }); справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; - справочникToolStripMenuItem.Size = new Size(94, 20); + справочникToolStripMenuItem.Size = new Size(117, 24); справочникToolStripMenuItem.Text = "Справочники"; // // AccossoriesToolStripMenuItem // AccossoriesToolStripMenuItem.Name = "AccossoriesToolStripMenuItem"; - AccossoriesToolStripMenuItem.Size = new Size(180, 22); + AccossoriesToolStripMenuItem.Size = new Size(207, 26); AccossoriesToolStripMenuItem.Text = "Комплектующие"; AccossoriesToolStripMenuItem.Click += AccossoriesToolStripMenuItem_Click; // // MasterToolStripMenuItem // MasterToolStripMenuItem.Name = "MasterToolStripMenuItem"; - MasterToolStripMenuItem.Size = new Size(180, 22); + MasterToolStripMenuItem.Size = new Size(207, 26); MasterToolStripMenuItem.Text = "Мастер"; MasterToolStripMenuItem.Click += MasterToolStripMenuItem_Click; // // ServiceToolStripMenuItem // ServiceToolStripMenuItem.Name = "ServiceToolStripMenuItem"; - ServiceToolStripMenuItem.Size = new Size(180, 22); + ServiceToolStripMenuItem.Size = new Size(207, 26); ServiceToolStripMenuItem.Text = "Услуга"; ServiceToolStripMenuItem.Click += ServiceToolStripMenuItem_Click; // @@ -82,39 +84,47 @@ // операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { OrderToolStripMenuItem }); операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; - операцииToolStripMenuItem.Size = new Size(75, 20); + операцииToolStripMenuItem.Size = new Size(95, 24); операцииToolStripMenuItem.Text = "Операции"; // // OrderToolStripMenuItem // OrderToolStripMenuItem.Name = "OrderToolStripMenuItem"; - OrderToolStripMenuItem.Size = new Size(104, 22); + OrderToolStripMenuItem.Size = new Size(130, 26); OrderToolStripMenuItem.Text = "Заказ"; OrderToolStripMenuItem.Click += OrderToolStripMenuItem_Click; // // отчетыToolStripMenuItem // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документСоСправочникамиToolStripMenuItem }); + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документСоСправочникамиToolStripMenuItem, excelToolStripMenuItem }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 20); + отчетыToolStripMenuItem.Size = new Size(73, 24); отчетыToolStripMenuItem.Text = "Отчеты"; // // документСоСправочникамиToolStripMenuItem // документСоСправочникамиToolStripMenuItem.Name = "документСоСправочникамиToolStripMenuItem"; - документСоСправочникамиToolStripMenuItem.Size = new Size(235, 22); + документСоСправочникамиToolStripMenuItem.Size = new Size(294, 26); документСоСправочникамиToolStripMenuItem.Text = "Документ со справочниками"; документСоСправочникамиToolStripMenuItem.Click += DirecotryReportToolStripMenuItem_Click; // + // excelToolStripMenuItem + // + excelToolStripMenuItem.Name = "excelToolStripMenuItem"; + excelToolStripMenuItem.Size = new Size(294, 26); + excelToolStripMenuItem.Text = "Excel"; + excelToolStripMenuItem.Click += excelToolStripMenuItem_Click; + // // FormCompRepair // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; BackgroundImage = Properties.Resources.morskie_kamni_raznocvetnaya_galka; BackgroundImageLayout = ImageLayout.Stretch; - ClientSize = new Size(784, 411); + ClientSize = new Size(896, 548); Controls.Add(menuStrip); MainMenuStrip = menuStrip; + Margin = new Padding(3, 4, 3, 4); Name = "FormCompRepair"; StartPosition = FormStartPosition.CenterScreen; Text = "Фирма по ремонту техники"; @@ -135,5 +145,6 @@ private ToolStripMenuItem MasterToolStripMenuItem; private ToolStripMenuItem ServiceToolStripMenuItem; private ToolStripMenuItem документСоСправочникамиToolStripMenuItem; + private ToolStripMenuItem excelToolStripMenuItem; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Form1.cs b/ProjectCompRepair/ProjectCompRepair/Form1.cs index f64837a..87dab1d 100644 --- a/ProjectCompRepair/ProjectCompRepair/Form1.cs +++ b/ProjectCompRepair/ProjectCompRepair/Form1.cs @@ -73,5 +73,17 @@ namespace ProjectCompRepair MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void excelToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs index 38d455c..13aa86a 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs @@ -42,30 +42,34 @@ // // dateTimePickerDateEnd // - dateTimePickerDateEnd.Location = new Point(173, 232); + dateTimePickerDateEnd.Location = new Point(198, 309); + dateTimePickerDateEnd.Margin = new Padding(3, 4, 3, 4); dateTimePickerDateEnd.Name = "dateTimePickerDateEnd"; - dateTimePickerDateEnd.Size = new Size(200, 23); + dateTimePickerDateEnd.Size = new Size(228, 27); dateTimePickerDateEnd.TabIndex = 0; // // dateTimePickerDateBegin // - dateTimePickerDateBegin.Location = new Point(173, 192); + dateTimePickerDateBegin.Location = new Point(198, 256); + dateTimePickerDateBegin.Margin = new Padding(3, 4, 3, 4); dateTimePickerDateBegin.Name = "dateTimePickerDateBegin"; - dateTimePickerDateBegin.Size = new Size(200, 23); + dateTimePickerDateBegin.Size = new Size(228, 27); dateTimePickerDateBegin.TabIndex = 1; // // textBoxFilePath // - textBoxFilePath.Location = new Point(173, 81); + textBoxFilePath.Location = new Point(198, 108); + textBoxFilePath.Margin = new Padding(3, 4, 3, 4); textBoxFilePath.Name = "textBoxFilePath"; - textBoxFilePath.Size = new Size(168, 23); + textBoxFilePath.Size = new Size(191, 27); textBoxFilePath.TabIndex = 2; // // buttonSelectFilePath // - buttonSelectFilePath.Location = new Point(347, 81); + buttonSelectFilePath.Location = new Point(397, 108); + buttonSelectFilePath.Margin = new Padding(3, 4, 3, 4); buttonSelectFilePath.Name = "buttonSelectFilePath"; - buttonSelectFilePath.Size = new Size(26, 23); + buttonSelectFilePath.Size = new Size(30, 31); buttonSelectFilePath.TabIndex = 3; buttonSelectFilePath.Text = "button1"; buttonSelectFilePath.UseVisualStyleBackColor = true; @@ -74,52 +78,54 @@ // comboBoxAccessories // comboBoxAccessories.FormattingEnabled = true; - comboBoxAccessories.Location = new Point(173, 138); + comboBoxAccessories.Location = new Point(198, 184); + comboBoxAccessories.Margin = new Padding(3, 4, 3, 4); comboBoxAccessories.Name = "comboBoxAccessories"; - comboBoxAccessories.Size = new Size(200, 23); + comboBoxAccessories.Size = new Size(228, 28); comboBoxAccessories.TabIndex = 4; // // label1 // label1.AutoSize = true; - label1.Location = new Point(60, 84); + label1.Location = new Point(69, 112); label1.Name = "label1"; - label1.Size = new Size(38, 15); + label1.Size = new Size(50, 20); label1.TabIndex = 5; label1.Text = "label1"; // // label2 // label2.AutoSize = true; - label2.Location = new Point(60, 141); + label2.Location = new Point(69, 188); label2.Name = "label2"; - label2.Size = new Size(38, 15); + label2.Size = new Size(50, 20); label2.TabIndex = 6; label2.Text = "label2"; // // label3 // label3.AutoSize = true; - label3.Location = new Point(60, 198); + label3.Location = new Point(69, 264); label3.Name = "label3"; - label3.Size = new Size(38, 15); + label3.Size = new Size(50, 20); label3.TabIndex = 7; label3.Text = "label3"; // // label4 // label4.AutoSize = true; - label4.Location = new Point(60, 238); + label4.Location = new Point(69, 317); label4.Name = "label4"; - label4.Size = new Size(38, 15); + label4.Size = new Size(50, 20); label4.TabIndex = 8; label4.Text = "label4"; // // buttonMakeReport // - buttonMakeReport.Location = new Point(153, 317); + buttonMakeReport.Location = new Point(175, 423); + buttonMakeReport.Margin = new Padding(3, 4, 3, 4); buttonMakeReport.Name = "buttonMakeReport"; - buttonMakeReport.Size = new Size(75, 23); + buttonMakeReport.Size = new Size(86, 31); buttonMakeReport.TabIndex = 9; buttonMakeReport.Text = "button2"; buttonMakeReport.UseVisualStyleBackColor = true; @@ -127,9 +133,9 @@ // // FormAccessoriesReport // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(535, 600); Controls.Add(buttonMakeReport); Controls.Add(label4); Controls.Add(label3); @@ -140,6 +146,7 @@ Controls.Add(textBoxFilePath); Controls.Add(dateTimePickerDateBegin); Controls.Add(dateTimePickerDateEnd); + Margin = new Padding(3, 4, 3, 4); Name = "FormAccessoriesReport"; Text = "FormAccessoriesReport"; ResumeLayout(false); diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.Designer.cs new file mode 100644 index 0000000..301cf1b --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.Designer.cs @@ -0,0 +1,45 @@ +namespace ProjectCompRepair.Forms +{ + partial class FormAccessorieslDistributionReport + { + /// + /// 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() + { + SuspendLayout(); + // + // FormAccessorieslDistributionReport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(432, 362); + Name = "FormAccessorieslDistributionReport"; + Text = "FormAccessorieslDistributionReport"; + ResumeLayout(false); + } + + #endregion + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.cs new file mode 100644 index 0000000..07222d6 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.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 ProjectCompRepair.Forms +{ + public partial class FormAccessorieslDistributionReport : Form + { + public FormAccessorieslDistributionReport() + { + InitializeComponent(); + } + } +} diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.resx b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.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/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs b/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs index 2fb579a..2a12711 100644 --- a/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs +++ b/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs @@ -1,47 +1,48 @@ -//using Microsoft.Extensions.Logging; -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using System.Text; -//using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using ProjectCompRepair.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -//namespace ProjectCompRepair.Reports; +namespace ProjectCompRepair.Reports; -//internal class ChartReport -//{ -// private readonly IFeedingAnimalRepository _feedingAnimalRepository; -// private readonly ILogger _logger; +internal class ChartReport +{ + private readonly IAccessoriesRepository _accessoriesRepository; + private readonly ILogger _logger; -// public ChartReport(IFeedingAnimalRepository feedingAnimalRepository, ILogger logger) -// { -// _feedingAnimalRepository = feedingAnimalRepository ?? throw new ArgumentNullException(nameof(feedingAnimalRepository)); -// _logger = logger ?? throw new ArgumentNullException(nameof(logger)); -// } + public ChartReport(IAccessoriesRepository accessoriesRepository, ILogger logger) + { + _accessoriesRepository = accessoriesRepository ?? throw new ArgumentNullException(nameof(accessoriesRepository)); + _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; -// } -// } + 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 _feedingAnimalRepository -// .ReadFeedingAnimals() -// .Where(x => x.FeedingDate.Date == dateTime.Date) -// .GroupBy(x => x.AnimalId, (key, group) => new { Id = key, Count = group.Sum(x => x.Ration) }) -// .Select(x => (x.Id.ToString(), (double)x.Count)) -// .ToList(); -// } -//} \ No newline at end of file + private List<(string Caption, double Value)> GetData(DateTime dateTime) + { + return _accessoriesRepository + .ReadAccessories() + .Where(x => x.Date.Date == dateTime.Date) + .GroupBy(x => x.Id, (key, group) => new { Id = key, Count = group.Sum(x => x.Count) }) + .Select(x => (x.Id.ToString(), (double)x.Count)) + .ToList(); + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/ExcelBuilder.cs b/ProjectCompRepair/ProjectCompRepair/Reports/ExcelBuilder.cs index 1a58bfa..fbdd2c3 100644 --- a/ProjectCompRepair/ProjectCompRepair/Reports/ExcelBuilder.cs +++ b/ProjectCompRepair/ProjectCompRepair/Reports/ExcelBuilder.cs @@ -63,10 +63,10 @@ internal class ExcelBuilder { throw new ArgumentNullException(nameof(data)); } - if (data.Any(x => x.Length != columnsWidths.Length)) - { - throw new InvalidOperationException("widths.Length != data.Length"); - } + //if (data.Any(x => x.Length != columnsWidths.Length)) + //{ + // throw new InvalidOperationException("widths.Length != data.Length"); + //} uint counter = 1; int coef = 2; diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs b/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs index 65a6828..35a8fb7 100644 --- a/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs +++ b/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs @@ -15,7 +15,7 @@ internal class TableReport private readonly IAccessoriesRepository _accessoriesRepository; private readonly ILogger _logger; - internal static readonly string[] item = ["Дата", "Тип комплектующего", "кол-во"]; + internal static readonly string[] item = ["Дата", "вход", "выход"]; public TableReport(IOrderRepository orderRepository, IAccessoriesRepository accessoriesRepository, ILogger logger) { @@ -31,7 +31,7 @@ internal class TableReport new ExcelBuilder(filePath) .AddHeader("Сводка по движению корма", 0, 4) .AddParagraph("за период", 0) - .AddTable([10, 10, 15, 15], GetData(accessoriesId, startDate, endDate)) + .AddTable([10, 15, 15], GetData(accessoriesId, startDate, endDate)) .Build(); return true; } @@ -45,7 +45,7 @@ internal class TableReport private List GetData(int accessoriesId, DateTime startDate, DateTime endDate) { var data = _orderRepository.ReadOrder() - .Where(x => x.Date >= startDate && x.Date <= endDate && x.AccessoiresOrders.Any(y => y.Id == accessoriesId)) + .Where(x => x.Date >= startDate && x.Date <= endDate && x.AccessoiresOrders.Any(y => y.Id == y.Id)) .Select(x => new {Date = x.Date, CountIn = x.AccessoiresOrders.FirstOrDefault(y => y.Id == accessoriesId)?.Count, CountOut = (int?)null }) .Union( _accessoriesRepository diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/IAccessoriesOrderRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/IAccessoriesOrderRepository.cs deleted file mode 100644 index bc6af51..0000000 --- a/ProjectCompRepair/ProjectCompRepair/Repositories/IAccessoriesOrderRepository.cs +++ /dev/null @@ -1,19 +0,0 @@ -using ProjectCompRepair.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectCompRepair.Repositories; - -public interface IAccessoriesOrderRepository -{ - void CreateAccessoriesOrder(AccessoiresOrder accessoriesOrder); - - void DeleteAccessoriesOrder(int id); - - IEnumerable ReadAccessoiresOrder(int? Id = 0, int? orderId = 0, int? count = 0); - - -} diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs deleted file mode 100644 index 0784b36..0000000 --- a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectCompRepair.Repositories.Implemantations; - -public class AccessoriesOrderRepository -{ - -} -- 2.25.1 From 56812e25df30d844772379bbc898378c0104119b Mon Sep 17 00:00:00 2001 From: maxim Date: Wed, 18 Dec 2024 03:09:10 +0400 Subject: [PATCH 5/6] =?UTF-8?q?80-90%=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/AccessoiresOrder.cs | 8 +- .../ProjectCompRepair/Entities/Order.cs | 14 ++ .../Entities/TempAccessoriesOrder.cs | 29 ++++ .../ProjectCompRepair/Form1.Designer.cs | 2 +- .../ProjectCompRepair/Form1.resx | 4 +- .../FormAccessoriesOrderReport.Designer.cs | 128 ++++++++++++++++++ .../Forms/FormAccessoriesOrderReport.cs | 78 +++++++++++ ...t.resx => FormAccessoriesOrderReport.resx} | 4 +- ...AccessorieslDistributionReport.Designer.cs | 45 ------ .../FormAccessorieslDistributionReport.cs | 20 --- .../ProjectCompRepair/Forms/FormOrder.cs | 8 +- .../ProjectCompRepair/Reports/ChartReport.cs | 26 ++-- .../ProjectCompRepair/Reports/ExcelBuilder.cs | 8 +- .../ProjectCompRepair/Reports/TableReport.cs | 12 +- .../Repositories/IOrderRepository.cs | 2 +- .../Implemantations/OrderRepository.cs | 30 ++-- 16 files changed, 307 insertions(+), 111 deletions(-) create mode 100644 ProjectCompRepair/ProjectCompRepair/Entities/TempAccessoriesOrder.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesOrderReport.Designer.cs create mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesOrderReport.cs rename ProjectCompRepair/ProjectCompRepair/Forms/{FormAccessorieslDistributionReport.resx => FormAccessoriesOrderReport.resx} (99%) delete mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.Designer.cs delete mode 100644 ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorieslDistributionReport.cs diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs index d5e9dff..c5ac8dc 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs @@ -8,16 +8,16 @@ namespace ProjectCompRepair.Entities; public class AccessoiresOrder { - public int Id { get; private set; } - public int OrderId { get; private set; } + public int AccessoriesId { get; private set; } + public int Count { get; private set; } - public static AccessoiresOrder CreateElement(int id, int orderId, int count) + public static AccessoiresOrder CreateElement(int orderId, int count, int accessoriesId) { - return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count }; + return new AccessoiresOrder { OrderId = orderId, Count = count, AccessoriesId = accessoriesId}; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/Order.cs b/ProjectCompRepair/ProjectCompRepair/Entities/Order.cs index 24de9bb..629c590 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/Order.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/Order.cs @@ -37,4 +37,18 @@ public class Order }; } + public static Order CreateElement(TempAccessoriesOrder tempAccessoriesOrder, IEnumerable accessoiresOrder) + { + return new Order + { + Id = tempAccessoriesOrder.Id, + Name = tempAccessoriesOrder.Name, + Coment = tempAccessoriesOrder.Coment, + Date = tempAccessoriesOrder.Date, + MasterID = tempAccessoriesOrder.MasterID, + AccessoiresOrders = accessoiresOrder, + ServicesOrders = tempAccessoriesOrder.ServicesOrders + + }; + } } diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/TempAccessoriesOrder.cs b/ProjectCompRepair/ProjectCompRepair/Entities/TempAccessoriesOrder.cs new file mode 100644 index 0000000..6f708be --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Entities/TempAccessoriesOrder.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Entities; + +public class TempAccessoriesOrder +{ + public int Id { get; private set; } + + public string Name { get; private set; } + + public string Coment { get; private set; } + + public DateTime Date { get; private set; } + + public int MasterID { get; private set; } + + public int AccessoriesId { get; private set; } + + public int Count { get; private set; } + + + public IEnumerable AccessoiresOrders { get; private set; } + + public IEnumerable ServicesOrders { get; private set; } +} diff --git a/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs index a8c5a12..30d66c2 100644 --- a/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs @@ -112,7 +112,7 @@ // excelToolStripMenuItem.Name = "excelToolStripMenuItem"; excelToolStripMenuItem.Size = new Size(294, 26); - excelToolStripMenuItem.Text = "Excel"; + excelToolStripMenuItem.Text = "Поток комплектующих"; excelToolStripMenuItem.Click += excelToolStripMenuItem_Click; // // FormCompRepair diff --git a/ProjectCompRepair/ProjectCompRepair/Form1.resx b/ProjectCompRepair/ProjectCompRepair/Form1.resx index 6c82d08..31084d5 100644 --- a/ProjectCompRepair/ProjectCompRepair/Form1.resx +++ b/ProjectCompRepair/ProjectCompRepair/Form1.resx @@ -1,7 +1,7 @@