Example #1
0
        //-----------------------------------------------------------------------------------------------------------

        private void AddNewDropInstruction(Entities.Order currentOrder, Entities.Job run, List <Entities.Instruction> amendedInstructions)
        {
            Facade.IPoint facPoint = new Facade.Point();

            // Load the job's current state.
            Facade.IJob facJob = new Facade.Job();

            #region Configure the end instruction.
            Entities.Instruction endInstruction = null;
            if (amendedInstructions.Count > 0)
            {
                endInstruction = amendedInstructions[0];
            }
            else
            {
                endInstruction = run.Instructions.Find(i => i.InstructionTypeId == (int)eInstructionType.Drop && i.PointID == this.cboNewDeliveryPoint.PointID);
            }

            // Can a matching instruction be found on the job after the start instruction?
            //endInstruction = job.Instructions.Find(i => i.InstructionOrder > startInstruction.InstructionOrder && i.InstructionTypeId == (int)untetheredLocations.EndInstructionType.Value && i.PointID == untetheredLocations.EndPointID.Value && !i.HasActual);
            if (endInstruction == null)
            {
                // A new instruction is required.
                endInstruction                   = new Orchestrator.Entities.Instruction();
                endInstruction.PointID           = this.cboNewDeliveryPoint.PointID;
                endInstruction.Point             = facPoint.GetPointForPointId(this.cboNewDeliveryPoint.PointID);
                endInstruction.InstructionTypeId = (int)eInstructionType.Drop;

                if (this.dteDeliveryByDate.SelectedDate.HasValue)
                {
                    endInstruction.BookedDateTime           = this.dteDeliveryByDate.SelectedDate.Value;
                    endInstruction.PlannedArrivalDateTime   = this.dteDeliveryByDate.SelectedDate.Value;
                    endInstruction.PlannedDepartureDateTime = this.dteDeliveryByDate.SelectedDate.Value;
                }
                else
                {
                    endInstruction.BookedDateTime           = currentOrder.DeliveryDateTime;
                    endInstruction.PlannedArrivalDateTime   = currentOrder.DeliveryDateTime;
                    endInstruction.PlannedDepartureDateTime = currentOrder.DeliveryDateTime;
                }

                if (this.rdDeliveryIsAnytime.Checked)
                {
                    endInstruction.IsAnyTime = true;
                }
                else
                {
                    endInstruction.IsAnyTime = false;
                }

                endInstruction.JobId = run.JobId;
                endInstruction.ClientsCustomerIdentityID = currentOrder.CustomerIdentityID;

                // Record that this instruction has been amended.
                amendedInstructions.Add(endInstruction);
            }
            else
            if (amendedInstructions.Count == 0)
            {
                amendedInstructions.Add(endInstruction);
            }

            // Add the collect drop for this order to the instruction.
            Entities.CollectDrop endCollectDrop = new Entities.CollectDrop();
            endCollectDrop.Order     = currentOrder;
            endCollectDrop.OrderID   = currentOrder.OrderID;
            endCollectDrop.NoPallets = currentOrder.NoPallets;
            endCollectDrop.ClientsCustomerReference = currentOrder.CustomerOrderNumber;
            endCollectDrop.GoodsTypeId = currentOrder.GoodsTypeID;
            endCollectDrop.NoCases     = currentOrder.Cases;
            endCollectDrop.Weight      = currentOrder.Weight;
            endCollectDrop.Docket      = currentOrder.OrderID.ToString();

            endCollectDrop.OrderAction = eOrderAction.Default;
            endInstruction.CollectDrops.Add(endCollectDrop);

            this.UpdateOrder(currentOrder);
            #endregion
        }
Example #2
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();
            }
        }
