PIbd-23_Nevaeva_K.A._Travel.../TravelCompany/TravelCompany/FormTravelCondition.cs
2023-02-20 08:36:19 +04:00

93 lines
2.6 KiB
C#

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 TravelCompanyContracts.BusinessLogicsContracts;
using TravelCompanyContracts.ViewModels;
using TravelCompanyDataModels.Models;
namespace TravelCompany
{
public partial class FormTravelCondition : Form
{
private readonly List<ConditionViewModel>? _list;
public int Id
{
get
{
return Convert.ToInt32(comboBoxCondition.SelectedValue);
}
set
{
comboBoxCondition.SelectedValue = value;
}
}
public IConditionModel? ConditionModel
{
get
{
if (_list == null)
{
return null;
}
foreach (var elem in _list)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
public int Count
{
get { return Convert.ToInt32(textBoxCount.Text); }
set
{ textBoxCount.Text = value.ToString(); }
}
public FormTravelCondition(IConditionLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxCondition.DisplayMember = "ConditionName";
comboBoxCondition.ValueMember = "Id";
comboBoxCondition.DataSource = _list;
comboBoxCondition.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxCondition.SelectedValue == null)
{
MessageBox.Show("Выберите компонент", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}