ошибка с сохранением маршрута

This commit is contained in:
VictoriaPresnyakova 2023-05-05 14:57:40 +04:00
parent caaa5d7f0f
commit 3609582418
9 changed files with 961 additions and 73 deletions

View File

@ -28,12 +28,228 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
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, 450);
this.Text = "FormRoute";
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;
}
}

View File

@ -1,20 +1,239 @@
using System;
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.BusinessLogicsContracts;
using TransportGuideContracts.SearchModels;
using TransportGuideDataModels.Models;
using TransportGuideContracts.BindingModels;
namespace TransportGuide
{
public partial class FormRoute : Form
{
public FormRoute()
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)
{
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();
_RouteStops = view.StopRoutes ?? new
Dictionary<int, (IStopModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
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);
}
}
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 });
}
//textBoxIP.Text = CalcIP().ToString();
}
}
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,
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();
}
}
}

View File

@ -1,64 +1,4 @@
<?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.
-->
<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">

View File

@ -28,12 +28,94 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
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(800, 450);
this.Text = "FormRoutes";
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;
}
}

View File

@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -7,14 +8,114 @@ 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
{
public FormRoutes()
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();
}
}
}

119
TransportGuide/FormStopRoute.Designer.cs generated Normal file
View 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;
}
}

View 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();
}
}
}

View 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>

View File

@ -48,7 +48,7 @@ namespace TransportGuide
services.AddTransient<FormStop>();
services.AddTransient<FormRoutes>();
services.AddTransient<FormRoute>();
services.AddTransient<FormStopRoute>();
}
}
}