2024-10-22 19:58:21 +04:00
|
|
|
|
using Contracts.BindingModels;
|
|
|
|
|
using Contracts.BusinessLogicsContracts;
|
|
|
|
|
using Contracts.SearchModels;
|
|
|
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
|
|
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 Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class ProviderForm : Form
|
|
|
|
|
{
|
|
|
|
|
private int? _id;
|
|
|
|
|
public int Id { set { _id = value; } }
|
|
|
|
|
private readonly IProviderLogic _pLogic;
|
|
|
|
|
private readonly IOrganisationTypeLogic _oLogic;
|
2024-10-22 19:59:11 +04:00
|
|
|
|
//private bool isEdited;
|
2024-10-22 19:58:21 +04:00
|
|
|
|
|
|
|
|
|
public ProviderForm(IProviderLogic plogic, IOrganisationTypeLogic ologic)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_pLogic = plogic;
|
|
|
|
|
_oLogic = ologic;
|
2024-10-22 20:02:31 +04:00
|
|
|
|
//isEdited = false;
|
2024-10-22 19:58:21 +04:00
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
var list = _oLogic.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
List<string> strList = new List<string>();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
strList.Add(item.Name);
|
|
|
|
|
}
|
|
|
|
|
controlSelectedComboBoxList.AddList(strList);
|
|
|
|
|
}
|
|
|
|
|
if (_id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var view = _pLogic.ReadElement(new ProviderSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = _id.Value,
|
|
|
|
|
});
|
|
|
|
|
controlSelectedComboBoxList.SelectedElement = view!.OrganisationType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(string.IsNullOrEmpty(textBoxName.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Заполните поле Название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(textBoxFurnitureType.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Заполните Перечень мебели ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(string.IsNullOrEmpty(controlSelectedComboBoxList.SelectedElement))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите Тип организации", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var s = controlInputNullableDate.Value.ToString();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var OperationResult = _pLogic.Create(new ProviderBindingModel
|
|
|
|
|
{
|
|
|
|
|
Name = textBoxName.Text,
|
|
|
|
|
FurnitureType = textBoxFurnitureType.Text,
|
|
|
|
|
DateLastDelivery = controlInputNullableDate.Value.ToString() == "" ? "No date" : controlInputNullableDate.Value.ToString(),
|
|
|
|
|
OrganisationType = controlSelectedComboBoxList.SelectedElement
|
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|