Esempio n. 1
0
        private Entities.InstructionCollection PopulateInstructions()
        {
            foreach (RepeaterItem item in repLegs.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    int instructionID = int.Parse(((HtmlInputHidden)item.FindControl("hidInstructionID")).Value);

                    RadDatePicker dteSDate = item.FindControl("dteSDate") as RadDatePicker;
                    RadTimePicker dteSTime = item.FindControl("dteSTime") as RadTimePicker;

                    RadDatePicker dteEDate = item.FindControl("dteEDate") as RadDatePicker;
                    RadTimePicker dteETime = item.FindControl("dteETime") as RadTimePicker;

                    // Configure the new date and time values.
                    DateTime startDateTime = dteSDate.SelectedDate.Value;
                    startDateTime = startDateTime.Subtract(startDateTime.TimeOfDay);
                    startDateTime = startDateTime.Add(dteSTime.SelectedDate.Value.TimeOfDay);
                    DateTime endDateTime = dteEDate.SelectedDate.Value;
                    endDateTime = endDateTime.Subtract(endDateTime.TimeOfDay);
                    endDateTime = endDateTime.Add(dteETime.SelectedDate.Value.TimeOfDay);

                    // Locate the instruction(s) to alter.
                    Entities.Instruction instruction = Instructions.GetForInstructionId(instructionID);

                    if (Instructions.Count == 1)
                    {
                        // First (and only) instruction on the job, set the arrival and departure date time.
                        instruction.PlannedArrivalDateTime   = startDateTime;
                        instruction.PlannedDepartureDateTime = endDateTime;
                    }
                    else
                    {
                        // Get the previous instruction.
                        Entities.Instruction previousInstruction = Instructions.GetPreviousInstruction(instruction);

                        Facade.IJob facJob = new Facade.Job();

                        if (previousInstruction != null)
                        {
                            if (previousInstruction.InstructionOrder == 0)
                            {
                                previousInstruction.PlannedArrivalDateTime = startDateTime;
                                var expectedTurnaroundTime = facJob.GetExpectedTurnaroundTimeForInstruction(previousInstruction);
                                previousInstruction.PlannedDepartureDateTime = previousInstruction.PlannedArrivalDateTime.Add(expectedTurnaroundTime);
                            }
                            else
                            {
                                previousInstruction.PlannedDepartureDateTime = startDateTime;
                            }
                        }

                        // Set the arrival date time for this instruction.
                        instruction.PlannedArrivalDateTime = endDateTime;
                        bool isLastInstruction = Instructions.IsLastInstruction(instruction);

                        if (isLastInstruction)
                        {
                            var expectedTurnaroundTime = facJob.GetExpectedTurnaroundTimeForInstruction(instruction);
                            instruction.PlannedDepartureDateTime = instruction.PlannedArrivalDateTime.Add(expectedTurnaroundTime);
                        }
                    }
                }
            }

            return(Instructions);
        }