From 083f7761aeaf4e128a2ad0044e1f5359776b2dcf Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Mon, 11 Nov 2024 15:05:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=B0=D0=B6=D0=B5=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?=D0=B2=D1=81=D0=B5.=20=D0=9D=D0=B0=20=D1=8D=D1=82=D0=BE=D0=BC?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=BD=D1=87=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectTourAgency/Enities/ClientTour.cs | 8 +- project/ProjectTourAgency/Enities/Tour.cs | 12 +- .../FormTourAgency.Designer.cs | 3 +- project/ProjectTourAgency/FormTourAgency.cs | 16 +- .../Forms/FormAddMoneys.Designer.cs | 97 +++++++++ .../ProjectTourAgency/Forms/FormAddMoneys.cs | 68 +++++++ .../Forms/FormAddMoneys.resx | 120 +++++++++++ .../Forms/FormClientTour.Designer.cs | 191 ++++++++++++++++++ .../ProjectTourAgency/Forms/FormClientTour.cs | 83 ++++++++ .../Forms/FormClientTour.resx | 126 ++++++++++++ .../Forms/FormTours.Designer.cs | 111 ++++++++++ project/ProjectTourAgency/Forms/FormTours.cs | 91 +++++++++ .../ProjectTourAgency/Forms/FormTours.resx | 120 +++++++++++ .../{TourRepositiry.cs => TourRepository.cs} | 4 +- project/ProjectTourAgency/Program.cs | 3 +- 15 files changed, 1040 insertions(+), 13 deletions(-) create mode 100644 project/ProjectTourAgency/Forms/FormAddMoneys.Designer.cs create mode 100644 project/ProjectTourAgency/Forms/FormAddMoneys.cs create mode 100644 project/ProjectTourAgency/Forms/FormAddMoneys.resx create mode 100644 project/ProjectTourAgency/Forms/FormClientTour.Designer.cs create mode 100644 project/ProjectTourAgency/Forms/FormClientTour.cs create mode 100644 project/ProjectTourAgency/Forms/FormClientTour.resx create mode 100644 project/ProjectTourAgency/Forms/FormTours.Designer.cs create mode 100644 project/ProjectTourAgency/Forms/FormTours.cs create mode 100644 project/ProjectTourAgency/Forms/FormTours.resx rename project/ProjectTourAgency/Implementations/{TourRepositiry.cs => TourRepository.cs} (83%) diff --git a/project/ProjectTourAgency/Enities/ClientTour.cs b/project/ProjectTourAgency/Enities/ClientTour.cs index a851770..a05bd98 100644 --- a/project/ProjectTourAgency/Enities/ClientTour.cs +++ b/project/ProjectTourAgency/Enities/ClientTour.cs @@ -9,18 +9,20 @@ namespace ProjectTourAgency.Enities; public class ClientTour { + public int Id { get; private set; } public int ClientId { get; private set; } public int TourId { get; private set; } - public int Count { get; private set; } + public int Cost { get; private set; } - public static ClientTour CreateEntity(int clientId, int tourId, int count) + public static ClientTour CreateEntity(int id,int clientId, int tourId, int cost) { return new ClientTour { + Id = id, ClientId = clientId, TourId = tourId, - Count = count + Cost = cost }; } diff --git a/project/ProjectTourAgency/Enities/Tour.cs b/project/ProjectTourAgency/Enities/Tour.cs index 8a75846..03f1cc9 100644 --- a/project/ProjectTourAgency/Enities/Tour.cs +++ b/project/ProjectTourAgency/Enities/Tour.cs @@ -10,16 +10,20 @@ namespace ProjectTourAgency.Enities; public class Tour { public int Id { get; private set; } + public int EmployeeId { get; private set; } + public int RouteId { get; private set; } public DateTime DepartureDate { get; private set; } - public int Cost { get; private set; } - public static Tour CreateEntity(int id, - DateTime date,int cost) + public IEnumerable ClientTours { get; private set; } = []; + public static Tour CreateEntity(int id, int employeeId, int routeId, + DateTime date,IEnumerable clientTours) { return new Tour { Id = id, + EmployeeId = employeeId, + RouteId = routeId, DepartureDate = date, - Cost = cost + ClientTours = clientTours }; } } diff --git a/project/ProjectTourAgency/FormTourAgency.Designer.cs b/project/ProjectTourAgency/FormTourAgency.Designer.cs index f0f7913..5c20f90 100644 --- a/project/ProjectTourAgency/FormTourAgency.Designer.cs +++ b/project/ProjectTourAgency/FormTourAgency.Designer.cs @@ -89,13 +89,14 @@ пополнитьБалансПользователяToolStripMenuItem.Name = "пополнитьБалансПользователяToolStripMenuItem"; пополнитьБалансПользователяToolStripMenuItem.Size = new Size(256, 22); пополнитьБалансПользователяToolStripMenuItem.Text = "Пополнить баланс пользователя"; - пополнитьБалансПользователяToolStripMenuItem.Click += пополнитьБалансПользователяToolStripMenuItem_Click; + пополнитьБалансПользователяToolStripMenuItem.Click += AddMoneyToolStripMenuItem_Click; // // турToolStripMenuItem // турToolStripMenuItem.Name = "турToolStripMenuItem"; турToolStripMenuItem.Size = new Size(256, 22); турToolStripMenuItem.Text = "Тур"; + турToolStripMenuItem.Click += ToursToolStripMenuItem_Click; // // отчетыToolStripMenuItem // diff --git a/project/ProjectTourAgency/FormTourAgency.cs b/project/ProjectTourAgency/FormTourAgency.cs index 54fbb9d..aca7679 100644 --- a/project/ProjectTourAgency/FormTourAgency.cs +++ b/project/ProjectTourAgency/FormTourAgency.cs @@ -50,11 +50,23 @@ public partial class FormTourAgency : Form } } - private void ToolStripMenuItem_Click(object sender, EventArgs e) + private void AddMoneyToolStripMenuItem_Click(object sender, EventArgs e) { try { - _container.Resolve().ShowDialog(); + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ToursToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); } catch (Exception ex) { diff --git a/project/ProjectTourAgency/Forms/FormAddMoneys.Designer.cs b/project/ProjectTourAgency/Forms/FormAddMoneys.Designer.cs new file mode 100644 index 0000000..b69a94a --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormAddMoneys.Designer.cs @@ -0,0 +1,97 @@ +namespace ProjectTourAgency.Forms +{ + partial class FormAddMoneys + { + /// + /// 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(699, 362); + dataGridViewData.TabIndex = 3; + // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(699, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(149, 362); + panel1.TabIndex = 2; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.free_icon_add_button_5974633; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(43, 25); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(61, 59); + buttonAdd.TabIndex = 1; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // FormAddMoneys + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(848, 362); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormAddMoneys"; + Text = "FormAddMoneys"; + Load += FormAddMoneys_Load; + ((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/project/ProjectTourAgency/Forms/FormAddMoneys.cs b/project/ProjectTourAgency/Forms/FormAddMoneys.cs new file mode 100644 index 0000000..8b9ae68 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormAddMoneys.cs @@ -0,0 +1,68 @@ +using ProjectTourAgency.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 ProjectTourAgency.Forms +{ + public partial class FormAddMoneys : Form + { + private readonly IUnityContainer _container; + + private readonly IAddMoneyRepository _addMoneyRepository; + + public FormAddMoneys(IAddMoneyRepository addMoneyRepository, IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _addMoneyRepository = addMoneyRepository ?? throw new ArgumentNullException(nameof(_addMoneyRepository)); + } + + private void FormAddMoneys_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 = _addMoneyRepository.ReadAddMoneys(); + + 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/project/ProjectTourAgency/Forms/FormAddMoneys.resx b/project/ProjectTourAgency/Forms/FormAddMoneys.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormAddMoneys.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/project/ProjectTourAgency/Forms/FormClientTour.Designer.cs b/project/ProjectTourAgency/Forms/FormClientTour.Designer.cs new file mode 100644 index 0000000..d3194d5 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormClientTour.Designer.cs @@ -0,0 +1,191 @@ +namespace ProjectTourAgency.Forms +{ + partial class FormClientTour + { + /// + /// 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() + { + labelEmployeeName = new Label(); + labelDate = new Label(); + groupBoxTour = new GroupBox(); + dataGridView = new DataGridView(); + ColumnClient = new DataGridViewComboBoxColumn(); + ColumnCost = new DataGridViewTextBoxColumn(); + labelRoute = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + comboBoxEmployeeId = new ComboBox(); + comboBoxRouteId = new ComboBox(); + dateTimePicker = new DateTimePicker(); + groupBoxTour.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelEmployeeName + // + labelEmployeeName.AutoSize = true; + labelEmployeeName.Location = new Point(12, 19); + labelEmployeeName.Name = "labelEmployeeName"; + labelEmployeeName.Size = new Size(59, 15); + labelEmployeeName.TabIndex = 0; + labelEmployeeName.Text = "Работник"; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(12, 95); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(127, 15); + labelDate.TabIndex = 1; + labelDate.Text = "Дата проведения тура"; + // + // groupBoxTour + // + groupBoxTour.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBoxTour.Controls.Add(dataGridView); + groupBoxTour.Location = new Point(18, 123); + groupBoxTour.Name = "groupBoxTour"; + groupBoxTour.Size = new Size(360, 248); + groupBoxTour.TabIndex = 2; + groupBoxTour.TabStop = false; + groupBoxTour.Text = "Клиенты"; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnClient, ColumnCost }); + dataGridView.Location = new Point(6, 22); + dataGridView.Name = "dataGridView"; + dataGridView.Size = new Size(348, 220); + dataGridView.TabIndex = 0; + dataGridView.CellContentClick += dataGridView_CellContentClick; + // + // ColumnClient + // + ColumnClient.HeaderText = "Клиент"; + ColumnClient.Name = "ColumnClient"; + ColumnClient.Resizable = DataGridViewTriState.True; + ColumnClient.SortMode = DataGridViewColumnSortMode.Automatic; + // + // ColumnCost + // + ColumnCost.HeaderText = "Цена"; + ColumnCost.Name = "ColumnCost"; + // + // labelRoute + // + labelRoute.AutoSize = true; + labelRoute.Location = new Point(12, 61); + labelRoute.Name = "labelRoute"; + labelRoute.Size = new Size(60, 15); + labelRoute.TabIndex = 3; + labelRoute.Text = "Маршрут"; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(29, 400); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(110, 25); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(249, 400); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(110, 25); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // comboBoxEmployeeId + // + comboBoxEmployeeId.FormattingEnabled = true; + comboBoxEmployeeId.Location = new Point(145, 16); + comboBoxEmployeeId.Name = "comboBoxEmployeeId"; + comboBoxEmployeeId.Size = new Size(186, 23); + comboBoxEmployeeId.TabIndex = 6; + // + // comboBoxRouteId + // + comboBoxRouteId.FormattingEnabled = true; + comboBoxRouteId.Location = new Point(145, 58); + comboBoxRouteId.Name = "comboBoxRouteId"; + comboBoxRouteId.Size = new Size(186, 23); + comboBoxRouteId.TabIndex = 7; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(145, 89); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(186, 23); + dateTimePicker.TabIndex = 8; + // + // FormClientTour + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(406, 456); + Controls.Add(dateTimePicker); + Controls.Add(comboBoxRouteId); + Controls.Add(comboBoxEmployeeId); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelRoute); + Controls.Add(groupBoxTour); + Controls.Add(labelDate); + Controls.Add(labelEmployeeName); + Name = "FormClientTour"; + Text = "FormClientTour"; + groupBoxTour.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelEmployeeName; + private Label labelDate; + private GroupBox groupBoxTour; + private DataGridView dataGridView; + private DataGridViewComboBoxColumn ColumnClient; + private DataGridViewTextBoxColumn ColumnCost; + private Label labelRoute; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxEmployeeId; + private ComboBox comboBoxRouteId; + private DateTimePicker dateTimePicker; + } +} \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormClientTour.cs b/project/ProjectTourAgency/Forms/FormClientTour.cs new file mode 100644 index 0000000..76552b8 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormClientTour.cs @@ -0,0 +1,83 @@ +using ProjectEmployeeAgency.Repositories; +using ProjectRouteAgency.Repositories; +using ProjectTourAgency.Enities; +using ProjectTourAgency.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 ProjectTourAgency.Forms +{ + public partial class FormClientTour : Form + { + private readonly ITourRepository _tourRepository; + public FormClientTour(ITourRepository tourRepository, + IEmployeeRepository employeeRepository, + IRouteRepository routeRepository, IClientRepository clientRepository) + { + InitializeComponent(); + _tourRepository = tourRepository ?? + throw new ArgumentNullException(nameof(tourRepository)); + comboBoxEmployeeId.DataSource = employeeRepository.ReadEmployees(); + comboBoxEmployeeId.DisplayMember = "FullName"; + comboBoxEmployeeId.ValueMember = "Id"; + + comboBoxRouteId.DataSource = routeRepository.ReadRoutes(); + comboBoxRouteId.DisplayMember = "Destination"; + comboBoxRouteId.ValueMember = "Id"; + + ColumnClient.DataSource = clientRepository.ReadClients(); + ColumnClient.DisplayMember = "FullName"; + ColumnClient.ValueMember = "Id"; + } + + private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (dataGridView.RowCount < 1 + || comboBoxEmployeeId.SelectedIndex < 0 + || comboBoxRouteId.SelectedIndex < 0) + { + throw new Exception("Есть незаполненные поля"); + } + _tourRepository.CreateTour(Tour.CreateEntity(0, comboBoxEmployeeId.SelectedIndex, + comboBoxRouteId.SelectedIndex, dateTimePicker.Value,CreateListClientTourFromDataGrid())); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + + private List CreateListClientTourFromDataGrid() + { + var list = new List(); + foreach(DataGridViewRow row in dataGridView.Rows) + { + if (row.Cells["ColumnClient"].Value == null + || row.Cells["ColumnCost"].Value == null) + { + continue; + } + list.Add(ClientTour.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnClient"].Value), 0, + Convert.ToInt32(row.Cells["ColumnCost"].Value))); + } + return list; + } + + } +} diff --git a/project/ProjectTourAgency/Forms/FormClientTour.resx b/project/ProjectTourAgency/Forms/FormClientTour.resx new file mode 100644 index 0000000..bb2c7f8 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormClientTour.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormTours.Designer.cs b/project/ProjectTourAgency/Forms/FormTours.Designer.cs new file mode 100644 index 0000000..a5b7a3f --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormTours.Designer.cs @@ -0,0 +1,111 @@ +namespace ProjectTourAgency.Forms +{ + partial class FormTours + { + /// + /// 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(746, 462); + dataGridViewData.TabIndex = 3; + // + // panel1 + // + panel1.Controls.Add(buttonDelete); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(746, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(149, 462); + panel1.TabIndex = 2; + // + // buttonDelete + // + buttonDelete.BackgroundImage = Properties.Resources.free_icon_delete_3807871; + buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; + buttonDelete.Location = new Point(43, 276); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(61, 59); + buttonDelete.TabIndex = 3; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.free_icon_add_button_5974633; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(43, 25); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(61, 59); + buttonAdd.TabIndex = 1; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // FormTours + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(895, 462); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormTours"; + Text = "FormTours"; + Load += FormTours_Load; + ((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/project/ProjectTourAgency/Forms/FormTours.cs b/project/ProjectTourAgency/Forms/FormTours.cs new file mode 100644 index 0000000..64529f2 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormTours.cs @@ -0,0 +1,91 @@ +using ProjectTourAgency.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 ProjectTourAgency.Forms +{ + public partial class FormTours : Form + { + private readonly IUnityContainer _container; + + private readonly ITourRepository _tourRepository; + + public FormTours(ITourRepository tourRepository, IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _tourRepository = tourRepository ?? throw new ArgumentNullException(nameof(_tourRepository)); + } + + private void FormTours_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 buttonDelete_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _tourRepository.DeleteTour(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _tourRepository.ReadTours(); + + 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/project/ProjectTourAgency/Forms/FormTours.resx b/project/ProjectTourAgency/Forms/FormTours.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormTours.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/project/ProjectTourAgency/Implementations/TourRepositiry.cs b/project/ProjectTourAgency/Implementations/TourRepository.cs similarity index 83% rename from project/ProjectTourAgency/Implementations/TourRepositiry.cs rename to project/ProjectTourAgency/Implementations/TourRepository.cs index 0d63b70..0ca7486 100644 --- a/project/ProjectTourAgency/Implementations/TourRepositiry.cs +++ b/project/ProjectTourAgency/Implementations/TourRepository.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace ProjectTourAgency.Implementations; -public class TourRepositiry : ITourRepository +public class TourRepository : ITourRepository { public void CreateTour(Tour tour) { @@ -21,7 +21,7 @@ public class TourRepositiry : ITourRepository public Tour ReadTourById(int id) { - return Tour.CreateEntity(0,DateTime.Now,0); + return Tour.CreateEntity(0,0, 0,DateTime.Now, []); } public IEnumerable ReadTours() diff --git a/project/ProjectTourAgency/Program.cs b/project/ProjectTourAgency/Program.cs index 08a2e39..676f643 100644 --- a/project/ProjectTourAgency/Program.cs +++ b/project/ProjectTourAgency/Program.cs @@ -24,11 +24,12 @@ namespace ProjectTourAgency { var container = new UnityContainer(); + container.RegisterType(); container.RegisterType(); container.RegisterType(); container.RegisterType(); container.RegisterType(); - container.RegisterType(); + container.RegisterType(); return container; }