Example #3
0
        private void PopulateEntities()
        {
            Entities.Job job = new Orchestrator.Entities.Job();
            job.Instructions           = new Orchestrator.Entities.InstructionCollection();
            job.JobType                = eJobType.Groupage;
            job.BusinessTypeID         = int.Parse(cboBusinessType.SelectedValue);
            job.IdentityId             = Globals.Configuration.IdentityId;
            job.LoadNumber             = "GRP" + Environment.TickCount.ToString().Substring(0, 3);
            job.Charge                 = new Orchestrator.Entities.JobCharge();
            job.Charge.JobChargeAmount = 0;
            job.Charge.JobChargeType   = eJobChargeType.FreeOfCharge;

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

            Entities.InstructionCollection drops = new Orchestrator.Entities.InstructionCollection();
            Entities.Instruction           iDrop = null;

            Facade.IPoint  facPoint = new Facade.Point();
            Facade.IOrder  facOrder = new Facade.Order();
            Entities.Point point    = null;

            bool newcollection = false;

            foreach (DataRow row in OrderData.Tables[0].Rows)
            {
                #region Collections
                newcollection = false;
                int      pointID             = (int)row["CollectFromPointID"];
                DateTime bookedDateTime      = (DateTime)row["CollectAtDateTime"];
                bool     collectionIsAnytime = (bool)row["CollectAtAnyTime"];

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

                if (iCollect == null)
                {
                    iCollect = new Orchestrator.Entities.Instruction();
                    iCollect.InstructionTypeId = (int)eInstructionType.Load;
                    iCollect.BookedDateTime    = bookedDateTime;
                    if ((bool)row["CollectAtAnytime"])
                    {
                        iCollect.IsAnyTime = true;
                    }
                    point            = facPoint.GetPointForPointId(pointID);
                    iCollect.PointID = pointID;
                    iCollect.Point   = point;
                    iCollect.ClientsCustomerIdentityID = point.IdentityId; //Steve is this correct
                    iCollect.CollectDrops = new Orchestrator.Entities.CollectDropCollection();
                    newcollection         = true;
                }

                cd             = new Orchestrator.Entities.CollectDrop();
                cd.NoPallets   = (int)row["NoPallets"];
                cd.NoCases     = (int)row["Cases"];
                cd.GoodsTypeId = (int)row["GoodsTypeID"];
                cd.OrderID     = (int)row["OrderID"];
                cd.Weight      = (decimal)row["Weight"];
                cd.ClientsCustomerReference = row["DeliveryOrderNumber"].ToString();
                cd.Docket = row["OrderID"].ToString();

                iCollect.CollectDrops.Add(cd);
                if (newcollection)
                {
                    collections.Add(iCollect);
                }

                #endregion
            }

            // Add the Drops in the Order specified
            DataView dvDrops = OrderData.Tables[0].DefaultView;
            dvDrops.Sort = "DeliveryOrder ASC";
            DataTable dtDrops = dvDrops.ToTable();
            foreach (DataRow row in dtDrops.Rows)
            {
                #region Deliveries
                bool newdelivery = false;
                newdelivery = false;
                int      deliveryPointID   = (int)row["DeliveryPointID"];
                DateTime deliveryDateTime  = (DateTime)row["DeliveryDateTime"];
                bool     deliveryIsAnyTime = (bool)row["DeliveryIsAnyTime"];

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

                if (iDrop == null)
                {
                    iDrop = new Orchestrator.Entities.Instruction();
                    iDrop.InstructionTypeId = (int)eInstructionType.Drop;
                    iDrop.BookedDateTime    = deliveryDateTime;
                    if ((bool)row["DeliveryIsAnytime"])
                    {
                        iDrop.IsAnyTime = true;
                    }
                    point = facPoint.GetPointForPointId(deliveryPointID);
                    iDrop.ClientsCustomerIdentityID = point.IdentityId;
                    iDrop.PointID = deliveryPointID;
                    iDrop.Point   = point;

                    iDrop.CollectDrops = new Orchestrator.Entities.CollectDropCollection();
                    newdelivery        = true;
                }

                cd             = new Orchestrator.Entities.CollectDrop();
                cd.NoPallets   = (int)row["NoPallets"];
                cd.NoCases     = (int)row["Cases"];
                cd.GoodsTypeId = (int)row["GoodsTypeID"];
                cd.OrderID     = (int)row["OrderID"];
                cd.Weight      = (decimal)row["Weight"];
                cd.ClientsCustomerReference = row["DeliveryOrderNumber"].ToString();
                cd.Docket = row["OrderID"].ToString();

                iDrop.CollectDrops.Add(cd);
                if (newdelivery)
                {
                    drops.Add(iDrop); //Stephen Newman 23/04/07 Changed to insert the drop to the front of the list as the sort processed later seems to swap objects if equal.
                }
                facOrder.UpdateForDeliveryRun(cd.OrderID, iCollect.PointID, iCollect.BookedDateTime, iCollect.IsAnyTime, Page.User.Identity.Name);

                #endregion
            }



            #region Add the Instructions to the job

            if (job.Instructions == null)
            {
                job.Instructions = new Entities.InstructionCollection();
            }

            foreach (Entities.Instruction instruction in collections)
            {
                job.Instructions.Add(instruction);
            }

            // removed by t.lunken 23/08/07 as this is now manually done.
            //drops.Sort(eInstructionSortType.DropDateTime);
            foreach (Entities.Instruction instruction in drops)
            {
                job.Instructions.Add(instruction);
            }
            #endregion

            Facade.IJob facjob = new Facade.Job();
            job.JobState = eJobState.Booked;
            int jobID = facjob.Create(job, Page.User.Identity.Name);
            _jobID   = jobID;
            _openJob = true;
        }
