Exemplo n.º 1
0
        //-----------------------------------------------------------------------------------------------------------

        protected void btnUpdateOrders_Click(object sender, EventArgs e)
        {
            // Find out if we need to create a new instruction, if all the orders have been selected then we can
            // change the instructions point and all the orders delivery points without adding a new instruction.

            // if some orders are left on the existing instruction then we need to remove the selected orders from
            // the current instruction and create a new instruction based on the new delivery details.
            // Then add the selected orders to the newly created instruction.

            // Ensure that all points are created.

            if (this.cboNewDeliveryPoint.PointID < 1)
            {
                this.lblError.Text = "Please select a Point.";
            }
            else
            {
                this.lblError.Text = String.Empty;
                Facade.IOrder        facorder       = new Facade.Order();
                Facade.IInstruction  facInstruction = new Facade.Instruction();
                Entities.Instruction instruction    = null;

                List <int> orderIds      = new List <int>();
                int        instructionId = -1;
                int        runId         = -1;

                foreach (GridDataItem item in grdOrders.Items)
                {
                    if (instructionId == -1)
                    {
                        Label lblInstruction = (Label)item.FindControl("lblInstructionId");
                        int.TryParse(lblInstruction.Text, out instructionId);
                    }
                    if (runId == -1)
                    {
                        HyperLink hypRun = (HyperLink)item.FindControl("hypRun");
                        int.TryParse(hypRun.Text, out runId);
                    }

                    CheckBox chkOrderId = (CheckBox)item.FindControl("chkSelectOrder");
                    int      orderId;
                    int.TryParse(chkOrderId.Attributes["OrderID"].ToString(), out orderId);

                    if (chkOrderId.Checked)
                    {
                        orderIds.Add(int.Parse(chkOrderId.Attributes["OrderID"].ToString()));
                    }
                }

                instruction = facInstruction.GetInstruction(instructionId);

                if (instruction != null)
                {
                    Facade.IJob  facJob = new Facade.Job();
                    Entities.Job run    = facJob.GetJob(runId, true);

                    if (orderIds.Count == this.grdOrders.Items.Count)
                    {
                        ChangeExistingInstruction(instruction, run, orderIds);

                        List <Entities.Instruction> amendedInstructions = new List <Orchestrator.Entities.Instruction>();
                        amendedInstructions.Add(instruction);
                        // Commit the action.
                        Entities.FacadeResult    retVal = null;
                        Entities.CustomPrincipal user   = (Entities.CustomPrincipal)Page.User;

                        retVal = facJob.AmendInstructions(run, amendedInstructions, eLegTimeAlterationMode.Enforce_Booked_Times, user.Name);
                    }
                    else
                    {
                        List <Entities.Instruction> amendedInstructions = new List <Orchestrator.Entities.Instruction>();

                        Facade.IOrder facOrder = new Facade.Order();
                        BusinessLogicLayer.ICollectDrop busCollectDrop = new BusinessLogicLayer.CollectDrop();

                        using (TransactionScope tran = new TransactionScope())
                        {
                            foreach (int ordId in orderIds)
                            {
                                Entities.Order currentOrder = facOrder.GetForOrderID(ordId);

                                Entities.CollectDrop collectDrop = instruction.CollectDrops.Find(i => i.OrderID == currentOrder.OrderID);
                                busCollectDrop.Delete(collectDrop, this.Page.User.Identity.Name);

                                this.AddNewDropInstruction(currentOrder, run, amendedInstructions);
                            }

                            // Commit the action.
                            Entities.FacadeResult    retVal = null;
                            Entities.CustomPrincipal user   = (Entities.CustomPrincipal)Page.User;

                            retVal = facJob.AmendInstructions(run, amendedInstructions, eLegTimeAlterationMode.Enforce_Booked_Times, user.Name);
                            if (retVal.Success)
                            {
                                tran.Complete();
                            }
                        }
                    }
                }

                this.grdOrders.DataSource = null;
                this.grdOrders.Rebind();
            }
        }
