Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
8f3e0c5116 | |||
495dcae781 | |||
75a6b87680 | |||
2d2cd016c7 | |||
fd475481ef | |||
3b98ee933a | |||
3609582418 | |||
caaa5d7f0f | |||
3aa11ac2dc | |||
f709d8cd0e | |||
ea1841f8bb | |||
064dac213c | |||
8b6767e489 | |||
0e46bc8b1f | |||
6aa28811fd | |||
db07407ffd | |||
585132da4a | |||
00f049749e | |||
a9a26d56c4 | |||
e53f659b02 | |||
9d6097f6d1 | |||
33d66e0d1a | |||
4e74949300 | |||
abf22b1c85 |
17
BusinessLogic/BusinessLogic.csproj
Normal file
17
BusinessLogic/BusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TransportGuideContracts\TransportGuideContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
129
BusinessLogic/BusinessLogic/RouteLogic.cs
Normal file
129
BusinessLogic/BusinessLogic/RouteLogic.cs
Normal file
@ -0,0 +1,129 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.StoragesContracts;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
|
||||
namespace BusinessLogic.BusinessLogic
|
||||
{
|
||||
public class RouteLogic : IRouteLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRouteStorage _routeStorage;
|
||||
|
||||
public RouteLogic(ILogger<RouteLogic> logger, IRouteStorage routeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_routeStorage = routeStorage;
|
||||
}
|
||||
|
||||
public bool Create(RouteBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_routeStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(RouteBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_routeStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public RouteViewModel? ReadElement(RouteSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. RouteName:{RouteName}.Id:{ Id}", model.Name, model.Id);
|
||||
var element = _routeStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<RouteViewModel>? ReadList(RouteSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. RouteName:{RoutetName}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _routeStorage.GetFullList() : _routeStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public string TestInsertList(int num)
|
||||
{
|
||||
return _routeStorage.TestInsertList(num);
|
||||
}
|
||||
|
||||
public string TestReadList(int num)
|
||||
{
|
||||
return _routeStorage.TestReadList(num);
|
||||
}
|
||||
|
||||
public bool Update(RouteBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_routeStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(RouteBindingModel model, bool withParams =
|
||||
true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия",nameof(model.Name));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.IP))
|
||||
{
|
||||
throw new ArgumentNullException("No IP", nameof(model.IP));
|
||||
}
|
||||
_logger.LogInformation("Route. Name:{Name}. IP:{ IP}. Id: { Id}", model.Name, model.IP, model.Id);
|
||||
var element = _routeStorage.GetElement(new RouteSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Route с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
116
BusinessLogic/BusinessLogic/StopLogic.cs
Normal file
116
BusinessLogic/BusinessLogic/StopLogic.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.StoragesContracts;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
|
||||
namespace BusinessLogic.BusinessLogic
|
||||
{
|
||||
public class StopLogic : IStopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStopStorage _stopStorage;
|
||||
|
||||
public StopLogic(ILogger<StopLogic> logger, IStopStorage stopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_stopStorage = stopStorage;
|
||||
}
|
||||
|
||||
public bool Create(StopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_stopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(StopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_stopStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public StopViewModel? ReadElement(StopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", model.Name, model.Id);
|
||||
var element = _stopStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<StopViewModel>? ReadList(StopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _stopStorage.GetFullList() : _stopStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(StopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_stopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(StopBindingModel model, bool withParams =
|
||||
true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия", nameof(model.Name));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Stop. Name:{Name}. Id: { Id}", model.Name,model.Id);
|
||||
var element = _stopStorage.GetElement(new StopSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Stop с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
119
BusinessLogic/BusinessLogic/TransportTypeLogic.cs
Normal file
119
BusinessLogic/BusinessLogic/TransportTypeLogic.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.StoragesContracts;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
|
||||
namespace BusinessLogic.BusinessLogic
|
||||
{
|
||||
public class TransportTypeLogic : ITransportTypeLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ITransportTypeStorage _transportTypeStorage;
|
||||
|
||||
public TransportTypeLogic(ILogger<TransportTypeLogic> logger, ITransportTypeStorage transportTypeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_transportTypeStorage = transportTypeStorage;
|
||||
}
|
||||
|
||||
public bool Create(TransportTypeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_transportTypeStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(TransportTypeBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_transportTypeStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public TransportTypeViewModel? ReadElement(TransportTypeSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", model.Name, model.Id);
|
||||
var element = _transportTypeStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<TransportTypeViewModel>? ReadList(TransportTypeSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Name:{Name}.Id:{ Id}", model?.Name, model?.Id);
|
||||
var list = model == null ? _transportTypeStorage.GetFullList() : _transportTypeStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(TransportTypeBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_transportTypeStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(TransportTypeBindingModel model, bool withParams =
|
||||
true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия ",nameof(model.Name));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("TransportType. Name:{Name}. Price:{ Price}. Id: { Id}", model.Name, model.Price, model.Id);
|
||||
var element = _transportTypeStorage.GetElement(new TransportTypeSearchModel
|
||||
{
|
||||
Name = model.Name
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Type с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
README_.md
Normal file
3
README_.md
Normal file
@ -0,0 +1,3 @@
|
||||
# A first-level heading
|
||||
## A second-level heading
|
||||
### A third-level heading
|
6
TransportGuide/App.config
Normal file
6
TransportGuide/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="connectToDb" value="Host=192.168.56.101;Port=5432;Database=TransportSubd;Username=postgres;Password=1502"/>
|
||||
</appSettings>
|
||||
</configuration>
|
106
TransportGuide/FormMain.Designer.cs
generated
Normal file
106
TransportGuide/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,106 @@
|
||||
namespace TransportGuide
|
||||
{
|
||||
partial class FormMain
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.transportTypeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.stopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.routeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.testsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.transportTypeToolStripMenuItem,
|
||||
this.stopToolStripMenuItem,
|
||||
this.routeToolStripMenuItem,
|
||||
this.testsToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(800, 33);
|
||||
this.menuStrip.TabIndex = 0;
|
||||
this.menuStrip.Text = "menuStrip";
|
||||
//
|
||||
// transportTypeToolStripMenuItem
|
||||
//
|
||||
this.transportTypeToolStripMenuItem.Name = "transportTypeToolStripMenuItem";
|
||||
this.transportTypeToolStripMenuItem.Size = new System.Drawing.Size(139, 29);
|
||||
this.transportTypeToolStripMenuItem.Text = "TransportType";
|
||||
this.transportTypeToolStripMenuItem.Click += new System.EventHandler(this.transportTypeToolStripMenuItem_Click);
|
||||
//
|
||||
// stopToolStripMenuItem
|
||||
//
|
||||
this.stopToolStripMenuItem.Name = "stopToolStripMenuItem";
|
||||
this.stopToolStripMenuItem.Size = new System.Drawing.Size(65, 29);
|
||||
this.stopToolStripMenuItem.Text = "Stop";
|
||||
this.stopToolStripMenuItem.Click += new System.EventHandler(this.stopToolStripMenuItem_Click);
|
||||
//
|
||||
// routeToolStripMenuItem
|
||||
//
|
||||
this.routeToolStripMenuItem.Name = "routeToolStripMenuItem";
|
||||
this.routeToolStripMenuItem.Size = new System.Drawing.Size(74, 29);
|
||||
this.routeToolStripMenuItem.Text = "Route";
|
||||
this.routeToolStripMenuItem.Click += new System.EventHandler(this.routeToolStripMenuItem_Click);
|
||||
//
|
||||
// testsToolStripMenuItem
|
||||
//
|
||||
this.testsToolStripMenuItem.Name = "testsToolStripMenuItem";
|
||||
this.testsToolStripMenuItem.Size = new System.Drawing.Size(66, 29);
|
||||
this.testsToolStripMenuItem.Text = "Tests";
|
||||
this.testsToolStripMenuItem.Click += new System.EventHandler(this.testsToolStripMenuItem_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormMain";
|
||||
this.Text = "FormMain";
|
||||
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem transportTypeToolStripMenuItem;
|
||||
private ToolStripMenuItem stopToolStripMenuItem;
|
||||
private ToolStripMenuItem routeToolStripMenuItem;
|
||||
private ToolStripMenuItem testsToolStripMenuItem;
|
||||
}
|
||||
}
|
67
TransportGuide/FormMain.cs
Normal file
67
TransportGuide/FormMain.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace TransportGuide
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
public FormMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void transportTypeToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormTransportTypes));
|
||||
|
||||
if (service is FormTransportTypes form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void stopToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStops));
|
||||
|
||||
if (service is FormStops form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void routeToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormRoutes));
|
||||
|
||||
if (service is FormRoutes form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void testsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormTests));
|
||||
|
||||
if (service is FormTests form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
63
TransportGuide/FormMain.resx
Normal file
63
TransportGuide/FormMain.resx
Normal file
@ -0,0 +1,63 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
255
TransportGuide/FormRoute.Designer.cs
generated
Normal file
255
TransportGuide/FormRoute.Designer.cs
generated
Normal file
@ -0,0 +1,255 @@
|
||||
namespace TransportGuide
|
||||
{
|
||||
partial class FormRoute
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.labelIP = new System.Windows.Forms.Label();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.textBoxIP = new System.Windows.Forms.TextBox();
|
||||
this.groupBoxStop = new System.Windows.Forms.GroupBox();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
this.buttonDelete = new System.Windows.Forms.Button();
|
||||
this.buttonChange = 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.ColumnNomer = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.labelTransportType = new System.Windows.Forms.Label();
|
||||
this.comboBoxTransportType = new System.Windows.Forms.ComboBox();
|
||||
this.groupBoxStop.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(19, 19);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(94, 25);
|
||||
this.labelName.TabIndex = 0;
|
||||
this.labelName.Text = "Название:";
|
||||
//
|
||||
// labelIP
|
||||
//
|
||||
this.labelIP.AutoSize = true;
|
||||
this.labelIP.Location = new System.Drawing.Point(19, 59);
|
||||
this.labelIP.Name = "labelIP";
|
||||
this.labelIP.Size = new System.Drawing.Size(47, 25);
|
||||
this.labelIP.TabIndex = 1;
|
||||
this.labelIP.Text = "ИП: ";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(177, 16);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(340, 31);
|
||||
this.textBoxName.TabIndex = 2;
|
||||
//
|
||||
// textBoxIP
|
||||
//
|
||||
this.textBoxIP.Location = new System.Drawing.Point(177, 56);
|
||||
this.textBoxIP.Name = "textBoxIP";
|
||||
this.textBoxIP.Size = new System.Drawing.Size(150, 31);
|
||||
this.textBoxIP.TabIndex = 3;
|
||||
//
|
||||
// groupBoxStop
|
||||
//
|
||||
this.groupBoxStop.Controls.Add(this.buttonUpdate);
|
||||
this.groupBoxStop.Controls.Add(this.buttonDelete);
|
||||
this.groupBoxStop.Controls.Add(this.buttonChange);
|
||||
this.groupBoxStop.Controls.Add(this.buttonAdd);
|
||||
this.groupBoxStop.Controls.Add(this.dataGridView);
|
||||
this.groupBoxStop.Location = new System.Drawing.Point(19, 157);
|
||||
this.groupBoxStop.Name = "groupBoxStop";
|
||||
this.groupBoxStop.Size = new System.Drawing.Size(763, 330);
|
||||
this.groupBoxStop.TabIndex = 4;
|
||||
this.groupBoxStop.TabStop = false;
|
||||
this.groupBoxStop.Text = "Stops";
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(604, 164);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonUpdate.TabIndex = 4;
|
||||
this.buttonUpdate.Text = "Обновить";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(604, 124);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonDelete.TabIndex = 3;
|
||||
this.buttonDelete.Text = "Удалить";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
|
||||
//
|
||||
// buttonChange
|
||||
//
|
||||
this.buttonChange.Location = new System.Drawing.Point(602, 81);
|
||||
this.buttonChange.Name = "buttonChange";
|
||||
this.buttonChange.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonChange.TabIndex = 2;
|
||||
this.buttonChange.Text = "Изменить";
|
||||
this.buttonChange.UseVisualStyleBackColor = true;
|
||||
this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(602, 35);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.ID,
|
||||
this.ColumnStop,
|
||||
this.ColumnNomer});
|
||||
this.dataGridView.Location = new System.Drawing.Point(27, 35);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 33;
|
||||
this.dataGridView.Size = new System.Drawing.Size(554, 281);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// ID
|
||||
//
|
||||
this.ID.HeaderText = "Column1";
|
||||
this.ID.MinimumWidth = 8;
|
||||
this.ID.Name = "ID";
|
||||
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;
|
||||
//
|
||||
// ColumnNomer
|
||||
//
|
||||
this.ColumnNomer.HeaderText = "Nomer";
|
||||
this.ColumnNomer.MinimumWidth = 8;
|
||||
this.ColumnNomer.Name = "ColumnNomer";
|
||||
this.ColumnNomer.Width = 150;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(436, 501);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonSave.TabIndex = 5;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(567, 503);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonCancel.TabIndex = 6;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// labelTransportType
|
||||
//
|
||||
this.labelTransportType.AutoSize = true;
|
||||
this.labelTransportType.Location = new System.Drawing.Point(19, 103);
|
||||
this.labelTransportType.Name = "labelTransportType";
|
||||
this.labelTransportType.Size = new System.Drawing.Size(141, 25);
|
||||
this.labelTransportType.TabIndex = 7;
|
||||
this.labelTransportType.Text = "Тип Транспорта";
|
||||
//
|
||||
// comboBoxTransportType
|
||||
//
|
||||
this.comboBoxTransportType.FormattingEnabled = true;
|
||||
this.comboBoxTransportType.Location = new System.Drawing.Point(177, 103);
|
||||
this.comboBoxTransportType.Name = "comboBoxTransportType";
|
||||
this.comboBoxTransportType.Size = new System.Drawing.Size(182, 33);
|
||||
this.comboBoxTransportType.TabIndex = 8;
|
||||
//
|
||||
// FormRoute
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 579);
|
||||
this.Controls.Add(this.comboBoxTransportType);
|
||||
this.Controls.Add(this.labelTransportType);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.groupBoxStop);
|
||||
this.Controls.Add(this.textBoxIP);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.labelIP);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Name = "FormRoute";
|
||||
this.Text = "Route";
|
||||
this.Load += new System.EventHandler(this.FormRoute_Load);
|
||||
this.groupBoxStop.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelName;
|
||||
private Label labelIP;
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxIP;
|
||||
private GroupBox groupBoxStop;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonDelete;
|
||||
private Button buttonChange;
|
||||
private Button buttonAdd;
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private DataGridViewTextBoxColumn ID;
|
||||
private DataGridViewTextBoxColumn ColumnStop;
|
||||
private DataGridViewTextBoxColumn ColumnNomer;
|
||||
private Label labelTransportType;
|
||||
private ComboBox comboBoxTransportType;
|
||||
}
|
||||
}
|
244
TransportGuide/FormRoute.cs
Normal file
244
TransportGuide/FormRoute.cs
Normal file
@ -0,0 +1,244 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideDataModels.Models;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
|
||||
namespace TransportGuide
|
||||
{
|
||||
public partial class FormRoute : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRouteLogic _logic;
|
||||
private readonly ITransportTypeLogic _logicTT;
|
||||
private int? _id;
|
||||
private Dictionary<int, (IStopModel, int)> _RouteStops;
|
||||
public int Id { set { _id = value; } }
|
||||
public FormRoute(ILogger<FormRoute> logger, IRouteLogic logic, ITransportTypeLogic logicTT)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_RouteStops = new Dictionary<int, (IStopModel, int)>();
|
||||
_logicTT = logicTT;
|
||||
}
|
||||
|
||||
private void FormRoute_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logicTT.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxTransportType.DisplayMember = "Type";
|
||||
comboBoxTransportType.ValueMember = "Id";
|
||||
comboBoxTransportType.DataSource = list.Select(c => c.Name).ToList();
|
||||
comboBoxTransportType.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new RouteSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.Name;
|
||||
textBoxIP.Text = view.IP.ToString();
|
||||
comboBoxTransportType.Text = view.TransportTypeName;
|
||||
_RouteStops = view.StopRoutes ?? 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)
|
||||
{
|
||||
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(FormStopRoute));
|
||||
if (service is FormStopRoute form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.StopModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_RouteStops.ContainsKey(form.Id))
|
||||
{
|
||||
_RouteStops[form.Id] = (form.StopModel, form.Nomer);
|
||||
}
|
||||
else
|
||||
{
|
||||
_RouteStops.Add(form.Id, (form.StopModel, form.Nomer));
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonChange_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStopRoute));
|
||||
if (service is FormStopRoute form)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||
form.Id = id;
|
||||
form.Nomer = _RouteStops[id].Item2;
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.StopModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_RouteStops[form.Id] = (form.StopModel, form.Nomer);
|
||||
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("Fill in Name", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxIP.Text))
|
||||
{
|
||||
MessageBox.Show("Fill in IP", "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (_RouteStops == null || _RouteStops.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Fill in Stops", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxTransportType.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Fill in Type", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var model = new RouteBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
Name = textBoxName.Text,
|
||||
IP = textBoxIP.Text,
|
||||
TransportTypeId = comboBoxTransportType.SelectedIndex + 1,
|
||||
StopRoutes = _RouteStops
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||
_logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения драгоценности");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
60
TransportGuide/FormRoute.resx
Normal file
60
TransportGuide/FormRoute.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
121
TransportGuide/FormRoutes.Designer.cs
generated
Normal file
121
TransportGuide/FormRoutes.Designer.cs
generated
Normal file
@ -0,0 +1,121 @@
|
||||
namespace TransportGuide
|
||||
{
|
||||
partial class FormRoutes
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.AddButton = new System.Windows.Forms.Button();
|
||||
this.ChangeButton = new System.Windows.Forms.Button();
|
||||
this.DeleteButton = new System.Windows.Forms.Button();
|
||||
this.UpdateButton = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.DataGridView.Location = new System.Drawing.Point(1, 2);
|
||||
this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.DataGridView.Name = "DataGridView";
|
||||
this.DataGridView.RowHeadersWidth = 62;
|
||||
this.DataGridView.RowTemplate.Height = 25;
|
||||
this.DataGridView.Size = new System.Drawing.Size(597, 547);
|
||||
this.DataGridView.TabIndex = 0;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
this.AddButton.Location = new System.Drawing.Point(615, 12);
|
||||
this.AddButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.AddButton.Name = "AddButton";
|
||||
this.AddButton.Size = new System.Drawing.Size(171, 39);
|
||||
this.AddButton.TabIndex = 1;
|
||||
this.AddButton.Text = "Добавить";
|
||||
this.AddButton.UseVisualStyleBackColor = true;
|
||||
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||
//
|
||||
// ChangeButton
|
||||
//
|
||||
this.ChangeButton.Location = new System.Drawing.Point(615, 110);
|
||||
this.ChangeButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.ChangeButton.Name = "ChangeButton";
|
||||
this.ChangeButton.Size = new System.Drawing.Size(171, 39);
|
||||
this.ChangeButton.TabIndex = 2;
|
||||
this.ChangeButton.Text = "Изменить";
|
||||
this.ChangeButton.UseVisualStyleBackColor = true;
|
||||
this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click);
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
this.DeleteButton.Location = new System.Drawing.Point(615, 209);
|
||||
this.DeleteButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.DeleteButton.Name = "DeleteButton";
|
||||
this.DeleteButton.Size = new System.Drawing.Size(171, 39);
|
||||
this.DeleteButton.TabIndex = 3;
|
||||
this.DeleteButton.Text = "Удалить";
|
||||
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||
//
|
||||
// UpdateButton
|
||||
//
|
||||
this.UpdateButton.Location = new System.Drawing.Point(615, 310);
|
||||
this.UpdateButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.UpdateButton.Name = "UpdateButton";
|
||||
this.UpdateButton.Size = new System.Drawing.Size(171, 39);
|
||||
this.UpdateButton.TabIndex = 4;
|
||||
this.UpdateButton.Text = "Обновить";
|
||||
this.UpdateButton.UseVisualStyleBackColor = true;
|
||||
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||
//
|
||||
// FormRoutes
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(805, 563);
|
||||
this.Controls.Add(this.UpdateButton);
|
||||
this.Controls.Add(this.DeleteButton);
|
||||
this.Controls.Add(this.ChangeButton);
|
||||
this.Controls.Add(this.AddButton);
|
||||
this.Controls.Add(this.DataGridView);
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.Name = "FormRoutes";
|
||||
this.Text = "Routes";
|
||||
this.Load += new System.EventHandler(this.FormRoutes_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView DataGridView;
|
||||
private Button AddButton;
|
||||
private Button ChangeButton;
|
||||
private Button DeleteButton;
|
||||
private Button UpdateButton;
|
||||
}
|
||||
}
|
121
TransportGuide/FormRoutes.cs
Normal file
121
TransportGuide/FormRoutes.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace TransportGuide
|
||||
{
|
||||
public partial class FormRoutes : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRouteLogic _logic;
|
||||
|
||||
public FormRoutes(ILogger<FormRoutes> logger, IRouteLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
DataGridView.DataSource = list;
|
||||
DataGridView.Columns["Id"].Visible = false;
|
||||
DataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
DataGridView.Columns["StopRoutes"].Visible = false;
|
||||
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка компонентов");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormRoute));
|
||||
|
||||
if (service is FormRoute form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ChangeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service = 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)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void DeleteButton_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);
|
||||
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new RouteBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void UpdateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
|
||||
private void FormRoutes_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
120
TransportGuide/FormRoutes.resx
Normal file
120
TransportGuide/FormRoutes.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
98
TransportGuide/FormStop.Designer.cs
generated
Normal file
98
TransportGuide/FormStop.Designer.cs
generated
Normal file
@ -0,0 +1,98 @@
|
||||
namespace TransportGuide
|
||||
{
|
||||
partial class FormStop
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(554, 353);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonSave.TabIndex = 0;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(676, 353);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonCancel.TabIndex = 1;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(90, 113);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(94, 25);
|
||||
this.labelName.TabIndex = 2;
|
||||
this.labelName.Text = "Название:";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(212, 113);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(150, 31);
|
||||
this.textBoxName.TabIndex = 4;
|
||||
|
||||
//
|
||||
// FormStop
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Name = "FormStop";
|
||||
this.Text = "Stop";
|
||||
this.Load += new System.EventHandler(this.FormStop_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private Label labelName;
|
||||
private TextBox textBoxName;
|
||||
}
|
||||
}
|
91
TransportGuide/FormStop.cs
Normal file
91
TransportGuide/FormStop.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
|
||||
namespace TransportGuide
|
||||
{
|
||||
public partial class FormStop : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStopLogic _logic;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
public FormStop(ILogger<FormStop> logger, IStopLogic
|
||||
logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
private void FormStop_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new StopSearchModel
|
||||
{
|
||||
Id =
|
||||
_id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.Name;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error with loading", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Name cant be empty", "error",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var model = new StopBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
Name = textBoxName.Text,
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||
_logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error with saving.");
|
||||
}
|
||||
MessageBox.Show("Stop was saved", "Saved",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
120
TransportGuide/FormStop.resx
Normal file
120
TransportGuide/FormStop.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
119
TransportGuide/FormStopRoute.Designer.cs
generated
Normal file
119
TransportGuide/FormStopRoute.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace TransportGuide
|
||||
{
|
||||
partial class FormStopRoute
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.comboBoxStop = new System.Windows.Forms.ComboBox();
|
||||
this.textBoxNomer = new System.Windows.Forms.TextBox();
|
||||
this.labelStop = new System.Windows.Forms.Label();
|
||||
this.labelNomer = new System.Windows.Forms.Label();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// comboBoxStop
|
||||
//
|
||||
this.comboBoxStop.FormattingEnabled = true;
|
||||
this.comboBoxStop.Location = new System.Drawing.Point(148, 10);
|
||||
this.comboBoxStop.Name = "comboBoxStop";
|
||||
this.comboBoxStop.Size = new System.Drawing.Size(182, 33);
|
||||
this.comboBoxStop.TabIndex = 0;
|
||||
//
|
||||
// textBoxNomer
|
||||
//
|
||||
this.textBoxNomer.Location = new System.Drawing.Point(150, 53);
|
||||
this.textBoxNomer.Name = "textBoxNomer";
|
||||
this.textBoxNomer.Size = new System.Drawing.Size(150, 31);
|
||||
this.textBoxNomer.TabIndex = 1;
|
||||
//
|
||||
// labelStop
|
||||
//
|
||||
this.labelStop.AutoSize = true;
|
||||
this.labelStop.Location = new System.Drawing.Point(16, 18);
|
||||
this.labelStop.Name = "labelStop";
|
||||
this.labelStop.Size = new System.Drawing.Size(103, 25);
|
||||
this.labelStop.TabIndex = 2;
|
||||
this.labelStop.Text = "Stop";
|
||||
//
|
||||
// labelNomer
|
||||
//
|
||||
this.labelNomer.AutoSize = true;
|
||||
this.labelNomer.Location = new System.Drawing.Point(16, 57);
|
||||
this.labelNomer.Name = "labelNomer";
|
||||
this.labelNomer.Size = new System.Drawing.Size(112, 25);
|
||||
this.labelNomer.TabIndex = 3;
|
||||
this.labelNomer.Text = "Nomer ";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(75, 99);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonSave.TabIndex = 4;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(206, 99);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonCancel.TabIndex = 5;
|
||||
this.buttonCancel.Text = "Отменить";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// FormJewelStop
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(426, 142);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.labelNomer);
|
||||
this.Controls.Add(this.labelStop);
|
||||
this.Controls.Add(this.textBoxNomer);
|
||||
this.Controls.Add(this.comboBoxStop);
|
||||
this.Name = "FormStopRoute";
|
||||
this.Text = "Stop Route";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxStop;
|
||||
private TextBox textBoxNomer;
|
||||
private Label labelStop;
|
||||
private Label labelNomer;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
91
TransportGuide/FormStopRoute.cs
Normal file
91
TransportGuide/FormStopRoute.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
using TransportGuideDataModels.Models;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace TransportGuide
|
||||
{
|
||||
public partial class FormStopRoute : Form
|
||||
{
|
||||
private readonly List<StopViewModel>? _list;
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(comboBoxStop.SelectedValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
comboBoxStop.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
public IStopModel? StopModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_list == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var elem in _list)
|
||||
{
|
||||
if (elem.Id == Id)
|
||||
{
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public int Nomer
|
||||
{
|
||||
get { return Convert.ToInt32(textBoxNomer.Text); }
|
||||
set { textBoxNomer.Text = value.ToString(); }
|
||||
}
|
||||
|
||||
public FormStopRoute(IStopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_list = logic.ReadList(null);
|
||||
if (_list != null)
|
||||
{
|
||||
comboBoxStop.DisplayMember = "Name";
|
||||
comboBoxStop.ValueMember = "Id";
|
||||
comboBoxStop.DataSource = _list;
|
||||
comboBoxStop.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxNomer.Text))
|
||||
{
|
||||
MessageBox.Show("Fill in Nomer", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxStop.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Choose Stop", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
TransportGuide/FormStopRoute.resx
Normal file
120
TransportGuide/FormStopRoute.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
116
TransportGuide/FormStops.Designer.cs
generated
Normal file
116
TransportGuide/FormStops.Designer.cs
generated
Normal file
@ -0,0 +1,116 @@
|
||||
namespace TransportGuide
|
||||
{
|
||||
partial class FormStops
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonChange = new System.Windows.Forms.Button();
|
||||
this.buttonDelete = new System.Windows.Forms.Button();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.dataGridView.Location = new System.Drawing.Point(0, 0);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 33;
|
||||
this.dataGridView.Size = new System.Drawing.Size(459, 488);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(480, 25);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||
//
|
||||
// buttonChange
|
||||
//
|
||||
this.buttonChange.Location = new System.Drawing.Point(481, 67);
|
||||
this.buttonChange.Name = "buttonChange";
|
||||
this.buttonChange.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonChange.TabIndex = 2;
|
||||
this.buttonChange.Text = "Изменить";
|
||||
this.buttonChange.UseVisualStyleBackColor = true;
|
||||
this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(481, 107);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonDelete.TabIndex = 3;
|
||||
this.buttonDelete.Text = "Удалить";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(481, 147);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonUpdate.TabIndex = 4;
|
||||
this.buttonUpdate.Text = "Обновить";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
|
||||
//
|
||||
// FormComponents
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(614, 488);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.buttonDelete);
|
||||
this.Controls.Add(this.buttonChange);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormStops";
|
||||
this.Text = "Stops";
|
||||
this.Load += new System.EventHandler(this.FormStops_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonAdd;
|
||||
private Button buttonChange;
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
}
|
||||
}
|
118
TransportGuide/FormStops.cs
Normal file
118
TransportGuide/FormStops.cs
Normal file
@ -0,0 +1,118 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace TransportGuide
|
||||
{
|
||||
public partial class FormStops : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStopLogic _logic;
|
||||
public FormStops(ILogger<FormStops> logger, IStopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void FormStops_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["Name"].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(FormStop));
|
||||
if (service is FormStop 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 StopBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonChange_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service =
|
||||
Program.ServiceProvider?.GetService(typeof(FormStop));
|
||||
if (service is FormStop form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
TransportGuide/FormStops.resx
Normal file
120
TransportGuide/FormStops.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
179
TransportGuide/FormTests.Designer.cs
generated
Normal file
179
TransportGuide/FormTests.Designer.cs
generated
Normal file
@ -0,0 +1,179 @@
|
||||
namespace TransportGuide
|
||||
{
|
||||
partial class FormTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonInsertTest = new System.Windows.Forms.Button();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.textBoxInsertTime = new System.Windows.Forms.TextBox();
|
||||
this.buttonReadTest = new System.Windows.Forms.Button();
|
||||
this.textBoxReadTime = new System.Windows.Forms.TextBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.numericUpDownInsert = new System.Windows.Forms.NumericUpDown();
|
||||
this.numericUpDownRead = new System.Windows.Forms.NumericUpDown();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonInsertTest
|
||||
//
|
||||
this.buttonInsertTest.Location = new System.Drawing.Point(17, 20);
|
||||
this.buttonInsertTest.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.buttonInsertTest.Name = "buttonInsertTest";
|
||||
this.buttonInsertTest.Size = new System.Drawing.Size(123, 102);
|
||||
this.buttonInsertTest.TabIndex = 0;
|
||||
this.buttonInsertTest.Text = "Тест вставки";
|
||||
this.buttonInsertTest.UseVisualStyleBackColor = true;
|
||||
this.buttonInsertTest.Click += new System.EventHandler(this.buttonInsertTest_Click);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(149, 20);
|
||||
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(234, 25);
|
||||
this.label1.TabIndex = 1;
|
||||
this.label1.Text = "Введите кол-во элементов:";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(149, 88);
|
||||
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(223, 25);
|
||||
this.label2.TabIndex = 3;
|
||||
this.label2.Text = "Итоговое время запроса:";
|
||||
//
|
||||
// textBoxInsertTime
|
||||
//
|
||||
this.textBoxInsertTime.Location = new System.Drawing.Point(380, 83);
|
||||
this.textBoxInsertTime.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.textBoxInsertTime.Name = "textBoxInsertTime";
|
||||
this.textBoxInsertTime.ReadOnly = true;
|
||||
this.textBoxInsertTime.Size = new System.Drawing.Size(141, 31);
|
||||
this.textBoxInsertTime.TabIndex = 4;
|
||||
//
|
||||
// buttonReadTest
|
||||
//
|
||||
this.buttonReadTest.Location = new System.Drawing.Point(17, 177);
|
||||
this.buttonReadTest.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.buttonReadTest.Name = "buttonReadTest";
|
||||
this.buttonReadTest.Size = new System.Drawing.Size(123, 93);
|
||||
this.buttonReadTest.TabIndex = 5;
|
||||
this.buttonReadTest.Text = "Тест чтения";
|
||||
this.buttonReadTest.UseVisualStyleBackColor = true;
|
||||
this.buttonReadTest.Click += new System.EventHandler(this.buttonReadTest_Click);
|
||||
//
|
||||
// textBoxReadTime
|
||||
//
|
||||
this.textBoxReadTime.Location = new System.Drawing.Point(380, 240);
|
||||
this.textBoxReadTime.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.textBoxReadTime.Name = "textBoxReadTime";
|
||||
this.textBoxReadTime.ReadOnly = true;
|
||||
this.textBoxReadTime.Size = new System.Drawing.Size(141, 31);
|
||||
this.textBoxReadTime.TabIndex = 9;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(149, 245);
|
||||
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(223, 25);
|
||||
this.label3.TabIndex = 8;
|
||||
this.label3.Text = "Итоговое время запроса:";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(149, 177);
|
||||
this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(234, 25);
|
||||
this.label4.TabIndex = 6;
|
||||
this.label4.Text = "Введите кол-во элементов:";
|
||||
//
|
||||
// numericUpDownInsert
|
||||
//
|
||||
this.numericUpDownInsert.Location = new System.Drawing.Point(380, 17);
|
||||
this.numericUpDownInsert.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.numericUpDownInsert.Name = "numericUpDownInsert";
|
||||
this.numericUpDownInsert.Size = new System.Drawing.Size(143, 31);
|
||||
this.numericUpDownInsert.TabIndex = 10;
|
||||
//
|
||||
// numericUpDownRead
|
||||
//
|
||||
this.numericUpDownRead.Location = new System.Drawing.Point(380, 173);
|
||||
this.numericUpDownRead.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.numericUpDownRead.Name = "numericUpDownRead";
|
||||
this.numericUpDownRead.Size = new System.Drawing.Size(143, 31);
|
||||
this.numericUpDownRead.TabIndex = 11;
|
||||
//
|
||||
// FormTests
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(547, 304);
|
||||
this.Controls.Add(this.numericUpDownRead);
|
||||
this.Controls.Add(this.numericUpDownInsert);
|
||||
this.Controls.Add(this.textBoxReadTime);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.buttonReadTest);
|
||||
this.Controls.Add(this.textBoxInsertTime);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.buttonInsertTest);
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.Name = "FormTests";
|
||||
this.Text = "Тесты запросов к бд";
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonInsertTest;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private TextBox textBoxInsertTime;
|
||||
private Button buttonReadTest;
|
||||
private TextBox textBoxReadTime;
|
||||
private Label label3;
|
||||
private Label label4;
|
||||
private NumericUpDown numericUpDownInsert;
|
||||
private NumericUpDown numericUpDownRead;
|
||||
}
|
||||
}
|
56
TransportGuide/FormTests.cs
Normal file
56
TransportGuide/FormTests.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace TransportGuide
|
||||
{
|
||||
public partial class FormTests : Form
|
||||
{
|
||||
private readonly IRouteLogic _routeLogic;
|
||||
public FormTests(IRouteLogic routeLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_routeLogic= routeLogic;
|
||||
numericUpDownInsert.Minimum = 1;
|
||||
numericUpDownInsert.Maximum = 1000000;
|
||||
numericUpDownRead.Minimum = 1;
|
||||
numericUpDownRead.Maximum = 1000000;
|
||||
}
|
||||
|
||||
private void buttonInsertTest_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _routeLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value));
|
||||
|
||||
textBoxInsertTime.Text = result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonReadTest_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _routeLogic.TestReadList(Convert.ToInt32(numericUpDownRead.Value));
|
||||
textBoxReadTime.Text = result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
60
TransportGuide/FormTests.resx
Normal file
60
TransportGuide/FormTests.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
119
TransportGuide/FormTransportType.Designer.cs
generated
Normal file
119
TransportGuide/FormTransportType.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace TransportGuide
|
||||
{
|
||||
partial class FormTransportType
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.labelPrice = new System.Windows.Forms.Label();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.textBoxPrice = new System.Windows.Forms.TextBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(76, 56);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(59, 25);
|
||||
this.labelName.TabIndex = 0;
|
||||
this.labelName.Text = "Name";
|
||||
//
|
||||
// labelPrice
|
||||
//
|
||||
this.labelPrice.AutoSize = true;
|
||||
this.labelPrice.Location = new System.Drawing.Point(76, 136);
|
||||
this.labelPrice.Name = "labelPrice";
|
||||
this.labelPrice.Size = new System.Drawing.Size(49, 25);
|
||||
this.labelPrice.TabIndex = 1;
|
||||
this.labelPrice.Text = "Price";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(76, 242);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonSave.TabIndex = 2;
|
||||
this.buttonSave.Text = "Save";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(219, 242);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonCancel.TabIndex = 3;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(181, 56);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(150, 31);
|
||||
this.textBoxName.TabIndex = 4;
|
||||
//
|
||||
// textBoxPrice
|
||||
//
|
||||
this.textBoxPrice.Location = new System.Drawing.Point(181, 136);
|
||||
this.textBoxPrice.Name = "textBoxPrice";
|
||||
this.textBoxPrice.Size = new System.Drawing.Size(150, 31);
|
||||
this.textBoxPrice.TabIndex = 5;
|
||||
//
|
||||
// FormTransportType
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(443, 315);
|
||||
this.Controls.Add(this.textBoxPrice);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.labelPrice);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Name = "FormTransportType";
|
||||
this.Text = "TransportType";
|
||||
this.Load += new System.EventHandler(this.FormTransportType_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelName;
|
||||
private Label labelPrice;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxPrice;
|
||||
}
|
||||
}
|
90
TransportGuide/FormTransportType.cs
Normal file
90
TransportGuide/FormTransportType.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
|
||||
namespace TransportGuide
|
||||
{
|
||||
public partial class FormTransportType : Form
|
||||
{
|
||||
private readonly ITransportTypeLogic _logic;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
public FormTransportType(ITransportTypeLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logic = logic;
|
||||
}
|
||||
private void FormTransportType_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new TransportTypeSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.Name;
|
||||
textBoxPrice.Text = view.Price.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Loading error", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Error", "Name cant be empty",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var model = new TransportTypeBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
Name = textBoxName.Text,
|
||||
Price = Convert.ToDouble(textBoxPrice.Text)
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||
_logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Error with save.");
|
||||
}
|
||||
MessageBox.Show("Transport Type was saved", "",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
60
TransportGuide/FormTransportType.resx
Normal file
60
TransportGuide/FormTransportType.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
116
TransportGuide/FormTransportTypes.Designer.cs
generated
Normal file
116
TransportGuide/FormTransportTypes.Designer.cs
generated
Normal file
@ -0,0 +1,116 @@
|
||||
namespace TransportGuide
|
||||
{
|
||||
partial class FormTransportTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeTransportType()
|
||||
{
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.buttonChange = new System.Windows.Forms.Button();
|
||||
this.buttonDelete = new System.Windows.Forms.Button();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.dataGridView.Location = new System.Drawing.Point(0, 0);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 33;
|
||||
this.dataGridView.Size = new System.Drawing.Size(459, 488);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(480, 25);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonAdd.TabIndex = 1;
|
||||
this.buttonAdd.Text = "Добавить";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
|
||||
//
|
||||
// buttonChange
|
||||
//
|
||||
this.buttonChange.Location = new System.Drawing.Point(481, 67);
|
||||
this.buttonChange.Name = "buttonChange";
|
||||
this.buttonChange.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonChange.TabIndex = 2;
|
||||
this.buttonChange.Text = "Изменить";
|
||||
this.buttonChange.UseVisualStyleBackColor = true;
|
||||
this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(481, 107);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonDelete.TabIndex = 3;
|
||||
this.buttonDelete.Text = "Удалить";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(481, 147);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonUpdate.TabIndex = 4;
|
||||
this.buttonUpdate.Text = "Обновить";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
|
||||
//
|
||||
// FormTransportTypes
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(614, 488);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.buttonDelete);
|
||||
this.Controls.Add(this.buttonChange);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormTransportTypes";
|
||||
this.Text = "TransportTypes";
|
||||
this.Load += new System.EventHandler(this.FormTransportTypes_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonAdd;
|
||||
private Button buttonChange;
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
}
|
||||
}
|
117
TransportGuide/FormTransportTypes.cs
Normal file
117
TransportGuide/FormTransportTypes.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
|
||||
namespace TransportGuide
|
||||
{
|
||||
public partial class FormTransportTypes : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ITransportTypeLogic _logic;
|
||||
public FormTransportTypes(ILogger<FormTransportTypes> logger, ITransportTypeLogic logic)
|
||||
{
|
||||
InitializeTransportType();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void FormTransportTypes_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["Name"].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(FormTransportType));
|
||||
if (service is FormTransportType 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 TransportTypeBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonChange_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service =
|
||||
Program.ServiceProvider?.GetService(typeof(FormTransportType));
|
||||
if (service is FormTransportType form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
TransportGuide/FormTransportTypes.resx
Normal file
120
TransportGuide/FormTransportTypes.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
56
TransportGuide/Program.cs
Normal file
56
TransportGuide/Program.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using BusinessLogic.BusinessLogic;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using TransportGuideContracts.BusinessLogicsContracts;
|
||||
using TransportGuideContracts.StoragesContracts;
|
||||
using TransportGuideDatabaseImplements.Implements;
|
||||
|
||||
namespace TransportGuide
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
services.AddTransient<IRouteStorage, RouteStorage>();
|
||||
services.AddTransient<IStopStorage, StopStorage>();
|
||||
services.AddTransient<ITransportTypeStorage, TransportTypeStorage>();
|
||||
|
||||
services.AddTransient<IRouteLogic, RouteLogic>();
|
||||
services.AddTransient<IStopLogic, StopLogic>();
|
||||
services.AddTransient<ITransportTypeLogic, TransportTypeLogic>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormTransportType>();
|
||||
services.AddTransient<FormTransportTypes>();
|
||||
services.AddTransient<FormStops>();
|
||||
services.AddTransient<FormStop>();
|
||||
services.AddTransient<FormRoutes>();
|
||||
services.AddTransient<FormRoute>();
|
||||
services.AddTransient<FormStopRoute>();
|
||||
services.AddTransient<FormTests>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
25
TransportGuide/TransportGuide.csproj
Normal file
25
TransportGuide/TransportGuide.csproj
Normal file
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TransportGuideDatabaseImplements\TransportGuideDatabaseImplements.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
49
TransportGuide/TransportGuide.sln
Normal file
49
TransportGuide/TransportGuide.sln
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.4.33122.133
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportGuide", "TransportGuide.csproj", "{4FB4F845-A1B0-4B67-B79D-054D8D9BF837}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportGuideDataModels", "..\TransportGuideDataModels\TransportGuideDataModels.csproj", "{97F50689-60B7-4955-9CF0-01CBCA875DEC}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportGuideDatabaseImplements", "..\TransportGuideDatabaseImplements\TransportGuideDatabaseImplements.csproj", "{EB404893-A2A8-4027-B5DD-3AB781274B4D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportGuideContracts", "..\TransportGuideContracts\TransportGuideContracts.csproj", "{C54EC4EF-09BD-4FFC-84A1-7C938F0803FB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogic", "..\BusinessLogic\BusinessLogic.csproj", "{09F7C041-606C-4D60-AF2F-14B030954930}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4FB4F845-A1B0-4B67-B79D-054D8D9BF837}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4FB4F845-A1B0-4B67-B79D-054D8D9BF837}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4FB4F845-A1B0-4B67-B79D-054D8D9BF837}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4FB4F845-A1B0-4B67-B79D-054D8D9BF837}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{97F50689-60B7-4955-9CF0-01CBCA875DEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{97F50689-60B7-4955-9CF0-01CBCA875DEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{97F50689-60B7-4955-9CF0-01CBCA875DEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{97F50689-60B7-4955-9CF0-01CBCA875DEC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EB404893-A2A8-4027-B5DD-3AB781274B4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EB404893-A2A8-4027-B5DD-3AB781274B4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EB404893-A2A8-4027-B5DD-3AB781274B4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EB404893-A2A8-4027-B5DD-3AB781274B4D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C54EC4EF-09BD-4FFC-84A1-7C938F0803FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C54EC4EF-09BD-4FFC-84A1-7C938F0803FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C54EC4EF-09BD-4FFC-84A1-7C938F0803FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C54EC4EF-09BD-4FFC-84A1-7C938F0803FB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{09F7C041-606C-4D60-AF2F-14B030954930}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{09F7C041-606C-4D60-AF2F-14B030954930}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{09F7C041-606C-4D60-AF2F-14B030954930}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{09F7C041-606C-4D60-AF2F-14B030954930}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {978F4C7D-1216-4FC4-8500-810480F8BB06}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
22
TransportGuideContracts/BindingModels/RouteBindingModel.cs
Normal file
22
TransportGuideContracts/BindingModels/RouteBindingModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideDataModels.Models;
|
||||
|
||||
namespace TransportGuideContracts.BindingModels
|
||||
{
|
||||
public class RouteBindingModel : IRouteModel
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string IP { get; set; } = string.Empty;
|
||||
|
||||
public int TransportTypeId { get; set; }
|
||||
|
||||
public Dictionary<int, (IStopModel, int)> StopRoutes { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
16
TransportGuideContracts/BindingModels/StopBindingModel.cs
Normal file
16
TransportGuideContracts/BindingModels/StopBindingModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideDataModels.Models;
|
||||
|
||||
namespace TransportGuideContracts.BindingModels
|
||||
{
|
||||
public class StopBindingModel : IStopModel
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideDataModels.Models;
|
||||
|
||||
namespace TransportGuideContracts.BindingModels
|
||||
{
|
||||
public class TransportTypeBindingModel : ITransportTypeModel
|
||||
{
|
||||
public double Price { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
|
||||
namespace TransportGuideContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IRouteLogic
|
||||
{
|
||||
List<RouteViewModel>? ReadList(RouteSearchModel? model);
|
||||
RouteViewModel? ReadElement(RouteSearchModel model);
|
||||
bool Create(RouteBindingModel model);
|
||||
bool Update(RouteBindingModel model);
|
||||
bool Delete(RouteBindingModel model);
|
||||
string TestInsertList(int num);
|
||||
string TestReadList(int num);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
|
||||
namespace TransportGuideContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IStopLogic
|
||||
{
|
||||
List<StopViewModel>? ReadList(StopSearchModel? model);
|
||||
StopViewModel? ReadElement(StopSearchModel model);
|
||||
bool Create(StopBindingModel model);
|
||||
bool Update(StopBindingModel model);
|
||||
bool Delete(StopBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
|
||||
namespace TransportGuideContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface ITransportTypeLogic
|
||||
{
|
||||
List<TransportTypeViewModel>? ReadList(TransportTypeSearchModel? model);
|
||||
TransportTypeViewModel? ReadElement(TransportTypeSearchModel model);
|
||||
bool Create(TransportTypeBindingModel model);
|
||||
bool Update(TransportTypeBindingModel model);
|
||||
bool Delete(TransportTypeBindingModel model);
|
||||
}
|
||||
}
|
16
TransportGuideContracts/SearchModels/RouteSearchModel.cs
Normal file
16
TransportGuideContracts/SearchModels/RouteSearchModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TransportGuideContracts.SearchModels
|
||||
{
|
||||
public class RouteSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? IP { get; set; }
|
||||
|
||||
}
|
||||
}
|
14
TransportGuideContracts/SearchModels/StopSearchModel.cs
Normal file
14
TransportGuideContracts/SearchModels/StopSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TransportGuideContracts.SearchModels
|
||||
{
|
||||
public class StopSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TransportGuideContracts.SearchModels
|
||||
{
|
||||
public class TransportTypeSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
23
TransportGuideContracts/StoragesContracts/IRouteStorage.cs
Normal file
23
TransportGuideContracts/StoragesContracts/IRouteStorage.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
|
||||
namespace TransportGuideContracts.StoragesContracts
|
||||
{
|
||||
public interface IRouteStorage
|
||||
{
|
||||
List<RouteViewModel> GetFullList();
|
||||
List<RouteViewModel> GetFilteredList(RouteSearchModel model);
|
||||
RouteViewModel? GetElement(RouteSearchModel model);
|
||||
RouteViewModel? Insert(RouteBindingModel model);
|
||||
RouteViewModel? Update(RouteBindingModel model);
|
||||
RouteViewModel? Delete(RouteBindingModel model);
|
||||
string TestInsertList(int num);
|
||||
string TestReadList(int num);
|
||||
}
|
||||
}
|
21
TransportGuideContracts/StoragesContracts/IStopStorage.cs
Normal file
21
TransportGuideContracts/StoragesContracts/IStopStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
|
||||
namespace TransportGuideContracts.StoragesContracts
|
||||
{
|
||||
public interface IStopStorage
|
||||
{
|
||||
List<StopViewModel> GetFullList();
|
||||
List<StopViewModel> GetFilteredList(StopSearchModel model);
|
||||
StopViewModel? GetElement(StopSearchModel model);
|
||||
StopViewModel? Insert(StopBindingModel model);
|
||||
StopViewModel? Update(StopBindingModel model);
|
||||
StopViewModel? Delete(StopBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
|
||||
namespace TransportGuideContracts.StoragesContracts
|
||||
{
|
||||
public interface ITransportTypeStorage
|
||||
{
|
||||
List<TransportTypeViewModel> GetFullList();
|
||||
List<TransportTypeViewModel> GetFilteredList(TransportTypeSearchModel model);
|
||||
TransportTypeViewModel? GetElement(TransportTypeSearchModel model);
|
||||
TransportTypeViewModel? Insert(TransportTypeBindingModel model);
|
||||
TransportTypeViewModel? Update(TransportTypeBindingModel model);
|
||||
TransportTypeViewModel? Delete(TransportTypeBindingModel model);
|
||||
}
|
||||
}
|
17
TransportGuideContracts/TransportGuideContracts.csproj
Normal file
17
TransportGuideContracts/TransportGuideContracts.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TransportGuideDataModels\TransportGuideDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
26
TransportGuideContracts/ViewModels/RouteViewModel.cs
Normal file
26
TransportGuideContracts/ViewModels/RouteViewModel.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace TransportGuideContracts.ViewModels
|
||||
{
|
||||
public class RouteViewModel : IRouteModel
|
||||
{
|
||||
[DisplayName("Rout's name")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Rout's IP")]
|
||||
public string IP { get; set; } = string.Empty;
|
||||
|
||||
public int TransportTypeId { get; set; }
|
||||
[DisplayName("TransportType")]
|
||||
public string TransportTypeName { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, (IStopModel, int)> StopRoutes { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
18
TransportGuideContracts/ViewModels/StopViewModel.cs
Normal file
18
TransportGuideContracts/ViewModels/StopViewModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace TransportGuideContracts.ViewModels
|
||||
{
|
||||
public class StopViewModel : IStopModel
|
||||
{
|
||||
[DisplayName("Stop's name")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
20
TransportGuideContracts/ViewModels/TransportTypeViewModel.cs
Normal file
20
TransportGuideContracts/ViewModels/TransportTypeViewModel.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace TransportGuideContracts.ViewModels
|
||||
{
|
||||
public class TransportTypeViewModel : ITransportTypeModel
|
||||
{
|
||||
[DisplayName("Ticket's Price")]
|
||||
public double Price { get; set; }
|
||||
[DisplayName("Transport type name")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
13
TransportGuideDataModels/IId.cs
Normal file
13
TransportGuideDataModels/IId.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TransportGuideDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
19
TransportGuideDataModels/Models/IRouteModel.cs
Normal file
19
TransportGuideDataModels/Models/IRouteModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TransportGuideDataModels.Models
|
||||
{
|
||||
public interface IRouteModel : IId
|
||||
{
|
||||
string Name { get;}
|
||||
string IP { get;}
|
||||
|
||||
int TransportTypeId { get;}
|
||||
|
||||
Dictionary<int, (IStopModel, int)> StopRoutes { get; }
|
||||
|
||||
}
|
||||
}
|
13
TransportGuideDataModels/Models/IStopModel.cs
Normal file
13
TransportGuideDataModels/Models/IStopModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TransportGuideDataModels.Models
|
||||
{
|
||||
public interface IStopModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
15
TransportGuideDataModels/Models/ITransportTypeModel.cs
Normal file
15
TransportGuideDataModels/Models/ITransportTypeModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TransportGuideDataModels.Models
|
||||
{
|
||||
public interface ITransportTypeModel : IId
|
||||
{
|
||||
double Price { get;}
|
||||
string Name { get;}
|
||||
|
||||
}
|
||||
}
|
14
TransportGuideDataModels/TransportGuideDataModels.csproj
Normal file
14
TransportGuideDataModels/TransportGuideDataModels.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
190
TransportGuideDatabaseImplements/Implements/RouteStorage.cs
Normal file
190
TransportGuideDatabaseImplements/Implements/RouteStorage.cs
Normal file
@ -0,0 +1,190 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.StoragesContracts;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
using TransportGuideDatabaseImplements.Models;
|
||||
|
||||
namespace TransportGuideDatabaseImplements.Implements
|
||||
{
|
||||
public class RouteStorage : IRouteStorage
|
||||
{
|
||||
public RouteViewModel? Delete(RouteBindingModel model)
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
var element = context.Routes.Include(x => x.Stops).Include(x => x.TransportType).FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Routes.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public RouteViewModel? GetElement(RouteSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
return context.Routes.Include(x => x.Stops).ThenInclude(x => x.Stop).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<RouteViewModel> GetFilteredList(RouteSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
return context.Routes.Include(x => x.Stops).ThenInclude(x => x.Stop).Where(x => x.Name.Contains(model.Name)).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<RouteViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
return context.Routes.Include(x => x.TransportType).Include(x => x.Stops).ThenInclude(x => x.Stop).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public RouteViewModel? Insert(RouteBindingModel model)
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
var newRoute = Route.Create(context, model);
|
||||
|
||||
if (newRoute == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Routes.Add(newRoute);
|
||||
context.SaveChanges();
|
||||
|
||||
return newRoute.GetViewModel;
|
||||
}
|
||||
|
||||
public string TestInsertList(int num)
|
||||
{
|
||||
var context = new TransportGuideDB();
|
||||
Stopwatch stopwatch = new();
|
||||
Random rnd = new Random();
|
||||
long[] res = new long[num * 2];
|
||||
List<TransportTypeViewModel> _types = context.TransportTypes.ToList().Select(x => x.GetViewModel).ToList();
|
||||
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
int rndId = rnd.Next();
|
||||
var model = new StopBindingModel
|
||||
{
|
||||
Id = rndId,
|
||||
Name = "Stop" + rndId.ToString(),
|
||||
};
|
||||
context.Stops.Add(Stop.Create(model));
|
||||
stopwatch.Start();
|
||||
context.SaveChanges();
|
||||
stopwatch.Stop();
|
||||
res[i] = stopwatch.ElapsedMilliseconds;
|
||||
}
|
||||
List<StopViewModel> _stops = context.Stops.Select(x => x.GetViewModel).ToList();
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
int rndId = rnd.Next();
|
||||
var model = new RouteBindingModel
|
||||
{
|
||||
Id = rndId,
|
||||
Name = "Route" + rndId.ToString(),
|
||||
IP = "IP" + rndId.ToString(),
|
||||
TransportTypeId = _types[rnd.Next(_types.Count)].Id
|
||||
};
|
||||
context.Routes.Add(Route.Create(context, model));
|
||||
stopwatch.Start();
|
||||
context.SaveChanges();
|
||||
stopwatch.Stop();
|
||||
res[i] = stopwatch.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
long sum = 0;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
sum += res[i];
|
||||
}
|
||||
int result = Convert.ToInt32(sum / num);
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
public string TestReadList(int num)
|
||||
{
|
||||
var context = new TransportGuideDB();
|
||||
Stopwatch stopwatch = new();
|
||||
|
||||
long[] res = new long[num];
|
||||
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
|
||||
stopwatch.Start();
|
||||
List<RouteViewModel> list = context.Routes.Include(x => x.TransportType).Include(x => x.Stops).ThenInclude(x => x.Stop).ToList().Select(x => x.GetViewModel).ToList();
|
||||
stopwatch.Stop();
|
||||
res[i] = stopwatch.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
long sum = 0;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
sum += res[i];
|
||||
}
|
||||
int result = Convert.ToInt32(sum / num);
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
public RouteViewModel? Update(RouteBindingModel model)
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var route = context.Routes.Include(x => x.TransportType).FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (route == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
route.Update(model);
|
||||
context.SaveChanges();
|
||||
route.UpdateStops(context, model);
|
||||
transaction.Commit();
|
||||
|
||||
return route.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
97
TransportGuideDatabaseImplements/Implements/StopStorage.cs
Normal file
97
TransportGuideDatabaseImplements/Implements/StopStorage.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.StoragesContracts;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
using TransportGuideDatabaseImplements.Models;
|
||||
|
||||
namespace TransportGuideDatabaseImplements.Implements
|
||||
{
|
||||
public class StopStorage : IStopStorage
|
||||
{
|
||||
public StopViewModel? Delete(StopBindingModel model)
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
var element = context.Stops.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Stops.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public StopViewModel? GetElement(StopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
return context.Stops.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<StopViewModel> GetFilteredList(StopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
return context.Stops.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<StopViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
return context.Stops.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public StopViewModel? Insert(StopBindingModel model)
|
||||
{
|
||||
var newStop = Stop.Create(model);
|
||||
|
||||
if (newStop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
context.Stops.Add(newStop);
|
||||
context.SaveChanges();
|
||||
|
||||
return newStop.GetViewModel;
|
||||
}
|
||||
|
||||
public StopViewModel? Update(StopBindingModel model)
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
var Stop = context.Stops.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (Stop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Stop.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return Stop.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.SearchModels;
|
||||
using TransportGuideContracts.StoragesContracts;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
using TransportGuideDatabaseImplements.Models;
|
||||
|
||||
namespace TransportGuideDatabaseImplements.Implements
|
||||
{
|
||||
public class TransportTypeStorage : ITransportTypeStorage
|
||||
{
|
||||
public TransportTypeViewModel? Delete(TransportTypeBindingModel model)
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
var element = context.TransportTypes.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.TransportTypes.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public TransportTypeViewModel? GetElement(TransportTypeSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
return context.TransportTypes.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<TransportTypeViewModel> GetFilteredList(TransportTypeSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
return context.TransportTypes.Where(x => x.Name.Contains(model.Name)).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<TransportTypeViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
return context.TransportTypes.ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public TransportTypeViewModel? Insert(TransportTypeBindingModel model)
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
var newTransportType = TransportType.Create(model);
|
||||
|
||||
if (newTransportType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.TransportTypes.Add(newTransportType);
|
||||
context.SaveChanges();
|
||||
|
||||
return newTransportType.GetViewModel;
|
||||
}
|
||||
|
||||
public TransportTypeViewModel? Update(TransportTypeBindingModel model)
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var transportType = context.TransportTypes.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (transportType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
transportType.Update(model);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
|
||||
return transportType.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
163
TransportGuideDatabaseImplements/Migrations/20230504163433_InitialCreate.Designer.cs
generated
Normal file
163
TransportGuideDatabaseImplements/Migrations/20230504163433_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,163 @@
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using TransportGuideDatabaseImplements;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TransportGuideDatabaseImplements.Migrations
|
||||
{
|
||||
[DbContext(typeof(TransportGuideDB))]
|
||||
[Migration("20230504163433_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <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("TransportGuideDatabaseImplements.Models.Route", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("IP")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TransportTypeId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TransportTypeId");
|
||||
|
||||
b.ToTable("Routes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.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("TransportGuideDatabaseImplements.Models.StopRoute", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Nomer")
|
||||
.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("StopRoutes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.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("TransportGuideDatabaseImplements.Models.Route", b =>
|
||||
{
|
||||
b.HasOne("TransportGuideDatabaseImplements.Models.TransportType", "TransportType")
|
||||
.WithMany("Routes")
|
||||
.HasForeignKey("TransportTypeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("TransportType");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.Models.StopRoute", b =>
|
||||
{
|
||||
b.HasOne("TransportGuideDatabaseImplements.Models.Route", "Route")
|
||||
.WithMany("Stops")
|
||||
.HasForeignKey("RouteId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TransportGuideDatabaseImplements.Models.Stop", "Stop")
|
||||
.WithMany("StopRoutes")
|
||||
.HasForeignKey("StopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Route");
|
||||
|
||||
b.Navigation("Stop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.Models.Route", b =>
|
||||
{
|
||||
b.Navigation("Stops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.Models.Stop", b =>
|
||||
{
|
||||
b.Navigation("StopRoutes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.Models.TransportType", b =>
|
||||
{
|
||||
b.Navigation("Routes");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TransportGuideDatabaseImplements.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
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: "Routes",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
TransportTypeId = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
IP = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Routes", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Routes_TransportTypes_TransportTypeId",
|
||||
column: x => x.TransportTypeId,
|
||||
principalTable: "TransportTypes",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "StopRoutes",
|
||||
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),
|
||||
Nomer = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_StopRoutes", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_StopRoutes_Routes_RouteId",
|
||||
column: x => x.RouteId,
|
||||
principalTable: "Routes",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_StopRoutes_Stops_StopId",
|
||||
column: x => x.StopId,
|
||||
principalTable: "Stops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Routes_TransportTypeId",
|
||||
table: "Routes",
|
||||
column: "TransportTypeId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_StopRoutes_RouteId",
|
||||
table: "StopRoutes",
|
||||
column: "RouteId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_StopRoutes_StopId",
|
||||
table: "StopRoutes",
|
||||
column: "StopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "StopRoutes");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Routes");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Stops");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "TransportTypes");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using TransportGuideDatabaseImplements;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TransportGuideDatabaseImplements.Migrations
|
||||
{
|
||||
[DbContext(typeof(TransportGuideDB))]
|
||||
partial class TransportGuideDBModelSnapshot : 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("TransportGuideDatabaseImplements.Models.Route", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("IP")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("TransportTypeId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TransportTypeId");
|
||||
|
||||
b.ToTable("Routes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.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("TransportGuideDatabaseImplements.Models.StopRoute", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Nomer")
|
||||
.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("StopRoutes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.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("TransportGuideDatabaseImplements.Models.Route", b =>
|
||||
{
|
||||
b.HasOne("TransportGuideDatabaseImplements.Models.TransportType", "TransportType")
|
||||
.WithMany("Routes")
|
||||
.HasForeignKey("TransportTypeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("TransportType");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.Models.StopRoute", b =>
|
||||
{
|
||||
b.HasOne("TransportGuideDatabaseImplements.Models.Route", "Route")
|
||||
.WithMany("Stops")
|
||||
.HasForeignKey("RouteId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TransportGuideDatabaseImplements.Models.Stop", "Stop")
|
||||
.WithMany("StopRoutes")
|
||||
.HasForeignKey("StopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Route");
|
||||
|
||||
b.Navigation("Stop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.Models.Route", b =>
|
||||
{
|
||||
b.Navigation("Stops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.Models.Stop", b =>
|
||||
{
|
||||
b.Navigation("StopRoutes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TransportGuideDatabaseImplements.Models.TransportType", b =>
|
||||
{
|
||||
b.Navigation("Routes");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
122
TransportGuideDatabaseImplements/Models/Route.cs
Normal file
122
TransportGuideDatabaseImplements/Models/Route.cs
Normal file
@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
using TransportGuideDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace TransportGuideDatabaseImplements.Models
|
||||
{
|
||||
public class Route : IRouteModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int TransportTypeId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string IP { get; private set; } = string.Empty;
|
||||
|
||||
|
||||
Dictionary<int, (IStopModel, int)>? _stopRoutes = null;
|
||||
|
||||
public virtual TransportType TransportType { get; set; }
|
||||
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IStopModel, int)> StopRoutes {
|
||||
get
|
||||
{
|
||||
if (_stopRoutes == null)
|
||||
{
|
||||
_stopRoutes = Stops.ToDictionary(recPC => recPC.StopId, recPC => (recPC.Stop as IStopModel, recPC.Nomer));
|
||||
}
|
||||
return _stopRoutes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ForeignKey("RouteId")]
|
||||
public virtual List<StopRoute> Stops { get; set; } = new();
|
||||
|
||||
public static Route Create(TransportGuideDB context, RouteBindingModel model)
|
||||
{
|
||||
return new Route()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
IP = model.IP,
|
||||
TransportTypeId = model.TransportTypeId,
|
||||
Stops = model.StopRoutes.Select(x => new StopRoute
|
||||
{
|
||||
Stop = context.Stops.First(y => y.Id == x.Key),
|
||||
Nomer = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(RouteBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
IP = model.IP;
|
||||
TransportTypeId = model.TransportTypeId;
|
||||
}
|
||||
|
||||
public RouteViewModel GetViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
using var context = new TransportGuideDB();
|
||||
return new RouteViewModel
|
||||
{
|
||||
Id = Id,
|
||||
TransportTypeId = TransportTypeId,
|
||||
IP = IP,
|
||||
Name = Name,
|
||||
TransportTypeName = context.TransportTypes.FirstOrDefault(x => x.Id == TransportTypeId)?.Name ?? string.Empty,
|
||||
StopRoutes = StopRoutes
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateStops(TransportGuideDB context, RouteBindingModel model)
|
||||
{
|
||||
var routeStops = context.StopRoutes.Where(rec => rec.RouteId == model.Id).ToList();
|
||||
|
||||
if (routeStops != null && routeStops.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.StopRoutes.RemoveRange(routeStops.Where(rec => !model.StopRoutes.ContainsKey(rec.StopId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateStop in routeStops)
|
||||
{
|
||||
updateStop.Nomer = model.StopRoutes[updateStop.StopId].Item2;
|
||||
model.StopRoutes.Remove(updateStop.StopId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
var route = context.Routes.First(x => x.Id == Id);
|
||||
|
||||
foreach (var pc in model.StopRoutes)
|
||||
{
|
||||
context.StopRoutes.Add(new StopRoute
|
||||
{
|
||||
Route = route,
|
||||
Stop = context.Stops.First(x => x.Id == pc.Key),
|
||||
Nomer = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_stopRoutes = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
58
TransportGuideDatabaseImplements/Models/Stop.cs
Normal file
58
TransportGuideDatabaseImplements/Models/Stop.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
using TransportGuideDataModels.Models;
|
||||
|
||||
namespace TransportGuideDatabaseImplements.Models
|
||||
{
|
||||
public class Stop : IStopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
|
||||
[ForeignKey("StopId")]
|
||||
public virtual List<StopRoute> StopRoutes { get; set; } = new();
|
||||
|
||||
public static Stop? Create(StopBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Stop()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
};
|
||||
}
|
||||
public static Stop Create(StopViewModel model)
|
||||
{
|
||||
return new Stop
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
};
|
||||
}
|
||||
public void Update(StopBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
}
|
||||
public StopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
};
|
||||
}
|
||||
}
|
22
TransportGuideDatabaseImplements/Models/StopRoute.cs
Normal file
22
TransportGuideDatabaseImplements/Models/StopRoute.cs
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace TransportGuideDatabaseImplements.Models
|
||||
{
|
||||
public class StopRoute
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int StopId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int RouteId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Nomer { get; set; }
|
||||
|
||||
public virtual Route Route { get; set; } = new();
|
||||
public virtual Stop Stop { get; set; } = new();
|
||||
}
|
||||
}
|
66
TransportGuideDatabaseImplements/Models/TransportType.cs
Normal file
66
TransportGuideDatabaseImplements/Models/TransportType.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideContracts.BindingModels;
|
||||
using TransportGuideContracts.ViewModels;
|
||||
using TransportGuideDataModels.Models;
|
||||
|
||||
namespace TransportGuideDatabaseImplements.Models
|
||||
{
|
||||
public class TransportType : ITransportTypeModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
|
||||
[ForeignKey("TransportTypeId")]
|
||||
public virtual List<Route> Routes { get; set; } = new();
|
||||
|
||||
|
||||
public static TransportType? Create(TransportTypeBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new TransportType()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price
|
||||
};
|
||||
}
|
||||
public static TransportType Create(TransportTypeViewModel model)
|
||||
{
|
||||
return new TransportType
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price
|
||||
};
|
||||
}
|
||||
public void Update(TransportTypeBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
Price = model.Price;
|
||||
}
|
||||
public TransportTypeViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Price = Price
|
||||
};
|
||||
}
|
||||
}
|
31
TransportGuideDatabaseImplements/TransportGuideDB.cs
Normal file
31
TransportGuideDatabaseImplements/TransportGuideDB.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportGuideDatabaseImplements.Models;
|
||||
|
||||
namespace TransportGuideDatabaseImplements
|
||||
{
|
||||
public class TransportGuideDB : DbContext
|
||||
{
|
||||
string dbName = ConfigurationManager.AppSettings["connectToDb"];
|
||||
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql(dbName);
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Route> Routes { set; get; }
|
||||
public virtual DbSet<Stop> Stops { set; get; }
|
||||
public virtual DbSet<StopRoute> StopRoutes { set; get; }
|
||||
public virtual DbSet<TransportType> TransportTypes { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\TransportGuideContracts\TransportGuideContracts.csproj" />
|
||||
<ProjectReference Include="..\TransportGuideDataModels\TransportGuideDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user