Ejemplo n.º 1
0
        private void BindLegs()
        {
            Facade.IJob  facJob = new Facade.Job();
            Entities.Job job    = facJob.GetJob(m_jobId, true, true);

            Entities.LegPlan lp = new Facade.Instruction().GetLegPlan(job.Instructions, false);
            repLegs.DataSource = lp.Legs();
            repLegs.DataBind();

            if (job.Instructions.Count > 0)
            {
                if (job.Instructions[0].Driver != null)
                {
                    chkLinkDriver.Text = "Link " + job.Instructions[0].Driver.Individual.FullName;
                }
                if (job.Instructions[0].Vehicle != null)
                {
                    chkLinkVehicle.Text = "Link " + job.Instructions[0].Vehicle.RegNo;
                }
                if (job.Instructions[0].Trailer != null)
                {
                    chkLinkTrailer.Text = "Link " + job.Instructions[0].Trailer.TrailerRef;
                }
            }
        }
Ejemplo n.º 2
0
        private void PopulateJob()
        {
            if (Page.IsValid)
            {
                #region Populate Job Charge

                m_job.Charge.JobChargeAmount = Decimal.Parse(txtRate.Text, System.Globalization.NumberStyles.Currency);

                #endregion

                #region Populate Leg Costs and Charges

                int instructionId = 0;

                // Setup the leg costs and charges
                foreach (GridViewRow item in gvLegs.Rows)
                {
                    if (item.RowType == DataControlRowType.DataRow)
                    {
                        decimal cost   = Decimal.Parse(((TextBox)item.FindControl("txtCost")).Text, System.Globalization.NumberStyles.Currency);
                        decimal charge = Decimal.Parse(((TextBox)item.FindControl("txtCharge")).Text, System.Globalization.NumberStyles.Currency);

                        instructionId = int.Parse(item.Attributes["__key"].ToString());

                        Entities.LegPlan legPlan = new Facade.Instruction().GetLegPlan(m_job.Instructions, false);
                        foreach (Entities.LegView leg in legPlan.Legs())
                        {
                            if (instructionId == leg.InstructionID)
                            {
                                leg.EndLegPoint.Instruction.Cost   = cost;
                                leg.EndLegPoint.Instruction.Charge = charge;
                            }
                        }
                    }
                }

                #endregion

                #region Update the Job State

                bool canBePriced = true;

                if (chkIsPriced.Enabled == false) // Don't change state of the job
                {
                    canBePriced = false;
                }
                else
                {
                    canBePriced = true;
                }

                m_job.IsPriced = chkIsPriced.Checked && canBePriced;

                if (m_job.IsPriced)
                {
                    chkIsPriced.Checked = true;

                    switch (m_job.JobState)
                    {
                    case eJobState.Completed:
                        m_job.JobState = eJobState.BookingInIncomplete;
                        break;

                    case eJobState.BookingInIncomplete:
                        m_job.JobState = eJobState.BookingInIncomplete;
                        break;

                    case eJobState.BookingInComplete:
                        m_job.JobState = eJobState.ReadyToInvoice;
                        break;

                    case eJobState.ReadyToInvoice:
                        m_job.JobState = eJobState.ReadyToInvoice;
                        break;
                    }
                }
                else
                {
                    chkIsPriced.Checked = false;

                    switch (m_job.JobState)
                    {
                    case eJobState.Completed:
                        m_job.JobState = eJobState.Completed;
                        break;

                    case eJobState.BookingInIncomplete:
                        m_job.JobState = eJobState.BookingInIncomplete;
                        break;

                    case eJobState.BookingInComplete:
                        m_job.JobState = eJobState.BookingInComplete;
                        break;

                    case eJobState.ReadyToInvoice:
                        m_job.JobState = eJobState.BookingInComplete;
                        break;
                    }
                }

                #endregion

                // We don't update extras this way anymore so remove them from the job entity.
                m_job.Extras = null;

                if (canBePriced)
                {
                    if (gvRefusals.Visible)
                    {
                        PriceRefusals();
                    }
                }

                m_runningRefusalCharge = 0;

                foreach (GridViewRow row in gvRefusals.Rows)
                {
                    m_runningRefusalCharge += decimal.Parse(((TextBox)row.FindControl("txtRefusalCharge")).Text, System.Globalization.NumberStyles.Currency);
                }


                //Update and check that the Job Rate and the Goods Refused add up
                if (m_runningRefusalCharge == m_job.Charge.JobChargeAmount || m_runningRefusalCharge == 0)
                {
                    // Update the job
                    string                userId = ((Entities.CustomPrincipal)Page.User).UserName;
                    Facade.IJob           facJob = new Facade.Job();
                    Entities.FacadeResult result = facJob.Update(m_job, userId);

                    if (result.Success)
                    {
                        LoadJob();
                        pnlConfirmation.Visible = true;
                        lblConfirmation.Text    = "The job pricing has been updated.";
                    }
                    else
                    {
                        pnlConfirmation.Visible = true;
                        lblConfirmation.Text    = "The job pricing was not updated, please try again.";

                        infringementDisplay.Infringements = result.Infringements;
                        infringementDisplay.DisplayInfringments();
                    }
                }
                else
                {
                    // Dont allow them to continue until the values are added correctly
                    pnlConfirmation.Visible = true;
                    lblConfirmation.Text    = "The job pricing was not updated, please ensure that the goods refused charges tally with the job rate.";
                }
            }
        }