Upload files to 'ShipyardView'
This commit is contained in:
parent
b3bb77e0b6
commit
e2c082a374
@ -1,5 +1,6 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ShipyardContracts.BindingModels;
|
||||
using ShipyardContracts.BusinessLogicContracts;
|
||||
using ShipyardContracts.BusinessLogicsContracts;
|
||||
using ShipyardDataModels.Enums;
|
||||
using ShipyardView;
|
||||
@ -11,11 +12,13 @@ namespace ShipyardView
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
||||
private readonly IReportLogic _reportLogic;
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
_reportLogic = reportLogic;
|
||||
}
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
@ -161,9 +164,36 @@ namespace ShipyardView
|
||||
};
|
||||
}
|
||||
|
||||
private void shipToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void ComponentListToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_reportLogic.SaveShipsToWordFile(new ReportBindingModel
|
||||
{
|
||||
FileName = dialog.FileName
|
||||
});
|
||||
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
|
||||
private void ComponentsShipToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportShipComponents));
|
||||
if (service is FormReportShipComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void OrderListToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
|
||||
if (service is FormReportOrders form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
92
ShipyardView/FormReportOrders.cs
Normal file
92
ShipyardView/FormReportOrders.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ShipyardContracts.BindingModels;
|
||||
using ShipyardContracts.BusinessLogicContracts;
|
||||
using Microsoft.Reporting.WinForms;
|
||||
|
||||
namespace ShipyardView
|
||||
{
|
||||
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("ReportOrder.rdlc", FileMode.Open));
|
||||
panelReport.Controls.Add(reportViewer);
|
||||
}
|
||||
|
||||
private void MakeButton_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user