diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorse.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorse.cs new file mode 100644 index 0000000..5269f89 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorse.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Entities; + +public class BuyHorse +{ + public int Id { get; private set; } + public int OwnersId { get; private set; } + public DateTime DatePurchase { get; private set; } + + public IEnumerable BuyHorseHorses { get; private set; } = []; + + public static BuyHorse CreateEntity(int id, int ownerId,DateTime date, IEnumerable buyHorseHorses) + { + return new BuyHorse + { + Id = id, + OwnersId = ownerId, + DatePurchase = date, + BuyHorseHorses = buyHorseHorses + }; + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorseHorse.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorseHorse.cs new file mode 100644 index 0000000..f8d653a --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/BuyHorseHorse.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.Runtime.InteropServices.JavaScript.JSType; + +namespace ProjectHorseRacing.Entities; + +public class BuyHorseHorse +{ + public int Id { get; private set; } + + public int HorseId { get; private set; } + + public static BuyHorseHorse CreateElement(int id, int horseId) + { + return new BuyHorseHorse + { + Id = id, + HorseId = horseId + }; + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/Enums/HorseCharacters.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/Enums/HorseCharacters.cs new file mode 100644 index 0000000..4371107 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/Enums/HorseCharacters.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Entities.Enums; + +[Flags] + +public enum HorseCharacters +{ + None = 0, + + Быстрая = 1, + + Выносливая = 2, + + Спокойная = 4, + + Сильная = 8, + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/Enums/HorseGender.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/Enums/HorseGender.cs new file mode 100644 index 0000000..20ecb85 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/Enums/HorseGender.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Entities.Enums; + +public enum HorseGender +{ + None = 0, + + Женский = 1, + + Мужской = 2 +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/Enums/RacePlaceEvent.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/Enums/RacePlaceEvent.cs new file mode 100644 index 0000000..a69eb77 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/Enums/RacePlaceEvent.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.Tracing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Entities.Enums; + +public enum RacePlaceEvent +{ + None = 0, + + Ипподром_1 = 1, + + Ипподром_2 = 2, + + Ипподром_3 = 3, + + Ипподром_4 = 4 +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/Horse.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/Horse.cs new file mode 100644 index 0000000..0829932 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/Horse.cs @@ -0,0 +1,34 @@ +using ProjectHorseRacing.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Entities; + +public class Horse +{ + public int Id { get; private set; } + + public string Nickname { get; private set; } = string.Empty; + + public HorseGender HorseGender { get; private set; } + + public int AgeHorse { get; private set; } + + public HorseCharacters HorseCharacters { get; private set; } + + + public static Horse CreateHorse(int id, string nickname, HorseGender horseGender, int ageHorse, HorseCharacters horseCharacters) + { + return new Horse + { + Id = id, + Nickname = nickname, + HorseGender = horseGender, + AgeHorse = ageHorse, + HorseCharacters = horseCharacters + }; + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/Jockey.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/Jockey.cs new file mode 100644 index 0000000..afcb351 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/Jockey.cs @@ -0,0 +1,34 @@ +using ProjectHorseRacing.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Entities; + +public class Jockey +{ + public int Id { get; private set; } + + public string FistName { get; private set; } = string.Empty; + + public string LastName { get; private set; } = string.Empty; + + public int Age { get; private set; } + + public double Rating { get; private set; } + + public static Jockey CreateEntity(int id, string fistName, string lastName, int age, double rating) + { + return new Jockey + { + Id = id, + FistName = fistName, + LastName = lastName, + Age = age, + Rating = rating + + }; + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/Owners.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/Owners.cs new file mode 100644 index 0000000..159d957 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/Owners.cs @@ -0,0 +1,29 @@ +namespace ProjectHorseRacing.Entities; + +public class Owners +{ + public int Id { get;private set; } + public string FistName { get; private set; } = string.Empty; + + public string LastName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public string PhoneNumber { get; private set; } = string.Empty; + + + public static Owners CreateEntity(int id, string fistName, string lastName, string address, string phoneNumber) + { + return new Owners + { + Id = id, + FistName = fistName, + LastName = lastName, + Address = address, + PhoneNumber = phoneNumber, + }; + } + +} + + diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/Race.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/Race.cs new file mode 100644 index 0000000..c2c7b03 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/Race.cs @@ -0,0 +1,29 @@ +using ProjectHorseRacing.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Entities; + +public class Race +{ + public int Id { get; private set; } + + public DateTime DateTime { get; private set; } + + public RacePlaceEvent RacePlaceEvent { get; private set; } + + + public static Race CreateOperation(int id, DateTime dateTime, RacePlaceEvent racePlaceEvent) + { + return new Race + { + Id = id, + DateTime = dateTime, + RacePlaceEvent = racePlaceEvent + }; + } + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Entities/Result.cs b/ProjectHorseRacing/ProjectHorseRacing/Entities/Result.cs new file mode 100644 index 0000000..42c8959 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Entities/Result.cs @@ -0,0 +1,34 @@ +using ProjectHorseRacing.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Entities; + +public class Result +{ + public int Id { get; private set; } + + public int Position { get; private set; } + + public int RacesId { get; private set; } + + public int JockeyId { get; private set; } + + public int HorsesId { get; private set; } + + public static Result CreateEntity(int id, int position, int racesId, int jockeyId, int horsesId) + { + return new Result + { + Id = id, + Position = position, + RacesId = racesId, + JockeyId = jockeyId, + HorsesId = horsesId + + }; + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Form1.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Form1.Designer.cs deleted file mode 100644 index 78b8133..0000000 --- a/ProjectHorseRacing/ProjectHorseRacing/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectHorseRacing -{ - 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/ProjectHorseRacing/ProjectHorseRacing/Form1.cs b/ProjectHorseRacing/ProjectHorseRacing/Form1.cs deleted file mode 100644 index 49ca883..0000000 --- a/ProjectHorseRacing/ProjectHorseRacing/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectHorseRacing -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/ProjectHorseRacing/ProjectHorseRacing/FormHorseRacing.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/FormHorseRacing.Designer.cs new file mode 100644 index 0000000..5321611 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/FormHorseRacing.Designer.cs @@ -0,0 +1,147 @@ +namespace ProjectHorseRacing +{ + 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(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + JockeyToolStripMenuItem = new ToolStripMenuItem(); + HorseToolStripMenuItem = new ToolStripMenuItem(); + RaceToolStripMenuItem = new ToolStripMenuItem(); + владелецToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); + ResultToolStripMenuItem = new ToolStripMenuItem(); + ListHorseToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(782, 28); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { JockeyToolStripMenuItem, HorseToolStripMenuItem, RaceToolStripMenuItem, владелецToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // JockeyToolStripMenuItem + // + JockeyToolStripMenuItem.Name = "JockeyToolStripMenuItem"; + JockeyToolStripMenuItem.Size = new Size(224, 26); + JockeyToolStripMenuItem.Text = "Жокей"; + JockeyToolStripMenuItem.Click += JockeyToolStripMenuItem_Click; + // + // HorseToolStripMenuItem + // + HorseToolStripMenuItem.Name = "HorseToolStripMenuItem"; + HorseToolStripMenuItem.Size = new Size(224, 26); + HorseToolStripMenuItem.Text = "Лошадь"; + HorseToolStripMenuItem.Click += HorseToolStripMenuItem_Click; + // + // RaceToolStripMenuItem + // + RaceToolStripMenuItem.Name = "RaceToolStripMenuItem"; + RaceToolStripMenuItem.Size = new Size(224, 26); + RaceToolStripMenuItem.Text = "Скачки"; + RaceToolStripMenuItem.Click += RaceToolStripMenuItem_Click; + // + // владелецToolStripMenuItem + // + владелецToolStripMenuItem.Name = "владелецToolStripMenuItem"; + владелецToolStripMenuItem.Size = new Size(224, 26); + владелецToolStripMenuItem.Text = "Владелец"; + владелецToolStripMenuItem.Click += владелецToolStripMenuItem_Click; + // + // операцииToolStripMenuItem + // + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ResultToolStripMenuItem, ListHorseToolStripMenuItem }); + операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; + операцииToolStripMenuItem.Size = new Size(95, 24); + операцииToolStripMenuItem.Text = "Операции"; + // + // ResultToolStripMenuItem + // + ResultToolStripMenuItem.Name = "ResultToolStripMenuItem"; + ResultToolStripMenuItem.Size = new Size(216, 26); + ResultToolStripMenuItem.Text = "Результат"; + ResultToolStripMenuItem.Click += ResultToolStripMenuItem_Click; + // + // ListHorseToolStripMenuItem + // + ListHorseToolStripMenuItem.Name = "ListHorseToolStripMenuItem"; + ListHorseToolStripMenuItem.Size = new Size(216, 26); + ListHorseToolStripMenuItem.Text = "Покупка лошадей"; + ListHorseToolStripMenuItem.Click += ListHorseToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(73, 24); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // FormHorseRacing + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + BackgroundImage = Properties.Resources.скачки; + BackgroundImageLayout = ImageLayout.Stretch; + ClientSize = new Size(782, 403); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormHorseRacing"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Скачки"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem операцииToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem JockeyToolStripMenuItem; + private ToolStripMenuItem HorseToolStripMenuItem; + private ToolStripMenuItem RaceToolStripMenuItem; + private ToolStripMenuItem ResultToolStripMenuItem; + private ToolStripMenuItem ListHorseToolStripMenuItem; + private ToolStripMenuItem владелецToolStripMenuItem; + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/FormHorseRacing.cs b/ProjectHorseRacing/ProjectHorseRacing/FormHorseRacing.cs new file mode 100644 index 0000000..0742ebb --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/FormHorseRacing.cs @@ -0,0 +1,102 @@ +using ProjectHorseRacing.Forms; +using System.ComponentModel; +using Unity; + +namespace ProjectHorseRacing +{ + public partial class FormHorseRacing : Form + { + + private readonly IUnityContainer _container; + public FormHorseRacing(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + + } + + + private void JockeyToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void HorseToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void RaceToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ResultToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ListHorseToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/FormHorseRacing.resx b/ProjectHorseRacing/ProjectHorseRacing/FormHorseRacing.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/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/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.Designer.cs new file mode 100644 index 0000000..d3db3d1 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.Designer.cs @@ -0,0 +1,170 @@ +namespace ProjectHorseRacing.Forms +{ + partial class FormBuyHorse + { + /// + /// 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() + { + SaveButtonOwner = new Button(); + CancelButtonOwner = new Button(); + groupBox = new GroupBox(); + dataGridView = new DataGridView(); + label2 = new Label(); + comboBoxOwner = new ComboBox(); + dateTimePicker = new DateTimePicker(); + label3 = new Label(); + ColumnHorse = new DataGridViewComboBoxColumn(); + groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // SaveButtonOwner + // + SaveButtonOwner.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + SaveButtonOwner.Location = new Point(109, 512); + SaveButtonOwner.Name = "SaveButtonOwner"; + SaveButtonOwner.Size = new Size(94, 29); + SaveButtonOwner.TabIndex = 26; + SaveButtonOwner.Text = "Сохранить"; + SaveButtonOwner.UseVisualStyleBackColor = true; + SaveButtonOwner.Click += SaveButtonOwner_Click; + // + // CancelButtonOwner + // + CancelButtonOwner.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + CancelButtonOwner.Location = new Point(287, 512); + CancelButtonOwner.Name = "CancelButtonOwner"; + CancelButtonOwner.Size = new Size(94, 29); + CancelButtonOwner.TabIndex = 38; + CancelButtonOwner.Text = "Отмена"; + CancelButtonOwner.UseVisualStyleBackColor = true; + CancelButtonOwner.Click += CancelButtonOwner_Click; + // + // groupBox + // + groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBox.Controls.Add(dataGridView); + groupBox.Location = new Point(25, 165); + groupBox.Name = "groupBox"; + groupBox.Size = new Size(438, 329); + groupBox.TabIndex = 40; + groupBox.TabStop = false; + groupBox.Text = "Лошади"; + // + // dataGridView + // + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnHorse }); + dataGridView.Location = new Point(0, 32); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(432, 291); + dataGridView.TabIndex = 0; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(88, 43); + label2.Name = "label2"; + label2.Size = new Size(78, 20); + label2.TabIndex = 42; + label2.Text = "Владелец:"; + // + // comboBoxOwner + // + comboBoxOwner.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxOwner.FormattingEnabled = true; + comboBoxOwner.Location = new Point(190, 35); + comboBoxOwner.Name = "comboBoxOwner"; + comboBoxOwner.Size = new Size(223, 28); + comboBoxOwner.TabIndex = 41; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(190, 103); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(223, 27); + dateTimePicker.TabIndex = 43; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(61, 110); + label3.Name = "label3"; + label3.Size = new Size(105, 20); + label3.TabIndex = 44; + label3.Text = "Дата покупки:"; + // + // ColumnHorse + // + ColumnHorse.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnHorse.HeaderText = "Лошадь"; + ColumnHorse.MinimumWidth = 6; + ColumnHorse.Name = "ColumnHorse"; + // + // FormBuyHorse + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(490, 562); + Controls.Add(label3); + Controls.Add(dateTimePicker); + Controls.Add(label2); + Controls.Add(comboBoxOwner); + Controls.Add(groupBox); + Controls.Add(CancelButtonOwner); + Controls.Add(SaveButtonOwner); + Name = "FormBuyHorse"; + StartPosition = FormStartPosition.CenterParent; + Text = "Покупка лошадей"; + groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Button CancelButtonOwner; + private Button SaveButtonOwner; + private ComboBox comboBoxCharacters; + private GroupBox groupBox1; + private GroupBox groupBox; + private DataGridView dataGridView; + private Label label2; + private ComboBox comboBoxOwner; + private DataGridViewComboBoxColumn ColumnHorse; + private DateTimePicker dateTimePicker; + private Label label3; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.cs new file mode 100644 index 0000000..68f7c75 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.cs @@ -0,0 +1,65 @@ +using ProjectHorseRacing.Entities; +using ProjectHorseRacing.Repositories; + +namespace ProjectHorseRacing.Forms; + +public partial class FormBuyHorse : Form +{ + private readonly IBuyHorseRepository _buyHorseRepository; + + public FormBuyHorse( + IBuyHorseRepository buyHorseRepository, + IOwnerRepository ownerRepository, + IHorseRepository horseRepository) + { + InitializeComponent(); + _buyHorseRepository = buyHorseRepository ?? + throw new ArgumentNullException(nameof(buyHorseRepository)); + comboBoxOwner.DataSource = ownerRepository.ReadOwners(); + comboBoxOwner.DisplayMember = "LastName"; + comboBoxOwner.ValueMember = "Id"; + + ColumnHorse.DataSource = horseRepository.ReadHorses(); + ColumnHorse.DisplayMember = "Nickname"; + ColumnHorse.ValueMember = "Id"; + + + } + private void SaveButtonOwner_Click(object sender, EventArgs e) + { + try + { + if (comboBoxOwner.SelectedIndex < 0 || + dataGridView.RowCount < 1) + { + throw new Exception("Имеются незаполненные поля"); + } + _buyHorseRepository.CreateBuyHorse(BuyHorse.CreateEntity(0, + (int)comboBoxOwner.SelectedValue!, + dateTimePicker.Value, + CreateListBuyHorsesListFromDataGrid())); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CancelButtonOwner_Click(object sender, EventArgs e) => Close(); + private List CreateListBuyHorsesListFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridView.Rows) + { + if (row.Cells["ColumnHorse"].Value == null) + { + continue; + } + list.Add(BuyHorseHorse.CreateElement( + 0, + Convert.ToInt32(row.Cells["ColumnHorse"].Value))); + } + return list; + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.resx new file mode 100644 index 0000000..4973883 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorse.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 + + + True + + \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorses.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorses.Designer.cs new file mode 100644 index 0000000..74e44df --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorses.Designer.cs @@ -0,0 +1,125 @@ +namespace ProjectHorseRacing.Forms +{ + partial class FormBuyHorses + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + panelJockey = new Panel(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panelJockey.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(637, 450); + dataGridView.TabIndex = 3; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.карандаш; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(34, 161); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(94, 94); + buttonUpd.TabIndex = 2; + buttonUpd.UseVisualStyleBackColor = true; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.минус; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(34, 287); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 94); + buttonDel.TabIndex = 1; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.плюс; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(34, 38); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 94); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // panelJockey + // + panelJockey.Controls.Add(buttonUpd); + panelJockey.Controls.Add(buttonDel); + panelJockey.Controls.Add(buttonAdd); + panelJockey.Dock = DockStyle.Right; + panelJockey.Location = new Point(637, 0); + panelJockey.Name = "panelJockey"; + panelJockey.Size = new Size(163, 450); + panelJockey.TabIndex = 2; + // + // FormBuyHorses + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panelJockey); + Name = "FormBuyHorses"; + Text = "Покупка лошадей"; + Load += FormBuyHorses_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panelJockey.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + private Panel panelJockey; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorses.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorses.cs new file mode 100644 index 0000000..74f96b7 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorses.cs @@ -0,0 +1,93 @@ +using ProjectHorseRacing.Repositories; +using ProjectHorseRacing.Repositories.Implementation; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectHorseRacing.Forms; + +public partial class FormBuyHorses : Form +{ + private readonly IUnityContainer _container; + + private readonly IBuyHorseRepository _buyHorseRepository; + + public FormBuyHorses(IUnityContainer container, IBuyHorseRepository buyHorseRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _buyHorseRepository = buyHorseRepository ?? + throw new ArgumentNullException(nameof(buyHorseRepository)); + } + + private void FormBuyHorses_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 + { + _buyHorseRepository.DeleteBuyHorse(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _buyHorseRepository.ReadBuyHorse(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + return true; + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Form1.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorses.resx similarity index 93% rename from ProjectHorseRacing/ProjectHorseRacing/Form1.resx rename to ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorses.resx index 1af7de1..af32865 100644 --- a/ProjectHorseRacing/ProjectHorseRacing/Form1.resx +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormBuyHorses.resx @@ -1,17 +1,17 @@  - diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorse.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorse.Designer.cs new file mode 100644 index 0000000..29284aa --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorse.Designer.cs @@ -0,0 +1,169 @@ +namespace ProjectHorseRacing.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() + { + comboBoxHorseGender = new ComboBox(); + CancelButtonHorse = new Button(); + SaveButtonHorse = new Button(); + textBoxNicknameHorse = new TextBox(); + NickNameHorse = new Label(); + AgeHorse = new Label(); + numericUpAgeHorse = new NumericUpDown(); + GenderHorse = new Label(); + Characters = new Label(); + checkedListBoxHorseCharacters = new CheckedListBox(); + ((System.ComponentModel.ISupportInitialize)numericUpAgeHorse).BeginInit(); + SuspendLayout(); + // + // comboBoxHorseGender + // + comboBoxHorseGender.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxHorseGender.FormattingEnabled = true; + comboBoxHorseGender.Location = new Point(237, 87); + comboBoxHorseGender.Name = "comboBoxHorseGender"; + comboBoxHorseGender.Size = new Size(151, 28); + comboBoxHorseGender.TabIndex = 0; + // + // CancelButtonHorse + // + CancelButtonHorse.Location = new Point(273, 376); + CancelButtonHorse.Name = "CancelButtonHorse"; + CancelButtonHorse.Size = new Size(94, 29); + CancelButtonHorse.TabIndex = 17; + CancelButtonHorse.Text = "Отмена"; + CancelButtonHorse.UseVisualStyleBackColor = true; + CancelButtonHorse.Click += CancelButtonHorse_Click_1; + // + // SaveButtonHorse + // + SaveButtonHorse.Location = new Point(138, 376); + SaveButtonHorse.Name = "SaveButtonHorse"; + SaveButtonHorse.Size = new Size(94, 29); + SaveButtonHorse.TabIndex = 16; + SaveButtonHorse.Text = "Сохранить"; + SaveButtonHorse.UseVisualStyleBackColor = true; + SaveButtonHorse.Click += SaveButtonHorse_Click; + // + // textBoxNicknameHorse + // + textBoxNicknameHorse.Location = new Point(237, 39); + textBoxNicknameHorse.Name = "textBoxNicknameHorse"; + textBoxNicknameHorse.Size = new Size(241, 27); + textBoxNicknameHorse.TabIndex = 13; + // + // NickNameHorse + // + NickNameHorse.AutoSize = true; + NickNameHorse.Location = new Point(31, 46); + NickNameHorse.Name = "NickNameHorse"; + NickNameHorse.Size = new Size(119, 20); + NickNameHorse.TabIndex = 10; + NickNameHorse.Text = "Кличка лошади:"; + // + // AgeHorse + // + AgeHorse.AutoSize = true; + AgeHorse.Location = new Point(31, 141); + AgeHorse.Name = "AgeHorse"; + AgeHorse.Size = new Size(125, 20); + AgeHorse.TabIndex = 18; + AgeHorse.Text = "Возраст лошади:"; + // + // numericUpAgeHorse + // + numericUpAgeHorse.Location = new Point(238, 141); + numericUpAgeHorse.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpAgeHorse.Name = "numericUpAgeHorse"; + numericUpAgeHorse.Size = new Size(150, 27); + numericUpAgeHorse.TabIndex = 19; + numericUpAgeHorse.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // GenderHorse + // + GenderHorse.AutoSize = true; + GenderHorse.Location = new Point(31, 95); + GenderHorse.Name = "GenderHorse"; + GenderHorse.Size = new Size(98, 20); + GenderHorse.TabIndex = 20; + GenderHorse.Text = "Пол лошади:"; + // + // Characters + // + Characters.AutoSize = true; + Characters.Location = new Point(31, 194); + Characters.Name = "Characters"; + Characters.Size = new Size(180, 20); + Characters.TabIndex = 21; + Characters.Text = "Характеристика лошади:"; + // + // checkedListBoxHorseCharacters + // + checkedListBoxHorseCharacters.FormattingEnabled = true; + checkedListBoxHorseCharacters.Location = new Point(237, 194); + checkedListBoxHorseCharacters.Name = "checkedListBoxHorseCharacters"; + checkedListBoxHorseCharacters.Size = new Size(211, 136); + checkedListBoxHorseCharacters.TabIndex = 22; + // + // FormHorse + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(515, 450); + Controls.Add(checkedListBoxHorseCharacters); + Controls.Add(Characters); + Controls.Add(GenderHorse); + Controls.Add(numericUpAgeHorse); + Controls.Add(AgeHorse); + Controls.Add(CancelButtonHorse); + Controls.Add(SaveButtonHorse); + Controls.Add(textBoxNicknameHorse); + Controls.Add(NickNameHorse); + Controls.Add(comboBoxHorseGender); + Name = "FormHorse"; + Text = "Лошадь"; + ((System.ComponentModel.ISupportInitialize)numericUpAgeHorse).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxHorseGender; + private ComboBox comboBoxCharactersHorse; + private Button CancelButtonHorse; + private Button SaveButtonHorse; + private TextBox textBoxNicknameHorse; + private Label NickNameHorse; + private Label AgeHorse; + private NumericUpDown numericUpAgeHorse; + private Label GenderHorse; + private Label Characters; + private CheckedListBox checkedListBoxHorseCharacters; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorse.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorse.cs new file mode 100644 index 0000000..c0f1f68 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorse.cs @@ -0,0 +1,116 @@ +using ProjectHorseRacing.Entities; +using ProjectHorseRacing.Entities.Enums; +using ProjectHorseRacing.Repositories; +using ProjectHorseRacing.Repositories.Implementation; +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 ProjectHorseRacing.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)); + } + + foreach (HorseCharacters elem in Enum.GetValues(typeof(HorseCharacters))) + { + if ((elem & horse.HorseCharacters) != 0) + { + checkedListBoxHorseCharacters.SetItemChecked(checkedListBoxHorseCharacters.Items.IndexOf(elem), true); + } + + } + + textBoxNicknameHorse.Text = horse.Nickname; + comboBoxHorseGender.SelectedItem = horse.HorseGender; + numericUpAgeHorse.Value = horse.AgeHorse; + + _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)); + + comboBoxHorseGender.DataSource = Enum.GetValues(typeof(HorseGender)); + + foreach (var elem in Enum.GetValues(typeof(HorseCharacters))) + { + checkedListBoxHorseCharacters.Items.Add(elem); + } + } + + private void SaveButtonHorse_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxNicknameHorse.Text) || + comboBoxHorseGender.SelectedIndex < 1 || + checkedListBoxHorseCharacters.CheckedItems.Count == 0) + { + 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 CancelButtonHorse_Click_1(object sender, EventArgs e) => Close(); + + + private Horse CreateHorse(int id) + { + HorseCharacters horseCharacters = HorseCharacters.None; + foreach (var elem in checkedListBoxHorseCharacters.CheckedItems) + { + horseCharacters |= (HorseCharacters)elem; + } + + return Horse.CreateHorse(id, textBoxNicknameHorse.Text, (HorseGender)comboBoxHorseGender.SelectedIndex, + Convert.ToInt32(numericUpAgeHorse.Value), horseCharacters); + + } + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorse.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorse.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorse.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/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorses.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorses.Designer.cs new file mode 100644 index 0000000..73cd77b --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorses.Designer.cs @@ -0,0 +1,126 @@ +namespace ProjectHorseRacing.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() + { + panelHorses = new Panel(); + ButtonUpd = new Button(); + ButtonDel = new Button(); + ButtonAdd = new Button(); + dataGridView = new DataGridView(); + panelHorses.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panelHorses + // + panelHorses.Controls.Add(ButtonUpd); + panelHorses.Controls.Add(ButtonDel); + panelHorses.Controls.Add(ButtonAdd); + panelHorses.Dock = DockStyle.Right; + panelHorses.Location = new Point(685, 0); + panelHorses.Name = "panelHorses"; + panelHorses.Size = new Size(153, 427); + panelHorses.TabIndex = 0; + // + // ButtonUpd + // + ButtonUpd.BackgroundImage = Properties.Resources.карандаш; + ButtonUpd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonUpd.Location = new Point(29, 165); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(94, 94); + ButtonUpd.TabIndex = 5; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonDel + // + ButtonDel.BackgroundImage = Properties.Resources.минус; + ButtonDel.BackgroundImageLayout = ImageLayout.Stretch; + ButtonDel.Location = new Point(29, 291); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(94, 94); + ButtonDel.TabIndex = 4; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonAdd + // + ButtonAdd.BackgroundImage = Properties.Resources.плюс; + ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonAdd.Location = new Point(29, 42); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(94, 94); + ButtonAdd.TabIndex = 3; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(685, 427); + dataGridView.TabIndex = 1; + // + // FormHorses + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(838, 427); + Controls.Add(dataGridView); + Controls.Add(panelHorses); + Name = "FormHorses"; + Text = "Лошади"; + Load += FormHorses_Load; + Click += FormHorses_Load; + panelHorses.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panelHorses; + private DataGridView dataGridView; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonAdd; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorses.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorses.cs new file mode 100644 index 0000000..e543a2e --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorses.cs @@ -0,0 +1,113 @@ +using ProjectHorseRacing.Repositories; +using ProjectHorseRacing.Repositories.Implementation; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectHorseRacing.Forms; + +public partial class 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() => dataGridView.DataSource = _horseRepository.ReadHorses(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + return true; + } + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorses.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormHorses.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/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/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockey.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockey.Designer.cs new file mode 100644 index 0000000..0717a7b --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockey.Designer.cs @@ -0,0 +1,171 @@ +namespace ProjectHorseRacing.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() + { + FirstNameJokey = new Label(); + AgeJockey = new Label(); + RatingJockey = new Label(); + textBoxFirstNameJokey = new TextBox(); + numericUpDownAgeJockey = new NumericUpDown(); + numericUpDownRatingJockey = new NumericUpDown(); + SaveButtonJockey = new Button(); + CancelButtonJockey = new Button(); + textBoxLastNameJokey = new TextBox(); + LastNameJokey = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownAgeJockey).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRatingJockey).BeginInit(); + SuspendLayout(); + // + // FirstNameJokey + // + FirstNameJokey.AutoSize = true; + FirstNameJokey.Location = new Point(21, 38); + FirstNameJokey.Name = "FirstNameJokey"; + FirstNameJokey.Size = new Size(89, 20); + FirstNameJokey.TabIndex = 0; + FirstNameJokey.Text = "Имя жокея:"; + // + // AgeJockey + // + AgeJockey.AutoSize = true; + AgeJockey.Location = new Point(22, 131); + AgeJockey.Name = "AgeJockey"; + AgeJockey.Size = new Size(114, 20); + AgeJockey.TabIndex = 1; + AgeJockey.Text = "Возраст жокея:"; + // + // RatingJockey + // + RatingJockey.AutoSize = true; + RatingJockey.Location = new Point(22, 182); + RatingJockey.Name = "RatingJockey"; + RatingJockey.Size = new Size(114, 20); + RatingJockey.TabIndex = 2; + RatingJockey.Text = "Рейтинг жокея:"; + // + // textBoxFirstNameJokey + // + textBoxFirstNameJokey.Location = new Point(153, 31); + textBoxFirstNameJokey.Name = "textBoxFirstNameJokey"; + textBoxFirstNameJokey.Size = new Size(234, 27); + textBoxFirstNameJokey.TabIndex = 3; + // + // numericUpDownAgeJockey + // + numericUpDownAgeJockey.Location = new Point(154, 124); + numericUpDownAgeJockey.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpDownAgeJockey.Name = "numericUpDownAgeJockey"; + numericUpDownAgeJockey.Size = new Size(125, 27); + numericUpDownAgeJockey.TabIndex = 6; + numericUpDownAgeJockey.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // numericUpDownRatingJockey + // + numericUpDownRatingJockey.DecimalPlaces = 2; + numericUpDownRatingJockey.Location = new Point(154, 175); + numericUpDownRatingJockey.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDownRatingJockey.Name = "numericUpDownRatingJockey"; + numericUpDownRatingJockey.Size = new Size(125, 27); + numericUpDownRatingJockey.TabIndex = 7; + numericUpDownRatingJockey.Value = new decimal(new int[] { 1, 0, 0, 131072 }); + // + // SaveButtonJockey + // + SaveButtonJockey.Location = new Point(96, 253); + SaveButtonJockey.Name = "SaveButtonJockey"; + SaveButtonJockey.Size = new Size(94, 29); + SaveButtonJockey.TabIndex = 8; + SaveButtonJockey.Text = "Сохранить"; + SaveButtonJockey.UseVisualStyleBackColor = true; + SaveButtonJockey.Click += SaveButtonJockey_Click; + // + // CancelButtonJockey + // + CancelButtonJockey.Location = new Point(231, 253); + CancelButtonJockey.Name = "CancelButtonJockey"; + CancelButtonJockey.Size = new Size(94, 29); + CancelButtonJockey.TabIndex = 9; + CancelButtonJockey.Text = "Отмена"; + CancelButtonJockey.UseVisualStyleBackColor = true; + CancelButtonJockey.Click += CancelButtonJockey_Click; + // + // textBoxLastNameJokey + // + textBoxLastNameJokey.Location = new Point(153, 77); + textBoxLastNameJokey.Name = "textBoxLastNameJokey"; + textBoxLastNameJokey.Size = new Size(234, 27); + textBoxLastNameJokey.TabIndex = 11; + // + // LastNameJokey + // + LastNameJokey.AutoSize = true; + LastNameJokey.Location = new Point(21, 84); + LastNameJokey.Name = "LastNameJokey"; + LastNameJokey.Size = new Size(123, 20); + LastNameJokey.TabIndex = 10; + LastNameJokey.Text = "Фамилия жокея:"; + // + // FormJockey + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(425, 320); + Controls.Add(textBoxLastNameJokey); + Controls.Add(LastNameJokey); + Controls.Add(CancelButtonJockey); + Controls.Add(SaveButtonJockey); + Controls.Add(numericUpDownRatingJockey); + Controls.Add(numericUpDownAgeJockey); + Controls.Add(textBoxFirstNameJokey); + Controls.Add(RatingJockey); + Controls.Add(AgeJockey); + Controls.Add(FirstNameJokey); + Name = "FormJockey"; + StartPosition = FormStartPosition.CenterParent; + Text = "Жокей"; + ((System.ComponentModel.ISupportInitialize)numericUpDownAgeJockey).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownRatingJockey).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label FirstNameJokey; + private Label AgeJockey; + private Label RatingJockey; + private TextBox textBoxFirstNameJokey; + private NumericUpDown numericUpDownAgeJockey; + private NumericUpDown numericUpDownRatingJockey; + private Button SaveButtonJockey; + private Button CancelButtonJockey; + private TextBox textBoxLastNameJokey; + private Label LastNameJokey; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockey.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockey.cs new file mode 100644 index 0000000..4e61356 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockey.cs @@ -0,0 +1,91 @@ +using ProjectHorseRacing.Entities; +using ProjectHorseRacing.Repositories; +using ProjectHorseRacing.Repositories.Implementation; +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 ProjectHorseRacing.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)); + } + + textBoxFirstNameJokey.Text = jockey.FistName; + textBoxLastNameJokey.Text = jockey.LastName; + numericUpDownAgeJockey.Value = jockey.Age; + numericUpDownRatingJockey.Value = (decimal)jockey.Rating; + _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)); + } + + + private void SaveButtonJockey_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFirstNameJokey.Text) || + string.IsNullOrWhiteSpace(textBoxLastNameJokey.Text)) + { + 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 CancelButtonJockey_Click(object sender, EventArgs e) => Close(); + + + private Jockey CreateJockey(int id) => Jockey.CreateEntity(id, + textBoxFirstNameJokey.Text, textBoxLastNameJokey.Text, + Convert.ToInt32(numericUpDownAgeJockey.Value), + Convert.ToDouble(numericUpDownRatingJockey.Value)); + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockey.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockey.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/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/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockeys.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockeys.Designer.cs new file mode 100644 index 0000000..95488c4 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockeys.Designer.cs @@ -0,0 +1,127 @@ +namespace ProjectHorseRacing.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() + { + panelJockey = new Panel(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panelJockey.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panelJockey + // + panelJockey.Controls.Add(buttonUpd); + panelJockey.Controls.Add(buttonDel); + panelJockey.Controls.Add(buttonAdd); + panelJockey.Dock = DockStyle.Right; + panelJockey.Location = new Point(683, 0); + panelJockey.Name = "panelJockey"; + panelJockey.Size = new Size(163, 425); + panelJockey.TabIndex = 0; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.карандаш; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(34, 161); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(94, 94); + buttonUpd.TabIndex = 2; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.минус; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(34, 287); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 94); + buttonDel.TabIndex = 1; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.плюс; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(34, 38); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 94); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(683, 425); + dataGridView.TabIndex = 1; + // + // FormJockeys + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(846, 425); + Controls.Add(dataGridView); + Controls.Add(panelJockey); + Name = "FormJockeys"; + StartPosition = FormStartPosition.CenterParent; + Text = "Жокеи"; + Load += FormJockeys_Load; + panelJockey.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panelJockey; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockeys.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockeys.cs new file mode 100644 index 0000000..abbdfa4 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockeys.cs @@ -0,0 +1,115 @@ +using ProjectHorseRacing.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectHorseRacing.Forms; + +public partial class 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() => dataGridView.DataSource = _jockeyRepository.ReadJockeys(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + return true; + } + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockeys.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormJockeys.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/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/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwner.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwner.Designer.cs new file mode 100644 index 0000000..e7a5aed --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwner.Designer.cs @@ -0,0 +1,161 @@ +namespace ProjectHorseRacing.Forms +{ + partial class FormOwner + { + /// + /// 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() + { + textBoxLastNameOwner = new TextBox(); + LastNameJokey = new Label(); + CancelButtonOwner = new Button(); + SaveButtonOwner = new Button(); + textBoxFirstNameOwner = new TextBox(); + RatingJockey = new Label(); + AgeJockey = new Label(); + FirstNameJokey = new Label(); + textBoxAddressOwner = new TextBox(); + textBoxPhoneNumberOwner = new TextBox(); + SuspendLayout(); + // + // textBoxLastNameOwner + // + textBoxLastNameOwner.Location = new Point(245, 81); + textBoxLastNameOwner.Name = "textBoxLastNameOwner"; + textBoxLastNameOwner.Size = new Size(234, 27); + textBoxLastNameOwner.TabIndex = 21; + // + // LastNameJokey + // + LastNameJokey.AutoSize = true; + LastNameJokey.Location = new Point(31, 84); + LastNameJokey.Name = "LastNameJokey"; + LastNameJokey.Size = new Size(153, 20); + LastNameJokey.TabIndex = 20; + LastNameJokey.Text = "Фамилия владельца:"; + // + // CancelButtonOwner + // + CancelButtonOwner.Location = new Point(293, 253); + CancelButtonOwner.Name = "CancelButtonOwner"; + CancelButtonOwner.Size = new Size(94, 29); + CancelButtonOwner.TabIndex = 19; + CancelButtonOwner.Text = "Отмена"; + CancelButtonOwner.UseVisualStyleBackColor = true; + CancelButtonOwner.Click += CancelButtonOwner_Click; + // + // SaveButtonOwner + // + SaveButtonOwner.Location = new Point(106, 253); + SaveButtonOwner.Name = "SaveButtonOwner"; + SaveButtonOwner.Size = new Size(94, 29); + SaveButtonOwner.TabIndex = 18; + SaveButtonOwner.Text = "Сохранить"; + SaveButtonOwner.UseVisualStyleBackColor = true; + SaveButtonOwner.Click += SaveButtonOwner_Click; + // + // textBoxFirstNameOwner + // + textBoxFirstNameOwner.Location = new Point(245, 35); + textBoxFirstNameOwner.Name = "textBoxFirstNameOwner"; + textBoxFirstNameOwner.Size = new Size(234, 27); + textBoxFirstNameOwner.TabIndex = 15; + // + // RatingJockey + // + RatingJockey.AutoSize = true; + RatingJockey.Location = new Point(32, 182); + RatingJockey.Name = "RatingJockey"; + RatingJockey.Size = new Size(207, 20); + RatingJockey.TabIndex = 14; + RatingJockey.Text = "Номер телефона владельца:"; + // + // AgeJockey + // + AgeJockey.AutoSize = true; + AgeJockey.Location = new Point(32, 131); + AgeJockey.Name = "AgeJockey"; + AgeJockey.Size = new Size(131, 20); + AgeJockey.TabIndex = 13; + AgeJockey.Text = "Адрес владельца:"; + // + // FirstNameJokey + // + FirstNameJokey.AutoSize = true; + FirstNameJokey.Location = new Point(31, 38); + FirstNameJokey.Name = "FirstNameJokey"; + FirstNameJokey.Size = new Size(119, 20); + FirstNameJokey.TabIndex = 12; + FirstNameJokey.Text = "Имя владельца:"; + // + // textBoxAddressOwner + // + textBoxAddressOwner.Location = new Point(245, 128); + textBoxAddressOwner.Name = "textBoxAddressOwner"; + textBoxAddressOwner.Size = new Size(234, 27); + textBoxAddressOwner.TabIndex = 22; + // + // textBoxPhoneNumberOwner + // + textBoxPhoneNumberOwner.Location = new Point(245, 179); + textBoxPhoneNumberOwner.Name = "textBoxPhoneNumberOwner"; + textBoxPhoneNumberOwner.Size = new Size(234, 27); + textBoxPhoneNumberOwner.TabIndex = 23; + // + // FormOwner + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(513, 315); + Controls.Add(textBoxPhoneNumberOwner); + Controls.Add(textBoxAddressOwner); + Controls.Add(textBoxLastNameOwner); + Controls.Add(LastNameJokey); + Controls.Add(CancelButtonOwner); + Controls.Add(SaveButtonOwner); + Controls.Add(textBoxFirstNameOwner); + Controls.Add(RatingJockey); + Controls.Add(AgeJockey); + Controls.Add(FirstNameJokey); + Name = "FormOwner"; + Text = "Владелец"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxLastNameOwner; + private Label LastNameJokey; + private Button CancelButtonOwner; + private Button SaveButtonOwner; + private TextBox textBoxFirstNameOwner; + private Label RatingJockey; + private Label AgeJockey; + private Label FirstNameJokey; + private TextBox textBoxAddressOwner; + private TextBox textBoxPhoneNumberOwner; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwner.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwner.cs new file mode 100644 index 0000000..70b4b94 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwner.cs @@ -0,0 +1,88 @@ +using ProjectHorseRacing.Entities; +using ProjectHorseRacing.Repositories; +using ProjectHorseRacing.Repositories.Implementation; +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 ProjectHorseRacing.Forms; + +public partial class FormOwner : Form +{ + private readonly IOwnerRepository _ownerRepository; + + private int? _ownerId; + + public int Id + { + set + { + try + { + var owner = _ownerRepository.ReadOwnerById(value); + if (owner == null) + { + throw new InvalidDataException(nameof(owner)); + } + + textBoxFirstNameOwner.Text = owner.FistName; + textBoxLastNameOwner.Text = owner.LastName; + textBoxAddressOwner.Text = owner.Address; + textBoxPhoneNumberOwner.Text = owner.PhoneNumber; + _ownerId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormOwner(IOwnerRepository ownerRepository) + { + InitializeComponent(); + _ownerRepository = ownerRepository ?? + throw new ArgumentNullException(nameof(ownerRepository)); + } + + private void SaveButtonOwner_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFirstNameOwner.Text) || + string.IsNullOrWhiteSpace(textBoxLastNameOwner.Text) || + string.IsNullOrWhiteSpace(textBoxAddressOwner.Text) || + string.IsNullOrWhiteSpace(textBoxPhoneNumberOwner.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_ownerId.HasValue) + { + _ownerRepository.UpdateOwner(CreateOwner(_ownerId.Value)); + } + else + { + _ownerRepository.CreateOwner(CreateOwner(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CancelButtonOwner_Click(object sender, EventArgs e) => Close(); + + private Owners CreateOwner(int id) => Owners.CreateEntity(id, + textBoxFirstNameOwner.Text, textBoxLastNameOwner.Text, + textBoxAddressOwner.Text, textBoxPhoneNumberOwner.Text); + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwner.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwner.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwner.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/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwners.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwners.Designer.cs new file mode 100644 index 0000000..4fc651e --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwners.Designer.cs @@ -0,0 +1,125 @@ +namespace ProjectHorseRacing.Forms +{ + partial class FormOwners + { + /// + /// 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() + { + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panelOwner = new Panel(); + ButtonUpd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panelOwner.SuspendLayout(); + SuspendLayout(); + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.минус; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(34, 287); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 94); + buttonDel.TabIndex = 1; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.плюс; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(34, 38); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 94); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(637, 450); + dataGridView.TabIndex = 3; + // + // panelOwner + // + panelOwner.Controls.Add(ButtonUpd); + panelOwner.Controls.Add(buttonDel); + panelOwner.Controls.Add(buttonAdd); + panelOwner.Dock = DockStyle.Right; + panelOwner.Location = new Point(637, 0); + panelOwner.Name = "panelOwner"; + panelOwner.Size = new Size(163, 450); + panelOwner.TabIndex = 2; + // + // ButtonUpd + // + ButtonUpd.BackgroundImage = Properties.Resources.карандаш; + ButtonUpd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonUpd.Location = new Point(34, 163); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(94, 94); + ButtonUpd.TabIndex = 6; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // FormOwners + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panelOwner); + Name = "FormOwners"; + Text = "Владельцы"; + Load += FormOwners_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panelOwner.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + private Button buttonDel; + private Button buttonAdd; + private DataGridView dataGridView; + private Panel panelOwner; + private Button ButtonUpd; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwners.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwners.cs new file mode 100644 index 0000000..5421f91 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwners.cs @@ -0,0 +1,114 @@ +using ProjectHorseRacing.Repositories; +using ProjectHorseRacing.Repositories.Implementation; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectHorseRacing.Forms; + +public partial class FormOwners : Form +{ + + private readonly IUnityContainer _container; + + private readonly IOwnerRepository _ownerRepository; + + public FormOwners(IUnityContainer container, IOwnerRepository ownerRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _ownerRepository = ownerRepository ?? + throw new ArgumentNullException(nameof(ownerRepository)); + } + + + private void FormOwners_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 + { + _ownerRepository.DeleteOwner(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _ownerRepository.ReadOwners(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + return true; + } + + 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); + } + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwners.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwners.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormOwners.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/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRace.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRace.Designer.cs new file mode 100644 index 0000000..163602a --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRace.Designer.cs @@ -0,0 +1,128 @@ +namespace ProjectHorseRacing.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() + { + GenderHorse = new Label(); + CancelButtonHorse = new Button(); + SaveButtonHorse = new Button(); + DateTime = new Label(); + comboBoxPlaceEvent = new ComboBox(); + dateTimePicker = new DateTimePicker(); + dateTimePicker1 = new DateTimePicker(); + SuspendLayout(); + // + // GenderHorse + // + GenderHorse.AutoSize = true; + GenderHorse.Location = new Point(30, 89); + GenderHorse.Name = "GenderHorse"; + GenderHorse.Size = new Size(194, 20); + GenderHorse.TabIndex = 30; + GenderHorse.Text = "Место проведения скачки:"; + // + // CancelButtonHorse + // + CancelButtonHorse.Location = new Point(265, 149); + CancelButtonHorse.Name = "CancelButtonHorse"; + CancelButtonHorse.Size = new Size(94, 29); + CancelButtonHorse.TabIndex = 27; + CancelButtonHorse.Text = "Отмена"; + CancelButtonHorse.UseVisualStyleBackColor = true; + CancelButtonHorse.Click += CancelButtonHorse_Click; + // + // SaveButtonHorse + // + SaveButtonHorse.Location = new Point(130, 149); + SaveButtonHorse.Name = "SaveButtonHorse"; + SaveButtonHorse.Size = new Size(94, 29); + SaveButtonHorse.TabIndex = 26; + SaveButtonHorse.Text = "Сохранить"; + SaveButtonHorse.UseVisualStyleBackColor = true; + SaveButtonHorse.Click += SaveButtonHorse_Click; + // + // DateTime + // + DateTime.AutoSize = true; + DateTime.Location = new Point(30, 35); + DateTime.Name = "DateTime"; + DateTime.Size = new Size(183, 20); + DateTime.TabIndex = 24; + DateTime.Text = "Дата проведения скачки:"; + // + // comboBoxPlaceEvent + // + comboBoxPlaceEvent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxPlaceEvent.FormattingEnabled = true; + comboBoxPlaceEvent.Location = new Point(246, 81); + comboBoxPlaceEvent.Name = "comboBoxPlaceEvent"; + comboBoxPlaceEvent.Size = new Size(190, 28); + comboBoxPlaceEvent.TabIndex = 22; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(0, 0); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(200, 27); + dateTimePicker.TabIndex = 0; + // + // dateTimePicker1 + // + dateTimePicker1.Location = new Point(244, 34); + dateTimePicker1.Name = "dateTimePicker1"; + dateTimePicker1.Size = new Size(192, 27); + dateTimePicker1.TabIndex = 31; + // + // FormRace + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(477, 218); + Controls.Add(dateTimePicker1); + Controls.Add(GenderHorse); + Controls.Add(CancelButtonHorse); + Controls.Add(SaveButtonHorse); + Controls.Add(DateTime); + Controls.Add(comboBoxPlaceEvent); + Name = "FormRace"; + StartPosition = FormStartPosition.CenterParent; + Text = "Скачка"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label GenderHorse; + private Button CancelButtonHorse; + private Button SaveButtonHorse; + private Label DateTime; + private ComboBox comboBoxPlaceEvent; + private DateTimePicker dateTimePicker; + private DateTimePicker dateTimePicker1; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRace.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRace.cs new file mode 100644 index 0000000..46ec46d --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRace.cs @@ -0,0 +1,87 @@ +using ProjectHorseRacing.Entities; +using ProjectHorseRacing.Entities.Enums; +using ProjectHorseRacing.Repositories; +using ProjectHorseRacing.Repositories.Implementation; +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 ProjectHorseRacing.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)); + } + + dateTimePicker.Value = race.DateTime; + comboBoxPlaceEvent.SelectedItem = race.RacePlaceEvent; + + _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)); + + comboBoxPlaceEvent.DataSource = Enum.GetValues(typeof(RacePlaceEvent)); + } + + private void SaveButtonHorse_Click(object sender, EventArgs e) + { + try + { + if (comboBoxPlaceEvent.SelectedIndex < 1) + { + 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 CancelButtonHorse_Click(object sender, EventArgs e) => Close(); + + private Race CreateRace(int id) => Race.CreateOperation(id, dateTimePicker.Value, (RacePlaceEvent)comboBoxPlaceEvent.SelectedItem!); + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRace.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRace.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/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/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRaces.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRaces.Designer.cs new file mode 100644 index 0000000..0fd09d9 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRaces.Designer.cs @@ -0,0 +1,126 @@ +namespace ProjectHorseRacing.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() + { + panel1 = new Panel(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(662, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(149, 450); + panel1.TabIndex = 0; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.карандаш; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(33, 177); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(94, 94); + buttonUpd.TabIndex = 5; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.минус; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(33, 303); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 94); + buttonDel.TabIndex = 4; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.плюс; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(33, 54); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 94); + buttonAdd.TabIndex = 3; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(662, 450); + dataGridView.TabIndex = 1; + // + // FormRaces + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(811, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormRaces"; + StartPosition = FormStartPosition.CenterParent; + Text = "Скачки"; + Load += FormRaces_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridView; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRaces.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRaces.cs new file mode 100644 index 0000000..629fa5a --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRaces.cs @@ -0,0 +1,109 @@ +using ProjectHorseRacing.Repositories; +using ProjectHorseRacing.Repositories.Implementation; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectHorseRacing.Forms; + +public partial class 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() => dataGridView.DataSource = _raceRepository.ReadRaces(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + return true; + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRaces.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormRaces.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/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/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResult.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResult.Designer.cs new file mode 100644 index 0000000..a082341 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResult.Designer.cs @@ -0,0 +1,172 @@ +namespace ProjectHorseRacing.Forms +{ + partial class FormResult + { + /// + /// 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() + { + comboBoxRace = new ComboBox(); + comboBoxJockey = new ComboBox(); + comboBoxHorse = new ComboBox(); + numericUpDownPosition = new NumericUpDown(); + Position = new Label(); + Race = new Label(); + label1 = new Label(); + label2 = new Label(); + CancelButtonResult = new Button(); + SaveButtonResult = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPosition).BeginInit(); + SuspendLayout(); + // + // comboBoxRace + // + comboBoxRace.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxRace.FormattingEnabled = true; + comboBoxRace.Location = new Point(236, 80); + comboBoxRace.Name = "comboBoxRace"; + comboBoxRace.Size = new Size(223, 28); + comboBoxRace.TabIndex = 0; + // + // comboBoxJockey + // + comboBoxJockey.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxJockey.FormattingEnabled = true; + comboBoxJockey.Location = new Point(236, 129); + comboBoxJockey.Name = "comboBoxJockey"; + comboBoxJockey.Size = new Size(223, 28); + comboBoxJockey.TabIndex = 1; + // + // comboBoxHorse + // + comboBoxHorse.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxHorse.FormattingEnabled = true; + comboBoxHorse.Location = new Point(236, 176); + comboBoxHorse.Name = "comboBoxHorse"; + comboBoxHorse.Size = new Size(223, 28); + comboBoxHorse.TabIndex = 2; + // + // numericUpDownPosition + // + numericUpDownPosition.Location = new Point(236, 36); + numericUpDownPosition.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpDownPosition.Name = "numericUpDownPosition"; + numericUpDownPosition.Size = new Size(150, 27); + numericUpDownPosition.TabIndex = 3; + numericUpDownPosition.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // Position + // + Position.AutoSize = true; + Position.Location = new Point(24, 43); + Position.Name = "Position"; + Position.Size = new Size(194, 20); + Position.TabIndex = 4; + Position.Text = "Место, занятое на скачках:"; + // + // Race + // + Race.AutoSize = true; + Race.Location = new Point(24, 88); + Race.Name = "Race"; + Race.Size = new Size(60, 20); + Race.TabIndex = 5; + Race.Text = "Скачки:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(24, 137); + label1.Name = "label1"; + label1.Size = new Size(58, 20); + label1.TabIndex = 6; + label1.Text = "Жокей:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(24, 184); + label2.Name = "label2"; + label2.Size = new Size(67, 20); + label2.TabIndex = 7; + label2.Text = "Лошадь:"; + // + // CancelButtonResult + // + CancelButtonResult.Location = new Point(270, 244); + CancelButtonResult.Name = "CancelButtonResult"; + CancelButtonResult.Size = new Size(94, 29); + CancelButtonResult.TabIndex = 19; + CancelButtonResult.Text = "Отмена"; + CancelButtonResult.UseVisualStyleBackColor = true; + CancelButtonResult.Click += CancelButtonResult_Click; + // + // SaveButtonResult + // + SaveButtonResult.Location = new Point(135, 244); + SaveButtonResult.Name = "SaveButtonResult"; + SaveButtonResult.Size = new Size(94, 29); + SaveButtonResult.TabIndex = 18; + SaveButtonResult.Text = "Сохранить"; + SaveButtonResult.UseVisualStyleBackColor = true; + SaveButtonResult.Click += SaveButtonResult_Click; + // + // FormResult + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(538, 307); + Controls.Add(CancelButtonResult); + Controls.Add(SaveButtonResult); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(Race); + Controls.Add(Position); + Controls.Add(numericUpDownPosition); + Controls.Add(comboBoxHorse); + Controls.Add(comboBoxJockey); + Controls.Add(comboBoxRace); + Name = "FormResult"; + StartPosition = FormStartPosition.CenterParent; + Text = "Результат"; + ((System.ComponentModel.ISupportInitialize)numericUpDownPosition).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxRace; + private ComboBox comboBoxJockey; + private ComboBox comboBoxHorse; + private NumericUpDown numericUpDownPosition; + private Label Position; + private Label Race; + private Label label1; + private Label label2; + private Button CancelButtonResult; + private Button SaveButtonResult; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResult.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResult.cs new file mode 100644 index 0000000..37b2c44 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResult.cs @@ -0,0 +1,66 @@ +using ProjectHorseRacing.Entities; +using ProjectHorseRacing.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectHorseRacing.Forms; + +public partial class FormResult : Form +{ + private readonly IResultRepository _resultRepository; + + public FormResult(IResultRepository resultRepository, + IRaceRepository raceRepository, IJockeyRepository jockeyRepository, + IHorseRepository horseRepository) + { + InitializeComponent(); + _resultRepository = resultRepository ?? + throw new ArgumentNullException(nameof(resultRepository)); + + comboBoxRace.DataSource =raceRepository.ReadRaces(); + comboBoxRace.DisplayMember = "DateTime"; + comboBoxRace.ValueMember = "Id"; + + comboBoxJockey.DataSource = jockeyRepository.ReadJockeys(); + comboBoxJockey.DisplayMember = "FirstName"; + comboBoxJockey.ValueMember = "Id"; + + comboBoxHorse.DataSource = horseRepository.ReadHorses(); + comboBoxHorse.DisplayMember = "Nickname"; + comboBoxHorse.ValueMember = "Id"; + + } + + private void SaveButtonResult_Click(object sender, EventArgs e) + { + try + { + if (comboBoxRace.SelectedIndex < 0 || + comboBoxJockey.SelectedIndex < 0 || + comboBoxHorse.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + _resultRepository.CreateResult(Result.CreateEntity(0, + Convert.ToInt32(numericUpDownPosition.Value), + (int)comboBoxRace.SelectedValue!, (int)comboBoxJockey.SelectedValue!, + (int)comboBoxHorse.SelectedValue!)); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void CancelButtonResult_Click(object sender, EventArgs e) => Close(); +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResult.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResult.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResult.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/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResults.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResults.Designer.cs new file mode 100644 index 0000000..aa56f73 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResults.Designer.cs @@ -0,0 +1,92 @@ +namespace ProjectHorseRacing.Forms +{ + partial class FormResults + { + /// + /// 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(); + dataGridView = new DataGridView(); + ButtonAdd = new Button(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(ButtonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(652, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(148, 450); + panel1.TabIndex = 0; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(652, 450); + dataGridView.TabIndex = 1; + // + // ButtonAdd + // + ButtonAdd.BackgroundImage = Properties.Resources.плюс; + ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonAdd.Location = new Point(29, 30); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(94, 94); + ButtonAdd.TabIndex = 4; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // FormResults + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormResults"; + Text = "Результаты"; + Load += FormResults_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridView; + private Button ButtonAdd; + } +} \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResults.cs b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResults.cs new file mode 100644 index 0000000..75eb4d2 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResults.cs @@ -0,0 +1,60 @@ +using ProjectHorseRacing.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectHorseRacing.Forms; + +public partial class FormResults : Form +{ + + private readonly IUnityContainer _container; + private readonly IResultRepository _resultRepository; + + public FormResults(IUnityContainer container, IResultRepository resultRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _resultRepository = resultRepository ?? + throw new ArgumentNullException(nameof(resultRepository)); + } + + private void FormResults_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() => dataGridView.DataSource = _resultRepository.ReadResults(); + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResults.resx b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResults.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Forms/FormResults.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/ProjectHorseRacing/ProjectHorseRacing/Program.cs b/ProjectHorseRacing/ProjectHorseRacing/Program.cs index 26c34ad..80ed3d6 100644 --- a/ProjectHorseRacing/ProjectHorseRacing/Program.cs +++ b/ProjectHorseRacing/ProjectHorseRacing/Program.cs @@ -1,3 +1,8 @@ +using Unity.Lifetime; +using Unity; +using ProjectHorseRacing.Repositories.Implementation; +using ProjectHorseRacing.Repositories; + namespace ProjectHorseRacing { internal static class Program @@ -11,7 +16,21 @@ namespace ProjectHorseRacing // 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()); + container.RegisterType(new TransientLifetimeManager()); + + return container; } } } \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/ProjectHorseRacing.csproj b/ProjectHorseRacing/ProjectHorseRacing/ProjectHorseRacing.csproj index 663fdb8..accbdf0 100644 --- a/ProjectHorseRacing/ProjectHorseRacing/ProjectHorseRacing.csproj +++ b/ProjectHorseRacing/ProjectHorseRacing/ProjectHorseRacing.csproj @@ -8,4 +8,23 @@ enable + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Properties/Resources.Designer.cs b/ProjectHorseRacing/ProjectHorseRacing/Properties/Resources.Designer.cs new file mode 100644 index 0000000..93a9b5d --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectHorseRacing.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("ProjectHorseRacing.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 минус { + 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/ProjectHorseRacing/ProjectHorseRacing/Properties/Resources.resx b/ProjectHorseRacing/ProjectHorseRacing/Properties/Resources.resx new file mode 100644 index 0000000..48e88b6 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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\скачки.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\плюс.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\минус.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\карандаш.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/IBuyHorseRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IBuyHorseRepository.cs new file mode 100644 index 0000000..3f861a2 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IBuyHorseRepository.cs @@ -0,0 +1,17 @@ +using ProjectHorseRacing.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Repositories; + +public interface IBuyHorseRepository +{ + IEnumerable ReadBuyHorse(); + + void CreateBuyHorse(BuyHorse buyHorse); + + void DeleteBuyHorse(int id); +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/IHorseRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IHorseRepository.cs new file mode 100644 index 0000000..da6db78 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IHorseRepository.cs @@ -0,0 +1,21 @@ +using ProjectHorseRacing.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.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/ProjectHorseRacing/ProjectHorseRacing/Repositories/IJockeyRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IJockeyRepository.cs new file mode 100644 index 0000000..6b741ed --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IJockeyRepository.cs @@ -0,0 +1,21 @@ +using ProjectHorseRacing.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.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/ProjectHorseRacing/ProjectHorseRacing/Repositories/IOwnerRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IOwnerRepository.cs new file mode 100644 index 0000000..35386a4 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IOwnerRepository.cs @@ -0,0 +1,16 @@ +using ProjectHorseRacing.Entities; + +namespace ProjectHorseRacing.Repositories; + +public interface IOwnerRepository +{ + IEnumerable ReadOwners(); + + Owners ReadOwnerById(int id); + + void CreateOwner(Owners owner); + + void UpdateOwner(Owners owner); + + void DeleteOwner(int id); +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/IRaceRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IRaceRepository.cs new file mode 100644 index 0000000..2c4a0b3 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IRaceRepository.cs @@ -0,0 +1,21 @@ +using ProjectHorseRacing.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Repositories; + +public interface IRaceRepository +{ + IEnumerable ReadRaces(DateTime? dateFrom = null, DateTime? dateTo = null); + + Race ReadRaceById(int id); + + void CreateRace(Race race); + + void UpdateRace(Race race); + + void DeleteRace(int id); +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/IResultRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IResultRepository.cs new file mode 100644 index 0000000..c5d7228 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/IResultRepository.cs @@ -0,0 +1,16 @@ +using ProjectHorseRacing.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Repositories; + +public interface IResultRepository +{ + IEnumerable ReadResults(int? RaceId = null, int? JockeyId = null, int? HorseId = null); + + void CreateResult(Result result); + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/BuyHorseRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/BuyHorseRepository.cs new file mode 100644 index 0000000..48e251a --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/BuyHorseRepository.cs @@ -0,0 +1,24 @@ +using ProjectHorseRacing.Entities.Enums; +using ProjectHorseRacing.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Repositories.Implementation; + +public class BuyHorseRepository : IBuyHorseRepository +{ + public void CreateBuyHorse(BuyHorse buyHorse) + { + } + public void DeleteBuyHorse(int id) + { + } + + public IEnumerable ReadBuyHorse() + { + return []; + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/HorseRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/HorseRepository.cs new file mode 100644 index 0000000..0a4a7f2 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/HorseRepository.cs @@ -0,0 +1,31 @@ +using ProjectHorseRacing.Entities; +using ProjectHorseRacing.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Repositories.Implementation; + +public class HorseRepository : IHorseRepository +{ + public void CreateHorse(Horse horse) + { + } + public void DeleteHorse(int id) + { + } + public Horse ReadHorseById(int id) + { + return Horse.CreateHorse(0, string.Empty, HorseGender.None, 0, HorseCharacters.None); + } + public IEnumerable ReadHorses() + { + return []; + } + public void UpdateHorse(Horse horse) + { + } + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/JockeyRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/JockeyRepository.cs new file mode 100644 index 0000000..0910572 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/JockeyRepository.cs @@ -0,0 +1,29 @@ +using ProjectHorseRacing.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Repositories.Implementation; + +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, 0, 0); + } + public IEnumerable ReadJockeys() + { + return []; + } + public void UpdateJockey(Jockey jockey) + { + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/OwnerRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/OwnerRepository.cs new file mode 100644 index 0000000..9529111 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/OwnerRepository.cs @@ -0,0 +1,30 @@ +using ProjectHorseRacing.Entities; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Repositories.Implementation; + +public class OwnerRepository : IOwnerRepository +{ + public void CreateOwner(Owners owner) + { + } + public void DeleteOwner(int id) + { + } + public Owners ReadOwnerById(int id) + { + return Owners.CreateEntity(0, string.Empty, string.Empty, string.Empty, string.Empty); + } + public IEnumerable ReadOwners() + { + return []; + } + public void UpdateOwner(Owners owner) + { + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/RaceRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/RaceRepository.cs new file mode 100644 index 0000000..bcaf871 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/RaceRepository.cs @@ -0,0 +1,30 @@ +using ProjectHorseRacing.Entities; +using ProjectHorseRacing.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Repositories.Implementation; + +public class RaceRepository : IRaceRepository +{ + public void CreateRace(Race race) + { + } + public void DeleteRace(int id) + { + } + public Race ReadRaceById(int id) + { + return Race.CreateOperation(0, DateTime.Now, RacePlaceEvent.None); + } + public IEnumerable ReadRaces(DateTime? dateFrom = null, DateTime? dateTo = null) + { + return []; + } + public void UpdateRace(Race race) + { + } +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/ResultRepository.cs b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/ResultRepository.cs new file mode 100644 index 0000000..76a2c47 --- /dev/null +++ b/ProjectHorseRacing/ProjectHorseRacing/Repositories/Implementation/ResultRepository.cs @@ -0,0 +1,22 @@ +using ProjectHorseRacing.Entities.Enums; +using ProjectHorseRacing.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHorseRacing.Repositories.Implementation; + +public class ResultRepository : IResultRepository +{ + public void CreateResult(Result result) + { + } + + public IEnumerable ReadResults(int? RaceId = null, int? JockeyId = null, int? HorseId = null) + { + return []; + } + +} diff --git a/ProjectHorseRacing/ProjectHorseRacing/Resources/карандаш.png b/ProjectHorseRacing/ProjectHorseRacing/Resources/карандаш.png new file mode 100644 index 0000000..eb8c805 Binary files /dev/null and b/ProjectHorseRacing/ProjectHorseRacing/Resources/карандаш.png differ diff --git a/ProjectHorseRacing/ProjectHorseRacing/Resources/минус.png b/ProjectHorseRacing/ProjectHorseRacing/Resources/минус.png new file mode 100644 index 0000000..5ecb344 Binary files /dev/null and b/ProjectHorseRacing/ProjectHorseRacing/Resources/минус.png differ diff --git a/ProjectHorseRacing/ProjectHorseRacing/Resources/плюс.png b/ProjectHorseRacing/ProjectHorseRacing/Resources/плюс.png new file mode 100644 index 0000000..ed70560 Binary files /dev/null and b/ProjectHorseRacing/ProjectHorseRacing/Resources/плюс.png differ diff --git a/ProjectHorseRacing/ProjectHorseRacing/Resources/скачки.jpg b/ProjectHorseRacing/ProjectHorseRacing/Resources/скачки.jpg new file mode 100644 index 0000000..8b97cb6 Binary files /dev/null and b/ProjectHorseRacing/ProjectHorseRacing/Resources/скачки.jpg differ