private void GrdCatalystsAdd() { if (ValidateCatalystsFooter()) { Page.Validate("catalystDataFooter"); if (Page.IsValid) { int companyId = Int32.Parse(hdfCompanyId.Value); bool inDatabase = false; bool deleted = false; int workId = Int32.Parse(hdfWorkId.Value); int catalystId = Int32.Parse(((DropDownList)grdCatalysts.FooterRow.FindControl("ddlNameFooter")).SelectedValue); decimal percentageByWeight = -1; if (((TextBox)grdCatalysts.FooterRow.FindControl("tbxPercentageByWeightFooter")).Text.Trim() != "") { if ((Validator.IsValidDecimal(((TextBox)grdCatalysts.FooterRow.FindControl("tbxPercentageByWeightFooter")).Text.Trim()))) { percentageByWeight = decimal.Round(decimal.Parse(((TextBox)grdCatalysts.FooterRow.FindControl("tbxPercentageByWeightFooter")).Text.Trim()), 2); } } decimal lbsForMixQuantity = -1; if (((Label)grdCatalysts.FooterRow.FindControl("lblLbsForMixQuantityFooter")).Text.Trim() != "") { if ((Validator.IsValidDecimal(((Label)grdCatalysts.FooterRow.FindControl("lblLbsForMixQuantityFooter")).Text.Trim()))) { lbsForMixQuantity = decimal.Round(decimal.Parse(((Label)grdCatalysts.FooterRow.FindControl("lblLbsForMixQuantityFooter")).Text.Trim()), 2); } } string lbsForDrum = ((Label)grdCatalysts.FooterRow.FindControl("lblLbsForDrumFooter")).Text.Trim(); ; WorkFullLengthLiningCatalystsGateway workFullLengthLiningCatalystsGateway = new WorkFullLengthLiningCatalystsGateway(); workFullLengthLiningCatalystsGateway.LoadByCatalystId(catalystId, companyId); string name = workFullLengthLiningCatalystsGateway.GetName(catalystId); FullLengthLiningWetOutCatalystsDetails model = new FullLengthLiningWetOutCatalystsDetails(fullLengthLiningTDS); model.Insert(workId, catalystId, name, percentageByWeight, lbsForMixQuantity, lbsForDrum, deleted, companyId, inDatabase); Session.Remove("wetOutCatalystsDetailsDummy"); Session["fullLengthLiningTDS"] = fullLengthLiningTDS; Session["wetOutCatalystsDetails"] = fullLengthLiningTDS.WetOutCatalystsDetails; grdCatalysts.DataBind(); grdCatalysts.PageIndex = grdCatalysts.PageCount - 1; } } }
protected void ddlNameFooter_SelectedIndexChanged(object sender, EventArgs e) { int companyId = Int32.Parse(hdfCompanyId.Value); int catalystId = Int32.Parse(((DropDownList)grdCatalysts.FooterRow.FindControl("ddlNameFooter")).SelectedValue); if (catalystId != -1) { // Load catalyst data WorkFullLengthLiningCatalystsGateway workFullLengthLiningCatalystsGateway = new WorkFullLengthLiningCatalystsGateway(); workFullLengthLiningCatalystsGateway.LoadByCatalystId(catalystId, companyId); double defaultPercentageByWeight = double.Parse(decimal.Round(decimal.Parse(workFullLengthLiningCatalystsGateway.GetDefaultPercentageByWeight(catalystId).ToString()), 2).ToString()); // .. Resin Information if ((ddlWetOutDataResins.SelectedValue != "-1") && (ddlWetOutDataPoundsDrums.SelectedValue != "(Select)") && (tbxWetOutDataTotalMixQuantity.Text != "")) { int resinId = Int32.Parse(ddlWetOutDataResins.SelectedValue); WorkFullLengthLiningResinsGateway workFullLengthLiningResinsGateway = new WorkFullLengthLiningResinsGateway(); workFullLengthLiningResinsGateway.LoadByResinId(resinId, companyId); int lbDrums = Int32.Parse(workFullLengthLiningResinsGateway.GetLbDrums(resinId).ToString()); double activeResin = double.Parse(workFullLengthLiningResinsGateway.GetActiveResin(resinId).ToString()) / 100; string applyCatalystTo = workFullLengthLiningResinsGateway.GetApplyCatalystTo(resinId); // Set data to grid ((TextBox)grdCatalysts.FooterRow.FindControl("tbxPercentageByWeightFooter")).Text = defaultPercentageByWeight.ToString(); // Calc the other columms // ... ... For Mix Quantity string forMixQuantity = ""; if (defaultPercentageByWeight.ToString() == "-1") { forMixQuantity = "-"; } else { double totalMixQuantity = double.Parse(tbxWetOutDataTotalMixQuantity.Text); double catalyse = 0d; if (applyCatalystTo == "(Select)") { catalyse = -1; } else { if (applyCatalystTo == "Active Resin & Filter") { catalyse = 1; } else { catalyse = activeResin; } } if (catalyse != -1) { double pureResin = totalMixQuantity * catalyse; decimal forMixQuantityDecimal = decimal.Parse((pureResin * (defaultPercentageByWeight) / 100).ToString()); forMixQuantity = decimal.Round(forMixQuantityDecimal,2).ToString(); ((Label)grdCatalysts.FooterRow.FindControl("lblLbsForMixQuantityFooter")).Text = forMixQuantity; } else { ((Label)grdCatalysts.FooterRow.FindControl("lblLbsForMixQuantityFooter")).Text = "ERROR"; } } // ... ... For Lbs For Drums string firstPart = ""; double percentageToCatalyse = -1; if (ddlWetOutDataPoundsDrums.SelectedValue == "Pounds & Drums") // OP 1 { if (defaultPercentageByWeight == -1) { firstPart = "-"; } else { if (applyCatalystTo == "(Select)") { percentageToCatalyse = -1; } else { if (applyCatalystTo == "Active Resin & Filter") { percentageToCatalyse = 1; } else { percentageToCatalyse = activeResin; } } if (percentageToCatalyse != -1) { double drumRes = lbDrums * percentageToCatalyse; double catalystPerDrum = drumRes * defaultPercentageByWeight / 100; decimal catalystPerDrumDecimal = Decimal.Parse(catalystPerDrum.ToString()); catalystPerDrumDecimal = decimal.Round(catalystPerDrumDecimal,2); firstPart = catalystPerDrumDecimal.ToString(); } else { firstPart = "ERROR"; } } } else { firstPart = "-"; } string secondPart = ""; if (ddlWetOutDataPoundsDrums.SelectedValue == "Pounds & Drums") // OP 1 { if (defaultPercentageByWeight == -1) { secondPart = "-"; } else { double drumRes = lbDrums * percentageToCatalyse; double catalystPerDrum = drumRes * defaultPercentageByWeight / 100; double roundUp = RoundUp(catalystPerDrum, 0); string upDown = ""; if ((roundUp - catalystPerDrum) > 0.05) { upDown = "Down"; } else { upDown = "Up"; } double fulllbs = 0d; if (upDown == "Up") { fulllbs = roundUp; } else { double roundDown = RoundDown(catalystPerDrum, 0); fulllbs = roundDown; } double partLbs = 0d; if (upDown == "Up") { partLbs = 0; } else { partLbs = catalystPerDrum - fulllbs; } double ozes = double.Parse(decimal.Round(decimal.Parse(partLbs.ToString()) * 16, 0).ToString()); string lbOzes = " = (" + fulllbs.ToString() + " lbs + " + ozes.ToString() + " oz) per drum"; secondPart = lbOzes; } } else { secondPart = "-"; } ((Label)grdCatalysts.FooterRow.FindControl("lblLbsForDrumFooter")).Text = firstPart + "lb/Drum " + secondPart; // Addition is available ((ImageButton)grdCatalysts.FooterRow.FindControl("ibtnAdd")).Visible = true; } else { // Addition is not available ((ImageButton)grdCatalysts.FooterRow.FindControl("ibtnAdd")).Visible = false; } } }