From 3a98780b1e836bfa75c862c6a84c34a938d889cd Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Sat, 9 Nov 2024 00:22:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20Tour,=20=D0=B8=D1=81=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=BF=D0=B5?= =?UTF-8?q?=D1=87=D0=B0=D1=82=D0=BA=D0=B0=20=D0=B2=20=D0=BD=D0=B0=D0=B7?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80?= =?UTF-8?q?=D1=84=D0=B5=D0=B9=D1=81=D0=B0=20ITourRepo=20=D0=B8=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B0=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D0=B5=20=D1=81=20=D0=BD=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/ProjectTourAgency/Enities/Tour.cs | 6 +- project/ProjectTourAgency/Forms/FormClient.cs | 2 +- .../Forms/FormTour.Designer.cs | 152 +++++++++++++++++- project/ProjectTourAgency/Forms/FormTour.cs | 72 ++++++++- project/ProjectTourAgency/Forms/FormTour.resx | 50 +++--- .../Implementations/TourRepositiry.cs | 6 +- .../Repositories/ITourRepositiry.cs | 4 +- 7 files changed, 253 insertions(+), 39 deletions(-) diff --git a/project/ProjectTourAgency/Enities/Tour.cs b/project/ProjectTourAgency/Enities/Tour.cs index 14b81f0..a98d37e 100644 --- a/project/ProjectTourAgency/Enities/Tour.cs +++ b/project/ProjectTourAgency/Enities/Tour.cs @@ -13,9 +13,10 @@ public class Tour public string Destination { get; private set; } = string.Empty; public string Departure { get; private set; } = string.Empty; public DateTime DepartureDate { get; private set; } + public int Duration { get; private set; } public int Cost { get; private set; } public static Tour CreateEntity(int id, string destination, - DateTime date, string departure, int cost) + DateTime date, string departure, int cost, int duration) { return new Tour { @@ -23,7 +24,8 @@ public class Tour Destination = destination, Departure = departure, DepartureDate = date, - Cost = cost + Cost = cost, + Duration = duration }; } } diff --git a/project/ProjectTourAgency/Forms/FormClient.cs b/project/ProjectTourAgency/Forms/FormClient.cs index 225fce4..1ec6d12 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)) + string.IsNullOrWhiteSpace(textBoxNumber.Text) || comboBoxSocialStatus.SelectedIndex < 1) { throw new Exception("Имеются незаполненные поля"); } diff --git a/project/ProjectTourAgency/Forms/FormTour.Designer.cs b/project/ProjectTourAgency/Forms/FormTour.Designer.cs index a21485e..df8a697 100644 --- a/project/ProjectTourAgency/Forms/FormTour.Designer.cs +++ b/project/ProjectTourAgency/Forms/FormTour.Designer.cs @@ -28,12 +28,156 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormTour"; + dateTimePickerDepartureDate = new DateTimePicker(); + textBoxDestination = new TextBox(); + labelDestination = new Label(); + labelDeparture = new Label(); + textBoxDuration = new TextBox(); + labelPrice = new Label(); + textBoxDeparture = new TextBox(); + labelDate = new Label(); + labelDuration = new Label(); + textBoxPrice = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // dateTimePickerDepartureDate + // + dateTimePickerDepartureDate.Location = new Point(144, 114); + dateTimePickerDepartureDate.Name = "dateTimePickerDepartureDate"; + dateTimePickerDepartureDate.Size = new Size(226, 23); + dateTimePickerDepartureDate.TabIndex = 2; + // + // textBoxDestination + // + textBoxDestination.Location = new Point(144, 32); + textBoxDestination.Name = "textBoxDestination"; + textBoxDestination.Size = new Size(226, 23); + textBoxDestination.TabIndex = 4; + // + // labelDestination + // + labelDestination.AutoSize = true; + labelDestination.Location = new Point(38, 32); + labelDestination.Name = "labelDestination"; + labelDestination.Size = new Size(100, 15); + labelDestination.TabIndex = 3; + labelDestination.Text = "Место прибытия"; + // + // labelDeparture + // + labelDeparture.AutoSize = true; + labelDeparture.Location = new Point(38, 78); + labelDeparture.Name = "labelDeparture"; + labelDeparture.Size = new Size(91, 15); + labelDeparture.TabIndex = 5; + labelDeparture.Text = "Место отбытия"; + // + // textBoxDuration + // + textBoxDuration.Location = new Point(144, 162); + textBoxDuration.Name = "textBoxDuration"; + textBoxDuration.Size = new Size(226, 23); + textBoxDuration.TabIndex = 7; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(35, 205); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(94, 15); + labelPrice.TabIndex = 6; + labelPrice.Text = "Стоимость тура"; + // + // textBoxDeparture + // + textBoxDeparture.Location = new Point(144, 75); + textBoxDeparture.Name = "textBoxDeparture"; + textBoxDeparture.Size = new Size(226, 23); + textBoxDeparture.TabIndex = 8; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(38, 120); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(84, 15); + labelDate.TabIndex = 9; + labelDate.Text = "Дата отбытия"; + // + // labelDuration + // + labelDuration.AutoSize = true; + labelDuration.Location = new Point(38, 162); + labelDuration.Name = "labelDuration"; + labelDuration.Size = new Size(84, 15); + labelDuration.TabIndex = 10; + labelDuration.Text = "Дата отбытия"; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(144, 205); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(226, 23); + textBoxPrice.TabIndex = 11; + // + // buttonSave + // + buttonSave.Location = new Point(63, 251); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 12; + buttonSave.Text = "button1"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(256, 251); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 13; + buttonCancel.Text = "button2"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormTour + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(414, 301); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxPrice); + Controls.Add(labelDuration); + Controls.Add(labelDate); + Controls.Add(textBoxDeparture); + Controls.Add(textBoxDuration); + Controls.Add(labelPrice); + Controls.Add(labelDeparture); + Controls.Add(textBoxDestination); + Controls.Add(labelDestination); + Controls.Add(dateTimePickerDepartureDate); + Name = "FormTour"; + StartPosition = FormStartPosition.CenterParent; + Text = "Тур"; + ResumeLayout(false); + PerformLayout(); } #endregion + private DateTimePicker dateTimePickerDepartureDate; + private TextBox textBoxDestination; + private Label labelDestination; + private Label labelDeparture; + private TextBox textBoxDuration; + private Label labelPrice; + private TextBox textBoxDeparture; + private Label labelDate; + private Label labelDuration; + private TextBox textBoxPrice; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormTour.cs b/project/ProjectTourAgency/Forms/FormTour.cs index 7d1fbc9..85a932d 100644 --- a/project/ProjectTourAgency/Forms/FormTour.cs +++ b/project/ProjectTourAgency/Forms/FormTour.cs @@ -1,4 +1,7 @@ -using System; +using ProjectTourAgency.Enities; +using ProjectTourAgency.Implementations; +using ProjectTourAgency.Repositories; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +15,74 @@ namespace ProjectTourAgency.Forms { public partial class FormTour : Form { - public FormTour() + private readonly ITourRepository _tourRepository; + + private int? _tourId; + public int Id + { + set + { + try + { + var tour = _tourRepository.ReadTourById(value); + if (tour == null) + { + throw new InvalidOperationException(nameof(tour)); + } + textBoxDestination.Text = tour.Destination; + textBoxDeparture.Text = tour.Departure; + dateTimePickerDepartureDate.Text = tour.DepartureDate.ToString(); + textBoxDuration.Text = tour.Duration.ToString(); + textBoxPrice.Text = tour.Cost.ToString(); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message,"Ошибка при получении ланных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormTour(ITourRepository tourRepository) { InitializeComponent(); + _tourRepository = tourRepository ?? + throw new ArgumentNullException(nameof(tourRepository)); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxDestination.Text) || + string.IsNullOrWhiteSpace(textBoxDeparture.Text) || string.IsNullOrWhiteSpace(textBoxDuration.Text) + || string.IsNullOrWhiteSpace(textBoxPrice.Text) || string.IsNullOrWhiteSpace(dateTimePickerDepartureDate.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_tourId.HasValue) + { + _tourRepository.UpdateTour(CreateTour(_tourId.Value)); + } + else + { + _tourRepository.CreateTour(CreateTour(_tourId.Value)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + + private Tour CreateTour(int id) => Tour.CreateEntity(id, textBoxDestination.Text, dateTimePickerDepartureDate, + textBoxDeparture.Text, int.Parse(textBoxPrice.Text), + int.Parse(textBoxDuration.Text)); } } diff --git a/project/ProjectTourAgency/Forms/FormTour.resx b/project/ProjectTourAgency/Forms/FormTour.resx index 1af7de1..af32865 100644 --- a/project/ProjectTourAgency/Forms/FormTour.resx +++ b/project/ProjectTourAgency/Forms/FormTour.resx @@ -1,17 +1,17 @@  - diff --git a/project/ProjectTourAgency/Implementations/TourRepositiry.cs b/project/ProjectTourAgency/Implementations/TourRepositiry.cs index 3ee32ad..9aef34f 100644 --- a/project/ProjectTourAgency/Implementations/TourRepositiry.cs +++ b/project/ProjectTourAgency/Implementations/TourRepositiry.cs @@ -8,9 +8,9 @@ using System.Threading.Tasks; namespace ProjectTourAgency.Implementations; -public class TourRepositiry : ITourRepositiry +public class TourRepositiry : ITourRepository { - public void CreateTourt(Tour tour) + public void CreateTour(Tour tour) { } @@ -21,7 +21,7 @@ public class TourRepositiry : ITourRepositiry public Tour ReadTourById(int id) { - return Tour.CreateEntity(0, string.Empty, DateTime.Now, string.Empty, 0); + return Tour.CreateEntity(0, string.Empty, DateTime.Now, string.Empty, 0,0); } public IEnumerable ReadTours() diff --git a/project/ProjectTourAgency/Repositories/ITourRepositiry.cs b/project/ProjectTourAgency/Repositories/ITourRepositiry.cs index 63a251c..39364e5 100644 --- a/project/ProjectTourAgency/Repositories/ITourRepositiry.cs +++ b/project/ProjectTourAgency/Repositories/ITourRepositiry.cs @@ -7,13 +7,13 @@ using System.Threading.Tasks; namespace ProjectTourAgency.Repositories; -public interface ITourRepositiry +public interface ITourRepository { IEnumerable ReadTours(); Tour ReadTourById(int id); - void CreateTourt(Tour tour); + void CreateTour(Tour tour); void UpdateTour(Tour tour);