diff --git a/.lab2.vpp.lck b/.lab2.vpp.lck new file mode 100644 index 0000000..e69de29 diff --git a/ProjectHotel/ProjectHotel/Entities/Athlete.cs b/ProjectHotel/ProjectHotel/Entities/Athlete.cs index 080a91d..24f0f5d 100644 --- a/ProjectHotel/ProjectHotel/Entities/Athlete.cs +++ b/ProjectHotel/ProjectHotel/Entities/Athlete.cs @@ -1,4 +1,5 @@  +using ProjectHotel.Entities.Enums; using System; using System.Collections.Generic; using System.Linq; @@ -13,7 +14,9 @@ public class Athlete public string FirstName { get; private set; } = string.Empty; public string LastName { get; private set; } = string.Empty; public string FatherName { get; private set; } = string.Empty; - public static Athlete CreateEntity(int id, string first, string last, string father) + public Sport Sport { get; private set; } + public AthleteClass AthleteClass { get; private set; } + public static Athlete CreateEntity(int id, string first, string last, string father, Sport sport, AthleteClass athleteClass) { return new Athlete { diff --git a/ProjectHotel/ProjectHotel/Entities/AthletePlacingAthlete.cs b/ProjectHotel/ProjectHotel/Entities/AthletePlacingAthlete.cs index 43e3ab0..c715d0f 100644 --- a/ProjectHotel/ProjectHotel/Entities/AthletePlacingAthlete.cs +++ b/ProjectHotel/ProjectHotel/Entities/AthletePlacingAthlete.cs @@ -10,14 +10,14 @@ public class AthletePlacingAthlete { public int Id { get; set; } public int AthleteId { get; private set; } - public int PlacingId { get; private set; } - public static AthletePlacingAthlete CreateElement(int id, int athleteId, int placingId) + public int LengthOfStay { get; private set; } + public static AthletePlacingAthlete CreateElement(int id, int athleteId, int lengthOfStay) { return new AthletePlacingAthlete { Id = id, AthleteId = athleteId, - PlacingId = placingId + LengthOfStay = lengthOfStay }; } diff --git a/ProjectHotel/ProjectHotel/Entities/Enums/AthleteClass.cs b/ProjectHotel/ProjectHotel/Entities/Enums/AthleteClass.cs new file mode 100644 index 0000000..556a03e --- /dev/null +++ b/ProjectHotel/ProjectHotel/Entities/Enums/AthleteClass.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHotel.Entities.Enums; + +public enum AthleteClass +{ + None = 0, + MSMK = 1, + MS = 2, + KMS = 3 + +} diff --git a/ProjectHotel/ProjectHotel/Entities/Enums/Sport.cs b/ProjectHotel/ProjectHotel/Entities/Enums/Sport.cs new file mode 100644 index 0000000..0e92e4c --- /dev/null +++ b/ProjectHotel/ProjectHotel/Entities/Enums/Sport.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectHotel.Entities.Enums; +[Flags] +public enum Sport +{ + None = 0, + Archery = 2, + Athletics = 4, + Badminton = 8, + Basketball = 16, + Boxing = 32, + Cycling = 64, + Fencing = 128, + Gymnastics = 256, + Rowing = 512, + Swimming = 1024 +} + diff --git a/ProjectHotel/ProjectHotel/Entities/Hotel.cs b/ProjectHotel/ProjectHotel/Entities/Hotel.cs index 38ac0ff..5425230 100644 --- a/ProjectHotel/ProjectHotel/Entities/Hotel.cs +++ b/ProjectHotel/ProjectHotel/Entities/Hotel.cs @@ -9,16 +9,16 @@ namespace ProjectHotel.Entities; public class Hotel { public int Id { get; private set; } - public string HotelName { get; private set; } = string.Empty; + public string Name { get; private set; } = string.Empty; public string Adress { get; private set; } = string.Empty; - public static Hotel CreateEntity(int id, string hotelName, string adress) + public static Hotel CreateEntity(int id, string name, string adress) { return new Hotel { Id = id, - HotelName = hotelName, + Name = name, Adress = adress diff --git a/ProjectHotel/ProjectHotel/Entities/PlacingAthlete.cs b/ProjectHotel/ProjectHotel/Entities/PlacingAthlete.cs index 10ec6a0..13df528 100644 --- a/ProjectHotel/ProjectHotel/Entities/PlacingAthlete.cs +++ b/ProjectHotel/ProjectHotel/Entities/PlacingAthlete.cs @@ -11,15 +11,19 @@ public class PlacingAthlete public int Id { get; private set; } public int RoomId { get; private set; } public DateTime PlacingDate { get; private set; } - public DateTime UnplacingDate { get; private set; } - public static PlacingAthlete CreateOpeartion(int id, int roomId, DateTime unplacing) + public IEnumerable AthletePlacingAthletes + { + get; + private set; + } = []; + public static PlacingAthlete CreateOpeartion(int id, int roomId, IEnumerable athletePlacingAthletes) { return new PlacingAthlete { Id = id, RoomId = roomId, PlacingDate = DateTime.Now, - UnplacingDate = unplacing, + AthletePlacingAthletes = athletePlacingAthletes }; } diff --git a/ProjectHotel/ProjectHotel/Entities/Rooms.cs b/ProjectHotel/ProjectHotel/Entities/Room.cs similarity index 81% rename from ProjectHotel/ProjectHotel/Entities/Rooms.cs rename to ProjectHotel/ProjectHotel/Entities/Room.cs index 0792a28..28abbd9 100644 --- a/ProjectHotel/ProjectHotel/Entities/Rooms.cs +++ b/ProjectHotel/ProjectHotel/Entities/Room.cs @@ -7,15 +7,15 @@ using static System.Runtime.InteropServices.JavaScript.JSType; namespace ProjectHotel.Entities; -public class Rooms +public class Room { public int Id { get; private set; } public int HotelId { get; private set; } public string Name { get; private set; } = string.Empty; public int Capacity { get; private set; } - public static Rooms CreateEntity(int id, int hotel, string name, int capacity) + public static Room CreateEntity(int id, int hotel, string name, int capacity) { - return new Rooms + return new Room { Id = id, HotelId = hotel, diff --git a/ProjectHotel/ProjectHotel/Forms/FormAthlete.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormAthlete.Designer.cs index 5160b7a..00bb4e3 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormAthlete.Designer.cs +++ b/ProjectHotel/ProjectHotel/Forms/FormAthlete.Designer.cs @@ -34,6 +34,12 @@ textBoxFirstName = new TextBox(); textBoxLastName = new TextBox(); textBoxFatherName = new TextBox(); + comboBoxClass = new ComboBox(); + labelClass = new Label(); + label1 = new Label(); + checkedListBoxSport = new CheckedListBox(); + buttonSave = new Button(); + buttonCancel = new Button(); SuspendLayout(); // // labelName @@ -84,11 +90,72 @@ textBoxFatherName.Size = new Size(207, 23); textBoxFatherName.TabIndex = 5; // + // comboBoxClass + // + comboBoxClass.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxClass.FormattingEnabled = true; + comboBoxClass.Location = new Point(99, 144); + comboBoxClass.Name = "comboBoxClass"; + comboBoxClass.Size = new Size(207, 23); + comboBoxClass.TabIndex = 6; + // + // labelClass + // + labelClass.AutoSize = true; + labelClass.Location = new Point(12, 147); + labelClass.Name = "labelClass"; + labelClass.Size = new Size(44, 15); + labelClass.TabIndex = 7; + labelClass.Text = "Разряд"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 186); + label1.Name = "label1"; + label1.Size = new Size(41, 15); + label1.TabIndex = 8; + label1.Text = "Спорт"; + // + // checkedListBoxSport + // + checkedListBoxSport.FormattingEnabled = true; + checkedListBoxSport.Location = new Point(98, 193); + checkedListBoxSport.Name = "checkedListBoxSport"; + checkedListBoxSport.Size = new Size(278, 112); + checkedListBoxSport.TabIndex = 9; + // + // buttonSave + // + buttonSave.Location = new Point(61, 324); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 11; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(251, 324); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 10; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // // FormAthlete // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(318, 139); + ClientSize = new Size(388, 359); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(checkedListBoxSport); + Controls.Add(label1); + Controls.Add(labelClass); + Controls.Add(comboBoxClass); Controls.Add(textBoxFatherName); Controls.Add(textBoxLastName); Controls.Add(textBoxFirstName); @@ -110,5 +177,11 @@ private TextBox textBoxFirstName; private TextBox textBoxLastName; private TextBox textBoxFatherName; + private ComboBox comboBoxClass; + private Label labelClass; + private Label label1; + private CheckedListBox checkedListBoxSport; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Forms/FormAthlete.cs b/ProjectHotel/ProjectHotel/Forms/FormAthlete.cs index d50b52e..8ed43b9 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormAthlete.cs +++ b/ProjectHotel/ProjectHotel/Forms/FormAthlete.cs @@ -1,4 +1,7 @@ -using ProjectHotel.Repositories; +using Microsoft.VisualBasic.FileIO; +using ProjectHotel.Entities; +using ProjectHotel.Entities.Enums; +using ProjectHotel.Repositories; using ProjectHotel.Repositories.Implementations; using System; using System.Collections.Generic; @@ -28,9 +31,18 @@ public partial class FormAthlete : Form throw new InvalidDataException(nameof(athlete)); } + foreach (Sport elem in Enum.GetValues(typeof(Sport))) + { + if ((elem & athlete.Sport) != 0) + { + checkedListBoxSport.SetItemChecked(checkedListBoxSport.Items.IndexOf(elem), true); + } + } + textBoxFirstName.Text = athlete.FirstName; textBoxLastName.Text = athlete.LastName; textBoxFatherName.Text = athlete.FatherName; + comboBoxClass.SelectedItem = athlete.AthleteClass; } catch (Exception ex) { @@ -43,20 +55,27 @@ public partial class FormAthlete : Form { InitializeComponent(); _athleteRepository = athleteRepository ?? - throw new - ArgumentNullException(nameof(athleteRepository)); + throw new ArgumentNullException(nameof(athleteRepository)); + foreach (var elem in Enum.GetValues(typeof(Sport))) + { + checkedListBoxSport.Items.Add(elem); + } + comboBoxClass.DataSource = Enum.GetValues(typeof(AthleteClass)); } - private void ButtonSave_Click(object sender, EventArgs e) + private void buttonSave_Click(object sender, EventArgs e) { try { - if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || string.IsNullOrWhiteSpace(textBoxLastName.Text) || string.IsNullOrWhiteSpace(textBoxFatherName.Text)) + if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || + string.IsNullOrWhiteSpace(textBoxLastName.Text) || + string.IsNullOrWhiteSpace(textBoxFatherName.Text) || + comboBoxClass.SelectedIndex < 0 || checkedListBoxSport.SelectedIndex < 0) { throw new Exception("Имеются незаполненные поля"); } if (_athleteId.HasValue) { - _athleteRepository.UpdateAthlete(CreateEmployee(_athleteId.Value)); + _athleteRepository.UpdateAthlete(CreateAthlete(_athleteId.Value)); } else { @@ -70,10 +89,17 @@ public partial class FormAthlete : Form MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonCancel_Click(object sender, EventArgs e) => + private void buttonCancel_Click(object sender, EventArgs e) => Close(); - private Employee CreateEmployee(int id) => - Employee.CreateEntity(id, textBoxFirstName.Text, - textBoxLastName.Text, - (EmployeePost)comboBoxPost.SelectedItem!); + private Athlete CreateAthlete(int id) + { + Sport sport = Sport.None; + foreach (var elem in checkedListBoxSport.CheckedItems) + { + sport |= (Sport)elem; + } + return Athlete.CreateEntity(id, textBoxFirstName.Text, textBoxLastName.Text, + textBoxFatherName.Text, sport, (AthleteClass)comboBoxClass.SelectedItem!); + } + } diff --git a/ProjectHotel/ProjectHotel/Forms/FormAthletes.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormAthletes.Designer.cs new file mode 100644 index 0000000..9257812 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormAthletes.Designer.cs @@ -0,0 +1,125 @@ +namespace ProjectHotel.Forms +{ + partial class FormAthletes + { + /// + /// 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(); + buttonDelete = new Button(); + buttonChange = new Button(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDelete); + panel1.Controls.Add(buttonChange); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(632, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(168, 450); + panel1.TabIndex = 1; + // + // buttonDelete + // + buttonDelete.BackgroundImage = Properties.Resources.ImageDelete; + buttonDelete.BackgroundImageLayout = ImageLayout.Zoom; + buttonDelete.Location = new Point(24, 308); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(130, 130); + buttonDelete.TabIndex = 2; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonChange + // + buttonChange.BackgroundImage = Properties.Resources.ImageChange; + buttonChange.BackgroundImageLayout = ImageLayout.Zoom; + buttonChange.Location = new Point(24, 158); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(130, 130); + buttonChange.TabIndex = 1; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.AddImage; + buttonAdd.BackgroundImageLayout = ImageLayout.Zoom; + buttonAdd.Location = new Point(24, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(130, 130); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(632, 450); + dataGridViewData.TabIndex = 2; + // + // FormAthletes + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormAthletes"; + StartPosition = FormStartPosition.CenterParent; + Text = "FormAthletes"; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonDelete; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Forms/FormAthletes.cs b/ProjectHotel/ProjectHotel/Forms/FormAthletes.cs new file mode 100644 index 0000000..0a15bd6 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormAthletes.cs @@ -0,0 +1,104 @@ +using ProjectHotel.Repositories; +using ProjectHotel.Repositories.Implementations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectHotel.Forms; + +public partial class FormAthletes : Form +{ + private readonly IUnityContainer _container; + private readonly IAthleteRepository _athleteRepository; + public FormAthletes(IUnityContainer container, IAthleteRepository athleteRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _athleteRepository = athleteRepository ?? throw new ArgumentNullException(nameof(athleteRepository)); + } + private void FormAthletes_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 ButtonChange_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 ButtonDelete_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _athleteRepository.DeleteAthlete(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridViewData.DataSource = _athleteRepository.ReadAthletes(); + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value); + return true; + } +} diff --git a/ProjectHotel/ProjectHotel/Forms/FormAthletes.resx b/ProjectHotel/ProjectHotel/Forms/FormAthletes.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormAthletes.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/ProjectHotel/ProjectHotel/Forms/FormCleaningRoom.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormCleaningRoom.Designer.cs new file mode 100644 index 0000000..de8788f --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormCleaningRoom.Designer.cs @@ -0,0 +1,98 @@ +namespace ProjectHotel.Forms +{ + partial class FormCleaningRoom + { + /// + /// 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() + { + labelRoom = new Label(); + comboBoxRoom = new ComboBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelRoom + // + labelRoom.AutoSize = true; + labelRoom.Location = new Point(46, 54); + labelRoom.Name = "labelRoom"; + labelRoom.Size = new Size(97, 15); + labelRoom.TabIndex = 0; + labelRoom.Text = "Номер комнаты"; + // + // comboBoxRoom + // + comboBoxRoom.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxRoom.FormattingEnabled = true; + comboBoxRoom.Location = new Point(176, 51); + comboBoxRoom.Name = "comboBoxRoom"; + comboBoxRoom.Size = new Size(161, 23); + comboBoxRoom.TabIndex = 1; + // + // buttonSave + // + buttonSave.Location = new Point(68, 149); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 2; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(218, 149); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCleaningRoom + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(364, 194); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(comboBoxRoom); + Controls.Add(labelRoom); + Name = "FormCleaningRoom"; + StartPosition = FormStartPosition.CenterParent; + Text = "FormCleaningRoom"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelRoom; + private ComboBox comboBoxRoom; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Forms/FormCleaningRoom.cs b/ProjectHotel/ProjectHotel/Forms/FormCleaningRoom.cs new file mode 100644 index 0000000..7329423 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormCleaningRoom.cs @@ -0,0 +1,49 @@ +using ProjectHotel.Entities.Enums; +using ProjectHotel.Entities; +using ProjectHotel.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 ProjectHotel.Forms; + +public partial class FormCleaningRoom : Form +{ + private readonly ICleaningRoomRepository _cleaningRoomRepository; + + public FormCleaningRoom(ICleaningRoomRepository cleaningRoomRepository, IRoomRepository roomRepository) + { + InitializeComponent(); + _cleaningRoomRepository = cleaningRoomRepository ?? + throw new ArgumentNullException(nameof(cleaningRoomRepository)); + comboBoxRoom.DataSource = roomRepository.ReadRooms(); + comboBoxRoom.DisplayMember = "Name"; + comboBoxRoom.ValueMember = "Id"; + + } + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxRoom.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + _cleaningRoomRepository.CreateCleaningRoom(CleaningRoom.CreateOperation(0, (int)comboBoxRoom.SelectedValue!)); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + +} diff --git a/ProjectHotel/ProjectHotel/Forms/FormCleaningRoom.resx b/ProjectHotel/ProjectHotel/Forms/FormCleaningRoom.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormCleaningRoom.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/ProjectHotel/ProjectHotel/Forms/FormCleaningRooms.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormCleaningRooms.Designer.cs new file mode 100644 index 0000000..17b6da6 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormCleaningRooms.Designer.cs @@ -0,0 +1,97 @@ +namespace ProjectHotel.Forms +{ + partial class FormCleaningRooms + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridViewData = new DataGridView(); + panel1 = new Panel(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(579, 445); + dataGridViewData.TabIndex = 5; + // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(579, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(168, 445); + panel1.TabIndex = 4; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.AddImage; + buttonAdd.BackgroundImageLayout = ImageLayout.Zoom; + buttonAdd.Location = new Point(26, 146); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(130, 130); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormCleaningRooms + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(747, 445); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormCleaningRooms"; + StartPosition = FormStartPosition.CenterParent; + Text = "FormCleaningRooms"; + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewData; + private Panel panel1; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Forms/FormCleaningRooms.cs b/ProjectHotel/ProjectHotel/Forms/FormCleaningRooms.cs new file mode 100644 index 0000000..4ccfd97 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormCleaningRooms.cs @@ -0,0 +1,54 @@ +using ProjectHotel.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 ProjectHotel.Forms; + +public partial class FormCleaningRooms : Form +{ + private readonly IUnityContainer _container; + private readonly ICleaningRoomRepository _cleaningRoomRepository; + public FormCleaningRooms(IUnityContainer container, ICleaningRoomRepository cleaningRoomRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _cleaningRoomRepository = cleaningRoomRepository ?? + throw new ArgumentNullException(nameof(cleaningRoomRepository)); + } + private void FormCleaningRooms_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridViewData.DataSource = _cleaningRoomRepository.ReadCleaningRooms(); +} + + diff --git a/ProjectHotel/ProjectHotel/Forms/FormCleaningRooms.resx b/ProjectHotel/ProjectHotel/Forms/FormCleaningRooms.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormCleaningRooms.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/ProjectHotel/ProjectHotel/Forms/FormHotel.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormHotel.Designer.cs index e6d5bee..8fbb75a 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormHotel.Designer.cs +++ b/ProjectHotel/ProjectHotel/Forms/FormHotel.Designer.cs @@ -31,7 +31,9 @@ label1 = new Label(); label2 = new Label(); textBoxHotelName = new TextBox(); - textBoxHotelAdress = new TextBox(); + textBoxHotelAddress = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); SuspendLayout(); // // label1 @@ -59,19 +61,41 @@ textBoxHotelName.Size = new Size(390, 23); textBoxHotelName.TabIndex = 2; // - // textBoxHotelAdress + // textBoxHotelAddress // - textBoxHotelAdress.Location = new Point(168, 90); - textBoxHotelAdress.Name = "textBoxHotelAdress"; - textBoxHotelAdress.Size = new Size(387, 23); - textBoxHotelAdress.TabIndex = 3; + textBoxHotelAddress.Location = new Point(168, 90); + textBoxHotelAddress.Name = "textBoxHotelAddress"; + textBoxHotelAddress.Size = new Size(387, 23); + textBoxHotelAddress.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(105, 136); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(385, 136); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // FormHotel // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(570, 167); - Controls.Add(textBoxHotelAdress); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxHotelAddress); Controls.Add(textBoxHotelName); Controls.Add(label2); Controls.Add(label1); @@ -88,5 +112,8 @@ private Label label2; private TextBox textBoxHotelName; private TextBox textBoxHotelAdress; + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxHotelAddress; } } \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Forms/FormHotel.cs b/ProjectHotel/ProjectHotel/Forms/FormHotel.cs index 7f09583..eb664df 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormHotel.cs +++ b/ProjectHotel/ProjectHotel/Forms/FormHotel.cs @@ -30,7 +30,7 @@ public partial class FormHotel : Form throw new InvalidDataException(nameof(hotel)); } - textBoxHotelName.Text = hotel.HotelName; + textBoxHotelName.Text = hotel.Name; textBoxHotelAdress.Text = hotel.Adress; @@ -39,7 +39,7 @@ public partial class FormHotel : Form catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; + return; } } } @@ -56,7 +56,7 @@ public partial class FormHotel : Form { if (string.IsNullOrWhiteSpace(textBoxHotelName.Text) || - string.IsNullOrWhiteSpace(textBoxHotelName.Text)) + string.IsNullOrWhiteSpace(textBoxHotelAddress.Text)) { throw new Exception("Имеются незаполненные поля"); } @@ -78,5 +78,7 @@ public partial class FormHotel : Form } private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private Hotel CreateHotel(int id) => Hotel.CreateEntity(id, textBoxHotelName.Text, textBoxHotelAdress.Text); + + } diff --git a/ProjectHotel/ProjectHotel/Forms/FormHotelForAthletes.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormHotelForAthletes.Designer.cs index 17894e5..d08df32 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormHotelForAthletes.Designer.cs +++ b/ProjectHotel/ProjectHotel/Forms/FormHotelForAthletes.Designer.cs @@ -29,68 +29,80 @@ private void InitializeComponent() { menuStrip1 = new MenuStrip(); - справочникиToolStripMenuItem = new ToolStripMenuItem(); - комнатыToolStripMenuItem = new ToolStripMenuItem(); - отелелиToolStripMenuItem = new ToolStripMenuItem(); - спортсменыToolStripMenuItem = new ToolStripMenuItem(); - операцииToolStripMenuItem = new ToolStripMenuItem(); - заселениеСпортсменаToolStripMenuItem = new ToolStripMenuItem(); - отчетыToolStripMenuItem = new ToolStripMenuItem(); + DirectoriesToolStripMenuItem = new ToolStripMenuItem(); + RoomsToolStripMenuItem = new ToolStripMenuItem(); + HotelsToolStripMenuItem = new ToolStripMenuItem(); + AthletesToolStripMenuItem = new ToolStripMenuItem(); + OperationsToolStripMenuItem = new ToolStripMenuItem(); + PlacingAthleteToolStripMenuItem = new ToolStripMenuItem(); + CleaningRoomToolStripMenuItem = new ToolStripMenuItem(); + ReportsToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); SuspendLayout(); // // menuStrip1 // - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { DirectoriesToolStripMenuItem, OperationsToolStripMenuItem, ReportsToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(800, 24); menuStrip1.TabIndex = 0; menuStrip1.Text = "menuStrip1"; // - // справочникиToolStripMenuItem + // DirectoriesToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { комнатыToolStripMenuItem, отелелиToolStripMenuItem, спортсменыToolStripMenuItem }); - справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(94, 20); - справочникиToolStripMenuItem.Text = "Справочники"; + DirectoriesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { RoomsToolStripMenuItem, HotelsToolStripMenuItem, AthletesToolStripMenuItem }); + DirectoriesToolStripMenuItem.Name = "DirectoriesToolStripMenuItem"; + DirectoriesToolStripMenuItem.Size = new Size(94, 20); + DirectoriesToolStripMenuItem.Text = "Справочники"; // - // комнатыToolStripMenuItem + // RoomsToolStripMenuItem // - комнатыToolStripMenuItem.Name = "комнатыToolStripMenuItem"; - комнатыToolStripMenuItem.Size = new Size(145, 22); - комнатыToolStripMenuItem.Text = "Комнаты"; + RoomsToolStripMenuItem.Name = "RoomsToolStripMenuItem"; + RoomsToolStripMenuItem.Size = new Size(180, 22); + RoomsToolStripMenuItem.Text = "Комнаты"; + RoomsToolStripMenuItem.Click += RoomsToolStripMenuItem_Click; // - // отелелиToolStripMenuItem + // HotelsToolStripMenuItem // - отелелиToolStripMenuItem.Name = "отелелиToolStripMenuItem"; - отелелиToolStripMenuItem.Size = new Size(145, 22); - отелелиToolStripMenuItem.Text = "Отелели"; + HotelsToolStripMenuItem.Name = "HotelsToolStripMenuItem"; + HotelsToolStripMenuItem.Size = new Size(180, 22); + HotelsToolStripMenuItem.Text = "Отелели"; + HotelsToolStripMenuItem.Click += HotelsToolStripMenuItem_Click; // - // спортсменыToolStripMenuItem + // AthletesToolStripMenuItem // - спортсменыToolStripMenuItem.Name = "спортсменыToolStripMenuItem"; - спортсменыToolStripMenuItem.Size = new Size(145, 22); - спортсменыToolStripMenuItem.Text = "Спортсмены"; + AthletesToolStripMenuItem.Name = "AthletesToolStripMenuItem"; + AthletesToolStripMenuItem.Size = new Size(180, 22); + AthletesToolStripMenuItem.Text = "Спортсмены"; + AthletesToolStripMenuItem.Click += AthletesToolStripMenuItem_Click; // - // операцииToolStripMenuItem + // OperationsToolStripMenuItem // - операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заселениеСпортсменаToolStripMenuItem }); - операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; - операцииToolStripMenuItem.Size = new Size(75, 20); - операцииToolStripMenuItem.Text = "Операции"; + OperationsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { PlacingAthleteToolStripMenuItem, CleaningRoomToolStripMenuItem }); + OperationsToolStripMenuItem.Name = "OperationsToolStripMenuItem"; + OperationsToolStripMenuItem.Size = new Size(75, 20); + OperationsToolStripMenuItem.Text = "Операции"; // - // заселениеСпортсменаToolStripMenuItem + // PlacingAthleteToolStripMenuItem // - заселениеСпортсменаToolStripMenuItem.Name = "заселениеСпортсменаToolStripMenuItem"; - заселениеСпортсменаToolStripMenuItem.Size = new Size(201, 22); - заселениеСпортсменаToolStripMenuItem.Text = "Заселение спортсмена"; + PlacingAthleteToolStripMenuItem.Name = "PlacingAthleteToolStripMenuItem"; + PlacingAthleteToolStripMenuItem.Size = new Size(201, 22); + PlacingAthleteToolStripMenuItem.Text = "Заселение спортсмена"; + PlacingAthleteToolStripMenuItem.Click += PlacingAthleteToolStripMenuItem_Click; // - // отчетыToolStripMenuItem + // CleaningRoomToolStripMenuItem // - отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 20); - отчетыToolStripMenuItem.Text = "Отчеты"; + CleaningRoomToolStripMenuItem.Name = "CleaningRoomToolStripMenuItem"; + CleaningRoomToolStripMenuItem.Size = new Size(201, 22); + CleaningRoomToolStripMenuItem.Text = "Уборка комнаты"; + CleaningRoomToolStripMenuItem.Click += CleaningRoomToolStripMenuItem_Click; + // + // ReportsToolStripMenuItem + // + ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; + ReportsToolStripMenuItem.Size = new Size(60, 20); + ReportsToolStripMenuItem.Text = "Отчеты"; // // FormHotelForAthletes // @@ -113,12 +125,13 @@ #endregion private MenuStrip menuStrip1; - private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem комнатыToolStripMenuItem; - private ToolStripMenuItem отелелиToolStripMenuItem; - private ToolStripMenuItem спортсменыToolStripMenuItem; - private ToolStripMenuItem операцииToolStripMenuItem; - private ToolStripMenuItem заселениеСпортсменаToolStripMenuItem; - private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem DirectoriesToolStripMenuItem; + private ToolStripMenuItem RoomsToolStripMenuItem; + private ToolStripMenuItem HotelsToolStripMenuItem; + private ToolStripMenuItem AthletesToolStripMenuItem; + private ToolStripMenuItem OperationsToolStripMenuItem; + private ToolStripMenuItem PlacingAthleteToolStripMenuItem; + private ToolStripMenuItem ReportsToolStripMenuItem; + private ToolStripMenuItem CleaningRoomToolStripMenuItem; } } diff --git a/ProjectHotel/ProjectHotel/Forms/FormHotelForAthletes.cs b/ProjectHotel/ProjectHotel/Forms/FormHotelForAthletes.cs index f56f2e7..8c05fc4 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormHotelForAthletes.cs +++ b/ProjectHotel/ProjectHotel/Forms/FormHotelForAthletes.cs @@ -1,10 +1,83 @@ -namespace ProjectHotel +using ProjectHotel.Forms; +using System.ComponentModel; +using System.Xml.Linq; +using Unity; + +namespace ProjectHotel; + +public partial class FormHotelForAthletes : Form { - public partial class FormHotelForAthletes : Form + private readonly IUnityContainer _container; + public FormHotelForAthletes(IUnityContainer container) { - public FormHotelForAthletes() + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + private void RoomsToolStripMenuItem_Click(object sender, EventArgs e) + { + try { - InitializeComponent(); + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void HotelsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AthletesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void PlacingAthleteToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CleaningRoomToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", + MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/ProjectHotel/ProjectHotel/Forms/FormHotels.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormHotels.Designer.cs index 8960bec..d8f13ae 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormHotels.Designer.cs +++ b/ProjectHotel/ProjectHotel/Forms/FormHotels.Designer.cs @@ -1,6 +1,6 @@ namespace ProjectHotel.Forms { - partial class Отели + partial class FormHotels { /// /// Required designer variable. @@ -57,6 +57,7 @@ buttonDelete.Size = new Size(130, 130); buttonDelete.TabIndex = 2; buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; // // buttonChange // @@ -67,6 +68,7 @@ buttonChange.Size = new Size(130, 130); buttonChange.TabIndex = 1; buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; // // buttonAdd // @@ -77,6 +79,7 @@ buttonAdd.Size = new Size(130, 130); buttonAdd.TabIndex = 0; buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; // // dataGridViewData // @@ -96,16 +99,16 @@ dataGridViewData.Size = new Size(632, 450); dataGridViewData.TabIndex = 1; // - // Отели + // FormHotels // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); Controls.Add(dataGridViewData); Controls.Add(panel1); - Name = "Отели"; + Name = "FormHotels"; StartPosition = FormStartPosition.CenterParent; - Text = "FormHotels"; + Text = "Гостиницы"; panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); ResumeLayout(false); diff --git a/ProjectHotel/ProjectHotel/Forms/FormHotels.cs b/ProjectHotel/ProjectHotel/Forms/FormHotels.cs index 6157dde..099b259 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormHotels.cs +++ b/ProjectHotel/ProjectHotel/Forms/FormHotels.cs @@ -13,12 +13,12 @@ using Unity; namespace ProjectHotel.Forms; -public partial class Отели : Form +public partial class FormHotels : Form { private readonly IUnityContainer _container; private readonly IHotelRepository _hotelRepository; - public Отели(IUnityContainer container, IHotelRepository hotelRepository) + public FormHotels(IUnityContainer container, IHotelRepository hotelRepository) { InitializeComponent(); _container = container ?? @@ -26,7 +26,7 @@ public partial class Отели : Form _hotelRepository = hotelRepository ?? throw new ArgumentNullException(nameof(hotelRepository)); } - private void FormAnimals_Load(object sender, EventArgs e) + private void FormRoom_Load(object sender, EventArgs e) { try { @@ -51,7 +51,7 @@ public partial class Отели : Form MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonUpd_Click(object sender, EventArgs e) + private void ButtonChange_Click(object sender, EventArgs e) { if (!TryGetIdentifierFromSelectedRow(out var findId)) { @@ -104,6 +104,8 @@ public partial class Отели : Form id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value); return true; } + + } diff --git a/ProjectHotel/ProjectHotel/Forms/FormPlacingAthlete.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthlete.Designer.cs new file mode 100644 index 0000000..8be2f83 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthlete.Designer.cs @@ -0,0 +1,166 @@ +namespace ProjectHotel.Forms +{ + partial class FormPlacingAthlete + { + /// + /// 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() + { + DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle(); + label1 = new Label(); + label2 = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + comboBoxRoom = new ComboBox(); + groupBox1 = new GroupBox(); + dataGridView = new DataGridView(); + ColumnAthlete = new DataGridViewComboBoxColumn(); + ColumnLengthOfStay = new DataGridViewTextBoxColumn(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(58, 35); + label1.Name = "label1"; + label1.Size = new Size(54, 15); + label1.TabIndex = 0; + label1.Text = "Комната"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(58, 90); + label2.Name = "label2"; + label2.Size = new Size(156, 15); + label2.TabIndex = 1; + label2.Text = "Длительность проживания"; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(304, 479); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(111, 479); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // comboBoxRoom + // + comboBoxRoom.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxRoom.FormattingEnabled = true; + comboBoxRoom.Location = new Point(118, 32); + comboBoxRoom.Name = "comboBoxRoom"; + comboBoxRoom.Size = new Size(382, 23); + comboBoxRoom.TabIndex = 6; + // + // groupBox1 + // + groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBox1.Controls.Add(dataGridView); + groupBox1.Location = new Point(12, 130); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(491, 329); + groupBox1.TabIndex = 7; + groupBox1.TabStop = false; + groupBox1.Text = "Спортсмены"; + // + // dataGridView + // + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnAthlete, ColumnLengthOfStay }); + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(3, 19); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleCenter; + dataGridView.RowsDefaultCellStyle = dataGridViewCellStyle1; + dataGridView.Size = new Size(485, 307); + dataGridView.TabIndex = 0; + // + // ColumnAthlete + // + ColumnAthlete.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox; + ColumnAthlete.HeaderText = "Спортсмен"; + ColumnAthlete.Name = "ColumnAthlete"; + // + // ColumnLengthOfStay + // + ColumnLengthOfStay.HeaderText = "Длительность проживания"; + ColumnLengthOfStay.Name = "ColumnLengthOfStay"; + // + // FormAthletePlacingAthlete + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(515, 534); + Controls.Add(groupBox1); + Controls.Add(comboBoxRoom); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormAthletePlacingAthlete"; + StartPosition = FormStartPosition.CenterParent; + Text = "Размещение спортсмена"; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Button buttonCancel; + private Button buttonSave; + private ComboBox comboBoxRoom; + private GroupBox groupBox1; + private DataGridView dataGridView; + private DataGridViewComboBoxColumn ColumnAthlete; + private DataGridViewTextBoxColumn ColumnLengthOfStay; + } +} \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Forms/FormPlacingAthlete.cs b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthlete.cs new file mode 100644 index 0000000..8c7ef6a --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthlete.cs @@ -0,0 +1,73 @@ +using ProjectHotel.Entities; +using ProjectHotel.Repositories; +using ProjectHotel.Repositories.Implementations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectHotel.Forms; + +public partial class FormPlacingAthlete : Form +{ + private readonly IPlacingAthleteRepository _placingAthleteRepository; + public FormPlacingAthlete(IPlacingAthleteRepository placingAthleteRepository, + IRoomRepository roomRepository, + IAthleteRepository athleteRepository) + { + InitializeComponent(); + _placingAthleteRepository = placingAthleteRepository ?? + throw new ArgumentNullException(nameof(placingAthleteRepository)); + comboBoxRoom.DataSource = roomRepository.ReadRooms(); + comboBoxRoom.DisplayMember = "Name"; + comboBoxRoom.ValueMember = "Id"; + ColumnAthlete.DataSource = athleteRepository.ReadAthletes(); + ColumnAthlete.DisplayMember = "FirstName"; + ColumnAthlete.ValueMember = "Id"; + } + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (dataGridView.RowCount < 1 || + comboBoxRoom.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + _placingAthleteRepository.CreatePlacingAthlete(PlacingAthlete.CreateOpeartion(0,(int)comboBoxRoom.SelectedValue!, + CreateListAthletePlacingAthleteFromDataGrid())); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + private List + CreateListAthletePlacingAthleteFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridView.Rows) + { + if (row.Cells["ColumnFeed"].Value == null || + row.Cells["ColumnCount"].Value == null) + { + continue; + } + list.Add(AthletePlacingAthlete.CreateElement(0, + Convert.ToInt32(row.Cells["ColumnAthlete"].Value), + Convert.ToInt32(row.Cells["ColumnLengthOfStay"].Value))); + } + return list; + } + +} + + diff --git a/ProjectHotel/ProjectHotel/Forms/FormPlacingAthlete.resx b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthlete.resx new file mode 100644 index 0000000..28a69c7 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthlete.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/ProjectHotel/ProjectHotel/Forms/FormPlacingAthletes.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthletes.Designer.cs new file mode 100644 index 0000000..fe7af57 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthletes.Designer.cs @@ -0,0 +1,110 @@ +namespace ProjectHotel.Forms +{ + partial class FormPlacingAthletes + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridViewData = new DataGridView(); + panel1 = new Panel(); + buttonDelete = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(632, 450); + dataGridViewData.TabIndex = 3; + // + // panel1 + // + panel1.Controls.Add(buttonDelete); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(632, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(168, 450); + panel1.TabIndex = 2; + // + // buttonDelete + // + buttonDelete.BackgroundImage = Properties.Resources.ImageDelete; + buttonDelete.BackgroundImageLayout = ImageLayout.Zoom; + buttonDelete.Location = new Point(26, 248); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(130, 130); + buttonDelete.TabIndex = 2; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.AddImage; + buttonAdd.BackgroundImageLayout = ImageLayout.Zoom; + buttonAdd.Location = new Point(24, 51); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(130, 130); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormPlacingAthletes + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormPlacingAthletes"; + Text = "FormPlacingAthletes"; + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewData; + private Panel panel1; + private Button buttonDelete; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Forms/FormPlacingAthletes.cs b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthletes.cs new file mode 100644 index 0000000..1ca386d --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthletes.cs @@ -0,0 +1,89 @@ +using ProjectHotel.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 ProjectHotel.Forms; + +public partial class FormPlacingAthletes : Form +{ + private readonly IUnityContainer _container; + private readonly IPlacingAthleteRepository _placingAthleteRepository; + public FormPlacingAthletes(IUnityContainer container, IPlacingAthleteRepository placingAthleteRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _placingAthleteRepository = placingAthleteRepository ?? + throw new ArgumentNullException(nameof(placingAthleteRepository)); + } + private void FormPlacingAthletes_Load1(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 ButtonDelete_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", + MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _placingAthleteRepository.DeletePlacingAthlete(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridViewData.DataSource = + _placingAthleteRepository.ReadPlacingAthlete(); + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = + Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value); + return true; + } + } diff --git a/ProjectHotel/ProjectHotel/Forms/FormPlacingAthletes.resx b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthletes.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormPlacingAthletes.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/ProjectHotel/ProjectHotel/Forms/FormRoom.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormRoom.Designer.cs index bf304be..6972411 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormRoom.Designer.cs +++ b/ProjectHotel/ProjectHotel/Forms/FormRoom.Designer.cs @@ -1,6 +1,6 @@ namespace ProjectHotel.Forms { - partial class Комната + partial class FormRoom { /// /// Required designer variable. @@ -30,26 +30,121 @@ { components = new System.ComponentModel.Container(); hotelBindingSource = new BindingSource(components); + labelHotelName = new Label(); + labelCapacity = new Label(); + labelRoomName = new Label(); + numericUpDownCapacity = new NumericUpDown(); + textBoxRoomName = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + comboBoxHotel = new ComboBox(); ((System.ComponentModel.ISupportInitialize)hotelBindingSource).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit(); SuspendLayout(); // - // hotelBindingSource + // labelHotelName // - hotelBindingSource.DataSource = typeof(Entities.Hotel); + labelHotelName.AutoSize = true; + labelHotelName.Location = new Point(31, 55); + labelHotelName.Name = "labelHotelName"; + labelHotelName.Size = new Size(93, 15); + labelHotelName.TabIndex = 0; + labelHotelName.Text = "Название отеля"; // - // Комната + // labelCapacity + // + labelCapacity.AutoSize = true; + labelCapacity.Location = new Point(31, 109); + labelCapacity.Name = "labelCapacity"; + labelCapacity.Size = new Size(80, 15); + labelCapacity.TabIndex = 1; + labelCapacity.Text = "Вместимость"; + // + // labelRoomName + // + labelRoomName.AutoSize = true; + labelRoomName.Location = new Point(31, 168); + labelRoomName.Name = "labelRoomName"; + labelRoomName.Size = new Size(97, 15); + labelRoomName.TabIndex = 2; + labelRoomName.Text = "Номер комнаты"; + // + // numericUpDownCapacity + // + numericUpDownCapacity.Location = new Point(153, 109); + numericUpDownCapacity.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpDownCapacity.Name = "numericUpDownCapacity"; + numericUpDownCapacity.Size = new Size(55, 23); + numericUpDownCapacity.TabIndex = 3; + numericUpDownCapacity.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // textBoxRoomName + // + textBoxRoomName.Location = new Point(153, 160); + textBoxRoomName.Name = "textBoxRoomName"; + textBoxRoomName.Size = new Size(185, 23); + textBoxRoomName.TabIndex = 5; + // + // buttonCancel + // + buttonCancel.Location = new Point(263, 251); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(73, 251); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // comboBoxHotel + // + comboBoxHotel.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxHotel.FormattingEnabled = true; + comboBoxHotel.Location = new Point(153, 47); + comboBoxHotel.Name = "comboBoxHotel"; + comboBoxHotel.Size = new Size(197, 23); + comboBoxHotel.TabIndex = 9; + // + // FormRoom // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(584, 389); - Name = "Комната"; + ClientSize = new Size(419, 309); + Controls.Add(comboBoxHotel); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxRoomName); + Controls.Add(numericUpDownCapacity); + Controls.Add(labelRoomName); + Controls.Add(labelCapacity); + Controls.Add(labelHotelName); + Name = "FormRoom"; StartPosition = FormStartPosition.CenterParent; - Text = "FormRoom"; + Text = "Комната"; ((System.ComponentModel.ISupportInitialize)hotelBindingSource).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit(); ResumeLayout(false); + PerformLayout(); } #endregion private BindingSource hotelBindingSource; + private Label labelHotelName; + private Label labelCapacity; + private Label labelRoomName; + private NumericUpDown numericUpDownCapacity; + private TextBox textBoxRoomName; + private Button buttonCancel; + private Button buttonSave; + private ComboBox comboBoxHotel; } } \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Forms/FormRoom.cs b/ProjectHotel/ProjectHotel/Forms/FormRoom.cs index e4a6c7a..8b866aa 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormRoom.cs +++ b/ProjectHotel/ProjectHotel/Forms/FormRoom.cs @@ -1,4 +1,6 @@ -using System; +using ProjectHotel.Entities; +using ProjectHotel.Repositories; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -10,11 +12,75 @@ using System.Windows.Forms; namespace ProjectHotel.Forms { - public partial class Комната : Form + public partial class FormRoom : Form { - public Комната() + private readonly IRoomRepository _roomRepository; + private int? _roomId; + public int Id + { + set + { + try + { + var room = _roomRepository.ReadRoomById(value); + if (room == null || comboBoxHotel.SelectedIndex < 0) + { + throw new + InvalidDataException(nameof(room)); + } + textBoxRoomName.Text = room.Name; + numericUpDownCapacity.Value = room.Capacity; + _roomId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormRoom(IRoomRepository roomRepository, IHotelRepository hotelRepository) { InitializeComponent(); + _roomRepository = roomRepository ?? + throw new ArgumentNullException(nameof(roomRepository)); + comboBoxHotel.DataSource = hotelRepository.ReadHotels(); + comboBoxHotel.DisplayMember = "Name"; + comboBoxHotel.ValueMember = "Id"; } + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + + if (string.IsNullOrWhiteSpace(textBoxRoomName.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_roomId.HasValue) + { + _roomRepository.UpdateRoom(CreateRoom(_roomId.Value)); + } + else + { + _roomRepository.CreateRoom(CreateRoom(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Room CreateRoom(int id) => Room.CreateEntity(id, (int)comboBoxHotel.SelectedValue!, textBoxRoomName.Text, Convert.ToInt32(numericUpDownCapacity.Value)); + + } + + + } + diff --git a/ProjectHotel/ProjectHotel/Forms/FormRoom.resx b/ProjectHotel/ProjectHotel/Forms/FormRoom.resx index bfd5f48..b922c5b 100644 --- a/ProjectHotel/ProjectHotel/Forms/FormRoom.resx +++ b/ProjectHotel/ProjectHotel/Forms/FormRoom.resx @@ -120,4 +120,28 @@ 17, 17 + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Forms/FormRooms.Designer.cs b/ProjectHotel/ProjectHotel/Forms/FormRooms.Designer.cs new file mode 100644 index 0000000..9c070fb --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormRooms.Designer.cs @@ -0,0 +1,125 @@ +namespace ProjectHotel.Forms +{ + partial class FormRooms + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridViewData = new DataGridView(); + panel1 = new Panel(); + buttonDelete = new Button(); + buttonChange = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(632, 450); + dataGridViewData.TabIndex = 3; + // + // panel1 + // + panel1.Controls.Add(buttonDelete); + panel1.Controls.Add(buttonChange); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(632, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(168, 450); + panel1.TabIndex = 2; + // + // buttonDelete + // + buttonDelete.BackgroundImage = Properties.Resources.ImageDelete; + buttonDelete.BackgroundImageLayout = ImageLayout.Zoom; + buttonDelete.Location = new Point(24, 308); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(130, 130); + buttonDelete.TabIndex = 2; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonChange + // + buttonChange.BackgroundImage = Properties.Resources.ImageChange; + buttonChange.BackgroundImageLayout = ImageLayout.Zoom; + buttonChange.Location = new Point(24, 158); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(130, 130); + buttonChange.TabIndex = 1; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.AddImage; + buttonAdd.BackgroundImageLayout = ImageLayout.Zoom; + buttonAdd.Location = new Point(24, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(130, 130); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormRooms + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormRooms"; + StartPosition = FormStartPosition.CenterParent; + Text = "FormRooms"; + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewData; + private Panel panel1; + private Button buttonDelete; + private Button buttonChange; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Forms/FormRooms.cs b/ProjectHotel/ProjectHotel/Forms/FormRooms.cs new file mode 100644 index 0000000..929bcc4 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormRooms.cs @@ -0,0 +1,111 @@ +using ProjectHotel.Repositories; +using ProjectHotel.Repositories.Implementations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectHotel.Forms; + +public partial class FormRooms : Form +{ + private readonly IUnityContainer _container; + private readonly IRoomRepository _roomRepository; + + public FormRooms(IUnityContainer container, IRoomRepository roomRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _roomRepository = roomRepository ?? + throw new ArgumentNullException(nameof(roomRepository)); + } + private void FormRoom_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 ButtonChange_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 ButtonDelete_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _roomRepository.DeleteRoom(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridViewData.DataSource = _roomRepository.ReadRooms(); + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value); + return true; + } + + +} + + diff --git a/ProjectHotel/ProjectHotel/Forms/FormRooms.resx b/ProjectHotel/ProjectHotel/Forms/FormRooms.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectHotel/ProjectHotel/Forms/FormRooms.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/ProjectHotel/ProjectHotel/Program.cs b/ProjectHotel/ProjectHotel/Program.cs index 8177a3b..6834d59 100644 --- a/ProjectHotel/ProjectHotel/Program.cs +++ b/ProjectHotel/ProjectHotel/Program.cs @@ -1,3 +1,8 @@ +using Unity.Lifetime; +using Unity; +using ProjectHotel.Repositories; +using ProjectHotel.Repositories.Implementations; + namespace ProjectHotel { internal static class Program @@ -11,7 +16,19 @@ namespace ProjectHotel // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormHotelForAthletes()); + Application.Run(CreateContainer().Resolve()); + } + private static IUnityContainer CreateContainer() + { + var container = new UnityContainer(); + + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + + return container; } } } \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/ProjectHotel.csproj b/ProjectHotel/ProjectHotel/ProjectHotel.csproj index 24b1910..8fef0f9 100644 --- a/ProjectHotel/ProjectHotel/ProjectHotel.csproj +++ b/ProjectHotel/ProjectHotel/ProjectHotel.csproj @@ -23,10 +23,6 @@ - - - - diff --git a/ProjectHotel/ProjectHotel/Repositories/IAthletePlacingAthleteRepository.cs b/ProjectHotel/ProjectHotel/Repositories/IAthletePlacingAthleteRepository.cs deleted file mode 100644 index 00a82fb..0000000 --- a/ProjectHotel/ProjectHotel/Repositories/IAthletePlacingAthleteRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using ProjectHotel.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectHotel.Repositories; - -internal interface IAthletePlacingAthleteRepository -{ - IEnumerable ReadAthletePlacingAthlete(int? id = null, int? athleteId = null, int? roomId = null); - void CreateAthletePlacingAthlete(AthletePlacingAthlete athletePlacingAthlete); - AthletePlacingAthlete ReadAthleteById(int id); -} diff --git a/ProjectHotel/ProjectHotel/Repositories/ICleaningRoomRepository.cs b/ProjectHotel/ProjectHotel/Repositories/ICleaningRoomRepository.cs index 63db9d7..c0116d5 100644 --- a/ProjectHotel/ProjectHotel/Repositories/ICleaningRoomRepository.cs +++ b/ProjectHotel/ProjectHotel/Repositories/ICleaningRoomRepository.cs @@ -7,10 +7,10 @@ using System.Threading.Tasks; namespace ProjectHotel.Repositories; -internal interface ICleaningRoomRepository +public interface ICleaningRoomRepository { - IEnumerable ReadCleaningRoom(int? id = null, int? roomId = null, int? athleteId = null); + IEnumerable ReadCleaningRooms(int? id = null, int? roomId = null); void CreateCleaningRoom(CleaningRoom cleaningRoom); - AthletePlacingAthlete ReadAthleteById(int id); + CleaningRoom ReadCleaningRoomById(int id); } \ No newline at end of file diff --git a/ProjectHotel/ProjectHotel/Repositories/IPlacingAthleteRepository.cs b/ProjectHotel/ProjectHotel/Repositories/IPlacingAthleteRepository.cs index 90d930d..ed3ba80 100644 --- a/ProjectHotel/ProjectHotel/Repositories/IPlacingAthleteRepository.cs +++ b/ProjectHotel/ProjectHotel/Repositories/IPlacingAthleteRepository.cs @@ -9,7 +9,7 @@ namespace ProjectHotel.Repositories; public interface IPlacingAthleteRepository { - IEnumerable ReadPlacingAthlete(DateTime? placing = null, DateTime? unplacing = null, int? roomId = null); + IEnumerable ReadPlacingAthlete(int? roomId = null, DateTime ? placing = null); void CreatePlacingAthlete(PlacingAthlete placingAthlete); - PlacingAthlete ReadPlacingAthleteById(int id); + void DeletePlacingAthlete(int id); } diff --git a/ProjectHotel/ProjectHotel/Repositories/IRoomRepository.cs b/ProjectHotel/ProjectHotel/Repositories/IRoomRepository.cs index d32eeb3..05f0116 100644 --- a/ProjectHotel/ProjectHotel/Repositories/IRoomRepository.cs +++ b/ProjectHotel/ProjectHotel/Repositories/IRoomRepository.cs @@ -10,9 +10,9 @@ namespace ProjectHotel.Repositories; public interface IRoomRepository { - IEnumerable ReadRooms(); - Rooms ReadRoomById(int id); - void CreateRoom(Rooms rooms); - void UpdateRoom(Rooms rooms); + IEnumerable ReadRooms(); + Room ReadRoomById(int id); + void CreateRoom(Room room); + void UpdateRoom(Room room); void DeleteRoom(int id); } diff --git a/ProjectHotel/ProjectHotel/Repositories/Implementations/AthletePlacingAthleteRepository.cs b/ProjectHotel/ProjectHotel/Repositories/Implementations/AthletePlacingAthleteRepository.cs deleted file mode 100644 index cf4cc95..0000000 --- a/ProjectHotel/ProjectHotel/Repositories/Implementations/AthletePlacingAthleteRepository.cs +++ /dev/null @@ -1,24 +0,0 @@ -using ProjectHotel.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectHotel.Repositories.Implementations; - -internal class AthletePlacingAthleteRepository -{ - public IEnumerable ReadAthletePlacingAthlete(int? id = null, int? athleteId = null, int? roomId = null) - { - return []; - } - public void CreateAthletePlacingAthlete(AthletePlacingAthleteRepository athletePlacingAthlete) - { - } - - public AthletePlacingAthlete ReadAthleteById(int id) - { - return AthletePlacingAthlete.CreateElement(0, 0, 0); - } -} diff --git a/ProjectHotel/ProjectHotel/Repositories/Implementations/AthleteRepository.cs b/ProjectHotel/ProjectHotel/Repositories/Implementations/AthleteRepository.cs index 02b7f70..d5866c8 100644 --- a/ProjectHotel/ProjectHotel/Repositories/Implementations/AthleteRepository.cs +++ b/ProjectHotel/ProjectHotel/Repositories/Implementations/AthleteRepository.cs @@ -17,7 +17,7 @@ internal class AthleteRepository : IAthleteRepository } public Athlete ReadAthleteById(int id) { - return Athlete.CreateEntity(0, string.Empty, string.Empty,string.Empty); + return Athlete.CreateEntity(0, string.Empty, string.Empty,string.Empty, Entities.Enums.Sport.None, Entities.Enums.AthleteClass.None); } public IEnumerable ReadAthletes() { diff --git a/ProjectHotel/ProjectHotel/Repositories/Implementations/CleaningRoomRepository.cs b/ProjectHotel/ProjectHotel/Repositories/Implementations/CleaningRoomRepository.cs index f0f4415..71713ea 100644 --- a/ProjectHotel/ProjectHotel/Repositories/Implementations/CleaningRoomRepository.cs +++ b/ProjectHotel/ProjectHotel/Repositories/Implementations/CleaningRoomRepository.cs @@ -7,18 +7,18 @@ using System.Threading.Tasks; namespace ProjectHotel.Repositories.Implementations; -internal class CleaningRoomRepository +internal class CleaningRoomRepository : ICleaningRoomRepository { - IEnumerable ReadCleaningRoom(int? id = null, int? roomId = null, int? athleteId = null) + public IEnumerable ReadCleaningRooms(int? id = null, int? roomId = null) { return []; } - void CreateCleaningRoom(CleaningRoom cleaningRoom) + public void CreateCleaningRoom(CleaningRoom cleaningRoom) { } - AthletePlacingAthlete ReadAthleteById(int id) + public CleaningRoom ReadCleaningRoomById(int id) { - return AthletePlacingAthlete.CreateElement(0, 0, 0); + return CleaningRoom.CreateOperation(0, 0); } } diff --git a/ProjectHotel/ProjectHotel/Repositories/Implementations/PlacingAthleteRepository.cs b/ProjectHotel/ProjectHotel/Repositories/Implementations/PlacingAthleteRepository.cs index 60773f0..af90ecd 100644 --- a/ProjectHotel/ProjectHotel/Repositories/Implementations/PlacingAthleteRepository.cs +++ b/ProjectHotel/ProjectHotel/Repositories/Implementations/PlacingAthleteRepository.cs @@ -9,7 +9,7 @@ namespace ProjectHotel.Repositories.Implementations; internal class PlacingAthleteRepository : IPlacingAthleteRepository { - public IEnumerable ReadPlacingAthlete(DateTime? plasing = null, DateTime? unplacing = null, int? roomId = null) + public IEnumerable ReadPlacingAthlete(int? roomId = null, DateTime? placing = null) { return []; } @@ -17,8 +17,8 @@ internal class PlacingAthleteRepository : IPlacingAthleteRepository { } - public PlacingAthlete ReadPlacingAthleteById(int id) + public void DeletePlacingAthlete(int id) { - return PlacingAthlete.CreateOpeartion(0, 0, DateTime.Now); + } } diff --git a/ProjectHotel/ProjectHotel/Repositories/Implementations/RoomRepository.cs b/ProjectHotel/ProjectHotel/Repositories/Implementations/RoomRepository.cs index 2ba2260..0aed54d 100644 --- a/ProjectHotel/ProjectHotel/Repositories/Implementations/RoomRepository.cs +++ b/ProjectHotel/ProjectHotel/Repositories/Implementations/RoomRepository.cs @@ -9,19 +9,19 @@ namespace ProjectHotel.Repositories.Implementations { internal class RoomRepository : IRoomRepository { - public IEnumerable ReadRooms() + public IEnumerable ReadRooms() { return []; } - public Rooms ReadRoomById(int id) + public Room ReadRoomById(int id) { - return Rooms.CreateEntity(0, 0, string.Empty, 0); + return Room.CreateEntity(0, 0, string.Empty, 0); } - public void CreateRoom(Rooms rooms) + public void CreateRoom(Room rooms) { } - public void UpdateRoom(Rooms rooms) + public void UpdateRoom(Room rooms) { } diff --git a/lab2.vpp b/lab2.vpp index 5da342e..bf3e8e5 100644 Binary files a/lab2.vpp and b/lab2.vpp differ diff --git a/lab2.vpp.bak_000f b/lab2.vpp.bak_000f new file mode 100644 index 0000000..5da342e Binary files /dev/null and b/lab2.vpp.bak_000f differ