private Entities.Job GetJobEntityFromCache() { Entities.Job job = (Entities.Job)Cache.Get("JobEntityForJobId" + m_jobID); if (job == null) { Facade.IJob facJob = new Facade.Job(); Facade.IPCV facPCV = new Facade.PCV(); Facade.IJobSubContractor facJobSubContractor = new Facade.Job(); job = facJob.GetJob(m_jobID, true, true); job.Charge = ((Facade.IJobCharge)facJob).GetForJobId(m_jobID); job.Extras = facJob.GetExtras(m_jobID, true); job.PCVs = facPCV.GetForJobId(m_jobID); job.References = ((Facade.IJobReference)facJob).GetJobReferences(m_jobID); job.SubContractors = facJobSubContractor.GetSubContractorForJobId(m_jobID); AddJobEntityToCache(job); } return(job); }
protected void Page_Load(object sender, EventArgs e) { Label PageTitle = ((System.Web.UI.UserControl)(Page.Master)).FindControl("lblWizardTitle") as Label; if (PageTitle != null) { PageTitle.Text = "Sub Contract"; } m_jobId = int.Parse(Request.QueryString["jobId"]); m_isUpdate = (Request.QueryString["isUpdate"] != null && Request.QueryString["isUpdate"].ToString() == "true"); if (!IsPostBack && Request.QueryString["rcbId"] == null) { // You can only sub-contract per order if the job is a groupage job. if (Job.JobType != eJobType.Groupage) { rdoSubContractMethod.Items.RemoveAt(2); } // If any of the legs have been completed then the sub contract whole job should be disabled (how can you sub the whole // job to someone when part of the job has already been completed. ReadOnlyCollection <Entities.Instruction> completedInstructions = Job.Instructions.FindAll(new Predicate <Orchestrator.Entities.Instruction>(FindAllCompletedInstructions)); if (completedInstructions != null && completedInstructions.Count > 0) { // disable the whole job radio button. rdoSubContractMethod.Items[0].Selected = false; rdoSubContractMethod.Items[0].Enabled = false; } if (!m_isUpdate) { grdLegs.Visible = false; } else if (Request.QueryString["rcbId"] == null) { // Populate with the correct settings. Facade.IJobSubContractor facJobSubContractor = new Facade.Job(); Facade.IOrganisation facOrganisation = new Facade.Organisation(); Entities.JobSubContractor jobSubContractor = facJobSubContractor.GetSubContractorForJobId(m_jobId)[0]; rntSubContractRate.Culture = new CultureInfo(jobSubContractor.LCID); cboSubContractor.SelectedValue = jobSubContractor.ContractorIdentityId.ToString(); cboSubContractor.Text = facOrganisation.GetNameForIdentityId(jobSubContractor.ContractorIdentityId); chkUseSubContractorTrailer.Checked = jobSubContractor.UseSubContractorTrailer; rntSubContractRate.Text = jobSubContractor.ForeignRate.ToString(); cboSubContractor.Enabled = false; chkUseSubContractorTrailer.Enabled = false; pnlTrailer.Visible = true; } if (Globals.Configuration.SubContractorCommunicationsRequired) { lblShowAsCommunicated.Visible = true; chkShowAsCommunicated.Visible = true; } } InjectScript.Text = string.Empty; }
void btnUpdateRates_Click(object sender, EventArgs e) { if (_wholeJobSubcontractor == null) { // the JS will not allow non currency figures. Facade.IJobSubContractor facSubby = new Facade.Job(); Entities.Job job = GetJobEntityFromCache(); int jobSubContractID = 0; decimal rate = 0M; string userID = this.User.Identity.Name; RadNumericTextBox txtRate = null; TextBox txtSubcontractReference = null; CheckBox chkIsAttended = null; HiddenField hidJobSubContractID = null; foreach (RepeaterItem legItem in repLegSubbyRates.Items) { if (legItem.ItemType == ListItemType.Item || legItem.ItemType == ListItemType.AlternatingItem) { txtRate = legItem.FindControl("rntSubContractRate") as RadNumericTextBox; hidJobSubContractID = legItem.FindControl("hidJobSubContractID") as HiddenField; txtSubcontractReference = legItem.FindControl("txtSubcontractReference") as TextBox; chkIsAttended = legItem.FindControl("chkIsAttended") as CheckBox; if (!string.IsNullOrEmpty(hidJobSubContractID.Value)) { jobSubContractID = int.Parse(hidJobSubContractID.Value); if (decimal.TryParse(txtRate.Text, System.Globalization.NumberStyles.Currency, System.Threading.Thread.CurrentThread.CurrentCulture, out rate)) { Entities.JobSubContractor jobSubContract = facSubby.GetSubContractorForJobSubContractId(jobSubContractID); jobSubContract.ForeignRate = rate; jobSubContract.IsAttended = chkIsAttended.Checked; jobSubContract.Reference = txtSubcontractReference.Text; facSubby.Update(m_jobID, jobSubContract, _job.LastUpdateDate, userID); } } else { Repeater repOrderSubbyRates = legItem.FindControl("repOrderSubbyRates") as Repeater; if (repOrderSubbyRates.Visible) { foreach (RepeaterItem orderItem in repOrderSubbyRates.Items) { if (orderItem.ItemType == ListItemType.Item || orderItem.ItemType == ListItemType.AlternatingItem) { txtRate = orderItem.FindControl("rntSubContractRate") as RadNumericTextBox; hidJobSubContractID = orderItem.FindControl("hidJobSubContractID") as HiddenField; txtSubcontractReference = orderItem.FindControl("txtSubcontractReference") as TextBox; chkIsAttended = orderItem.FindControl("chkIsAttended") as CheckBox; if (!string.IsNullOrEmpty(hidJobSubContractID.Value)) { jobSubContractID = int.Parse(hidJobSubContractID.Value); if (decimal.TryParse(txtRate.Text, System.Globalization.NumberStyles.Currency, System.Threading.Thread.CurrentThread.CurrentCulture, out rate)) { Entities.JobSubContractor jobSubContract = facSubby.GetSubContractorForJobSubContractId(jobSubContractID); jobSubContract.ForeignRate = rate; jobSubContract.IsAttended = chkIsAttended.Checked; jobSubContract.Reference = txtSubcontractReference.Text; facSubby.Update(m_jobID, jobSubContract, _job.LastUpdateDate, userID); } } } } } } } } Facade.IJobSubContractor facSub = new Facade.Job(); job.SubContractors = facSub.GetSubContractorForJobId(_job.JobId); AddJobEntityToCache(_job); } else { // Save and Hide the Edit Facilities decimal rate = 0; Facade.IJobSubContractor facSub = new Facade.Job(); if (Decimal.TryParse(txtWholeJobSubcontractRate.Text, System.Globalization.NumberStyles.Currency, CultureInfo.CreateSpecificCulture("en-GB"), out rate)) { int jobSubContractID = int.Parse(txtWholeJobSubcontractRate.Attributes["jobSubContractID"]); // Set the jobsubcontract information. _wholeJobSubcontractor.ForeignRate = decimal.Parse(txtWholeJobSubcontractRate.Text); _wholeJobSubcontractor.IsAttended = chkIsAttended.Checked; _wholeJobSubcontractor.Reference = txtReference.Text; // Save it. facSub.Update(_wholeJobSubcontractor.JobID, _wholeJobSubcontractor, _job.LastUpdateDate, User.Identity.Name); // Update the cached job. _job.SubContractors = facSub.GetSubContractorForJobId(_job.JobId); AddJobEntityToCache(_job); } } // Refresh the job details page. lblInjectScript.Text = "<script>RefreshParentPage();</script>"; }