106 lines
4.2 KiB
C#
106 lines
4.2 KiB
C#
|
using DressAtelierContracts.BusinessLogicContracts;
|
|||
|
using Microsoft.Extensions.Logging;
|
|||
|
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 Microsoft.Reporting.WinForms;
|
|||
|
using DressAtelierContracts.BindingModels;
|
|||
|
|
|||
|
namespace SewingDresses
|
|||
|
{
|
|||
|
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
|
|||
|
};
|
|||
|
reportViewer.LocalReport.LoadReportDefinition(new
|
|||
|
FileStream("ReportOrders.rdlc", FileMode.Open));
|
|||
|
Controls.Clear();
|
|||
|
Controls.Add(reportViewer);
|
|||
|
Controls.Add(panelFunctional);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void buttonGenerate_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
|
|||
|
{
|
|||
|
MessageBox.Show("Beginning date should be less than finishind date", "Error", 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", $"From {dateTimePickerFrom.Value.ToShortDateString()} to {dateTimePickerTo.Value.ToShortDateString()}") };
|
|||
|
reportViewer.LocalReport.SetParameters(parameters);
|
|||
|
reportViewer.RefreshReport();
|
|||
|
_logger.LogInformation("Downloading list of orders by period {From}-{ To}", dateTimePickerFrom.Value.ToShortDateString(),dateTimePickerTo.Value.ToShortDateString());
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Downloading list of orders by specific period error");
|
|||
|
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
|
|||
|
MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void buttonSaveToPdf_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
|
|||
|
{
|
|||
|
MessageBox.Show("Beginning date should be less than finishind date","Error", 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("Saving list of orders for period { From }-{ To }", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString());
|
|||
|
MessageBox.Show("Done", "Success", MessageBoxButtons.OK,MessageBoxIcon.Information);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ошибка сохранения списка заказов на период");
|
|||
|
|
|||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|