protected void fvAg_WFP3_Invoice_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        int?     i     = null;
        int      iCode = 0;
        FormView fv    = fvAg_WFP3_Invoice;

        CustomControls_AjaxCalendar invoiceDate = fv.FindControl("tbCalInvoiceDate") as CustomControls_AjaxCalendar;
        TextBox tbInvoiceNumber = fv.FindControl("tbInvoiceNumber") as TextBox;
        TextBox tbAmount        = fv.FindControl("tbAmount") as TextBox;

        StringBuilder sb = new StringBuilder();

        using (WACDataClassesDataContext wDataContext = new WACDataClassesDataContext())
        {
            try
            {
                DateTime?dtDate = invoiceDate.CalDateNullable;

                string sInvoiceNumber = null;
                if (!string.IsNullOrEmpty(tbInvoiceNumber.Text))
                {
                    sInvoiceNumber = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbInvoiceNumber.Text, 48);
                }
                else
                {
                    sb.Append("Invoice Number is required. ");
                }

                decimal?dAmount = null;
                if (!string.IsNullOrEmpty(tbAmount.Text))
                {
                    try { dAmount = Convert.ToDecimal(tbAmount.Text); }
                    catch { sb.Append("Amount must be a number (Decimal). "); }
                }
                else
                {
                    sb.Append("Amount is required. ");
                }

                if (string.IsNullOrEmpty(sb.ToString()))
                {
                    iCode = wDataContext.form_wfp3_invoice_add(FK_Wfp3, dtDate, sInvoiceNumber, dAmount, Session["userName"].ToString(), ref i);
                    if (iCode != 0)
                    {
                        WACAlert.Show("Error Returned from Database.", iCode);
                    }
                    else
                    {
                        PK_Wfp3Invoice = Convert.ToInt32(i);
                    }
                }
                else
                {
                    WACAlert.Show(sb.ToString(), iCode);
                }
            }
            catch (Exception ex) { WACAlert.Show(ex.Message, 0); }
        }
    }