This commit is contained in:
maxim 2024-12-18 14:20:40 +04:00
parent 56812e25df
commit 113be1af22
14 changed files with 150 additions and 101 deletions

View File

@ -18,6 +18,6 @@ public class AccessoiresOrder
public static AccessoiresOrder CreateElement(int orderId, int count, int accessoriesId)
{
return new AccessoiresOrder { OrderId = orderId, Count = count, AccessoriesId = accessoriesId};
return new AccessoiresOrder { OrderId = orderId, Count = count, AccessoriesId = accessoriesId };
}
}

View File

@ -38,6 +38,7 @@
отчетыToolStripMenuItem = new ToolStripMenuItem();
документСоСправочникамиToolStripMenuItem = new ToolStripMenuItem();
excelToolStripMenuItem = new ToolStripMenuItem();
TypeOfAccessoriesToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
SuspendLayout();
//
@ -96,7 +97,7 @@
//
// отчетыToolStripMenuItem
//
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документСоСправочникамиToolStripMenuItem, excelToolStripMenuItem });
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документСоСправочникамиToolStripMenuItem, excelToolStripMenuItem, TypeOfAccessoriesToolStripMenuItem });
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
отчетыToolStripMenuItem.Size = new Size(73, 24);
отчетыToolStripMenuItem.Text = "Отчеты";
@ -104,17 +105,24 @@
// документСоСправочникамиToolStripMenuItem
//
документСоСправочникамиToolStripMenuItem.Name = окументСоСправочникамиToolStripMenuItem";
документСоСправочникамиToolStripMenuItem.Size = new Size(294, 26);
документСоСправочникамиToolStripMenuItem.Size = new Size(348, 26);
документСоСправочникамиToolStripMenuItem.Text = "Документ со справочниками";
документСоСправочникамиToolStripMenuItem.Click += DirecotryReportToolStripMenuItem_Click;
//
// excelToolStripMenuItem
//
excelToolStripMenuItem.Name = "excelToolStripMenuItem";
excelToolStripMenuItem.Size = new Size(294, 26);
excelToolStripMenuItem.Size = new Size(348, 26);
excelToolStripMenuItem.Text = "Поток комплектующих";
excelToolStripMenuItem.Click += excelToolStripMenuItem_Click;
//
// TypeOfAccessoriesToolStripMenuItem
//
TypeOfAccessoriesToolStripMenuItem.Name = "TypeOfAccessoriesToolStripMenuItem";
TypeOfAccessoriesToolStripMenuItem.Size = new Size(348, 26);
TypeOfAccessoriesToolStripMenuItem.Text = "Отчет о потраченых комплектующих";
TypeOfAccessoriesToolStripMenuItem.Click += TypeOfAccessoriesToolStripMenuItem_Click_1;
//
// FormCompRepair
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -146,5 +154,6 @@
private ToolStripMenuItem ServiceToolStripMenuItem;
private ToolStripMenuItem документСоСправочникамиToolStripMenuItem;
private ToolStripMenuItem excelToolStripMenuItem;
private ToolStripMenuItem TypeOfAccessoriesToolStripMenuItem;
}
}

View File

