diff --git a/RouteGuide/RouteGuide/App.config b/RouteGuide/RouteGuide/App.config
index db7447d..90ed356 100644
--- a/RouteGuide/RouteGuide/App.config
+++ b/RouteGuide/RouteGuide/App.config
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/RouteGuide/RouteGuide/FormRoute.Designer.cs b/RouteGuide/RouteGuide/FormRoute.Designer.cs
index 4a7fcfd..870f53c 100644
--- a/RouteGuide/RouteGuide/FormRoute.Designer.cs
+++ b/RouteGuide/RouteGuide/FormRoute.Designer.cs
@@ -32,6 +32,17 @@
this.textBoxName = new System.Windows.Forms.TextBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
+ this.groupBox = new System.Windows.Forms.GroupBox();
+ this.buttonUpdate = new System.Windows.Forms.Button();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonRefresh = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnStop = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnNumber = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.groupBox.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// labelName
@@ -52,7 +63,7 @@
//
// buttonCancel
//
- this.buttonCancel.Location = new System.Drawing.Point(323, 54);
+ this.buttonCancel.Location = new System.Drawing.Point(656, 372);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(112, 34);
this.buttonCancel.TabIndex = 2;
@@ -62,7 +73,7 @@
//
// buttonSave
//
- this.buttonSave.Location = new System.Drawing.Point(185, 54);
+ this.buttonSave.Location = new System.Drawing.Point(528, 372);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(112, 34);
this.buttonSave.TabIndex = 3;
@@ -70,18 +81,111 @@
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
+ // groupBox
+ //
+ this.groupBox.Controls.Add(this.buttonUpdate);
+ this.groupBox.Controls.Add(this.buttonDelete);
+ this.groupBox.Controls.Add(this.buttonRefresh);
+ this.groupBox.Controls.Add(this.buttonAdd);
+ this.groupBox.Controls.Add(this.dataGridView);
+ this.groupBox.Location = new System.Drawing.Point(12, 43);
+ this.groupBox.Name = "groupBox";
+ this.groupBox.Size = new System.Drawing.Size(756, 323);
+ this.groupBox.TabIndex = 4;
+ this.groupBox.TabStop = false;
+ this.groupBox.Text = "Остановки";
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(620, 237);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(112, 34);
+ this.buttonUpdate.TabIndex = 18;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click);
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(620, 181);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(112, 34);
+ this.buttonDelete.TabIndex = 17;
+ this.buttonDelete.Text = "Удалить";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
+ //
+ // buttonRefresh
+ //
+ this.buttonRefresh.Location = new System.Drawing.Point(620, 123);
+ this.buttonRefresh.Name = "buttonRefresh";
+ this.buttonRefresh.Size = new System.Drawing.Size(112, 34);
+ this.buttonRefresh.TabIndex = 16;
+ this.buttonRefresh.Text = "Изменить";
+ this.buttonRefresh.UseVisualStyleBackColor = true;
+ this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(620, 63);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(112, 34);
+ this.buttonAdd.TabIndex = 15;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Window;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(6, 30);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 62;
+ this.dataGridView.RowTemplate.Height = 33;
+ this.dataGridView.Size = new System.Drawing.Size(590, 287);
+ this.dataGridView.TabIndex = 0;
+ this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.ID,
+ this.ColumnStop,
+ this.ColumnNumber});
+ //
+ // ID
+ //
+ this.ID.HeaderText = "StopId";
+ this.ID.MinimumWidth = 8;
+ this.ID.Name = "StopId";
+ this.ID.Visible = false;
+ this.ID.Width = 150;
+ //
+ // ColumnStop
+ //
+ this.ColumnStop.HeaderText = "Stop";
+ this.ColumnStop.MinimumWidth = 8;
+ this.ColumnStop.Name = "ColumnStop";
+ this.ColumnStop.Width = 150;
+ //
+ // ColumnNumber
+ //
+ this.ColumnNumber.HeaderText = "Number";
+ this.ColumnNumber.MinimumWidth = 8;
+ this.ColumnNumber.Name = "ColumnNumber";
+ this.ColumnNumber.Width = 150;
+ //
// FormRoute
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(453, 109);
+ this.ClientSize = new System.Drawing.Size(780, 418);
+ this.Controls.Add(this.groupBox);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelName);
- this.Name = "FormRoute";
this.Text = "Маршрут";
this.Load += new System.EventHandler(this.FormRoute_Load);
+ this.groupBox.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -93,5 +197,15 @@
private TextBox textBoxName;
private Button buttonCancel;
private Button buttonSave;
+ private GroupBox groupBox;
+ private DataGridView dataGridView;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonRefresh;
+ private Button buttonAdd;
+ private DataGridViewTextBoxColumn ID;
+ private DataGridViewTextBoxColumn ColumnStop;
+ private DataGridViewTextBoxColumn ColumnNumber;
+
}
}
\ No newline at end of file
diff --git a/RouteGuide/RouteGuide/FormRoute.cs b/RouteGuide/RouteGuide/FormRoute.cs
index 6c0f983..c59ae51 100644
--- a/RouteGuide/RouteGuide/FormRoute.cs
+++ b/RouteGuide/RouteGuide/FormRoute.cs
@@ -1,6 +1,8 @@
-using RouteGuideContracts.BindingModels;
+using Microsoft.Extensions.Logging;
+using RouteGuideContracts.BindingModels;
using RouteGuideContracts.BusinessLogicContracts;
using RouteGuideContracts.SearchModels;
+using RouteGuideDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -10,20 +12,23 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace RouteGuide
{
public partial class FormRoute : Form
{
+ private readonly ILogger _logger;
private readonly IRouteLogic _logic;
private int? _id;
+ private Dictionary _RouteStops;
public int Id { set { _id = value; } }
-
- public FormRoute(IRouteLogic logic)
+ public FormRoute(ILogger logger, IRouteLogic logic)
{
InitializeComponent();
+ _logger = logger;
_logic = logic;
- InitializeComponent();
+ _RouteStops = new Dictionary();
}
private void FormRoute_Load(object sender, EventArgs e)
@@ -39,21 +44,129 @@ namespace RouteGuide
if (view != null)
{
textBoxName.Text = view.Name;
+ _RouteStops = view.RouteStops ?? new Dictionary();
+ LoadData();
+ //foreach (var el in view.StopRoutes.Values)
+ //{
+ // dataGridView.Rows.Add(new object[] {el.Item1.Name, el.Item2});
+ //}
}
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message, "Loading error", MessageBoxButtons.OK,
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
+ private void LoadData()
+ {
+ try
+ {
+ if (_RouteStops != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var pc in _RouteStops)
+ {
+ dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Name, pc.Value.Item2 });
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormRouteStop));
+ if (service is FormRouteStop form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.StopModel == null)
+ {
+ return;
+ }
+ if (_RouteStops.ContainsKey(form.Id))
+ {
+ _RouteStops[form.Id] = (form.StopModel, form.Number);
+ }
+ else
+ {
+ _RouteStops.Add(form.Id, (form.StopModel, form.Number));
+ }
+ LoadData();
+ }
+ }
+
+ }
+
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormRouteStop));
+ if (service is FormRouteStop form)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Number = _RouteStops[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.StopModel == null)
+ {
+ return;
+ }
+ _RouteStops[form.Id] = (form.StopModel, form.Number);
+ LoadData();
+ }
+ }
+ }
+
+ }
+
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ try
+ {
+ _RouteStops?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ LoadData();
+ }
+ }
+
+ }
+
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
- MessageBox.Show("Error", "Name cant be empty",
+ MessageBox.Show("Fill in Name", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (_RouteStops == null || _RouteStops.Count == 0)
+ {
+ MessageBox.Show("Fill in Stops", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
@@ -63,22 +176,25 @@ namespace RouteGuide
{
Id = _id ?? 0,
Name = textBoxName.Text,
+ RouteStops = _RouteStops
};
var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model);
if (!operationResult)
{
- throw new Exception("Error with save.");
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
- MessageBox.Show("Route was saved", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK,
- MessageBoxIcon.Error);
+ _logger.LogError(ex, "Ошибка сохранения драгоценности");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
+
}
private void ButtonCancel_Click(object sender, EventArgs e)
diff --git a/RouteGuide/RouteGuide/FormRoutes.cs b/RouteGuide/RouteGuide/FormRoutes.cs
index 37dabba..22b0075 100644
--- a/RouteGuide/RouteGuide/FormRoutes.cs
+++ b/RouteGuide/RouteGuide/FormRoutes.cs
@@ -18,7 +18,7 @@ namespace RouteGuide
private readonly ILogger _logger;
private readonly IRouteLogic _logic;
- public FormRoutes(ILogger logger, IRouteLogic logic)
+ public FormRoutes(ILogger logger, IRouteLogic logic)
{
InitializeComponent();
_logger = logger;
@@ -53,8 +53,8 @@ namespace RouteGuide
private void ButtonAdd_Click(object sender, EventArgs e)
{
- var service = Program.ServiceProvider?.GetService(typeof(FormStop));
- if (service is FormStop form)
+ var service = Program.ServiceProvider?.GetService(typeof(FormRoute));
+ if (service is FormRoute form)
{
if (form.ShowDialog() == DialogResult.OK)
{
@@ -105,8 +105,8 @@ namespace RouteGuide
if (dataGridView.SelectedRows.Count == 1)
{
var service =
- Program.ServiceProvider?.GetService(typeof(FormStop));
- if (service is FormStop form)
+ Program.ServiceProvider?.GetService(typeof(FormRoute));
+ if (service is FormRoute form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
diff --git a/RouteGuide/RouteGuide/FormStop.cs b/RouteGuide/RouteGuide/FormStop.cs
index 628282f..2ab7a96 100644
--- a/RouteGuide/RouteGuide/FormStop.cs
+++ b/RouteGuide/RouteGuide/FormStop.cs
@@ -21,7 +21,6 @@ namespace RouteGuide
public FormStop(IStopLogic logic)
{
- InitializeComponent();
_logic = logic;
InitializeComponent();
}
diff --git a/RouteGuide/RouteGuide/FormTransport.Designer.cs b/RouteGuide/RouteGuide/FormTransport.Designer.cs
index 526fd1a..ace821c 100644
--- a/RouteGuide/RouteGuide/FormTransport.Designer.cs
+++ b/RouteGuide/RouteGuide/FormTransport.Designer.cs
@@ -96,6 +96,7 @@
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
@@ -105,6 +106,7 @@
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormTransport
//
@@ -121,6 +123,8 @@
this.Controls.Add(this.labelDriverName);
this.Name = "FormTransport";
this.Text = "Транспорт";
+ this.Load += new System.EventHandler(this.FormTransport_Load);
+ this.Click += new System.EventHandler(this.FormTransport_Load);
this.ResumeLayout(false);
this.PerformLayout();
diff --git a/RouteGuide/RouteGuide/FormTransport.cs b/RouteGuide/RouteGuide/FormTransport.cs
index 628536c..b502314 100644
--- a/RouteGuide/RouteGuide/FormTransport.cs
+++ b/RouteGuide/RouteGuide/FormTransport.cs
@@ -25,6 +25,8 @@ namespace RouteGuide
private List? _listR;
private List? _listTT;
+ private int? _id;
+ public int Id { set { _id = value; } }
public FormTransport(ILogger logger, ITransportLogic logicT, IRouteLogic logicR, ITransportTypeLogic logicTT)
{
@@ -125,6 +127,7 @@ namespace RouteGuide
{
TransportTypeId = Convert.ToInt32(comboBoxTransportType.SelectedIndex) + 1,
RouteId = Convert.ToInt32(comboBoxRoute.SelectedIndex) + 1,
+ DriverName = textBoxDriverName.Text
});
if (!operationResult)
{
diff --git a/RouteGuide/RouteGuide/FormTransports.Designer.cs b/RouteGuide/RouteGuide/FormTransports.Designer.cs
index 318374e..667937d 100644
--- a/RouteGuide/RouteGuide/FormTransports.Designer.cs
+++ b/RouteGuide/RouteGuide/FormTransports.Designer.cs
@@ -44,6 +44,7 @@
this.buttonUpdate.TabIndex = 9;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click);
//
// buttonDelete
//
@@ -53,6 +54,7 @@
this.buttonDelete.TabIndex = 8;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
//
// buttonRefresh
//
@@ -62,6 +64,7 @@
this.buttonRefresh.TabIndex = 7;
this.buttonRefresh.Text = "Изменить";
this.buttonRefresh.UseVisualStyleBackColor = true;
+ this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click);
//
// buttonAdd
//
@@ -71,6 +74,7 @@
this.buttonAdd.TabIndex = 6;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// dataGridView
//
@@ -95,6 +99,7 @@
this.Controls.Add(this.dataGridView);
this.Name = "FormTransports";
this.Text = "Транспортные средства";
+ this.Load += new System.EventHandler(this.FormTransports_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
diff --git a/RouteGuide/RouteGuide/FormTransports.cs b/RouteGuide/RouteGuide/FormTransports.cs
index fa06088..fa85eec 100644
--- a/RouteGuide/RouteGuide/FormTransports.cs
+++ b/RouteGuide/RouteGuide/FormTransports.cs
@@ -1,4 +1,7 @@
-using System;
+using Microsoft.Extensions.Logging;
+using RouteGuideContracts.BindingModels;
+using RouteGuideContracts.BusinessLogicContracts;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -12,9 +15,113 @@ namespace RouteGuide
{
public partial class FormTransports : Form
{
- public FormTransports()
+ private readonly ILogger _logger;
+ private readonly ITransportLogic _logic;
+
+ public FormTransports(ILogger logger, ITransportLogic logic)
{
InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormTransports_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["TransportTypeId"].Visible = false;
+ dataGridView.Columns["TransportTypeName"].AutoSizeMode =
+ DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["DriverName"].AutoSizeMode =
+ DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["RouteId"].AutoSizeMode =
+ DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["RouteName"].AutoSizeMode =
+ DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation("Загрузка компонентов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки компонентов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormTransport));
+ if (service is FormTransport form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление компонента");
+ try
+ {
+ if (!_logic.Delete(new TransportBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления компонента");
+ MessageBox.Show(ex.Message, "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ }
+
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service =
+ Program.ServiceProvider?.GetService(typeof(FormTransport));
+ if (service is FormTransport form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
}
}
}
diff --git a/RouteGuide/RouteGuide/RouteGuide.csproj b/RouteGuide/RouteGuide/RouteGuide.csproj
index 8a0c0bf..df31f99 100644
--- a/RouteGuide/RouteGuide/RouteGuide.csproj
+++ b/RouteGuide/RouteGuide/RouteGuide.csproj
@@ -9,6 +9,10 @@
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/RouteGuide/RouteGuideDatabaseImplement/Migrations/20230518162402_Initial.Designer.cs b/RouteGuide/RouteGuideDatabaseImplement/Migrations/20230518162402_Initial.Designer.cs
new file mode 100644
index 0000000..434b308
--- /dev/null
+++ b/RouteGuide/RouteGuideDatabaseImplement/Migrations/20230518162402_Initial.Designer.cs
@@ -0,0 +1,177 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+using RouteGuideDatabaseImplements;
+
+#nullable disable
+
+namespace RouteGuideDatabaseImplements.Migrations
+{
+ [DbContext(typeof(RouteGuideDatabase))]
+ [Migration("20230518162402_Initial")]
+ partial class Initial
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.5")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Route", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Routes");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.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("RoutesStops");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Stop", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Stops");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Transport", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("DriverName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("RouteId")
+ .HasColumnType("integer");
+
+ b.Property("TransportTypeId")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("TransportTypeId");
+
+ b.ToTable("Transports");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.TransportType", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Price")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.ToTable("TransportTypes");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.RouteStop", b =>
+ {
+ b.HasOne("RouteGuideDatabaseImplements.Models.Route", "Route")
+ .WithMany("Stops")
+ .HasForeignKey("RouteId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("RouteGuideDatabaseImplements.Models.Stop", "Stop")
+ .WithMany("RoutesStops")
+ .HasForeignKey("StopId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Route");
+
+ b.Navigation("Stop");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Transport", b =>
+ {
+ b.HasOne("RouteGuideDatabaseImplements.Models.TransportType", null)
+ .WithMany("Transports")
+ .HasForeignKey("TransportTypeId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Route", b =>
+ {
+ b.Navigation("Stops");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Stop", b =>
+ {
+ b.Navigation("RoutesStops");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.TransportType", b =>
+ {
+ b.Navigation("Transports");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/RouteGuide/RouteGuideDatabaseImplement/Migrations/20230518162402_Initial.cs b/RouteGuide/RouteGuideDatabaseImplement/Migrations/20230518162402_Initial.cs
new file mode 100644
index 0000000..ef6a200
--- /dev/null
+++ b/RouteGuide/RouteGuideDatabaseImplement/Migrations/20230518162402_Initial.cs
@@ -0,0 +1,137 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace RouteGuideDatabaseImplements.Migrations
+{
+ ///
+ public partial class Initial : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ 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)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Routes", 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)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Stops", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "TransportTypes",
+ columns: table => new
+ {
+ Id = table.Column(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ Name = table.Column(type: "text", nullable: false),
+ Price = table.Column(type: "double precision", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_TransportTypes", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "RoutesStops",
+ columns: table => new
+ {
+ Id = table.Column(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ StopId = table.Column(type: "integer", nullable: false),
+ RouteId = table.Column(type: "integer", nullable: false),
+ Number = table.Column(type: "integer", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_RoutesStops", x => x.Id);
+ table.ForeignKey(
+ name: "FK_RoutesStops_Routes_RouteId",
+ column: x => x.RouteId,
+ principalTable: "Routes",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_RoutesStops_Stops_StopId",
+ column: x => x.StopId,
+ principalTable: "Stops",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Transports",
+ columns: table => new
+ {
+ Id = table.Column(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ DriverName = table.Column(type: "text", nullable: false),
+ RouteId = table.Column(type: "integer", nullable: false),
+ TransportTypeId = table.Column(type: "integer", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Transports", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Transports_TransportTypes_TransportTypeId",
+ column: x => x.TransportTypeId,
+ principalTable: "TransportTypes",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_RoutesStops_RouteId",
+ table: "RoutesStops",
+ column: "RouteId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_RoutesStops_StopId",
+ table: "RoutesStops",
+ column: "StopId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Transports_TransportTypeId",
+ table: "Transports",
+ column: "TransportTypeId");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "RoutesStops");
+
+ migrationBuilder.DropTable(
+ name: "Transports");
+
+ migrationBuilder.DropTable(
+ name: "Routes");
+
+ migrationBuilder.DropTable(
+ name: "Stops");
+
+ migrationBuilder.DropTable(
+ name: "TransportTypes");
+ }
+ }
+}
diff --git a/RouteGuide/RouteGuideDatabaseImplement/Migrations/RouteGuideDatabaseModelSnapshot.cs b/RouteGuide/RouteGuideDatabaseImplement/Migrations/RouteGuideDatabaseModelSnapshot.cs
new file mode 100644
index 0000000..25e3362
--- /dev/null
+++ b/RouteGuide/RouteGuideDatabaseImplement/Migrations/RouteGuideDatabaseModelSnapshot.cs
@@ -0,0 +1,174 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+using RouteGuideDatabaseImplements;
+
+#nullable disable
+
+namespace RouteGuideDatabaseImplements.Migrations
+{
+ [DbContext(typeof(RouteGuideDatabase))]
+ partial class RouteGuideDatabaseModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.5")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Route", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Routes");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.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("RoutesStops");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Stop", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Stops");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Transport", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("DriverName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("RouteId")
+ .HasColumnType("integer");
+
+ b.Property("TransportTypeId")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("TransportTypeId");
+
+ b.ToTable("Transports");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.TransportType", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Price")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.ToTable("TransportTypes");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.RouteStop", b =>
+ {
+ b.HasOne("RouteGuideDatabaseImplements.Models.Route", "Route")
+ .WithMany("Stops")
+ .HasForeignKey("RouteId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("RouteGuideDatabaseImplements.Models.Stop", "Stop")
+ .WithMany("RoutesStops")
+ .HasForeignKey("StopId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Route");
+
+ b.Navigation("Stop");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Transport", b =>
+ {
+ b.HasOne("RouteGuideDatabaseImplements.Models.TransportType", null)
+ .WithMany("Transports")
+ .HasForeignKey("TransportTypeId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Route", b =>
+ {
+ b.Navigation("Stops");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Stop", b =>
+ {
+ b.Navigation("RoutesStops");
+ });
+
+ modelBuilder.Entity("RouteGuideDatabaseImplements.Models.TransportType", b =>
+ {
+ b.Navigation("Transports");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/RouteGuide/RouteGuideDatabaseImplement/RouteGuideDatabaseImplements.csproj b/RouteGuide/RouteGuideDatabaseImplement/RouteGuideDatabaseImplements.csproj
index 633724b..e6a4b2e 100644
--- a/RouteGuide/RouteGuideDatabaseImplement/RouteGuideDatabaseImplements.csproj
+++ b/RouteGuide/RouteGuideDatabaseImplement/RouteGuideDatabaseImplements.csproj
@@ -8,6 +8,10 @@
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+