s
This commit is contained in:
parent
a0db0595f1
commit
51d95da83b
@ -28,12 +28,135 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "FormAccessoriesReport";
|
||||
dateTimePickerDateEnd = new DateTimePicker();
|
||||
dateTimePickerDateBegin = new DateTimePicker();
|
||||
textBoxFilePath = new TextBox();
|
||||
buttonSelectFilePath = new Button();
|
||||
comboBoxAccessories = new ComboBox();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
label3 = new Label();
|
||||
label4 = new Label();
|
||||
buttonMakeReport = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dateTimePickerDateEnd
|
||||
//
|
||||
dateTimePickerDateEnd.Location = new Point(173, 232);
|
||||
dateTimePickerDateEnd.Name = "dateTimePickerDateEnd";
|
||||
dateTimePickerDateEnd.Size = new Size(200, 23);
|
||||
dateTimePickerDateEnd.TabIndex = 0;
|
||||
//
|
||||
// dateTimePickerDateBegin
|
||||
//
|
||||
dateTimePickerDateBegin.Location = new Point(173, 192);
|
||||
dateTimePickerDateBegin.Name = "dateTimePickerDateBegin";
|
||||
dateTimePickerDateBegin.Size = new Size(200, 23);
|
||||
dateTimePickerDateBegin.TabIndex = 1;
|
||||
//
|
||||
// textBoxFilePath
|
||||
//
|
||||
textBoxFilePath.Location = new Point(173, 81);
|
||||
textBoxFilePath.Name = "textBoxFilePath";
|
||||
textBoxFilePath.Size = new Size(168, 23);
|
||||
textBoxFilePath.TabIndex = 2;
|
||||
//
|
||||
// buttonSelectFilePath
|
||||
//
|
||||
buttonSelectFilePath.Location = new Point(347, 81);
|
||||
buttonSelectFilePath.Name = "buttonSelectFilePath";
|
||||
buttonSelectFilePath.Size = new Size(26, 23);
|
||||
buttonSelectFilePath.TabIndex = 3;
|
||||
buttonSelectFilePath.Text = "button1";
|
||||
buttonSelectFilePath.UseVisualStyleBackColor = true;
|
||||
buttonSelectFilePath.Click += ButtonSelectFilePath_Click;
|
||||
//
|
||||
// comboBoxAccessories
|
||||
//
|
||||
comboBoxAccessories.FormattingEnabled = true;
|
||||
comboBoxAccessories.Location = new Point(173, 138);
|
||||
comboBoxAccessories.Name = "comboBoxAccessories";
|
||||
comboBoxAccessories.Size = new Size(200, 23);
|
||||
comboBoxAccessories.TabIndex = 4;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(60, 84);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(38, 15);
|
||||
label1.TabIndex = 5;
|
||||
label1.Text = "label1";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(60, 141);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(38, 15);
|
||||
label2.TabIndex = 6;
|
||||
label2.Text = "label2";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(60, 198);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(38, 15);
|
||||
label3.TabIndex = 7;
|
||||
label3.Text = "label3";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(60, 238);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(38, 15);
|
||||
label4.TabIndex = 8;
|
||||
label4.Text = "label4";
|
||||
//
|
||||
// buttonMakeReport
|
||||
//
|
||||
buttonMakeReport.Location = new Point(153, 317);
|
||||
buttonMakeReport.Name = "buttonMakeReport";
|
||||
buttonMakeReport.Size = new Size(75, 23);
|
||||
buttonMakeReport.TabIndex = 9;
|
||||
buttonMakeReport.Text = "button2";
|
||||
buttonMakeReport.UseVisualStyleBackColor = true;
|
||||
buttonMakeReport.Click += ButtonMakeReport_Click;
|
||||
//
|
||||
// FormAccessoriesReport
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonMakeReport);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(comboBoxAccessories);
|
||||
Controls.Add(buttonSelectFilePath);
|
||||
Controls.Add(textBoxFilePath);
|
||||
Controls.Add(dateTimePickerDateBegin);
|
||||
Controls.Add(dateTimePickerDateEnd);
|
||||
Name = "FormAccessoriesReport";
|
||||
Text = "FormAccessoriesReport";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DateTimePicker dateTimePickerDateEnd;
|
||||
private DateTimePicker dateTimePickerDateBegin;
|
||||
private TextBox textBoxFilePath;
|
||||
private Button buttonSelectFilePath;
|
||||
private ComboBox comboBoxAccessories;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Label label3;
|
||||
private Label label4;
|
||||
private Button buttonMakeReport;
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using ProjectCompRepair.Reports;
|
||||
using ProjectCompRepair.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -15,13 +16,13 @@ namespace ProjectCompRepair.Forms;
|
||||
public partial class FormAccessoriesReport : Form
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
public FormAccessoriesReport()
|
||||
public FormAccessoriesReport(IUnityContainer container, IAccessoriesRepository accessoriesRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
comboBoxFeed.DataSource = feedRepository.ReadFeeds();
|
||||
comboBoxFeed.DisplayMember = "Name";
|
||||
comboBoxFeed.ValueMember = "Id";
|
||||
comboBoxAccessories.DataSource = accessoriesRepository.ReadAccessories();
|
||||
comboBoxAccessories.DisplayMember = "Name";
|
||||
comboBoxAccessories.ValueMember = "Id";
|
||||
|
||||
}
|
||||
private void ButtonSelectFilePath_Click(object sender, EventArgs e)
|
||||
@ -48,7 +49,7 @@ public partial class FormAccessoriesReport : Form
|
||||
throw new Exception("Отсутствует имя файла для отчета");
|
||||
}
|
||||
|
||||
if (comboBoxFeed.SelectedIndex < 0)
|
||||
if (comboBoxAccessories.SelectedIndex < 0)
|
||||
{
|
||||
throw new Exception("Не выбран корм");
|
||||
}
|
||||
@ -58,7 +59,7 @@ public partial class FormAccessoriesReport : Form
|
||||
throw new Exception("Дата начала должна быть раньше даты окончания");
|
||||
}
|
||||
|
||||
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, (int)comboBoxFeed.SelectedValue!, dateTimePickerDateBegin.Value, dateTimePickerDateEnd.Value))
|
||||
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, (int)comboBoxAccessories.SelectedValue!, dateTimePickerDateBegin.Value, dateTimePickerDateEnd.Value))
|
||||
{
|
||||
MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
@ -1,47 +1,47 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCompRepair.Reports;
|
||||
//namespace ProjectCompRepair.Reports;
|
||||
|
||||
internal class ChartReport
|
||||
{
|
||||
private readonly IFeedingAnimalRepository _feedingAnimalRepository;
|
||||
private readonly ILogger<ChartReport> _logger;
|
||||
//internal class ChartReport
|
||||
//{
|
||||
// private readonly IFeedingAnimalRepository _feedingAnimalRepository;
|
||||
// private readonly ILogger<ChartReport> _logger;
|
||||
|
||||
public ChartReport(IFeedingAnimalRepository feedingAnimalRepository, ILogger<ChartReport> logger)
|
||||
{
|
||||
_feedingAnimalRepository = feedingAnimalRepository ?? throw new ArgumentNullException(nameof(feedingAnimalRepository));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
// public ChartReport(IFeedingAnimalRepository feedingAnimalRepository, ILogger<ChartReport> logger)
|
||||
// {
|
||||
// _feedingAnimalRepository = feedingAnimalRepository ?? throw new ArgumentNullException(nameof(feedingAnimalRepository));
|
||||
// _logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
// }
|
||||
|
||||
public bool CreateChart(string filePath, DateTime dateTime)
|
||||
{
|
||||
try
|
||||
{
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Питание животных")
|
||||
.AddPieChart("Выданные корма", GetData(dateTime))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// public bool CreateChart(string filePath, DateTime dateTime)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// new PdfBuilder(filePath)
|
||||
// .AddHeader("Питание животных")
|
||||
// .AddPieChart("Выданные корма", GetData(dateTime))
|
||||
// .Build();
|
||||
// return true;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// _logger.LogError(ex, "Ошибка при формировании документа");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
return _feedingAnimalRepository
|
||||
.ReadFeedingAnimals()
|
||||
.Where(x => x.FeedingDate.Date == dateTime.Date)
|
||||
.GroupBy(x => x.AnimalId, (key, group) => new { Id = key, Count = group.Sum(x => x.Ration) })
|
||||
.Select(x => (x.Id.ToString(), (double)x.Count))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
// private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
// {
|
||||
// return _feedingAnimalRepository
|
||||
// .ReadFeedingAnimals()
|
||||
// .Where(x => x.FeedingDate.Date == dateTime.Date)
|
||||
// .GroupBy(x => x.AnimalId, (key, group) => new { Id = key, Count = group.Sum(x => x.Ration) })
|
||||
// .Select(x => (x.Id.ToString(), (double)x.Count))
|
||||
// .ToList();
|
||||
// }
|
||||
//}
|
Loading…
Reference in New Issue
Block a user