diff --git a/ProjectAirline/Entities/PraparatoryWorkPlane.cs b/ProjectAirline/Entities/PraparatoryWorkPlane.cs new file mode 100644 index 0000000..bb2ab66 --- /dev/null +++ b/ProjectAirline/Entities/PraparatoryWorkPlane.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirline.Entities; + +public class PreparatoryWorkPlane +{ + public int Id { get; private set; } + public int PreparatoryWorkId { get; private set; } + public int PlaneId { get; private set; } + public int Count { get; private set; } + + public static PreparatoryWorkPlane CreateElement(int id, int preparatoryWorkId, int planeId, int count) + { + return new PreparatoryWorkPlane + { + Id = id, + PreparatoryWorkId = preparatoryWorkId, + PlaneId = planeId, + Count = count + }; + } +} diff --git a/ProjectAirline/Entities/PreparatoryWork.cs b/ProjectAirline/Entities/PreparatoryWork.cs index add5718..513dda6 100644 --- a/ProjectAirline/Entities/PreparatoryWork.cs +++ b/ProjectAirline/Entities/PreparatoryWork.cs @@ -1,4 +1,5 @@ using ProjectAirline.Entities.Enums; +using ProjectAirline.Forms; using System; using System.Collections.Generic; using System.Linq; @@ -10,27 +11,22 @@ namespace ProjectAirline.Entities; public class PreparatoryWork { public int Id { get; private set; } - public int FlightId { get; private set; } - - public int PlaneId { get; private set; } - public DateTime StartDate { get; private set; } - public DateTime EndDate { get; private set; } - public PreparatoryWorkStatus Status { get; private set; } + public IEnumerable PreparatoryWorkPlanes { get; private set; } = Enumerable.Empty(); - public static PreparatoryWork CreatePrerapatoryWork(int id, int FlightId, int PlaneId, DateTime StartDate, DateTime EndDate, PreparatoryWorkStatus Status) + public static PreparatoryWork CreatePreparatoryWork(int id, int flightId, DateTime startDate, DateTime endDate, PreparatoryWorkStatus status, IEnumerable preparatoryWorkPlanes) { return new PreparatoryWork { Id = id, - FlightId = FlightId, - PlaneId = PlaneId, - StartDate = StartDate, - EndDate = EndDate, - Status = Status + FlightId = flightId, + StartDate = startDate, + EndDate = endDate, + Status = status, + PreparatoryWorkPlanes = preparatoryWorkPlanes }; } } diff --git a/ProjectAirline/FormAirline.Designer.cs b/ProjectAirline/FormAirline.Designer.cs index 2f26f61..f17c868 100644 --- a/ProjectAirline/FormAirline.Designer.cs +++ b/ProjectAirline/FormAirline.Designer.cs @@ -30,13 +30,13 @@ { menuStrip = new MenuStrip(); справочникиToolStripMenuItem = new ToolStripMenuItem(); - полетToolStripMenuItem = new ToolStripMenuItem(); - операцииToolStripMenuItem = new ToolStripMenuItem(); - отчетыToolStripMenuItem = new ToolStripMenuItem(); пассажирыToolStripMenuItem = new ToolStripMenuItem(); самолетыToolStripMenuItem = new ToolStripMenuItem(); билетыToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); подготовительныеРаботыToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + полетыToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -51,53 +51,58 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { полетToolStripMenuItem, пассажирыToolStripMenuItem, самолетыToolStripMenuItem, билетыToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { пассажирыToolStripMenuItem, самолетыToolStripMenuItem, билетыToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(94, 20); справочникиToolStripMenuItem.Text = "Справочники"; // - // полетToolStripMenuItem + // пассажирыToolStripMenuItem // - полетToolStripMenuItem.Name = "полетToolStripMenuItem"; - полетToolStripMenuItem.Size = new Size(180, 22); - полетToolStripMenuItem.Text = "Полеты"; + пассажирыToolStripMenuItem.Name = "пассажирыToolStripMenuItem"; + пассажирыToolStripMenuItem.Size = new Size(180, 22); + пассажирыToolStripMenuItem.Text = "Пассажиры"; + пассажирыToolStripMenuItem.Click += PassangersToolStripMenuItem_Click; + // + // самолетыToolStripMenuItem + // + самолетыToolStripMenuItem.Name = "самолетыToolStripMenuItem"; + самолетыToolStripMenuItem.Size = new Size(180, 22); + самолетыToolStripMenuItem.Text = "Самолеты"; + самолетыToolStripMenuItem.Click += PlanesToolStripMenuItem_Click; + // + // билетыToolStripMenuItem + // + билетыToolStripMenuItem.Name = "билетыToolStripMenuItem"; + билетыToolStripMenuItem.Size = new Size(180, 22); + билетыToolStripMenuItem.Text = "Билеты"; + билетыToolStripMenuItem.Click += TicketsToolStripMenuItem_Click; // // операцииToolStripMenuItem // - операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { подготовительныеРаботыToolStripMenuItem }); + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { подготовительныеРаботыToolStripMenuItem, полетыToolStripMenuItem }); операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; операцииToolStripMenuItem.Size = new Size(75, 20); операцииToolStripMenuItem.Text = "Операции"; // + // подготовительныеРаботыToolStripMenuItem + // + подготовительныеРаботыToolStripMenuItem.Name = "подготовительныеРаботыToolStripMenuItem"; + подготовительныеРаботыToolStripMenuItem.Size = new Size(223, 22); + подготовительныеРаботыToolStripMenuItem.Text = "Подготовительные работы"; + подготовительныеРаботыToolStripMenuItem.Click += PreparatoryWorksToolStripMenuItem_Click; + // // отчетыToolStripMenuItem // отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; отчетыToolStripMenuItem.Size = new Size(60, 20); отчетыToolStripMenuItem.Text = "Отчеты"; // - // пассажирыToolStripMenuItem + // полетыToolStripMenuItem // - пассажирыToolStripMenuItem.Name = "пассажирыToolStripMenuItem"; - пассажирыToolStripMenuItem.Size = new Size(180, 22); - пассажирыToolStripMenuItem.Text = "Пассажиры"; - // - // самолетыToolStripMenuItem - // - самолетыToolStripMenuItem.Name = "самолетыToolStripMenuItem"; - самолетыToolStripMenuItem.Size = new Size(180, 22); - самолетыToolStripMenuItem.Text = "Самолеты"; - // - // билетыToolStripMenuItem - // - билетыToolStripMenuItem.Name = "билетыToolStripMenuItem"; - билетыToolStripMenuItem.Size = new Size(180, 22); - билетыToolStripMenuItem.Text = "Билеты"; - // - // подготовительныеРаботыToolStripMenuItem - // - подготовительныеРаботыToolStripMenuItem.Name = "подготовительныеРаботыToolStripMenuItem"; - подготовительныеРаботыToolStripMenuItem.Size = new Size(223, 22); - подготовительныеРаботыToolStripMenuItem.Text = "Подготовительные работы"; + полетыToolStripMenuItem.Name = "полетыToolStripMenuItem"; + полетыToolStripMenuItem.Size = new Size(223, 22); + полетыToolStripMenuItem.Text = "Полеты"; + полетыToolStripMenuItem.Click += FlightsToolStripMenuItem_Click; // // FormAirline // @@ -121,12 +126,12 @@ private MenuStrip menuStrip; private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem полетToolStripMenuItem; private ToolStripMenuItem операцииToolStripMenuItem; private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem пассажирыToolStripMenuItem; private ToolStripMenuItem самолетыToolStripMenuItem; private ToolStripMenuItem билетыToolStripMenuItem; private ToolStripMenuItem подготовительныеРаботыToolStripMenuItem; + private ToolStripMenuItem полетыToolStripMenuItem; } } diff --git a/ProjectAirline/FormAirline.cs b/ProjectAirline/FormAirline.cs index 24f2168..03ba57d 100644 --- a/ProjectAirline/FormAirline.cs +++ b/ProjectAirline/FormAirline.cs @@ -1,11 +1,75 @@ -namespace ProjectAirline -{ - public partial class FormAirline : Form - { - public FormAirline() - { - InitializeComponent(); - } +using ProjectAirline.Forms; +using Unity; +namespace ProjectAirline; + +public partial class FormAirline : Form +{ + private readonly IUnityContainer _container; + + public FormAirline(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void FlightsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void PassangersToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void TicketsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void PlanesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void PreparatoryWorksToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } diff --git a/ProjectAirline/Forms/FormPassanger.Designer.cs b/ProjectAirline/Forms/FormPassanger.Designer.cs index 4f98a7c..da066a0 100644 --- a/ProjectAirline/Forms/FormPassanger.Designer.cs +++ b/ProjectAirline/Forms/FormPassanger.Designer.cs @@ -100,7 +100,7 @@ Controls.Add(buttonCancel); Controls.Add(buttonSave); Name = "FormPassanger"; - Text = "FormPassanger"; + Text = "Пассажир"; ResumeLayout(false); PerformLayout(); } diff --git a/ProjectAirline/Forms/FormPreparatoryWork.cs b/ProjectAirline/Forms/FormPreparatoryWork.cs index 73d6f48..1801133 100644 --- a/ProjectAirline/Forms/FormPreparatoryWork.cs +++ b/ProjectAirline/Forms/FormPreparatoryWork.cs @@ -10,12 +10,15 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ProjectAirline.Repositories.Implementations; namespace ProjectAirline.Forms; public partial class FormPreparatoryWork : Form { private readonly IPreparatoryWorkRepository _preparatoryWorkRepository; + private readonly IFlightRepository _flightRepository; + private readonly IPlaneRepository _planeRepository; private int? _preparatoryWorkId; public int Id @@ -30,7 +33,6 @@ public partial class FormPreparatoryWork : Form throw new InvalidDataException(nameof(preparatoryWork)); } comboBoxFlightId.SelectedItem = preparatoryWork.FlightId; - comboBoxPlaneId.SelectedItem = preparatoryWork.PlaneId; comboBoxStatus.SelectedItem = preparatoryWork.Status; _preparatoryWorkId = value; } @@ -42,16 +44,15 @@ public partial class FormPreparatoryWork : Form } } - public FormPreparatoryWork(IPreparatoryWorkRepository preparatoryWorkRepository) + public FormPreparatoryWork(IPreparatoryWorkRepository preparatoryWorkRepository, IFlightRepository flightRepository, IPlaneRepository planeRepository) { InitializeComponent(); _preparatoryWorkRepository = preparatoryWorkRepository ?? throw new ArgumentNullException(nameof(preparatoryWorkRepository)); + _flightRepository = flightRepository ?? throw new ArgumentNullException(nameof(_flightRepository)); + _planeRepository = planeRepository ?? throw new ArgumentNullException(nameof(_planeRepository)); + comboBoxFlightId.DataSource = _flightRepository.ReadFlights(); + comboBoxPlaneId.DataSource = _planeRepository.ReadPlanes(); - // Заполнение comboBoxFlightId и comboBoxPlaneId данными из репозитория - comboBoxFlightId.DataSource = _preparatoryWorkRepository.GetFlightIds(); - comboBoxPlaneId.DataSource = _preparatoryWorkRepository.GetPlaneIds(); - - // Заполнение comboBoxStatus данными из перечисления PreparatoryWorkStatus comboBoxStatus.DataSource = Enum.GetValues(typeof(PreparatoryWorkStatus)); } @@ -88,10 +89,10 @@ public partial class FormPreparatoryWork : Form return PreparatoryWork.CreatePreparatoryWork( id, (int)comboBoxFlightId.SelectedItem, - (int)comboBoxPlaneId.SelectedItem, DateTime.Now, DateTime.Now.AddHours(1), (PreparatoryWorkStatus)comboBoxStatus.SelectedItem + ); } } diff --git a/ProjectAirline/Forms/FormPreparatoryWorks.Designer.cs b/ProjectAirline/Forms/FormPreparatoryWorks.Designer.cs index 0a809fa..b4acada 100644 --- a/ProjectAirline/Forms/FormPreparatoryWorks.Designer.cs +++ b/ProjectAirline/Forms/FormPreparatoryWorks.Designer.cs @@ -48,38 +48,38 @@ panel.Size = new Size(200, 450); panel.TabIndex = 0; // - // buttonUpd - // - buttonUpd.BackgroundImage = Properties.Resources.Antu_qtdesigner_svg; - buttonUpd.BackgroundImageLayout = ImageLayout.Zoom; - buttonUpd.Location = new Point(51, 148); - buttonUpd.Name = "buttonUpd"; - buttonUpd.Size = new Size(79, 65); - buttonUpd.TabIndex = 2; - buttonUpd.UseVisualStyleBackColor = true; - buttonUpd.Click += ButtonUpd_Click; - // - // buttonDel - // - buttonDel.BackgroundImage = Properties.Resources.kisspng_computer_icons_download_5b218289889485_4804831415289227615594; - buttonDel.BackgroundImageLayout = ImageLayout.Stretch; - buttonDel.Location = new Point(51, 248); - buttonDel.Name = "buttonDel"; - buttonDel.Size = new Size(79, 65); - buttonDel.TabIndex = 1; - buttonDel.UseVisualStyleBackColor = true; - buttonDel.Click += ButtonDel_Click; - // - // buttonAdd - // - buttonAdd.BackgroundImage = Properties.Resources.Fairytale_button_add_svg; - buttonAdd.BackgroundImageLayout = ImageLayout.Zoom; - buttonAdd.Location = new Point(51, 44); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(79, 65); - buttonAdd.TabIndex = 0; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += ButtonAdd_Click; + //// buttonUpd + //// + //buttonUpd.BackgroundImage = Properties.Resources.Antu_qtdesigner_svg; + //buttonUpd.BackgroundImageLayout = ImageLayout.Zoom; + //buttonUpd.Location = new Point(51, 148); + //buttonUpd.Name = "buttonUpd"; + //buttonUpd.Size = new Size(79, 65); + //buttonUpd.TabIndex = 2; + //buttonUpd.UseVisualStyleBackColor = true; + //buttonUpd.Click += ButtonUpd_Click; + //// + //// buttonDel + //// + //buttonDel.BackgroundImage = Properties.Resources.kisspng_computer_icons_download_5b218289889485_4804831415289227615594; + //buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + //buttonDel.Location = new Point(51, 248); + //buttonDel.Name = "buttonDel"; + //buttonDel.Size = new Size(79, 65); + //buttonDel.TabIndex = 1; + //buttonDel.UseVisualStyleBackColor = true; + //buttonDel.Click += ButtonDel_Click; + //// + //// buttonAdd + //// + //buttonAdd.BackgroundImage = Properties.Resources.Fairytale_button_add_svg; + //buttonAdd.BackgroundImageLayout = ImageLayout.Zoom; + //buttonAdd.Location = new Point(51, 44); + //buttonAdd.Name = "buttonAdd"; + //buttonAdd.Size = new Size(79, 65); + //buttonAdd.TabIndex = 0; + //buttonAdd.UseVisualStyleBackColor = true; + //buttonAdd.Click += ButtonAdd_Click; // // dataGridViewData // @@ -107,6 +107,7 @@ Controls.Add(dataGridViewData); Controls.Add(panel); Name = "FormPreparatoryWorks"; + StartPosition = FormStartPosition.CenterParent; Text = "Подготовительные работы"; Load += FormPreparatoryWorks_Load; panel.ResumeLayout(false); diff --git a/ProjectAirline/Forms/FormPreparatoryWorks.cs b/ProjectAirline/Forms/FormPreparatoryWorks.cs index 4df3dd8..4689182 100644 --- a/ProjectAirline/Forms/FormPreparatoryWorks.cs +++ b/ProjectAirline/Forms/FormPreparatoryWorks.cs @@ -1,4 +1,6 @@ -using ProjectAirline.Repositories; +using ProjectAirline.Entities.Enums; +using ProjectAirline.Entities; +using ProjectAirline.Repositories; using System; using System.Collections.Generic; using System.ComponentModel; @@ -12,94 +14,173 @@ using Unity; namespace ProjectAirline.Forms; +//public partial class FormPreparatoryWorks : Form +//{ +// private readonly IUnityContainer _container; +// private readonly IPreparatoryWorkRepository _preparatoryWorkRepository; + +// public FormPreparatoryWorks(IUnityContainer container, IPreparatoryWorkRepository preparatoryWorkRepository) +// { +// InitializeComponent(); +// _container = container ?? throw new ArgumentNullException(nameof(container)); +// _preparatoryWorkRepository = preparatoryWorkRepository ?? throw new ArgumentNullException(nameof(preparatoryWorkRepository)); +// } + +// private void FormPreparatoryWorks_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 +// { +// _preparatoryWorkRepository.DeletePreparatoryWork(findId); +// LoadList(); +// } +// catch (Exception ex) +// { +// MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); +// } +// } + +// private void LoadList() => dataGridViewData.DataSource = _preparatoryWorkRepository.ReadPreparatoryWorks(); + +// 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; +// } +//} public partial class FormPreparatoryWorks : Form { - private readonly IUnityContainer _container; private readonly IPreparatoryWorkRepository _preparatoryWorkRepository; + private readonly IPlaneRepository _planeRepository; - public FormPreparatoryWorks(IUnityContainer container, IPreparatoryWorkRepository preparatoryWorkRepository) + public FormPreparatoryWorks(IPreparatoryWorkRepository preparatoryWorkRepository, IPlaneRepository planeRepository) { InitializeComponent(); - _container = container ?? throw new ArgumentNullException(nameof(container)); _preparatoryWorkRepository = preparatoryWorkRepository ?? throw new ArgumentNullException(nameof(preparatoryWorkRepository)); + _planeRepository = planeRepository ?? throw new ArgumentNullException(nameof(planeRepository)); + + // Настройка DataGridView + dataGridViewData.AutoGenerateColumns = false; + dataGridViewData.Columns.Add(new DataGridViewComboBoxColumn + { + Name = "ColumnPlane", + HeaderText = "Самолет", + DataSource = _planeRepository.ReadPlanes(), + DisplayMember = "Name", + ValueMember = "Id", + DataPropertyName = "PlaneId" + }); + dataGridViewData.Columns.Add(new DataGridViewTextBoxColumn + { + Name = "ColumnCount", + HeaderText = "Количество", + DataPropertyName = "Count" + }); } - private void FormPreparatoryWorks_Load(object sender, EventArgs e) + private void ButtonSave_Click(object sender, EventArgs e) { try { - LoadList(); + if (dataGridViewData.RowCount < 1) + { + throw new Exception("Имеются незаполненные поля"); + } + + var preparatoryWorkPlanes = CreateListPreparatoryWorkPlanesFromDataGrid(); + + var preparatoryWork = PreparatoryWork.CreatePreparatoryWork( + 0, // ID будет присвоен при сохранении + -1, // FlightId (если нужно, добавьте поле для ввода) + DateTime.Now, // StartDate (если нужно, добавьте поле для ввода) + DateTime.Now, // EndDate (если нужно, добавьте поле для ввода) + PreparatoryWorkStatus.None, // Status (если нужно, добавьте поле для ввода) + preparatoryWorkPlanes + ); + + _preparatoryWorkRepository.CreatePreparatoryWork(preparatoryWork); + Close(); } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + 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 ButtonCancel_Click(object sender, EventArgs e) => Close(); - private void ButtonUpd_Click(object sender, EventArgs e) + private List CreateListPreparatoryWorkPlanesFromDataGrid() { - if (!TryGetIdentifierFromSelectedRow(out var findId)) + var list = new List(); + foreach (DataGridViewRow row in dataGridViewData.Rows) { - return; - } - try - { - var form = _container.Resolve(); - form.Id = findId; - form.ShowDialog(); - LoadList(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + if (row.Cells["ColumnPlane"].Value == null || row.Cells["ColumnCount"].Value == null) + { + continue; + } - private void ButtonDel_Click(object sender, EventArgs e) - { - if (!TryGetIdentifierFromSelectedRow(out var findId)) - { - return; - } - if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) - { - return; - } - try - { - _preparatoryWorkRepository.DeletePreparatoryWork(findId); - LoadList(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + var planeId = Convert.ToInt32(row.Cells["ColumnPlane"].Value); + var count = Convert.ToInt32(row.Cells["ColumnCount"].Value); - private void LoadList() => dataGridViewData.DataSource = _preparatoryWorkRepository.ReadPreparatoryWorks(); - - private bool TryGetIdentifierFromSelectedRow(out int id) - { - id = 0; - if (dataGridViewData.SelectedRows.Count < 1) - { - MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; + list.Add(PreparatoryWorkPlane.CreateElement(0, -1, planeId, count)); } - id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value); - return true; + return list; } } diff --git a/ProjectAirline/Forms/FormTicket.Designer.cs b/ProjectAirline/Forms/FormTicket.Designer.cs index 40f52fe..5dc681c 100644 --- a/ProjectAirline/Forms/FormTicket.Designer.cs +++ b/ProjectAirline/Forms/FormTicket.Designer.cs @@ -60,7 +60,7 @@ buttonSave.TabIndex = 3; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; + buttonSave.Click += ButtonSave_Click; // // buttonCancel // @@ -70,7 +70,7 @@ buttonCancel.TabIndex = 4; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; + buttonCancel.Click += ButtonCancel_Click; // // FormTicket // diff --git a/ProjectAirline/Forms/FormTicket.cs b/ProjectAirline/Forms/FormTicket.cs index e17f5c7..1ff11ce 100644 --- a/ProjectAirline/Forms/FormTicket.cs +++ b/ProjectAirline/Forms/FormTicket.cs @@ -10,20 +10,55 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Microsoft.VisualBasic.FileIO; namespace ProjectAirline.Forms; public partial class FormTicket : Form { private readonly ITicketRepository _ticketRepository; + private int? _ticketId; + + public int Id + { + set + { + try + { + var ticket = _ticketRepository.ReadTicketById(value); + if (ticket == null) + { + throw new InvalidDataException(nameof(ticket)); + } + + foreach (TicketStatus elem in Enum.GetValues(typeof(TicketStatus))) + { + if ((elem & ticket.Status) != 0) + { + checkedListBoxStatus.SetItemChecked(checkedListBoxStatus.Items.IndexOf(elem), true); + } + } + + _ticketId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } public FormTicket(ITicketRepository ticketRepository) { InitializeComponent(); _ticketRepository = ticketRepository ?? throw new ArgumentNullException(nameof(ticketRepository)); - //Тут нада чета делать но я пьяный уже пол 2 ночи пора спать - //checkedListBoxStatus.Items.AddRange(Enum.GetValues(typeof(TicketStatus)).Cast().ToArray()); + foreach (var elem in Enum.GetValues(typeof(TicketStatus))) + { + checkedListBoxStatus.Items.Add(elem); + } + } private void ButtonSave_Click(object sender, EventArgs e) @@ -36,7 +71,15 @@ public partial class FormTicket : Form throw new Exception("Необходимо выбрать хотя бы один статус"); } - _ticketRepository.CreateTicket(Ticket.CreateTicket(0, status)); + if (_ticketId.HasValue) + { + _ticketRepository.UpdateTicket(CreateTicket(_ticketId.Value)); + } + else + { + _ticketRepository.CreateTicket(CreateTicket(0)); + } + Close(); } catch (Exception ex) @@ -47,6 +90,12 @@ public partial class FormTicket : Form private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + private Ticket CreateTicket(int id) + { + var status = GetTicketStatusFromCheckedListBox(); + return Ticket.CreateTicket(id, status); + } + private TicketStatus GetTicketStatusFromCheckedListBox() { TicketStatus status = TicketStatus.None; diff --git a/ProjectAirline/Forms/FormTickets.Designer.cs b/ProjectAirline/Forms/FormTickets.Designer.cs new file mode 100644 index 0000000..17d01c9 --- /dev/null +++ b/ProjectAirline/Forms/FormTickets.Designer.cs @@ -0,0 +1,125 @@ +namespace ProjectAirline.Forms +{ + partial class FormTickets + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel = new Panel(); + dataGridViewData = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + panel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonDel); + panel.Controls.Add(buttonUpd); + panel.Controls.Add(buttonAdd); + panel.Dock = DockStyle.Right; + panel.Location = new Point(600, 0); + panel.Name = "panel"; + panel.Size = new Size(200, 450); + panel.TabIndex = 0; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.ColumnHeadersVisible = false; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(600, 450); + dataGridViewData.TabIndex = 1; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Fairytale_button_add_svg; + buttonAdd.BackgroundImageLayout = ImageLayout.Zoom; + buttonAdd.Location = new Point(35, 70); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(69, 65); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.Antu_qtdesigner_svg; + buttonUpd.BackgroundImageLayout = ImageLayout.Zoom; + buttonUpd.Location = new Point(35, 166); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(69, 65); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.kisspng_computer_icons_download_5b218289889485_4804831415289227615594; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(35, 264); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(69, 65); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // FormTickets + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel); + Name = "FormTickets"; + Text = "Билеты"; + Load += FormTickets_Load; + panel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/ProjectAirline/Forms/FormTickets.cs b/ProjectAirline/Forms/FormTickets.cs new file mode 100644 index 0000000..cc4cde9 --- /dev/null +++ b/ProjectAirline/Forms/FormTickets.cs @@ -0,0 +1,105 @@ +using ProjectAirline.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 ProjectAirline.Forms; + +public partial class FormTickets : Form +{ + private readonly IUnityContainer _container; + private readonly ITicketRepository _ticketRepository; + + public FormTickets(IUnityContainer container, ITicketRepository ticketRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _ticketRepository = ticketRepository ?? throw new ArgumentNullException(nameof(ticketRepository)); + } + + private void FormTickets_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 + { + _ticketRepository.DeleteTicket(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _ticketRepository.ReadTickets(); + + 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/ProjectAirline/Forms/FormTickets.resx b/ProjectAirline/Forms/FormTickets.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirline/Forms/FormTickets.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/ProjectAirline/Repositories/IPreparatoryWorkRepository.cs b/ProjectAirline/Repositories/IPreparatoryWorkRepository.cs index f8d619e..581a811 100644 --- a/ProjectAirline/Repositories/IPreparatoryWorkRepository.cs +++ b/ProjectAirline/Repositories/IPreparatoryWorkRepository.cs @@ -15,6 +15,7 @@ public interface IPreparatoryWorkRepository void CreatePreparatoryWork(PreparatoryWork preparatoryWork); void UpdatePreparatoryWork(PreparatoryWork preparatoryWork); + void DeletePreparatoryWork(int id); PreparatoryWork ReadPreparatoryWorkById(int id); diff --git a/ProjectAirline/Repositories/Implementations/PreparatoryWorkRepository.cs b/ProjectAirline/Repositories/Implementations/PreparatoryWorkRepository.cs index 7b19aed..99db6ca 100644 --- a/ProjectAirline/Repositories/Implementations/PreparatoryWorkRepository.cs +++ b/ProjectAirline/Repositories/Implementations/PreparatoryWorkRepository.cs @@ -21,13 +21,20 @@ public class PreparatoryWorkRepository : IPreparatoryWorkRepository { } + + public PreparatoryWork ReadPreparatoryWorkById(int id) { - return PreparatoryWork.CreatePrerapatoryWork(0, 0, 0, DateTime.Now, DateTime.Now, 0); + return PreparatoryWork.CreatePreparatoryWork(0, 0, DateTime.Now, DateTime.Now, 0); } public IEnumerable ReadPreparatoryWork(DateTime? dateFrom = null, int? planeId = null, int? flightId = null, DateTime? dateTo = null, int? preparatoryWorkId = null, PreparatoryWork? preparatoryWorkStatus = null) { return []; } + + public IEnumerable ReadPreparatoryWorks() + { + return []; + } }