2024-03-24 18:34:06 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Reporting.WinForms;
|
|
|
|
|
using SushiBarContracts.BindingModel;
|
|
|
|
|
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.Reports
|
|
|
|
|
{
|
|
|
|
|
public partial class FormReportOrders : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ReportViewer reportViewer;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IReportLogic _logic;
|
|
|
|
|
public FormReportOrders(ILogger<FormReportOrders> logger, IReportLogic logic)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
reportViewer = new ReportViewer
|
|
|
|
|
{
|
|
|
|
|
Dock = DockStyle.Fill
|
|
|
|
|
};
|
2024-03-24 20:42:18 +04:00
|
|
|
|
var path = Directory.GetParent(Directory.GetCurrentDirectory())?.Parent?.Parent?.ToString() + "\\ReportOrders.rdlc";
|
|
|
|
|
reportViewer.LocalReport.LoadReportDefinition(new FileStream(path, FileMode.Open));
|
|
|
|
|
//reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrders.rdlc", FileMode.Open));
|
2024-03-24 18:34:06 +04:00
|
|
|
|
Controls.Clear();
|
|
|
|
|
Controls.Add(reportViewer);
|
|
|
|
|
Controls.Add(panel);
|
|
|
|
|
}
|
|
|
|
|
private void ButtonMake_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dateTimePickerDateFrom.Value.Date >= dateTimePickerDateTo.Value.Date)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Дата начала должна быть меньше даты окончания",
|
|
|
|
|
"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var dataSource = _logic.GetOrders(new ReportBindingModel
|
|
|
|
|
{
|
|
|
|
|
DateFrom = dateTimePickerDateFrom.Value,
|
|
|
|
|
DateTo = dateTimePickerDateTo.Value
|
|
|
|
|
});
|
|
|
|
|
var source = new ReportDataSource("DataSetOrders", dataSource);
|
|
|
|
|
reportViewer.LocalReport.DataSources.Clear();
|
|
|
|
|
reportViewer.LocalReport.DataSources.Add(source);
|
|
|
|
|
var parameters = new[] { new ReportParameter("ReportParameterPeriod",
|
2024-03-24 20:42:18 +04:00
|
|
|
|
$"c {dateTimePickerDateFrom.Value.ToShortDateString()} по {dateTimePickerDateTo.Value.ToShortDateString()}")
|
2024-03-24 18:34:06 +04:00
|
|
|
|
};
|
|
|
|
|
reportViewer.LocalReport.SetParameters(parameters);
|
|
|
|
|
reportViewer.RefreshReport();
|
2024-03-24 20:42:18 +04:00
|
|
|
|
_logger.LogInformation("Загрузка списка заказов на период {From}-{To}",
|
2024-03-24 18:34:06 +04:00
|
|
|
|
dateTimePickerDateFrom.Value.ToShortDateString(), dateTimePickerDateTo.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 (dateTimePickerDateFrom.Value.Date >= dateTimePickerDateTo.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 = dateTimePickerDateFrom.Value,
|
|
|
|
|
DateTo = dateTimePickerDateTo.Value
|
|
|
|
|
});
|
2024-03-24 20:42:18 +04:00
|
|
|
|
_logger.LogInformation("Сохранение списка заказов на период {From}-{To} ",
|
2024-03-24 18:34:06 +04:00
|
|
|
|
dateTimePickerDateFrom.Value.ToShortDateString(), dateTimePickerDateTo.Value.ToShortDateString());
|
|
|
|
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка сохранения списка заказов на период");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|