using Microsoft.Extensions.Logging; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.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 PrecastConcretePlantView { public partial class FormMain : Form { private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; public FormMain(ILogger logger, IOrderLogic orderLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; } private void FormMain_Load(object sender, EventArgs e) { LoadData(); } private void LoadData() { try { var list = _orderLogic.ReadList(null); if (list != null) { dataGridView.DataSource = list; dataGridView.Columns["ReinforcedId"].Visible = false; dataGridView.Columns["reinforcedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("青沭箸赅 玎赅珙"); } catch (Exception ex) { _logger.LogError(ex, "硒栳赅 玎沭箸觇 玎赅珙"); MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void 暑祜铐屙螓ToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComponentS)); if (service is FormComponentS form) { form.ShowDialog(); } } private void 如溴腓ToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedS)); if (service is FormReinforcedS form) { form.ShowDialog(); } } private void 锑汔玷睇ToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); if (service is FormShops form) { form.ShowDialog(); } } private void 项镱腠屙桢锑汔玷磬ToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment)); if (service is FormShopReplenishment form) { form.ShowDialog(); } } private void 橡钿噫嗳玟咫栝ToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedSale)); if (service is FormReinforcedSale form) { form.ShowDialog(); } } private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); if (service is FormCreateOrder form) { form.ShowDialog(); LoadData(); } } private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("青赅 箋id}. 体<> 耱囹篑 磬 '<27> 疣犷蝈'", id); try { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("硒栳赅 镳<> 耦躔囗屙梃.念镱腠栩咫 桧纛痨圉 <20> 腩汔."); } LoadData(); } catch (Exception ex) { _logger.LogError(ex, "硒栳赅 镥疱溧麒 玎赅玎 <20> 疣犷蝮"); MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void ButtonOrderReady_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("青赅 箋id}. 体<> 耱囹篑 磬 '妙蝾'", id); try { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("硒栳赅 镳<> 耦躔囗屙梃. 念镱腠栩咫 桧纛痨圉 <20> 腩汔."); } LoadData(); } catch (Exception ex) { _logger.LogError(ex, "硒栳赅 铗戾蜿 <20> 泐蝾忭铖蜩 玎赅玎"); MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void ButtonIssuedOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("青赅 箋id}. 体<> 耱囹篑 磬 '蔓溧'", id); try { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("硒栳赅"); } _logger.LogInformation("青赅 箋id} 恹溧", id); LoadData(); } catch (Exception ex) { _logger.LogError(ex, "硒栳赅 铗戾蜿 <20> 恹溧麒 玎赅玎"); MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void ButtonUpd_Click(object sender, EventArgs e) { LoadData(); } } }