using SportCompetitionsContracts.BindingModels; using SportCompetitionsContracts.BusinessLogicsContracts; 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 SportCompetitionsView { public partial class FormRecord : Form { private readonly IRecordLogic _recordLogic; private readonly IMemberLogic _memberLogic; private int? _id; public int Id { set { _id = value; } } public FormRecord(IMemberLogic memberLogic, IRecordLogic recordLogic) { InitializeComponent(); _memberLogic = memberLogic; _recordLogic = recordLogic; } private void FormRecord_Load(object sender, EventArgs e) { var _listP = _memberLogic.ReadList(null); if (_listP != null) { comboBoxMember.DisplayMember = "MemberFCs"; comboBoxMember.ValueMember = "Id"; comboBoxMember.DataSource = _listP; comboBoxMember.SelectedItem = null; } } private void buttonSave_Click(object sender, EventArgs e) { try { var model = new RecordBindingModel { Id = _id ?? 0, RecordName = textBox2.Text, RecordDate = dateTimePicker1.Value, RecordDecriptiption = textBox1.Text, MemberId = comboBoxMember.SelectedIndex, RecordValue = Convert.ToInt32(textBox3.Text), }; var operationResult = _id.HasValue ? _recordLogic.Update(model) : _recordLogic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении. Доп информация в логах"); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void buttonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } } }