From 06d1a0d61057852c75f296ce2a1255581dd6ef01 Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Mon, 2 Dec 2024 13:21:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B4=D0=B8=D0=B0=D0=B3=D0=B0=D1=80=D0=BC=D0=BC?= =?UTF-8?q?=D1=8B=20=D0=BF=D0=BE=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BF=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B4=D0=B5=D0=BD=D0=B5=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormTourAgency.Designer.cs | 12 +- project/ProjectTourAgency/FormTourAgency.cs | 12 ++ project/ProjectTourAgency/FormTourAgency.resx | 3 + .../Forms/FormAddMoneyReport.Designer.cs | 107 ++++++++++++++++ .../Forms/FormAddMoneyReport.cs | 66 ++++++++++ .../Forms/FormAddMoneyReport.resx | 120 ++++++++++++++++++ .../ProjectTourAgency/Reports/ChartReport.cs | 52 ++++++++ .../Reports/TableReportcs.cs | 16 +-- 8 files changed, 373 insertions(+), 15 deletions(-) create mode 100644 project/ProjectTourAgency/Forms/FormAddMoneyReport.Designer.cs create mode 100644 project/ProjectTourAgency/Forms/FormAddMoneyReport.cs create mode 100644 project/ProjectTourAgency/Forms/FormAddMoneyReport.resx create mode 100644 project/ProjectTourAgency/Reports/ChartReport.cs diff --git a/project/ProjectTourAgency/FormTourAgency.Designer.cs b/project/ProjectTourAgency/FormTourAgency.Designer.cs index 38bbaec..14fe04e 100644 --- a/project/ProjectTourAgency/FormTourAgency.Designer.cs +++ b/project/ProjectTourAgency/FormTourAgency.Designer.cs @@ -38,6 +38,7 @@ турToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); DirectoryReportToolStripMenuItem = new ToolStripMenuItem(); + AddMoneyReportToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); SuspendLayout(); // @@ -103,7 +104,7 @@ // // отчетыToolStripMenuItem // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem }); + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, AddMoneyReportToolStripMenuItem }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; отчетыToolStripMenuItem.Size = new Size(88, 29); отчетыToolStripMenuItem.Text = "Отчеты"; @@ -116,6 +117,14 @@ DirectoryReportToolStripMenuItem.Text = "Документы со справочниками"; DirectoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click; // + // AddMoneyReportToolStripMenuItem + // + AddMoneyReportToolStripMenuItem.Name = "AddMoneyReportToolStripMenuItem"; + AddMoneyReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P; + AddMoneyReportToolStripMenuItem.Size = new Size(434, 34); + AddMoneyReportToolStripMenuItem.Text = "Денежная диаграмма"; + AddMoneyReportToolStripMenuItem.Click += AddMoneyReportToolStripMenuItem_Click; + // // FormTourAgency // AutoScaleDimensions = new SizeF(10F, 25F); @@ -148,5 +157,6 @@ private ToolStripMenuItem пополнитьБалансПользователяToolStripMenuItem; private ToolStripMenuItem турToolStripMenuItem; private ToolStripMenuItem DirectoryReportToolStripMenuItem; + private ToolStripMenuItem AddMoneyReportToolStripMenuItem; } } diff --git a/project/ProjectTourAgency/FormTourAgency.cs b/project/ProjectTourAgency/FormTourAgency.cs index d916d09..3b492a4 100644 --- a/project/ProjectTourAgency/FormTourAgency.cs +++ b/project/ProjectTourAgency/FormTourAgency.cs @@ -85,4 +85,16 @@ public partial class FormTourAgency : Form MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void AddMoneyReportToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } diff --git a/project/ProjectTourAgency/FormTourAgency.resx b/project/ProjectTourAgency/FormTourAgency.resx index b48baf1..0219098 100644 --- a/project/ProjectTourAgency/FormTourAgency.resx +++ b/project/ProjectTourAgency/FormTourAgency.resx @@ -120,4 +120,7 @@ 17, 17 + + 32 + \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormAddMoneyReport.Designer.cs b/project/ProjectTourAgency/Forms/FormAddMoneyReport.Designer.cs new file mode 100644 index 0000000..05a9ae7 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormAddMoneyReport.Designer.cs @@ -0,0 +1,107 @@ +namespace ProjectTourAgency.Forms +{ + partial class FormAddMoneyReport + { + /// + /// 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() + { + dateTimePicker1 = new DateTimePicker(); + buttonSelectFileName = new Button(); + buttonCreate = new Button(); + labelFileName = new Label(); + labelDate = new Label(); + SuspendLayout(); + // + // dateTimePicker1 + // + dateTimePicker1.Location = new Point(102, 123); + dateTimePicker1.Name = "dateTimePicker1"; + dateTimePicker1.Size = new Size(222, 31); + dateTimePicker1.TabIndex = 0; + // + // buttonSelectFileName + // + buttonSelectFileName.Location = new Point(43, 50); + buttonSelectFileName.Name = "buttonSelectFileName"; + buttonSelectFileName.Size = new Size(112, 34); + buttonSelectFileName.TabIndex = 1; + buttonSelectFileName.Text = "Выбрать"; + buttonSelectFileName.UseVisualStyleBackColor = true; + buttonSelectFileName.Click += buttonSelectFileName_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(43, 195); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(144, 34); + buttonCreate.TabIndex = 2; + buttonCreate.Text = "Сформировать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // labelFileName + // + labelFileName.AutoSize = true; + labelFileName.Location = new Point(193, 55); + labelFileName.Name = "labelFileName"; + labelFileName.Size = new Size(53, 25); + labelFileName.TabIndex = 3; + labelFileName.Text = "Файл"; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(43, 123); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(53, 25); + labelDate.TabIndex = 4; + labelDate.Text = "Дата:"; + // + // FormAddMoneyReport + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(446, 269); + Controls.Add(labelDate); + Controls.Add(labelFileName); + Controls.Add(buttonCreate); + Controls.Add(buttonSelectFileName); + Controls.Add(dateTimePicker1); + Name = "FormAddMoneyReport"; + Text = "FormAddMoneyReport"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker dateTimePicker1; + private Button buttonSelectFileName; + private Button buttonCreate; + private Label labelFileName; + private Label labelDate; + } +} \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormAddMoneyReport.cs b/project/ProjectTourAgency/Forms/FormAddMoneyReport.cs new file mode 100644 index 0000000..2d126d4 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormAddMoneyReport.cs @@ -0,0 +1,66 @@ +using ProjectTourAgency.Reports; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectTourAgency.Forms +{ + public partial class FormAddMoneyReport : Form + { + private string _fileName = string.Empty; + + private readonly IUnityContainer _container; + + public FormAddMoneyReport(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().CreateChart(_fileName, dateTimePicker1.Value)) + { + MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах", "Формирование документа", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/project/ProjectTourAgency/Forms/FormAddMoneyReport.resx b/project/ProjectTourAgency/Forms/FormAddMoneyReport.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormAddMoneyReport.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/ChartReport.cs b/project/ProjectTourAgency/Reports/ChartReport.cs new file mode 100644 index 0000000..ac2b5d2 --- /dev/null +++ b/project/ProjectTourAgency/Reports/ChartReport.cs @@ -0,0 +1,52 @@ +using Microsoft.Extensions.Logging; +using ProjectTourAgency.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTourAgency.Reports; + +internal class ChartReport +{ + private readonly IAddMoneyRepository _addMoneyRepository; + + private readonly ILogger _logger; + + public ChartReport(IAddMoneyRepository addMoneyRepository, ILogger logger) + { + _addMoneyRepository = addMoneyRepository ?? + throw new ArgumentNullException(nameof(addMoneyRepository)); + _logger = logger ?? + throw new ArgumentNullException(nameof(logger)); + } + + public bool CreateChart(string filePath, DateTime dateTime) + { + try + { + new PdfBuilder(filePath) + .AddHeader("Операции пополнения") + .AddPieChart("Пополнения счетов клиентов", GetData(dateTime)) + .Build(); + + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при формировании документа"); + return false; + } + } + + private List<(string Caption, double Value)> GetData(DateTime dateTime) + { + return _addMoneyRepository + .ReadAddMoneys() + .Where(x => x.Date.Date == dateTime.Date) + .GroupBy(x => x.ClientId, (key, group) => new { Id = key, Count = group.Count() }) + .Select(x => (x.Id.ToString(), (double)x.Count)) + .ToList(); + } +} diff --git a/project/ProjectTourAgency/Reports/TableReportcs.cs b/project/ProjectTourAgency/Reports/TableReportcs.cs index c7edbea..0b6e3c5 100644 --- a/project/ProjectTourAgency/Reports/TableReportcs.cs +++ b/project/ProjectTourAgency/Reports/TableReportcs.cs @@ -33,13 +33,7 @@ internal class TableReport { try { - new ExcelBuilder(filePath) - .AddHeader("Сводка по операциям пополнения", 0, 4) - .AddParagraph("за период", 0) - .AddTable([15, 15, 15, 15], GetData(addMoneyId, startDate, endDate)) - .Build(); - - return true; + return false; } catch (Exception ex) { @@ -48,13 +42,7 @@ internal class TableReport } } - private List GetData(int addMoneyId, DateTime startDate, DateTime endDate) - { - var data = _addMoneyRepository - .ReadAddMoneys() - .Where(x => x.Date >= startDate && x.Date <= endDate && x.) - - } + }