PIbd-22_Petrushin_E.A._LawFirm/LawFirm/LawFirmView/FormDocumentComponent.cs

96 lines
2.6 KiB
C#
Raw Normal View History

2024-02-27 19:44:44 +04:00
using AbstractLawFirmContracts.BusinessLogicsContracts;
using AbstractLawFirmContracts.ViewModels;
using AbstractLawFirmDataModels.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;
2024-02-11 18:24:54 +04:00
2024-02-14 00:11:21 +04:00
namespace LawFirmView
2024-02-11 18:24:54 +04:00
{
2024-02-14 00:11:21 +04:00
public partial class FormDocumentComponent : Form
2024-02-11 18:24:54 +04:00
{
private readonly List<ComponentViewModel>? _list;
2024-02-27 19:44:44 +04:00
public int Id
{
get
{
return
Convert.ToInt32(comboBoxComponent.SelectedValue);
}
set
{
comboBoxComponent.SelectedValue = value;
}
}
2024-02-11 18:24:54 +04:00
public IComponentModel? ComponentModel
{
get
{
if (_list == null)
{
return null;
}
2024-02-27 19:44:44 +04:00
foreach (var elem in _list)
2024-02-11 18:24:54 +04:00
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
2024-02-27 19:44:44 +04:00
public int Count
{
get { return Convert.ToInt32(textBoxCount.Text); }
set
{ textBoxCount.Text = value.ToString(); }
}
2024-02-11 18:24:54 +04:00
2024-02-14 00:11:21 +04:00
public FormDocumentComponent(IComponentLogic logic)
2024-02-11 18:24:54 +04:00
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxComponent.DisplayMember = "ComponentName";
comboBoxComponent.ValueMember = "Id";
comboBoxComponent.DataSource = _list;
comboBoxComponent.SelectedItem = null;
}
2024-02-27 19:44:44 +04:00
2024-02-11 18:24:54 +04:00
}
2024-02-27 19:44:44 +04:00
private void buttonSave_Click(object sender, EventArgs e)
2024-02-11 18:24:54 +04:00
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
2024-02-27 19:44:44 +04:00
MessageBox.Show("Заполните поле Количество", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-02-11 18:24:54 +04:00
return;
}
if (comboBoxComponent.SelectedValue == null)
{
2024-02-27 19:44:44 +04:00
MessageBox.Show("Выберите компонент", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-02-11 18:24:54 +04:00
return;
}
DialogResult = DialogResult.OK;
Close();
}
2024-02-27 19:44:44 +04:00
private void buttonCancel_Click(object sender, EventArgs e)
2024-02-11 18:24:54 +04:00
{
DialogResult = DialogResult.Cancel;
Close();
2024-02-27 19:44:44 +04:00
2024-02-11 18:24:54 +04:00
}
}
2024-02-27 19:44:44 +04:00
}