Убрал лишнее перечисление

This commit is contained in:
sheymuh 2024-11-20 12:31:41 +04:00
parent 8f35937785
commit 07835de7ef
4 changed files with 15 additions and 27 deletions

View File

@ -8,15 +8,15 @@ public class Bus
public string LicensePlate { get; private set; } = string.Empty; public string LicensePlate { get; private set; } = string.Empty;
public BusType Type { get; private set; } public string Model { get; private set; } = string.Empty;
public static Bus CreateEntity(int id, string licensePlate, BusType type) public static Bus CreateEntity(int id, string licensePlate, string model)
{ {
return new Bus return new Bus
{ {
Id = id, Id = id,
LicensePlate = licensePlate, LicensePlate = licensePlate,
Type = type Model = model
}; };
} }
} }

View File

@ -1,10 +0,0 @@
namespace ProjectPassengerTransportation.Entities.Enums;
public enum BusType
{
None = 0,
Bus = 1,
Minibus = 2
}

View File

@ -33,7 +33,7 @@
labelBusTypeName = new Label(); labelBusTypeName = new Label();
buttonSave = new Button(); buttonSave = new Button();
buttonCancel = new Button(); buttonCancel = new Button();
comboBoxBusType = new ComboBox(); textBoxModel = new TextBox();
SuspendLayout(); SuspendLayout();
// //
// labelLicensePlate // labelLicensePlate
@ -84,21 +84,20 @@
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click; buttonCancel.Click += ButtonCancel_Click;
// //
// comboBoxBusType // textBoxModel
// //
comboBoxBusType.DropDownStyle = ComboBoxStyle.DropDownList; textBoxModel.Location = new Point(231, 96);
comboBoxBusType.FormattingEnabled = true; textBoxModel.MaxLength = 10;
comboBoxBusType.Location = new Point(231, 96); textBoxModel.Name = "textBoxModel";
comboBoxBusType.Name = "comboBoxBusType"; textBoxModel.Size = new Size(240, 35);
comboBoxBusType.Size = new Size(240, 38); textBoxModel.TabIndex = 8;
comboBoxBusType.TabIndex = 8;
// //
// FormBus // FormBus
// //
AutoScaleDimensions = new SizeF(12F, 30F); AutoScaleDimensions = new SizeF(12F, 30F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(506, 226); ClientSize = new Size(506, 226);
Controls.Add(comboBoxBusType); Controls.Add(textBoxModel);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(labelBusTypeName); Controls.Add(labelBusTypeName);
@ -118,6 +117,6 @@
private Label labelBusTypeName; private Label labelBusTypeName;
private Button buttonSave; private Button buttonSave;
private Button buttonCancel; private Button buttonCancel;
private ComboBox comboBoxBusType; private TextBox textBoxModel;
} }
} }

View File

@ -23,7 +23,7 @@ namespace ProjectPassengerTransportation.Forms
} }
textBoxLicensePlate.Text = bus.LicensePlate; textBoxLicensePlate.Text = bus.LicensePlate;
comboBoxBusType.SelectedItem = bus.Type; comboBoxBusType.SelectedItem = bus.Model;
_busId = value; _busId = value;
} }
catch (Exception ex) catch (Exception ex)
@ -38,14 +38,13 @@ namespace ProjectPassengerTransportation.Forms
{ {
InitializeComponent(); InitializeComponent();
_busRepository = busRepository ?? throw new ArgumentNullException(nameof(busRepository)); _busRepository = busRepository ?? throw new ArgumentNullException(nameof(busRepository));
comboBoxBusType.DataSource = Enum.GetValues(typeof(BusType));
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
try try
{ {
if (string.IsNullOrWhiteSpace(textBoxLicensePlate.Text) || comboBoxBusType.SelectedIndex < 1) if (string.IsNullOrWhiteSpace(textBoxLicensePlate.Text) || string.IsNullOrWhiteSpace(textBoxModel.Text))
{ {
throw new Exception("Имеются незаполненные поля"); throw new Exception("Имеются незаполненные поля");
} }
@ -69,6 +68,6 @@ namespace ProjectPassengerTransportation.Forms
private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Bus CreateBus(int id) => Bus.CreateEntity(id, textBoxLicensePlate.Text, (BusType)comboBoxBusType.SelectedItem!); private Bus CreateBus(int id) => Bus.CreateEntity(id, textBoxLicensePlate.Text, textBoxModel.Text);
} }
} }