From 0618c74ff32a14e5c478da244cd455ff1cc217a7 Mon Sep 17 00:00:00 2001 From: malimova Date: Thu, 25 Apr 2024 20:14:44 +0400 Subject: [PATCH] =?UTF-8?q?=D1=8F=20=D0=B4=D0=B5=D0=BB=D0=B0=D1=8E,=20?= =?UTF-8?q?=D1=81=20=D0=BF=D0=B4=D1=84=20=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/ReportOrdersViewModel.cs | 1 + .../ConfectioneryFileImplement.csproj | 4 + .../ConfectioneryListImplement.csproj | 1 + .../ConfectioneryView.csproj | 7 + .../ConfectioneryView/FormMain.Designer.cs | 1 + Confectionery/ConfectioneryView/FormMain.cs | 23 +- .../FormReportOrders.Designer.cs | 130 ++++ .../ConfectioneryView/FormReportOrders.cs | 107 ++++ .../ConfectioneryView/FormReportOrders.resx | 60 ++ Confectionery/ConfectioneryView/Program.cs | 2 +- .../ConfectioneryView/ReportOrders.rdlc | 572 ++++++++++++++++++ 11 files changed, 905 insertions(+), 3 deletions(-) create mode 100644 Confectionery/ConfectioneryView/FormReportOrders.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormReportOrders.cs create mode 100644 Confectionery/ConfectioneryView/FormReportOrders.resx create mode 100644 Confectionery/ConfectioneryView/ReportOrders.rdlc diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ReportOrdersViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ReportOrdersViewModel.cs index 88e4738..3521275 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/ReportOrdersViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/ReportOrdersViewModel.cs @@ -12,5 +12,6 @@ namespace ConfectioneryContracts.ViewModels public DateTime DateCreate { get; set; } public string PastryName { get; set; } = string.Empty; public double Sum { get; set; } + public string Status { get; set; } = string.Empty; } } diff --git a/Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj b/Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj index 41b6c3e..778307f 100644 --- a/Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj +++ b/Confectionery/ConfectioneryFileImplement/ConfectioneryFileImplement.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj index 48a2e81..f7206a4 100644 --- a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj +++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj @@ -8,6 +8,7 @@ + diff --git a/Confectionery/ConfectioneryView/ConfectioneryView.csproj b/Confectionery/ConfectioneryView/ConfectioneryView.csproj index ce7d654..88f69ae 100644 --- a/Confectionery/ConfectioneryView/ConfectioneryView.csproj +++ b/Confectionery/ConfectioneryView/ConfectioneryView.csproj @@ -13,7 +13,9 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + @@ -23,4 +25,9 @@ + + + + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index 658ef3b..fdff896 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -100,6 +100,7 @@ componentsListToolStripMenuItem.Name = "componentsListToolStripMenuItem"; componentsListToolStripMenuItem.Size = new Size(327, 34); componentsListToolStripMenuItem.Text = "Список компонентов"; + componentsListToolStripMenuItem.Click += componentsListToolStripMenuItem_Click; // // componentPastryToolStripMenuItem // diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index d2d1aee..8e93937 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -16,7 +16,7 @@ namespace ConfectioneryView public partial class FormMain : Form { private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; + private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) @@ -168,11 +168,30 @@ namespace ConfectioneryView { form.ShowDialog(); } + } private void ordersListToolStripMenuItem_Click(object sender, EventArgs e) { - + var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } + + 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); + } } } } diff --git a/Confectionery/ConfectioneryView/FormReportOrders.Designer.cs b/Confectionery/ConfectioneryView/FormReportOrders.Designer.cs new file mode 100644 index 0000000..7262b61 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormReportOrders.Designer.cs @@ -0,0 +1,130 @@ +namespace ConfectioneryView +{ + 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() + { + panel = new Panel(); + buttonToPdf = new Button(); + buttonMake = new Button(); + dateTimePickerTo = new DateTimePicker(); + labelTo = new Label(); + dateTimePickerFrom = new DateTimePicker(); + labelFrom = new Label(); + panel.SuspendLayout(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonToPdf); + panel.Controls.Add(buttonMake); + panel.Controls.Add(dateTimePickerTo); + panel.Controls.Add(labelTo); + panel.Controls.Add(dateTimePickerFrom); + panel.Controls.Add(labelFrom); + panel.Location = new Point(0, 0); + panel.Name = "panel"; + panel.Size = new Size(1332, 69); + panel.TabIndex = 0; + // + // buttonToPdf + // + buttonToPdf.Location = new Point(1094, 12); + buttonToPdf.Name = "buttonToPdf"; + buttonToPdf.Size = new Size(156, 45); + buttonToPdf.TabIndex = 5; + buttonToPdf.Text = "В PDF"; + buttonToPdf.UseVisualStyleBackColor = true; + buttonToPdf.Click += buttonToPdf_Click; + // + // buttonMake + // + buttonMake.Location = new Point(800, 12); + buttonMake.Name = "buttonMake"; + buttonMake.Size = new Size(189, 48); + buttonMake.TabIndex = 4; + buttonMake.Text = "Сформировать"; + buttonMake.UseVisualStyleBackColor = true; + buttonMake.Click += buttonMake_Click; + // + // dateTimePickerTo + // + dateTimePickerTo.Location = new Point(447, 21); + dateTimePickerTo.Name = "dateTimePickerTo"; + dateTimePickerTo.Size = new Size(300, 31); + dateTimePickerTo.TabIndex = 3; + // + // labelTo + // + labelTo.AutoSize = true; + labelTo.Location = new Point(399, 26); + labelTo.Name = "labelTo"; + labelTo.Size = new Size(33, 25); + labelTo.TabIndex = 2; + labelTo.Text = "по"; + // + // dateTimePickerFrom + // + dateTimePickerFrom.Location = new Point(80, 21); + dateTimePickerFrom.Name = "dateTimePickerFrom"; + dateTimePickerFrom.Size = new Size(300, 31); + dateTimePickerFrom.TabIndex = 1; + // + // labelFrom + // + labelFrom.AutoSize = true; + labelFrom.Location = new Point(39, 26); + labelFrom.Name = "labelFrom"; + labelFrom.Size = new Size(23, 25); + labelFrom.TabIndex = 0; + labelFrom.Text = "С"; + // + // FormReportOrders + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1331, 465); + Controls.Add(panel); + Name = "FormReportOrders"; + Text = "Заказы"; + panel.ResumeLayout(false); + panel.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private TextBox textBox1; + private Label labelFrom; + private Button buttonToPdf; + private Button buttonMake; + private DateTimePicker dateTimePickerTo; + private Label labelTo; + private DateTimePicker dateTimePickerFrom; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormReportOrders.cs b/Confectionery/ConfectioneryView/FormReportOrders.cs new file mode 100644 index 0000000..d03cd6f --- /dev/null +++ b/Confectionery/ConfectioneryView/FormReportOrders.cs @@ -0,0 +1,107 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +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 ConfectioneryView +{ + 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/Confectionery/ConfectioneryView/FormReportOrders.resx b/Confectionery/ConfectioneryView/FormReportOrders.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormReportOrders.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index 74a30b4..50617db 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -52,7 +52,7 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); - //services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/ReportOrders.rdlc b/Confectionery/ConfectioneryView/ReportOrders.rdlc new file mode 100644 index 0000000..6b3375b --- /dev/null +++ b/Confectionery/ConfectioneryView/ReportOrders.rdlc @@ -0,0 +1,572 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + ConfectioneryContractsViewModels + /* Local Query */ + + + + Id + System.Int32 + + + DateCreate + System.DateTime + + + PastryName + System.String + + + Sum + System.Decimal + + + Status + System.String + + + + ConfectioneryContracts.ViewModels + ReportOrdersViewModel + ConfectioneryContracts.ViewModels.ReportOrdersViewModel, ConfectioneryContracts, 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!PastryName.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 +