private void btnBindLV_Click(object sender, EventArgs e) { _context.SaveChanges(); if (BindOrderToLV()) { bool isAllBindings = true; foreach (var shipmentOrder in _shipment.ShipmentOrders) { _context.Entry(shipmentOrder).Reload(); if (shipmentOrder.IsBinding == null || shipmentOrder.IsBinding == false) { MessageBox.Show($"Заказ [{shipmentOrder.OrderId} не найдет в Lvision]"); isAllBindings = false; } } _context.Entry(_shipment).Reload(); tblShipmentOrders.DataSource = _shipment.ShipmentOrders.ToList(); if (isAllBindings) { MessageBox.Show("Все заказы привязаны к отгрузке"); } } }
private void Save() { if (cmbType.SelectedIndex < 2) { _shipmentAddResult.IsShipment = true; _shipment = new Shipment(); _shipment.SDate = dtSDate.Value; _shipment.ShIn = cmbType.Text == "Вход" ? true : false; _shipment.DepositorId = DataService.GetDictIdByName("Депозиторы", cmbDepositor.Text); _shipment.TimeSlotId = DataService.GetDictIdByCondition("ТаймСлоты", $"depositor_id = {_shipment.DepositorId} and slot_time = '{cmbTimeSlot.Text}'"); _shipment.IsAddLv = false; for (int i = 0; i < tblShipmentItem.RowCount; i++) { ShipmentOrder shipmentOrder = new ShipmentOrder(); shipmentOrder.OrderId = tblShipmentItem.Rows[i].Cells["colItemId"].Value.ToString(); shipmentOrder.LVOrderId = (int?)tblShipmentItem.Rows[i].Cells["colLVOrdId"].Value; shipmentOrder.lv_order_code = tblShipmentItem.Rows[i].Cells["colItemId"].Value.ToString(); shipmentOrder.IsBinding = true; _shipment.ShipmentOrders.Add(shipmentOrder); } _shipmentAddResult.Result = _shipment; _context.Shipments.Add(_shipment); } else if (cmbType.SelectedIndex == 2) { _shipmentAddResult.IsShipment = false; _movement = new Movement(); _movement.MDate = dtSDate.Value; _movement.TimeSlotId = DataService.GetDictIdByCondition("ТаймСлоты", $"depositor_id = {DataService.GetDictIdByName("Депозиторы", cmbDepositor.Text)} and slot_time = '{cmbTimeSlot.Text}'"); for (int i = 0; i < tblShipmentItem.RowCount; i++) { MovementItem movementItem = new MovementItem(); movementItem.DepositorId = (int)DataService.GetDictIdByName("Депозиторы", cmbDepositor.Text); movementItem.TklLVID = int.Parse(tblShipmentItem.Rows[i].Cells["colLVOrdId"].Value.ToString()); _movement.MovementItems.Add(movementItem); } _shipmentAddResult.Result = _movement; _context.Movements.Add(_movement); } _context.SaveChanges(); }