コード例 #1
0
    protected void fvBMPPlanning_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        int?i     = null;
        int iCode = 0;

        DropDownList ddlFarm                 = fvBMPPlanning.FindControl("ddlFarm") as DropDownList;
        DropDownList ddlBMPSource            = fvBMPPlanning.FindControl("ddlBMPSource") as DropDownList;
        DropDownList ddlRevisionDescription  = fvBMPPlanning.FindControl("ddlRevisionDescription") as DropDownList;
        DropDownList ddlPollutantCategory    = fvBMPPlanning.FindControl("ddlPollutantCategory") as DropDownList;
        TextBox      tbBMPNumber             = fvBMPPlanning.FindControl("tbBMPNumber") as TextBox;
        TextBox      tbDescription           = fvBMPPlanning.FindControl("tbDescription") as TextBox;
        TextBox      tbSubIssueStatement     = fvBMPPlanning.FindControl("tbSubIssueStatement") as TextBox;
        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 ddlImplementationYear = fvBMPPlanning.FindControl("ddlImplementationYear") as DropDownList;
        TextBox      tbLocation = fvBMPPlanning.FindControl("tbLocation") 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;

        StringBuilder sb = new StringBuilder();

        using (WACDataClassesDataContext wDataContext = new WACDataClassesDataContext())
        {
            try
            {
                int?iPK_FarmBusiness = null;
                if (!string.IsNullOrEmpty(ddlFarm.SelectedValue))
                {
                    iPK_FarmBusiness = Convert.ToInt32(ddlFarm.SelectedValue);
                }
                else
                {
                    sb.Append("Farm is required. ");
                }

                string sBMPSource = ddlBMPSource.SelectedValue;

                string sPollutant = null;
                if (!string.IsNullOrEmpty(ddlPollutantCategory.SelectedValue))
                {
                    sPollutant = ddlPollutantCategory.SelectedValue;
                }
                else
                {
                    sb.Append("Pollutant is required. ");
                }

                string sBMPNumber = null;
                if (!string.IsNullOrEmpty(tbBMPNumber.Text))
                {
                    sBMPNumber = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbBMPNumber.Text, 24);
                }
                else
                {
                    sb.Append("BMP Number is required. ");
                }

                string sDescription = null;
                if (!string.IsNullOrEmpty(tbDescription.Text))
                {
                    sDescription = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbDescription.Text, 400);
                }
                string  sSubIssueStatement = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbSubIssueStatement.Text, 1000);
                decimal?dPractice          = null;
                if (!string.IsNullOrEmpty(ddlBMPPractice.SelectedValue))
                {
                    dPractice = Convert.ToDecimal(ddlBMPPractice.SelectedValue);
                }
                else
                {
                    sb.Append("Practice is required. ");
                }

                decimal?dUnitsPlanned = null;
                if (!string.IsNullOrEmpty(tbUnitsPlanned.Text))
                {
                    try { dUnitsPlanned = Convert.ToDecimal(tbUnitsPlanned.Text); }
                    catch { }
                }

                decimal?dEstPlanPrior = null;
                if (!string.IsNullOrEmpty(tbPriorPlanningEstimate.Text))
                {
                    try { dEstPlanPrior = Convert.ToDecimal(tbPriorPlanningEstimate.Text); }
                    catch { }
                }
                else
                {
                    sb.Append("Prior Planning Estimate is required. ");
                }

                decimal?dCurrentPlanningEstimate = null;
                if (!string.IsNullOrEmpty(tbPlanningEstimate.Text))
                {
                    try { dCurrentPlanningEstimate = Convert.ToDecimal(tbPlanningEstimate.Text); }
                    catch { sb.Append("Current Planning Estimate must be a number (Decimal). "); }
                }
                else
                {
                    sb.Append("Current Planning Estimate is required. ");
                }

                string sCREP = null;
                if (!string.IsNullOrEmpty(ddlCREP.SelectedValue))
                {
                    sCREP = ddlCREP.SelectedValue;
                }

                string sBMPStatus = "DR";

                //short? shScheduledImplementationYear = null;
                //if (!string.IsNullOrEmpty(ddlImplementationYear.SelectedValue)) shScheduledImplementationYear = Convert.ToInt16(ddlImplementationYear.SelectedValue);
                //else sb.Append("Implementation Year is required. ");

                //string sNMCPType = null;
                //if (!string.IsNullOrEmpty(ddlNMCPType.SelectedValue)) sNMCPType = ddlNMCPType.SelectedValue;

                string sLocation = null;
                if (!string.IsNullOrEmpty(tbLocation.Text))
                {
                    sLocation = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbLocation.Text, 96);
                }

                string sRevisionDescription = null;
                if (!string.IsNullOrEmpty(ddlRevisionDescription.SelectedValue))
                {
                    sRevisionDescription = ddlRevisionDescription.SelectedValue;
                }

                string sSAAssignType = null;
                int?   iPK_SupplementalAgreementTaxParcel = null;
                if (!string.IsNullOrEmpty(ddlSAA.SelectedValue) && !string.IsNullOrEmpty(ddlSA.SelectedValue))
                {
                    sSAAssignType = ddlSAA.SelectedValue;
                    iPK_SupplementalAgreementTaxParcel = Convert.ToInt32(ddlSA.SelectedValue);
                }
                else
                {
                    if ((!string.IsNullOrEmpty(ddlSAA.SelectedValue) && string.IsNullOrEmpty(ddlSA.SelectedValue)) || (string.IsNullOrEmpty(ddlSAA.SelectedValue) && !string.IsNullOrEmpty(ddlSA.SelectedValue)))
                    {
                        sb.Append("Both Supplemental Agreement Assignment and Supplemental Agreement must be defined when attaching a Supplemental Agreement. ");
                    }
                }


                string sfk_BMPSortGroup_code = null;
                //if (!string.IsNullOrEmpty(sfk_BMPSortGroup_code.Text)) sLocation = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbLocation.Text, 96);

                if (string.IsNullOrEmpty(sb.ToString()))
                {
                    iCode = wDataContext.bmp_ag_add_express(iPK_FarmBusiness, sPollutant, sBMPNumber, sDescription, dPractice,
                                                            dUnitsPlanned, dEstPlanPrior, dCurrentPlanningEstimate, sCREP, sBMPStatus, sBMPSource, sLocation, sRevisionDescription,
                                                            sSAAssignType, iPK_SupplementalAgreementTaxParcel, sfk_BMPSortGroup_code, null, null, sSubIssueStatement,
                                                            Session["userName"].ToString(), ref i);
                    if (iCode == 0)
                    {
                        fvBMPPlanning.ChangeMode(FormViewMode.ReadOnly);
                        BindData_BMPPlanning_FormView(Convert.ToInt32(i));
                    }
                    else
                    {
                        WACAlert.Show("Error Returned from Database.", iCode);
                    }
                }
                else
                {
                    sb.Insert(0, "The Insert Failed: ");
                    WACAlert.Show(sb.ToString(), 0);
                }
            }
            catch (Exception ex) { WACAlert.Show(ex.Message, 0); }
        }
    }