From 19cebdffb2862e3bbc23ca6c79e53b47b6f7fd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D1=91=D0=BD=D0=B0=20=D0=A4=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0?= Date: Wed, 18 Dec 2024 16:37:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectHorseRacing/Entities/BuyHorse.cs | 11 ++ .../Entities/BuyHorseHorse.cs | 7 +- .../Entities/TempBuyHorseHorse.cs | 16 ++ .../ProjectHorseRacing/Forms/FormBuyHorse.cs | 2 +- .../Forms/FormOwnerHorsesReport.Designer.cs | 168 ++++++++++++++++++ .../Forms/FormOwnerHorsesReport.cs | 80 +++++++++ .../Repositories/IBuyHorseRepository.cs | 2 +- 7 files changed, 282 insertions(+), 4 deletions(-) create mode 100644 ProjectHorseRacing/ProjectHorseRacing/Entities/TempBuyHorseHorse.cs create mode 100644 ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwnerHorsesReport.Designer.cs create mode 100644 ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwnerHorsesReport.cs diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorse.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorse.cs index 5269f89..436354d 100644 --- a/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorse.cs +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorse.cs @@ -24,4 +24,15 @@ public class BuyHorse BuyHorseHorses = buyHorseHorses }; } + + public static BuyHorse CreateEntity(TempBuyHorseHorse tempBuyHorseHorse, IEnumerable buyHorseHorses) + { + return new BuyHorse + { + Id = tempBuyHorseHorse.Id, + OwnersId = tempBuyHorseHorse.OwnersId, + DatePurchase = tempBuyHorseHorse.DatePurchase, + BuyHorseHorses = buyHorseHorses + }; + } } diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorseHorse.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorseHorse.cs index f8d653a..39582d4 100644 --- a/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorseHorse.cs +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorseHorse.cs @@ -13,12 +13,15 @@ public class BuyHorseHorse public int HorseId { get; private set; } - public static BuyHorseHorse CreateElement(int id, int horseId) + public int Cost { get; private set; } + + public static BuyHorseHorse CreateElement(int id, int horseId, int cost) { return new BuyHorseHorse { Id = id, - HorseId = horseId + HorseId = horseId, + Cost = cost }; } } diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/TempBuyHorseHorse.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/TempBuyHorseHorse.cs new file mode 100644 index 0000000..42ace9f --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/TempBuyHorseHorse.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Entities; + +public class TempBuyHorseHorse +{ + public int Id { get; private set; } + public int OwnersId { get; private set; } + public DateTime DatePurchase { get; private set; } + public int HorseId { get; private set; } + public int Cost { get; private set; } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.cs index 68f7c75..c524223 100644 --- a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.cs +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.cs @@ -58,7 +58,7 @@ public partial class FormBuyHorse : Form } list.Add(BuyHorseHorse.CreateElement( 0, - Convert.ToInt32(row.Cells["ColumnHorse"].Value))); + Convert.ToInt32(row.Cells["ColumnHorse"].Value),1)); } return list; } diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwnerHorsesReport.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwnerHorsesReport.Designer.cs new file mode 100644 index 0000000..596af49 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwnerHorsesReport.Designer.cs @@ -0,0 +1,168 @@ +namespace ProjectHorseRacing.Forms +{ + partial class FormOwnerHorsesReport + { + /// + /// 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() + { + label4 = new Label(); + label3 = new Label(); + label2 = new Label(); + label1 = new Label(); + buttonBuild = new Button(); + buttonFile = new Button(); + textBoxFilePath = new TextBox(); + comboBoxOwner = new ComboBox(); + dateTimePickerStart = new DateTimePicker(); + dateTimePickerEnd = new DateTimePicker(); + SuspendLayout(); + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(33, 193); + label4.Name = "label4"; + label4.Size = new Size(90, 20); + label4.TabIndex = 29; + label4.Text = "Дата конца:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(33, 144); + label3.Name = "label3"; + label3.Size = new Size(97, 20); + label3.TabIndex = 28; + label3.Text = "Дата начала:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(33, 88); + label2.Name = "label2"; + label2.Size = new Size(78, 20); + label2.TabIndex = 27; + label2.Text = "Владелец:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(33, 36); + label1.Name = "label1"; + label1.Size = new Size(112, 20); + label1.TabIndex = 26; + label1.Text = "Путь до файла:"; + // + // buttonBuild + // + buttonBuild.Location = new Point(33, 246); + buttonBuild.Margin = new Padding(3, 4, 3, 4); + buttonBuild.Name = "buttonBuild"; + buttonBuild.Size = new Size(338, 31); + buttonBuild.TabIndex = 25; + buttonBuild.Text = "Сформировать"; + buttonBuild.UseVisualStyleBackColor = true; + buttonBuild.Click += buttonBuild_Click; + // + // buttonFile + // + buttonFile.Location = new Point(339, 32); + buttonFile.Margin = new Padding(3, 4, 3, 4); + buttonFile.Name = "buttonFile"; + buttonFile.Size = new Size(30, 31); + buttonFile.TabIndex = 24; + buttonFile.Text = "..."; + buttonFile.UseVisualStyleBackColor = true; + buttonFile.Click += buttonFile_Click; + // + // textBoxFilePath + // + textBoxFilePath.Location = new Point(143, 32); + textBoxFilePath.Margin = new Padding(3, 4, 3, 4); + textBoxFilePath.Name = "textBoxFilePath"; + textBoxFilePath.Size = new Size(189, 27); + textBoxFilePath.TabIndex = 23; + // + // comboBoxOwner + // + comboBoxOwner.FormattingEnabled = true; + comboBoxOwner.Location = new Point(143, 84); + comboBoxOwner.Margin = new Padding(3, 4, 3, 4); + comboBoxOwner.Name = "comboBoxOwner"; + comboBoxOwner.Size = new Size(226, 28); + comboBoxOwner.TabIndex = 22; + // + // dateTimePickerStart + // + dateTimePickerStart.Location = new Point(143, 137); + dateTimePickerStart.Margin = new Padding(3, 4, 3, 4); + dateTimePickerStart.Name = "dateTimePickerStart"; + dateTimePickerStart.Size = new Size(228, 27); + dateTimePickerStart.TabIndex = 21; + // + // dateTimePickerEnd + // + dateTimePickerEnd.Location = new Point(143, 188); + dateTimePickerEnd.Margin = new Padding(3, 4, 3, 4); + dateTimePickerEnd.Name = "dateTimePickerEnd"; + dateTimePickerEnd.Size = new Size(228, 27); + dateTimePickerEnd.TabIndex = 20; + // + // FormOwnerHorsesReport + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(413, 298); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonBuild); + Controls.Add(buttonFile); + Controls.Add(textBoxFilePath); + Controls.Add(comboBoxOwner); + Controls.Add(dateTimePickerStart); + Controls.Add(dateTimePickerEnd); + Name = "FormOwnerHorsesReport"; + Text = "Отчет по покупке лошадей"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label4; + private Label label3; + private Label label2; + private Label label1; + private Button buttonBuild; + private Button buttonFile; + private TextBox textBoxFilePath; + private ComboBox comboBoxOwner; + private DateTimePicker dateTimePickerStart; + private DateTimePicker dateTimePickerEnd; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwnerHorsesReport.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwnerHorsesReport.cs new file mode 100644 index 0000000..31b5390 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwnerHorsesReport.cs @@ -0,0 +1,80 @@ +using ProjectHorseRacing.Reports; +using ProjectHorseRacing.Repositories; +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 ProjectHorseRacing.Forms +{ + public partial class FormOwnerHorsesReport : Form + { + private readonly IUnityContainer _container; + + public FormOwnerHorsesReport(IUnityContainer container, IOwnerRepository ownerRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + + comboBoxOwner.DataSource = ownerRepository.ReadOwners(); + comboBoxOwner.DisplayMember = "LastName"; + comboBoxOwner.ValueMember = "Id"; + } + + private void buttonBuild_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFilePath.Text)) + { + throw new Exception("Отсутствует имя файла для отчета"); + } + if (comboBoxOwner.SelectedIndex < 0) + { + throw new Exception("Не выбран корм"); + } + if (dateTimePickerEnd.Value <= dateTimePickerStart.Value) + { + throw new Exception("Дата начала должна быть раньше даты окончания"); + } + if (_container.Resolve().CreateTable(textBoxFilePath.Text, 4, (int)comboBoxOwner.SelectedValue!, dateTimePickerStart.Value, dateTimePickerEnd.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); + } + } + + private void buttonFile_Click(object sender, EventArgs e) + { + var sfd = new SaveFileDialog() + { + Filter = "Excel Files | *.xlsx" + }; + if (sfd.ShowDialog() != DialogResult.OK) + { + return; + } + textBoxFilePath.Text = sfd.FileName; + } + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/IBuyHorseRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IBuyHorseRepository.cs index 3f861a2..42eec87 100644 --- a/ProjectHorseRacing/ProjectHorseRacing/Repositories/IBuyHorseRepository.cs +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IBuyHorseRepository.cs @@ -9,7 +9,7 @@ namespace ProjectHorseRacing.Repositories; public interface IBuyHorseRepository { - IEnumerable ReadBuyHorse(); + IEnumerable ReadBuyHorse(DateTime? dateForm = null, DateTime? dateTo = null, int? ownersId = null); void CreateBuyHorse(BuyHorse buyHorse);