From 3fd6b1e6eb448c7b03db14d80ed5b26992315829 Mon Sep 17 00:00:00 2001 From: Factorino73 Date: Mon, 8 Apr 2024 21:05:52 +0400 Subject: [PATCH] Migrations Fixes --- .../20240407200755_InitialCreate.Designer.cs | 241 ++++++++++++++++++ .../20240407200755_InitialCreate.cs | 185 ++++++++++++++ .../RouteGuideDatabaseModelSnapshot.cs | 238 +++++++++++++++++ .../Models/Transport.cs | 1 + .../RouteGuideView/FormRoute.Designer.cs | 26 +- RouteGuide/RouteGuideView/FormRoute.cs | 36 ++- RouteGuide/RouteGuideView/FormRoute.resx | 9 - .../RouteGuideView/FormRouteStop.Designer.cs | 1 + .../RouteGuideView/FormSchedule.Designer.cs | 1 + RouteGuide/RouteGuideView/FormStops.cs | 1 + .../RouteGuideView/FormTransport.Designer.cs | 2 + RouteGuide/RouteGuideView/FormTransport.cs | 6 +- RouteGuide/RouteGuideView/FormTransports.cs | 1 + 13 files changed, 733 insertions(+), 15 deletions(-) create mode 100644 RouteGuide/RouteGuideDatabaseImplement/Migrations/20240407200755_InitialCreate.Designer.cs create mode 100644 RouteGuide/RouteGuideDatabaseImplement/Migrations/20240407200755_InitialCreate.cs create mode 100644 RouteGuide/RouteGuideDatabaseImplement/Migrations/RouteGuideDatabaseModelSnapshot.cs diff --git a/RouteGuide/RouteGuideDatabaseImplement/Migrations/20240407200755_InitialCreate.Designer.cs b/RouteGuide/RouteGuideDatabaseImplement/Migrations/20240407200755_InitialCreate.Designer.cs new file mode 100644 index 0000000..142500c --- /dev/null +++ b/RouteGuide/RouteGuideDatabaseImplement/Migrations/20240407200755_InitialCreate.Designer.cs @@ -0,0 +1,241 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using RouteGuideDatabaseImplement; + +#nullable disable + +namespace RouteGuideDatabaseImplement.Migrations +{ + [DbContext(typeof(RouteGuideDatabase))] + [Migration("20240407200755_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Driver", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Experience") + .HasColumnType("integer"); + + b.Property("FullName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Drivers"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Route", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("TransportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TransportId"); + + b.ToTable("Routes"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.RouteStop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Number") + .HasColumnType("integer"); + + b.Property("RouteId") + .HasColumnType("integer"); + + b.Property("StopId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RouteId"); + + b.HasIndex("StopId"); + + b.ToTable("RouteStops"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Schedule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ArrivalTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DepartureTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Frequency") + .HasColumnType("timestamp with time zone"); + + b.Property("RouteId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RouteId"); + + b.ToTable("Schedules"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Stop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .HasColumnType("integer"); + + b.Property("Street") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Stops"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Transport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Capacity") + .HasColumnType("integer"); + + b.Property("DriverId") + .HasColumnType("integer"); + + b.Property("License") + .IsRequired() + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DriverId"); + + b.ToTable("Transport"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Route", b => + { + b.HasOne("RouteGuideDatabaseImplement.Models.Transport", "Transport") + .WithMany() + .HasForeignKey("TransportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Transport"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.RouteStop", b => + { + b.HasOne("RouteGuideDatabaseImplement.Models.Route", "Route") + .WithMany("Stops") + .HasForeignKey("RouteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RouteGuideDatabaseImplement.Models.Stop", "Stop") + .WithMany() + .HasForeignKey("StopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Route"); + + b.Navigation("Stop"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Schedule", b => + { + b.HasOne("RouteGuideDatabaseImplement.Models.Route", "Route") + .WithMany() + .HasForeignKey("RouteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Route"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Transport", b => + { + b.HasOne("RouteGuideDatabaseImplement.Models.Driver", "Driver") + .WithMany() + .HasForeignKey("DriverId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Driver"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Route", b => + { + b.Navigation("Stops"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/RouteGuide/RouteGuideDatabaseImplement/Migrations/20240407200755_InitialCreate.cs b/RouteGuide/RouteGuideDatabaseImplement/Migrations/20240407200755_InitialCreate.cs new file mode 100644 index 0000000..d5546f0 --- /dev/null +++ b/RouteGuide/RouteGuideDatabaseImplement/Migrations/20240407200755_InitialCreate.cs @@ -0,0 +1,185 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace RouteGuideDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Drivers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FullName = table.Column(type: "text", nullable: false), + Phone = table.Column(type: "text", nullable: false), + Experience = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Drivers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Stops", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Street = table.Column(type: "text", nullable: false), + Number = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Stops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Transport", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + License = table.Column(type: "text", nullable: false), + Type = table.Column(type: "integer", nullable: false), + Capacity = table.Column(type: "integer", nullable: false), + DriverId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Transport", x => x.Id); + table.ForeignKey( + name: "FK_Transport_Drivers_DriverId", + column: x => x.DriverId, + principalTable: "Drivers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Routes", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + TransportId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Routes", x => x.Id); + table.ForeignKey( + name: "FK_Routes_Transport_TransportId", + column: x => x.TransportId, + principalTable: "Transport", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "RouteStops", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RouteId = table.Column(type: "integer", nullable: false), + StopId = table.Column(type: "integer", nullable: false), + Number = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RouteStops", x => x.Id); + table.ForeignKey( + name: "FK_RouteStops_Routes_RouteId", + column: x => x.RouteId, + principalTable: "Routes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RouteStops_Stops_StopId", + column: x => x.StopId, + principalTable: "Stops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Schedules", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Date = table.Column(type: "timestamp with time zone", nullable: false), + DepartureTime = table.Column(type: "timestamp with time zone", nullable: false), + ArrivalTime = table.Column(type: "timestamp with time zone", nullable: false), + Frequency = table.Column(type: "timestamp with time zone", nullable: false), + RouteId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Schedules", x => x.Id); + table.ForeignKey( + name: "FK_Schedules_Routes_RouteId", + column: x => x.RouteId, + principalTable: "Routes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Routes_TransportId", + table: "Routes", + column: "TransportId"); + + migrationBuilder.CreateIndex( + name: "IX_RouteStops_RouteId", + table: "RouteStops", + column: "RouteId"); + + migrationBuilder.CreateIndex( + name: "IX_RouteStops_StopId", + table: "RouteStops", + column: "StopId"); + + migrationBuilder.CreateIndex( + name: "IX_Schedules_RouteId", + table: "Schedules", + column: "RouteId"); + + migrationBuilder.CreateIndex( + name: "IX_Transport_DriverId", + table: "Transport", + column: "DriverId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "RouteStops"); + + migrationBuilder.DropTable( + name: "Schedules"); + + migrationBuilder.DropTable( + name: "Stops"); + + migrationBuilder.DropTable( + name: "Routes"); + + migrationBuilder.DropTable( + name: "Transport"); + + migrationBuilder.DropTable( + name: "Drivers"); + } + } +} diff --git a/RouteGuide/RouteGuideDatabaseImplement/Migrations/RouteGuideDatabaseModelSnapshot.cs b/RouteGuide/RouteGuideDatabaseImplement/Migrations/RouteGuideDatabaseModelSnapshot.cs new file mode 100644 index 0000000..f596729 --- /dev/null +++ b/RouteGuide/RouteGuideDatabaseImplement/Migrations/RouteGuideDatabaseModelSnapshot.cs @@ -0,0 +1,238 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using RouteGuideDatabaseImplement; + +#nullable disable + +namespace RouteGuideDatabaseImplement.Migrations +{ + [DbContext(typeof(RouteGuideDatabase))] + partial class RouteGuideDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Driver", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Experience") + .HasColumnType("integer"); + + b.Property("FullName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Drivers"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Route", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("TransportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TransportId"); + + b.ToTable("Routes"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.RouteStop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Number") + .HasColumnType("integer"); + + b.Property("RouteId") + .HasColumnType("integer"); + + b.Property("StopId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RouteId"); + + b.HasIndex("StopId"); + + b.ToTable("RouteStops"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Schedule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ArrivalTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DepartureTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Frequency") + .HasColumnType("timestamp with time zone"); + + b.Property("RouteId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RouteId"); + + b.ToTable("Schedules"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Stop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .HasColumnType("integer"); + + b.Property("Street") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Stops"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Transport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Capacity") + .HasColumnType("integer"); + + b.Property("DriverId") + .HasColumnType("integer"); + + b.Property("License") + .IsRequired() + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DriverId"); + + b.ToTable("Transport"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Route", b => + { + b.HasOne("RouteGuideDatabaseImplement.Models.Transport", "Transport") + .WithMany() + .HasForeignKey("TransportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Transport"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.RouteStop", b => + { + b.HasOne("RouteGuideDatabaseImplement.Models.Route", "Route") + .WithMany("Stops") + .HasForeignKey("RouteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RouteGuideDatabaseImplement.Models.Stop", "Stop") + .WithMany() + .HasForeignKey("StopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Route"); + + b.Navigation("Stop"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Schedule", b => + { + b.HasOne("RouteGuideDatabaseImplement.Models.Route", "Route") + .WithMany() + .HasForeignKey("RouteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Route"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Transport", b => + { + b.HasOne("RouteGuideDatabaseImplement.Models.Driver", "Driver") + .WithMany() + .HasForeignKey("DriverId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Driver"); + }); + + modelBuilder.Entity("RouteGuideDatabaseImplement.Models.Route", b => + { + b.Navigation("Stops"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs b/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs index bfc00e3..ef1e2b9 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs @@ -99,6 +99,7 @@ namespace RouteGuideDatabaseImplement.Models Id = Id, License = License, Type = Type, + Capacity= Capacity, DriverId = DriverId, DriverName = Driver.FullName }; diff --git a/RouteGuide/RouteGuideView/FormRoute.Designer.cs b/RouteGuide/RouteGuideView/FormRoute.Designer.cs index c704611..9650aa3 100644 --- a/RouteGuide/RouteGuideView/FormRoute.Designer.cs +++ b/RouteGuide/RouteGuideView/FormRoute.Designer.cs @@ -41,6 +41,8 @@ ColumnNumber = new DataGridViewTextBoxColumn(); buttonSave = new Button(); buttonCancel = new Button(); + comboBoxTransport = new ComboBox(); + labelTransport = new Label(); groupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -49,7 +51,7 @@ // textBoxName.Location = new Point(80, 12); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(200, 23); + textBoxName.Size = new Size(150, 23); textBoxName.TabIndex = 0; // // labelName @@ -173,11 +175,31 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += buttonCancel_Click; // + // comboBoxTransport + // + comboBoxTransport.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxTransport.FormattingEnabled = true; + comboBoxTransport.Location = new Point(395, 12); + comboBoxTransport.Name = "comboBoxTransport"; + comboBoxTransport.Size = new Size(150, 23); + comboBoxTransport.TabIndex = 10; + // + // labelTransport + // + labelTransport.AutoSize = true; + labelTransport.Location = new Point(321, 15); + labelTransport.Name = "labelTransport"; + labelTransport.Size = new Size(68, 15); + labelTransport.TabIndex = 11; + labelTransport.Text = "Транспорт:"; + // // FormRoute // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(684, 361); + Controls.Add(labelTransport); + Controls.Add(comboBoxTransport); Controls.Add(buttonSave); Controls.Add(buttonCancel); Controls.Add(groupBox); @@ -207,5 +229,7 @@ private DataGridViewTextBoxColumn ColumnId; private DataGridViewTextBoxColumn ColumnName; private DataGridViewTextBoxColumn ColumnNumber; + private ComboBox comboBoxTransport; + private Label labelTransport; } } \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormRoute.cs b/RouteGuide/RouteGuideView/FormRoute.cs index bcd7ef4..da9dd4d 100644 --- a/RouteGuide/RouteGuideView/FormRoute.cs +++ b/RouteGuide/RouteGuideView/FormRoute.cs @@ -27,10 +27,15 @@ namespace RouteGuideView private readonly ILogger _logger; /// - /// Бизнес-логика + /// Бизнес-логика маршрутов /// private readonly IRouteLogic _routeLogic; + /// + /// Бизнес-логика транспорта + /// + private readonly ITransportLogic _transportLogic; + /// /// Идентификатор /// @@ -51,11 +56,12 @@ namespace RouteGuideView /// /// /// - public FormRoute(ILogger logger, IRouteLogic routeLogic) + public FormRoute(ILogger logger, IRouteLogic routeLogic, ITransportLogic transportLogic) { InitializeComponent(); _logger = logger; _routeLogic = routeLogic; + _transportLogic = transportLogic; _routeStops = new Dictionary(); } @@ -66,6 +72,25 @@ namespace RouteGuideView /// private void FormRoute_Load(object sender, EventArgs e) { + try + { + // Загрузка маршрутов для ComboBoxTransport + _logger.LogInformation("Загрузка списка транспорта"); + var list = _transportLogic.ReadList(null); + if (list != null) + { + comboBoxTransport.DisplayMember = "License"; + comboBoxTransport.ValueMember = "Id"; + comboBoxTransport.DataSource = list; + comboBoxTransport.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка транспорта"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + if (!_id.HasValue) { return; @@ -81,6 +106,7 @@ namespace RouteGuideView if (view != null) { textBoxName.Text = view.Name; + comboBoxTransport.SelectedValue = view.TransportId; _routeStops = view.RouteStops ?? new Dictionary(); LoadData(); } @@ -202,6 +228,11 @@ namespace RouteGuideView MessageBox.Show("Заполните название маршрута", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (comboBoxTransport.SelectedValue == null) + { + MessageBox.Show("Выберите транспорт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Сохранение сущности 'Маршрут'"); try @@ -210,6 +241,7 @@ namespace RouteGuideView { Id = _id ?? 0, Name = textBoxName.Text, + TransportId = Convert.ToInt32(comboBoxTransport.SelectedValue), RouteStops = _routeStops }; diff --git a/RouteGuide/RouteGuideView/FormRoute.resx b/RouteGuide/RouteGuideView/FormRoute.resx index 64451e7..e12df0d 100644 --- a/RouteGuide/RouteGuideView/FormRoute.resx +++ b/RouteGuide/RouteGuideView/FormRoute.resx @@ -126,13 +126,4 @@ True - - True - - - True - - - True - \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormRouteStop.Designer.cs b/RouteGuide/RouteGuideView/FormRouteStop.Designer.cs index 55479d3..0368180 100644 --- a/RouteGuide/RouteGuideView/FormRouteStop.Designer.cs +++ b/RouteGuide/RouteGuideView/FormRouteStop.Designer.cs @@ -38,6 +38,7 @@ // // comboBoxStop // + comboBoxStop.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStop.FormattingEnabled = true; comboBoxStop.Location = new Point(80, 7); comboBoxStop.Name = "comboBoxStop"; diff --git a/RouteGuide/RouteGuideView/FormSchedule.Designer.cs b/RouteGuide/RouteGuideView/FormSchedule.Designer.cs index d6929ff..419ea18 100644 --- a/RouteGuide/RouteGuideView/FormSchedule.Designer.cs +++ b/RouteGuide/RouteGuideView/FormSchedule.Designer.cs @@ -75,6 +75,7 @@ // // comboBoxRoute // + comboBoxRoute.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxRoute.FormattingEnabled = true; comboBoxRoute.Location = new Point(101, 12); comboBoxRoute.Name = "comboBoxRoute"; diff --git a/RouteGuide/RouteGuideView/FormStops.cs b/RouteGuide/RouteGuideView/FormStops.cs index 28e28aa..6bf2d8d 100644 --- a/RouteGuide/RouteGuideView/FormStops.cs +++ b/RouteGuide/RouteGuideView/FormStops.cs @@ -140,6 +140,7 @@ namespace RouteGuideView { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка списка остановок"); } diff --git a/RouteGuide/RouteGuideView/FormTransport.Designer.cs b/RouteGuide/RouteGuideView/FormTransport.Designer.cs index 95fba38..c8a03c7 100644 --- a/RouteGuide/RouteGuideView/FormTransport.Designer.cs +++ b/RouteGuide/RouteGuideView/FormTransport.Designer.cs @@ -42,6 +42,7 @@ // // comboBoxType // + comboBoxType.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxType.FormattingEnabled = true; comboBoxType.Location = new Point(101, 12); comboBoxType.Name = "comboBoxType"; @@ -50,6 +51,7 @@ // // comboBoxDriver // + comboBoxDriver.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxDriver.FormattingEnabled = true; comboBoxDriver.Location = new Point(101, 41); comboBoxDriver.Name = "comboBoxDriver"; diff --git a/RouteGuide/RouteGuideView/FormTransport.cs b/RouteGuide/RouteGuideView/FormTransport.cs index 253b0b6..e7ddb6e 100644 --- a/RouteGuide/RouteGuideView/FormTransport.cs +++ b/RouteGuide/RouteGuideView/FormTransport.cs @@ -109,7 +109,7 @@ namespace RouteGuideView { textBoxLicense.Text = view.License; textBoxCapacity.Text = view.Capacity.ToString(); - comboBoxDriver.SelectedItem = view.DriverId; + comboBoxDriver.SelectedValue = view.DriverId; comboBoxType.SelectedItem = view.Type; } } @@ -127,7 +127,7 @@ namespace RouteGuideView /// private void buttonSave_Click(object sender, EventArgs e) { - if (comboBoxType.SelectedValue == null) + if (comboBoxType.SelectedIndex == -1) { MessageBox.Show("Выберите тип транспорта", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -155,7 +155,7 @@ namespace RouteGuideView { Id = _id ?? 0, License = textBoxLicense.Text, - Type = (TransportType)comboBoxType.SelectedValue, + Type = (TransportType)comboBoxType.SelectedItem, Capacity = int.TryParse(textBoxCapacity.Text, out var capacity) ? capacity : 1, DriverId = Convert.ToInt32(comboBoxDriver.SelectedValue) }; diff --git a/RouteGuide/RouteGuideView/FormTransports.cs b/RouteGuide/RouteGuideView/FormTransports.cs index e3df11d..25e1194 100644 --- a/RouteGuide/RouteGuideView/FormTransports.cs +++ b/RouteGuide/RouteGuideView/FormTransports.cs @@ -141,6 +141,7 @@ namespace RouteGuideView dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["DriverId"].Visible = false; + dataGridView.Columns["DriverName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка списка транспорта"); }