using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; using AbstractSoftwareInstallationContracts.ViewModels; using AbstractSoftwareInstallationDataModels.Models; namespace SoftwareInstallationView { public partial class FormPackageSoftware : Form { private readonly List? _list; public int Id { get { return Convert.ToInt32(comboBoxSoftware.SelectedValue); } set { comboBoxSoftware.SelectedValue = value; } } public ISoftwareModel? SoftwareModel { 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(textBox1.Text); } set { textBox1.Text = value.ToString(); } } public FormPackageSoftware(ISoftwareLogic logic) { InitializeComponent(); _list = logic.ReadList(null); if (_list != null) { comboBoxSoftware.DisplayMember = "SoftwareName"; comboBoxSoftware.ValueMember = "Id"; comboBoxSoftware.DataSource = _list; comboBoxSoftware.SelectedItem = null; } } private void ButtonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxSoftware.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(); } } }