Esempio n. 1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ScrapOrders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToScrapOrders(ScrapOrder scrapOrder)
 {
     base.AddObject("ScrapOrders", scrapOrder);
 }
Esempio n. 2
0
        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;
            });
        }
Esempio n. 3
0
 /// <summary>
 /// Create a new ScrapOrder object.
 /// </summary>
 /// <param name="scrapOrderID">Initial value of the ScrapOrderID property.</param>
 /// <param name="scrapDate">Initial value of the ScrapDate property.</param>
 /// <param name="code">Initial value of the Code property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 /// <param name="lastUpdatedBy">Initial value of the LastUpdatedBy property.</param>
 /// <param name="lastUpdateTime">Initial value of the LastUpdateTime property.</param>
 public static ScrapOrder CreateScrapOrder(global::System.Int32 scrapOrderID, global::System.DateTime scrapDate, global::System.String code, global::System.Int32 status, global::System.Int32 lastUpdatedBy, global::System.DateTime lastUpdateTime)
 {
     ScrapOrder scrapOrder = new ScrapOrder();
     scrapOrder.ScrapOrderID = scrapOrderID;
     scrapOrder.ScrapDate = scrapDate;
     scrapOrder.Code = code;
     scrapOrder.Status = status;
     scrapOrder.LastUpdatedBy = lastUpdatedBy;
     scrapOrder.LastUpdateTime = lastUpdateTime;
     return scrapOrder;
 }
Esempio n. 4
0
        private void LoadData()
        {
            SystemHelper.BindComboxToCustomer(cbCustomer);
            SystemHelper.BindComboxToSystemUser(cbSystemUser);

            // Set data object value
            if (CurrentOrder == null)
            {
                CurrentOrder = new ScrapOrder();
                CurrentMode = MODE_CREATESELF;
            }

            if (CurrentMode == MODE_CREATESELF)
            {
                CurrentOrder.Status = 1;
                CurrentOrder.SystemUser = SystemHelper.CurrentUser;
            }

            txtCode.Text = CurrentOrder.Code;
            dtScrapDate.Value = CurrentOrder.ScrapDate;

            cbCustomer.SelectedItem = CurrentOrder.Customer;
            cbSystemUser.SelectedItem = CurrentOrder.SystemUser;

            foreach (ScrapOrderDetail item in CurrentOrder.Items)
            {
                DataGridViewRow dgvr = new DataGridViewRow();
                object[] row = { item.ScrapOrderDetailID, item.Tool.Code, item.PrescrapQuantity, item.Tool.Name, item.Tool.Dimensions, item.Quantity, item.RepairingQuantity, item.ScrapQuantity, item.ScrapReason };
                dataGridViewDetail.Rows.Add(row);
            }
        }