protected void cvLateralsMaxNumber_ServerValidate(object source, ServerValidateEventArgs args)
        {
            // Get Measured From Mh value
            int assetId = Int32.Parse(hdfAssetId.Value);
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int workId = Int32.Parse(hdfWorkId.Value);
            int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.ToString());

            string measuredFromMh = "";

            FullLengthLiningLateralDetails flLateralDetails = new FullLengthLiningLateralDetails();
            flLateralDetails.LoadForEdit(workId, assetId, companyId, currentProjectId);

            if (flLateralDetails.Table.Rows.Count > 0)
            {
                measuredFromMh = "USMH";
            }
            else
            {
                measuredFromMh = ddlM1DataMeasuredFromMh.SelectedValue;
            }

            // Generate increment
            FullLengthLiningLateralDetails fullLengthLiningLateraldetails = new FullLengthLiningLateralDetails(fullLengthLiningTDS);

            if (measuredFromMh == "USMH" || measuredFromMh == "")
            {
                if (fullLengthLiningLateraldetails.GetMaxLateralId2() == "A[") args.IsValid = false; else args.IsValid = true;

            }
            else
            {
                if (measuredFromMh == "DSMH")
                {
                    if (fullLengthLiningLateraldetails.GetMinLateralId2() == "@") args.IsValid = false; else args.IsValid = true;
                }
            }
        }
        private string GetLateralIdIncrement()
        {
            // Get Measured From Mh value
            int assetId = Int32.Parse(hdfAssetId.Value);
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int workId = Int32.Parse(hdfWorkId.Value);
            int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.ToString());

            string measuredFromMh = "";

            FullLengthLiningLateralDetails flLateralDetails = new FullLengthLiningLateralDetails();
            flLateralDetails.LoadForEdit(workId, assetId, companyId, currentProjectId);

            if (flLateralDetails.Table.Rows.Count > 0)
            {
                measuredFromMh = "USMH";
            }
            else
            {
                measuredFromMh = ddlM1DataMeasuredFromMh.SelectedValue;
            }

            // Generate increment
            string lateralIdIncrement = "";
            FullLengthLiningLateralDetails fullLengthLiningLateraldetails = new FullLengthLiningLateralDetails(fullLengthLiningTDS);

            if (measuredFromMh == "USMH" || measuredFromMh == "")
            {
                lateralIdIncrement = fullLengthLiningLateraldetails.GetMaxLateralId2();

            }
            else
            {
                if (measuredFromMh == "DSMH")
                {
                    lateralIdIncrement = fullLengthLiningLateraldetails.GetMinLateralId2();
                }
            }

            return "FL-"+lateralIdIncrement;
        }
        /// <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);
            }
        }