88 lines
2.7 KiB
C#
88 lines
2.7 KiB
C#
using Publication.Entites;
|
|
using Publication.Repositories;
|
|
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 Publication.Forms;
|
|
|
|
public partial class FormPrintingHouse : Form
|
|
{
|
|
private readonly IPrintingHouseRepository printingHouseRepository;
|
|
public FormPrintingHouse(IPrintingHouseRepository _printingHouseRepository,
|
|
IMaterialRepository materialRepository,
|
|
IOrderRepository orderRepository)
|
|
{
|
|
InitializeComponent();
|
|
printingHouseRepository = _printingHouseRepository ?? throw new ArgumentNullException(nameof(_printingHouseRepository));
|
|
|
|
comboBoxMaterials.DataSource = materialRepository.ReadMaterials();
|
|
comboBoxMaterials.DisplayMember = "Material";
|
|
comboBoxMaterials.ValueMember = "Id";
|
|
|
|
ColumnOrders.DataSource = orderRepository.ReadOrders();
|
|
ColumnOrders.DisplayMember = "Id";
|
|
ColumnOrders.ValueMember = "Id";
|
|
}
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (dataGridView1.RowCount < 1 ||
|
|
comboBoxMaterials.SelectedIndex < 0)
|
|
{
|
|
throw new Exception("Имеются незаполненные поля");
|
|
}
|
|
|
|
printingHouseRepository.CreatePrintingHouse
|
|
(
|
|
PrintingHouses.CreateEntity
|
|
(
|
|
0,
|
|
textBoxTitle.Text,
|
|
textBoxPhone.Text,
|
|
textBoxAddress.Text,
|
|
(int)comboBoxMaterials.SelectedValue!,
|
|
CreateListPrintingHouseOrdersFromDataGrid()
|
|
)
|
|
);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
private IEnumerable<PrintingHouseOrders> CreateListPrintingHouseOrdersFromDataGrid()
|
|
{
|
|
var list =
|
|
new List<PrintingHouseOrders>();
|
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
|
{
|
|
if (row.Cells["ColumnOrders"].Value == null ||
|
|
row.Cells["ColumnCopy"].Value == null)
|
|
{
|
|
continue;
|
|
}
|
|
list.Add
|
|
(
|
|
PrintingHouseOrders.CreateEntity
|
|
(
|
|
0, Convert.ToInt32(row.Cells["ColumnOrders"].Value),
|
|
Convert.ToInt32(row.Cells["ColumnCopy"].Value)
|
|
)
|
|
);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private void ButtonBreak_Click(object sender, EventArgs e) => Close();
|
|
}
|