DB/TransportGuide/FormStopRoute.cs

92 lines
1.8 KiB
C#

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