From 737778adc46838846a4facebda70171f525b4a06 Mon Sep 17 00:00:00 2001 From: tellsense Date: Thu, 25 Apr 2024 20:50:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D1=82=D0=B8=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=204=20=D0=BB=D0=B0=D0=B1=D0=B0.=20?= =?UTF-8?q?=D0=9D=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= =?UTF-8?q?=20pdf=20=D0=BE=D1=82=D1=87=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarView/FormMain.Designer.cs | 57 +- SushiBar/SushiBarView/FormMain.cs | 39 +- .../SushiBarView/FormReportOrders.Designer.cs | 114 ++++ SushiBar/SushiBarView/FormReportOrders.cs | 99 +++ SushiBar/SushiBarView/FormReportOrders.resx | 123 ++++ .../FormReportSushiComponents.Designer.cs | 2 +- SushiBar/SushiBarView/Program.cs | 17 +- SushiBar/SushiBarView/Report1.rdlc | 10 - SushiBar/SushiBarView/ReportOrders.rdlc | 572 ++++++++++++++++++ SushiBar/SushiBarView/SushiBarView.csproj | 4 +- 10 files changed, 994 insertions(+), 43 deletions(-) create mode 100644 SushiBar/SushiBarView/FormReportOrders.Designer.cs create mode 100644 SushiBar/SushiBarView/FormReportOrders.cs create mode 100644 SushiBar/SushiBarView/FormReportOrders.resx delete mode 100644 SushiBar/SushiBarView/Report1.rdlc create mode 100644 SushiBar/SushiBarView/ReportOrders.rdlc diff --git a/SushiBar/SushiBarView/FormMain.Designer.cs b/SushiBar/SushiBarView/FormMain.Designer.cs index daeff07..eaedf1d 100644 --- a/SushiBar/SushiBarView/FormMain.Designer.cs +++ b/SushiBar/SushiBarView/FormMain.Designer.cs @@ -38,10 +38,10 @@ toolStripMenuItem = new ToolStripMenuItem(); componentsToolStripMenuItem = new ToolStripMenuItem(); sushiToolStripMenuItem = new ToolStripMenuItem(); - отчетыToolStripMenuItem = new ToolStripMenuItem(); - списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); - компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); - списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + ReportsToolStripMenuItem = new ToolStripMenuItem(); + ComponentsListToolStripMenuItem = new ToolStripMenuItem(); + ComponentSushisToolStripMenuItem = new ToolStripMenuItem(); + OrdersToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -52,7 +52,6 @@ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Location = new Point(1, 29); dataGridView.Name = "dataGridView"; - dataGridView.RowTemplate.Height = 25; dataGridView.Size = new Size(1080, 307); dataGridView.TabIndex = 0; // @@ -108,7 +107,7 @@ // // menuStrip // - menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, ReportsToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1265, 24); @@ -136,30 +135,33 @@ sushiToolStripMenuItem.Text = "Суши"; sushiToolStripMenuItem.Click += sushiToolStripMenuItem_Click; // - // отчетыToolStripMenuItem + // ReportsToolStripMenuItem // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); - отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 20); - отчетыToolStripMenuItem.Text = "Отчеты"; + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsListToolStripMenuItem, ComponentSushisToolStripMenuItem, OrdersToolStripMenuItem }); + ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; + ReportsToolStripMenuItem.Size = new Size(60, 20); + ReportsToolStripMenuItem.Text = "Отчеты"; // - // списокКомпонентовToolStripMenuItem + // ComponentsListToolStripMenuItem // - списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; - списокКомпонентовToolStripMenuItem.Size = new Size(218, 22); - списокКомпонентовToolStripMenuItem.Text = "Список компонентов"; + ComponentsListToolStripMenuItem.Name = "ComponentsListToolStripMenuItem"; + ComponentsListToolStripMenuItem.Size = new Size(218, 22); + ComponentsListToolStripMenuItem.Text = "Список компонентов"; + ComponentsListToolStripMenuItem.Click += ComponentsListToolStripMenuItem_Click; // - // компонентыПоИзделиямToolStripMenuItem + // ComponentSushisToolStripMenuItem // - компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; - компонентыПоИзделиямToolStripMenuItem.Size = new Size(218, 22); - компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям"; + ComponentSushisToolStripMenuItem.Name = "ComponentSushisToolStripMenuItem"; + ComponentSushisToolStripMenuItem.Size = new Size(218, 22); + ComponentSushisToolStripMenuItem.Text = "Компоненты по изделиям"; + ComponentSushisToolStripMenuItem.Click += ComponentSushisToolStripMenuItem_Click; // - // списокЗаказовToolStripMenuItem + // OrdersToolStripMenuItem // - списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - списокЗаказовToolStripMenuItem.Size = new Size(218, 22); - списокЗаказовToolStripMenuItem.Text = "Список заказов"; + OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem"; + OrdersToolStripMenuItem.Size = new Size(218, 22); + OrdersToolStripMenuItem.Text = "Список заказов"; + OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // // FormMain // @@ -196,9 +198,10 @@ private ToolStripMenuItem toolStripMenuItem; private ToolStripMenuItem componentsToolStripMenuItem; private ToolStripMenuItem sushiToolStripMenuItem; - private ToolStripMenuItem отчетыToolStripMenuItem; - private ToolStripMenuItem списокКомпонентовToolStripMenuItem; - private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; - private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem ReportsToolStripMenuItem; + private ToolStripMenuItem toolStripMenuItem1; + private ToolStripMenuItem ComponentsListToolStripMenuItem; + private ToolStripMenuItem ComponentSushisToolStripMenuItem; + private ToolStripMenuItem OrdersToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.cs b/SushiBar/SushiBarView/FormMain.cs index cb8c267..9d49670 100644 --- a/SushiBar/SushiBarView/FormMain.cs +++ b/SushiBar/SushiBarView/FormMain.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using SushiBarBusinessLogic.BusinessLogics; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using System; @@ -17,11 +18,13 @@ namespace SushiBarView { private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) + private readonly IReportLogic _reportLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; + _reportLogic = reportLogic; } private void FormMain_Load(object sender, EventArgs e) { @@ -156,6 +159,40 @@ namespace SushiBarView } } } + private void ComponentsListToolStripMenuItem_Click(object sender, EventArgs +e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveComponentsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + private void ComponentSushisToolStripMenuItem_Click(object sender, + EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormReportSushiComponents)); + if (service is FormReportSushiComponents form) + { + form.ShowDialog(); + } + } + private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } + private void ButtonRef_Click(object sender, EventArgs e) { LoadData(); diff --git a/SushiBar/SushiBarView/FormReportOrders.Designer.cs b/SushiBar/SushiBarView/FormReportOrders.Designer.cs new file mode 100644 index 0000000..0a33b89 --- /dev/null +++ b/SushiBar/SushiBarView/FormReportOrders.Designer.cs @@ -0,0 +1,114 @@ +namespace SushiBarView +{ + partial class FormReportOrders + { + /// + /// 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() + { + dateTimePickerFrom = new DateTimePicker(); + dateTimePickerTo = new DateTimePicker(); + panel = new Panel(); + ButtonToPdf = new Button(); + ButtonMake = new Button(); + reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer(); + panel.SuspendLayout(); + SuspendLayout(); + // + // dateTimePickerFrom + // + dateTimePickerFrom.Location = new Point(58, 11); + dateTimePickerFrom.Name = "dateTimePickerFrom"; + dateTimePickerFrom.Size = new Size(200, 23); + dateTimePickerFrom.TabIndex = 0; + // + // dateTimePickerTo + // + dateTimePickerTo.Location = new Point(321, 11); + dateTimePickerTo.Name = "dateTimePickerTo"; + dateTimePickerTo.Size = new Size(200, 23); + dateTimePickerTo.TabIndex = 1; + // + // panel + // + panel.Controls.Add(ButtonToPdf); + panel.Controls.Add(ButtonMake); + panel.Controls.Add(dateTimePickerTo); + panel.Controls.Add(dateTimePickerFrom); + panel.Location = new Point(3, 3); + panel.Name = "panel"; + panel.Size = new Size(1191, 52); + panel.TabIndex = 2; + // + // ButtonToPdf + // + ButtonToPdf.Location = new Point(974, 10); + ButtonToPdf.Name = "ButtonToPdf"; + ButtonToPdf.Size = new Size(197, 23); + ButtonToPdf.TabIndex = 3; + ButtonToPdf.Text = "В Pdf"; + ButtonToPdf.UseVisualStyleBackColor = true; + ButtonToPdf.Click += ButtonToPdf_Click; + // + // ButtonMake + // + ButtonMake.Location = new Point(583, 10); + ButtonMake.Name = "ButtonMake"; + ButtonMake.Size = new Size(149, 23); + ButtonMake.TabIndex = 2; + ButtonMake.Text = "Сформировать"; + ButtonMake.UseVisualStyleBackColor = true; + ButtonMake.Click += ButtonMake_Click; + // + // reportViewer1 + // + reportViewer1.Location = new Point(0, 0); + reportViewer1.Name = "ReportViewer"; + reportViewer1.ServerReport.BearerToken = null; + reportViewer1.Size = new Size(396, 246); + reportViewer1.TabIndex = 0; + // + // FormReportOrders + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1197, 450); + Controls.Add(panel); + Name = "FormReportOrders"; + Text = "Заказы"; + panel.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DateTimePicker dateTimePickerFrom; + private DateTimePicker dateTimePickerTo; + private Panel panel; + private Button ButtonToPdf; + private Button ButtonMake; + private Microsoft.Reporting.WinForms.ReportViewer reportViewer1; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormReportOrders.cs b/SushiBar/SushiBarView/FormReportOrders.cs new file mode 100644 index 0000000..111f665 --- /dev/null +++ b/SushiBar/SushiBarView/FormReportOrders.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +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; + +namespace SushiBarView +{ + public partial class FormReportOrders : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + public FormReportOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + private void ButtonMake_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", + "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var dataSource = _logic.GetOrders(new ReportBindingModel + { + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") }; reportViewer.LocalReport.SetParameters(parameters); + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{ To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonToPdf_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", + "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + using var dialog = new SaveFileDialog + { + Filter = "pdf|*.pdf" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + _logger.LogInformation("Сохранение списка заказов на период { From}-{ To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} + diff --git a/SushiBar/SushiBarView/FormReportOrders.resx b/SushiBar/SushiBarView/FormReportOrders.resx new file mode 100644 index 0000000..fbd1d64 --- /dev/null +++ b/SushiBar/SushiBarView/FormReportOrders.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormReportSushiComponents.Designer.cs b/SushiBar/SushiBarView/FormReportSushiComponents.Designer.cs index 5e9cac9..e3b45c8 100644 --- a/SushiBar/SushiBarView/FormReportSushiComponents.Designer.cs +++ b/SushiBar/SushiBarView/FormReportSushiComponents.Designer.cs @@ -69,7 +69,7 @@ ButtonSaveToExcel.TabIndex = 1; ButtonSaveToExcel.Text = "Сохранить в Excel"; ButtonSaveToExcel.UseVisualStyleBackColor = true; - ButtonSaveToExcel.Click += this.ButtonSaveToExcel_Click_1; + ButtonSaveToExcel.Click += this.ButtonSaveToExcel_Click; // // FormReportSushiComponents // diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs index 0d12b88..e85e214 100644 --- a/SushiBar/SushiBarView/Program.cs +++ b/SushiBar/SushiBarView/Program.cs @@ -1,12 +1,12 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using SushiBarContracts.BusinessLogicsContracts; -using System; +using SushiBarDatabaseImplement.Implements; using SushiBarBusinessLogic.BusinessLogics; -using SushiBarFileImplement.Implements; using SushiBarContracts.StoragesContracts; -using SushiBarView; using NLog.Extensions.Logging; +using SushiBarBusinessLogic.OfficePackage.Implements; +using SushiBarBusinessLogic.OfficePackage; namespace SushiBarView @@ -37,9 +37,11 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -47,6 +49,15 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); } } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/Report1.rdlc b/SushiBar/SushiBarView/Report1.rdlc deleted file mode 100644 index 7c2476d..0000000 --- a/SushiBar/SushiBarView/Report1.rdlc +++ /dev/null @@ -1,10 +0,0 @@ - - - 6.5in - - 2in - - true - - - diff --git a/SushiBar/SushiBarView/ReportOrders.rdlc b/SushiBar/SushiBarView/ReportOrders.rdlc new file mode 100644 index 0000000..20a9a39 --- /dev/null +++ b/SushiBar/SushiBarView/ReportOrders.rdlc @@ -0,0 +1,572 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + SushiBarContractsViewModels + /* Local Query */ + + + + Id + System.Int32 + + + DateCreate + System.DateTime + + + SushiName + System.String + + + Sum + System.Decimal + + + Status + System.String + + + + SushiBarContracts.ViewModels + ReportOrdersViewModel + SushiBarContracts.ViewModels.ReportOrdersViewModel, SushiBarContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Заказы + + + + 0.6cm + 16.51cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + ReportParameterPeriod + 0.6cm + 0.6cm + 16.51cm + 1 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 2.60583cm + + + 3.262cm + + + 4.8495cm + + + 2.5cm + + + 2.5cm + + + + + 0.6cm + + + + + true + true + + + + + Номер + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Дата создания + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Суши + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Статус + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Id.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!DateCreate.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!SushiName.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Status.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 1.9177cm + 0.79267cm + 1.2cm + 15.71733cm + 2 + + + + + + true + true + + + + + Итого: + + + + 3.46287cm + 11.51cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + 2pt + 2pt + 2pt + 2pt + + + + 2in +