PIbd-23 SheymuhovA.I. LabWork01 #1

Closed
sheym wants to merge 4 commits from LabWork1 into main
5 changed files with 16 additions and 28 deletions
Showing only changes of commit d2fb047b36 - Show all commits

View File

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

View File

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

View File

@ -17,7 +17,7 @@ public class BusRepository : IBusRepository
public Bus ReadBusById(int busId)
{
return Bus.CreateEntity(0, string.Empty, BusType.None);
return Bus.CreateEntity(0, string.Empty, string.Empty);
}
public IEnumerable<Bus> ReadBuses()