private bool StepNewIntermediateSectionsNext()
        {
            Page.Validate("intermediateData");
            if (Page.IsValid)
            {
                // Saving new data
                string secuentialPart = ddlNewIntermediateSectionId.SelectedValue.ToString();
                string street = tbxNewIntermediateStreet.Text.Trim();
                string usmh = tbxNewIntermediateUsmh.Text.Trim();
                string dsmh = tbxNewIntermediateDsmh.Text.Trim();
                string mapSize = tbxNewIntermediateMapSize.Text.Trim();
                string mapLength = tbxNewIntermediateMapLength.Text.Trim();

                ProjectAddSectionsTDS dataSet = new ProjectAddSectionsTDS();
                dataSet.ProjectAddSectionsNew.Merge(projectAddSectionsNew, true);
                ProjectAddSectionsNew intermediateData = new ProjectAddSectionsNew(dataSet);

                // ... Insert section
                string countryId = "0"; if (hdfCountryId.Value != "") countryId = hdfCountryId.Value;
                string provinceId = "0"; if (hdfProvinceId.Value != "") provinceId = hdfProvinceId.Value;
                string countyId = "0"; if (hdfCountyId.Value != "") countyId = hdfCountyId.Value;
                string cityId = "0"; if (hdfCityId.Value != "") cityId = hdfCityId.Value;

                string sectionId = countryId + "." + provinceId + "." + countyId + "." + cityId;
                sectionId = sectionId + "-" + secuentialPart;

                string flowOrderId = sectionId.Substring(sectionId.Length - 6, 6);

                bool rehabAssesswork = false; if (hdfWorkType.Value == "Rehab Assessment") rehabAssesswork = true;
                bool fullLengthLiningWork = false; if (hdfWorkType.Value == "Full Length Lining") fullLengthLiningWork = true;
                bool pointRepairsWork = false; if (hdfWorkType.Value == "Point Repairs") pointRepairsWork = true;
                bool junctionLiningWork = false; if (hdfWorkType.Value == "Junction Lining") junctionLiningWork = true;

                intermediateData.Insert(sectionId, street, usmh, dsmh, rehabAssesswork, fullLengthLiningWork, pointRepairsWork, junctionLiningWork, false, flowOrderId, mapSize, mapLength, "", "", "", "", "", null, null, "", "", "", "", "", null, "", "", "", "", "", "", "", "", "", "", null, null, "", "", "", "", "", null, "", "", "", "", "", "", "", false, false);

                // create temp dataset
                dataSet.ProjectAddSectionsTemp.Merge(projectAddSectionsTemp, true);

                // process new sections
                ProjectAddSectionsTemp model = new ProjectAddSectionsTemp(dataSet);
                model.ProcessNew();

                // get changes
                projectAddSectionsNew.Rows.Clear();
                projectAddSectionsTemp.Rows.Clear();
                projectAddSectionsTemp.Merge(model.Table);

                // store tables
                Session.Remove("projectAddSectionsNewDummy");
                Session["projectAddSectionsNew"] = projectAddSectionsNew;
                Session["projectAddSectionsTemp"] = projectAddSectionsTemp;
                return true;

            }
            return false;
        }
        private bool StepNewSectionsNext()
        {
            // Update dataset
            ProjectAddSectionsTDS dataSet = new ProjectAddSectionsTDS();
            dataSet.ProjectAddSectionsNew.Merge(projectAddSectionsNew, true);
            ProjectAddSectionsNew model = new ProjectAddSectionsNew(dataSet);

            // Conditions Gridview, if the gridview is edition mode
            if (grdProjectAddSectionsNew.EditIndex >= 0)
            {
                grdProjectAddSectionsNew.UpdateRow(grdProjectAddSectionsNew.EditIndex, false);
            }

            if (ValidateProjectAddSectionsFooter())
            {
                Page.Validate("AddSectionsAdd");
                if (!Page.IsValid)
                {
                    return false;
                }
                else
                {
                    bool cbxRA = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxRehabAssessmentWorkAdd")).Checked;
                    bool cbxFLL = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxFullLengthLiningWorkAdd")).Checked;
                    bool cbxPR = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxPointRepairsWorkAdd")).Checked;
                    bool cbxJL = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxJunctionLiningWorkAdd")).Checked;

                    bool cbxMHRehabUsmh = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxMHRehabUsmhAdd")).Checked;
                    bool cbxMHRehabDsmh = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxMHRehabDsmhAdd")).Checked;

                    if (cbxRA || cbxFLL || cbxJL || cbxPR)
                    {
                        // Get values
                        int companyId = Int32.Parse(hdfCompanyId.Value);
                        string street = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxStreetAdd")).Text;
                        string usmh = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxUsmhAdd")).Text;
                        string dsmh = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxDsmhAdd")).Text;
                        string mapSize = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxMapSizeAdd")).Text;
                        string mapLength = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxMapLengthAdd")).Text;

                        string clientId = "";
                        if (((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxClientIdAdd")).Text.Trim() != "")
                        {
                            clientId = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxClientIdAdd")).Text;
                        }

                        string sectionMaterial = "";
                        if (((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlSectionMaterialAdd")).SelectedValue != "-1")
                        {
                            sectionMaterial = ((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlSectionMaterialAdd")).SelectedValue;
                        }

                        string usmhStreet = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxUsmhStreetAdd")).Text.Trim();
                        string usmhLatitude = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxUsmhLatitudeAdd")).Text.Trim();
                        string usmhLongitude = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxUsmhLongitudeAdd")).Text.Trim();
                        string usmhShape = ((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhShapeAdd")).SelectedValue;
                        string usmhLocation = ((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhLocationAdd")).SelectedValue;
                        int? usmhConditionRating = null;
                        if (((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhConditionRatingAdd")).SelectedValue != "-1")
                        {
                            usmhConditionRating = Int32.Parse(((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhConditionRatingAdd")).SelectedValue);
                        }
                        int? usmhMaterialId = null;
                        string usmhMaterial = "";
                        if (((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhMaterialAdd")).SelectedValue != "-1")
                        {
                            usmhMaterialId = Int32.Parse(((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhMaterialAdd")).SelectedValue);
                            AssetSewerMHMaterialTypeGateway assetSewerMHMaterialTypeGatewayForUsmh = new AssetSewerMHMaterialTypeGateway();
                            assetSewerMHMaterialTypeGatewayForUsmh.LoadByMaterialId((int)usmhMaterialId, companyId);
                            usmhMaterial = assetSewerMHMaterialTypeGatewayForUsmh.GetMaterialType((int)usmhMaterialId);
                        }

                        string dsmhStreet = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxDsmhStreetAdd")).Text.Trim();
                        string dsmhLatitude = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxDsmhLatitudeAdd")).Text.Trim();
                        string dsmhLongitude = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxDsmhLongitudeAdd")).Text.Trim();
                        string dsmhShape = ((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhShapeAdd")).SelectedValue;
                        string dsmhLocation = ((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhLocationAdd")).SelectedValue;
                        int? dsmhConditionRating = null;
                        if (((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhConditionRatingAdd")).SelectedValue != "-1")
                        {
                            dsmhConditionRating = Int32.Parse(((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhConditionRatingAdd")).SelectedValue);
                        }
                        int? dsmhMaterialId = null;
                        string dsmhMaterial = "";
                        if (((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhMaterialAdd")).SelectedValue != "-1")
                        {
                            dsmhMaterialId = Int32.Parse(((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhMaterialAdd")).SelectedValue);
                            AssetSewerMHMaterialTypeGateway assetSewerMHMaterialTypeGatewayForDsmh = new AssetSewerMHMaterialTypeGateway();
                            assetSewerMHMaterialTypeGatewayForDsmh.LoadByMaterialId((int)dsmhMaterialId, companyId);
                            dsmhMaterial = assetSewerMHMaterialTypeGatewayForDsmh.GetMaterialType((int)dsmhMaterialId);
                        }

                        // ... get structure data
                        string usmhTopDiameter = "";
                        string usmhTopDepth = "";
                        string usmhDownDiameter = "";
                        string usmhDownDepth = "";
                        int? usmhManholeRugs = null;
                        string usmhRectangle1LongSide = "";
                        string usmhRectangle1ShortSide = "";
                        string usmhRectangle2LongSide = "";
                        string usmhRectangle2ShortSide = "";
                        string usmhTotalSurfaceArea = "";
                        string dsmhTopDiameter = "";
                        string dsmhTopDepth = "";
                        string dsmhDownDiameter = "";
                        string dsmhDownDepth = "";
                        int? dsmhManholeRugs = null;
                        string dsmhRectangle1LongSide = "";
                        string dsmhRectangle1ShortSide = "";
                        string dsmhRectangle2LongSide = "";
                        string dsmhRectangle2ShortSide = "";
                        string dsmhTotalSurfaceArea = "";

                        int sectionId = model.Table.Rows.Count + 1;

                        // Insert section
                        if ((street != "") || (usmh != "") || (dsmh != "") || (mapSize != "") || (mapLength != ""))
                        {
                            model.Insert(sectionId.ToString(), street, usmh, dsmh, cbxRA, cbxFLL, cbxPR, cbxJL, false, sectionId.ToString(), mapSize, mapLength, usmhStreet, usmhLatitude, usmhLongitude, usmhShape, usmhLocation, usmhConditionRating, usmhMaterialId, usmhMaterial, usmhTopDiameter, usmhTopDepth, usmhDownDiameter, usmhDownDepth, usmhManholeRugs, usmhRectangle1LongSide, usmhRectangle1ShortSide, usmhRectangle2LongSide, usmhRectangle2ShortSide, usmhTotalSurfaceArea, dsmhStreet, dsmhLatitude, dsmhLongitude, dsmhShape, dsmhLocation, dsmhConditionRating, dsmhMaterialId, dsmhMaterial, dsmhTopDiameter, dsmhTopDepth, dsmhDownDiameter, dsmhDownDepth, dsmhManholeRugs, dsmhRectangle1LongSide, dsmhRectangle1ShortSide, dsmhRectangle2LongSide, dsmhRectangle2ShortSide, dsmhTotalSurfaceArea, sectionMaterial, clientId, cbxMHRehabUsmh, cbxMHRehabDsmh);
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
            }

            // create dataset for temp
            dataSet.ProjectAddSectionsTemp.Merge(projectAddSectionsTemp, true);

            // process new sections
            ProjectAddSectionsTemp modelTemp = new ProjectAddSectionsTemp(dataSet);
            modelTemp.ProcessNew();

            // get changes
            projectAddSectionsNew.Rows.Clear();
            projectAddSectionsTemp.Rows.Clear();
            projectAddSectionsTemp.Merge(modelTemp.Table);

            // store tables
            Session.Remove("projectAddSectionsNewDummy");
            Session["projectAddSectionsNew"] = projectAddSectionsNew;
            Session["projectAddSectionsTemp"] = projectAddSectionsTemp;

            return true;
        }
        private void GrdProjectAddSectionsNewAdd()
        {
            if (ValidateProjectAddSectionsFooter())
            {
                Page.Validate("AddSectionsAdd");
                if (Page.IsValid)
                {
                    // Get values
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    string street = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxStreetAdd")).Text;
                    string usmh = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxUsmhAdd")).Text;
                    string dsmh = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxDsmhAdd")).Text;
                    string mapSize = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxMapSizeAdd")).Text;
                    string mapLength = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxMapLengthAdd")).Text;

                    string clientId = "";
                    if (((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxClientIdAdd")).Text.Trim() != "")
                    {
                        clientId = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxClientIdAdd")).Text;
                    }

                    string sectionMaterial = "";
                    if (((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlSectionMaterialAdd")).SelectedValue != "-1")
                    {
                        sectionMaterial = ((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlSectionMaterialAdd")).SelectedValue;
                    }

                    bool cbxRA = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxRehabAssessmentWorkAdd")).Checked;
                    bool cbxFLL = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxFullLengthLiningWorkAdd")).Checked;
                    bool cbxPR = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxPointRepairsWorkAdd")).Checked;
                    bool cbxJL = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxJunctionLiningWorkAdd")).Checked;

                    bool cbxMHRehabUsmh = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxMHRehabUsmhAdd")).Checked;
                    bool cbxMHRehabDsmh = ((CheckBox)grdProjectAddSectionsNew.FooterRow.FindControl("cbxMHRehabDsmhAdd")).Checked;

                    string usmhStreet = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxUsmhStreetAdd")).Text.Trim();
                    string usmhLatitude = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxUsmhLatitudeAdd")).Text.Trim();
                    string usmhLongitude = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxUsmhLongitudeAdd")).Text.Trim();
                    string usmhShape = ((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhShapeAdd")).SelectedValue;
                    string usmhLocation = ((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhLocationAdd")).SelectedValue;
                    int? usmhConditionRating = null;
                    if (((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhConditionRatingAdd")).SelectedValue != "-1")
                    {
                        usmhConditionRating = Int32.Parse(((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhConditionRatingAdd")).SelectedValue);
                    }
                    int? usmhMaterialId = null;
                    string usmhMaterial = "";
                    if (((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhMaterialAdd")).SelectedValue != "-1")
                    {
                        usmhMaterialId = Int32.Parse(((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlUsmhMaterialAdd")).SelectedValue);
                        AssetSewerMHMaterialTypeGateway assetSewerMHMaterialTypeGatewayForUsmh = new AssetSewerMHMaterialTypeGateway();
                        assetSewerMHMaterialTypeGatewayForUsmh.LoadByMaterialId((int)usmhMaterialId, companyId);
                        usmhMaterial = assetSewerMHMaterialTypeGatewayForUsmh.GetMaterialType((int)usmhMaterialId);
                    }

                    string dsmhStreet = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxDsmhStreetAdd")).Text.Trim();
                    string dsmhLatitude = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxDsmhLatitudeAdd")).Text.Trim();
                    string dsmhLongitude = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxDsmhLongitudeAdd")).Text.Trim();
                    string dsmhShape = ((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhShapeAdd")).SelectedValue;
                    string dsmhLocation = ((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhLocationAdd")).SelectedValue;
                    int? dsmhConditionRating = null;
                    if (((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhConditionRatingAdd")).SelectedValue != "-1")
                    {
                        dsmhConditionRating = Int32.Parse(((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhConditionRatingAdd")).SelectedValue);
                    }
                    int? dsmhMaterialId = null;
                    string dsmhMaterial = "";
                    if (((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhMaterialAdd")).SelectedValue != "-1")
                    {
                        dsmhMaterialId = Int32.Parse(((DropDownList)grdProjectAddSectionsNew.FooterRow.FindControl("ddlDsmhMaterialAdd")).SelectedValue);
                        AssetSewerMHMaterialTypeGateway assetSewerMHMaterialTypeGatewayForDsmh = new AssetSewerMHMaterialTypeGateway();
                        assetSewerMHMaterialTypeGatewayForDsmh.LoadByMaterialId((int)dsmhMaterialId, companyId);
                        dsmhMaterial = assetSewerMHMaterialTypeGatewayForDsmh.GetMaterialType((int)dsmhMaterialId);
                    }

                    // ... get structure data
                    string usmhTopDiameter = "";
                    string usmhTopDepth = "";
                    string usmhDownDiameter = "";
                    string usmhDownDepth = "";
                    int? usmhManholeRugs = null;
                    string usmhRectangle1LongSide = "";
                    string usmhRectangle1ShortSide = "";
                    string usmhRectangle2LongSide = "";
                    string usmhRectangle2ShortSide = "";
                    string usmhTotalSurfaceArea = "";
                    string dsmhTopDiameter = "";
                    string dsmhTopDepth = "";
                    string dsmhDownDiameter = "";
                    string dsmhDownDepth = "";
                    int? dsmhManholeRugs = null;
                    string dsmhRectangle1LongSide = "";
                    string dsmhRectangle1ShortSide = "";
                    string dsmhRectangle2LongSide = "";
                    string dsmhRectangle2ShortSide = "";
                    string dsmhTotalSurfaceArea = "";

                    // Update datasets
                    ProjectAddSectionsTDS dataSet = new ProjectAddSectionsTDS();
                    dataSet.ProjectAddSectionsNew.Merge(projectAddSectionsNew, true);
                    ProjectAddSectionsNew model = new ProjectAddSectionsNew(dataSet);
                    int sectionId = model.Table.Rows.Count + 1;

                    // Insert section
                    model.Insert(sectionId.ToString(), street, usmh, dsmh, cbxRA, cbxFLL, cbxPR, cbxJL, false, sectionId.ToString(), mapSize, mapLength, usmhStreet, usmhLatitude, usmhLongitude, usmhShape, usmhLocation, usmhConditionRating, usmhMaterialId, usmhMaterial, usmhTopDiameter, usmhTopDepth, usmhDownDiameter, usmhDownDepth, usmhManholeRugs, usmhRectangle1LongSide, usmhRectangle1ShortSide, usmhRectangle2LongSide, usmhRectangle2ShortSide, usmhTotalSurfaceArea, dsmhStreet, dsmhLatitude, dsmhLongitude, dsmhShape, dsmhLocation, dsmhConditionRating, dsmhMaterialId, dsmhMaterial, dsmhTopDiameter, dsmhTopDepth, dsmhDownDiameter, dsmhDownDepth, dsmhManholeRugs, dsmhRectangle1LongSide, dsmhRectangle1ShortSide, dsmhRectangle2LongSide, dsmhRectangle2ShortSide, dsmhTotalSurfaceArea, sectionMaterial, clientId, cbxMHRehabUsmh, cbxMHRehabDsmh);

                    // Store data
                    Session.Remove("projectAddSectionsNewDummy");
                    Session["projectAddSectionsNew"] = dataSet.ProjectAddSectionsNew;

                    grdProjectAddSectionsNew.DataBind();

                    grdProjectAddSectionsNew.PageIndex = grdProjectAddSectionsNew.PageCount - 1;
                }
            }
        }