年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

106 lines
3.4 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Maps;
using Kingo.PluginServiceInterface;
namespace Kingo.Plugin.EngineEditor.helper
{
public class FeatureBSMHelper
{
public static string GetNewBSM(List<IFeatureClass> fcList, string cdm = "")
{
string result = string.Empty;
try
{
if (string.IsNullOrWhiteSpace(cdm))
cdm = "1240";
int xh = 0;
string leftStr = string.Empty;
foreach (var item in fcList)
{
string MaxBSM = GetMaxBSM(item);
if (MaxBSM.Length != 18)
continue;
int xh2 = Convert.ToInt32(MaxBSM.Substring(10));
leftStr = MaxBSM.Substring(0, 10);
if (xh < xh2)
xh = xh2;
}
xh++;
if (string.IsNullOrWhiteSpace(leftStr))
leftStr = ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) as ProjectInfo).CODE + cdm;
result = leftStr + xh.ToString().PadLeft(8, '0');
return result;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return result;
}
}
private static string GetMaxBSM(IFeatureClass fc)
{
System.Windows.Forms.Application.DoEvents();
string BSM = string.Empty;
try
{
int BSMIndex = fc.FindField("BSM");
if (BSMIndex == -1) return BSM;
ITable table = (ITable)fc;
// 创建一个ITableSort接口对象
ITableSort tableSort = new TableSortClass();
tableSort.Table = table;
tableSort.Fields = "BSM";
tableSort.set_Ascending("BSM", false);
tableSort.Sort(null);
ICursor cursor = tableSort.Rows;
IRow row = cursor.NextRow();
if (row != null)
{
int maxBSM = 0;
int currBSM = 0;
string BSMStr = row.Value[BSMIndex].ToString();
if (BSMStr.Length != 18) return BSM;
string subBSMStr = BSMStr.Substring(9);
try
{
currBSM = Convert.ToInt32(subBSMStr);
}
catch (Exception)
{
return BSM;
}
if (currBSM > maxBSM) maxBSM = currBSM;
if (BSMStr.Length != 18) return BSM;
string maxStr = maxBSM.ToString();
int zeroNum = 9 - maxStr.Length;
for (int i = 0; i < zeroNum; i++)
{
maxStr = 0 + maxStr;
}
BSM = BSMStr.Substring(0, 9) + maxStr;
}
return BSM;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return BSM;
}
}
}
}