Exemplo n.º 2
0
        //private void MessageBox(string msg)
        //{
        //    Label lbl = new Label();
        //    lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
        //    Page.Controls.Add(lbl);
        //}

        private void btnConfirmDropConversion_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                var facPoint = new Facade.Point();

                // Get the point to trunk to.
                var trunkPoint = facPoint.GetPointForPointId(ucPoint.PointID);;

                // Configure the instructions.
                var dropInstruction = GetInstruction();
                Entities.Instruction trunkInstruction = new Entities.Instruction(eInstructionType.Trunk, dropInstruction.JobId, String.Empty);
                trunkInstruction.BookedDateTime            = dropInstruction.BookedDateTime;
                trunkInstruction.IsAnyTime                 = dropInstruction.IsAnyTime;
                trunkInstruction.PointID                   = trunkPoint.PointId;
                trunkInstruction.Point                     = trunkPoint;
                trunkInstruction.CollectDrops              = new Entities.CollectDropCollection();
                trunkInstruction.ClientsCustomerIdentityID = trunkPoint.IdentityId;

                // Process the collect drops.
                for (int collectDropIndex = 0; collectDropIndex < dropInstruction.CollectDrops.Count; collectDropIndex++)
                {
                    var cd = dropInstruction.CollectDrops[collectDropIndex];

                    // If the order can be moved from the drop to the trunk do so.
                    if (CanBeRemovedFromDrop(dropInstruction, cd.Order))
                    {
                        cd.CollectDropId = 0;
                        cd.InstructionID = trunkInstruction.InstructionID;
                        cd.OrderAction   = eOrderAction.Cross_Dock;
                        trunkInstruction.CollectDrops.Add(cd);
                        dropInstruction.CollectDrops.RemoveAt(collectDropIndex);
                        collectDropIndex--;
                    }
                }

                if (trunkInstruction.CollectDrops.Count > 0)
                {
                    // Alter the job.
                    Facade.IJob facJob       = new Facade.Job();
                    var         job          = facJob.GetJob(dropInstruction.JobId, true, true);
                    var         instructions = new List <Entities.Instruction>()
                    {
                        dropInstruction, trunkInstruction
                    };
                    Entities.CustomPrincipal user = Page.User as Entities.CustomPrincipal;
                    var result = facJob.AmendInstructions(job, instructions, eLegTimeAlterationMode.Minimal, user.UserName);

                    if (result.Success)
                    {
                        // Close this window and refresh the parent window.
                        this.ReturnValue = "refresh";
                        this.Close();
                    }
                }
                else
                {
                    // No action to take - close this window.
                    if (String.IsNullOrEmpty(errorMessage))
                    {
                        this.ReturnValue = "refresh";
                        this.Close();
                    }
                    else
                    {
                        //System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Please see the Message in the " +
                        //"Table for more information", "Error",
                        //    System.Windows.Forms.MessageBoxButtons.OK);
                        ClientScript.RegisterStartupScript(GetType(), "Error", "alert('Please see the message in the Table for more information');", true);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void AddOrderToRun(int orderId, int runId)
        {
            CustomPrincipal customPrincipal = (Entities.CustomPrincipal)Page.User;
            string          userName        = customPrincipal.UserName;

            Facade.IJob  facJob = new Facade.Job();
            Entities.Job job    = new Orchestrator.Entities.Job();
            job = facJob.GetJob(runId, true, true);

            Entities.InstructionCollection collections           = new Orchestrator.Entities.InstructionCollection();
            Entities.Instruction           collectionInstruction = null;
            Entities.CollectDrop           cd;

            Entities.InstructionCollection deliveries          = new Orchestrator.Entities.InstructionCollection();
            Entities.Instruction           deliveryInstruction = null;

            Facade.IPoint  facPoint = new Facade.Point();
            Facade.IOrder  facOrder = new Facade.Order();
            Entities.Point point;
            Entities.Order order = facOrder.GetForOrderID(orderId);

            int      pointID             = order.CollectionPointID;
            DateTime bookedDateTime      = order.CollectionDateTime;
            bool     collectionIsAnyTime = order.CollectionIsAnytime;

            // if this setting is true then we want to create a new instruction for the order.
            if (Globals.Configuration.OneDropAndLoadInstructionPerOrder)
            {
                collectionInstruction = null;
            }
            else
            {
                collectionInstruction = job.Instructions.GetForInstructionTypeAndPointID(eInstructionType.Load, pointID, bookedDateTime, collectionIsAnyTime);
            }

            if (collectionInstruction == null)
            {
                collectionInstruction = new Orchestrator.Entities.Instruction();
                collectionInstruction.InstructionTypeId = (int)eInstructionType.Load;
                collectionInstruction.BookedDateTime    = bookedDateTime;
                if (collectionIsAnyTime)
                {
                    collectionInstruction.IsAnyTime = true;
                }
                point = facPoint.GetPointForPointId(pointID);
                collectionInstruction.PointID = pointID;
                collectionInstruction.Point   = point;
                collectionInstruction.ClientsCustomerIdentityID = point.IdentityId;
                collectionInstruction.CollectDrops     = new Orchestrator.Entities.CollectDropCollection();
                collectionInstruction.InstructionOrder = 0;
            }

            cd = new Orchestrator.Entities.CollectDrop();
            cd.PalletTypeID             = order.PalletTypeID;
            cd.NoPallets                = order.NoPallets;
            cd.NoCases                  = order.Cases;
            cd.GoodsTypeId              = order.GoodsTypeID;
            cd.OrderID                  = order.OrderID;
            cd.OrderAction              = eOrderAction.Default;
            cd.Weight                   = order.Weight;
            cd.ClientsCustomerReference = order.DeliveryOrderNumber;
            cd.Docket                   = order.OrderID.ToString();

            collectionInstruction.CollectDrops.Add(cd);
            collections.Add(collectionInstruction);

            eOrderAction orderAction       = eOrderAction.Default;
            int          deliveryPointID   = order.DeliveryPointID;
            DateTime     deliveryDateTime  = order.DeliveryDateTime;
            bool         deliveryIsAnyTime = order.DeliveryIsAnytime;

            // if this setting is true then we want to create a new instruction for the order.
            if (Globals.Configuration.OneDropAndLoadInstructionPerOrder)
            {
                deliveryInstruction = null;
            }
            else
            {
                deliveryInstruction = job.Instructions.GetForInstructionTypeAndPointID(eInstructionType.Drop, deliveryPointID, deliveryDateTime, deliveryIsAnyTime);
            }

            if (deliveryInstruction == null)
            {
                deliveryInstruction = new Orchestrator.Entities.Instruction();
                deliveryInstruction.InstructionTypeId = (int)eInstructionType.Drop;
                deliveryInstruction.BookedDateTime    = deliveryDateTime;
                if (deliveryIsAnyTime)
                {
                    deliveryInstruction.IsAnyTime = true;
                }
                point = facPoint.GetPointForPointId(deliveryPointID);
                deliveryInstruction.ClientsCustomerIdentityID = point.IdentityId;
                deliveryInstruction.PointID = deliveryPointID;
                deliveryInstruction.Point   = point;

                deliveryInstruction.CollectDrops     = new Orchestrator.Entities.CollectDropCollection();
                deliveryInstruction.InstructionOrder = 0;
            }

            cd = new Orchestrator.Entities.CollectDrop();
            cd.PalletTypeID             = order.PalletTypeID;
            cd.NoPallets                = order.NoPallets;
            cd.NoCases                  = order.Cases;
            cd.GoodsTypeId              = order.GoodsTypeID;
            cd.OrderID                  = order.OrderID;
            cd.Weight                   = order.Weight;
            cd.ClientsCustomerReference = order.DeliveryOrderNumber;
            cd.Docket                   = order.OrderID.ToString();
            cd.OrderAction              = orderAction;

            deliveryInstruction.CollectDrops.Add(cd);
            deliveries.Add(deliveryInstruction);

            facOrder.UpdateForCollectionRun(cd.OrderID, deliveryInstruction.PointID, deliveryInstruction.BookedDateTime, deliveryInstruction.IsAnyTime, cd.OrderAction, userName);

            List <Instruction> instructions = new List <Instruction>();

            Entities.CollectDropCollection orderedCollectDrops = new CollectDropCollection();

            for (int i = 0; i < collections.Count; i++)
            {
                orderedCollectDrops = new CollectDropCollection();
                int pos = 0;
                foreach (Entities.CollectDrop orderedCD in collections[i].CollectDrops)
                {
                    if (orderedCollectDrops.Count == 0)
                    {
                        orderedCollectDrops.Add(orderedCD);
                    }
                    else
                    {
                        for (int x = 0; x < orderedCollectDrops.Count; x++)
                        {
                            if (orderedCD.OrderID > orderedCollectDrops[x].OrderID)
                            {
                                pos = x + 1;
                            }
                        }
                        orderedCollectDrops.Insert(pos, orderedCD);
                    }
                }
                collections[i].CollectDrops = orderedCollectDrops;
                instructions.Add(collections[i]);
            }

            Entities.InstructionCollection orderedInstructions = new InstructionCollection();
            for (int i = 0; i < deliveries.Count; i++)
            {
                int pos = 0;
                if (orderedInstructions.Count == 0)
                {
                    orderedInstructions.Add(deliveries[i]);
                }
                else
                {
                    for (int y = 0; y < orderedInstructions.Count; y++)
                    {
                        if (deliveries[i].CollectDrops[0].OrderID > orderedInstructions[y].CollectDrops[0].OrderID)
                        {
                            pos = y + 1;
                        }
                    }
                    orderedInstructions.Insert(pos, deliveries[i]);
                }
            }

            foreach (Entities.Instruction ins in orderedInstructions)
            {
                instructions.Add(ins);
            }

            facJob.AmendInstructions(job, instructions, eLegTimeAlterationMode.Minimal, userName);
        }
Exemplo n.º 4
0
        void btnConfirmTrunkConversion_Click(object sender, EventArgs e)
        {
            var dropInstructions = new Dictionary <int, Entities.Instruction>();
            var facPoint         = new Facade.Point();

            // Configure the instructions.
            var trunkInstruction = GetInstruction();

            // Process the collect drops.
            for (int collectDropIndex = 0; collectDropIndex < trunkInstruction.CollectDrops.Count; collectDropIndex++)
            {
                var cd = trunkInstruction.CollectDrops[collectDropIndex];

                // If the order can be moved from the drop to the trunk do so.
                if (CanBeRemovedFromTrunk(trunkInstruction, cd.Order))
                {
                    Entities.Instruction dropInstruction;
                    if (!dropInstructions.TryGetValue(cd.Order.DeliveryPointID, out dropInstruction))
                    {
                        var deliveryPoint = facPoint.GetPointForPointId(cd.Order.DeliveryPointID);
                        dropInstruction = new Entities.Instruction(eInstructionType.Drop, trunkInstruction.JobId, String.Empty);
                        dropInstruction.BookedDateTime            = trunkInstruction.BookedDateTime;
                        dropInstruction.IsAnyTime                 = trunkInstruction.IsAnyTime;
                        dropInstruction.PointID                   = deliveryPoint.PointId;
                        dropInstruction.Point                     = deliveryPoint;
                        dropInstruction.CollectDrops              = new Entities.CollectDropCollection();
                        dropInstruction.ClientsCustomerIdentityID = deliveryPoint.IdentityId;
                        dropInstructions.Add(cd.Order.DeliveryPointID, dropInstruction);
                    }

                    cd.CollectDropId = 0;
                    cd.InstructionID = dropInstruction.InstructionID;
                    cd.OrderAction   = eOrderAction.Cross_Dock;
                    dropInstruction.CollectDrops.Add(cd);
                    trunkInstruction.CollectDrops.RemoveAt(collectDropIndex);
                    collectDropIndex--;
                }
            }

            if (dropInstructions.Count > 0)
            {
                // Alter the job.
                Facade.IJob facJob       = new Facade.Job();
                var         job          = facJob.GetJob(trunkInstruction.JobId, true, true);
                var         instructions = new List <Entities.Instruction>()
                {
                    trunkInstruction
                };
                instructions.AddRange(dropInstructions.Values);
                Entities.CustomPrincipal user = Page.User as Entities.CustomPrincipal;
                var result = facJob.AmendInstructions(job, instructions, eLegTimeAlterationMode.Minimal, user.UserName);

                if (result.Success)
                {
                    // Close this window and refresh the parent window.
                    this.ReturnValue = "refresh";
                    this.Close();
                }
            }
            else
            {
                // No action to take - close this window.
                this.ReturnValue = "refresh";
                this.Close();
            }
        }