AccountingWarehouseProducts.../AccountingWarehouseProducts/AccountingWarehouseProductsView/FormStand.cs

81 lines
2.8 KiB
C#
Raw Permalink Normal View History

2024-05-01 22:21:11 +04:00
using AccountingWarehouseProductsContracts.BindingModels;
using AccountingWarehouseProductsContracts.BusinessLogicsContracts;
using AccountingWarehouseProductsContracts.SearchModels;
2024-05-07 16:15:07 +04:00
using Microsoft.IdentityModel.Tokens;
2024-05-01 22:21:11 +04:00
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 AccountingWarehouseProductsView
{
public partial class FormStand : Form
{
private readonly IStandLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormStand(IStandLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void FormStand_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var view = _logic.ReadElement(new StandSearchModel { Id = _id.Value });
if (view != null)
{
textBoxNameStand.Text = view.StandName;
2024-05-07 16:15:07 +04:00
dateTimePickerDeliveryDate.Value = (DateTime)view.DeliveryDate;
2024-05-01 22:21:11 +04:00
textBoxCount.Text = view.Count.ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
try
{
var model = new StandBindingModel
{
Id = _id ?? 0,
StandName = textBoxNameStand.Text,
2024-05-07 16:15:07 +04:00
DeliveryDate = dateTimePickerDeliveryDate.Value,
2024-05-01 22:21:11 +04:00
Count = Convert.ToInt32(textBoxCount.Text),
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.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();
}
}
}