Сделана логика для формы Tour, исправлена опечатка в название интерфейса ITourRepo и все связанное с ней
This commit is contained in:
parent
2043b7962e
commit
3a98780b1e
@ -13,9 +13,10 @@ public class Tour
|
|||||||
public string Destination { get; private set; } = string.Empty;
|
public string Destination { get; private set; } = string.Empty;
|
||||||
public string Departure { get; private set; } = string.Empty;
|
public string Departure { get; private set; } = string.Empty;
|
||||||
public DateTime DepartureDate { get; private set; }
|
public DateTime DepartureDate { get; private set; }
|
||||||
|
public int Duration { get; private set; }
|
||||||
public int Cost { get; private set; }
|
public int Cost { get; private set; }
|
||||||
public static Tour CreateEntity(int id, string destination,
|
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
|
return new Tour
|
||||||
{
|
{
|
||||||
@ -23,7 +24,8 @@ public class Tour
|
|||||||
Destination = destination,
|
Destination = destination,
|
||||||
Departure = departure,
|
Departure = departure,
|
||||||
DepartureDate = date,
|
DepartureDate = date,
|
||||||
Cost = cost
|
Cost = cost,
|
||||||
|
Duration = duration
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public partial class FormClient : Form
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(string.IsNullOrWhiteSpace(textBoxName.Text) ||
|
if(string.IsNullOrWhiteSpace(textBoxName.Text) ||
|
||||||
string.IsNullOrWhiteSpace(textBoxNumber.Text))
|
string.IsNullOrWhiteSpace(textBoxNumber.Text) || comboBoxSocialStatus.SelectedIndex < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
|
152
project/ProjectTourAgency/Forms/FormTour.Designer.cs
generated
152
project/ProjectTourAgency/Forms/FormTour.Designer.cs
generated
@ -28,12 +28,156 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.components = new System.ComponentModel.Container();
|
dateTimePickerDepartureDate = new DateTimePicker();
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
textBoxDestination = new TextBox();
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
labelDestination = new Label();
|
||||||
this.Text = "FormTour";
|
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
|
#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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
using System;
|
using ProjectTourAgency.Enities;
|
||||||
|
using ProjectTourAgency.Implementations;
|
||||||
|
using ProjectTourAgency.Repositories;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@ -12,9 +15,74 @@ namespace ProjectTourAgency.Forms
|
|||||||
{
|
{
|
||||||
public partial class FormTour : Form
|
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();
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProjectTourAgency.Implementations;
|
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)
|
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<Tour> ReadTours()
|
public IEnumerable<Tour> ReadTours()
|
||||||
|
@ -7,13 +7,13 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProjectTourAgency.Repositories;
|
namespace ProjectTourAgency.Repositories;
|
||||||
|
|
||||||
public interface ITourRepositiry
|
public interface ITourRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Tour> ReadTours();
|
IEnumerable<Tour> ReadTours();
|
||||||
|
|
||||||
Tour ReadTourById(int id);
|
Tour ReadTourById(int id);
|
||||||
|
|
||||||
void CreateTourt(Tour tour);
|
void CreateTour(Tour tour);
|
||||||
|
|
||||||
void UpdateTour(Tour tour);
|
void UpdateTour(Tour tour);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user