Сделал все до изменения temp класса

This commit is contained in:
Tonb73 2024-12-05 15:22:26 +03:00
parent 06d1a0d610
commit 9dac978c93
6 changed files with 386 additions and 6 deletions

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTourAgency.Enities;
public class TempClientTour
{
public int Id { get; private set; }
public int ClientId { get; private set; }
public int TourId { get; private set; }
public int EmployeeId { get; private set; }
public DateTime DepartureDate { get; private set; }
public int Cost { get; private set; }
}

View File

@ -26,4 +26,13 @@ public class Tour
ClientTours = clientTours
};
}
public static Tour CreateEntity(TempClientTour tempClientTour, IEnumerable<ClientTour> clientTours)
{
return new Tour
{
Id = tempClientTour.Id,
EmployeeId = tempClientTour.EmployeeId
}
}
}

View File

@ -0,0 +1,114 @@
namespace ProjectTourAgency.Forms
{
partial class FormExcelReport
{
/// <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()
{
dateTimePickerDateEnd = new DateTimePicker();
dateTimePickerDateBegin = new DateTimePicker();
buttonSelectFilePath = new Button();
buttonMakeReport = new Button();
comboBoxTour = new ComboBox();
textBoxFilePath = new TextBox();
SuspendLayout();
//
// dateTimePickerDateEnd
//
dateTimePickerDateEnd.Location = new Point(58, 155);
dateTimePickerDateEnd.Name = "dateTimePickerDateEnd";
dateTimePickerDateEnd.Size = new Size(201, 31);
dateTimePickerDateEnd.TabIndex = 0;
//
// dateTimePickerDateBegin
//
dateTimePickerDateBegin.Location = new Point(58, 105);
dateTimePickerDateBegin.Name = "dateTimePickerDateBegin";
dateTimePickerDateBegin.Size = new Size(201, 31);
dateTimePickerDateBegin.TabIndex = 1;
//
// buttonSelectFilePath
//
buttonSelectFilePath.Location = new Point(148, 47);
buttonSelectFilePath.Name = "buttonSelectFilePath";
buttonSelectFilePath.Size = new Size(112, 34);
buttonSelectFilePath.TabIndex = 2;
buttonSelectFilePath.Text = "button1";
buttonSelectFilePath.UseVisualStyleBackColor = true;
buttonSelectFilePath.Click += buttonSelectFilePath_Click;
//
// buttonMakeReport
//
buttonMakeReport.Location = new Point(144, 234);
buttonMakeReport.Name = "buttonMakeReport";
buttonMakeReport.Size = new Size(112, 34);
buttonMakeReport.TabIndex = 3;
buttonMakeReport.Text = "button2";
buttonMakeReport.UseVisualStyleBackColor = true;
buttonMakeReport.Click += buttonMakeReport_Click;
//
// comboBoxTour
//
comboBoxTour.FormattingEnabled = true;
comboBoxTour.Location = new Point(298, 157);
comboBoxTour.Name = "comboBoxTour";
comboBoxTour.Size = new Size(182, 33);
comboBoxTour.TabIndex = 4;
//
// textBoxFilePath
//
textBoxFilePath.Location = new Point(279, 47);
textBoxFilePath.Name = "textBoxFilePath";
textBoxFilePath.Size = new Size(150, 31);
textBoxFilePath.TabIndex = 5;
//
// FormExcelReport
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(textBoxFilePath);
Controls.Add(comboBoxTour);
Controls.Add(buttonMakeReport);
Controls.Add(buttonSelectFilePath);
Controls.Add(dateTimePickerDateBegin);
Controls.Add(dateTimePickerDateEnd);
Name = "FormExcelReport";
Text = "FormExcelReport";
ResumeLayout(false);
PerformLayout();
}
#endregion
private DateTimePicker dateTimePickerDateEnd;
private DateTimePicker dateTimePickerDateBegin;
private Button buttonSelectFilePath;
private Button buttonMakeReport;
private ComboBox comboBoxTour;
private TextBox textBoxFilePath;
}
}

View File

@ -0,0 +1,84 @@
using ProjectTourAgency.Reports;
using ProjectTourAgency.Repositories;
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 ProjectTourAgency.Forms;
public partial class FormExcelReport : Form
{
private readonly IUnityContainer _container;
public FormExcelReport(IUnityContainer container, ITourRepository tourRepository )
{
InitializeComponent();
container = container ??
throw new ArgumentNullException(nameof(container));
comboBoxTour.DataSource = tourRepository.ReadTours();
comboBoxTour.DisplayMember = "iD";
comboBoxTour.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 (comboBoxTour.SelectedIndex < 0)
{
throw new Exception("Не выбран корм");
}
if (dateTimePickerDateEnd.Value <=
dateTimePickerDateBegin.Value)
{
throw new Exception("Дата начала должна быть раньше даты окончания");
}
if
(_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text,
(int)comboBoxTour.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);
}
}
}

View 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>

View File

@ -16,7 +16,7 @@ internal class TableReport
private readonly ILogger<TableReport> _logger;
internal static readonly string[] item = ["Сотрудник","Клиент","Дата","Депозит"];
internal static readonly string[] item = ["Клиент","Дата","Списания","Пополнения"];
public TableReport(IAddMoneyRepository addMoneyRepository,
ITourRepository tourRepository, ILogger<TableReport> logger)
@ -29,11 +29,17 @@ internal class TableReport
throw new ArgumentNullException(nameof(logger));
}
public bool CreateTable(string filePath, int addMoneyId, DateTime startDate, DateTime endDate)
public bool CreateTable(string filePath, int tourId, DateTime startDate, DateTime endDate)
{
try
{
return false;
{
new ExcelBuilder(filePath)
.AddHeader("Сводка по движению корма", 0, 4)
.AddParagraph("за период", 0)
.AddTable([10, 10, 15, 15], GetData(tourId, startDate,
endDate))
.Build();
return true;
}
catch (Exception ex)
{
@ -41,8 +47,37 @@ internal class TableReport
return false;
}
}
private List<string[]> GetData(int tourId, DateTime startDate, DateTime
endDate)
{
var data = _tourRepository.ReadTours().Select(x => new {
ClientId = x.ClientTours.FirstOrDefault(y => y.TourId == tourId).ClientId,
Date = x.DepartureDate,
CountIn = (int?)null,
CountOut = (int?)null
})
.Union(
_addMoneyRepository.ReadAddMoneys().Select(x => new {
ClientId = x.ClientId,
Date = x.Date,
CountIn = (int?)null,
CountOut= (int?)null })
)
.OrderBy(x => x.Date);
return
new List<string[]>() { item }
.Union(
data
.Select(x => new string[] {
x.ClientId.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();
}
}