PIbd-22 Pyzhov E.A. LabWork03 #3
@ -20,4 +20,17 @@ public class Order
|
||||
OrderService = orderService
|
||||
};
|
||||
}
|
||||
|
||||
public static Order CreateOperation(TempOrder tempOrder, IEnumerable<OrderService> orderService)
|
||||
{
|
||||
return new Order
|
||||
{
|
||||
Id = tempOrder.Id,
|
||||
CompanyId = tempOrder.CompanyId,
|
||||
Date = tempOrder.Date,
|
||||
Price = tempOrder.Price,
|
||||
OrderService = orderService
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
12
ITServiceManager/ITServiceManager/Entities/TempOrder.cs
Normal file
12
ITServiceManager/ITServiceManager/Entities/TempOrder.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace ITServiceManager.Entities;
|
||||
|
||||
public class TempOrder
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int CompanyId { get; private set; }
|
||||
public int ServiceId { get; private set; }
|
||||
public DateTime Date { get; private set; }
|
||||
public decimal Price { get; private set; }
|
||||
public int Quantity { get; private set; }
|
||||
public DateTime ExecutionTime { get; private set; }
|
||||
}
|
@ -37,15 +37,20 @@
|
||||
заказыToolStripMenuItem = new ToolStripMenuItem();
|
||||
назначениеСотрудниковToolStripMenuItem = new ToolStripMenuItem();
|
||||
отчетыToolStripMenuItem = new ToolStripMenuItem();
|
||||
DocumentReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
TableReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
ChartReportToolStripMenuItem = new ToolStripMenuItem();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(784, 24);
|
||||
menuStrip1.Padding = new Padding(7, 3, 0, 3);
|
||||
menuStrip1.Size = new Size(896, 30);
|
||||
menuStrip1.TabIndex = 0;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
@ -53,27 +58,27 @@
|
||||
//
|
||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компанииToolStripMenuItem, сотрудникиToolStripMenuItem, услугиToolStripMenuItem });
|
||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||
справочникиToolStripMenuItem.Size = new Size(94, 20);
|
||||
справочникиToolStripMenuItem.Size = new Size(117, 24);
|
||||
справочникиToolStripMenuItem.Text = "Справочники";
|
||||
//
|
||||
// компанииToolStripMenuItem
|
||||
//
|
||||
компанииToolStripMenuItem.Name = "компанииToolStripMenuItem";
|
||||
компанииToolStripMenuItem.Size = new Size(180, 22);
|
||||
компанииToolStripMenuItem.Size = new Size(174, 26);
|
||||
компанииToolStripMenuItem.Text = "Компании";
|
||||
компанииToolStripMenuItem.Click += CompaniesToolStripMenuItem_Click;
|
||||
//
|
||||
// сотрудникиToolStripMenuItem
|
||||
//
|
||||
сотрудникиToolStripMenuItem.Name = "сотрудникиToolStripMenuItem";
|
||||
сотрудникиToolStripMenuItem.Size = new Size(180, 22);
|
||||
сотрудникиToolStripMenuItem.Size = new Size(174, 26);
|
||||
сотрудникиToolStripMenuItem.Text = "Сотрудники";
|
||||
сотрудникиToolStripMenuItem.Click += EmployeesToolStripMenuItem_Click;
|
||||
//
|
||||
// услугиToolStripMenuItem
|
||||
//
|
||||
услугиToolStripMenuItem.Name = "услугиToolStripMenuItem";
|
||||
услугиToolStripMenuItem.Size = new Size(180, 22);
|
||||
услугиToolStripMenuItem.Size = new Size(174, 26);
|
||||
услугиToolStripMenuItem.Text = "Услуги";
|
||||
услугиToolStripMenuItem.Click += ServicesToolStripMenuItem_Click;
|
||||
//
|
||||
@ -81,38 +86,61 @@
|
||||
//
|
||||
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заказыToolStripMenuItem, назначениеСотрудниковToolStripMenuItem });
|
||||
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
|
||||
операцииToolStripMenuItem.Size = new Size(75, 20);
|
||||
операцииToolStripMenuItem.Size = new Size(95, 24);
|
||||
операцииToolStripMenuItem.Text = "Операции";
|
||||
//
|
||||
// заказыToolStripMenuItem
|
||||
//
|
||||
заказыToolStripMenuItem.Name = "заказыToolStripMenuItem";
|
||||
заказыToolStripMenuItem.Size = new Size(213, 22);
|
||||
заказыToolStripMenuItem.Size = new Size(269, 26);
|
||||
заказыToolStripMenuItem.Text = "Заказы";
|
||||
заказыToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
|
||||
//
|
||||
// назначениеСотрудниковToolStripMenuItem
|
||||
//
|
||||
назначениеСотрудниковToolStripMenuItem.Name = "назначениеСотрудниковToolStripMenuItem";
|
||||
назначениеСотрудниковToolStripMenuItem.Size = new Size(213, 22);
|
||||
назначениеСотрудниковToolStripMenuItem.Size = new Size(269, 26);
|
||||
назначениеСотрудниковToolStripMenuItem.Text = "Назначение сотрудников";
|
||||
назначениеСотрудниковToolStripMenuItem.Click += AppointmentsToolStripMenuItem_Click;
|
||||
//
|
||||
// отчетыToolStripMenuItem
|
||||
//
|
||||
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DocumentReportToolStripMenuItem, TableReportToolStripMenuItem, ChartReportToolStripMenuItem });
|
||||
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
|
||||
отчетыToolStripMenuItem.Size = new Size(60, 20);
|
||||
отчетыToolStripMenuItem.Size = new Size(73, 24);
|
||||
отчетыToolStripMenuItem.Text = "Отчеты";
|
||||
//
|
||||
// DocumentReportToolStripMenuItem
|
||||
//
|
||||
DocumentReportToolStripMenuItem.Name = "DocumentReportToolStripMenuItem";
|
||||
DocumentReportToolStripMenuItem.Size = new Size(317, 26);
|
||||
DocumentReportToolStripMenuItem.Text = "Документ со справочниками";
|
||||
DocumentReportToolStripMenuItem.Click += DocumentReportToolStripMenuItem_Click;
|
||||
//
|
||||
// TableReportToolStripMenuItem
|
||||
//
|
||||
TableReportToolStripMenuItem.Name = "TableReportToolStripMenuItem";
|
||||
TableReportToolStripMenuItem.Size = new Size(317, 26);
|
||||
TableReportToolStripMenuItem.Text = "Отчёт по использованию услуги";
|
||||
TableReportToolStripMenuItem.Click += TableReportToolStripMenuItem_Click;
|
||||
//
|
||||
// ChartReportToolStripMenuItem
|
||||
//
|
||||
ChartReportToolStripMenuItem.Name = "ChartReportToolStripMenuItem";
|
||||
ChartReportToolStripMenuItem.Size = new Size(317, 26);
|
||||
ChartReportToolStripMenuItem.Text = "Учёт компаний";
|
||||
ChartReportToolStripMenuItem.Click += ChartReportToolStripMenuItem_Click;
|
||||
//
|
||||
// FormItCompany
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
BackgroundImage = Properties.Resources.company;
|
||||
BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ClientSize = new Size(784, 411);
|
||||
ClientSize = new Size(896, 548);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormItCompany";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "IT компания";
|
||||
@ -133,5 +161,8 @@
|
||||
private ToolStripMenuItem заказыToolStripMenuItem;
|
||||
private ToolStripMenuItem назначениеСотрудниковToolStripMenuItem;
|
||||
private ToolStripMenuItem отчетыToolStripMenuItem;
|
||||
private ToolStripMenuItem DocumentReportToolStripMenuItem;
|
||||
private ToolStripMenuItem TableReportToolStripMenuItem;
|
||||
private ToolStripMenuItem ChartReportToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using CarpentryWorkshop.Forms;
|
||||
using ITServiceManager.Forms;
|
||||
using Unity;
|
||||
|
||||
@ -72,5 +73,41 @@ namespace ITServiceManager
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void DocumentReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormDirectoryReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void TableReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormAppointmentReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ChartReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormCompaniesSpendingReport>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
168
ITServiceManager/ITServiceManager/Forms/FormAppointmentReport.Designer.cs
generated
Normal file
168
ITServiceManager/ITServiceManager/Forms/FormAppointmentReport.Designer.cs
generated
Normal file
@ -0,0 +1,168 @@
|
||||
namespace ITServiceManager.Forms
|
||||
{
|
||||
partial class FormAppointmentReport
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
labelFilePath = new Label();
|
||||
labelService = new Label();
|
||||
labelDateStart = new Label();
|
||||
labelDateEnd = new Label();
|
||||
comboBoxService = new ComboBox();
|
||||
dateTimePickerStart = new DateTimePicker();
|
||||
dateTimePickerEnd = new DateTimePicker();
|
||||
textBoxFilePath = new TextBox();
|
||||
buttonSelectFilePath = new Button();
|
||||
buttonMakeReport = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelFilePath
|
||||
//
|
||||
labelFilePath.AutoSize = true;
|
||||
labelFilePath.Location = new Point(24, 49);
|
||||
labelFilePath.Name = "labelFilePath";
|
||||
labelFilePath.Size = new Size(109, 20);
|
||||
labelFilePath.TabIndex = 1;
|
||||
labelFilePath.Text = "Путь до файла";
|
||||
//
|
||||
// labelService
|
||||
//
|
||||
labelService.AutoSize = true;
|
||||
labelService.Location = new Point(24, 129);
|
||||
labelService.Name = "labelService";
|
||||
labelService.Size = new Size(54, 20);
|
||||
labelService.TabIndex = 2;
|
||||
labelService.Text = "Услуга";
|
||||
//
|
||||
// labelDateStart
|
||||
//
|
||||
labelDateStart.AutoSize = true;
|
||||
labelDateStart.Location = new Point(24, 204);
|
||||
labelDateStart.Name = "labelDateStart";
|
||||
labelDateStart.Size = new Size(94, 20);
|
||||
labelDateStart.TabIndex = 3;
|
||||
labelDateStart.Text = "Дата начала";
|
||||
//
|
||||
// labelDateEnd
|
||||
//
|
||||
labelDateEnd.AutoSize = true;
|
||||
labelDateEnd.Location = new Point(24, 292);
|
||||
labelDateEnd.Name = "labelDateEnd";
|
||||
labelDateEnd.Size = new Size(87, 20);
|
||||
labelDateEnd.TabIndex = 4;
|
||||
labelDateEnd.Text = "Дата конца";
|
||||
//
|
||||
// comboBoxService
|
||||
//
|
||||
comboBoxService.FormattingEnabled = true;
|
||||
comboBoxService.Location = new Point(158, 129);
|
||||
comboBoxService.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxService.Name = "comboBoxService";
|
||||
comboBoxService.Size = new Size(138, 28);
|
||||
comboBoxService.TabIndex = 5;
|
||||
//
|
||||
// dateTimePickerStart
|
||||
//
|
||||
dateTimePickerStart.Location = new Point(158, 204);
|
||||
dateTimePickerStart.Margin = new Padding(3, 4, 3, 4);
|
||||
dateTimePickerStart.Name = "dateTimePickerStart";
|
||||
dateTimePickerStart.Size = new Size(228, 27);
|
||||
dateTimePickerStart.TabIndex = 6;
|
||||
//
|
||||
// dateTimePickerEnd
|
||||
//
|
||||
dateTimePickerEnd.Location = new Point(158, 281);
|
||||
dateTimePickerEnd.Margin = new Padding(3, 4, 3, 4);
|
||||
dateTimePickerEnd.Name = "dateTimePickerEnd";
|
||||
dateTimePickerEnd.Size = new Size(228, 27);
|
||||
dateTimePickerEnd.TabIndex = 7;
|
||||
//
|
||||
// textBoxFilePath
|
||||
//
|
||||
textBoxFilePath.Location = new Point(154, 51);
|
||||
textBoxFilePath.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxFilePath.Name = "textBoxFilePath";
|
||||
textBoxFilePath.Size = new Size(188, 27);
|
||||
textBoxFilePath.TabIndex = 8;
|
||||
//
|
||||
// buttonSelectFilePath
|
||||
//
|
||||
buttonSelectFilePath.Location = new Point(352, 51);
|
||||
buttonSelectFilePath.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonSelectFilePath.Name = "buttonSelectFilePath";
|
||||
buttonSelectFilePath.Size = new Size(34, 31);
|
||||
buttonSelectFilePath.TabIndex = 9;
|
||||
buttonSelectFilePath.UseVisualStyleBackColor = true;
|
||||
buttonSelectFilePath.Click += buttonSelectFilePath_Click;
|
||||
//
|
||||
// buttonMakeReport
|
||||
//
|
||||
buttonMakeReport.Location = new Point(24, 341);
|
||||
buttonMakeReport.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonMakeReport.Name = "buttonMakeReport";
|
||||
buttonMakeReport.Size = new Size(362, 31);
|
||||
buttonMakeReport.TabIndex = 10;
|
||||
buttonMakeReport.Text = "Сформировать";
|
||||
buttonMakeReport.UseVisualStyleBackColor = true;
|
||||
buttonMakeReport.Click += buttonMakeReport_Click;
|
||||
//
|
||||
// FormAppointmentReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(418, 387);
|
||||
Controls.Add(buttonMakeReport);
|
||||
Controls.Add(buttonSelectFilePath);
|
||||
Controls.Add(textBoxFilePath);
|
||||
Controls.Add(dateTimePickerEnd);
|
||||
Controls.Add(dateTimePickerStart);
|
||||
Controls.Add(comboBoxService);
|
||||
Controls.Add(labelDateEnd);
|
||||
Controls.Add(labelDateStart);
|
||||
Controls.Add(labelService);
|
||||
Controls.Add(labelFilePath);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormAppointmentReport";
|
||||
Text = "Сводка по использованию услуги";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelFilePath;
|
||||
private Label labelService;
|
||||
private Label labelDateStart;
|
||||
private Label labelDateEnd;
|
||||
private ComboBox comboBoxService;
|
||||
private DateTimePicker dateTimePickerStart;
|
||||
private DateTimePicker dateTimePickerEnd;
|
||||
private TextBox textBoxFilePath;
|
||||
private Button buttonSelectFilePath;
|
||||
private Button buttonMakeReport;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
using ITServiceManager.Reports;
|
||||
using ITServiceManager.Repositories;
|
||||
using Unity;
|
||||
|
||||
namespace ITServiceManager.Forms;
|
||||
|
||||
public partial class FormAppointmentReport : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
public FormAppointmentReport(IUnityContainer container, IServiceRepository serviceRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container;
|
||||
|
||||
comboBoxService.DataSource = serviceRepository.ReadServices();
|
||||
comboBoxService.DisplayMember = "Name";
|
||||
comboBoxService.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 (comboBoxService.SelectedIndex < 0)
|
||||
{
|
||||
throw new Exception("Не выбрана услуга");
|
||||
}
|
||||
if (dateTimePickerEnd.Value <= dateTimePickerStart.Value)
|
||||
{
|
||||
throw new Exception("Дата начала должна быть раньше даты окончания");
|
||||
}
|
||||
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, (int)comboBoxService.SelectedValue!,
|
||||
dateTimePickerStart.Value, dateTimePickerEnd.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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
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
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
111
ITServiceManager/ITServiceManager/Forms/FormCompaniesSpendingReport.Designer.cs
generated
Normal file
111
ITServiceManager/ITServiceManager/Forms/FormCompaniesSpendingReport.Designer.cs
generated
Normal file
@ -0,0 +1,111 @@
|
||||
namespace ITServiceManager.Forms
|
||||
{
|
||||
partial class FormCompaniesSpendingReport
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dateTimePicker = new DateTimePicker();
|
||||
labelFileName = new Label();
|
||||
buttonCreate = new Button();
|
||||
buttonSelectFileName = new Button();
|
||||
labelDate = new Label();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dateTimePicker
|
||||
//
|
||||
dateTimePicker.Location = new Point(119, 85);
|
||||
dateTimePicker.Margin = new Padding(3, 4, 3, 4);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(228, 27);
|
||||
dateTimePicker.TabIndex = 7;
|
||||
//
|
||||
// labelFileName
|
||||
//
|
||||
labelFileName.AutoSize = true;
|
||||
labelFileName.Location = new Point(119, 33);
|
||||
labelFileName.Name = "labelFileName";
|
||||
labelFileName.Size = new Size(45, 20);
|
||||
labelFileName.TabIndex = 8;
|
||||
labelFileName.Text = "Файл";
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(72, 141);
|
||||
buttonCreate.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(362, 31);
|
||||
buttonCreate.TabIndex = 11;
|
||||
buttonCreate.Text = "Сформировать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonSelectFileName
|
||||
//
|
||||
buttonSelectFileName.Location = new Point(14, 28);
|
||||
buttonSelectFileName.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonSelectFileName.Name = "buttonSelectFileName";
|
||||
buttonSelectFileName.Size = new Size(98, 31);
|
||||
buttonSelectFileName.TabIndex = 12;
|
||||
buttonSelectFileName.Text = "Выбрать";
|
||||
buttonSelectFileName.UseVisualStyleBackColor = true;
|
||||
buttonSelectFileName.Click += buttonSelectFileName_Click;
|
||||
//
|
||||
// labelDate
|
||||
//
|
||||
labelDate.AutoSize = true;
|
||||
labelDate.Location = new Point(41, 93);
|
||||
labelDate.Name = "labelDate";
|
||||
labelDate.Size = new Size(41, 20);
|
||||
labelDate.TabIndex = 13;
|
||||
labelDate.Text = "Дата";
|
||||
//
|
||||
// FormOrderDistibutionReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(509, 185);
|
||||
Controls.Add(labelDate);
|
||||
Controls.Add(buttonSelectFileName);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(labelFileName);
|
||||
Controls.Add(dateTimePicker);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormOrderDistibutionReport";
|
||||
Text = "Распределение услуг";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DateTimePicker dateTimePicker;
|
||||
private Label labelFileName;
|
||||
private Button buttonCreate;
|
||||
private Button buttonSelectFileName;
|
||||
private Label labelDate;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
using ITServiceManager.Reports;
|
||||
using Unity;
|
||||
|
||||
namespace ITServiceManager.Forms;
|
||||
|
||||
public partial class FormCompaniesSpendingReport : Form
|
||||
{
|
||||
private string _fileName = string.Empty;
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
public FormCompaniesSpendingReport(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
}
|
||||
|
||||
private void buttonSelectFileName_Click(object sender, EventArgs e)
|
||||
{
|
||||
var sfd = new SaveFileDialog()
|
||||
{
|
||||
Filter = "Pdf Files | *.pdf"
|
||||
};
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_fileName = sfd.FileName;
|
||||
labelFileName.Text = Path.GetFileName(_fileName);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_fileName))
|
||||
{
|
||||
throw new Exception("Отсутствует имя файла для отчета");
|
||||
}
|
||||
if (_container.Resolve<ChartReport>().CreateChart(_fileName, dateTimePicker.Value))
|
||||
{
|
||||
MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах", "Формирование документа",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при создании очета",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
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
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
104
ITServiceManager/ITServiceManager/Forms/FormDirectoryReport.Designer.cs
generated
Normal file
104
ITServiceManager/ITServiceManager/Forms/FormDirectoryReport.Designer.cs
generated
Normal file
@ -0,0 +1,104 @@
|
||||
namespace CarpentryWorkshop.Forms
|
||||
{
|
||||
partial class FormDirectoryReport
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonBuild = new Button();
|
||||
checkBoxCompanies = new CheckBox();
|
||||
checkBoxEmployees = new CheckBox();
|
||||
checkBoxServices = new CheckBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonBuild
|
||||
//
|
||||
buttonBuild.Location = new Point(185, 63);
|
||||
buttonBuild.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonBuild.Name = "buttonBuild";
|
||||
buttonBuild.Size = new Size(137, 31);
|
||||
buttonBuild.TabIndex = 0;
|
||||
buttonBuild.Text = "Сформировать";
|
||||
buttonBuild.UseVisualStyleBackColor = true;
|
||||
buttonBuild.Click += buttonBuild_Click;
|
||||
//
|
||||
// checkBoxCompanies
|
||||
//
|
||||
checkBoxCompanies.AutoSize = true;
|
||||
checkBoxCompanies.Location = new Point(43, 16);
|
||||
checkBoxCompanies.Margin = new Padding(3, 4, 3, 4);
|
||||
checkBoxCompanies.Name = "checkBoxCompanies";
|
||||
checkBoxCompanies.Size = new Size(104, 24);
|
||||
checkBoxCompanies.TabIndex = 1;
|
||||
checkBoxCompanies.Text = "Компании";
|
||||
checkBoxCompanies.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxEmployees
|
||||
//
|
||||
checkBoxEmployees.AutoSize = true;
|
||||
checkBoxEmployees.Location = new Point(43, 67);
|
||||
checkBoxEmployees.Margin = new Padding(3, 4, 3, 4);
|
||||
checkBoxEmployees.Name = "checkBoxEmployees";
|
||||
checkBoxEmployees.Size = new Size(113, 24);
|
||||
checkBoxEmployees.TabIndex = 2;
|
||||
checkBoxEmployees.Text = "Сотрудники";
|
||||
checkBoxEmployees.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxServices
|
||||
//
|
||||
checkBoxServices.AutoSize = true;
|
||||
checkBoxServices.Location = new Point(43, 123);
|
||||
checkBoxServices.Margin = new Padding(3, 4, 3, 4);
|
||||
checkBoxServices.Name = "checkBoxServices";
|
||||
checkBoxServices.Size = new Size(77, 24);
|
||||
checkBoxServices.TabIndex = 3;
|
||||
checkBoxServices.Text = "Услуги";
|
||||
checkBoxServices.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormDirectoryReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(334, 164);
|
||||
Controls.Add(checkBoxServices);
|
||||
Controls.Add(checkBoxEmployees);
|
||||
Controls.Add(checkBoxCompanies);
|
||||
Controls.Add(buttonBuild);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormDirectoryReport";
|
||||
Text = "FormDirectotyReport";
|
||||
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonBuild;
|
||||
private CheckBox checkBoxCompanies;
|
||||
private CheckBox checkBoxEmployees;
|
||||
private CheckBox checkBoxServices;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
using ITServiceManager.Reports;
|
||||
using Unity;
|
||||
|
||||
namespace CarpentryWorkshop.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 (!checkBoxCompanies.Checked && !checkBoxEmployees.Checked && !checkBoxServices.Checked)
|
||||
{
|
||||
throw new Exception("Не выбран ни один справочник для выгрузки");
|
||||
}
|
||||
|
||||
var sfd = new SaveFileDialog()
|
||||
{
|
||||
Filter = "Docx Files | *.docx"
|
||||
};
|
||||
|
||||
if (sfd.ShowDialog() != DialogResult.OK)
|
||||
{
|
||||
throw new Exception("Не выбран файла для отчета");
|
||||
}
|
||||
|
||||
if (_container.Resolve<DocReport>().CreateDoc(sfd.FileName, checkBoxCompanies.Checked, checkBoxEmployees.Checked, checkBoxServices.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
ITServiceManager/ITServiceManager/Forms/FormDirectoryReport.resx
Normal file
120
ITServiceManager/ITServiceManager/Forms/FormDirectoryReport.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
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
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -11,11 +11,13 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="8.0.5" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
|
60
ITServiceManager/ITServiceManager/Reports/ChartReport.cs
Normal file
60
ITServiceManager/ITServiceManager/Reports/ChartReport.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using ITServiceManager.Repositories;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ITServiceManager.Reports;
|
||||
|
||||
public class ChartReport
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly ICompanyRepository _companyRepository;
|
||||
private readonly ILogger<ChartReport> _logger;
|
||||
|
||||
public ChartReport(IOrderRepository orderRepository, ICompanyRepository companyRepository, ILogger<ChartReport> logger)
|
||||
{
|
||||
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
||||
_companyRepository = companyRepository ?? throw new ArgumentNullException(nameof(companyRepository));
|
||||
_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)
|
||||
{
|
||||
var orders = _orderRepository
|
||||
.ReadOrders()
|
||||
.Where(order => order.Date.Date == dateTime.Date)
|
||||
.ToList();
|
||||
|
||||
var groupedOrders = orders
|
||||
.GroupBy(order => order.CompanyId)
|
||||
.Select(group => new
|
||||
{
|
||||
CompanyId = group.Key,
|
||||
TotalSpent = group.Sum(order => (double)order.Price)
|
||||
});
|
||||
|
||||
return groupedOrders
|
||||
.Select(group =>
|
||||
{
|
||||
var company = _companyRepository.ReadCompanyById(group.CompanyId);
|
||||
return (Caption: company.Name, Value: group.TotalSpent);
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
}
|
78
ITServiceManager/ITServiceManager/Reports/DocReport.cs
Normal file
78
ITServiceManager/ITServiceManager/Reports/DocReport.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using ITServiceManager.Repositories;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ITServiceManager.Reports;
|
||||
|
||||
public class DocReport
|
||||
{
|
||||
private readonly ICompanyRepository _companyRepository;
|
||||
private readonly IServiceRepository _serviceRepository;
|
||||
private readonly IEmployeeRepository _employeeRepository;
|
||||
|
||||
private readonly ILogger<DocReport> _logger;
|
||||
|
||||
public DocReport(ICompanyRepository companyRepository, IServiceRepository serviceRepository, IEmployeeRepository employeeRepository, ILogger<DocReport> logger)
|
||||
{
|
||||
_companyRepository = companyRepository ?? throw new ArgumentNullException(nameof(companyRepository));
|
||||
_serviceRepository = serviceRepository ?? throw new ArgumentNullException(nameof(serviceRepository));
|
||||
_employeeRepository = employeeRepository ?? throw new ArgumentNullException(nameof(employeeRepository));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public bool CreateDoc(string filePath, bool includeCompanies, bool includeServices, bool includeEmployees)
|
||||
{
|
||||
try
|
||||
{
|
||||
var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками");
|
||||
if (includeCompanies)
|
||||
{
|
||||
builder.AddParagraph("Компании").AddTable([2400, 2400], GetCompanies());
|
||||
}
|
||||
if (includeServices)
|
||||
{
|
||||
builder.AddParagraph("Услуги").AddTable([2400, 2400, 2400], GetServices());
|
||||
}
|
||||
if (includeEmployees)
|
||||
{
|
||||
builder.AddParagraph("Сотрудники").AddTable([2400, 2400, 2400], GetEmployees());
|
||||
}
|
||||
builder.Build();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<string[]> GetCompanies()
|
||||
{
|
||||
return [
|
||||
["Название", "Адресс"],
|
||||
.. _companyRepository
|
||||
.ReadCompanies()
|
||||
.Select(x => new string[] { x.Name, x.Address.ToString()}),
|
||||
];
|
||||
}
|
||||
|
||||
private List<string[]> GetEmployees()
|
||||
{
|
||||
return [
|
||||
["Имя", "Фамилия", "Должность"],
|
||||
.. _employeeRepository
|
||||
.ReadEmployees()
|
||||
.Select(x => new string[] { x.FirstName, x.LastName, x.Position.ToString() }),
|
||||
];
|
||||
}
|
||||
|
||||
private List<string[]> GetServices()
|
||||
{
|
||||
return [
|
||||
["Название услуги", "Тип услуги", "Описание"],
|
||||
.. _serviceRepository
|
||||
.ReadServices()
|
||||
.Select(x => new string[] {x.ServiceName, x.ServiceType.ToString(), x.Description }),
|
||||
];
|
||||
}
|
||||
}
|
311
ITServiceManager/ITServiceManager/Reports/ExcelBuilder.cs
Normal file
311
ITServiceManager/ITServiceManager/Reports/ExcelBuilder.cs
Normal file
@ -0,0 +1,311 @@
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml;
|
||||
|
||||
namespace ITServiceManager.Reports;
|
||||
|
||||
public class ExcelBuilder
|
||||
{
|
||||
private readonly string _filePath;
|
||||
private readonly SheetData _sheetData;
|
||||
private readonly MergeCells _mergeCells;
|
||||
private readonly Columns _columns;
|
||||
private uint _rowIndex = 0;
|
||||
|
||||
public ExcelBuilder(string filePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(filePath));
|
||||
}
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
_filePath = filePath;
|
||||
_sheetData = new SheetData();
|
||||
_mergeCells = new MergeCells();
|
||||
_columns = new Columns();
|
||||
_rowIndex = 1;
|
||||
}
|
||||
|
||||
public ExcelBuilder AddHeader(string header, int startIndex, int count)
|
||||
{
|
||||
CreateCell(startIndex, _rowIndex, header, StyleIndex.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;
|
||||
}
|
||||
|
||||
public ExcelBuilder AddParagraph(string text, int columnIndex)
|
||||
{
|
||||
CreateCell(columnIndex, _rowIndex++, text, StyleIndex.SimpleTextWithoutBorder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExcelBuilder AddTable(int[] columnsWidths, List<string[]> data)
|
||||
{
|
||||
if (columnsWidths == null || columnsWidths.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(columnsWidths));
|
||||
}
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.Any(x => x.Length != columnsWidths.Length))
|
||||
{
|
||||
throw new InvalidOperationException("widths.Length != data.Length");
|
||||
}
|
||||
|
||||
uint counter = 1;
|
||||
int coef = 2;
|
||||
_columns.Append(columnsWidths.Select(x => new Column
|
||||
{
|
||||
Min = counter,
|
||||
Max = counter++,
|
||||
Width = x * coef,
|
||||
CustomWidth = true
|
||||
}));
|
||||
for (var j = 0; j < data.First().Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder);
|
||||
}
|
||||
_rowIndex++;
|
||||
|
||||
for (var i = 1; i < data.Count - 1; ++i)
|
||||
{
|
||||
for (var j = 0; j < data[i].Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder);
|
||||
}
|
||||
_rowIndex++;
|
||||
}
|
||||
for (var j = 0; j < data.Last().Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder);
|
||||
}
|
||||
_rowIndex++;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Build()
|
||||
{
|
||||
using var spreadsheetDocument = SpreadsheetDocument.Create(_filePath, SpreadsheetDocumentType.Workbook);
|
||||
var workbookpart = spreadsheetDocument.AddWorkbookPart();
|
||||
GenerateStyle(workbookpart);
|
||||
workbookpart.Workbook = new Workbook();
|
||||
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
|
||||
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<SheetData>().First());
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateStyle(WorkbookPart workbookPart)
|
||||
{
|
||||
var workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>();
|
||||
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>(FontSchemeValues.Minor)
|
||||
}
|
||||
});
|
||||
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
|
||||
var fills = new Fills() { Count = 1 };
|
||||
fills.Append(new Fill
|
||||
{
|
||||
PatternFill = new PatternFill()
|
||||
{
|
||||
PatternType = new EnumValue<PatternValues>(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<Row>().FirstOrDefault(r => r.RowIndex! == rowIndex);
|
||||
if (row == null)
|
||||
{
|
||||
row = new Row() { RowIndex = rowIndex };
|
||||
_sheetData.Append(row);
|
||||
}
|
||||
var newCell = row.Elements<Cell>().FirstOrDefault(c => c.CellReference != null &&
|
||||
c.CellReference.Value == columnName + rowIndex);
|
||||
if (newCell == null)
|
||||
{
|
||||
Cell? refCell = null;
|
||||
foreach (Cell cell in row.Elements<Cell>())
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
75
ITServiceManager/ITServiceManager/Reports/PdfBuilder.cs
Normal file
75
ITServiceManager/ITServiceManager/Reports/PdfBuilder.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||
using MigraDoc.Rendering;
|
||||
using System.Text;
|
||||
namespace ITServiceManager.Reports;
|
||||
|
||||
public class PdfBuilder
|
||||
{
|
||||
private readonly string _filePath;
|
||||
private readonly Document _document;
|
||||
|
||||
public PdfBuilder(string filePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(filePath));
|
||||
}
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
_filePath = filePath;
|
||||
_document = new Document();
|
||||
DefineStyles();
|
||||
}
|
||||
|
||||
public PdfBuilder AddHeader(string header)
|
||||
{
|
||||
_document.AddSection().AddParagraph(header, "NormalBold");
|
||||
return this;
|
||||
}
|
||||
|
||||
public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data)
|
||||
{
|
||||
if (data == null || data.Count == 0)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
var chart = new Chart(ChartType.Pie2D);
|
||||
var series = chart.SeriesCollection.AddSeries();
|
||||
series.Add(data.Select(x => x.Value).ToArray());
|
||||
var xseries = chart.XValues.AddXSeries();
|
||||
xseries.Add(data.Select(x => x.Caption).ToArray());
|
||||
chart.DataLabel.Type = DataLabelType.Percent;
|
||||
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
|
||||
chart.Width = Unit.FromCentimeter(16);
|
||||
chart.Height = Unit.FromCentimeter(12);
|
||||
chart.TopArea.AddParagraph(title);
|
||||
chart.XAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.HasMajorGridlines = true;
|
||||
chart.PlotArea.LineFormat.Width = 1;
|
||||
chart.PlotArea.LineFormat.Visible = true;
|
||||
chart.TopArea.AddLegend();
|
||||
_document.LastSection.Add(chart);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Build()
|
||||
{
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
var renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(_filePath);
|
||||
}
|
||||
private void DefineStyles()
|
||||
{
|
||||
var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal");
|
||||
headerStyle.Font.Bold = true;
|
||||
headerStyle.Font.Size = 14;
|
||||
}
|
||||
}
|
68
ITServiceManager/ITServiceManager/Reports/TableReport.cs
Normal file
68
ITServiceManager/ITServiceManager/Reports/TableReport.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using ITServiceManager.Repositories;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ITServiceManager.Reports;
|
||||
|
||||
public class TableReport
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly IAppointmentRepository _appointmentRepository;
|
||||
private readonly ILogger<TableReport> _logger;
|
||||
internal static readonly string[] item = ["Сотрудник", "Дата", "Количество"];
|
||||
|
||||
public TableReport(IOrderRepository orderRepository,
|
||||
IAppointmentRepository appointmentRepository, ILogger<TableReport> logger)
|
||||
{
|
||||
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
||||
_appointmentRepository = appointmentRepository ?? throw new ArgumentNullException(nameof(appointmentRepository));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public bool CreateTable(string filePath, int employeeId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по выбору услуг", 0, 3)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddTable([10, 30, 30], GetData(employeeId, startDate, endDate))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<string[]> GetData(int serviceId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
|
||||
var data = _orderRepository
|
||||
.ReadOrders()
|
||||
.Where(order =>
|
||||
order.Date >= startDate &&
|
||||
order.Date <= endDate &&
|
||||
order.OrderService.Any(service => service.ServiceId == serviceId))
|
||||
.SelectMany(order => order.OrderService
|
||||
.Where(service => service.ServiceId == serviceId)
|
||||
.Select(service => new
|
||||
{
|
||||
EmployeeId = _appointmentRepository
|
||||
.ReadAppointments()
|
||||
.FirstOrDefault(app => app.OrderId == order.Id)?.EmployeeId,
|
||||
Date = order.Date,
|
||||
Quantity = service.Quantity
|
||||
}))
|
||||
.OrderBy(result => result.Date);
|
||||
return new List<string[]>() { item }
|
||||
.Union(
|
||||
data
|
||||
.Select(x => new string[] { x.EmployeeId?.ToString() ?? "Не назначен", x.Date.ToString(), x.Quantity.ToString()}))
|
||||
.Union(
|
||||
[["Всего", string.Empty, data.Sum(x => x.Quantity).ToString()]])
|
||||
.ToList();
|
||||
}
|
||||
|
||||
}
|
102
ITServiceManager/ITServiceManager/Reports/WordBuilder.cs
Normal file
102
ITServiceManager/ITServiceManager/Reports/WordBuilder.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
|
||||
namespace ITServiceManager.Reports;
|
||||
|
||||
public class WordBuilder
|
||||
{
|
||||
private readonly string _filePath;
|
||||
private readonly Document _document;
|
||||
private readonly Body _body;
|
||||
|
||||
public WordBuilder(string filePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(filePath));
|
||||
}
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
_filePath = filePath;
|
||||
_document = new Document();
|
||||
_body = _document.AppendChild(new Body());
|
||||
}
|
||||
|
||||
public WordBuilder AddHeader(string header)
|
||||
{
|
||||
var paragraph = _body.AppendChild(new Paragraph());
|
||||
var run = paragraph.AppendChild(new Run());
|
||||
var runProperties = run.AppendChild(new RunProperties());
|
||||
runProperties.AppendChild(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<string[]> 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>(BorderValues.Single), Size = 12 },
|
||||
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
|
||||
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(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;
|
||||
}
|
||||
}
|
@ -16,16 +16,24 @@ public class OrderRepository : IOrderRepository
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public IEnumerable<Order> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? orderId = null, int? companyId = null)
|
||||
public IEnumerable<Order> ReadOrders(DateTime? dateForm = null, DateTime? dateTo = null, int? serviceId = null, int? companyId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM Orders";
|
||||
var order = connection.Query<Order>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(order));
|
||||
return order;
|
||||
var querySelect = @"
|
||||
SELECT o.*, os.serviceId, os.quantity
|
||||
FROM Orders AS o
|
||||
INNER JOIN Order_Service AS os ON o.id = os.orderId
|
||||
Where os.serviceId = @serviceId";
|
||||
var orders = connection.Query<TempOrder>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orders));
|
||||
return orders.GroupBy(x => x.Id, y => y,
|
||||
(key, value) =>
|
||||
Order.CreateOperation(value.First(),
|
||||
value.Select(z =>
|
||||
OrderService.CreateOperation(0, z.ServiceId, z.Quantity, z.ExecutionTime)))).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user
Заголовок формы оформлен неверно