private void GetJobAndInstructions()
        {
            // Get the job.
            using (Facade.IInstruction facInstruction = new Facade.Instruction())
            {
                // Try and get the job from the cache
                _job = (Entities.Job)Cache.Get("JobEntityForJobId" + _jobId.ToString());

                if (_job == null)
                {
                    Facade.IJob facJob = new Facade.Job();
                    _job = facJob.GetJob(_jobId);

                    // Job was not in the cache thus get the instruction collection from the db
                    _instructions = new Facade.Instruction().GetForJobId(_jobId);
                }
                else
                {
                    // Job is in the cache, check for instructions

                    if (_job.Instructions != null)
                    {
                        // We have instructions
                        _instructions = _job.Instructions;
                    }
                    else
                    {
                        // otherwise get a fresh instruction collection
                        _instructions = new Facade.Instruction().GetForJobId(_jobId);
                    }
                }

                // Get the end instruction
                _endInstruction = _instructions.Find(instruc => instruc.InstructionOrder == _instructions.Count - 1);

                if (_endInstruction == null)
                {
                    throw new ApplicationException("Cannot find last instruction.");
                }
            }
        }
Exemple #2
0
        void btnConfirmSubContract_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && ValidateSubContractLeg())
            {
                // Check whether the user is trying to subcontract instructions that have resources assigned.
                // Only applies to driver and vehicle resources.
                Entities.InstructionCollection instructions = Job.Instructions;

                // Extract the collections.
                Entities.Instruction selected = instructions.Find(
                    delegate(Entities.Instruction instruction)
                {
                    return(instruction.InstructionOrder == 0);
                });

                // No resources exist for selected instructions, so continue with save oepration.
                SubContractingMethod method = (SubContractingMethod)int.Parse(rdoSubContractMethod.SelectedValue);
                string userID = ((Entities.CustomPrincipal)Page.User).UserName;

                Entities.JobSubContractor jobSubContractor = GetJobSubContract(selected);
                DateTime lastUpdateDate = DateTime.Parse(Request.QueryString["LastUpdateDate"]);

                // Set the job to be sub-contracted
                Entities.FacadeResult result = null;

                switch (method)
                {
                case SubContractingMethod.WholeJob:
                    //add something that finds if any of the other legs have been subbed out already.
                    result = SubContractWholeJob(jobSubContractor, lastUpdateDate, userID);
                    break;

                case SubContractingMethod.SpecificLegs:
                    result = SubContractSpecificLegs(jobSubContractor, lastUpdateDate, userID);
                    break;

                case SubContractingMethod.PerOrder:
                    result = SubContractPerOrder(jobSubContractor, lastUpdateDate, userID);
                    break;
                }

                if (Globals.Configuration.SubContractorCommunicationsRequired &&
                    chkShowAsCommunicated.Checked)
                {
                    CommunicateInstructionsForSubContractor(Job.JobId, jobSubContractor.ContractorIdentityId, userID);
                }

                if (result.Success)
                {
                    Cache.Remove("JobEntityForJobId" + m_jobId.ToString());
                    //InjectScript.Text = "<script>RefreshParentPage();</script>";
                    this.ReturnValue = "refresh";
                    this.Close();
                }
                else
                {
                    infrigementDisplay.Infringements = result.Infringements;
                    infrigementDisplay.DisplayInfringments();
                    infrigementDisplay.Visible = true;

                    pnlConfirmation.Visible = false;
                }
            }
        }