Beispiel #1
0
    protected void fvAg_WFP3_Bid_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        int?     i     = null;
        int      iCode = 0;
        FormView fv    = fvAg_WFP3_Bid;

        DropDownList ddlContractor = fv.FindControl("ddlContractor") as DropDownList;
        TextBox      tbBidAmount   = fv.FindControl("tbBidAmount") as TextBox;
        CustomControls_AjaxCalendar tbCalBidAwardDate = fv.FindControl("tbCalBidAwardDate") as CustomControls_AjaxCalendar;
        TextBox tbModificationAmount = fv.FindControl("tbModificationAmount") as TextBox;
        TextBox tbBidRank            = fv.FindControl("tbBidRank") as TextBox;
        TextBox tbNote = fv.FindControl("tbNote") as TextBox;

        StringBuilder sb = new StringBuilder();

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

                decimal?dBidAmount = null;
                try { if (!string.IsNullOrEmpty(tbBidAmount.Text))
                      {
                          dBidAmount = Convert.ToDecimal(tbBidAmount.Text);
                      }
                }
                catch { }
                if (dBidAmount == null || dBidAmount == 0)
                {
                    sb.Append("Bid Amount is required and must be greater than 0. ");
                }

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

                string sNote = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbNote.Text, 255);

                byte?byBidRank = null;
                try { if (!string.IsNullOrEmpty(tbBidRank.Text))
                      {
                          byBidRank = Convert.ToByte(tbBidRank.Text);
                      }
                }
                catch { }

                DateTime?dtBidAwarded = tbCalBidAwardDate.CalDateNullable;

                if (string.IsNullOrEmpty(sb.ToString()))
                {
                    iCode = wDataContext.form_wfp3_bid_add(FK_Wfp3, iContractorFK, dBidAmount, dModificationAmount, sNote, byBidRank, dtBidAwarded, Session["userName"].ToString(), ref i);
                    if (iCode != 0)
                    {
                        WACAlert.Show("Error Returned from Database.", iCode);
                    }
                    else
                    {
                        PK_Wfp3Bid = Convert.ToInt32(i);
                    }
                }
                else
                {
                    WACAlert.Show(sb.ToString(), iCode);
                }
            }
            catch (Exception ex) { WACAlert.Show(ex.Message, 0); }
        }
    }