Compare commits

..

7 Commits

Author SHA1 Message Date
mara-1
20215be662 улучшения 2 и 3 2024-12-24 21:26:31 +04:00
mara-1
dfb8ee759f исправление ошибок по таблице(жирный шрифт) Excel 2024-12-13 13:23:32 +04:00
mara-1
596f40441a третий шаг 2024-12-13 03:15:49 +04:00
mara-1
0ed0d71bc8 Второй шаг 2024-12-13 02:07:58 +04:00
mara-1
e64555709f первый шаг 2024-12-13 02:05:06 +04:00
mara-1
4656445077 LabWork02 2024-12-12 03:21:18 +04:00
mara-1
a369e88614 LabWork01 2024-12-11 19:40:18 +04:00
81 changed files with 6943 additions and 77 deletions

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Entities.Enums;
public enum JockeyTitle
{
None = 0,
FirstCategory = 1,
SecondCategory = 2,
Master = 3
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Entities.Enums;
[Flags]
public enum RaceType
{
None = 0,
Dressage = 1,
Concourse = 2,
Triathlon = 4,
HorseRun = 8
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Entities;
public class Horse
{
public int Id { get; private set; }
[DisplayName("Вид")]
public string HorseSpecies { get; private set; } = string.Empty;
[DisplayName("Кличка")]
public string HorseNickName { get; private set; } = string.Empty;
public string FullName => $"{HorseSpecies} {HorseNickName}";
[DisplayName("Возраст")]
public int Age { get; private set; }
[DisplayName("Вес")]
public double Weight { get; private set; }
public static Horse CreateEntity(int id, string horseSpecies, string
horseNickName, int age, double weight)
{
return new Horse
{
Id = id,
HorseSpecies = horseSpecies ?? string.Empty,
HorseNickName = horseNickName ?? string.Empty,
Age = age,
Weight = weight
};
}
}

View File

@ -0,0 +1,38 @@
using ProjectHorseRacingOrg.Entities.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Entities;
public class Jockey
{
public int Id { get; private set; }
[DisplayName("Имя")]
public string FirstName { get; private set; } = string.Empty;
[DisplayName("Фамилия")]
public string LastName { get; private set; } = string.Empty;
public string FullName => $"{LastName} {FirstName}";
[DisplayName("Титул")]
public JockeyTitle JockeyTitle { get; private set; }
public static Jockey CreateEntity(int id, string first, string last,
JockeyTitle jockeyTitle)
{
return new Jockey
{
Id = id,
FirstName = first ?? string.Empty,
LastName = last ?? string.Empty,
JockeyTitle = jockeyTitle
};
}
}

View File

@ -0,0 +1,36 @@
using Microsoft.VisualBasic.FileIO;
using ProjectHorseRacingOrg.Entities.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Entities;
public class Race
{
public int Id { get; private set; }
[DisplayName("Тип соревнований")]
public RaceType RaceType { get; private set; }
[DisplayName("Название")]
public string Name { get; private set; } = string.Empty;
[DisplayName("Описание")]
public string Description { get; private set; } = string.Empty;
public static Race CreateEntity(int id, RaceType raceType, string name, string description)
{
return new Race
{
Id = id,
RaceType = raceType,
Name = name ?? string.Empty,
Description = description ?? string.Empty
};
}
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Entities;
public class RaceEntries
{
public int Id { get; private set; }
[Browsable(false)]
public int JockeyId { get; private set; }
[DisplayName("Жокей")]
public string JockeyName { get; private set; } = string.Empty;
[DisplayName("Дата соревнований")]
public DateTime DateReceipt { get; private set; }
[DisplayName("Соревнования")]
public string Feed => RacesEntryDetails != null ?
string.Join(", ", RacesEntryDetails.Select(x => $"{x.RaceName} {x.Count}")) : string.Empty;
[Browsable(false)]
public IEnumerable<RaceEntryDetails> RacesEntryDetails { get; private set;} = [];
public static RaceEntries CreateOpeartion(int id, int jockeyId,
IEnumerable<RaceEntryDetails> racesEntryDetails)
{
return new RaceEntries
{
Id = id,
JockeyId = jockeyId,
DateReceipt = DateTime.Now,
RacesEntryDetails = racesEntryDetails
};
}
public void SetRacesEntryDetails(IEnumerable<RaceEntryDetails> racesEntryDetails)
{
if (racesEntryDetails != null && racesEntryDetails.Any())
{
RacesEntryDetails = racesEntryDetails;
}
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Entities;
public class RaceEntryDetails
{
public int Id { get; private set; }
public int RaceId { get; private set; }
public int Count { get; private set; }
public string RaceName { get; private set; } = string.Empty;
public static RaceEntryDetails CreateElement(int id, int raceId, int
count)
{
return new RaceEntryDetails
{
Id = id,
RaceId = raceId,
Count = count
};
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Entities;
public class RacingHorses
{
public int Id { get; private set; }
[Browsable(false)]
public int RaceId { get; private set; }
[Browsable(false)]
public int JockeyId { get; private set; }
[Browsable(false)]
public int HorseId { get; private set; }
[DisplayName("Соревнование")]
public string RaceName { get; private set; } = string.Empty;
[DisplayName("Жокей")]
public string JockeyName { get; private set; } = string.Empty;
[DisplayName("Лошадь")]
public string HorseName { get; private set; } = string.Empty;
[DisplayName("Дата соревнования")]
public DateTime RacingDate { get; private set; }
[DisplayName("результаты место")]
public int Result { get; private set; }
public static RacingHorses CreateOpeartion(int id, int raceId, int
jockeyId, int horseId, int result)
{
return new RacingHorses
{
Id = id,
RaceId = raceId,
JockeyId = jockeyId,
HorseId = horseId,
RacingDate = DateTime.Now,
Result = result
};
}
}

View File

@ -1,39 +0,0 @@
namespace ProjectHorseRacingOrg
{
partial class Form1
{
/// <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);
}
#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()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace ProjectHorseRacingOrg
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,168 @@
namespace ProjectHorseRacingOrg
{
partial class FormHorseRacing
{
/// <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);
}
#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()
{
menuStrip1 = new MenuStrip();
ReferencesToolStripMenuItem = new ToolStripMenuItem();
JockeysToolStripMenuItem = new ToolStripMenuItem();
HorsesToolStripMenuItem = new ToolStripMenuItem();
RacesToolStripMenuItem = new ToolStripMenuItem();
OperationsToolStripMenuItem = new ToolStripMenuItem();
RacingHorsesToolStripMenuItem = new ToolStripMenuItem();
RaceEntryDetalisToolStripMenuItem = new ToolStripMenuItem();
ReportsToolStripMenuItem = new ToolStripMenuItem();
DirectoryReportToolStripMenuItem = new ToolStripMenuItem();
raceReportToolStripMenuItem = new ToolStripMenuItem();
raceDistributionToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { ReferencesToolStripMenuItem, OperationsToolStripMenuItem, ReportsToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(800, 28);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip";
//
// ReferencesToolStripMenuItem
//
ReferencesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { JockeysToolStripMenuItem, HorsesToolStripMenuItem, RacesToolStripMenuItem });
ReferencesToolStripMenuItem.Name = "ReferencesToolStripMenuItem";
ReferencesToolStripMenuItem.Size = new Size(117, 24);
ReferencesToolStripMenuItem.Text = "Справочники";
//
// JockeysToolStripMenuItem
//
JockeysToolStripMenuItem.Name = "JockeysToolStripMenuItem";
JockeysToolStripMenuItem.Size = new Size(195, 26);
JockeysToolStripMenuItem.Text = "Жокеи";
JockeysToolStripMenuItem.Click += JockeysToolStripMenuItem_Click;
//
// HorsesToolStripMenuItem
//
HorsesToolStripMenuItem.Name = "HorsesToolStripMenuItem";
HorsesToolStripMenuItem.Size = new Size(195, 26);
HorsesToolStripMenuItem.Text = "Лошади";
HorsesToolStripMenuItem.Click += HorsesToolStripMenuItem_Click;
//
// RacesToolStripMenuItem
//
RacesToolStripMenuItem.Name = "RacesToolStripMenuItem";
RacesToolStripMenuItem.Size = new Size(195, 26);
RacesToolStripMenuItem.Text = "Соревнования";
RacesToolStripMenuItem.Click += RacesToolStripMenuItem_Click;
//
// OperationsToolStripMenuItem
//
OperationsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { RacingHorsesToolStripMenuItem, RaceEntryDetalisToolStripMenuItem });
OperationsToolStripMenuItem.Name = "OperationsToolStripMenuItem";
OperationsToolStripMenuItem.Size = new Size(95, 24);
OperationsToolStripMenuItem.Text = "Операции";
//
// RacingHorsesToolStripMenuItem
//
RacingHorsesToolStripMenuItem.Name = "RacingHorsesToolStripMenuItem";
RacingHorsesToolStripMenuItem.Size = new Size(218, 26);
RacingHorsesToolStripMenuItem.Text = "Участие лошадей";
RacingHorsesToolStripMenuItem.Click += RacingHorsesToolStripMenuItem_Click;
//
// RaceEntryDetalisToolStripMenuItem
//
RaceEntryDetalisToolStripMenuItem.Name = "RaceEntryDetalisToolStripMenuItem";
RaceEntryDetalisToolStripMenuItem.Size = new Size(218, 26);
RaceEntryDetalisToolStripMenuItem.Text = "Заявки на участие";
RaceEntryDetalisToolStripMenuItem.Click += RaceEntryDetalisToolStripMenuItem_Click;
//
// ReportsToolStripMenuItem
//
ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, raceReportToolStripMenuItem, raceDistributionToolStripMenuItem });
ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem";
ReportsToolStripMenuItem.Size = new Size(73, 24);
ReportsToolStripMenuItem.Text = "Отчеты";
//
// DirectoryReportToolStripMenuItem
//
DirectoryReportToolStripMenuItem.Name = "DirectoryReportToolStripMenuItem";
DirectoryReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W;
DirectoryReportToolStripMenuItem.Size = new Size(355, 26);
DirectoryReportToolStripMenuItem.Text = "Документ со справочниками";
DirectoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click;
//
// raceReportToolStripMenuItem
//
raceReportToolStripMenuItem.Name = "raceReportToolStripMenuItem";
raceReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.E;
raceReportToolStripMenuItem.Size = new Size(355, 26);
raceReportToolStripMenuItem.Text = "Движение соревнований";
raceReportToolStripMenuItem.Click += RaceReportToolStripMenuItem_Click;
//
// raceDistributionToolStripMenuItem
//
raceDistributionToolStripMenuItem.Name = "raceDistributionToolStripMenuItem";
raceDistributionToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P;
raceDistributionToolStripMenuItem.Size = new Size(355, 26);
raceDistributionToolStripMenuItem.Text = "Распределение соревнований";
raceDistributionToolStripMenuItem.Click += RaceDistributionToolStripMenuItem_Click;
//
// FormHorseRacing
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
BackgroundImage = Properties.Resources.скачки;
BackgroundImageLayout = ImageLayout.Stretch;
ClientSize = new Size(800, 450);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Name = "FormHorseRacing";
Text = "Соревнования по конному спорту";
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem ReferencesToolStripMenuItem;
private ToolStripMenuItem JockeysToolStripMenuItem;
private ToolStripMenuItem HorsesToolStripMenuItem;
private ToolStripMenuItem RacesToolStripMenuItem;
private ToolStripMenuItem OperationsToolStripMenuItem;
private ToolStripMenuItem ReportsToolStripMenuItem;
private ToolStripMenuItem RacingHorsesToolStripMenuItem;
private ToolStripMenuItem RaceEntryDetalisToolStripMenuItem;
private ToolStripMenuItem DirectoryReportToolStripMenuItem;
private ToolStripMenuItem raceReportToolStripMenuItem;
private ToolStripMenuItem raceDistributionToolStripMenuItem;
}
}

View File

@ -0,0 +1,128 @@
using ProjectHorseRacingOrg.Forms;
using Unity;
namespace ProjectHorseRacingOrg
{
public partial class FormHorseRacing : Form
{
private readonly IUnityContainer _container;
public FormHorseRacing(IUnityContainer container)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
}
private void JockeysToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormJockeys>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void HorsesToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormHorses>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void RacesToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormRaces>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void RacingHorsesToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormRacingHorses>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void RaceEntryDetalisToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormRacesEntries>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void DirectoryReportToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormDirectoryReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void RaceReportToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormRaceReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void RaceDistributionToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormRaceEntryReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,99 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormDirectoryReport
{
/// <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);
}
#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()
{
checkBoxHorses = new CheckBox();
checkBoxJockeys = new CheckBox();
checkBoxRaces = new CheckBox();
buttonBuild = new Button();
SuspendLayout();
//
// checkBoxHorses
//
checkBoxHorses.AutoSize = true;
checkBoxHorses.Location = new Point(39, 33);
checkBoxHorses.Name = "checkBoxHorses";
checkBoxHorses.Size = new Size(87, 24);
checkBoxHorses.TabIndex = 0;
checkBoxHorses.Text = "Лошади";
checkBoxHorses.UseVisualStyleBackColor = true;
//
// checkBoxJockeys
//
checkBoxJockeys.AutoSize = true;
checkBoxJockeys.Location = new Point(39, 87);
checkBoxJockeys.Name = "checkBoxJockeys";
checkBoxJockeys.Size = new Size(77, 24);
checkBoxJockeys.TabIndex = 1;
checkBoxJockeys.Text = "Жокеи";
checkBoxJockeys.UseVisualStyleBackColor = true;
//
// checkBoxRaces
//
checkBoxRaces.AutoSize = true;
checkBoxRaces.Location = new Point(39, 147);
checkBoxRaces.Name = "checkBoxRaces";
checkBoxRaces.Size = new Size(134, 24);
checkBoxRaces.TabIndex = 2;
checkBoxRaces.Text = "Соревнование";
checkBoxRaces.UseVisualStyleBackColor = true;
//
// buttonBuild
//
buttonBuild.Location = new Point(212, 84);
buttonBuild.Name = "buttonBuild";
buttonBuild.Size = new Size(132, 29);
buttonBuild.TabIndex = 3;
buttonBuild.Text = "Сформировать";
buttonBuild.UseVisualStyleBackColor = true;
buttonBuild.Click += ButtonBuild_Click;
//
// FormDirectoryReport
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(412, 228);
Controls.Add(buttonBuild);
Controls.Add(checkBoxRaces);
Controls.Add(checkBoxJockeys);
Controls.Add(checkBoxHorses);
Name = "FormDirectoryReport";
Text = "FormDirectoryReport";
ResumeLayout(false);
PerformLayout();
}
#endregion
private CheckBox checkBoxHorses;
private CheckBox checkBoxJockeys;
private CheckBox checkBoxRaces;
private Button buttonBuild;
}
}

View File

@ -0,0 +1,62 @@
using ProjectHorseRacingOrg.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 ProjectHorseRacingOrg.Forms
{
public partial class FormDirectoryReport : Form
{
private readonly IUnityContainer _container;
public FormDirectoryReport(IUnityContainer container)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
}
private void ButtonBuild_Click(object sender, EventArgs e)
{
try
{
if (!checkBoxHorses.Checked && !checkBoxJockeys.Checked && !checkBoxRaces.Checked)
{
throw new Exception("Не выбран ни один справочник для выгрузки");
}
var sfd = new SaveFileDialog()
{
Filter = "Docx Files | *.docx"
};
if (sfd.ShowDialog() != DialogResult.OK)
{
throw new Exception("Не выбран файла для отчета");
}
if
(_container.Resolve<DocReport>().CreateDoc(sfd.FileName, checkBoxHorses.Checked,
checkBoxJockeys.Checked, checkBoxRaces.Checked))
{
MessageBox.Show("Документ сформирован",
"Формирование документа",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах",
"Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -0,0 +1,169 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormHorse
{
/// <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);
}
#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()
{
labeHorseSpecies = new Label();
textBoxHorseSpecies = new TextBox();
labelHorseNickName = new Label();
textBoxHorseNickName = new TextBox();
labelAge = new Label();
numericUpDownAge = new NumericUpDown();
labelWeight = new Label();
numericUpDownWeight = new NumericUpDown();
buttonSave = new Button();
buttonCancel = new Button();
((System.ComponentModel.ISupportInitialize)numericUpDownAge).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
SuspendLayout();
//
// labeHorseSpecies
//
labeHorseSpecies.AutoSize = true;
labeHorseSpecies.Location = new Point(55, 43);
labeHorseSpecies.Name = "labeHorseSpecies";
labeHorseSpecies.Size = new Size(96, 20);
labeHorseSpecies.TabIndex = 0;
labeHorseSpecies.Text = "Вид лошади:";
//
// textBoxHorseSpecies
//
textBoxHorseSpecies.Location = new Point(209, 40);
textBoxHorseSpecies.Name = "textBoxHorseSpecies";
textBoxHorseSpecies.Size = new Size(195, 27);
textBoxHorseSpecies.TabIndex = 1;
//
// labelHorseNickName
//
labelHorseNickName.AutoSize = true;
labelHorseNickName.Location = new Point(55, 115);
labelHorseNickName.Name = "labelHorseNickName";
labelHorseNickName.Size = new Size(119, 20);
labelHorseNickName.TabIndex = 2;
labelHorseNickName.Text = "Кличка лошади:";
//
// textBoxHorseNickName
//
textBoxHorseNickName.Location = new Point(209, 115);
textBoxHorseNickName.Name = "textBoxHorseNickName";
textBoxHorseNickName.Size = new Size(195, 27);
textBoxHorseNickName.TabIndex = 3;
//
// labelAge
//
labelAge.AutoSize = true;
labelAge.Location = new Point(55, 180);
labelAge.Name = "labelAge";
labelAge.Size = new Size(67, 20);
labelAge.TabIndex = 4;
labelAge.Text = "Возраст:";
//
// numericUpDownAge
//
numericUpDownAge.Location = new Point(209, 178);
numericUpDownAge.Name = "numericUpDownAge";
numericUpDownAge.Size = new Size(86, 27);
numericUpDownAge.TabIndex = 6;
//
// labelWeight
//
labelWeight.AutoSize = true;
labelWeight.Location = new Point(55, 247);
labelWeight.Name = "labelWeight";
labelWeight.Size = new Size(36, 20);
labelWeight.TabIndex = 7;
labelWeight.Text = "Вес:";
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(209, 245);
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownWeight.Minimum = new decimal(new int[] { 300, 0, 0, 0 });
numericUpDownWeight.Name = "numericUpDownWeight";
numericUpDownWeight.Size = new Size(86, 27);
numericUpDownWeight.TabIndex = 8;
numericUpDownWeight.Value = new decimal(new int[] { 300, 0, 0, 0 });
//
// buttonSave
//
buttonSave.Location = new Point(79, 309);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(108, 28);
buttonSave.TabIndex = 9;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(252, 309);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(112, 28);
buttonCancel.TabIndex = 10;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormHorse
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(450, 384);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(numericUpDownWeight);
Controls.Add(labelWeight);
Controls.Add(numericUpDownAge);
Controls.Add(labelAge);
Controls.Add(textBoxHorseNickName);
Controls.Add(labelHorseNickName);
Controls.Add(textBoxHorseSpecies);
Controls.Add(labeHorseSpecies);
Name = "FormHorse";
StartPosition = FormStartPosition.CenterParent;
Text = "Лошадь";
((System.ComponentModel.ISupportInitialize)numericUpDownAge).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labeHorseSpecies;
private TextBox textBoxHorseSpecies;
private Label labelHorseNickName;
private TextBox textBoxHorseNickName;
private Label labelAge;
private NumericUpDown numericUpDownAge;
private Label labelWeight;
private NumericUpDown numericUpDownWeight;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,91 @@
using ProjectHorseRacingOrg.Entities;
using ProjectHorseRacingOrg.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;
namespace ProjectHorseRacingOrg.Forms
{
public partial class FormHorse : Form
{
private readonly IHorseRepository _horseRepository;
private int? _horseId;
public int Id
{
set
{
try
{
var horse =
_horseRepository.ReadHorseById(value);
if (horse == null)
{
throw new
InvalidDataException(nameof(horse));
}
textBoxHorseSpecies.Text = horse.HorseSpecies;
textBoxHorseNickName.Text = horse.HorseNickName;
numericUpDownAge.Value = horse.Age;
numericUpDownWeight.Value =
(decimal)horse.Weight;
_horseId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormHorse(IHorseRepository horseRepository)
{
InitializeComponent();
_horseRepository = horseRepository ??
throw new
ArgumentNullException(nameof(horseRepository));
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxHorseSpecies.Text)
||
string.IsNullOrWhiteSpace(textBoxHorseNickName.Text))
{
throw new Exception("Имеются незаполненные поля");
}
if (_horseId.HasValue)
{
_horseRepository.UpdateHorse(CreateHorse(_horseId.Value));
}
else
{
_horseRepository.CreateHorse(CreateHorse(0));
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Horse CreateHorse(int id) => Horse.CreateEntity(id,
textBoxHorseSpecies.Text,
textBoxHorseNickName.Text,
Convert.ToInt32(numericUpDownAge.Value),
Convert.ToDouble(numericUpDownWeight.Value));
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,125 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormHorses
{
/// <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);
}
#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()
{
buttonAdd = new Button();
buttonUpd = new Button();
buttonDel = new Button();
flowLayoutPanel = new FlowLayoutPanel();
dataGridViewData = new DataGridView();
flowLayoutPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
SuspendLayout();
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.Добавить;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(3, 3);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(114, 96);
buttonAdd.TabIndex = 1;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.изменить;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(3, 105);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(114, 96);
buttonUpd.TabIndex = 2;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.удалить;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(3, 207);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(114, 96);
buttonDel.TabIndex = 3;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// flowLayoutPanel
//
flowLayoutPanel.Controls.Add(buttonAdd);
flowLayoutPanel.Controls.Add(buttonUpd);
flowLayoutPanel.Controls.Add(buttonDel);
flowLayoutPanel.Dock = DockStyle.Right;
flowLayoutPanel.Location = new Point(648, 0);
flowLayoutPanel.Name = "flowLayoutPanel";
flowLayoutPanel.Size = new Size(152, 450);
flowLayoutPanel.TabIndex = 4;
//
// dataGridViewData
//
dataGridViewData.AllowUserToAddRows = false;
dataGridViewData.AllowUserToDeleteRows = false;
dataGridViewData.AllowUserToResizeColumns = false;
dataGridViewData.AllowUserToResizeRows = false;
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewData.Dock = DockStyle.Fill;
dataGridViewData.Location = new Point(0, 0);
dataGridViewData.MultiSelect = false;
dataGridViewData.Name = "dataGridViewData";
dataGridViewData.ReadOnly = true;
dataGridViewData.RowHeadersVisible = false;
dataGridViewData.RowHeadersWidth = 51;
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewData.Size = new Size(648, 450);
dataGridViewData.TabIndex = 5;
//
// FormHorses
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridViewData);
Controls.Add(flowLayoutPanel);
Name = "FormHorses";
Text = "Лошади";
Load += FormHorses_Load;
flowLayoutPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
ResumeLayout(false);
}
#endregion
private Button buttonAdd;
private Button buttonUpd;
private Button buttonDel;
private FlowLayoutPanel flowLayoutPanel;
private DataGridView dataGridViewData;
}
}

View File

@ -0,0 +1,119 @@
using ProjectHorseRacingOrg.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 ProjectHorseRacingOrg.Forms
{
public partial class FormHorses : Form
{
private readonly IUnityContainer _container;
private readonly IHorseRepository _horseRepository;
public FormHorses(IUnityContainer container, IHorseRepository
horseRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_horseRepository = horseRepository ??
throw new
ArgumentNullException(nameof(horseRepository));
}
private void FormHorses_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormHorse>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
try
{
var form = _container.Resolve<FormHorse>();
form.Id = findId;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление",
MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_horseRepository.DeleteHorse(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList()
{
dataGridViewData.DataSource = _horseRepository.ReadHorses();
dataGridViewData.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewData.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id =
Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
return true;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,141 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormJockey
{
/// <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);
}
#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()
{
comboBoxTitle = new ComboBox();
labelFirstName = new Label();
LastName = new Label();
labelJockeyTitle = new Label();
buttonSave = new Button();
buttonCancel = new Button();
textBoxFirstName = new TextBox();
textBoxLastName = new TextBox();
SuspendLayout();
//
// comboBoxTitle
//
comboBoxTitle.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxTitle.FormattingEnabled = true;
comboBoxTitle.Location = new Point(165, 155);
comboBoxTitle.Name = "comboBoxTitle";
comboBoxTitle.Size = new Size(151, 28);
comboBoxTitle.TabIndex = 0;
//
// labelFirstName
//
labelFirstName.AutoSize = true;
labelFirstName.Location = new Point(51, 52);
labelFirstName.Name = "labelFirstName";
labelFirstName.Size = new Size(42, 20);
labelFirstName.TabIndex = 1;
labelFirstName.Text = "Имя:";
//
// LastName
//
LastName.AutoSize = true;
LastName.Location = new Point(51, 102);
LastName.Name = "LastName";
LastName.Size = new Size(76, 20);
LastName.TabIndex = 2;
LastName.Text = "Фамилия:";
//
// labelJockeyTitle
//
labelJockeyTitle.AutoSize = true;
labelJockeyTitle.Location = new Point(51, 155);
labelJockeyTitle.Name = "labelJockeyTitle";
labelJockeyTitle.Size = new Size(62, 20);
labelJockeyTitle.TabIndex = 3;
labelJockeyTitle.Text = "Звание:";
//
// buttonSave
//
buttonSave.Location = new Point(69, 220);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 4;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(238, 220);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// textBoxFirstName
//
textBoxFirstName.Location = new Point(165, 52);
textBoxFirstName.Name = "textBoxFirstName";
textBoxFirstName.Size = new Size(222, 27);
textBoxFirstName.TabIndex = 6;
//
// textBoxLastName
//
textBoxLastName.Location = new Point(165, 102);
textBoxLastName.Name = "textBoxLastName";
textBoxLastName.Size = new Size(222, 27);
textBoxLastName.TabIndex = 7;
//
// FormJockey
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(424, 300);
Controls.Add(textBoxLastName);
Controls.Add(textBoxFirstName);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(labelJockeyTitle);
Controls.Add(LastName);
Controls.Add(labelFirstName);
Controls.Add(comboBoxTitle);
Name = "FormJockey";
Text = "Жокей";
ResumeLayout(false);
PerformLayout();
}
#endregion
private ComboBox comboBoxTitle;
private Label labelFirstName;
private Label LastName;
private Label labelJockeyTitle;
private Button buttonSave;
private Button buttonCancel;
private TextBox textBoxFirstName;
private TextBox textBoxLastName;
}
}

View File

@ -0,0 +1,90 @@
using ProjectHorseRacingOrg.Entities;
using ProjectHorseRacingOrg.Entities.Enums;
using ProjectHorseRacingOrg.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;
namespace ProjectHorseRacingOrg.Forms
{
public partial class FormJockey : Form
{
private readonly IJockeyRepository _jockeyRepository;
private int? _jockeyId;
public int Id
{
set
{
try
{
var jockey =
_jockeyRepository.ReadJockeyById(value);
if (jockey == null)
{
throw new
InvalidDataException(nameof(jockey));
}
textBoxFirstName.Text = jockey.FirstName;
textBoxLastName.Text = jockey.LastName;
comboBoxTitle.SelectedItem = jockey.JockeyTitle;
_jockeyId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormJockey(IJockeyRepository jockeyRepository)
{
InitializeComponent();
_jockeyRepository = jockeyRepository ??
throw new
ArgumentNullException(nameof(jockeyRepository));
comboBoxTitle.DataSource =
Enum.GetValues(typeof(JockeyTitle));
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) ||
string.IsNullOrWhiteSpace(textBoxLastName.Text)
||
comboBoxTitle.SelectedIndex < 1)
{
throw new Exception("Имеются незаполненные поля");
}
if (_jockeyId.HasValue)
{
_jockeyRepository.UpdateJockey(CreateJockey(_jockeyId.Value));
}
else
{
_jockeyRepository.CreateJockey(CreateJockey(0));
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) =>
Close();
private Jockey CreateJockey(int id) =>
Jockey.CreateEntity(id, textBoxFirstName.Text,
textBoxLastName.Text,
(JockeyTitle)comboBoxTitle.SelectedItem!);
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,126 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormJockeys
{
/// <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);
}
#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();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridViewData = new DataGridView();
panel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
SuspendLayout();
//
// panel
//
panel.Controls.Add(buttonDel);
panel.Controls.Add(buttonUpd);
panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right;
panel.Location = new Point(613, 0);
panel.Name = "panel";
panel.Size = new Size(187, 450);
panel.TabIndex = 0;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.удалить;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(40, 276);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(110, 100);
buttonDel.TabIndex = 2;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.изменить;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(40, 160);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(110, 100);
buttonUpd.TabIndex = 1;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.Добавить;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(40, 40);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(110, 100);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewData
//
dataGridViewData.AllowUserToAddRows = false;
dataGridViewData.AllowUserToDeleteRows = false;
dataGridViewData.AllowUserToResizeColumns = false;
dataGridViewData.AllowUserToResizeRows = false;
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewData.Dock = DockStyle.Fill;
dataGridViewData.Location = new Point(0, 0);
dataGridViewData.MultiSelect = false;
dataGridViewData.Name = "dataGridViewData";
dataGridViewData.ReadOnly = true;
dataGridViewData.RowHeadersVisible = false;
dataGridViewData.RowHeadersWidth = 51;
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewData.Size = new Size(613, 450);
dataGridViewData.TabIndex = 1;
//
// FormJockeys
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridViewData);
Controls.Add(panel);
Name = "FormJockeys";
Text = "Жокеи";
Load += FormJockeys_Load;
panel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridViewData;
}
}

View File

@ -0,0 +1,116 @@
using ProjectHorseRacingOrg.Repositories;
using ProjectHorseRacingOrg.Repositories.Implementations;
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 ProjectHorseRacingOrg.Forms
{
public partial class FormJockeys : Form
{
private readonly IUnityContainer _container;
private readonly IJockeyRepository _jockeyRepository;
public FormJockeys(IUnityContainer container, IJockeyRepository jockeyRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_jockeyRepository = jockeyRepository ??
throw new
ArgumentNullException(nameof(jockeyRepository));
}
private void FormJockeys_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormJockey>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
try
{
var form = _container.Resolve<FormJockey>();
form.Id = findId;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление",
MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_jockeyRepository.DeleteJockey(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList()
{
dataGridViewData.DataSource = _jockeyRepository.ReadJockeys();
dataGridViewData.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewData.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id =
Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
return true;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,141 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormRace
{
/// <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);
}
#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()
{
checkedListBoxRaceType = new CheckedListBox();
labelRaceType = new Label();
labelName = new Label();
labelDescription = new Label();
buttonSave = new Button();
buttonCancel = new Button();
textBoxName = new TextBox();
textBoxDescription = new TextBox();
SuspendLayout();
//
// checkedListBoxRaceType
//
checkedListBoxRaceType.FormattingEnabled = true;
checkedListBoxRaceType.Location = new Point(213, 23);
checkedListBoxRaceType.Name = "checkedListBoxRaceType";
checkedListBoxRaceType.Size = new Size(228, 92);
checkedListBoxRaceType.TabIndex = 0;
//
// labelRaceType
//
labelRaceType.AutoSize = true;
labelRaceType.Location = new Point(44, 56);
labelRaceType.Name = "labelRaceType";
labelRaceType.Size = new Size(143, 20);
labelRaceType.TabIndex = 1;
labelRaceType.Text = "Тип соревнования:";
//
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(46, 143);
labelName.Name = "labelName";
labelName.Size = new Size(80, 20);
labelName.TabIndex = 2;
labelName.Text = "Название:";
//
// labelDescription
//
labelDescription.AutoSize = true;
labelDescription.Location = new Point(44, 225);
labelDescription.Name = "labelDescription";
labelDescription.Size = new Size(82, 20);
labelDescription.TabIndex = 3;
labelDescription.Text = "Описание:";
//
// buttonSave
//
buttonSave.Location = new Point(76, 341);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(95, 33);
buttonSave.TabIndex = 4;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(254, 341);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(95, 33);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// textBoxName
//
textBoxName.Location = new Point(213, 143);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(228, 27);
textBoxName.TabIndex = 6;
//
// textBoxDescription
//
textBoxDescription.Location = new Point(213, 192);
textBoxDescription.Multiline = true;
textBoxDescription.Name = "textBoxDescription";
textBoxDescription.Size = new Size(228, 95);
textBoxDescription.TabIndex = 7;
//
// FormRace
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(508, 397);
Controls.Add(textBoxDescription);
Controls.Add(textBoxName);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(labelDescription);
Controls.Add(labelName);
Controls.Add(labelRaceType);
Controls.Add(checkedListBoxRaceType);
Name = "FormRace";
Text = "Соревнование";
ResumeLayout(false);
PerformLayout();
}
#endregion
private CheckedListBox checkedListBoxRaceType;
private Label labelRaceType;
private Label labelName;
private Label labelDescription;
private Button buttonSave;
private Button buttonCancel;
private TextBox textBoxName;
private TextBox textBoxDescription;
}
}

View File

@ -0,0 +1,106 @@
using Microsoft.VisualBasic.FileIO;
using ProjectHorseRacingOrg.Entities;
using ProjectHorseRacingOrg.Entities.Enums;
using ProjectHorseRacingOrg.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;
namespace ProjectHorseRacingOrg.Forms
{
public partial class FormRace : Form
{
private readonly IRaceRepository _raceRepository;
private int? _raceId;
public int Id
{
set
{
try
{
var race = _raceRepository.ReadRaceById(value);
if (race == null)
{
throw new
InvalidDataException(nameof(race));
}
foreach (RaceType elem in
Enum.GetValues(typeof(RaceType)))
{
if ((elem & race.RaceType) != 0)
{
checkedListBoxRaceType.SetItemChecked(checkedListBoxRaceType.Items.IndexOf(elem), true);
}
}
textBoxName.Text = race.Name;
textBoxDescription.Text = race.Description;
_raceId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormRace(IRaceRepository raceRepository)
{
InitializeComponent();
_raceRepository = raceRepository ??
throw new ArgumentNullException(nameof(raceRepository));
foreach (var elem in Enum.GetValues(typeof(RaceType)))
{
checkedListBoxRaceType.Items.Add(elem);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxName.Text) ||
string.IsNullOrWhiteSpace(textBoxDescription.Text) ||
checkedListBoxRaceType.CheckedItems.Count == 0)
{
throw new Exception("Имеются незаполненные поля");
}
if (_raceId.HasValue)
{
_raceRepository.UpdateRace(CreateRace(_raceId.Value));
}
else
{
_raceRepository.CreateRace(CreateRace(0));
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) =>
Close();
private Race CreateRace(int id)
{
RaceType raceType = RaceType.None;
foreach (var elem in checkedListBoxRaceType.CheckedItems)
{
raceType |= (RaceType)elem;
}
return Race.CreateEntity(id, raceType, textBoxName.Text,
textBoxDescription.Text);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,152 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormRaceEntries
{
/// <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);
}
#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()
{
labelJockey = new Label();
groupBoxRace = new GroupBox();
dataGridView = new DataGridView();
ColumnRace = new DataGridViewComboBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
comboBoxJockey = new ComboBox();
buttonSave = new Button();
buttonCancel = new Button();
groupBoxRace.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// labelJockey
//
labelJockey.AutoSize = true;
labelJockey.Location = new Point(44, 49);
labelJockey.Name = "labelJockey";
labelJockey.Size = new Size(58, 20);
labelJockey.TabIndex = 0;
labelJockey.Text = "Жокей:";
//
// groupBoxRace
//
groupBoxRace.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBoxRace.Controls.Add(dataGridView);
groupBoxRace.Location = new Point(44, 127);
groupBoxRace.Name = "groupBoxRace";
groupBoxRace.Size = new Size(331, 306);
groupBoxRace.TabIndex = 1;
groupBoxRace.TabStop = false;
groupBoxRace.Text = "Соревнования";
//
// dataGridView
//
dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnRace, ColumnCount });
dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(3, 23);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51;
dataGridView.Size = new Size(325, 280);
dataGridView.TabIndex = 2;
//
// ColumnRace
//
ColumnRace.HeaderText = "Соревнование";
ColumnRace.MinimumWidth = 6;
ColumnRace.Name = "ColumnRace";
//
// ColumnCount
//
ColumnCount.HeaderText = "Кол-во ";
ColumnCount.MinimumWidth = 6;
ColumnCount.Name = "ColumnCount";
ColumnCount.Resizable = DataGridViewTriState.True;
ColumnCount.SortMode = DataGridViewColumnSortMode.NotSortable;
//
// comboBoxJockey
//
comboBoxJockey.FormattingEnabled = true;
comboBoxJockey.Location = new Point(159, 41);
comboBoxJockey.Name = "comboBoxJockey";
comboBoxJockey.Size = new Size(216, 28);
comboBoxJockey.TabIndex = 2;
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonSave.Location = new Point(59, 463);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 3;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(253, 463);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 4;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormRaceEntries
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(411, 520);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(comboBoxJockey);
Controls.Add(groupBoxRace);
Controls.Add(labelJockey);
Name = "FormRaceEntries";
Text = "Заявка на участие";
groupBoxRace.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelJockey;
private GroupBox groupBoxRace;
private DataGridView dataGridView;
private ComboBox comboBoxJockey;
private Button buttonSave;
private Button buttonCancel;
private DataGridViewComboBoxColumn ColumnRace;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -0,0 +1,79 @@
using ProjectHorseRacingOrg.Entities;
using ProjectHorseRacingOrg.Repositories;
using ProjectHorseRacingOrg.Repositories.Implementations;
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;
namespace ProjectHorseRacingOrg.Forms
{
public partial class FormRaceEntries : Form
{
private readonly IRaceEntriesRepository _raceEntriesRepository;
public FormRaceEntries(IRaceEntriesRepository raceEntriesRepository,
IJockeyRepository jockeyRepository,
IRaceRepository raceRepository)
{
InitializeComponent();
_raceEntriesRepository = raceEntriesRepository ??
throw new
ArgumentNullException(nameof(raceEntriesRepository));
comboBoxJockey.DataSource = jockeyRepository.ReadJockeys();
comboBoxJockey.DisplayMember = "FullName";
comboBoxJockey.ValueMember = "Id";
ColumnRace.DataSource = raceRepository.ReadRaces();
ColumnRace.DisplayMember = "Name";
ColumnRace.ValueMember = "Id";
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (dataGridView.RowCount < 1 ||
comboBoxJockey.SelectedIndex < 0)
{
throw new Exception("Имеются незаполненные поля");
}
_raceEntriesRepository.CreateRaceEntries(RaceEntries.CreateOpeartion(0,
(int)comboBoxJockey.SelectedValue!,
CreateListRaceEntryDetailsFromDataGrid()));
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) =>
Close();
private List<RaceEntryDetails>
CreateListRaceEntryDetailsFromDataGrid()
{
var list = new List<RaceEntryDetails>();
foreach (DataGridViewRow row in dataGridView.Rows)
{
if (row.Cells["ColumnRace"].Value == null ||
row.Cells["ColumnCount"].Value == null)
{
continue;
}
list.Add(RaceEntryDetails.CreateElement(0,
Convert.ToInt32(row.Cells["ColumnRace"].Value),
Convert.ToInt32(row.Cells["ColumnCount"].Value)));
}
return list.GroupBy(x => x.RaceId, x => x.Count, (id, counts) =>
RaceEntryDetails.CreateElement(0, id, counts.Sum())).ToList();
}
}
}

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ColumnRace.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -0,0 +1,107 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormRaceEntryReport
{
/// <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);
}
#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()
{
buttonCreate = new Button();
buttonSelectFileName = new Button();
labelData = new Label();
labelFileName = new Label();
dateTimePicker = new DateTimePicker();
SuspendLayout();
//
// buttonCreate
//
buttonCreate.Location = new Point(132, 155);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(140, 29);
buttonCreate.TabIndex = 0;
buttonCreate.Text = "Сформировать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// buttonSelectFileName
//
buttonSelectFileName.Location = new Point(39, 30);
buttonSelectFileName.Name = "buttonSelectFileName";
buttonSelectFileName.Size = new Size(94, 29);
buttonSelectFileName.TabIndex = 1;
buttonSelectFileName.Text = "Выбрать";
buttonSelectFileName.UseVisualStyleBackColor = true;
buttonSelectFileName.Click += ButtonSelectFileName_Click;
//
// labelData
//
labelData.AutoSize = true;
labelData.Location = new Point(39, 100);
labelData.Name = "labelData";
labelData.Size = new Size(44, 20);
labelData.TabIndex = 2;
labelData.Text = "Дата:";
//
// labelFileName
//
labelFileName.AutoSize = true;
labelFileName.Location = new Point(166, 34);
labelFileName.Name = "labelFileName";
labelFileName.Size = new Size(45, 20);
labelFileName.TabIndex = 3;
labelFileName.Text = "Файл";
//
// dateTimePicker
//
dateTimePicker.Location = new Point(100, 100);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(250, 27);
dateTimePicker.TabIndex = 4;
//
// FormRaceEntryReport
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(402, 230);
Controls.Add(dateTimePicker);
Controls.Add(labelFileName);
Controls.Add(labelData);
Controls.Add(buttonSelectFileName);
Controls.Add(buttonCreate);
Name = "FormRaceEntryReport";
Text = "FormRaceEntryReport";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCreate;
private Button buttonSelectFileName;
private Label labelData;
private Label labelFileName;
private DateTimePicker dateTimePicker;
}
}

View File

@ -0,0 +1,66 @@
using ProjectHorseRacingOrg.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 ProjectHorseRacingOrg.Forms;
public partial class FormRaceEntryReport : Form
{
private string _fileName = string.Empty;
private readonly IUnityContainer _container;
public FormRaceEntryReport(IUnityContainer container)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
}
private void ButtonSelectFileName_Click(object sender, EventArgs e)
{
var sfd = new SaveFileDialog()
{
Filter = "Pdf Files | *.pdf"
};
if (sfd.ShowDialog() == DialogResult.OK)
{
_fileName = sfd.FileName;
labelFileName.Text = Path.GetFileName(_fileName);
}
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(_fileName))
{
throw new Exception("Отсутствует имя файла для отчета");
}
if
(_container.Resolve<ChartReport>().CreateChart(_fileName, dateTimePicker.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);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,163 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormRaceReport
{
/// <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);
}
#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()
{
dateTimePickerDateBegin = new DateTimePicker();
dateTimePickerDateEnd = new DateTimePicker();
ButtonMakeReport = new Button();
labelWay = new Label();
labelRace = new Label();
labelBegin = new Label();
labelEnd = new Label();
buttonSelectFilePath = new Button();
textBoxFilePath = new TextBox();
comboBoxRace = new ComboBox();
SuspendLayout();
//
// dateTimePickerDateBegin
//
dateTimePickerDateBegin.Location = new Point(164, 159);
dateTimePickerDateBegin.Name = "dateTimePickerDateBegin";
dateTimePickerDateBegin.Size = new Size(262, 27);
dateTimePickerDateBegin.TabIndex = 0;
//
// dateTimePickerDateEnd
//
dateTimePickerDateEnd.Location = new Point(164, 214);
dateTimePickerDateEnd.Name = "dateTimePickerDateEnd";
dateTimePickerDateEnd.Size = new Size(262, 27);
dateTimePickerDateEnd.TabIndex = 1;
//
// ButtonMakeReport
//
ButtonMakeReport.Location = new Point(164, 270);
ButtonMakeReport.Name = "ButtonMakeReport";
ButtonMakeReport.Size = new Size(136, 29);
ButtonMakeReport.TabIndex = 2;
ButtonMakeReport.Text = "Сформировать";
ButtonMakeReport.UseVisualStyleBackColor = true;
ButtonMakeReport.Click += ButtonMakeReport_Click;
//
// labelWay
//
labelWay.AutoSize = true;
labelWay.Location = new Point(37, 36);
labelWay.Name = "labelWay";
labelWay.Size = new Size(112, 20);
labelWay.TabIndex = 3;
labelWay.Text = "Путь до файла:";
//
// labelRace
//
labelRace.AutoSize = true;
labelRace.Location = new Point(37, 98);
labelRace.Name = "labelRace";
labelRace.Size = new Size(115, 20);
labelRace.TabIndex = 4;
labelRace.Text = "Соревнование:";
//
// labelBegin
//
labelBegin.AutoSize = true;
labelBegin.Location = new Point(37, 159);
labelBegin.Name = "labelBegin";
labelBegin.Size = new Size(97, 20);
labelBegin.TabIndex = 5;
labelBegin.Text = "Дата начала:";
//
// labelEnd
//
labelEnd.AutoSize = true;
labelEnd.Location = new Point(37, 219);
labelEnd.Name = "labelEnd";
labelEnd.Size = new Size(90, 20);
labelEnd.TabIndex = 6;
labelEnd.Text = "Дата конца:";
//
// buttonSelectFilePath
//
buttonSelectFilePath.Location = new Point(390, 31);
buttonSelectFilePath.Name = "buttonSelectFilePath";
buttonSelectFilePath.Size = new Size(36, 29);
buttonSelectFilePath.TabIndex = 7;
buttonSelectFilePath.Text = "..";
buttonSelectFilePath.UseVisualStyleBackColor = true;
buttonSelectFilePath.Click += ButtonSelectFilePath_Click;
//
// textBoxFilePath
//
textBoxFilePath.Location = new Point(164, 33);
textBoxFilePath.Name = "textBoxFilePath";
textBoxFilePath.ReadOnly = true;
textBoxFilePath.Size = new Size(220, 27);
textBoxFilePath.TabIndex = 8;
//
// comboBoxRace
//
comboBoxRace.FormattingEnabled = true;
comboBoxRace.Location = new Point(164, 95);
comboBoxRace.Name = "comboBoxRace";
comboBoxRace.Size = new Size(262, 28);
comboBoxRace.TabIndex = 9;
//
// FormRaceReport
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(475, 322);
Controls.Add(comboBoxRace);
Controls.Add(textBoxFilePath);
Controls.Add(buttonSelectFilePath);
Controls.Add(labelEnd);
Controls.Add(labelBegin);
Controls.Add(labelRace);
Controls.Add(labelWay);
Controls.Add(ButtonMakeReport);
Controls.Add(dateTimePickerDateEnd);
Controls.Add(dateTimePickerDateBegin);
Name = "FormRaceReport";
Text = "FormRaceReport";
ResumeLayout(false);
PerformLayout();
}
#endregion
private DateTimePicker dateTimePickerDateBegin;
private DateTimePicker dateTimePickerDateEnd;
private Button ButtonMakeReport;
private Label labelWay;
private Label labelRace;
private Label labelBegin;
private Label labelEnd;
private Button buttonSelectFilePath;
private TextBox textBoxFilePath;
private ComboBox comboBoxRace;
}
}

View File

@ -0,0 +1,88 @@
using ProjectHorseRacingOrg.Reports;
using ProjectHorseRacingOrg.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 ProjectHorseRacingOrg.Forms
{
public partial class FormRaceReport : Form
{
private readonly IUnityContainer _container;
public FormRaceReport(IUnityContainer container, IRaceRepository raceRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
comboBoxRace.DataSource = raceRepository.ReadRaces();
comboBoxRace.DisplayMember = "Name";
comboBoxRace.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 (comboBoxRace.SelectedIndex < 0)
{
throw new Exception("Не выбран корм");
}
if (dateTimePickerDateBegin.Value >=
dateTimePickerDateEnd.Value)
{
throw new Exception("Дата начала должна быть раньше даты окончания");
}
if
(_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text,
(int)comboBoxRace.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);
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,126 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormRaces
{
/// <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);
}
#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()
{
dataGridViewData = new DataGridView();
panel1 = new Panel();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
panel1.SuspendLayout();
SuspendLayout();
//
// dataGridViewData
//
dataGridViewData.AllowUserToAddRows = false;
dataGridViewData.AllowUserToDeleteRows = false;
dataGridViewData.AllowUserToResizeColumns = false;
dataGridViewData.AllowUserToResizeRows = false;
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewData.BackgroundColor = SystemColors.ButtonShadow;
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewData.Dock = DockStyle.Fill;
dataGridViewData.Location = new Point(0, 0);
dataGridViewData.MultiSelect = false;
dataGridViewData.Name = "dataGridViewData";
dataGridViewData.ReadOnly = true;
dataGridViewData.RowHeadersVisible = false;
dataGridViewData.RowHeadersWidth = 51;
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewData.Size = new Size(599, 450);
dataGridViewData.TabIndex = 1;
//
// panel1
//
panel1.Controls.Add(buttonDel);
panel1.Controls.Add(buttonUpd);
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(599, 0);
panel1.Name = "panel1";
panel1.Size = new Size(201, 450);
panel1.TabIndex = 2;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.удалить;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(54, 295);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(110, 100);
buttonDel.TabIndex = 2;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.изменить;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(54, 164);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(110, 100);
buttonUpd.TabIndex = 1;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.Добавить;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(54, 36);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(110, 100);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// FormRaces
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridViewData);
Controls.Add(panel1);
Name = "FormRaces";
Text = "Соревнования";
Load += FormRaces_Load;
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
panel1.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private DataGridView dataGridViewData;
private Panel panel1;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,117 @@
using ProjectHorseRacingOrg.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 ProjectHorseRacingOrg.Forms
{
public partial class FormRaces : Form
{
private readonly IUnityContainer _container;
private readonly IRaceRepository _raceRepository;
public FormRaces(IUnityContainer container, IRaceRepository raceRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_raceRepository = raceRepository ??
throw new ArgumentNullException(nameof(raceRepository));
}
private void FormRaces_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormRace>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
try
{
var form = _container.Resolve<FormRace>();
form.Id = findId;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление",
MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_raceRepository.DeleteRace(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList()
{
dataGridViewData.DataSource = _raceRepository.ReadRaces();
dataGridViewData.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewData.SelectedRows.Count< 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id =
Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
return true;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,112 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormRacesEntries
{
/// <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);
}
#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()
{
panel1 = new Panel();
buttonDel = new Button();
buttonAdd = new Button();
dataGridViewData = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonDel);
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(627, 0);
panel1.Name = "panel1";
panel1.Size = new Size(173, 450);
panel1.TabIndex = 0;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.удалить;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(35, 295);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(110, 100);
buttonDel.TabIndex = 1;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.Добавить;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(35, 43);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(110, 100);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewData
//
dataGridViewData.AllowUserToAddRows = false;
dataGridViewData.AllowUserToDeleteRows = false;
dataGridViewData.AllowUserToResizeColumns = false;
dataGridViewData.AllowUserToResizeRows = false;
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewData.Dock = DockStyle.Fill;
dataGridViewData.Location = new Point(0, 0);
dataGridViewData.MultiSelect = false;
dataGridViewData.Name = "dataGridViewData";
dataGridViewData.ReadOnly = true;
dataGridViewData.RowHeadersVisible = false;
dataGridViewData.RowHeadersWidth = 51;
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewData.Size = new Size(627, 450);
dataGridViewData.TabIndex = 1;
//
// FormRacesEntries
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridViewData);
Controls.Add(panel1);
Name = "FormRacesEntries";
Text = "Заявки на участие";
Load += FormRaceEntriesRepository_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private Button buttonDel;
private Button buttonAdd;
private DataGridView dataGridViewData;
}
}

View File

@ -0,0 +1,98 @@
using ProjectHorseRacingOrg.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 ProjectHorseRacingOrg.Forms
{
public partial class FormRacesEntries : Form
{
private readonly IUnityContainer _container;
private readonly IRaceEntriesRepository _raceEntriesRepository;
public FormRacesEntries(IUnityContainer container, IRaceEntriesRepository raceEntriesRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_raceEntriesRepository = raceEntriesRepository ??
throw new
ArgumentNullException(nameof(raceEntriesRepository));
}
private void FormRaceEntriesRepository_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormRaceEntries>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление",
MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_raceEntriesRepository.DeleteRaceEntries(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList()
{
dataGridViewData.DataSource = _raceEntriesRepository.ReadRaceEntries();
dataGridViewData.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewData.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id =
Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
return true;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,169 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormRacingHorse
{
/// <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);
}
#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()
{
labelRace = new Label();
label2 = new Label();
label3 = new Label();
label4 = new Label();
comboBoxRace = new ComboBox();
comboBoxJockey = new ComboBox();
comboBoxHorse = new ComboBox();
buttonSave = new Button();
buttonCancel = new Button();
numericUpDownResult = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)numericUpDownResult).BeginInit();
SuspendLayout();
//
// labelRace
//
labelRace.AutoSize = true;
labelRace.Location = new Point(40, 36);
labelRace.Name = "labelRace";
labelRace.Size = new Size(115, 20);
labelRace.TabIndex = 0;
labelRace.Text = "Соревнование:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(40, 89);
label2.Name = "label2";
label2.Size = new Size(58, 20);
label2.TabIndex = 1;
label2.Text = "Жокей:";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(40, 154);
label3.Name = "label3";
label3.Size = new Size(67, 20);
label3.TabIndex = 2;
label3.Text = "Лошадь:";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(43, 223);
label4.Name = "label4";
label4.Size = new Size(55, 20);
label4.TabIndex = 3;
label4.Text = "Место:";
//
// comboBoxRace
//
comboBoxRace.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxRace.FormattingEnabled = true;
comboBoxRace.Location = new Point(183, 36);
comboBoxRace.Name = "comboBoxRace";
comboBoxRace.Size = new Size(214, 28);
comboBoxRace.TabIndex = 4;
//
// comboBoxJockey
//
comboBoxJockey.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxJockey.FormattingEnabled = true;
comboBoxJockey.Location = new Point(183, 89);
comboBoxJockey.Name = "comboBoxJockey";
comboBoxJockey.Size = new Size(214, 28);
comboBoxJockey.TabIndex = 5;
//
// comboBoxHorse
//
comboBoxHorse.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxHorse.FormattingEnabled = true;
comboBoxHorse.Location = new Point(183, 154);
comboBoxHorse.Name = "comboBoxHorse";
comboBoxHorse.Size = new Size(214, 28);
comboBoxHorse.TabIndex = 6;
//
// buttonSave
//
buttonSave.Location = new Point(79, 303);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(112, 32);
buttonSave.TabIndex = 7;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(252, 303);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(112, 31);
buttonCancel.TabIndex = 8;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// numericUpDownResult
//
numericUpDownResult.Location = new Point(183, 223);
numericUpDownResult.Name = "numericUpDownResult";
numericUpDownResult.Size = new Size(214, 27);
numericUpDownResult.TabIndex = 9;
//
// FormRacingHorse
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(445, 361);
Controls.Add(numericUpDownResult);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(comboBoxHorse);
Controls.Add(comboBoxJockey);
Controls.Add(comboBoxRace);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(labelRace);
Name = "FormRacingHorse";
Text = "Участие лошади";
((System.ComponentModel.ISupportInitialize)numericUpDownResult).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelRace;
private Label label2;
private Label label3;
private Label label4;
private ComboBox comboBoxRace;
private ComboBox comboBoxJockey;
private ComboBox comboBoxHorse;
private Button buttonSave;
private Button buttonCancel;
private NumericUpDown numericUpDownResult;
}
}

View File

@ -0,0 +1,68 @@
using ProjectHorseRacingOrg.Entities;
using ProjectHorseRacingOrg.Repositories;
using ProjectHorseRacingOrg.Repositories.Implementations;
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;
namespace ProjectHorseRacingOrg.Forms
{
public partial class FormRacingHorse : Form
{
private readonly IRacingHorsesRepository _racingHorsesRepository;
public FormRacingHorse(IRacingHorsesRepository racingHorsesRepository,
IRaceRepository raceRepository, IJockeyRepository jockeyRepository,
IHorseRepository horseRepository)
{
InitializeComponent();
_racingHorsesRepository = racingHorsesRepository ??
throw new
ArgumentNullException(nameof(racingHorsesRepository));
comboBoxJockey.DataSource = jockeyRepository.ReadJockeys();
comboBoxJockey.DisplayMember = "FullName";
comboBoxJockey.ValueMember = "Id";
comboBoxRace.DataSource = raceRepository.ReadRaces();
comboBoxRace.DisplayMember = "Name";
comboBoxRace.ValueMember = "Id";
comboBoxHorse.DataSource = horseRepository.ReadHorses();
comboBoxHorse.DisplayMember = "FullName";
comboBoxHorse.ValueMember = "Id";
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (comboBoxRace.SelectedIndex < 0 ||
comboBoxJockey.SelectedIndex < 0 ||
comboBoxHorse.SelectedIndex < 0)
{
throw new Exception("Имеются незаполненные поля");
}
_racingHorsesRepository.CreateRacingHorse(RacingHorses.CreateOpeartion(
0,
(int)comboBoxRace.SelectedValue!,
(int)comboBoxJockey.SelectedValue!,
(int)comboBoxHorse.SelectedValue!,
Convert.ToInt32(numericUpDownResult.Value)));
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) =>
Close();
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,92 @@
namespace ProjectHorseRacingOrg.Forms
{
partial class FormRacingHorses
{
/// <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);
}
#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()
{
panel1 = new Panel();
buttonAdd = new Button();
dataGridViewData = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(615, 0);
panel1.Name = "panel1";
panel1.Size = new Size(185, 450);
panel1.TabIndex = 0;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.Добавить1;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(23, 64);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(118, 118);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewData
//
dataGridViewData.AllowUserToAddRows = false;
dataGridViewData.AllowUserToDeleteRows = false;
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewData.Dock = DockStyle.Fill;
dataGridViewData.Location = new Point(0, 0);
dataGridViewData.Name = "dataGridViewData";
dataGridViewData.ReadOnly = true;
dataGridViewData.RowHeadersWidth = 51;
dataGridViewData.Size = new Size(615, 450);
dataGridViewData.TabIndex = 1;
//
// FormRacingHorses
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridViewData);
Controls.Add(panel1);
Name = "FormRacingHorses";
Text = "Участие лошадей";
Load += FormRacingHorses_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private Button buttonAdd;
private DataGridView dataGridViewData;
}
}

View File

@ -0,0 +1,62 @@
using ProjectHorseRacingOrg.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 ProjectHorseRacingOrg.Forms
{
public partial class FormRacingHorses : Form
{
private readonly IUnityContainer _container;
private readonly IRacingHorsesRepository _racingHorsesRepository;
public FormRacingHorses(IUnityContainer container,
IRacingHorsesRepository racingHorsesRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_racingHorsesRepository = racingHorsesRepository ??
throw new
ArgumentNullException(nameof(racingHorsesRepository));
}
private void FormRacingHorses_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormRacingHorse>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList()
{
dataGridViewData.DataSource = _racingHorsesRepository.ReadRacingHorses();
dataGridViewData.Columns["Id"].Visible = false;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,3 +1,12 @@
using Unity.Lifetime;
using Unity;
using ProjectHorseRacingOrg.Repositories;
using ProjectHorseRacingOrg.Repositories.Implementations;
using Unity.Microsoft.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Serilog;
namespace ProjectHorseRacingOrg
{
internal static class Program
@ -11,7 +20,38 @@ namespace ProjectHorseRacingOrg
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(CreateContainer().Resolve<FormHorseRacing>());
}
private static IUnityContainer CreateContainer()
{
var container = new UnityContainer();
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
container.RegisterType<IJockeyRepository, JockeyRepository>(new TransientLifetimeManager());
container.RegisterType<IHorseRepository, HorseRepository>(new TransientLifetimeManager());
container.RegisterType<IRaceRepository, RaceRepository>(new TransientLifetimeManager());
container.RegisterType<IRacingHorsesRepository, RacingHorsesRepository>(new TransientLifetimeManager());
container.RegisterType<IRaceEntriesRepository, RaceEntriesRepository>(new TransientLifetimeManager());
container.RegisterType<IConnectionString, ConnectionString>();
return container;
}
private static LoggerFactory CreateLoggerFactory()
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build())
.CreateLogger());
return loggerFactory;
}
}
}

View File

@ -8,4 +8,38 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.2.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql" Version="9.0.2" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -0,0 +1,113 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectHorseRacingOrg.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectHorseRacingOrg.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Добавить {
get {
object obj = ResourceManager.GetObject("Добавить", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Добавить1 {
get {
object obj = ResourceManager.GetObject(обавить1", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap изменить {
get {
object obj = ResourceManager.GetObject("изменить", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap скачки {
get {
object obj = ResourceManager.GetObject("скачки", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap удалить {
get {
object obj = ResourceManager.GetObject("удалить", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,136 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="изменить" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\изменить.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="скачки" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\скачки.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Добавить" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Добавить.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="удалить" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\удалить.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Добавить1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Добавить1.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -0,0 +1,53 @@
using Microsoft.Extensions.Logging;
using ProjectHorseRacingOrg.Repositories;
using ProjectHorseRacingOrg.Repositories.Implementations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Reports;
public class ChartReport
{
private readonly IRacingHorsesRepository _racingHorsesRepository;
private readonly ILogger<ChartReport> _logger;
public ChartReport(IRacingHorsesRepository racingHorsesRepository, ILogger<ChartReport> logger)
{
_racingHorsesRepository = racingHorsesRepository ??
throw new ArgumentNullException(nameof(racingHorsesRepository));
_logger = logger ??
throw new ArgumentNullException(nameof(logger));
}
public bool CreateChart(string filePath, DateTime dateTime)
{
try
{
new PdfBuilder(filePath)
.AddHeader("Участие лошадей")
.AddPieChart($"Состоявшиеся соревнования на {dateTime:dd MMMM yyyy}", GetData(dateTime))
.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<(string Caption, double Value)> GetData(DateTime dateTime)
{
return _racingHorsesRepository
.ReadRacingHorses()
.Where(x => x.RacingDate.Date == dateTime.Date)
.GroupBy(x => x.HorseName, (key, group) => new {
Name = key,
Count = group.Sum(x => x.Result)
})
.Select(x => (x.Name, (double)x.Count))
.ToList();
}
}

View File

@ -0,0 +1,89 @@
using Microsoft.Extensions.Logging;
using ProjectHorseRacingOrg.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Reports;
internal class DocReport
{
private readonly IHorseRepository _horseRepository;
private readonly IJockeyRepository _jockeyRepository;
private readonly IRaceRepository _raceRepository;
private readonly ILogger<DocReport> _logger;
public DocReport(IHorseRepository horseRepository, IJockeyRepository jockeyRepository,
IRaceRepository raceRepository, ILogger<DocReport> logger)
{
_horseRepository = horseRepository ?? throw new ArgumentNullException(nameof(horseRepository));
_jockeyRepository = jockeyRepository ?? throw new ArgumentNullException(nameof(jockeyRepository));
_raceRepository = raceRepository ?? throw new ArgumentNullException(nameof(raceRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public bool CreateDoc(string filePath, bool includeHorses, bool
includeJockeys, bool includeRaces)
{
try
{
var builder = new WordBuilder(filePath)
.AddHeader("Документ со справочниками");
if (includeHorses)
{
builder.AddParagraph("Лошади")
.AddTable([2400, 2400, 1200, 1200],
GetHorses());
}
if (includeJockeys)
{
builder.AddParagraph("Жокеи")
.AddTable([2400, 2400, 2400], GetJockeys());
}
if (includeRaces)
{
builder.AddParagraph("Соревнование")
.AddTable([2400, 2400, 2400], GetRaces());
}
builder.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<string[]> GetHorses()
{
return [
["Вид лошади", "Имя лошади", "Вес", "Возраст"],
.. _horseRepository
.ReadHorses()
.Select(x => new string[] { x.HorseSpecies, x.HorseNickName, x.Weight.ToString(), x.Age.ToString() }),
];
}
private List<string[]> GetJockeys()
{
return [
["Имя", "Фамилия", "Титул"],
.. _jockeyRepository
.ReadJockeys()
.Select(x => new string[] { x.FirstName, x.LastName, x.JockeyTitle.ToString() }),
];
}
private List<string[]> GetRaces()
{
return [
["Тип соревнований", "Название", "Описание"],
.. _raceRepository
.ReadRaces()
.Select(x => new string[] { x.RaceType.ToString(), x.Name, x.Description }),
];
}
}

View File

@ -0,0 +1,311 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Reports;
public class ExcelBuilder
{
private readonly string _filePath;
private readonly SheetData _sheetData;
private readonly MergeCells _mergeCells;
private readonly Columns _columns;
private uint _rowIndex = 0;
public ExcelBuilder(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new ArgumentNullException(nameof(filePath));
}
if (File.Exists(filePath))
{
File.Delete(filePath);
}
_filePath = filePath;
_sheetData = new SheetData();
_mergeCells = new MergeCells();
_columns = new Columns();
_rowIndex = 1;
}
public ExcelBuilder AddHeader(string header, int startIndex, int count)
{
CreateCell(startIndex, _rowIndex, header,
StyleIndex.BoldTextWithoutBorder);
for (int i = startIndex + 1; i < startIndex + count; ++i)
{
CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder);
}
_mergeCells.Append(new MergeCell()
{
Reference = new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}")
});
_rowIndex++;
return this;
}
public ExcelBuilder AddParagraph(string text, int columnIndex)
{
CreateCell(columnIndex, _rowIndex++, text, StyleIndex.SimpleTextWithoutBorder);
return this;
}
public ExcelBuilder AddTable(int[] columnsWidths, List<string[]> data)
{
if (columnsWidths == null || columnsWidths.Length == 0)
{
throw new ArgumentNullException(nameof(columnsWidths));
}
if (data == null || data.Count == 0)
{
throw new ArgumentNullException(nameof(data));
}
if (data.Any(x => x.Length != columnsWidths.Length))
{
throw new InvalidOperationException("widths.Length != data.Length");
}
uint counter = 1;
int coef = 2;
_columns.Append(columnsWidths.Select(x => new Column
{
Min = counter,
Max = counter++,
Width = x * coef,
CustomWidth = true
}));
for (var j = 0; j < data.First().Length; ++j)
{
CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder);
}
_rowIndex++;
for (var i = 1; i < data.Count - 1; ++i)
{
for (var j = 0; j < data[i].Length; ++j)
{
CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder);
}
_rowIndex++;
}
for (var j = 0; j < data.Last().Length; ++j)
{
CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder);
}
_rowIndex++;
return this;
}
public void Build()
{
using var spreadsheetDocument = SpreadsheetDocument.Create(_filePath, SpreadsheetDocumentType.Workbook);
var workbookpart = spreadsheetDocument.AddWorkbookPart();
GenerateStyle(workbookpart);
workbookpart.Workbook = new Workbook();
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet();
if (_columns.HasChildren)
{
worksheetPart.Worksheet.Append(_columns);
}
worksheetPart.Worksheet.Append(_sheetData);
var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets());
var sheet = new Sheet()
{
Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Лист 1"
};
sheets.Append(sheet);
if (_mergeCells.HasChildren)
{
worksheetPart.Worksheet.InsertAfter(_mergeCells, worksheetPart.Worksheet.Elements<SheetData>().First());
}
}
private static void GenerateStyle(WorkbookPart workbookPart)
{
var workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>();
workbookStylesPart.Stylesheet = new Stylesheet();
var fonts = new Fonts()
{
Count = 2,
KnownFonts = BooleanValue.FromBoolean(true)
};
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
{
FontSize = new FontSize() { Val = 11 },
FontName = new FontName() { Val = "Calibri" },
FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
FontScheme = new FontScheme()
{
Val = new EnumValue<FontSchemeValues>(FontSchemeValues.Minor)
}
});
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
{
FontSize = new FontSize() { Val = 11 },
FontName = new FontName() { Val = "Calibri" },
Bold = new Bold(),
FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
FontScheme = new FontScheme()
{
Val = new EnumValue<FontSchemeValues>(FontSchemeValues.Minor)
}
});
workbookStylesPart.Stylesheet.Append(fonts);
// Default Fill
var fills = new Fills() { Count = 1 };
fills.Append(new Fill
{
PatternFill = new PatternFill()
{
PatternType = new EnumValue<PatternValues>(PatternValues.None)
}
});
workbookStylesPart.Stylesheet.Append(fills);
// Default Border
var borders = new Borders() { Count = 2 };
borders.Append(new Border
{
LeftBorder = new LeftBorder(),
RightBorder = new RightBorder(),
TopBorder = new TopBorder(),
BottomBorder = new BottomBorder(),
DiagonalBorder = new DiagonalBorder()
});
borders.Append(new Border
{
LeftBorder = new LeftBorder() { Style = BorderStyleValues.Medium },
RightBorder = new RightBorder() { Style = BorderStyleValues.Medium },
TopBorder = new TopBorder() { Style = BorderStyleValues.Medium },
BottomBorder = new BottomBorder() { Style = BorderStyleValues.Medium },
DiagonalBorder = new DiagonalBorder() { Style = BorderStyleValues.Medium },
});
workbookStylesPart.Stylesheet.Append(borders);
// Default cell format and a date cell format
var cellFormats = new CellFormats() { Count = 4 };
cellFormats.Append(new CellFormat
{
NumberFormatId = 0,
FormatId = 0,
FontId = 0,
BorderId = 0,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Left,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
cellFormats.Append(new CellFormat
{
NumberFormatId = 1,
FormatId = 0,
FontId = 0,
BorderId = 1,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Left,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
cellFormats.Append(new CellFormat
{
NumberFormatId = 2,
FormatId = 0,
FontId = 1,
BorderId = 0,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Left,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
cellFormats.Append(new CellFormat
{
NumberFormatId = 3,
FormatId = 0,
FontId = 1,
BorderId = 1,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Left,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
workbookStylesPart.Stylesheet.Append(cellFormats);
}
private enum StyleIndex
{
SimpleTextWithoutBorder = 0,
SimpleTextWithBorder = 1,
BoldTextWithoutBorder = 2,
BoldTextWithBorder = 3,
}
private void CreateCell(int columnIndex, uint rowIndex, string text, StyleIndex styleIndex)
{
var columnName = GetExcelColumnName(columnIndex);
var cellReference = columnName + rowIndex;
var row = _sheetData.Elements<Row>().FirstOrDefault(r => r.RowIndex! == rowIndex);
if (row == null)
{
row = new Row() { RowIndex = rowIndex };
_sheetData.Append(row);
}
var newCell = row.Elements<Cell>().FirstOrDefault(c => c.CellReference != null && c.CellReference.Value == columnName + rowIndex);
if (newCell == null)
{
Cell? refCell = null;
foreach (Cell cell in row.Elements<Cell>())
{
if (cell.CellReference?.Value != null && cell.CellReference.Value.Length == cellReference.Length)
{
if (string.Compare(cell.CellReference.Value, cellReference, true) > 0)
{
refCell = cell;
break;
}
}
}
newCell = new Cell() { CellReference = cellReference };
row.InsertBefore(newCell, refCell);
}
newCell.CellValue = new CellValue(text);
newCell.DataType = CellValues.String;
newCell.StyleIndex = (uint)styleIndex;
}
private static string GetExcelColumnName(int columnNumber)
{
columnNumber += 1;
int dividend = columnNumber;
string columnName = string.Empty;
int modulo;
while (dividend > 0)
{
modulo = (dividend - 1) % 26;
columnName = Convert.ToChar(65 + modulo).ToString() +
columnName;
dividend = (dividend - modulo) / 26;
}
return columnName;
}
}

View File

@ -0,0 +1,88 @@
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 ProjectHorseRacingOrg.Reports;
public 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()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(_filePath);
}
private void DefineStyles()
{
var headerStyle = _document.AddStyle("NormalBold", "Normal");
headerStyle.Font.Bold = true;
headerStyle.Font.Size = 14;
headerStyle.Font.Color = Colors.DeepPink;
}
}

View File

@ -0,0 +1,70 @@
using Microsoft.Extensions.Logging;
using ProjectHorseRacingOrg.Entities;
using ProjectHorseRacingOrg.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Reports;
internal class TableReport
{
private readonly IRaceEntriesRepository _raceEntriesRepository;
private readonly IRacingHorsesRepository _racingHorsesRepository;
private readonly ILogger<TableReport> _logger;
internal static readonly string[] item = ["Жокей", "Дата", "Количество пришло", "Количество ушло"];
public TableReport(IRaceEntriesRepository raceEntriesRepositor,
IRacingHorsesRepository racingHorsesRepository,
ILogger<TableReport> logger)
{
_raceEntriesRepository = raceEntriesRepositor ?? throw new ArgumentNullException(nameof(raceEntriesRepositor));
_racingHorsesRepository = racingHorsesRepository ?? throw new ArgumentNullException(nameof(racingHorsesRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public bool CreateTable(string filePath, int raceId, DateTime startDate,
DateTime endDate)
{
try
{
new ExcelBuilder(filePath)
.AddHeader("Сводка по движению соревнований", 0, 4)
.AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0)
.AddTable([10, 10, 15, 15], GetData(raceId, startDate, endDate))
.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<string[]> GetData(int raceId, DateTime startDate, DateTime endDate)
{
var data = _raceEntriesRepository
.ReadRaceEntries()
.Where(x => x.DateReceipt >= startDate && x.DateReceipt <= endDate && x.RacesEntryDetails.Any(y => y.RaceId == raceId))
.Select(x => new { x.JockeyName, Date = x.DateReceipt, CountIn = x.RacesEntryDetails.FirstOrDefault(y => y.RaceId == raceId)?.Count, CountOut = (int?)null })
.Union(
_racingHorsesRepository
.ReadRacingHorses()
.Where(x => x.RacingDate >= startDate && x.RacingDate <= endDate && x.RaceId == raceId)
.Select(x => new { x.JockeyName, Date = x.RacingDate, CountIn = (int?)null, CountOut = (int?)x.Result }))
.OrderBy(x => x.Date);
return
new List<string[]>() { item }
.Union(
data
.Select(x => new string[] { x.JockeyName, 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();
}
}

View File

@ -0,0 +1,127 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Reports;
internal class WordBuilder
{
private readonly string _filePath;
private readonly Document _document;
private readonly Body _body;
public WordBuilder(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new ArgumentNullException(nameof(filePath));
}
if (File.Exists(filePath))
{
File.Delete(filePath);
}
_filePath = filePath;
_document = new Document();
_body = _document.AppendChild(new Body());
}
public WordBuilder AddHeader(string header)
{
var paragraph = _body.AppendChild(new Paragraph());
var run = paragraph.AppendChild(new Run());
run.PrependChild(new RunProperties());
run.RunProperties.AddChild(new Bold());
run.AppendChild(new Text(header));
return this;
}
public WordBuilder AddParagraph(string text)
{
var paragraph = _body.AppendChild(new Paragraph());
var run = paragraph.AppendChild(new Run());
run.AppendChild(new Text(text));
return this;
}
public WordBuilder AddTable(int[] widths, List<string[]> data)
{
if (widths == null || widths.Length == 0)
{
throw new ArgumentNullException(nameof(widths));
}
if (data == null || data.Count == 0)
{
throw new ArgumentNullException(nameof(data));
}
if (data.Any(x => x.Length != widths.Length))
{
throw new InvalidOperationException("widths.Length != data.Length");
}
var table = new Table();
table.AppendChild(new TableProperties(
new TableBorders(
new TopBorder()
{
Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12
},
new BottomBorder()
{
Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12
},
new LeftBorder()
{
Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12
},
new RightBorder()
{
Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12
},
new InsideHorizontalBorder()
{
Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12
},
new InsideVerticalBorder()
{
Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12
}
)
));
// Заголовок
var tr = new TableRow();
for (var j = 0; j < widths.Length; ++j)
{
tr.Append(new TableCell(
new TableCellProperties(new TableCellWidth()
{
Width = widths[j].ToString()
}),
new Paragraph(new Run(new RunProperties(new Bold()), new
Text(data.First()[j])))));
}
table.Append(tr);
// Данные
table.Append(data.Skip(1).Select(x =>
new TableRow(x.Select(y => new TableCell(new Paragraph(new Run(new Text(y))))))));
_body.Append(table);
return this;
}
public void Build()
{
using var wordDocument = WordprocessingDocument.Create(_filePath, WordprocessingDocumentType.Document);
var mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = _document;
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories;
public interface IConnectionString
{
string ConnectionString { get; }
}

View File

@ -0,0 +1,17 @@
using ProjectHorseRacingOrg.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories;
public interface IHorseRepository
{
IEnumerable<Horse> ReadHorses();
Horse ReadHorseById(int id);
void CreateHorse(Horse horse);
void UpdateHorse(Horse horse);
void DeleteHorse(int id);
}

View File

@ -0,0 +1,18 @@
using ProjectHorseRacingOrg.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories;
public interface IJockeyRepository
{
IEnumerable<Jockey> ReadJockeys();
Jockey ReadJockeyById(int id);
void CreateJockey(Jockey jockey);
void UpdateJockey(Jockey jockey);
void DeleteJockey(int id);
}

View File

@ -0,0 +1,19 @@
using ProjectHorseRacingOrg.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories;
public interface IRaceEntriesRepository
{
IEnumerable<RaceEntries> ReadRaceEntries(DateTime? dateForm =
null, DateTime? dateTo = null,
int? raceId = null, int? jockeyId = null);
void CreateRaceEntries(RaceEntries raceEntries);
void DeleteRaceEntries(int id);
}

View File

@ -0,0 +1,18 @@
using ProjectHorseRacingOrg.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories;
public interface IRaceRepository
{
IEnumerable<Race> ReadRaces();
Race ReadRaceById(int id);
void CreateRace(Race race);
void UpdateRace(Race race);
void DeleteRace(int id);
}

View File

@ -0,0 +1,16 @@
using ProjectHorseRacingOrg.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories;
public interface IRacingHorsesRepository
{
IEnumerable<RacingHorses> ReadRacingHorses(DateTime? dateForm = null,
DateTime? dateTo = null, int? raceId = null,
int? jockeyId = null, int? horseId = null);
void CreateRacingHorse(RacingHorses racingHorses);
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories.Implementations;
internal class ConnectionString : IConnectionString
{
string IConnectionString.ConnectionString => "Server=localhost, 5432;Database=racinghorse;Uid=postgres;Pwd=postgres;";
}

View File

@ -0,0 +1,146 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.Devices;
using Newtonsoft.Json;
using ProjectHorseRacingOrg.Entities;
using Serilog.Core;
using System;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Npgsql;
namespace ProjectHorseRacingOrg.Repositories.Implementations;
public class HorseRepository : IHorseRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<HorseRepository> _logger;
public HorseRepository(IConnectionString connectionString, ILogger<HorseRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateHorse(Horse horse)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(horse));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO Horses (HorseSpecies, HorseNickName, Age, Weight)
VALUES (@HorseSpecies, @HorseNickName, @Age, @Weight)";
connection.Execute(queryInsert, horse);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void UpdateHorse(Horse horse)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(horse));
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Horses
SET
HorseSpecies=@HorseSpecies,
HorseNickName=@HorseNickName,
Age=@Age,
Weight=@Weight
WHERE Id=@Id";
connection.Execute(queryUpdate, horse);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
public void DeleteHorse(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Horses
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public Horse ReadHorseById(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Horses
WHERE Id=@id";
var horse = connection.QueryFirst<Horse>(querySelect, new
{
id
});
_logger.LogDebug("Найденный объект: {json}",
JsonConvert.SerializeObject(horse));
return horse;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Horse> ReadHorses()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Horses";
var horses = connection.Query<Horse>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(horses));
return horses;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

View File

@ -0,0 +1,142 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectHorseRacingOrg.Entities;
using ProjectHorseRacingOrg.Entities.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories.Implementations;
public class JockeyRepository : IJockeyRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<JockeyRepository> _logger;
public JockeyRepository(IConnectionString connectionString, ILogger<JockeyRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateJockey(Jockey jockey)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(jockey));
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO Jockeys (FirstName, LastName, JockeyTitle)
VALUES (@FirstName, @LastName, @JockeyTitle)";
connection.Execute(queryInsert, jockey);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void UpdateJockey(Jockey jockey)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(jockey));
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Jockeys
SET
FirstName=@FirstName,
LastName=@LastName,
JockeyTitle=@JockeyTitle
WHERE Id=@Id";
connection.Execute(queryUpdate, jockey);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
public void DeleteJockey(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Jockeys
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public Jockey ReadJockeyById(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Jockeys
WHERE Id=@id";
var jockey = connection.QueryFirst<Jockey>(querySelect,
new { id });
_logger.LogDebug("Найденный объект: {json}",
JsonConvert.SerializeObject(jockey));
return jockey;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Jockey> ReadJockeys()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Jockeys";
var jockeys = connection.Query<Jockey>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(jockeys));
return jockeys;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories.Implementations;
public class QueryBuilder
{
private readonly StringBuilder _builder;
public QueryBuilder()
{
_builder = new();
}
public QueryBuilder AddCondition(string condition)
{
if (_builder.Length > 0)
{
_builder.Append(" AND ");
}
_builder.Append(condition);
return this;
}
public string Build()
{
if (_builder.Length == 0)
{
return string.Empty;
}
return $"WHERE {_builder}";
}
}

View File

@ -0,0 +1,150 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectHorseRacingOrg.Entities;
using Serilog.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories.Implementations;
public class RaceEntriesRepository : IRaceEntriesRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<RaceEntriesRepository> _logger;
public RaceEntriesRepository(IConnectionString connectionString,
ILogger<RaceEntriesRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateRaceEntries(RaceEntries raceEntries)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(raceEntries));
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
connection.Open();
using var transaction = connection.BeginTransaction();
var queryInsert = @"
INSERT INTO RaceEntries (JockeyId, DateReceipt)
VALUES (@JockeyId, @DateReceipt);
SELECT MAX(Id) FROM RaceEntries";
var raceEntryId =
connection.QueryFirst<int>(queryInsert, raceEntries, transaction);
var querySubInsert = @"
INSERT INTO RaceEntryDetails (RaceEntryId, RaceId, Count)
VALUES (@RaceEntryId,@RaceId, @Count)";
foreach (var elem in raceEntries.RacesEntryDetails)
{
connection.Execute(querySubInsert, new
{
raceEntryId,
elem.RaceId,
elem.Count
}, transaction);
}
transaction.Commit();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void DeleteRaceEntries(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM RaceEntries
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public IEnumerable<RaceEntries> ReadRaceEntries(DateTime? dateForm = null, DateTime? dateTo = null, int? raceId = null, int? jockeyId = null)
{
_logger.LogInformation("Получение всех объектов");
try
{
var builder = new QueryBuilder();
if (dateForm.HasValue)
{
builder.AddCondition("re.DateReceipt >= @dateForm");
}
if (dateTo.HasValue)
{
builder.AddCondition("re.DateReceipt <= @dateTo");
}
if (raceId.HasValue)
{
builder.AddCondition("re.RaceId = @raceId");
}
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @$"
SELECT
re.*,
CONCAT(j.LastName, ' ', j.FirstName) as JockeyName,
red.RaceId,
red.Count,
r.Name as RaceName
FROM RaceEntries re
LEFT JOIN Jockeys j ON j.Id = re.JockeyId
INNER JOIN RaceEntryDetails red ON red.RaceEntryId = re.Id
LEFT JOIN Races r ON r.Id = red.RaceId
{builder.Build()}";
var raceEntryDict = new Dictionary<int, List<RaceEntryDetails>>();
var raceEntries = connection.Query<RaceEntries, RaceEntryDetails, RaceEntries>(querySelect,
(entry, details) =>
{
if (!raceEntryDict.TryGetValue(entry.Id, out var red))
{
red = new List<RaceEntryDetails>();
raceEntryDict.Add(entry.Id, red);
}
red.Add(details);
return entry;
}, splitOn: "RaceId", param: new { dateForm, dateTo, raceId });
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(raceEntries));
return raceEntryDict.Select(x =>
{
var re = raceEntries.First(y => y.Id == x.Key);
re.SetRacesEntryDetails(x.Value);
return re;
}).ToArray();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

View File

@ -0,0 +1,147 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.FileIO;
using Newtonsoft.Json;
using Npgsql;
using ProjectHorseRacingOrg.Entities;
using ProjectHorseRacingOrg.Entities.Enums;
using Serilog.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories.Implementations;
public class RaceRepository : IRaceRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<RaceRepository> _logger;
public RaceRepository(IConnectionString connectionString,
ILogger<RaceRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateRace(Race race)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(race));
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO Races (RaceType, Name, Description)
VALUES (@RaceType, @Name, @Description)";
connection.Execute(queryInsert, race);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void UpdateRace(Race race)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(race));
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Races
SET
RaceType=@RaceType,
Name=@Name,
Description=@Description
WHERE Id=@Id";
connection.Execute(queryUpdate, race);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
public void DeleteRace(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Races
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public Race ReadRaceById(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Races
WHERE Id=@id";
var race = connection.QueryFirst<Race>(querySelect, new
{
id
});
_logger.LogDebug("Найденный объект: {json}",
JsonConvert.SerializeObject(race));
return race;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Race> ReadRaces()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Races";
var races = connection.Query<Race>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(races));
return races;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

View File

@ -0,0 +1,71 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectHorseRacingOrg.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectHorseRacingOrg.Repositories.Implementations;
public class RacingHorsesRepository : IRacingHorsesRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<RacingHorsesRepository> _logger;
public RacingHorsesRepository(IConnectionString connectionString,
ILogger<RacingHorsesRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateRacingHorse(RacingHorses racingHorses)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(racingHorses));
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO RacingHorses (RaceId, JockeyId, HorseId, RacingDate, Result)
VALUES (@RaceId, @JockeyId, @HorseId, @RacingDate, @Result)";
connection.Execute(queryInsert, racingHorses);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public IEnumerable<RacingHorses> ReadRacingHorses(DateTime? dateForm = null, DateTime? dateTo = null, int? raceId = null, int? jockeyId = null, int? horseId = null)
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"select rh.*, r.RaceType as RaceName, CONCAT(j.LastName, ' ', j.FirstName) as JockeyName, h.HorseNickName as HorseName
from racingHorses rh
INNER JOIN Races r ON r.Id = rh.RaceId
INNER JOIN Jockeys j ON j.Id = rh.JockeyId
INNER JOIN Horses h ON h.Id = rh.HorseId";
var racingHorses =
connection.Query<RacingHorses>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(racingHorses));
return racingHorses;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

View File

@ -0,0 +1,15 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/HorseRacing_log.txt",
"rollingInterval": "Day"
}
}
]
}
}