protected void fvBMPPlanning_ItemUpdating(object sender, FormViewUpdateEventArgs e) { StringBuilder sb = new StringBuilder(); TextBox tbBMPNumber = fvBMPPlanning.FindControl("tbBMPNumber") as TextBox; TextBox tbDescription = fvBMPPlanning.FindControl("tbDescription") as TextBox; TextBox tbSubIssueStatement = fvBMPPlanning.FindControl("tbSubIssueStatement") as TextBox; DropDownList ddlBMPSource = fvBMPPlanning.FindControl("ddlBMPSource") as DropDownList; TextBox tbLocation = fvBMPPlanning.FindControl("tbLocation") as TextBox; DropDownList ddlRevisionDescription = fvBMPPlanning.FindControl("ddlRevisionDescription") as DropDownList; DropDownList ddlPollutantCategory = fvBMPPlanning.FindControl("ddlPollutantCategory") as DropDownList; DropDownList ddlBMPPractice = fvBMPPlanning.FindControl("ddlBMPPractice") as DropDownList; TextBox tbUnitsPlanned = fvBMPPlanning.FindControl("tbUnitsPlanned") as TextBox; TextBox tbPriorPlanningEstimate = fvBMPPlanning.FindControl("tbPriorPlanningEstimate") as TextBox; TextBox tbPlanningEstimate = fvBMPPlanning.FindControl("tbPlanningEstimate") as TextBox; DropDownList ddlCREP = fvBMPPlanning.FindControl("ddlCREP") as DropDownList; DropDownList ddlNMCPType = fvBMPPlanning.FindControl("ddlNMCPType") as DropDownList; DropDownList ddlSAA = fvBMPPlanning.FindControl("ddlSAA") as DropDownList; DropDownList ddlSA = fvBMPPlanning.FindControl("ddlSA") as DropDownList; using (WACDataClassesDataContext wac = new WACDataClassesDataContext()) { try { int? iPH_PK_SA_TP = null; bool bPerformSABMPInsert = false; var a = wac.bmp_ags.Where(w => w.pk_bmp_ag == Convert.ToInt32(fvBMPPlanning.DataKey.Value)).Single(); string sBMP_NBR_Orig = a.bmp_nbr; string sBMP_NBR = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbBMPNumber.Text, 24); if (sBMP_NBR_Orig != sBMP_NBR) { int iBMP_NBR_Count = wac.bmp_ags.Where(w => w.fk_farmBusiness == a.fk_farmBusiness && w.bmp_nbr == sBMP_NBR).Count(); if (iBMP_NBR_Count > 0) { sb.Append("BMP Number was not updated. The BMP Number already exists within this farm."); } else { a.bmp_nbr = sBMP_NBR; } } if (!string.IsNullOrEmpty(tbDescription.Text)) { a.description = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbDescription.Text, 400); } else { sb.Append("Description was not updated. Description is required. "); } if (!string.IsNullOrEmpty(tbSubIssueStatement.Text)) { a.issueStatement_wfp2 = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbSubIssueStatement.Text, 1000); } else { a.issueStatement_wfp2 = null; } if (!string.IsNullOrEmpty(ddlBMPSource.SelectedValue)) { a.fk_BMPSource_code = ddlBMPSource.SelectedValue; } else { sb.Append("BMP Source was not updated. BMP Source is required. "); } if (!string.IsNullOrEmpty(tbLocation.Text)) { a.location = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbLocation.Text, 96); } //else sb.Append("Location was not updated. Location is required. "); if (!string.IsNullOrEmpty(ddlRevisionDescription.SelectedValue)) { a.fk_revisionDescription_code = ddlRevisionDescription.SelectedValue; } else { sb.Append("Revision Description was not updated. Revision Description is required. "); } if (!string.IsNullOrEmpty(ddlPollutantCategory.SelectedValue)) { a.fk_pollutant_category_code = ddlPollutantCategory.SelectedValue; } else { sb.Append("Pollutant Category was not updated. Pollutant Category is required. "); } if (!string.IsNullOrEmpty(ddlBMPPractice.SelectedValue)) { a.fk_bmpPractice_code = Convert.ToDecimal(ddlBMPPractice.SelectedValue); } else { sb.Append("BMP Practice was not updated. BMP Practice is required. "); } if (!string.IsNullOrEmpty(tbUnitsPlanned.Text)) { try { a.units_planned = Convert.ToDecimal(tbUnitsPlanned.Text); } catch { sb.Append("Units Planned was not updated. Units Planned must be a number (Decimal). "); } } //else sb.Append("Units Planned was not updated. Units Planned is required. "); if (!string.IsNullOrEmpty(tbPriorPlanningEstimate.Text)) { try { a.est_plan_prior = Convert.ToDecimal(tbPriorPlanningEstimate.Text); } catch { sb.Append("Prior Planning Estimate was not updated. Prior Planning Estimate must be a number (Decimal). "); } } else { sb.Append("Prior Planning Estimate was not updated. Prior Planning Estimate is required. "); } if (!string.IsNullOrEmpty(tbPlanningEstimate.Text)) { try { a.est_plan_rev = Convert.ToDecimal(tbPlanningEstimate.Text); } catch { sb.Append("Planning Estimate was not updated. Planning Estimate must be a number (Decimal). "); } } else { sb.Append("Planning Estimate was not updated. Planning Estimate is required. "); } if (!string.IsNullOrEmpty(ddlCREP.SelectedValue)) { a.CREP = ddlCREP.SelectedValue; } else { a.CREP = null; } //if (!string.IsNullOrEmpty(ddlNMCPType.SelectedValue)) a.fk_NMCPType_code = ddlNMCPType.SelectedValue; //else a.fk_NMCPType_code = null; if (!string.IsNullOrEmpty(ddlSAA.SelectedValue) && !string.IsNullOrEmpty(ddlSA.SelectedValue)) { iPH_PK_SA_TP = Convert.ToInt32(ddlSA.SelectedValue); if (a.fk_supplementalAgreementTaxParcel != iPH_PK_SA_TP) { bPerformSABMPInsert = true; } a.fk_SAAssignType_code = ddlSAA.SelectedValue; } else if ((!string.IsNullOrEmpty(ddlSAA.SelectedValue) && string.IsNullOrEmpty(ddlSA.SelectedValue)) || (string.IsNullOrEmpty(ddlSAA.SelectedValue) && !string.IsNullOrEmpty(ddlSA.SelectedValue))) { sb.Append("Supplemental Agreement was not updated. Both Supplemental Agreement Assignment and Supplemental Agreement must be defined when attaching a Supplemental Agreement. "); } else if (string.IsNullOrEmpty(ddlSAA.SelectedValue) && string.IsNullOrEmpty(ddlSA.SelectedValue)) { if (a.fk_supplementalAgreementTaxParcel != null) { bPerformSABMPInsert = true; } a.fk_SAAssignType_code = null; } a.modified = DateTime.Now; a.modified_by = Session["userName"].ToString(); //wac.SubmitChanges(); ISingleResult <bmp_ag_update_expressResult> code = wac.bmp_ag_update_express(a.pk_bmp_ag, a.fk_pollutant_category_code, a.bmp_nbr, a.description, a.fk_bmpPractice_code, a.units_planned, a.units_completed, a.est_plan_prior, a.est_plan_rev, a.CREP, a.fk_BMPSource_code, a.location, a.fk_revisionDescription_code, a.fk_SAAssignType_code, a.fk_supplementalAgreementTaxParcel, a.fk_BMPTypeCode, a.fk_BMPCode_code, a.fk_BMPCREPH20_code, a.lifespan_year, a.revisionDescription_addl, a.issueStatement_wfp2, a.modified_by); int iCode = (int)code.ReturnValue; if (iCode == 0) { if (bPerformSABMPInsert) { int?i = null; //int iCodeInsert = wac.bmp_ag_SA_add(Convert.ToInt32(fvBMPPlanning.DataKey.Value), iPH_PK_SA_TP, Session["userName"].ToString(), ref i); int iCodeInsert = wac.bmp_ag_SA_add(Convert.ToInt32(fvBMPPlanning.DataKey.Value), iPH_PK_SA_TP, a.fk_SAAssignType_code, Session["userName"].ToString(), ref i); } fvBMPPlanning.ChangeMode(FormViewMode.ReadOnly); BindData_BMPPlanning_FormView(Convert.ToInt32(fvBMPPlanning.DataKey.Value)); } else { WACAlert.Show("Update failed: ", iCode); } if (!string.IsNullOrEmpty(sb.ToString())) { WACAlert.Show(sb.ToString(), 0); } } catch (Exception ex) { WACAlert.Show(ex.Message, 0); } } }