Ejemplo n.º 1
0
    /// <summary>
    /// Force closes an order
    /// </summary>
    private void SubmitForceClose()
    {
        // Creates a list of outstanding items (StockItemID and quantity outstanding)
        List <OutstandingItem> outstandingItems = new List <OutstandingItem>();

        foreach (GridViewRow row in ReceivingItemsGridView.Rows)
        {
            // Adds row to the temporary list
            OutstandingItem item = new OutstandingItem();
            item.StockItemID         = int.Parse(row.Cells[0].Text);
            item.QuantityOutstanding = int.Parse(row.Cells[3].Text);

            outstandingItems.Add(item);
        }

        // Submits information
        ReceivingController controller = new ReceivingController();

        controller.CloseOrder(currentOrderId, ForceCloseReasonTextBox.Text.Trim(), outstandingItems);

        ClearAndRefreshPage();
    }
        protected void ReceiveShipment_Click(object sender, EventArgs e)
        {
            var receiveditems = new List <TransactionItemPOCO>();
            var rejecteditems = new List <RejectedItemPOCO>();

            int orderid = 0;

            GridViewRow orderrow = PurchaseOrderGridView.Rows[1];

            orderid = int.Parse((orderrow.FindControl("OrderID") as Label).Text);
            MessageUserControl.TryRun(() =>
            {
                foreach (GridViewRow row in PurchaseOrderGridView.Rows)
                {
                    if (int.Parse(((row.FindControl("QuantityOutstanding") as Label).Text).ToString()) > 0)
                    {
                        if (!int.TryParse(((row.FindControl("ReceivedUnitsBox") as TextBox).Text), out int receivecheck) || receivecheck <= 0)
                        {
                            throw new BusinessRuleException("Input Error", new List <String> {
                                "Received items must be an integer number greater than zero."
                            });
                        }
                        int salvageditems = 0;

                        int itemunitsize = int.Parse(((row.FindControl("ReceivedUnitsBox") as TextBox).Text));
                        int maxorder     = int.Parse(row.Cells[2].Text);
                        string itemname  = row.Cells[1].Text;
                        int itemquantity = int.Parse(((row.FindControl("UnitLabel") as Label).Text).ToString()) * itemunitsize;

                        if (string.IsNullOrEmpty(((row.FindControl("SalvagedItemsBox") as TextBox).Text)) == false)
                        {
                            if (!int.TryParse(((row.FindControl("SalvagedItemsBox") as TextBox).Text), out int salvagedcheck) || salvagedcheck <= 0)
                            {
                                throw new BusinessRuleException("Input Error", new List <String> {
                                    "Salvaged items must be an integer number greater than zero."
                                });
                            }
                            else if (itemquantity + int.Parse(((row.FindControl("SalvagedItemsBox") as TextBox).Text)) > maxorder)
                            {
                                throw new BusinessRuleException("Input Error", new List <String> {
                                    "Total Item quantity cannot be greater than the initial item order."
                                });
                            }
                            else
                            {
                                salvageditems = int.Parse(((row.FindControl("SalvagedItemsBox") as TextBox).Text));
                                itemquantity  = itemquantity + salvageditems;
                            }
                        }

                        itemquantity = itemquantity + salvageditems;

                        if (!string.IsNullOrEmpty((row.FindControl("RejectedUnitsBox") as TextBox).Text) && !string.IsNullOrEmpty((row.FindControl("RejectedReason") as TextBox).Text))
                        {
                            if (!int.TryParse(((row.FindControl("RejectedUnitsBox") as TextBox).Text), out int rejectedcheck) || rejectedcheck <= 0)
                            {
                                throw new BusinessRuleException("Input Error", new List <String> {
                                    "Rejected items must be an integer number greater than zero."
                                });
                            }
                            else if (int.TryParse(((row.FindControl("RejectedReasons") as TextBox).Text), out int rejected))
                            {
                                throw new BusinessRuleException("Input Error", new List <String> {
                                    "Reason for rejection cannot be a number."
                                });
                            }
                            else
                            {
                                int rejectitems = int.Parse((row.FindControl("RejectedUnitsBox") as TextBox).Text);
                                string reasons  = (row.FindControl("RejectedReason") as TextBox).ToString();

                                rejecteditems.Add(new RejectedItemPOCO()
                                {
                                    ItemName     = itemname,
                                    ItemQuantity = rejectitems,
                                    Reason       = reasons
                                });
                            }
                        }

                        receiveditems.Add(new TransactionItemPOCO()
                        {
                            ItemName     = itemname,
                            ItemQuantity = itemquantity
                        });
                    }
                }
            });

            MessageUserControl.TryRun(() =>
            {
                ReceivingController sysmgr = new ReceivingController();

                sysmgr.ReceiveShipment(orderid, receiveditems, rejecteditems);
            }, "Transaction Processed", "Order Received Successfully"
                                      );


            PurchaseOrderGridView.DataBind();
            int remainingitems = 0;

            foreach (GridViewRow row in PurchaseOrderGridView.Rows)
            {
                remainingitems = remainingitems + int.Parse(((row.FindControl("QuantityOutstanding") as Label).Text).ToString());
            }

            if (remainingitems == 0)
            {
                MessageUserControl.TryRun(() => {
                    ReceivingController sysmgr = new ReceivingController();
                    sysmgr.CloseOrder(orderid);
                }, "Order Complete", "This Order will now be closed");

                Response.Redirect(Request.RawUrl);
                MessageUserControl.TryRun(() => { }, "Order Complete", "The Order was closed. Please select a new one.");
            }
        }