private void UpdateDatabase()
        {
            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            Int64 countryId = projectGateway.GetCountryID(projectId);
            Int64? provinceId = null; if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? countyId = null; if (projectGateway.GetCountyID(projectId).HasValue) countyId = (Int64)projectGateway.GetCountyID(projectId);
            Int64? cityId = null; if (projectGateway.GetCityID(projectId).HasValue) cityId = (Int64)projectGateway.GetCityID(projectId);

            string workType = hdfWorkType.Value.Trim();
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int workId = Int32.Parse(hdfWorkId.Value);
            int sectionAssetId = Int32.Parse(hdfAssetId.Value);
            bool isNewMeasuredFromDsmh = false;

            FullLengthLiningLateralDetails flLateralDetails = new FullLengthLiningLateralDetails();
            flLateralDetails.LoadForEdit(workId, sectionAssetId, companyId, projectId);

            if (flLateralDetails.Table.Rows.Count == 0)
            {
                if (ddlM1DataMeasuredFromMh.SelectedValue == "DSMH")
                {
                    isNewMeasuredFromDsmh = true;
                    FullLengthLiningLateralDetails fllLateralDetails = new FullLengthLiningLateralDetails(fullLengthLiningTDS);
                    fllLateralDetails.ModifyLateralId();
                }
            }

            DB.Open();
            DB.BeginTransaction();
            try
            {
                // Save lateral details
                // Save lateral details
                bool roboticPrepCompleted = ckbxPrepDataRoboticPrepCompleted.Checked;
                DateTime? roboticPrepCompletedCompleted = null; if (tkrdpPrepDataRoboticPrepCompletedDate.SelectedDate.HasValue) roboticPrepCompletedCompleted = tkrdpPrepDataRoboticPrepCompletedDate.SelectedDate.Value;

                FullLengthLiningLateralDetails fullLengthLiningLateralDetails = new FullLengthLiningLateralDetails(fullLengthLiningTDS);
                fullLengthLiningLateralDetails.Save(workId, projectId, sectionAssetId, countryId, provinceId, countyId, cityId, tbxVideoLength.Text.Trim(), companyId, isNewMeasuredFromDsmh, roboticPrepCompleted, roboticPrepCompletedCompleted);

                // Save catalyst details
                string newRunDetails = "";
                foreach (ListItem lst in cbxlSectionId.Items)
                {
                    if (lst.Selected)
                    {
                        newRunDetails = newRunDetails + lst.Value + ">";
                    }
                }
                newRunDetails = newRunDetails.Substring(0, newRunDetails.Length - 1);
                FullLengthLiningWetOutCatalystsDetails fullLengthLiningWetOutCatalystsDetails = new FullLengthLiningWetOutCatalystsDetails(fullLengthLiningTDS);
                fullLengthLiningWetOutCatalystsDetails.Save(companyId, newRunDetails, projectId);

                // Save section details
                FullLengthLiningSectionDetails fullLengthLiningSectionDetails = new FullLengthLiningSectionDetails(fullLengthLiningTDS);
                fullLengthLiningSectionDetails.Save(countryId, provinceId, countyId, cityId, projectId, companyId);

                // Save work details
                FullLengthLiningWorkDetails fullLengthLiningWorkDetails = new FullLengthLiningWorkDetails(fullLengthLiningTDS);
                fullLengthLiningWorkDetails.Save(countryId, provinceId, countyId, cityId, projectId, sectionAssetId, companyId, ckbxWetOutDataIncludeWetOutInformation.Checked, ckbxInversionDataIncludeInversionInformation.Checked);

                // Save material details
                string newMaterial = ddlM1DataMaterial.SelectedValue;

                if (ddlM1DataMaterial.SelectedIndex > 0)
                {
                    LfsAssetSewerLateralGateway lfsAssetSewertLateralGateway = new LfsAssetSewerLateralGateway(null);
                    if (!lfsAssetSewertLateralGateway.IsUsedInMaterials(sectionAssetId, newMaterial, companyId))
                    {
                        MaterialInformation materialInformation = new MaterialInformation(materialInformationTDS);
                        materialInformation.Save(companyId);
                    }
                }

                DB.CommitTransaction();

                // Store datasets
                fullLengthLiningTDS.AcceptChanges();
                Session["fullLengthLiningTDS"] = fullLengthLiningTDS;

                materialInformationTDS.AcceptChanges();
                Session["materialInformationTDS"] = materialInformationTDS;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="loginId">loginId</param>
        public void Save(int projectId, Int64 countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int companyId, int loginId)
        {
            FullLengthLiningTDS fullLengthLiningTDS = new FullLengthLiningTDS();

            foreach (WincapBulkUploadTDS.WincapBulkUploadRow row in (WincapBulkUploadTDS.WincapBulkUploadDataTable)Table)
            {
                string state = ""; if (!row.IsStateNull()) state = row.State;
                string direction = ""; if (!row.IsDirectionNull()) direction = row.Direction;
                string distance = ""; if (!row.IsDistanceNull()) distance = row.Distance;
                string videoDistance = ""; if (!row.IsVideoDistanceNull()) videoDistance = row.VideoDistance;
                string clockPosition = ""; if (!row.IsClockPositionNull()) clockPosition = row.ClockPosition;
                string distanceToCentre = ""; if (!row.IsDistanceToCentreNull()) distanceToCentre = row.DistanceToCentre;
                string reverseSetup = ""; if (!row.IsReverseSetupNull()) reverseSetup = row.ReverseSetup;
                string comments = ""; if (!row.IsCommentsNull()) comments = row.Comments;
                string measuredFromMh = "USMH";
                if (row.Direction.Contains("D"))
                {
                    measuredFromMh = "DSMH";
                }

                int section_assetId = SaveSection(row.SectionID, projectId, countryId, provinceId, countyId, cityId, companyId);

                WorkFullLengthLining workFullLengthLining = new WorkFullLengthLining(null);
                int workId = workFullLengthLining.InsertDirectEmptyWorks(projectId, section_assetId, null, "", null, null, null, null, null, null, null, false, false, false, false, false, false, false, companyId, false, "", "");

                FullLengthLiningLateralDetails flLateralDetails = new FullLengthLiningLateralDetails();
                flLateralDetails.LoadForEdit(workId, section_assetId, companyId, projectId);

                // Generate increment
                string lateralIdIncrement = "";

                if (measuredFromMh == "USMH" || measuredFromMh == "")
                {
                    lateralIdIncrement = flLateralDetails.GetMaxLateralId2();
                }
                else
                {
                    if (measuredFromMh == "DSMH")
                    {
                        lateralIdIncrement = flLateralDetails.GetMinLateralId2();
                    }
                }

                string videoLength = "";

                string lateralId = "FL-" + lateralIdIncrement;

                FullLengthLiningLateralDetails model = new FullLengthLiningLateralDetails(fullLengthLiningTDS);
                model.Insert(videoDistance, clockPosition, distanceToCentre, "", reverseSetup, null, comments, lateralId, "", "", false, companyId, true, state, "", "", "", "", null, false, null, false, false, false, "", false, false, null);

                model.Save(workId, projectId, section_assetId, countryId, provinceId, countyId, cityId, videoLength, companyId, false, false, null);
            }
        }