Изменения в формах, теперь все работает. + миграция.
This commit is contained in:
parent
22919a363a
commit
269eeaea99
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<add key="connectToDb" value="Host=192.168.56.104;Port=5432;Database=RouteGuide;Username=postgres;Password=password"/>
|
<add key="connectToDb" value="Host=192.168.56.104;Port=5432;Database=TransportRoutes;Username=postgres;Password=password"/>
|
||||||
</appSettings>
|
</appSettings>
|
||||||
</configuration>
|
</configuration>
|
122
RouteGuide/RouteGuide/FormRoute.Designer.cs
generated
122
RouteGuide/RouteGuide/FormRoute.Designer.cs
generated
@ -32,6 +32,17 @@
|
|||||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||||
this.buttonCancel = new System.Windows.Forms.Button();
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
this.buttonSave = 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();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// labelName
|
// labelName
|
||||||
@ -52,7 +63,7 @@
|
|||||||
//
|
//
|
||||||
// buttonCancel
|
// 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.Name = "buttonCancel";
|
||||||
this.buttonCancel.Size = new System.Drawing.Size(112, 34);
|
this.buttonCancel.Size = new System.Drawing.Size(112, 34);
|
||||||
this.buttonCancel.TabIndex = 2;
|
this.buttonCancel.TabIndex = 2;
|
||||||
@ -62,7 +73,7 @@
|
|||||||
//
|
//
|
||||||
// buttonSave
|
// 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.Name = "buttonSave";
|
||||||
this.buttonSave.Size = new System.Drawing.Size(112, 34);
|
this.buttonSave.Size = new System.Drawing.Size(112, 34);
|
||||||
this.buttonSave.TabIndex = 3;
|
this.buttonSave.TabIndex = 3;
|
||||||
@ -70,18 +81,111 @@
|
|||||||
this.buttonSave.UseVisualStyleBackColor = true;
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
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
|
// FormRoute
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
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.buttonSave);
|
||||||
this.Controls.Add(this.buttonCancel);
|
this.Controls.Add(this.buttonCancel);
|
||||||
this.Controls.Add(this.textBoxName);
|
this.Controls.Add(this.textBoxName);
|
||||||
this.Controls.Add(this.labelName);
|
this.Controls.Add(this.labelName);
|
||||||
this.Name = "FormRoute";
|
|
||||||
this.Text = "Маршрут";
|
this.Text = "Маршрут";
|
||||||
this.Load += new System.EventHandler(this.FormRoute_Load);
|
this.Load += new System.EventHandler(this.FormRoute_Load);
|
||||||
|
this.groupBox.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
@ -93,5 +197,15 @@
|
|||||||
private TextBox textBoxName;
|
private TextBox textBoxName;
|
||||||
private Button buttonCancel;
|
private Button buttonCancel;
|
||||||
private Button buttonSave;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,8 @@
|
|||||||
using RouteGuideContracts.BindingModels;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using RouteGuideContracts.BindingModels;
|
||||||
using RouteGuideContracts.BusinessLogicContracts;
|
using RouteGuideContracts.BusinessLogicContracts;
|
||||||
using RouteGuideContracts.SearchModels;
|
using RouteGuideContracts.SearchModels;
|
||||||
|
using RouteGuideDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
@ -10,20 +12,23 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
|
|
||||||
namespace RouteGuide
|
namespace RouteGuide
|
||||||
{
|
{
|
||||||
public partial class FormRoute : Form
|
public partial class FormRoute : Form
|
||||||
{
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
private readonly IRouteLogic _logic;
|
private readonly IRouteLogic _logic;
|
||||||
private int? _id;
|
private int? _id;
|
||||||
|
private Dictionary<int, (IStopModel, int)> _RouteStops;
|
||||||
public int Id { set { _id = value; } }
|
public int Id { set { _id = value; } }
|
||||||
|
public FormRoute(ILogger<FormRoute> logger, IRouteLogic logic)
|
||||||
public FormRoute(IRouteLogic logic)
|
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
InitializeComponent();
|
_RouteStops = new Dictionary<int, (IStopModel, int)>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormRoute_Load(object sender, EventArgs e)
|
private void FormRoute_Load(object sender, EventArgs e)
|
||||||
@ -39,21 +44,129 @@ namespace RouteGuide
|
|||||||
if (view != null)
|
if (view != null)
|
||||||
{
|
{
|
||||||
textBoxName.Text = view.Name;
|
textBoxName.Text = view.Name;
|
||||||
|
_RouteStops = view.RouteStops ?? new Dictionary<int, (IStopModel, int)>();
|
||||||
|
LoadData();
|
||||||
|
//foreach (var el in view.StopRoutes.Values)
|
||||||
|
//{
|
||||||
|
// dataGridView.Rows.Add(new object[] {el.Item1.Name, el.Item2});
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Loading error", MessageBoxButtons.OK,
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
MessageBoxIcon.Error);
|
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)
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
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);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -63,22 +176,25 @@ namespace RouteGuide
|
|||||||
{
|
{
|
||||||
Id = _id ?? 0,
|
Id = _id ?? 0,
|
||||||
Name = textBoxName.Text,
|
Name = textBoxName.Text,
|
||||||
|
RouteStops = _RouteStops
|
||||||
};
|
};
|
||||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||||
_logic.Create(model);
|
_logic.Create(model);
|
||||||
if (!operationResult)
|
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;
|
DialogResult = DialogResult.OK;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK,
|
_logger.LogError(ex, "Ошибка сохранения драгоценности");
|
||||||
MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
@ -18,7 +18,7 @@ namespace RouteGuide
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IRouteLogic _logic;
|
private readonly IRouteLogic _logic;
|
||||||
|
|
||||||
public FormRoutes(ILogger<FormStops> logger, IRouteLogic logic)
|
public FormRoutes(ILogger<FormRoutes> logger, IRouteLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@ -53,8 +53,8 @@ namespace RouteGuide
|
|||||||
|
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormStop));
|
var service = Program.ServiceProvider?.GetService(typeof(FormRoute));
|
||||||
if (service is FormStop form)
|
if (service is FormRoute form)
|
||||||
{
|
{
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
@ -105,8 +105,8 @@ namespace RouteGuide
|
|||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
var service =
|
var service =
|
||||||
Program.ServiceProvider?.GetService(typeof(FormStop));
|
Program.ServiceProvider?.GetService(typeof(FormRoute));
|
||||||
if (service is FormStop form)
|
if (service is FormRoute form)
|
||||||
{
|
{
|
||||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
@ -21,7 +21,6 @@ namespace RouteGuide
|
|||||||
|
|
||||||
public FormStop(IStopLogic logic)
|
public FormStop(IStopLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
4
RouteGuide/RouteGuide/FormTransport.Designer.cs
generated
4
RouteGuide/RouteGuide/FormTransport.Designer.cs
generated
@ -96,6 +96,7 @@
|
|||||||
this.buttonSave.TabIndex = 6;
|
this.buttonSave.TabIndex = 6;
|
||||||
this.buttonSave.Text = "Сохранить";
|
this.buttonSave.Text = "Сохранить";
|
||||||
this.buttonSave.UseVisualStyleBackColor = true;
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
@ -105,6 +106,7 @@
|
|||||||
this.buttonCancel.TabIndex = 7;
|
this.buttonCancel.TabIndex = 7;
|
||||||
this.buttonCancel.Text = "Отмена";
|
this.buttonCancel.Text = "Отмена";
|
||||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
//
|
//
|
||||||
// FormTransport
|
// FormTransport
|
||||||
//
|
//
|
||||||
@ -121,6 +123,8 @@
|
|||||||
this.Controls.Add(this.labelDriverName);
|
this.Controls.Add(this.labelDriverName);
|
||||||
this.Name = "FormTransport";
|
this.Name = "FormTransport";
|
||||||
this.Text = "Транспорт";
|
this.Text = "Транспорт";
|
||||||
|
this.Load += new System.EventHandler(this.FormTransport_Load);
|
||||||
|
this.Click += new System.EventHandler(this.FormTransport_Load);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ namespace RouteGuide
|
|||||||
private List<RouteViewModel>? _listR;
|
private List<RouteViewModel>? _listR;
|
||||||
private List<TransportTypeViewModel>? _listTT;
|
private List<TransportTypeViewModel>? _listTT;
|
||||||
|
|
||||||
|
private int? _id;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
|
||||||
public FormTransport(ILogger<FormTransport> logger, ITransportLogic logicT, IRouteLogic logicR, ITransportTypeLogic logicTT)
|
public FormTransport(ILogger<FormTransport> logger, ITransportLogic logicT, IRouteLogic logicR, ITransportTypeLogic logicTT)
|
||||||
{
|
{
|
||||||
@ -125,6 +127,7 @@ namespace RouteGuide
|
|||||||
{
|
{
|
||||||
TransportTypeId = Convert.ToInt32(comboBoxTransportType.SelectedIndex) + 1,
|
TransportTypeId = Convert.ToInt32(comboBoxTransportType.SelectedIndex) + 1,
|
||||||
RouteId = Convert.ToInt32(comboBoxRoute.SelectedIndex) + 1,
|
RouteId = Convert.ToInt32(comboBoxRoute.SelectedIndex) + 1,
|
||||||
|
DriverName = textBoxDriverName.Text
|
||||||
});
|
});
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
|
5
RouteGuide/RouteGuide/FormTransports.Designer.cs
generated
5
RouteGuide/RouteGuide/FormTransports.Designer.cs
generated
@ -44,6 +44,7 @@
|
|||||||
this.buttonUpdate.TabIndex = 9;
|
this.buttonUpdate.TabIndex = 9;
|
||||||
this.buttonUpdate.Text = "Обновить";
|
this.buttonUpdate.Text = "Обновить";
|
||||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click);
|
||||||
//
|
//
|
||||||
// buttonDelete
|
// buttonDelete
|
||||||
//
|
//
|
||||||
@ -53,6 +54,7 @@
|
|||||||
this.buttonDelete.TabIndex = 8;
|
this.buttonDelete.TabIndex = 8;
|
||||||
this.buttonDelete.Text = "Удалить";
|
this.buttonDelete.Text = "Удалить";
|
||||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
|
||||||
//
|
//
|
||||||
// buttonRefresh
|
// buttonRefresh
|
||||||
//
|
//
|
||||||
@ -62,6 +64,7 @@
|
|||||||
this.buttonRefresh.TabIndex = 7;
|
this.buttonRefresh.TabIndex = 7;
|
||||||
this.buttonRefresh.Text = "Изменить";
|
this.buttonRefresh.Text = "Изменить";
|
||||||
this.buttonRefresh.UseVisualStyleBackColor = true;
|
this.buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click);
|
||||||
//
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
@ -71,6 +74,7 @@
|
|||||||
this.buttonAdd.TabIndex = 6;
|
this.buttonAdd.TabIndex = 6;
|
||||||
this.buttonAdd.Text = "Добавить";
|
this.buttonAdd.Text = "Добавить";
|
||||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
//
|
//
|
||||||
// dataGridView
|
// dataGridView
|
||||||
//
|
//
|
||||||
@ -95,6 +99,7 @@
|
|||||||
this.Controls.Add(this.dataGridView);
|
this.Controls.Add(this.dataGridView);
|
||||||
this.Name = "FormTransports";
|
this.Name = "FormTransports";
|
||||||
this.Text = "Транспортные средства";
|
this.Text = "Транспортные средства";
|
||||||
|
this.Load += new System.EventHandler(this.FormTransports_Load);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
using System;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using RouteGuideContracts.BindingModels;
|
||||||
|
using RouteGuideContracts.BusinessLogicContracts;
|
||||||
|
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,113 @@ namespace RouteGuide
|
|||||||
{
|
{
|
||||||
public partial class FormTransports : Form
|
public partial class FormTransports : Form
|
||||||
{
|
{
|
||||||
public FormTransports()
|
private readonly ILogger _logger;
|
||||||
|
private readonly ITransportLogic _logic;
|
||||||
|
|
||||||
|
public FormTransports(ILogger<FormTransports> logger, ITransportLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
|
||||||
|
177
RouteGuide/RouteGuideDatabaseImplement/Migrations/20230518162402_Initial.Designer.cs
generated
Normal file
177
RouteGuide/RouteGuideDatabaseImplement/Migrations/20230518162402_Initial.Designer.cs
generated
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
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<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Routes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RouteGuideDatabaseImplements.Models.RouteStop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Number")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("RouteId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("StopId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RouteId");
|
||||||
|
|
||||||
|
b.HasIndex("StopId");
|
||||||
|
|
||||||
|
b.ToTable("RoutesStops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Stop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Stops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Transport", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("DriverName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("RouteId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("TransportTypeId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("TransportTypeId");
|
||||||
|
|
||||||
|
b.ToTable("Transports");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RouteGuideDatabaseImplements.Models.TransportType", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<double>("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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,137 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace RouteGuideDatabaseImplements.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Initial : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Routes",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Routes", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Stops",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Stops", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "TransportTypes",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Price = table.Column<double>(type: "double precision", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_TransportTypes", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "RoutesStops",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
StopId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
RouteId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Number = table.Column<int>(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<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
DriverName = table.Column<string>(type: "text", nullable: false),
|
||||||
|
RouteId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
TransportTypeId = table.Column<int>(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");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,174 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
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<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Routes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RouteGuideDatabaseImplements.Models.RouteStop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Number")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("RouteId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("StopId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RouteId");
|
||||||
|
|
||||||
|
b.HasIndex("StopId");
|
||||||
|
|
||||||
|
b.ToTable("RoutesStops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Stop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Stops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RouteGuideDatabaseImplements.Models.Transport", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("DriverName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("RouteId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("TransportTypeId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("TransportTypeId");
|
||||||
|
|
||||||
|
b.ToTable("Transports");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RouteGuideDatabaseImplements.Models.TransportType", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<double>("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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,10 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
|
||||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user