Exemple #1
0
    protected int fvAg_WFP3_ItemInserting(object sender, EventArgs e)
    {
        int?i     = null;
        int iCode = -1;

        CustomControls_AjaxCalendar tbCalDesignDate          = fvAg_WFP3.FindControl("tbCalDesignDate") as CustomControls_AjaxCalendar;
        CustomControls_AjaxCalendar tbCalProcurementPlanDate = fvAg_WFP3.FindControl("tbCalProcurementPlanDate") as CustomControls_AjaxCalendar;
        CustomControls_AjaxCalendar tbCalOutForBidDate       = fvAg_WFP3.FindControl("tbCalOutForBidDate") as CustomControls_AjaxCalendar;
        CustomControls_AjaxCalendar tbCalBidDeadlineDate     = fvAg_WFP3.FindControl("tbCalBidDeadlineDate") as CustomControls_AjaxCalendar;
        CustomControls_AjaxCalendar tbCalInstallToDate       = fvAg_WFP3.FindControl("tbCalInstallToDate") as CustomControls_AjaxCalendar;
        CustomControls_AjaxCalendar tbCalInstallFromDate     = fvAg_WFP3.FindControl("tbCalInstallFromDate") as CustomControls_AjaxCalendar;
        CustomControls_AjaxCalendar tbCalConstructionDate    = fvAg_WFP3.FindControl("tbCalConstructionDate") as CustomControls_AjaxCalendar;
        CustomControls_AjaxCalendar tbCalPrintDate           = fvAg_WFP3.FindControl("tbCalPrintDate") as CustomControls_AjaxCalendar;
        DropDownList ddlSpecialProvisions     = fvAg_WFP3.FindControl("ddlSpecialProvisions") as DropDownList;
        TextBox      tbDescription            = fvAg_WFP3.FindControl("tbDescription") as TextBox;
        TextBox      tbAttachedPages          = fvAg_WFP3.FindControl("tbAttachedPages") as TextBox;
        TextBox      tbAttachedSpecifications = fvAg_WFP3.FindControl("tbAttachedSpecifications") as TextBox;
        DropDownList ddlProcurementType       = fvAg_WFP3.FindControl("ddlProcurementType") as DropDownList;
        TextBox      tbNote = fvAg_WFP3.FindControl("tbNote") as TextBox;

        StringBuilder sb = new StringBuilder();

        using (WACDataClassesDataContext wDataContext = new WACDataClassesDataContext())
        {
            try
            {
                string sProcurementType = null;
                if (!string.IsNullOrEmpty(ddlProcurementType.SelectedValue))
                {
                    sProcurementType = ddlProcurementType.SelectedValue;
                }
                if (string.IsNullOrEmpty(sProcurementType))
                {
                    sb.Append("Procurement Type is required. ");
                }

                if (!string.IsNullOrEmpty(sProcurementType))
                {
                    string sDescription = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbDescription.Text, 255);

                    DateTime?dtDesignDate = tbCalDesignDate.CalDateNullable;

                    DateTime?dtProcurementPlanDate = tbCalProcurementPlanDate.CalDateNullable;

                    DateTime?dtOutForBid = tbCalOutForBidDate.CalDateNullable;

                    DateTime?dtBidDeadlineDate = tbCalBidDeadlineDate.CalDateNullable;

                    DateTime?dtUnderConstruction = tbCalConstructionDate.CalDateNullable;

                    string sSpecialProvisions = "N";
                    if (!string.IsNullOrEmpty(ddlSpecialProvisions.SelectedValue))
                    {
                        sSpecialProvisions = ddlSpecialProvisions.SelectedValue;
                    }

                    DateTime?dtInstallFrom = tbCalInstallFromDate.CalDateNullable;

                    DateTime?dtInstallTo = tbCalInstallToDate.CalDateNullable;

                    DateTime?dtPrintDate = tbCalPrintDate.CalDateNullable;

                    string sAttachedPages = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbAttachedPages.Text, 4);

                    string sAttachedSpecifications = null;
                    if (!string.IsNullOrEmpty(tbAttachedSpecifications.Text))
                    {
                        sAttachedSpecifications = WACGlobal_Methods.Format_Global_StringLengthRestriction(tbAttachedSpecifications.Text, 255);
                    }

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

                    iCode = wDataContext.form_wfp3_add_express(Convert.ToInt32(FK_FarmBusiness), sDescription, sProcurementType, dtDesignDate, dtPrintDate,
                                                               dtProcurementPlanDate, dtBidDeadlineDate, dtOutForBid, dtUnderConstruction, sSpecialProvisions, dtInstallFrom, dtInstallTo, sAttachedPages,
                                                               sAttachedSpecifications, sNote, Session["userName"].ToString(), ref i);
                    if (iCode == 0)
                    {
                        fvAg_WFP3.ChangeMode(FormViewMode.ReadOnly);
                        PK_FormWfp3 = Convert.ToInt32(i);
                        BindAg_WFP3();
                    }
                    else
                    {
                        WACAlert.Show("Error Returned from Database.", iCode);
                    }
                }
                else
                {
                    WACAlert.Show(sb.ToString(), 0);
                }
            }
            catch (Exception ex) { WACAlert.Show(ex.Message, 0); }
        }
        return(iCode);
    }