PIbd-21_MasenkinMS_SUBD_Rou.../RouteGuide/RouteGuideView/FormRouteStop.cs

125 lines
3.5 KiB
C#
Raw Permalink Normal View History

2024-04-05 02:48:52 +04:00
using RouteGuideContracts.BusinessLogicsContracts;
using RouteGuideContracts.ViewModels;
using RouteGuideDataModels.Models;
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 RouteGuideView
{
/// <summary>
/// Форма для привязки остановки к маршруту
/// </summary>
public partial class FormRouteStop : Form
{
/// <summary>
/// Список остановок
/// </summary>
private readonly List<StopViewModel>? _list;
/// <summary>
/// Идентификатор остановки
/// </summary>
public int Id
{
get
{
return Convert.ToInt32(comboBoxStop.SelectedValue);
}
set
{
comboBoxStop.SelectedValue = value;
}
}
/// <summary>
/// Сущность "Остановка"
/// </summary>
public IStopModel? StopModel
{
get
{
if (_list == null)
{
return null;
}
foreach (var elem in _list)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
/// <summary>
/// Номер остановки в маршруте
/// </summary>
public int Number
{
get { return Convert.ToInt32(textBoxNumber.Text); }
set { textBoxNumber.Text = value.ToString(); }
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="stopLogic"></param>
public FormRouteStop(IStopLogic stopLogic)
{
InitializeComponent();
// Загрузка списка остановок для ComboBoxStop
_list = stopLogic.ReadList(null);
if (_list != null)
{
comboBoxStop.DisplayMember = "Name";
comboBoxStop.ValueMember = "Id";
comboBoxStop.DataSource = _list;
comboBoxStop.SelectedItem = null;
}
}
/// <summary>
/// Кнопка "Сохранить"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSave_Click(object sender, EventArgs e)
{
if (comboBoxStop.SelectedValue == null)
{
MessageBox.Show("Выберите остановку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxNumber.Text))
{
MessageBox.Show("Заполните номер остановки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
/// <summary>
/// Кнопка "Отмена"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}