From a6fbd1de2e892db6dbbe522df8b2bd63666e82aa Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Sat, 9 Nov 2024 00:38:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20Tour=20=D0=B8?= =?UTF-8?q?=20Tours?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/ProjectTourAgency/Forms/FormClient.cs | 2 +- project/ProjectTourAgency/Forms/FormTour.cs | 4 +- .../Forms/FormTours.Designer.cs | 125 ++++++++++++++++++ project/ProjectTourAgency/Forms/FormTours.cs | 110 +++++++++++++++ .../ProjectTourAgency/Forms/FormTours.resx | 120 +++++++++++++++++ 5 files changed, 358 insertions(+), 3 deletions(-) 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 diff --git a/project/ProjectTourAgency/Forms/FormClient.cs b/project/ProjectTourAgency/Forms/FormClient.cs index 1ec6d12..191d028 100644 --- a/project/ProjectTourAgency/Forms/FormClient.cs +++ b/project/ProjectTourAgency/Forms/FormClient.cs @@ -57,7 +57,7 @@ public partial class FormClient : Form try { if(string.IsNullOrWhiteSpace(textBoxName.Text) || - string.IsNullOrWhiteSpace(textBoxNumber.Text) || comboBoxSocialStatus.SelectedIndex < 1) + string.IsNullOrWhiteSpace(textBoxNumber.Text) || comboBoxSocialStatus.SelectedIndex < 0) { throw new Exception("Имеются незаполненные поля"); } diff --git a/project/ProjectTourAgency/Forms/FormTour.cs b/project/ProjectTourAgency/Forms/FormTour.cs index 85a932d..884ccd6 100644 --- a/project/ProjectTourAgency/Forms/FormTour.cs +++ b/project/ProjectTourAgency/Forms/FormTour.cs @@ -31,7 +31,7 @@ namespace ProjectTourAgency.Forms } textBoxDestination.Text = tour.Destination; textBoxDeparture.Text = tour.Departure; - dateTimePickerDepartureDate.Text = tour.DepartureDate.ToString(); + dateTimePickerDepartureDate.Value = tour.DepartureDate; textBoxDuration.Text = tour.Duration.ToString(); textBoxPrice.Text = tour.Cost.ToString(); } @@ -81,7 +81,7 @@ namespace ProjectTourAgency.Forms private void buttonCancel_Click(object sender, EventArgs e) => Close(); - private Tour CreateTour(int id) => Tour.CreateEntity(id, textBoxDestination.Text, dateTimePickerDepartureDate, + private Tour CreateTour(int id) => Tour.CreateEntity(id, textBoxDestination.Text, dateTimePickerDepartureDate.Value, textBoxDeparture.Text, int.Parse(textBoxPrice.Text), int.Parse(textBoxDuration.Text)); } diff --git a/project/ProjectTourAgency/Forms/FormTours.Designer.cs b/project/ProjectTourAgency/Forms/FormTours.Designer.cs new file mode 100644 index 0000000..a22f020 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormTours.Designer.cs @@ -0,0 +1,125 @@ +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(); + buttonUpdate = 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(651, 450); + dataGridViewData.TabIndex = 3; + // + // panel1 + // + panel1.Controls.Add(buttonDelete); + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(651, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(149, 450); + 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; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.free_icon_edit_8679935; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(43, 142); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(61, 59); + buttonUpdate.TabIndex = 2; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_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(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormTours"; + Text = "Туры"; + 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 buttonUpdate; + 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..3a4852d --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormTours.cs @@ -0,0 +1,110 @@ +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 buttonUpdate_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 + { + _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