diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs index a0eed76..75972c4 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs @@ -14,10 +14,10 @@ public class AccessoiresOrder public int Count { get; private set; } - public DateTime Date { get; private set; } + - public static AccessoiresOrder CreateElement(int id, int orderId, int count, DateTime date) + public static AccessoiresOrder CreateElement(int id, int orderId, int count) { - return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count, Date = DateTime.Now}; + return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count}; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs b/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs index 230cfd5..382ccc8 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs @@ -17,14 +17,17 @@ public class Accessories public float Price { get; private set; } - public static Accessories CreateEntity(int id, AccessoriesType accessoriesType, int count, float price) + public DateTime Date { get; private set; } + + public static Accessories CreateEntity(int id, AccessoriesType accessoriesType, int count, float price, DateTime date) { return new Accessories { Id = id, AccessoriesType = accessoriesType, Count = count, - Price = price + Price = price, + Date = date }; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs index d9d5320..b51429f 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs @@ -28,6 +28,8 @@ buttonCreate = new Button(); buttonCancel = new Button(); comboBoxType = new ComboBox(); + labelDate = new Label(); + dateTimePickerAccessories = new DateTimePicker(); ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); SuspendLayout(); @@ -36,9 +38,9 @@ // labelType.Anchor = AnchorStyles.Right; labelType.AutoSize = true; - labelType.Location = new Point(54, 75); + labelType.Location = new Point(47, 56); labelType.Name = "labelType"; - labelType.Size = new Size(158, 20); + labelType.Size = new Size(128, 15); labelType.TabIndex = 0; labelType.Text = "Вид комплектующего"; // @@ -46,9 +48,9 @@ // labelCount.Anchor = AnchorStyles.Right; labelCount.AutoSize = true; - labelCount.Location = new Point(54, 152); + labelCount.Location = new Point(47, 114); labelCount.Name = "labelCount"; - labelCount.Size = new Size(98, 20); + labelCount.Size = new Size(79, 15); labelCount.TabIndex = 2; labelCount.Text = "Колличество"; // @@ -56,9 +58,9 @@ // labelPrice.Anchor = AnchorStyles.Right; labelPrice.AutoSize = true; - labelPrice.Location = new Point(54, 231); + labelPrice.Location = new Point(47, 173); labelPrice.Name = "labelPrice"; - labelPrice.Size = new Size(45, 20); + labelPrice.Size = new Size(35, 15); labelPrice.TabIndex = 4; labelPrice.Text = "Цена"; // @@ -66,29 +68,26 @@ // numericUpDownPrice.Anchor = AnchorStyles.Right; numericUpDownPrice.DecimalPlaces = 2; - numericUpDownPrice.Location = new Point(252, 235); - numericUpDownPrice.Margin = new Padding(3, 4, 3, 4); + numericUpDownPrice.Location = new Point(220, 176); numericUpDownPrice.Name = "numericUpDownPrice"; - numericUpDownPrice.Size = new Size(119, 27); + numericUpDownPrice.Size = new Size(104, 23); numericUpDownPrice.TabIndex = 5; // // numericUpDownCount // numericUpDownCount.Anchor = AnchorStyles.Right; - numericUpDownCount.Location = new Point(252, 156); - numericUpDownCount.Margin = new Padding(3, 4, 3, 4); + numericUpDownCount.Location = new Point(220, 117); numericUpDownCount.Name = "numericUpDownCount"; - numericUpDownCount.Size = new Size(119, 27); + numericUpDownCount.Size = new Size(104, 23); numericUpDownCount.TabIndex = 6; // // buttonCreate // buttonCreate.AllowDrop = true; buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(53, 417); - buttonCreate.Margin = new Padding(3, 4, 3, 4); + buttonCreate.Location = new Point(46, 313); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(98, 33); + buttonCreate.Size = new Size(86, 25); buttonCreate.TabIndex = 8; buttonCreate.Text = "Сохранить"; buttonCreate.UseVisualStyleBackColor = true; @@ -97,10 +96,9 @@ // buttonCancel // buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(310, 416); - buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Location = new Point(271, 312); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(101, 31); + buttonCancel.Size = new Size(88, 23); buttonCancel.TabIndex = 10; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -109,19 +107,38 @@ // comboBoxType // comboBoxType.FormattingEnabled = true; - comboBoxType.Location = new Point(250, 78); + comboBoxType.Location = new Point(219, 58); + comboBoxType.Margin = new Padding(3, 2, 3, 2); comboBoxType.Name = "comboBoxType"; - comboBoxType.Size = new Size(151, 28); + comboBoxType.Size = new Size(133, 23); comboBoxType.TabIndex = 11; // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(47, 234); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(68, 15); + labelDate.TabIndex = 12; + labelDate.Text = "Поступили"; + // + // dateTimePickerAccessories + // + dateTimePickerAccessories.Location = new Point(220, 234); + dateTimePickerAccessories.Name = "dateTimePickerAccessories"; + dateTimePickerAccessories.Size = new Size(132, 23); + dateTimePickerAccessories.TabIndex = 13; + // // FormAccessorie // AllowDrop = true; - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; AutoSizeMode = AutoSizeMode.GrowAndShrink; AutoValidate = AutoValidate.EnableAllowFocusChange; - ClientSize = new Size(448, 478); + ClientSize = new Size(392, 358); + Controls.Add(dateTimePickerAccessories); + Controls.Add(labelDate); Controls.Add(comboBoxType); Controls.Add(buttonCancel); Controls.Add(buttonCreate); @@ -130,7 +147,6 @@ Controls.Add(labelPrice); Controls.Add(labelCount); Controls.Add(labelType); - Margin = new Padding(3, 4, 3, 4); Name = "FormAccessorie"; Text = "Комплектующое"; ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); @@ -150,5 +166,7 @@ private Button buttonUpdate; private Button buttonCancel; private ComboBox comboBoxType; + private Label labelDate; + private DateTimePicker dateTimePickerAccessories; } } \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs index 8e26b42..6372d92 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs @@ -31,7 +31,8 @@ namespace ProjectCompRepair.Forms { throw new InvalidOperationException(nameof(accessorie)); } - + + dateTimePickerAccessories.Value = accessorie.Date; numericUpDownCount.Value = accessorie.Count; numericUpDownPrice.Value = (int)accessorie.Price; _accessorieId = value; @@ -79,7 +80,7 @@ namespace ProjectCompRepair.Forms private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - private Accessories CreateAccessories(int id) => Accessories.CreateEntity(id, (AccessoriesType)comboBoxType.SelectedItem! , (int)numericUpDownCount.Value, (float)numericUpDownPrice.Value); + private Accessories CreateAccessories(int id) => Accessories.CreateEntity(id, (AccessoriesType)comboBoxType.SelectedItem! , (int)numericUpDownCount.Value, (float)numericUpDownPrice.Value, dateTimePickerAccessories.Value); } diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs new file mode 100644 index 0000000..52af124 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.Designer.cs @@ -0,0 +1,39 @@ +namespace ProjectCompRepair.Forms +{ + partial class FormAccessoriesReport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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"; + } + + #endregion + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs new file mode 100644 index 0000000..5e0f881 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.cs @@ -0,0 +1,75 @@ +using ProjectCompRepair.Reports; +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 Unity; + +namespace ProjectCompRepair.Forms; + +public partial class FormAccessoriesReport : Form +{ + private readonly IUnityContainer _container; + public FormAccessoriesReport() + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + comboBoxFeed.DataSource = feedRepository.ReadFeeds(); + comboBoxFeed.DisplayMember = "Name"; + comboBoxFeed.ValueMember = "Id"; + + } + private void ButtonSelectFilePath_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Excel Files | *.xlsx" + }; + + if (sfd.ShowDialog() != DialogResult.OK) + { + return; + } + + textBoxFilePath.Text = sfd.FileName; + } + + private void ButtonMakeReport_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFilePath.Text)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + + if (comboBoxFeed.SelectedIndex < 0) + { + throw new Exception("Не выбран корм"); + } + + if (dateTimePickerDateEnd.Value <= dateTimePickerDateBegin.Value) + { + throw new Exception("Дата начала должна быть раньше даты окончания"); + } + + if (_container.Resolve().CreateTable(textBoxFilePath.Text, (int)comboBoxFeed.SelectedValue!, dateTimePickerDateBegin.Value, dateTimePickerDateEnd.Value)) + { + MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } +} diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.resx b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessoriesReport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs index c53dc9e..a9110fd 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs @@ -55,74 +55,79 @@ // labelName // labelName.AutoSize = true; - labelName.Location = new Point(19, 35); + labelName.Location = new Point(17, 26); labelName.Name = "labelName"; - labelName.Size = new Size(77, 20); + labelName.Size = new Size(59, 15); labelName.TabIndex = 0; labelName.Text = "Название"; // // labelComent // labelComent.AutoSize = true; - labelComent.Location = new Point(19, 109); + labelComent.Location = new Point(17, 82); labelComent.Name = "labelComent"; - labelComent.Size = new Size(79, 20); + labelComent.Size = new Size(62, 15); labelComent.TabIndex = 1; labelComent.Text = "Описание"; // // textBoxComent // - textBoxComent.Location = new Point(208, 81); + textBoxComent.Location = new Point(182, 61); + textBoxComent.Margin = new Padding(3, 2, 3, 2); textBoxComent.Multiline = true; textBoxComent.Name = "textBoxComent"; - textBoxComent.Size = new Size(125, 72); + textBoxComent.Size = new Size(110, 55); textBoxComent.TabIndex = 2; // // textBoxName // - textBoxName.Location = new Point(208, 28); + textBoxName.Location = new Point(182, 21); + textBoxName.Margin = new Padding(3, 2, 3, 2); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(125, 27); + textBoxName.Size = new Size(110, 23); textBoxName.TabIndex = 3; // // labelDate // labelDate.AutoSize = true; - labelDate.Location = new Point(19, 192); + labelDate.Location = new Point(17, 144); labelDate.Name = "labelDate"; - labelDate.Size = new Size(183, 20); + labelDate.Size = new Size(142, 15); labelDate.TabIndex = 4; labelDate.Text = "Дата регистрации заказа"; // // dateTimePicker // - dateTimePicker.Location = new Point(208, 192); + dateTimePicker.Location = new Point(182, 144); + dateTimePicker.Margin = new Padding(3, 2, 3, 2); dateTimePicker.Name = "dateTimePicker"; - dateTimePicker.Size = new Size(192, 27); + dateTimePicker.Size = new Size(168, 23); dateTimePicker.TabIndex = 5; // // comboBoxMaster // comboBoxMaster.FormattingEnabled = true; - comboBoxMaster.Location = new Point(208, 254); + comboBoxMaster.Location = new Point(182, 190); + comboBoxMaster.Margin = new Padding(3, 2, 3, 2); comboBoxMaster.Name = "comboBoxMaster"; - comboBoxMaster.Size = new Size(151, 28); + comboBoxMaster.Size = new Size(133, 23); comboBoxMaster.TabIndex = 6; // // labelMaster // labelMaster.AutoSize = true; - labelMaster.Location = new Point(21, 262); + labelMaster.Location = new Point(18, 196); labelMaster.Name = "labelMaster"; - labelMaster.Size = new Size(60, 20); + labelMaster.Size = new Size(48, 15); labelMaster.TabIndex = 7; labelMaster.Text = "Мастер"; // // buttonSave // - buttonSave.Location = new Point(35, 389); + buttonSave.Location = new Point(31, 292); + buttonSave.Margin = new Padding(3, 2, 3, 2); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(94, 29); + buttonSave.Size = new Size(82, 22); buttonSave.TabIndex = 8; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; @@ -130,9 +135,10 @@ // // buttonCancel // - buttonCancel.Location = new Point(1077, 389); + buttonCancel.Location = new Point(942, 292); + buttonCancel.Margin = new Padding(3, 2, 3, 2); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(94, 29); + buttonCancel.Size = new Size(82, 22); buttonCancel.TabIndex = 9; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -141,9 +147,11 @@ // groupBox1 // groupBox1.Controls.Add(dataGridViewAccessories); - groupBox1.Location = new Point(449, 35); + groupBox1.Location = new Point(393, 26); + groupBox1.Margin = new Padding(3, 2, 3, 2); groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(309, 247); + groupBox1.Padding = new Padding(3, 2, 3, 2); + groupBox1.Size = new Size(270, 183); groupBox1.TabIndex = 10; groupBox1.TabStop = false; groupBox1.Text = "Комплектующие"; @@ -153,10 +161,11 @@ dataGridViewAccessories.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridViewAccessories.Columns.AddRange(new DataGridViewColumn[] { ColumnAccessories, ColumnCount }); dataGridViewAccessories.Dock = DockStyle.Fill; - dataGridViewAccessories.Location = new Point(3, 23); + dataGridViewAccessories.Location = new Point(3, 18); + dataGridViewAccessories.Margin = new Padding(3, 2, 3, 2); dataGridViewAccessories.Name = "dataGridViewAccessories"; dataGridViewAccessories.RowHeadersWidth = 51; - dataGridViewAccessories.Size = new Size(303, 221); + dataGridViewAccessories.Size = new Size(264, 163); dataGridViewAccessories.TabIndex = 0; // // ColumnAccessories @@ -176,9 +185,11 @@ // groupBoxServices // groupBoxServices.Controls.Add(dataGridViewServices); - groupBoxServices.Location = new Point(789, 35); + groupBoxServices.Location = new Point(690, 26); + groupBoxServices.Margin = new Padding(3, 2, 3, 2); groupBoxServices.Name = "groupBoxServices"; - groupBoxServices.Size = new Size(310, 247); + groupBoxServices.Padding = new Padding(3, 2, 3, 2); + groupBoxServices.Size = new Size(271, 185); groupBoxServices.TabIndex = 11; groupBoxServices.TabStop = false; groupBoxServices.Text = "Услуги"; @@ -188,10 +199,11 @@ dataGridViewServices.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridViewServices.Columns.AddRange(new DataGridViewColumn[] { ColumnService, ColumnCountServ }); dataGridViewServices.Dock = DockStyle.Fill; - dataGridViewServices.Location = new Point(3, 23); + dataGridViewServices.Location = new Point(3, 18); + dataGridViewServices.Margin = new Padding(3, 2, 3, 2); dataGridViewServices.Name = "dataGridViewServices"; dataGridViewServices.RowHeadersWidth = 51; - dataGridViewServices.Size = new Size(304, 221); + dataGridViewServices.Size = new Size(265, 165); dataGridViewServices.TabIndex = 0; // // ColumnService @@ -210,9 +222,9 @@ // // FormOrder // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1183, 430); + ClientSize = new Size(1035, 322); Controls.Add(groupBoxServices); Controls.Add(groupBox1); Controls.Add(buttonCancel); @@ -225,6 +237,7 @@ Controls.Add(textBoxComent); Controls.Add(labelComent); Controls.Add(labelName); + Margin = new Padding(3, 2, 3, 2); Name = "FormOrder"; Text = "Заказ"; groupBox1.ResumeLayout(false); diff --git a/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj b/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj index 7eadc6a..9c35c14 100644 --- a/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj +++ b/ProjectCompRepair/ProjectCompRepair/ProjectCompRepair.csproj @@ -16,6 +16,7 @@ + diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs b/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs new file mode 100644 index 0000000..60c5226 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Reports/ChartReport.cs @@ -0,0 +1,47 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Reports; + +internal class ChartReport +{ + private readonly IFeedingAnimalRepository _feedingAnimalRepository; + private readonly ILogger _logger; + + public ChartReport(IFeedingAnimalRepository feedingAnimalRepository, ILogger 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; + } + } + + 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(); + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/PdfBuilder.cs b/ProjectCompRepair/ProjectCompRepair/Reports/PdfBuilder.cs new file mode 100644 index 0000000..3e27b22 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Reports/PdfBuilder.cs @@ -0,0 +1,87 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Shapes.Charts; +using MigraDoc.Rendering; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Reports; + +internal class PdfBuilder +{ + private readonly string _filePath; + private readonly Document _document; + + public PdfBuilder(string filePath) + { + if (string.IsNullOrWhiteSpace(filePath)) + { + throw new ArgumentNullException(nameof(filePath)); + } + + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + + _filePath = filePath; + _document = new Document(); + DefineStyles(); + } + + public PdfBuilder AddHeader(string header) + { + _document.AddSection().AddParagraph(header, "NormalBold"); + return this; + } + + public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data) + { + if (data == null || data.Count == 0) + { + return this; + } + + var chart = new Chart(ChartType.Pie2D); + var series = chart.SeriesCollection.AddSeries(); + series.Add(data.Select(x => x.Value).ToArray()); + + var xseries = chart.XValues.AddXSeries(); + xseries.Add(data.Select(x => x.Caption).ToArray()); + + chart.DataLabel.Type = DataLabelType.Percent; + chart.DataLabel.Position = DataLabelPosition.OutsideEnd; + chart.Width = Unit.FromCentimeter(16); + chart.Height = Unit.FromCentimeter(12); + chart.TopArea.AddParagraph(title); + chart.XAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.MajorTickMark = TickMarkType.Outside; + chart.YAxis.HasMajorGridlines = true; + chart.PlotArea.LineFormat.Width = 1; + chart.PlotArea.LineFormat.Visible = true; + chart.TopArea.AddLegend(); + + _document.LastSection.Add(chart); + return this; + } + + public void Build() + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + + renderer.RenderDocument(); + renderer.PdfDocument.Save(_filePath); + } + + private void DefineStyles() + { + var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal"); + headerStyle.Font.Bold = true; + headerStyle.Font.Size = 14; + } +} diff --git a/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs b/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs index 8d475cf..65a6828 100644 --- a/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs +++ b/ProjectCompRepair/ProjectCompRepair/Reports/TableReport.cs @@ -12,15 +12,15 @@ namespace ProjectCompRepair.Reports; internal class TableReport { private readonly IOrderRepository _orderRepository; - private readonly IAccessoriesOrderRepository _accessoriesOrdersRepository; + private readonly IAccessoriesRepository _accessoriesRepository; private readonly ILogger _logger; - internal static readonly string[] item = ["Сотрудник", "Дата", "Тип комплектующего", "кол-во"]; + internal static readonly string[] item = ["Дата", "Тип комплектующего", "кол-во"]; - public TableReport(IOrderRepository orderRepository, IAccessoriesOrderRepository accessoriesOrdersRepository, ILogger logger) + public TableReport(IOrderRepository orderRepository, IAccessoriesRepository accessoriesRepository, ILogger logger) { _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); - _accessoriesOrdersRepository = accessoriesOrdersRepository ?? throw new ArgumentNullException(nameof(accessoriesOrdersRepository)); + _accessoriesRepository = accessoriesRepository ?? throw new ArgumentNullException(nameof(accessoriesRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } @@ -44,21 +44,20 @@ internal class TableReport private List GetData(int accessoriesId, DateTime startDate, DateTime endDate) { - var data = _feedReplenishmentRepository - .ReadFeedReplenishment() - .Where(x => x.DateReceipt >= startDate && x.DateReceipt <= endDate && x.FeedFeedReplenishments.Any(y => y.FeedId == feedId)) - .Select(x => new { x.EmployeeId, Date = x.DateReceipt, CountIn = x.FeedFeedReplenishments.FirstOrDefault(y => y.FeedId == feedId)?.Count, CountOut = (int?)null }) + var data = _orderRepository.ReadOrder() + .Where(x => x.Date >= startDate && x.Date <= endDate && x.AccessoiresOrders.Any(y => y.Id == accessoriesId)) + .Select(x => new {Date = x.Date, CountIn = x.AccessoiresOrders.FirstOrDefault(y => y.Id == accessoriesId)?.Count, CountOut = (int?)null }) .Union( - _feedingAnimalRepository - .ReadFeedingAnimals() - .Where(x => x.FeedingDate >= startDate && x.FeedingDate <= endDate && x.FeedId == feedId) - .Select(x => new { x.EmployeeId, Date = x.FeedingDate, CountIn = (int?)null, CountOut = (int?)x.Ration })) + _accessoriesRepository + .ReadAccessories() + .Where(x => x.Date >= startDate && x.Date <= endDate && x.Id == accessoriesId) + .Select(x => new {Date = x.Date, CountIn = (int?)null, CountOut = (int?)x.Count })) .OrderBy(x => x.Date); return new List() { item } .Union( data - .Select(x => new string[] { x.EmployeeId.ToString(), x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) + .Select(x => new string[] { x.Date.ToString(), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) .Union( [["Всего", "", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]]) .ToList(); diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs new file mode 100644 index 0000000..0784b36 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesOrderRepository.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Repositories.Implemantations; + +public class AccessoriesOrderRepository +{ + +} diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs index 6fbab98..aa3fbd4 100644 --- a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs +++ b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs @@ -35,8 +35,8 @@ public class AccessoriesRepository : IAccessoriesRepository connection.Open(); var queryInsert = @" -INSERT INTO Accessories (AccessoriesType, Count, Price) -VALUES (@AccessoriesType, @Count, @Price)"; +INSERT INTO Accessories (AccessoriesType, Count, Price, Date) +VALUES (@AccessoriesType, @Count, @Price, @Date)"; connection.Execute(queryInsert, accessories); } catch (Exception ex) @@ -58,7 +58,8 @@ VALUES (@AccessoriesType, @Count, @Price)"; SET AccessoriesType = @AccessoriesType, Count = @Count, - Price = @Price + Price = @Price, + Date = @Date WHERE ID = @Id;"; connection.Execute(queryUpdate, accessories); }