Example #4
0
        /// <summary>
        /// The docket number entered must not appear on any other collection in the job.
        /// </summary>
        private void cfvDocket_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = true;

            // This validation only applies for load instructions, drops do not allow the collect drop docket number to be altered.
            if (m_instruction.InstructionTypeId == (int)eInstructionType.Load)
            {
                if (m_isUpdate)
                {
                    // See if the docket number can be found in any of the collections in m_job.
                    foreach (Entities.Instruction instruction in m_job.Instructions)
                    {
                        if (instruction.InstructionTypeId == (int)eInstructionType.Load && instruction.InstructionID != m_instruction.InstructionID)
                        {
                            foreach (Entities.CollectDrop collect in instruction.CollectDrops)
                            {
                                if (collect.Docket == txtDocket.Text)
                                {
                                    args.IsValid = false;
                                }
                            }
                        }
                    }

                    // See if the docket number can be found in the current instruction.
                    for (int collectIndex = 0; collectIndex < m_instruction.CollectDrops.Count; collectIndex++)
                    {
                        if (collectIndex != m_collectDropIndex)
                        {
                            Entities.CollectDrop thisCollect = m_instruction.CollectDrops[collectIndex];

                            if (thisCollect.Docket == txtDocket.Text)
                            {
                                args.IsValid = false;
                            }
                        }
                    }
                }
                else
                {
                    int currentInstructionIndex = (int)Session[wizard.C_INSTRUCTION_INDEX];

                    // See if the docket number can be found in any of the collections in m_job.Instructions
                    for (int instructionIndex = 0; instructionIndex < m_job.Instructions.Count; instructionIndex++)
                    {
                        Entities.Instruction instruction = m_job.Instructions[instructionIndex];

                        if (instruction.InstructionTypeId == (int)eInstructionType.Load && instructionIndex != currentInstructionIndex)
                        {
                            for (int collectIndex = 0; collectIndex < instruction.CollectDrops.Count; collectIndex++)
                            {
                                Entities.CollectDrop thisCollect = instruction.CollectDrops[collectIndex];

                                if (thisCollect.Docket == txtDocket.Text)
                                {
                                    if (instructionIndex != currentInstructionIndex || collectIndex != m_collectDropIndex)
                                    {
                                        args.IsValid = false;
                                    }
                                }
                            }
                        }
                    }

                    // See if the docket can be found in the current instruction
                    for (int collectIndex = 0; collectIndex < m_instruction.CollectDrops.Count; collectIndex++)
                    {
                        if (collectIndex != m_collectDropIndex)
                        {
                            Entities.CollectDrop thisCollect = m_instruction.CollectDrops[collectIndex];

                            if (thisCollect.Docket == txtDocket.Text)
                            {
                                args.IsValid = false;
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            m_jobId = Convert.ToInt32(Request.QueryString["jobId"]);

            if (m_jobId > 0)
            {
                m_isUpdate = true;
            }

            // Retrieve the job from the session variable
            m_job         = (Entities.Job)Session[wizard.C_JOB];
            m_instruction = (Entities.Instruction)Session[wizard.C_INSTRUCTION];

            if (Session[wizard.C_COLLECT_DROP_INDEX] != null)
            {
                m_collectDropIndex = (int)Session[wizard.C_COLLECT_DROP_INDEX];

                if (m_collectDropIndex != m_instruction.CollectDrops.Count)
                {
                    m_isAmendment = true;

                    // You can only add a docket at the end
                    if (m_collectDropIndex < m_instruction.CollectDrops.Count - 1)
                    {
                        chkAddAnotherDocket.Visible = false;
                    }
                }
            }

            if (!IsPostBack)
            {
                btnNext.Attributes.Add("onClick", "javascript:HidePage();");
                btnCancel.Attributes.Add("onClick", wizard.C_CONFIRM_MESSAGE);



                // Do not show the remove docket button for the only docket in each collection/drop - they must delete the instruction to
                // remove all dockets.
                btnRemoveDocket.Visible = m_instruction.CollectDrops.Count > 1 || m_collectDropIndex == m_instruction.CollectDrops.Count;

                ConfigureDocketTerminology();

                // Details of added Dockets
                repDockets.DataSource = m_instruction.CollectDrops;
                repDockets.DataBind();

                dteBookedDate.SelectedDate = m_instruction.BookedDateTime;
                if (m_instruction.IsAnyTime)
                {
                    dteBookedTime.Text = "AnyTime";
                }
                else
                {
                    dteBookedTime.SelectedDate = m_instruction.BookedDateTime;
                }

                if (Session[wizard.C_COLLECT_DROP] != null)
                {
                    m_collectdrop = (Entities.CollectDrop)Session[wizard.C_COLLECT_DROP];
                }
                else
                {
                    m_collectdrop = new Entities.CollectDrop();
                    m_collectdrop.InstructionID = m_instruction.InstructionID;

                    Session[wizard.C_COLLECT_DROP]       = m_collectdrop;
                    Session[wizard.C_COLLECT_DROP_INDEX] = m_instruction.CollectDrops.Count;
                }

                switch ((eInstructionType)m_instruction.InstructionTypeId)
                {
                case eInstructionType.Load:
                    lblCollection.Visible     = true;
                    chkAddAnotherDocket.Text += "collection.";
                    lblDelivery.Visible       = false;
                    trSelectDocket.Visible    = false;
                    lblCollectDrop.Text       = "Collection Details";
                    if (!m_isAmendment && m_collectDropIndex == 0)
                    {
                        dteBookedDate.Text = DateTime.UtcNow.ToString("dd/MM/yy");
                    }
                    break;

                case eInstructionType.Drop:
                    lblCollection.Visible     = false;
                    chkAddAnotherDocket.Text += "delivery.";
                    lblDelivery.Visible       = true;
                    trSelectDocket.Visible    = true;

                    // Stop the user from editing the docket information
                    txtDocket.Enabled        = false;
                    txtQuantityCases.Enabled = false;
                    txtPallets.Enabled       = false;
                    txtWeight.Enabled        = false;
                    lblCollectDrop.Text      = "Delivery Details";
                    cboGoodsType.Enabled     = false;

                    // Populate the dockets
                    PopulateDockets();
                    break;
                }

                if (m_collectdrop != null)
                {
                    if (m_isUpdate)
                    {
                        cboGoodsType.DataSource = Facade.GoodsType.GetGoodsTypesForClientAndCollectDrop(m_job.IdentityId, m_collectdrop.CollectDropId);
                    }
                    else
                    {
                        cboGoodsType.DataSource = Facade.GoodsType.GetGoodsTypesForClient(m_job.IdentityId);
                    }
                    cboGoodsType.DataBind();

                    // Populate the collect drop information onto the form
                    txtDocket.Text        = m_collectdrop.Docket;
                    txtQuantityCases.Text = (m_collectdrop.NoCases == 0 && !m_isAmendment) ? "" : m_collectdrop.NoCases.ToString();
                    txtPallets.Text       = (m_collectdrop.NoPallets == 0 && !m_isAmendment) ? "" : m_collectdrop.NoPallets.ToString();
                    txtWeight.Text        = (m_collectdrop.Weight == 0 && !m_isAmendment) ? "" : m_collectdrop.Weight.ToString();
                    if (m_isAmendment || m_isUpdate)
                    {
                        cboGoodsType.ClearSelection();
                        ListItem item = cboGoodsType.Items.FindByValue(m_collectdrop.GoodsTypeId.ToString());
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                    txtNotes.Text = m_instruction.Note;
                }
            }
            else
            {
                m_collectdrop = (Entities.CollectDrop)Session[wizard.C_COLLECT_DROP];
            }
        }
Example #6
0
        private ListItem DocketItem(Entities.CollectDrop collectDrop)
        {
            ListItem li = new ListItem(collectDrop.Docket, collectDrop.Docket);

            return(li);
        }
Example #7
0
        private void PopulateEntities()
        {
            Entities.Job job = new Orchestrator.Entities.Job();
            job.Instructions           = new Orchestrator.Entities.InstructionCollection();
            job.JobType                = eJobType.Groupage;
            job.BusinessTypeID         = int.Parse(cboBusinessType.SelectedValue);
            job.IdentityId             = Globals.Configuration.IdentityId;
            job.LoadNumber             = "GRP" + Environment.TickCount.ToString().Substring(0, 3);
            job.Charge                 = new Orchestrator.Entities.JobCharge();
            job.Charge.JobChargeAmount = 0;
            job.Charge.JobChargeType   = eJobChargeType.FreeOfCharge;

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

            Entities.InstructionCollection drops = new Orchestrator.Entities.InstructionCollection();
            Entities.Instruction           iDrop = null;

            Facade.IPoint  facPoint = new Facade.Point();
            Facade.IOrder  facOrder = new Facade.Order();
            Entities.Point point    = null;

            int  collectSequence = 1;
            bool newcollection   = false;

            foreach (DataRow row in OrderData.Tables[0].Rows)
            {
                #region Collections
                newcollection = false;
                int      pointID             = (int)row["CollectionRunDeliveryPointID"];
                DateTime bookedDateTime      = (DateTime)row["CollectionRunDeliveryDateTime"];
                bool     collectionIsAnyTime = (bool)row["CollectionRunDeliveryIsAnyTime"];

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

                if (iCollect == null)
                {
                    iCollect = new Orchestrator.Entities.Instruction();
                    iCollect.InstructionTypeId = (int)eInstructionType.Load;
                    iCollect.BookedDateTime    = bookedDateTime;
                    if (collectionIsAnyTime)
                    {
                        iCollect.IsAnyTime = true;
                    }
                    point            = facPoint.GetPointForPointId(pointID);
                    iCollect.PointID = pointID;
                    iCollect.Point   = point;
                    iCollect.ClientsCustomerIdentityID = point.IdentityId; //Steve is this correct
                    iCollect.CollectDrops     = new Orchestrator.Entities.CollectDropCollection();
                    iCollect.InstructionOrder = collectSequence;
                    newcollection             = true;
                    collectSequence++;
                }

                cd             = new Orchestrator.Entities.CollectDrop();
                cd.NoPallets   = (int)row["NoPallets"];
                cd.NoCases     = (int)row["Cases"];
                cd.GoodsTypeId = (int)row["GoodsTypeID"];
                cd.OrderID     = (int)row["OrderID"];
                cd.Weight      = (decimal)row["Weight"];
                cd.ClientsCustomerReference = row["DeliveryOrderNumber"].ToString();
                cd.Docket = row["OrderID"].ToString();

                iCollect.CollectDrops.Add(cd);
                if (newcollection)
                {
                    collections.Add(iCollect);
                }

                #endregion

                #region Deliveries
                eOrderAction orderAction  = (eOrderAction)(int)row[C_OrderActionID];
                int          dropSequence = 1;
                bool         newdelivery  = false;
                newdelivery = false;
                int      deliveryPointID   = (int)row[C_DeliverToPointID];
                DateTime deliveryDateTime  = (DateTime)row[C_DeliverAtDateTime];
                bool     deliveryIsAnyTime = (bool)row[C_DeliverAtAnyTime];
                // If the user has selected Default (i.e. Deliver) a drop instruction will be created, otherwise a trunk instruction will be
                // created.
                eInstructionType instructionType = orderAction == eOrderAction.Default ? eInstructionType.Drop : eInstructionType.Trunk;

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

                if (iDrop == null)
                {
                    iDrop = new Orchestrator.Entities.Instruction();
                    iDrop.InstructionTypeId = (int)instructionType;
                    iDrop.BookedDateTime    = deliveryDateTime;
                    if ((bool)row[C_DeliverAtAnyTime])
                    {
                        iDrop.IsAnyTime = true;
                    }
                    point = facPoint.GetPointForPointId(deliveryPointID);
                    iDrop.ClientsCustomerIdentityID = point.IdentityId;
                    iDrop.PointID = deliveryPointID;
                    iDrop.Point   = point;

                    iDrop.CollectDrops     = new Orchestrator.Entities.CollectDropCollection();
                    iDrop.InstructionOrder = dropSequence;
                    newdelivery            = true;
                    dropSequence++;
                }

                cd             = new Orchestrator.Entities.CollectDrop();
                cd.NoPallets   = (int)row["NoPallets"];
                cd.NoCases     = (int)row["Cases"];
                cd.GoodsTypeId = (int)row["GoodsTypeID"];
                cd.OrderID     = (int)row["OrderID"];
                cd.Weight      = (decimal)row["Weight"];
                cd.ClientsCustomerReference = row["DeliveryOrderNumber"].ToString();
                cd.Docket      = row["OrderID"].ToString();
                cd.OrderAction = orderAction;

                iDrop.CollectDrops.Add(cd);
                if (newdelivery)
                {
                    drops.Insert(0, iDrop);
                }
                //drops.Add(iDrop); Stephen Newman 23/04/07 Changed to insert the drop to the front of the list as the sort processed later seems to swap objects if equal.

                facOrder.UpdateForCollectionRun(cd.OrderID, iDrop.PointID, iDrop.BookedDateTime, iDrop.IsAnyTime, cd.OrderAction, Page.User.Identity.Name);
                #endregion
            }

            #region Add the Instructions to the job
            foreach (Entities.Instruction instruction in collections)
            {
                job.Instructions.Add(instruction);
            }

            drops.Sort(eInstructionSortType.DropDateTime);
            foreach (Entities.Instruction instruction in drops)
            {
                job.Instructions.Add(instruction);
            }
            #endregion

            job.JobState = eJobState.Booked;

            Facade.IJob facjob = new Facade.Job();
            _jobID   = facjob.Create(job, Page.User.Identity.Name);
            _openJob = true;
        }