Beispiel #1
0
    protected void fvAg_WFP3_BMP_ItemUpdating(object sender, EventArgs e)
    {
        StringBuilder sbErrorCollection = new StringBuilder();

        FormView     fv              = fvAg_WFP3_BMP;
        DropDownList ddlBMP          = fv.FindControl("ddlBMP") as DropDownList;
        TextBox      tbUnitsDesigned = fv.FindControl("tbUnitsDesigned") as TextBox;
        TextBox      tbDesignCost    = fv.FindControl("tbDesignCost") as TextBox;
        //TextBox tbDimensions = fv.FindControl("tbDimensions") as TextBox;
        TextBox tbUnitsCompleted = fv.FindControl("tbUnitsCompleted") as TextBox;

        //TextBox tbDesignCostNote = fv.FindControl("tbDesignCostNote") as TextBox;

        using (WACDataClassesDataContext wDataContext = new WACDataClassesDataContext())
        {
            var a = (from b in wDataContext.vw_form_wfp3_BMPs.Where(w => w.pk_form_wfp3_bmp == Convert.ToInt32(fv.DataKey.Value))
                     select b).Single();
            int     pk_form_wfp3_bmp = a.pk_form_wfp3_bmp;
            int     fk_bmp_ag        = a.pk_bmp_ag;
            decimal?units_designed   = a.units_designed;
            decimal?design_cost      = a.design_cost;
            decimal?units_completed  = a.units_completed;

            try
            {
                if (!string.IsNullOrEmpty(ddlBMP.SelectedValue))
                {
                    fk_bmp_ag = Convert.ToInt32(ddlBMP.SelectedValue);
                }

                if (!string.IsNullOrEmpty(tbUnitsDesigned.Text))
                {
                    try { units_designed = Convert.ToDecimal(tbUnitsDesigned.Text); }
                    catch
                    {
                        sbErrorCollection.Append("Units Designed was not updated. Units Designed must be a number (Decimal). ");
                        units_designed = a.units_designed;
                    }
                }

                if (!string.IsNullOrEmpty(tbDesignCost.Text))
                {
                    try { design_cost = Convert.ToDecimal(tbDesignCost.Text); }
                    catch
                    {
                        sbErrorCollection.Append("Design Cost was not updated. Design Cost must be a number (Decimal). ");
                        design_cost = a.design_cost;
                    }
                }

                if (!string.IsNullOrEmpty(tbUnitsCompleted.Text))
                {
                    try { units_completed = Convert.ToDecimal(tbUnitsCompleted.Text); }
                    catch
                    {
                        sbErrorCollection.Append("Units Completed was not updated. Design Cost must be a number (Decimal). ");
                        units_completed = a.units_completed;
                    }
                }

                int iCode = wDataContext.form_wfp3_bmp_update(pk_form_wfp3_bmp, fk_bmp_ag, units_designed, units_completed, design_cost, Session["userName"].ToString());
                if (iCode != 0)
                {
                    WACAlert.Show("Error Returned from Database. ", iCode);
                }

                if (!string.IsNullOrEmpty(sbErrorCollection.ToString()))
                {
                    WACAlert.Show(sbErrorCollection.ToString(), 0);
                }
            }
            catch (Exception ex) { WACAlert.Show(ex.Message, 0); }
        }
    }