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); }
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; }