76 lines
3.0 KiB
C#
76 lines
3.0 KiB
C#
|
using AutomobilePlantContracts.BindingModels;
|
|||
|
using AutomobilePlantContracts.BusinessLogicsContracts;
|
|||
|
using Microsoft.Extensions.Logging;
|
|||
|
using Microsoft.Reporting.WinForms;
|
|||
|
|
|||
|
namespace AutomobilePlantView
|
|||
|
{
|
|||
|
public partial class FormReportDateOrders : Form
|
|||
|
{
|
|||
|
private readonly ReportViewer reportViewer;
|
|||
|
private readonly ILogger _logger;
|
|||
|
private readonly IReportLogic _logic;
|
|||
|
private readonly FileStream _fileStream;
|
|||
|
public FormReportDateOrders(ILogger<FormReportDateOrders> logger, IReportLogic reportLogic)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_logger = logger;
|
|||
|
_logic = reportLogic;
|
|||
|
reportViewer = new ReportViewer
|
|||
|
{
|
|||
|
Dock = DockStyle.Fill
|
|||
|
};
|
|||
|
_fileStream = new FileStream("ReportOrdersByDate.rdlc", FileMode.Open);
|
|||
|
reportViewer.LocalReport.LoadReportDefinition(_fileStream);
|
|||
|
Controls.Clear();
|
|||
|
Controls.Add(reportViewer);
|
|||
|
Controls.Add(panel);
|
|||
|
}
|
|||
|
|
|||
|
private void buttonMake_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var dataSource = _logic.GetDateOrders();
|
|||
|
var source = new ReportDataSource("DataSetOrders", dataSource);
|
|||
|
reportViewer.LocalReport.DataSources.Clear();
|
|||
|
reportViewer.LocalReport.DataSources.Add(source);
|
|||
|
reportViewer.RefreshReport();
|
|||
|
_logger.LogInformation("Загрузка списка заказов на весь период по датам");
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка загрузки списка заказов на период");
|
|||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void buttonToPDF_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" };
|
|||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_logic.SaveDateOrdersToPdfFile(new ReportBindingModel
|
|||
|
{
|
|||
|
FileName = dialog.FileName
|
|||
|
});
|
|||
|
_logger.LogInformation("Сохранение списка заказов на весь период по датам");
|
|||
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка сохранения списка заказов на период");
|
|||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void FormReportDateOrders_FormClosed(object sender, FormClosedEventArgs e)
|
|||
|
{
|
|||
|
_fileStream.Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|