diff --git a/ProjectHorseRacingOrg/Entities/Enums/JockeyTitle.cs b/ProjectHorseRacingOrg/Entities/Enums/JockeyTitle.cs new file mode 100644 index 0000000..2c5c095 --- /dev/null +++ b/ProjectHorseRacingOrg/Entities/Enums/JockeyTitle.cs @@ -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, + + SecondCategory = 1, + + FirstCategory = 2, + + Master = 3 +} diff --git a/ProjectHorseRacingOrg/Entities/Enums/RaceType.cs b/ProjectHorseRacingOrg/Entities/Enums/RaceType.cs new file mode 100644 index 0000000..8723733 --- /dev/null +++ b/ProjectHorseRacingOrg/Entities/Enums/RaceType.cs @@ -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 + +} diff --git a/ProjectHorseRacingOrg/Entities/Horse.cs b/ProjectHorseRacingOrg/Entities/Horse.cs new file mode 100644 index 0000000..8f1ae42 --- /dev/null +++ b/ProjectHorseRacingOrg/Entities/Horse.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacingOrg.Entities; + +public class Horse +{ + public int Id { get; private set; } + public string HorseSpecies { get; private set; } = string.Empty; + public string HorseNickName { get; private set; } = string.Empty; + public int Age { get; private set; } + 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 + }; + } +} diff --git a/ProjectHorseRacingOrg/Entities/Jockey.cs b/ProjectHorseRacingOrg/Entities/Jockey.cs new file mode 100644 index 0000000..244514b --- /dev/null +++ b/ProjectHorseRacingOrg/Entities/Jockey.cs @@ -0,0 +1,28 @@ +using ProjectHorseRacingOrg.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacingOrg.Entities; + +public class Jockey +{ + public int Id { get; private set; } + public string FirstName { get; private set; } = string.Empty; + public string LastName { get; private set; } = string.Empty; + 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 + }; + } + +} diff --git a/ProjectHorseRacingOrg/Entities/Race.cs b/ProjectHorseRacingOrg/Entities/Race.cs new file mode 100644 index 0000000..b5c95cc --- /dev/null +++ b/ProjectHorseRacingOrg/Entities/Race.cs @@ -0,0 +1,29 @@ +using Microsoft.VisualBasic.FileIO; +using ProjectHorseRacingOrg.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacingOrg.Entities; + +public class Race +{ + public int Id { get; private set; } + public RaceType RaceType { get; private set; } + public string Name { get; private set; } = string.Empty; + 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 + }; + } + +} diff --git a/ProjectHorseRacingOrg/Entities/RaceEntries.cs b/ProjectHorseRacingOrg/Entities/RaceEntries.cs new file mode 100644 index 0000000..295f102 --- /dev/null +++ b/ProjectHorseRacingOrg/Entities/RaceEntries.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacingOrg.Entities; + +public class RaceEntries +{ + public int Id { get; private set; } + public int JockeyId { get; private set; } + public DateTime DateReceipt { get; private set; } + public IEnumerable RaceEntryDetails + { + get; + private set; + } = []; + public static RaceEntries CreateOpeartion(int id, int jockeyId, + IEnumerable raceEntryDetails) + { + return new RaceEntries + { + Id = id, + JockeyId = jockeyId, + DateReceipt = DateTime.Now, + RaceEntryDetails = raceEntryDetails + }; + } + +} diff --git a/ProjectHorseRacingOrg/Entities/RaceEntryDetails.cs b/ProjectHorseRacingOrg/Entities/RaceEntryDetails.cs new file mode 100644 index 0000000..0e35106 --- /dev/null +++ b/ProjectHorseRacingOrg/Entities/RaceEntryDetails.cs @@ -0,0 +1,24 @@ +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 static RaceEntryDetails CreateElement(int id, int raceId, int + count) + { + return new RaceEntryDetails + { + Id = id, + RaceId = raceId, + Count = count + }; + } +} diff --git a/ProjectHorseRacingOrg/Entities/RacingHorses.cs b/ProjectHorseRacingOrg/Entities/RacingHorses.cs new file mode 100644 index 0000000..fa61eb4 --- /dev/null +++ b/ProjectHorseRacingOrg/Entities/RacingHorses.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacingOrg.Entities; + +public class RacingHorses +{ + public int Id { get; private set; } + public int RaceId { get; private set; } + public int JockeyId { get; private set; } + public int HorseId { get; private set; } + public DateTime RacingDate { get; private set; } + 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 + }; + } +} diff --git a/ProjectHorseRacingOrg/Form1.Designer.cs b/ProjectHorseRacingOrg/Form1.Designer.cs deleted file mode 100644 index 8443b42..0000000 --- a/ProjectHorseRacingOrg/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectHorseRacingOrg -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/ProjectHorseRacingOrg/Form1.cs b/ProjectHorseRacingOrg/Form1.cs deleted file mode 100644 index 869d689..0000000 --- a/ProjectHorseRacingOrg/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectHorseRacingOrg -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/ProjectHorseRacingOrg/FormHorseRacing.Designer.cs b/ProjectHorseRacingOrg/FormHorseRacing.Designer.cs new file mode 100644 index 0000000..ef5bff8 --- /dev/null +++ b/ProjectHorseRacingOrg/FormHorseRacing.Designer.cs @@ -0,0 +1,137 @@ +namespace ProjectHorseRacingOrg +{ + partial class FormHorseRacing + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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(); + 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(224, 26); + JockeysToolStripMenuItem.Text = "Жокеи"; + JockeysToolStripMenuItem.Click += JockeysToolStripMenuItem_Click; + // + // HorsesToolStripMenuItem + // + HorsesToolStripMenuItem.Name = "HorsesToolStripMenuItem"; + HorsesToolStripMenuItem.Size = new Size(224, 26); + HorsesToolStripMenuItem.Text = "Лошади"; + HorsesToolStripMenuItem.Click += HorsesToolStripMenuItem_Click; + // + // RacesToolStripMenuItem + // + RacesToolStripMenuItem.Name = "RacesToolStripMenuItem"; + RacesToolStripMenuItem.Size = new Size(224, 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(224, 26); + RacingHorsesToolStripMenuItem.Text = "Участие лошадей"; + RacingHorsesToolStripMenuItem.Click += RacingHorsesToolStripMenuItem_Click; + // + // RaceEntryDetalisToolStripMenuItem + // + RaceEntryDetalisToolStripMenuItem.Name = "RaceEntryDetalisToolStripMenuItem"; + RaceEntryDetalisToolStripMenuItem.Size = new Size(224, 26); + RaceEntryDetalisToolStripMenuItem.Text = "Заявки на участие"; + RaceEntryDetalisToolStripMenuItem.Click += RaceEntryDetalisToolStripMenuItem_Click; + // + // ReportsToolStripMenuItem + // + ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; + ReportsToolStripMenuItem.Size = new Size(73, 24); + ReportsToolStripMenuItem.Text = "Отчеты"; + // + // 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; + } +} diff --git a/ProjectHorseRacingOrg/FormHorseRacing.cs b/ProjectHorseRacingOrg/FormHorseRacing.cs new file mode 100644 index 0000000..00437b6 --- /dev/null +++ b/ProjectHorseRacingOrg/FormHorseRacing.cs @@ -0,0 +1,91 @@ +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().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + + } + + private void HorsesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void RacesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void RacingHorsesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void RaceEntryDetalisToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + } +} + diff --git a/ProjectHorseRacingOrg/FormHorseRacing.resx b/ProjectHorseRacingOrg/FormHorseRacing.resx new file mode 100644 index 0000000..b48baf1 --- /dev/null +++ b/ProjectHorseRacingOrg/FormHorseRacing.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormHorse.Designer.cs b/ProjectHorseRacingOrg/Forms/FormHorse.Designer.cs new file mode 100644 index 0000000..6fbedf2 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormHorse.Designer.cs @@ -0,0 +1,169 @@ +namespace ProjectHorseRacingOrg.Forms +{ + partial class FormHorse + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + } +} \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormHorse.cs b/ProjectHorseRacingOrg/Forms/FormHorse.cs new file mode 100644 index 0000000..9747952 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormHorse.cs @@ -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)); + } + +} + diff --git a/ProjectHorseRacingOrg/Form1.resx b/ProjectHorseRacingOrg/Forms/FormHorse.resx similarity index 92% rename from ProjectHorseRacingOrg/Form1.resx rename to ProjectHorseRacingOrg/Forms/FormHorse.resx index 1af7de1..8b2ff64 100644 --- a/ProjectHorseRacingOrg/Form1.resx +++ b/ProjectHorseRacingOrg/Forms/FormHorse.resx @@ -1,17 +1,17 @@  - diff --git a/ProjectHorseRacingOrg/Forms/FormHorses.Designer.cs b/ProjectHorseRacingOrg/Forms/FormHorses.Designer.cs new file mode 100644 index 0000000..9bc403e --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormHorses.Designer.cs @@ -0,0 +1,125 @@ +namespace ProjectHorseRacingOrg.Forms +{ + partial class FormHorses + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + } +} \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormHorses.cs b/ProjectHorseRacingOrg/Forms/FormHorses.cs new file mode 100644 index 0000000..6c80fda --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormHorses.cs @@ -0,0 +1,114 @@ +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().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(); + 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(); + 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; + } + + } +} diff --git a/ProjectHorseRacingOrg/Forms/FormHorses.resx b/ProjectHorseRacingOrg/Forms/FormHorses.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormHorses.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormJockey.Designer.cs b/ProjectHorseRacingOrg/Forms/FormJockey.Designer.cs new file mode 100644 index 0000000..6fbb487 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormJockey.Designer.cs @@ -0,0 +1,141 @@ +namespace ProjectHorseRacingOrg.Forms +{ + partial class FormJockey + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + } +} \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormJockey.cs b/ProjectHorseRacingOrg/Forms/FormJockey.cs new file mode 100644 index 0000000..e72d036 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormJockey.cs @@ -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!); + } +} diff --git a/ProjectHorseRacingOrg/Forms/FormJockey.resx b/ProjectHorseRacingOrg/Forms/FormJockey.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormJockey.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormJockeys.Designer.cs b/ProjectHorseRacingOrg/Forms/FormJockeys.Designer.cs new file mode 100644 index 0000000..4b67f4d --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormJockeys.Designer.cs @@ -0,0 +1,126 @@ +namespace ProjectHorseRacingOrg.Forms +{ + partial class FormJockeys + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + } +} \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormJockeys.cs b/ProjectHorseRacingOrg/Forms/FormJockeys.cs new file mode 100644 index 0000000..c73b319 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormJockeys.cs @@ -0,0 +1,113 @@ +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().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(); + 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(); + 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; + } + } +} diff --git a/ProjectHorseRacingOrg/Forms/FormJockeys.resx b/ProjectHorseRacingOrg/Forms/FormJockeys.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormJockeys.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRace.Designer.cs b/ProjectHorseRacingOrg/Forms/FormRace.Designer.cs new file mode 100644 index 0000000..79b9e8b --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRace.Designer.cs @@ -0,0 +1,139 @@ +namespace ProjectHorseRacingOrg.Forms +{ + partial class FormRace + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + // + // buttonCancel + // + buttonCancel.Location = new Point(254, 341); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(95, 33); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // 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; + } +} \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRace.cs b/ProjectHorseRacingOrg/Forms/FormRace.cs new file mode 100644 index 0000000..30d808b --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRace.cs @@ -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); + } + + + } +} diff --git a/ProjectHorseRacingOrg/Forms/FormRace.resx b/ProjectHorseRacingOrg/Forms/FormRace.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRace.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRaceEntries.Designer.cs b/ProjectHorseRacingOrg/Forms/FormRaceEntries.Designer.cs new file mode 100644 index 0000000..5014f77 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRaceEntries.Designer.cs @@ -0,0 +1,152 @@ +namespace ProjectHorseRacingOrg.Forms +{ + partial class FormRaceEntries + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + } +} \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRaceEntries.cs b/ProjectHorseRacingOrg/Forms/FormRaceEntries.cs new file mode 100644 index 0000000..1e01e68 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRaceEntries.cs @@ -0,0 +1,78 @@ +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 = "FirstName"; + 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 + CreateListRaceEntryDetailsFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridView.Rows) + { + if (row.Cells["ColumnFeed"].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; + } + + } + +} diff --git a/ProjectHorseRacingOrg/Forms/FormRaceEntries.resx b/ProjectHorseRacingOrg/Forms/FormRaceEntries.resx new file mode 100644 index 0000000..66e606d --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRaceEntries.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRaces.Designer.cs b/ProjectHorseRacingOrg/Forms/FormRaces.Designer.cs new file mode 100644 index 0000000..33507fb --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRaces.Designer.cs @@ -0,0 +1,126 @@ +namespace ProjectHorseRacingOrg.Forms +{ + partial class FormRaces + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + } +} \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRaces.cs b/ProjectHorseRacingOrg/Forms/FormRaces.cs new file mode 100644 index 0000000..59e00a9 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRaces.cs @@ -0,0 +1,112 @@ +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().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(); + 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(); + 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; + } + + } +} diff --git a/ProjectHorseRacingOrg/Forms/FormRaces.resx b/ProjectHorseRacingOrg/Forms/FormRaces.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRaces.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRacesEntries.Designer.cs b/ProjectHorseRacingOrg/Forms/FormRacesEntries.Designer.cs new file mode 100644 index 0000000..ff551ac --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRacesEntries.Designer.cs @@ -0,0 +1,112 @@ +namespace ProjectHorseRacingOrg.Forms +{ + partial class FormRacesEntries + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + } +} \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRacesEntries.cs b/ProjectHorseRacingOrg/Forms/FormRacesEntries.cs new file mode 100644 index 0000000..e64ef07 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRacesEntries.cs @@ -0,0 +1,95 @@ +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().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(); + 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; + } + + } + } diff --git a/ProjectHorseRacingOrg/Forms/FormRacesEntries.resx b/ProjectHorseRacingOrg/Forms/FormRacesEntries.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRacesEntries.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRacingHorse.Designer.cs b/ProjectHorseRacingOrg/Forms/FormRacingHorse.Designer.cs new file mode 100644 index 0000000..bcf79b4 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRacingHorse.Designer.cs @@ -0,0 +1,169 @@ +namespace ProjectHorseRacingOrg.Forms +{ + partial class FormRacingHorse + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + } +} \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRacingHorse.cs b/ProjectHorseRacingOrg/Forms/FormRacingHorse.cs new file mode 100644 index 0000000..3120026 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRacingHorse.cs @@ -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 = "FirstName"; + comboBoxJockey.ValueMember = "Id"; + comboBoxRace.DataSource = raceRepository.ReadRaces(); + comboBoxRace.DisplayMember = "Name"; + comboBoxRace.ValueMember = "Id"; + comboBoxHorse.DataSource = horseRepository.ReadHorses(); + comboBoxHorse.DisplayMember = "HorseNickName"; + 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(); + + } +} diff --git a/ProjectHorseRacingOrg/Forms/FormRacingHorse.resx b/ProjectHorseRacingOrg/Forms/FormRacingHorse.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRacingHorse.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRacingHorses.Designer.cs b/ProjectHorseRacingOrg/Forms/FormRacingHorses.Designer.cs new file mode 100644 index 0000000..ddd0e10 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRacingHorses.Designer.cs @@ -0,0 +1,92 @@ +namespace ProjectHorseRacingOrg.Forms +{ + partial class FormRacingHorses + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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; + } +} \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Forms/FormRacingHorses.cs b/ProjectHorseRacingOrg/Forms/FormRacingHorses.cs new file mode 100644 index 0000000..e249bbc --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRacingHorses.cs @@ -0,0 +1,59 @@ +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().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + + MessageBox.Show(ex.Message, "Ошибка при добавлении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridViewData.DataSource = + _racingHorsesRepository.ReadRacingHorses(); + + } +} diff --git a/ProjectHorseRacingOrg/Forms/FormRacingHorses.resx b/ProjectHorseRacingOrg/Forms/FormRacingHorses.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectHorseRacingOrg/Forms/FormRacingHorses.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Program.cs b/ProjectHorseRacingOrg/Program.cs index b470679..7ef4c45 100644 --- a/ProjectHorseRacingOrg/Program.cs +++ b/ProjectHorseRacingOrg/Program.cs @@ -1,3 +1,8 @@ +using Unity.Lifetime; +using Unity; +using ProjectHorseRacingOrg.Repositories; +using ProjectHorseRacingOrg.Repositories.Implementations; + namespace ProjectHorseRacingOrg { internal static class Program @@ -11,7 +16,23 @@ 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()); + } + private static IUnityContainer CreateContainer() + { + var container = new UnityContainer(); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + return container; + } + } } \ No newline at end of file diff --git a/ProjectHorseRacingOrg/ProjectHorseRacingOrg.csproj b/ProjectHorseRacingOrg/ProjectHorseRacingOrg.csproj index 663fdb8..accbdf0 100644 --- a/ProjectHorseRacingOrg/ProjectHorseRacingOrg.csproj +++ b/ProjectHorseRacingOrg/ProjectHorseRacingOrg.csproj @@ -8,4 +8,23 @@ enable + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Properties/Resources.Designer.cs b/ProjectHorseRacingOrg/Properties/Resources.Designer.cs new file mode 100644 index 0000000..91b50ed --- /dev/null +++ b/ProjectHorseRacingOrg/Properties/Resources.Designer.cs @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectHorseRacingOrg.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом 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() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [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; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Добавить { + get { + object obj = ResourceManager.GetObject("Добавить", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Добавить1 { + get { + object obj = ResourceManager.GetObject("Добавить1", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap изменить { + get { + object obj = ResourceManager.GetObject("изменить", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap скачки { + get { + object obj = ResourceManager.GetObject("скачки", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap удалить { + get { + object obj = ResourceManager.GetObject("удалить", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ProjectHorseRacingOrg/Properties/Resources.resx b/ProjectHorseRacingOrg/Properties/Resources.resx new file mode 100644 index 0000000..5004dad --- /dev/null +++ b/ProjectHorseRacingOrg/Properties/Resources.resx @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\изменить.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\скачки.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Добавить.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\удалить.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Добавить1.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ProjectHorseRacingOrg/Repositories/IHorseRepository.cs b/ProjectHorseRacingOrg/Repositories/IHorseRepository.cs new file mode 100644 index 0000000..36f27ec --- /dev/null +++ b/ProjectHorseRacingOrg/Repositories/IHorseRepository.cs @@ -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 ReadHorses(); + Horse ReadHorseById(int id); + void CreateHorse(Horse horse); + void UpdateHorse(Horse horse); + void DeleteHorse(int id); +} diff --git a/ProjectHorseRacingOrg/Repositories/IJockeyRepository.cs b/ProjectHorseRacingOrg/Repositories/IJockeyRepository.cs new file mode 100644 index 0000000..2c804ff --- /dev/null +++ b/ProjectHorseRacingOrg/Repositories/IJockeyRepository.cs @@ -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 ReadJockeys(); + Jockey ReadJockeyById(int id); + void CreateJockey(Jockey jockey); + void UpdateJockey(Jockey jockey); + void DeleteJockey(int id); + +} diff --git a/ProjectHorseRacingOrg/Repositories/IRaceEntriesRepository.cs b/ProjectHorseRacingOrg/Repositories/IRaceEntriesRepository.cs new file mode 100644 index 0000000..01d0f94 --- /dev/null +++ b/ProjectHorseRacingOrg/Repositories/IRaceEntriesRepository.cs @@ -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 ReadRaceEntries(DateTime? dateForm = +null, DateTime? dateTo = null, +int? raceId = null, int? jockeyId = null); + + void CreateRaceEntries(RaceEntries raceEntries); + + void DeleteRaceEntries(int id); +} diff --git a/ProjectHorseRacingOrg/Repositories/IRaceRepository.cs b/ProjectHorseRacingOrg/Repositories/IRaceRepository.cs new file mode 100644 index 0000000..b6ded2f --- /dev/null +++ b/ProjectHorseRacingOrg/Repositories/IRaceRepository.cs @@ -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 ReadRaces(); + Race ReadRaceById(int id); + void CreateRace(Race race); + void UpdateRace(Race race); + void DeleteRace(int id); + +} diff --git a/ProjectHorseRacingOrg/Repositories/IRacingHorsesRepository.cs b/ProjectHorseRacingOrg/Repositories/IRacingHorsesRepository.cs new file mode 100644 index 0000000..c908150 --- /dev/null +++ b/ProjectHorseRacingOrg/Repositories/IRacingHorsesRepository.cs @@ -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 ReadRacingHorses(DateTime? dateForm = null, +DateTime? dateTo = null, int? raceId = null, +int? jockeyId = null, int? horseId = null); + void CreateRacingHorse(RacingHorses racingHorses); +} diff --git a/ProjectHorseRacingOrg/Repositories/Implementations/HorseRepository.cs b/ProjectHorseRacingOrg/Repositories/Implementations/HorseRepository.cs new file mode 100644 index 0000000..e232404 --- /dev/null +++ b/ProjectHorseRacingOrg/Repositories/Implementations/HorseRepository.cs @@ -0,0 +1,36 @@ +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 HorseRepository : IHorseRepository +{ + public void CreateHorse(Horse horse) + { + + } + + public void DeleteHorse(int id) + { + + } + + public Horse ReadHorseById(int id) + { + return Horse.CreateEntity(0, string.Empty, string.Empty, 0, 0); + } + + public IEnumerable ReadHorses() + { + return []; + } + + public void UpdateHorse(Horse horse) + { + + } +} diff --git a/ProjectHorseRacingOrg/Repositories/Implementations/JockeyRepository.cs b/ProjectHorseRacingOrg/Repositories/Implementations/JockeyRepository.cs new file mode 100644 index 0000000..a92e007 --- /dev/null +++ b/ProjectHorseRacingOrg/Repositories/Implementations/JockeyRepository.cs @@ -0,0 +1,38 @@ +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 +{ + public void CreateJockey(Jockey jockey) + { + + } + + public void DeleteJockey(int id) + { + + } + + public Jockey ReadJockeyById(int id) + { + return Jockey.CreateEntity(0, string.Empty, string.Empty, JockeyTitle.None); + + } + + public IEnumerable ReadJockeys() + { + return []; + } + + public void UpdateJockey(Jockey jockey) + { + + } +} diff --git a/ProjectHorseRacingOrg/Repositories/Implementations/RaceEntriesRepository.cs b/ProjectHorseRacingOrg/Repositories/Implementations/RaceEntriesRepository.cs new file mode 100644 index 0000000..e8ae20e --- /dev/null +++ b/ProjectHorseRacingOrg/Repositories/Implementations/RaceEntriesRepository.cs @@ -0,0 +1,26 @@ +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 RaceEntriesRepository : IRaceEntriesRepository +{ + public void CreateRaceEntries(RaceEntries raceEntries) + { + + } + + public void DeleteRaceEntries(int id) + { + + } + + public IEnumerable ReadRaceEntries(DateTime? dateForm = null, DateTime? dateTo = null, int? raceId = null, int? jockeyId = null) + { + return []; + } +} diff --git a/ProjectHorseRacingOrg/Repositories/Implementations/RaceRepository.cs b/ProjectHorseRacingOrg/Repositories/Implementations/RaceRepository.cs new file mode 100644 index 0000000..ec4498a --- /dev/null +++ b/ProjectHorseRacingOrg/Repositories/Implementations/RaceRepository.cs @@ -0,0 +1,40 @@ +using Microsoft.VisualBasic.FileIO; +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 RaceRepository : IRaceRepository +{ + public void CreateRace(Race race) + { + + } + + public void DeleteRace(int id) + { + + } + + public Race ReadRaceById(int id) + { + return Race.CreateEntity(0, RaceType.None, string.Empty, string.Empty); + + } + + public IEnumerable ReadRaces() + { + return []; + + } + + public void UpdateRace(Race race) + { + + } +} diff --git a/ProjectHorseRacingOrg/Repositories/Implementations/RacingHorsesRepository.cs b/ProjectHorseRacingOrg/Repositories/Implementations/RacingHorsesRepository.cs new file mode 100644 index 0000000..2b4f1ec --- /dev/null +++ b/ProjectHorseRacingOrg/Repositories/Implementations/RacingHorsesRepository.cs @@ -0,0 +1,21 @@ +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 +{ + public void CreateRacingHorse(RacingHorses racingHorses) + { + + } + + public IEnumerable ReadRacingHorses(DateTime? dateForm = null, DateTime? dateTo = null, int? raceId = null, int? jockeyId = null, int? horseId = null) + { + return []; + } +} diff --git a/ProjectHorseRacingOrg/Resources/Добавить.jpg b/ProjectHorseRacingOrg/Resources/Добавить.jpg new file mode 100644 index 0000000..fbeef11 Binary files /dev/null and b/ProjectHorseRacingOrg/Resources/Добавить.jpg differ diff --git a/ProjectHorseRacingOrg/Resources/Добавить1.jpg b/ProjectHorseRacingOrg/Resources/Добавить1.jpg new file mode 100644 index 0000000..fbeef11 Binary files /dev/null and b/ProjectHorseRacingOrg/Resources/Добавить1.jpg differ diff --git a/ProjectHorseRacingOrg/Resources/изменить.png b/ProjectHorseRacingOrg/Resources/изменить.png new file mode 100644 index 0000000..7d0dfd9 Binary files /dev/null and b/ProjectHorseRacingOrg/Resources/изменить.png differ diff --git a/ProjectHorseRacingOrg/Resources/скачки.jpg b/ProjectHorseRacingOrg/Resources/скачки.jpg new file mode 100644 index 0000000..8d362d8 Binary files /dev/null and b/ProjectHorseRacingOrg/Resources/скачки.jpg differ diff --git a/ProjectHorseRacingOrg/Resources/удалить.jpg b/ProjectHorseRacingOrg/Resources/удалить.jpg new file mode 100644 index 0000000..47cf7d1 Binary files /dev/null and b/ProjectHorseRacingOrg/Resources/удалить.jpg differ