protected void gvGradingFactors1_RowDataBound(object sender, GridViewRowEventArgs e) { GradingResultControlNew grc = ((GradingResultControlNew)e.Row.FindControl("ResultInputControl")); Label type = ((Label)e.Row.FindControl("lblType")); Label possibleValues = ((Label)e.Row.FindControl("lblPossibleValues")); Label result = ((Label)e.Row.FindControl("lblResult")); if (grc != null && type != null) { grc.setType(type.Text, possibleValues.Text, result.Text); } }
private GradingModel SetGrading() { Boolean Isnormaldeposit = true; if (RdBtndeposit.Checked != true) { Isnormaldeposit = false; } int gradingResultStatus = ((Dictionary <string, int>)ViewState["FGs"])[drpCommodityFactorGroup.SelectedValue]; //eg. General Requirement Fail Sesame status = 3 GradingModel gm = new GradingModel(); gm.ID = new Guid(ViewState["GradingResultID"].ToString()); // new Guid(ViewState[GradingConstants.GradingID.ToString()].ToString()); Guid gFGID = new Guid(drpCommodityFactorGroup.SelectedValue); gm.GradingResultStatusID = gradingResultStatus; gm.GradingFactorGroupID = gFGID; if ((int)GradingResultStatus.AcceptableResult == gradingResultStatus)//for moisture fail { gm.GradingFactorGroupID = gFGID; gm.GradingResultStatusID = (int)GradingResultStatus.AcceptableResult; gm.TotalValue = 0; gm.GradeRecived = drpGrade.SelectedItem.Text; gm.ProductionYear = int.Parse(drpProductionYear.Text); gm.CommodityClassID = new Guid(drpCommodityClass.SelectedValue); gm.Isnormaldeposit = Isnormaldeposit; } gm.NumberofSeparations = 1;/*By default the separation(segrigation) number is one*/ gm.GradeRecivedDateTime = DateTime.Parse(txtDateRecived.Text + " " + txtTimeRecived.Text); gm.ResultCreatedBy = BLL.UserBLL.CurrentUser.UserId; gm.LastModifiedBy = BLL.UserBLL.CurrentUser.UserId; GradingDetail gd; decimal gradingValue = 0; //bool ValueForsemi_wased =false; //bool ValueForUnderScreen =false; int?classificationNo = 1; ViewState["ClassificatonMsg"] = null; foreach (GridViewRow gr in gvGradingFactors1.Rows) { GradingResultControlNew grc = ((GradingResultControlNew)gr.FindControl("ResultInputControl")); if (!grc.validate()) { Messages1.SetMessage("The grading factor '" + ((Label)gr.FindControl("lblGradingFactorName")).Text + "' has invalid Value! " + grc.errorMessage, Messages.MessageType.Error); return(null); } gd = new GradingDetail(gm); gd.ID = Guid.NewGuid(); gd.GradingsID = gm.ID; gd.GradingFactorID = new Guid(((Label)gr.FindControl("lblId")).Text); gd.ReceivedValue = grc.Value; gd.Status = 1; gm.addGradingDetail(gd); TextBox isInTotal = ((TextBox)gr.FindControl("txtIsInTotalValue")); gradingValue = 0; bool canAddToTotal = false; if (decimal.TryParse(grc.Value.ToString(), out gradingValue) &&/*we need the value after the loop even if not added to total value*/ bool.TryParse(isInTotal.Text, out canAddToTotal) && canAddToTotal) { gm.TotalValue += gradingValue; } if (!gd.IsValid()) { Messages1.SetMessage("The grading factor" + ((Label)gr.FindControl("lblGradingFactorName")).Text + " " + gd.ErrorMessage, Messages.MessageType.Error); return(null); } /*Check for semi-washed, under screen and Moisture Content factor values*/ decimal limit = -1; string value = ((Label)gr.FindControl("lblIsSemiWashedFactor")).Text; if (bool.Parse(value) && grc.Value.ToString().ToLower() == "yes")//for semi-washed case { classificationNo *= 3; if (ViewState["ClassificatonMsg"] != null) { ViewState.Add("ClassificatonMsg", ViewState["ClassificatonMsg"].ToString() + ", Semi-washed"); } else { ViewState.Add("ClassificatonMsg", "Semi-washed"); } } value = ((Label)gr.FindControl("lblIsUnderScreenFactor")).Text; if (bool.Parse(value) && decimal.TryParse(((Label)gr.FindControl("lblUnderScreenLimit")).Text, out limit) && limit > 0 && gradingValue < limit) //for under screen case { classificationNo *= 5; if (ViewState["ClassificatonMsg"] != null) { ViewState.Add("ClassificatonMsg", ViewState["ClassificatonMsg"].ToString() + ", Under Screen"); } else { ViewState.Add("ClassificatonMsg", "Under Screen"); } } value = ((Label)gr.FindControl("lblIsType")).Text; if (bool.Parse(value) && decimal.TryParse(grc.Value, out limit))//for non coffee case { classificationNo *= int.Parse(grc.Value); if (ViewState["ClassificatonMsg"] != null) { ViewState.Add("ClassificatonMsg", ViewState["ClassificatonMsg"].ToString() + ", " + grc.Text); } else { ViewState.Add("ClassificatonMsg", grc.Text); } } //Moisture Content factor values value = ((Label)gr.FindControl("lblIsMoistureContentFactor")).Text; //string expvalue = ""; //expvalue = ((Label)gr.FindControl("MoistureContentLimitexp")).Text; limit = -1; if (bool.Parse(value) && decimal.TryParse(((Label)gr.FindControl("lblMoistureContentLimit")).Text, out limit) && limit > 0) //for moisture content case { string MFFactorGroup = ((Label)gr.FindControl("lblMoistureFailFactorGroup")).Text; if (gradingValue > limit && !gm.GradingFactorGroupID.ToString().Equals(MFFactorGroup.Trim())) { Messages1.SetMessage("Value entered for moisture content is above range " + limit.ToString() + "! The grading must be considered with factor group 'Moisture Fail'!", Messages.MessageType.Error); return(null); } else if (gradingValue <= limit && gm.GradingFactorGroupID.ToString().Equals(MFFactorGroup.Trim())) { Messages1.SetMessage("The grading factor moisture content is set with in the limit " + limit.ToString() + "! The grading MUST NOT be considered with factor group 'Moisture Fail'!", Messages.MessageType.Error); return(null); } } } //gm.IsSemiWashed = ValueForsemi_wased; //gm.IsUnderScreen = ValueForUnderScreen; if (classificationNo > 1) { gm.ClassificationNo = classificationNo; } /*we expect only one factor for segrigation request * i.e. number of segrigations the grading value will take this value from above*/ if ((int)GradingResultStatus.SegrigationRequested == gradingResultStatus) { gm.NumberofSeparations = Convert.ToInt32(gradingValue); } if (!gm.IsValidForGradingResult()) { Messages1.SetMessage(gm.ErrorMessage, Messages.MessageType.Error); return(null); } return(gm); }