From 9dac978c9392e87ab3ed326fe54f3738598b1f05 Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Thu, 5 Dec 2024 15:22:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=20=D0=B4=D0=BE=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20temp=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Enities/TempClientTour.cs | 18 +++ project/ProjectTourAgency/Enities/Tour.cs | 9 ++ .../Forms/FormExcelReport.Designer.cs | 114 +++++++++++++++++ .../Forms/FormExcelReport.cs | 84 ++++++++++++ .../Forms/FormExcelReport.resx | 120 ++++++++++++++++++ .../Reports/TableReportcs.cs | 47 ++++++- 6 files changed, 386 insertions(+), 6 deletions(-) create mode 100644 project/ProjectTourAgency/Enities/TempClientTour.cs create mode 100644 project/ProjectTourAgency/Forms/FormExcelReport.Designer.cs create mode 100644 project/ProjectTourAgency/Forms/FormExcelReport.cs create mode 100644 project/ProjectTourAgency/Forms/FormExcelReport.resx diff --git a/project/ProjectTourAgency/Enities/TempClientTour.cs b/project/ProjectTourAgency/Enities/TempClientTour.cs new file mode 100644 index 0000000..f2de69e --- /dev/null +++ b/project/ProjectTourAgency/Enities/TempClientTour.cs @@ -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; } +} diff --git a/project/ProjectTourAgency/Enities/Tour.cs b/project/ProjectTourAgency/Enities/Tour.cs index 03f1cc9..0387586 100644 --- a/project/ProjectTourAgency/Enities/Tour.cs +++ b/project/ProjectTourAgency/Enities/Tour.cs @@ -26,4 +26,13 @@ public class Tour ClientTours = clientTours }; } + + public static Tour CreateEntity(TempClientTour tempClientTour, IEnumerable clientTours) + { + return new Tour + { + Id = tempClientTour.Id, + EmployeeId = tempClientTour.EmployeeId + } + } } diff --git a/project/ProjectTourAgency/Forms/FormExcelReport.Designer.cs b/project/ProjectTourAgency/Forms/FormExcelReport.Designer.cs new file mode 100644 index 0000000..2a0c9ed --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormExcelReport.Designer.cs @@ -0,0 +1,114 @@ +namespace ProjectTourAgency.Forms +{ + partial class FormExcelReport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + } +} \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormExcelReport.cs b/project/ProjectTourAgency/Forms/FormExcelReport.cs new file mode 100644 index 0000000..fea29b9 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormExcelReport.cs @@ -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().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); + } + } +} diff --git a/project/ProjectTourAgency/Forms/FormExcelReport.resx b/project/ProjectTourAgency/Forms/FormExcelReport.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormExcelReport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/project/ProjectTourAgency/Reports/TableReportcs.cs b/project/ProjectTourAgency/Reports/TableReportcs.cs index 0b6e3c5..07aedd9 100644 --- a/project/ProjectTourAgency/Reports/TableReportcs.cs +++ b/project/ProjectTourAgency/Reports/TableReportcs.cs @@ -16,7 +16,7 @@ internal class TableReport private readonly ILogger _logger; - internal static readonly string[] item = ["Сотрудник","Клиент","Дата","Депозит"]; + internal static readonly string[] item = ["Клиент","Дата","Списания","Пополнения"]; public TableReport(IAddMoneyRepository addMoneyRepository, ITourRepository tourRepository, ILogger 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 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() { 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(); + } + - - }