Lab4Magic #13

Closed
Serxionaft wants to merge 1 commits from Lab4 into Lab4-Hard
2 changed files with 199 additions and 199 deletions

View File

@ -1,129 +1,129 @@
namespace SewingDressesView
{
partial class ReportOrdersForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
partial class ReportOrdersForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
panel = new Panel();
buttonPdf = new Button();
buttonCreate = new Button();
dateTimePickerTo = new DateTimePicker();
label2 = new Label();
dateTimePickerFrom = new DateTimePicker();
label1 = new Label();
panel.SuspendLayout();
SuspendLayout();
//
// panel
//
panel.Controls.Add(buttonPdf);
panel.Controls.Add(buttonCreate);
panel.Controls.Add(dateTimePickerTo);
panel.Controls.Add(label2);
panel.Controls.Add(dateTimePickerFrom);
panel.Controls.Add(label1);
panel.Location = new Point(-1, -1);
panel.Name = "panel";
panel.Size = new Size(1060, 59);
panel.TabIndex = 0;
//
// buttonPdf
//
buttonPdf.Location = new Point(905, 15);
buttonPdf.Name = "buttonPdf";
buttonPdf.Size = new Size(144, 29);
buttonPdf.TabIndex = 5;
buttonPdf.Text = "В Pdf";
buttonPdf.UseVisualStyleBackColor = true;
buttonPdf.Click += ButtonToPdf_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(656, 16);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(144, 29);
buttonCreate.TabIndex = 4;
buttonCreate.Text = "Сформировать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonMake_Click;
//
// dateTimePickerTo
//
dateTimePickerTo.Location = new Point(367, 15);
dateTimePickerTo.Name = "dateTimePickerTo";
dateTimePickerTo.Size = new Size(250, 27);
dateTimePickerTo.TabIndex = 3;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(320, 18);
label2.Name = "label2";
label2.Size = new Size(27, 20);
label2.TabIndex = 2;
label2.Text = "по";
//
// dateTimePickerFrom
//
dateTimePickerFrom.Location = new Point(37, 15);
dateTimePickerFrom.Name = "dateTimePickerFrom";
dateTimePickerFrom.Size = new Size(250, 27);
dateTimePickerFrom.TabIndex = 1;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(13, 20);
label1.Name = "label1";
label1.Size = new Size(18, 20);
label1.TabIndex = 0;
label1.Text = "С";
//
// ReportOrdersForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1060, 450);
Controls.Add(panel);
Name = "ReportOrdersForm";
Text = "ReportOrtdersForm";
panel.ResumeLayout(false);
panel.PerformLayout();
ResumeLayout(false);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
panel = new Panel();
buttonPdf = new Button();
buttonCreate = new Button();
dateTimePickerTo = new DateTimePicker();
label2 = new Label();
dateTimePickerFrom = new DateTimePicker();
label1 = new Label();
panel.SuspendLayout();
SuspendLayout();
//
// panel
//
panel.Controls.Add(buttonPdf);
panel.Controls.Add(buttonCreate);
panel.Controls.Add(dateTimePickerTo);
panel.Controls.Add(label2);
panel.Controls.Add(dateTimePickerFrom);
panel.Controls.Add(label1);
panel.Location = new Point(-1, -1);
panel.Name = "panel";
panel.Size = new Size(1060, 59);
panel.TabIndex = 0;
//
// buttonPdf
//
buttonPdf.Location = new Point(905, 15);
buttonPdf.Name = "buttonPdf";
buttonPdf.Size = new Size(144, 29);
buttonPdf.TabIndex = 5;
buttonPdf.Text = "В Pdf";
buttonPdf.UseVisualStyleBackColor = true;
buttonPdf.Click += ButtonToPdf_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(656, 16);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(144, 29);
buttonCreate.TabIndex = 4;
buttonCreate.Text = "Сформировать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonMake_Click;
//
// dateTimePickerTo
//
dateTimePickerTo.Location = new Point(367, 15);
dateTimePickerTo.Name = "dateTimePickerTo";
dateTimePickerTo.Size = new Size(250, 27);
dateTimePickerTo.TabIndex = 3;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(320, 18);
label2.Name = "label2";
label2.Size = new Size(27, 20);
label2.TabIndex = 2;
label2.Text = "по";
//
// dateTimePickerFrom
//
dateTimePickerFrom.Location = new Point(37, 15);
dateTimePickerFrom.Name = "dateTimePickerFrom";
dateTimePickerFrom.Size = new Size(250, 27);
dateTimePickerFrom.TabIndex = 1;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(13, 20);
label1.Name = "label1";
label1.Size = new Size(18, 20);
label1.TabIndex = 0;
label1.Text = "С";
//
// ReportOrdersForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1060, 450);
Controls.Add(panel);
Name = "ReportOrdersForm";
Text = "Форма отчетов по заказам";
panel.ResumeLayout(false);
panel.PerformLayout();
ResumeLayout(false);
}
#endregion
#endregion
private Panel panel;
private Label label1;
private Button buttonPdf;
private Button buttonCreate;
private DateTimePicker dateTimePickerTo;
private Label label2;
private DateTimePicker dateTimePickerFrom;
}
private Panel panel;
private Label label1;
private Button buttonPdf;
private Button buttonCreate;
private DateTimePicker dateTimePickerTo;
private Label label2;
private DateTimePicker dateTimePickerFrom;
}
}

View File

@ -5,88 +5,88 @@ using Microsoft.Reporting.WinForms;
namespace SewingDressesView
{
public partial class ReportOrdersForm : Form
{
private readonly ReportViewer reportViewer;
public partial class ReportOrdersForm : Form
{
private readonly ReportViewer reportViewer;
private readonly ILogger _logger;
private readonly ILogger _logger;
private readonly IReportLogic _logic;
private readonly IReportLogic _logic;
public ReportOrdersForm(ILogger<ReportOrdersForm> logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
reportViewer = new ReportViewer
{
Dock = DockStyle.Fill
};
var path = Directory.GetParent(Directory.GetCurrentDirectory())?.Parent?.Parent?.ToString() + "\\ReportOrders.rdlc";
reportViewer.LocalReport.LoadReportDefinition(new FileStream(path, FileMode.Open));
Controls.Clear();
Controls.Add(panel);
Controls.Add(reportViewer);
}
public ReportOrdersForm(ILogger<ReportOrdersForm> logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
reportViewer = new ReportViewer
{
Dock = DockStyle.Fill
};
var path = Directory.GetParent(Directory.GetCurrentDirectory())?.Parent?.Parent?.ToString() + "\\ReportOrders.rdlc";
reportViewer.LocalReport.LoadReportDefinition(new FileStream(path, FileMode.Open));
Controls.Clear();
Controls.Add(panel);
Controls.Add(reportViewer);
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 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);
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);
}
}
}
}
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);
}
}
}
}
}