//----------------------------------------------------------------------------------------------------------- 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 }
private void TrunkLeg() { Entities.CustomPrincipal user = (Entities.CustomPrincipal)Page.User; Entities.FacadeResult result = null; int pointId = ucPoint.PointID;// int.Parse(cboPoint.SelectedValue); if (!IsUpdate) { #region Create New Trunk Entities.Instruction instruction = null; using (Facade.IInstruction facInstruction = new Facade.Instruction()) { instruction = facInstruction.GetInstruction(m_instructionId); } // We've trunked the leg. DateTime arriveAtTrunkPoint; DateTime leaveTrunkPoint; // Get the arrival time. //arriveAtTrunkPoint = timeStartDate.xDateTime; arriveAtTrunkPoint = new DateTime(rdiStartDate.SelectedDate.Value.Year, rdiStartDate.SelectedDate.Value.Month, rdiStartDate.SelectedDate.Value.Day, rdiStartTime.SelectedDate.Value.Hour, rdiStartTime.SelectedDate.Value.Minute, 0); // Get the departure time. //leaveTrunkPoint = timeEndDate.xDateTime; leaveTrunkPoint = new DateTime(rdiEndDate.SelectedDate.Value.Year, rdiEndDate.SelectedDate.Value.Month, rdiEndDate.SelectedDate.Value.Day, rdiEndTime.SelectedDate.Value.Hour, rdiEndTime.SelectedDate.Value.Minute, 0); DateTime lastUpdateDate = DateTime.Parse(Request.QueryString["LastUpdateDate"]); // Create the new trunk instruction Entities.Instruction trunkInstruction = new Orchestrator.Entities.Instruction(); trunkInstruction.InstructionTypeId = (int)eInstructionType.Trunk; trunkInstruction.JobId = instruction.JobId; trunkInstruction.PointID = pointId; trunkInstruction.PlannedDepartureDateTime = leaveTrunkPoint; trunkInstruction.PlannedArrivalDateTime = arriveAtTrunkPoint; trunkInstruction.Trailer = instruction.Trailer; // Set the booked datetime of the trunk to the trunks planned arrival time. This could produce a situation // where the booked times do not flow, however, the trunks booked time is irrelevant so if this happens, it shouldn't matter. // Failing to set a booked time for the trunk here would cause an error when attempting to save the instruction. trunkInstruction.BookedDateTime = arriveAtTrunkPoint; // Note: Always get the driver and the vehicle. trunkInstruction.Driver = instruction.Driver; trunkInstruction.Vehicle = instruction.Vehicle; // Add the trunk to the job. using (Facade.IJob facJob = new Facade.Job()) { Entities.Job job = facJob.GetJob(instruction.JobId); result = facJob.Trunk(trunkInstruction, instruction, job.IdentityId, user.UserName, job.LastUpdateDate, chkDriver.Checked, chkVehicle.Checked); } #endregion } else { using (Facade.IInstruction facInstruction = new Facade.Instruction()) { facInstruction.UpdatePointID(m_instructionId, pointId, user.UserName); result = new Orchestrator.Entities.FacadeResult(true); } } if (result.Success) { this.ReturnValue = "refresh"; this.Close(); } else { infringementDisplay.Infringements = result.Infringements; infringementDisplay.DisplayInfringments(); } }
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; }
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; }