ASP.NET code error

Hi,

I am having an issue with the calculations on my ASP.NET page.

See the attached image.
Incorrect screenshot
The issue is with the totals.  They are all incorrect.  They are infact double what that should be and I cannot figure out why!  
I am hoping someone can help.

I will attach some further screenshots and code.
SmashAndGrabAsked:
Who is Participating?
 
Fernando SotoRetiredCommented:
@SmashAndGrab, I can only guess what controls correspond to the total row and from that assumption it looks OK. Now seeming that this is being displayed with a values that are twice the value it should be is it possible you are calling then Bind method two times?
0
 
Fernando SotoRetiredCommented:
Please post the code where you make the calculations.
0
 
SmashAndGrabAuthor Commented:
I think the totals are worked out on the server side:

   

Web Code:

Web page
C# code:
c
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Fernando SotoRetiredCommented:
Please post the complete code which does the calculations in text format. I can't paste an image into a text editor to analyze.
0
 
SmashAndGrabAuthor Commented:
hiya,

I think the code:

        protected void dgrDetails_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink hypComments = (HyperLink)e.Row.FindControl("hypComments");

                string sComments = dgrSum.DataKeys[e.Row.RowIndex].Values[4].ToString();

                if (sComments != "")
                {
                    hypComments.Attributes.Add("title", sComments);
                }
                else
                {
                    hypComments.Style.Add("text-decoration", "none");
                    hypComments.Style.Add("color", "black");
                }

                // Planned Stoppage
                Label lblBreakMins = (Label)e.Row.FindControl("lblBreakMins");
                decimal breakMins = Decimal.Parse(lblBreakMins.Text);
                totalBreakMins += breakMins;

                // Mins
                Label lblTotMins = (Label)e.Row.FindControl("lblTotMins");
                decimal mins = Decimal.Parse(lblTotMins.Text);
                totalMins += mins;

                // Input NM3
                Label lblInputM3 = (Label)e.Row.FindControl("lblInputM3");
                decimal InputM3 = Decimal.Parse(lblInputM3.Text);
                totalInputM3 += InputM3;

                // Output NM3
                Label lblOutputM3 = (Label)e.Row.FindControl("lblOutputM3");
                decimal OutputM3 = Decimal.Parse(lblOutputM3.Text);
                totalOutputM3 += OutputM3;

                // Co/By NM3
                Label lblCoByProdM3 = (Label)e.Row.FindControl("lblCoByProdM3");
                decimal CoByProdM3 = Decimal.Parse(lblCoByProdM3.Text);
                totalCoByProdM3 += CoByProdM3;
                
                // Setup
                Label lblSetup = (Label)e.Row.FindControl("lblSetup");
                decimal Setup = Decimal.Parse(lblSetup.Text);
                totalSetup += Setup;

                // Input LM (hidden)
                Label lblInputLM = (Label)e.Row.FindControl("lblInputLM");
                decimal InputLM = Decimal.Parse(lblInputLM.Text);
                totalInputLM += InputLM;

                // Reject M3 (hidden)
                Label lblRejectM3 = (Label)e.Row.FindControl("lblRejectM3");
                decimal RejectM3 = Decimal.Parse(lblRejectM3.Text);
                totalRejectM3 += RejectM3;

                // Other DT
                Label lblOtherDT = (Label)e.Row.FindControl("lblOtherDT");
                decimal DTMins = Decimal.Parse(lblOtherDT.Text);
                totalDTMins += DTMins;
                
                // Total DT
                Label lblTotalDT = (Label)e.Row.FindControl("lblTotalDT");
                lblTotalDT.Text = (DTMins + Setup + breakMins).ToString();
                totalTotalDT += DTMins + Setup + breakMins;

                // SAP Base Quantity (hidden)
                Label lblSAPBaseQty = (Label)e.Row.FindControl("lblSAPBaseQty");
                decimal SAPBaseQty = Decimal.Parse(lblSAPBaseQty.Text);
                totalSapBaseQty = SAPBaseQty; // This is not a sum !

                // Reject (hidden)
                Label lblReject = (Label)e.Row.FindControl("lblReject");
                decimal Reject = Decimal.Parse(lblReject.Text);
                totalReject += Reject;

                // % Complete
                /*Label lblPercentComp = (Label)e.Row.FindControl("lblPercentComp");
                decimal Calc = Decimal.Parse(lblPercentComp.Text);
                totalCalc += Calc;*/

                // Availability %
                Label lblAvailability = (Label)e.Row.FindControl("lblAvailability");
                decimal Availability = Decimal.Parse(lblAvailability.Text);

                AC = (mins - Setup - DTMins) * SAPBaseQty;
                totalAC += AC;

                LinkButton lbtAmend = (LinkButton)e.Row.FindControl("lbtAmend");
                LinkButton lbtAdd = (LinkButton)e.Row.FindControl("lbtAdd");

                int Currstatus = Convert.ToInt32(dgrSum.DataKeys[e.Row.RowIndex].Values[3].ToString());

                Users UserDetails = new Users(Page.User.Identity.Name);

                if ((Currstatus == 20) && (!UserDetails.ModifyOrders))
                {
                    lbtAmend.Enabled = false;
                    lbtAdd.Enabled = false;
                }
                else
                {
                    lbtAmend.Enabled = true;
                    lbtAdd.Enabled = true;
                }
            }

            if (e.Row.RowType == DataControlRowType.Footer)
            {

                Label lblTotalM3PerHour = (Label)e.Row.FindControl("lblTotalM3PerHour");
                if (totalMins > 0)
                {
                    totalM3PerHour = totalOutputM3 / (totalMins / 60);
                    lblTotalM3PerHour.Text = decimal.Round(totalM3PerHour, 3).ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    lblTotalM3PerHour.Text = "DIV/0";
                }

                Label lblTotalQuality = (Label)e.Row.FindControl("lblTotalQuality");
                if (totalInputM3 > 0)
                {
                    totalQuality = (totalInputM3 - totalRejectM3) / totalInputM3;
                    lblTotalQuality.Text = decimal.Round(totalQuality * 100, 2).ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    totalQuality = 0;
                    lblTotalQuality.Text = "DIV/0";
                }

                Label lblTotalInputM3 = (Label)e.Row.FindControl("lblTotalInputM3");
                lblTotalInputM3.Text = totalInputM3.ToString(CultureInfo.InvariantCulture);

                Label lblTotalAvailability = (Label)e.Row.FindControl("lblTotalAvailability");
                if (totalMins > 0)
                {
                    totalAvailability = (totalMins - totalSetup - totalDTMins) / totalMins;
                    lblTotalAvailability.Text = decimal.Round(totalAvailability * 100, 2).ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    totalAvailability = 0;
                    lblTotalAvailability.Text = "DIV/0";
                }

                Label lblTotalPerformance = (Label)e.Row.FindControl("lblTotalPerformance");
                if (totalAC > 0)
                {
                    //totalPerformance = totalInputLM / ((totalMins - totalSetup - totalDTMins) * totalSapBaseQty);
                    totalPerformance = totalInputLM / totalAC;
                    lblTotalPerformance.Text = decimal.Round(totalPerformance * 100, 2).ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    totalPerformance = 0;
                    lblTotalPerformance.Text = "DIV/0";
                }
                
                Label lblTotalBreakMins = (Label)e.Row.FindControl("lblTotalBreakMins");
                lblTotalBreakMins.Text = totalBreakMins.ToString(CultureInfo.InvariantCulture);

                Label lblTotalTime = (Label)e.Row.FindControl("lblTotalTime");
                lblTotalTime.Text = totalMins.ToString(CultureInfo.InvariantCulture);

                Label lblTotalOutputM3 = (Label)e.Row.FindControl("lblTotalOutputM3");
                lblTotalOutputM3.Text = totalOutputM3.ToString(CultureInfo.InvariantCulture);

                Label lblTotalCoByProdM3 = (Label)e.Row.FindControl("lblTotalCoByProdM3");
                lblTotalCoByProdM3.Text = totalCoByProdM3.ToString(CultureInfo.InvariantCulture);
                
                Label lblTotalSetup = (Label)e.Row.FindControl("lblTotalSetup");
                lblTotalSetup.Text = totalSetup.ToString(CultureInfo.InvariantCulture);

                Label lblTotalOtherDT = (Label)e.Row.FindControl("lblTotalOtherDT");
                lblTotalOtherDT.Text = totalDTMins.ToString(CultureInfo.InvariantCulture);

                Label lblTotalTotalDT = (Label)e.Row.FindControl("lblTotalTotalDT");
                lblTotalTotalDT.Text = totalTotalDT.ToString(CultureInfo.InvariantCulture);

                totalOEE = totalAvailability * totalPerformance * totalQuality;
                Label lblTotalOEE = (Label)e.Row.FindControl("lblTotalOEE");
                lblTotalOEE.Text = decimal.Round(totalOEE * 100, 2).ToString(CultureInfo.InvariantCulture);

                /*Label lblTotalCalc = (Label)e.Row.FindControl("lblCalc");
                lblTotalCalc.Text = totalCalc.ToString(CultureInfo.InvariantCulture);*/
            }
        }

Open in new window

0
 
Fernando SotoRetiredCommented:
Author posted that my post was helpful.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.