/// <summary> /// Create a new ScrapOrderDetail object. /// </summary> /// <param name="scrapOrderDetailID">Initial value of the ScrapOrderDetailID property.</param> /// <param name="scrapOrderID">Initial value of the ScrapOrderID property.</param> /// <param name="scrapDate">Initial value of the ScrapDate property.</param> /// <param name="toolID">Initial value of the ToolID property.</param> /// <param name="prescrapQuantity">Initial value of the PrescrapQuantity property.</param> /// <param name="quantity">Initial value of the Quantity property.</param> /// <param name="scrapQuantity">Initial value of the ScrapQuantity property.</param> /// <param name="repairingQuantity">Initial value of the RepairingQuantity property.</param> /// <param name="unitPrice">Initial value of the UnitPrice property.</param> public static ScrapOrderDetail CreateScrapOrderDetail(global::System.Int32 scrapOrderDetailID, global::System.Int32 scrapOrderID, global::System.DateTime scrapDate, global::System.Int32 toolID, global::System.Decimal prescrapQuantity, global::System.Decimal quantity, global::System.Decimal scrapQuantity, global::System.Decimal repairingQuantity, global::System.Decimal unitPrice) { ScrapOrderDetail scrapOrderDetail = new ScrapOrderDetail(); scrapOrderDetail.ScrapOrderDetailID = scrapOrderDetailID; scrapOrderDetail.ScrapOrderID = scrapOrderID; scrapOrderDetail.ScrapDate = scrapDate; scrapOrderDetail.ToolID = toolID; scrapOrderDetail.PrescrapQuantity = prescrapQuantity; scrapOrderDetail.Quantity = quantity; scrapOrderDetail.ScrapQuantity = scrapQuantity; scrapOrderDetail.RepairingQuantity = repairingQuantity; scrapOrderDetail.UnitPrice = unitPrice; return scrapOrderDetail; }
/// <summary> /// Deprecated Method for adding a new object to the ScrapOrderDetails EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToScrapOrderDetails(ScrapOrderDetail scrapOrderDetail) { base.AddObject("ScrapOrderDetails", scrapOrderDetail); }
private void _saveButton_Click(object sender, EventArgs e) { ExecuteActionHelper.ExecuteAction(delegate() { if (!_validationManager.Validate()) { return; } CurrentOrder.Code = txtCode.Text; CurrentOrder.InboundDate = dtInboundDate.Value; CurrentOrder.Customer = cbCustomer.SelectedItem as Unit; CurrentOrder.SystemUser = cbSystemUser.SelectedItem as SystemUser; CurrentOrder.OutboundOrder = ReferenceOrder; if (CurrentOrder.EntityKey == null) SystemHelper.TMSContext.AddToInboundOrders(CurrentOrder); CurrentOrder.SystemUser = SystemHelper.CurrentUser; CurrentOrder.LastUpdateTime = System.DateTime.Now; ScrapOrder scrapOrder = new ScrapOrder(); // Iterate all rows foreach (DataGridViewRow dgvr in dataGridViewDetail.Rows) { if (!dgvr.IsNewRow) { // for inbound detail int itemID = 0; int.TryParse(dgvr.Cells["ItemID"].Value.ToString(), out itemID); OutboundOrderDetail referenceItem = SystemHelper.TMSContext.OutboundOrderDetails.FirstOrDefault(s => s.OutboundOrderDetailID == itemID); decimal quantity = 0; if (dgvr.Cells["Quantity"].Value != null) decimal.TryParse(dgvr.Cells["Quantity"].Value.ToString(), out quantity); decimal prescrapQuantity = 0; if (dgvr.Cells["PrescrapQuantity"].Value != null) decimal.TryParse(dgvr.Cells["PrescrapQuantity"].Value.ToString(), out prescrapQuantity); decimal transferQuantity = 0; if (dgvr.Cells["TransferQuantity"].Value != null) decimal.TryParse(dgvr.Cells["TransferQuantity"].Value.ToString(), out transferQuantity); if (quantity == 0 && prescrapQuantity == 0 && transferQuantity == 0) continue; InboundOrderDetail item = SystemHelper.TMSContext.InboundOrderDetails.CreateObject(); item.InboundDate = CurrentOrder.LastUpdateTime; item.OutboundOrderDetail = referenceItem; item.Tool = referenceItem.Tool; item.UnitPrice = referenceItem.UnitPrice; item.Quantity = quantity; item.PrescrapQuantity = prescrapQuantity; item.TransferQuantity = transferQuantity; CurrentOrder.Items.Add(item); // for inventory and inventory history ToolInventory inventory = SystemHelper.TMSContext.ToolInventories.FirstOrDefault(ti => ti.ToolID == item.ToolID); inventory.Tool = item.Tool; inventory.OutQuantity = inventory.OutQuantity - item.Quantity - item.TransferQuantity; ToolInventoryHistory inventoryHistory = SystemHelper.TMSContext.ToolInventoryHistories.CreateObject(); inventoryHistory.Customer = CurrentOrder.Customer; inventoryHistory.ToolInventoryHistoryDate = CurrentOrder.InboundDate; inventoryHistory.Tool = item.Tool; inventoryHistory.Quantity = item.Quantity + item.TransferQuantity; inventoryHistory.UnitPrice = item.UnitPrice; inventoryHistory.OutboundOrder = ReferenceOrder; inventoryHistory.OutboundOrderDetail = referenceItem; // for prescrap order if (item.PrescrapQuantity != 0) { ScrapOrderDetail scrapItem = new ScrapOrderDetail(); scrapItem.Tool = item.Tool; scrapItem.OutboundOrderDetail = item.OutboundOrderDetail; scrapItem.ScrapDate = item.InboundDate; scrapItem.PrescrapQuantity = item.PrescrapQuantity; scrapItem.UnitPrice = item.UnitPrice; scrapOrder.Items.Add(scrapItem); } } } if (scrapOrder.Items.Count > 0) { scrapOrder.OutboundOrder = CurrentOrder.OutboundOrder; scrapOrder.ScrapDate = CurrentOrder.InboundDate; scrapOrder.Customer = CurrentOrder.Customer; scrapOrder.SystemUser = CurrentOrder.SystemUser; scrapOrder.LastUpdateTime = CurrentOrder.LastUpdateTime; SystemHelper.TMSContext.AddToScrapOrders(scrapOrder); } SystemHelper.TMSContext.SaveChanges(); DialogResult = DialogResult.OK; }); }