@ -85,5 +85,18 @@ namespace ProjectCompRepair
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void TypeOfAccessoriesToolStripMenuItem_Click_1(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAccessoriesOrderReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -45,6 +45,7 @@
buttonSelectFileName.TabIndex = 0;
buttonSelectFileName.Text = "Выбрать";
buttonSelectFileName.UseVisualStyleBackColor = true;
buttonSelectFileName.Click += ButtonSelectFileName_Click;
//
// labelFileName
//
@ -73,12 +74,13 @@
//
// buttonCreate
//
buttonCreate.Location = new Point(136, 178);
buttonCreate.Location = new Point(178, 178);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(94, 29);
buttonCreate.Size = new Size(198, 29);
buttonCreate.TabIndex = 4;
buttonCreate.Text = "Сформировать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// comboBoxAccessories
//

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectCompRepair.Entities.Enums;
using ProjectCompRepair.Entities;
using ProjectCompRepair.Reports;
using ProjectCompRepair.Repositories;
using Unity;
@ -25,8 +25,10 @@ namespace ProjectCompRepair.Forms
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
comboBoxAccessories.DataSource = Enum.GetValues(typeof(AccessoriesType));
comboBoxAccessories.DataSource = accessoriesRepository.ReadAccessories();
comboBoxAccessories.ValueMember = "Id";
comboBoxAccessories.DisplayMember = "AccessoriesType";
}
private void ButtonSelectFileName_Click(object sender, EventArgs e)
@ -53,7 +55,7 @@ namespace ProjectCompRepair.Forms
}
if
(_container.Resolve<ChartReport>().CreateChart(_fileName, dateTimePicker.Value, (int)comboBoxAccessories.SelectedIndex!))
(_container.Resolve<ChartReport>().CreateChart(_fileName, dateTimePicker.Value, (int)comboBoxAccessories.SelectedValue!))
{
MessageBox.Show("Документ сформирован",
"Формирование документа",

View File

@ -33,10 +33,10 @@
textBoxFilePath = new TextBox();
buttonSelectFilePath = new Button();
comboBoxAccessories = new ComboBox();
label1 = new Label();
label2 = new Label();
label3 = new Label();
label4 = new Label();
labelFile = new Label();
labelNameAccessories = new Label();
labelBeginTime = new Label();
labelEndTime = new Label();
buttonMakeReport = new Button();
SuspendLayout();
//
@ -71,7 +71,7 @@
buttonSelectFilePath.Name = "buttonSelectFilePath";
buttonSelectFilePath.Size = new Size(30, 31);
buttonSelectFilePath.TabIndex = 3;
buttonSelectFilePath.Text = "button1";
buttonSelectFilePath.Text = "...";
buttonSelectFilePath.UseVisualStyleBackColor = true;
buttonSelectFilePath.Click += ButtonSelectFilePath_Click;
//
@ -84,50 +84,50 @@
comboBoxAccessories.Size = new Size(228, 28);
comboBoxAccessories.TabIndex = 4;
//
// label1
// labelFile
//
label1.AutoSize = true;
label1.Location = new Point(69, 112);
label1.Name = "label1";
label1.Size = new Size(50, 20);
label1.TabIndex = 5;
label1.Text = "label1";
labelFile.AutoSize = true;
labelFile.Location = new Point(69, 112);
labelFile.Name = "labelFile";
labelFile.Size = new Size(41, 20);
labelFile.TabIndex = 5;
labelFile.Text = "Путь";
//
// label2
// labelNameAccessories
//
label2.AutoSize = true;
label2.Location = new Point(69, 188);
label2.Name = "label2";
label2.Size = new Size(50, 20);
label2.TabIndex = 6;
label2.Text = "label2";
labelNameAccessories.AutoSize = true;
labelNameAccessories.Location = new Point(47, 187);
labelNameAccessories.Name = "labelNameAccessories";
labelNameAccessories.Size = new Size(145, 20);
labelNameAccessories.TabIndex = 6;
labelNameAccessories.Text = "id комплектующего";
//
// label3
// labelBeginTime
//
label3.AutoSize = true;
label3.Location = new Point(69, 264);
label3.Name = "label3";
label3.Size = new Size(50, 20);
label3.TabIndex = 7;
label3.Text = "label3";
labelBeginTime.AutoSize = true;
labelBeginTime.Location = new Point(47, 261);
labelBeginTime.Name = "labelBeginTime";
labelBeginTime.Size = new Size(134, 20);
labelBeginTime.TabIndex = 7;
labelBeginTime.Text = "Начальное время";
//
// label4
// labelEndTime
//
label4.AutoSize = true;
label4.Location = new Point(69, 317);
label4.Name = "label4";
label4.Size = new Size(50, 20);
label4.TabIndex = 8;
label4.Text = "label4";
labelEndTime.AutoSize = true;
labelEndTime.Location = new Point(47, 314);
labelEndTime.Name = "labelEndTime";
labelEndTime.Size = new Size(126, 20);
labelEndTime.TabIndex = 8;
labelEndTime.Text = "Конечное время";
//
// buttonMakeReport
//
buttonMakeReport.Location = new Point(175, 423);
buttonMakeReport.Margin = new Padding(3, 4, 3, 4);
buttonMakeReport.Name = "buttonMakeReport";
buttonMakeReport.Size = new Size(86, 31);
buttonMakeReport.Size = new Size(134, 31);
buttonMakeReport.TabIndex = 9;
buttonMakeReport.Text = "button2";
buttonMakeReport.Text = "Сформировать";
buttonMakeReport.UseVisualStyleBackColor = true;
buttonMakeReport.Click += ButtonMakeReport_Click;
//
@ -137,10 +137,10 @@
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(535, 600);
Controls.Add(buttonMakeReport);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(labelEndTime);
Controls.Add(labelBeginTime);
Controls.Add(labelNameAccessories);
Controls.Add(labelFile);
Controls.Add(comboBoxAccessories);
Controls.Add(buttonSelectFilePath);
Controls.Add(textBoxFilePath);
@ -160,10 +160,10 @@
private TextBox textBoxFilePath;
private Button buttonSelectFilePath;
private ComboBox comboBoxAccessories;
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private Label labelFile;
private Label labelNameAccessories;
private Label labelBeginTime;
private Label labelEndTime;
private Button buttonMakeReport;
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -7,6 +7,7 @@ using Unity;
using Microsoft.Extensions.Configuration;
using Unity.Microsoft.Logging;
using Unity.Lifetime;
using System.Text;
@ -24,6 +25,7 @@ namespace ProjectCompRepair
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(CreateContainer().Resolve<FormCompRepair>());
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
private static IUnityContainer CreateContainer()

View File

@ -2,6 +2,7 @@
using ProjectCompRepair.Entities;
using ProjectCompRepair.Repositories;
using ProjectCompRepair.Repositories.Implemantations;
using RegistrationOfPatients.Reports;
using System;
using System.Collections.Generic;
using System.Linq;
@ -42,7 +43,7 @@ internal class ChartReport
{
return _orderRepository
.ReadOrder()
.Where(x => x.Date.Date == dateTime.Date)
.Where(x => x.Date.Date == dateTime.Date && x.AccessoiresOrders.Any(y => y.AccessoriesId == accessoriesId))
.GroupBy(x => x.Id, (key, group) => new
{
Id = key,

View File

@ -39,11 +39,11 @@ internal class DocReport
}
if (includeService)
{
builder.AddParagraph("Услуги").AddTable([2400], GetService());
builder.AddParagraph("Услуги").AddTable([2400,2400], GetService());
}
if (includeAccessories)
{
builder.AddParagraph("Комплектующие").AddTable([2400], AccessoriesGet());
builder.AddParagraph("Комплектующие").AddTable([2400,2400,2400], AccessoriesGet());
}
builder.Build();

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCompRepair.Reports;
namespace RegistrationOfPatients.Reports;
internal class ExcelBuilder
{
@ -32,17 +32,20 @@ internal class ExcelBuilder
_columns = new Columns();
_rowIndex = 1;
}
public ExcelBuilder AddHeader(string header, int startIndex, int count)
{
CreateCell(startIndex, _rowIndex, header, StyleIndex.SimpleTextWithoutBorder);
CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithoutBorder);
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;
}
@ -59,10 +62,12 @@ internal class ExcelBuilder
{
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");
@ -77,28 +82,28 @@ internal class ExcelBuilder
Width = x * coef,
CustomWidth = true
}));
for (var j = 0; j < data.First().Length; ++j)
{
CreateCell(j, _rowIndex, data.First()[j], StyleIndex.SimpleTextWithoutBorder);
CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder);
}
_rowIndex++;
_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);
CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder);
}
_rowIndex++;
}
for (var j = 0; j < data.Last().Length; ++j)
{
CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.SimpleTextWithoutBorder);
CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder);
}
_rowIndex++;
_rowIndex++;
return this;
}
@ -110,13 +115,12 @@ internal class ExcelBuilder
workbookpart.Workbook = new Workbook();
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet();
if (_columns.HasChildren)
{
worksheetPart.Worksheet.Append(_columns);
}
worksheetPart.Worksheet.Append(_sheetData);
worksheetPart.Worksheet.Append(_sheetData);
var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets());
var sheet = new Sheet()
{
@ -124,11 +128,12 @@ internal class ExcelBuilder
SheetId = 1,
Name = "Лист 1"
};
sheets.Append(sheet);
sheets.Append(sheet);
if (_mergeCells.HasChildren)
{
worksheetPart.Worksheet.InsertAfter(_mergeCells, worksheetPart.Worksheet.Elements<SheetData>().First());
worksheetPart.Worksheet.InsertAfter(_mergeCells,
worksheetPart.Worksheet.Elements<SheetData>().First());
}
}
@ -137,18 +142,13 @@ internal class ExcelBuilder
var workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>();
workbookStylesPart.Stylesheet = new Stylesheet();
var fonts = new Fonts() { Count = 2, KnownFonts = BooleanValue.FromBoolean(true) };
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>(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 },
@ -157,18 +157,33 @@ internal class ExcelBuilder
Val = new EnumValue<FontSchemeValues>(FontSchemeValues.Minor)
}
});
// TODO добавить шрифт с жирным
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>(FontSchemeValues.Minor)
},
Bold = new Bold() { Val = true }
});
workbookStylesPart.Stylesheet.Append(fonts);
// Default Fill
// Default Fill
var fills = new Fills() { Count = 1 };
fills.Append(new Fill
{
PatternFill = new PatternFill() { PatternType = new EnumValue<PatternValues>(PatternValues.None) }
PatternFill = new PatternFill()
{
PatternType = new EnumValue<PatternValues>(PatternValues.None)
}
});
workbookStylesPart.Stylesheet.Append(fills);
// Default Border
// Default Border
var borders = new Borders() { Count = 2 };
borders.Append(new Border
{
@ -178,7 +193,7 @@ internal class ExcelBuilder
BottomBorder = new BottomBorder(),
DiagonalBorder = new DiagonalBorder()
});
// TODO добавить настройку с границами
borders.Append(new Border
{
LeftBorder = new LeftBorder { Style = BorderStyleValues.Thin },
@ -187,9 +202,10 @@ internal class ExcelBuilder
BottomBorder = new BottomBorder { Style = BorderStyleValues.Thin },
DiagonalBorder = new DiagonalBorder()
});
workbookStylesPart.Stylesheet.Append(borders);
// Default cell format and a date cell format
// Default cell format and a date cell format
var cellFormats = new CellFormats() { Count = 4 };
cellFormats.Append(new CellFormat
{
@ -205,7 +221,7 @@ internal class ExcelBuilder
WrapText = true
}
});
// TODO дополнить форматы
cellFormats.Append(new CellFormat
{
NumberFormatId = 0,
@ -248,12 +264,14 @@ internal class ExcelBuilder
WrapText = true
}
});
workbookStylesPart.Stylesheet.Append(cellFormats);
}
private enum StyleIndex
{
SimpleTextWithoutBorder = 0,
// TODO дополнить стили
SimpleTextWithBorder = 1,
BoldTextWithoutBorder = 2,
BoldTextWithBorder = 3,
@ -264,7 +282,6 @@ internal class ExcelBuilder
var columnName = GetExcelColumnName(columnIndex);
var cellReference = columnName + rowIndex;
var row = _sheetData.Elements<Row>().FirstOrDefault(r => r.RowIndex! == rowIndex);
if (row == null)
{
row = new Row() { RowIndex = rowIndex };
@ -273,7 +290,6 @@ internal class ExcelBuilder
var newCell = row.Elements<Cell>()
.FirstOrDefault(c => c.CellReference != null && c.CellReference.Value == columnName + rowIndex);
if (newCell == null)
{
Cell? refCell = null;
@ -313,5 +329,4 @@ internal class ExcelBuilder
return columnName;
}
}

View File

@ -7,25 +7,22 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCompRepair.Reports;
namespace RegistrationOfPatients.Reports;
internal class PdfBuilder
public class PdfBuilder
{
private readonly string _filePath;
private readonly Document _document;
public PdfBuilder(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new ArgumentNullException(nameof(filePath));
}
if (File.Exists(filePath))
{
File.Delete(filePath);
}
_filePath = filePath;
_document = new Document();
DefineStyles();
@ -36,7 +33,6 @@ internal class PdfBuilder
_document.AddSection().AddParagraph(header, "NormalBold");
return this;
}
public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data)
{
if (data == null || data.Count == 0)
@ -53,22 +49,30 @@ internal class PdfBuilder
chart.DataLabel.Type = DataLabelType.Percent;
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
chart.Width = Unit.FromCentimeter(16);
chart.Height = Unit.FromCentimeter(12);
chart.TopArea.AddParagraph(title);
chart.XAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.HasMajorGridlines = true;
chart.PlotArea.LineFormat.Width = 1;
chart.PlotArea.LineFormat.Visible = true;
chart.TopArea.AddLegend();
_document.LastSection.Add(chart);
return this;
}
public void Build()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
@ -77,11 +81,11 @@ internal class PdfBuilder
renderer.RenderDocument();
renderer.PdfDocument.Save(_filePath);
}
private void DefineStyles()
{
var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal");
headerStyle.Font.Bold = true;
headerStyle.Font.Size = 14;
var style = _document.Styles.AddStyle("NormalBold", "Normal");
style.Font.Bold = true;
style.Font.Size = 14;
style.ParagraphFormat.Alignment = ParagraphAlignment.Center;
}
}

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using ProjectCompRepair.Entities;
using ProjectCompRepair.Repositories;
using RegistrationOfPatients.Reports;
using System;
using System.Collections.Generic;
using System.Linq;

View File

@ -137,7 +137,7 @@ INNER JOIN AccessoriesOrder ao ON ao.OrderId = o.ID;";
_logger.LogDebug("Полученные объекты : {json}", JsonConvert.SerializeObject(order));
return order.GroupBy(x => x.Id, y => y,
(key, value) => Order.CreateElement(value.First(),
value.Select(z => AccessoiresOrder.CreateElement(0, z.AccessoriesId, z.Count)))).ToList();
value.Select(z => AccessoiresOrder.CreateElement(0, z.Count, z.AccessoriesId)))).ToList();
}
catch (Exception ex)
{