年度变更建库软件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.

1180 lines
60 KiB

6 months ago
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using KUI.Windows;
using KGIS.Framework.Platform;
using KGIS.Framework.Maps;
using Kingo.PluginServiceInterface;
using System.IO;
using KGIS.Framework.DBOperator;
using Aspose.Cells;
using System.Data;
using KGIS.Framework.Utils.ExtensionMethod;
using Kingo.Plugin.BGResultManager.Model;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Carto;
using System.Runtime.InteropServices;
using KGIS.Framework.AE.GPHelper;
using KGIS.Framework.AE.ExtensionMethod;
using KGIS.Framework.AE;
using Path = System.IO.Path;
using KGIS.Framework.AE.Enum;
using KGIS.Framework.OpenData.Control;
using KGIS.Framework.OpenData.InterFace;
using KGIS.Framework.OpenData.Filter;
using Kingo.OpenData.Filter;
using IRDBHelper = KGIS.Framework.DBOperator.IRDBHelper;
namespace Kingo.Plugin.BGResultManager.View
{
/// <summary>
/// 年初末库报表汇总 的交互逻辑
/// </summary>
public partial class FrmNCMKHZExport : BaseWindow
{
private ProjectInfo projectInfo = null;
/// <summary>
/// 地类图斑年末库
/// </summary>
private IFeatureLayer m_DLTBLayer = null;
/// <summary>
/// 城镇村年末库
/// </summary>
private IFeatureLayer m_CZCDYDLayer = null;
private string ImportDataType = string.Empty;
private string s_SelPath = string.Empty;
private IWorkspaceAPI s_WsAPI = null;
public FrmNCMKHZExport()
{
InitializeComponent();
InitViewDisPaly();
}
public void InitViewDisPaly()
{
if (rbNOWNMK.IsChecked == true)
{
SelNMKPath.IsEnabled = false;
}
else
{
SelNMKPath.IsEnabled = true;
}
}
/// <summary>
/// 报表导出执行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnTBTQ_Click(object sender, RoutedEventArgs e)
{
double LDKZMJ = 0;
double HDKZMJ = 0;
projectInfo = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo);
if (projectInfo != null && projectInfo.CODE == null)
{
MessageHelper.ShowTips("工程信息中区划代码未配置,无法输出报表!");
return;
}
if (rbECTNMK.IsChecked == true)
{ //其他年末库报表
if (string.IsNullOrWhiteSpace(s_SelPath)) return;
if (ImportDataType == "MDB")
{
s_WsAPI = new WorkspaceAPI(s_SelPath, WorkspaceTypeEnum.MDBFile);
}
else
{
s_WsAPI = new WorkspaceAPI(s_SelPath, WorkspaceTypeEnum.GDBFile);
}
//源数据获取图层
if (s_WsAPI == null) return;//源数据不能为空
if (s_WsAPI.ExistFeatureClass("DLTB"))
{
m_DLTBLayer = new FeatureLayer { FeatureClass = s_WsAPI.OpenFeatureClass("DLTB").FeatureClass };
}
if (s_WsAPI.ExistFeatureClass("CZCDYD"))
{
m_CZCDYDLayer = new FeatureLayer { FeatureClass = s_WsAPI.OpenFeatureClass("CZCDYD").FeatureClass };
}
}
else
{ //当前年初库报表
m_DLTBLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑");
m_CZCDYDLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("CZCDYD");
//LDKZMJ = projectInfo.DCMJ2; //HDKZMJ = projectInfo.DCMJHD2;
}
try
{
if (m_DLTBLayer == null || m_CZCDYDLayer == null)
{
MessageHelper.ShowTips("获取年末库基础数据失败!");
return;
}
LDKZMJ = double.TryParse(LDMJTex.Text.ToTrim(), out double resultMJ) ? resultMJ : 0;
HDKZMJ = double.TryParse(HDMJTex.Text.ToTrim(), out resultMJ) ? resultMJ : 0;
if (LDKZMJ == 0 && HDKZMJ == 0)
{
if (MessageHelper.ShowYesNoAndTips("控制面积存在都为0的情况,是否继续执行?") != System.Windows.Forms.DialogResult.Yes)
return;
}
string OutPath = string.Empty;
System.Windows.Forms.SaveFileDialog dialog = new System.Windows.Forms.SaveFileDialog();
//dialog.Filter = "Excel文件|*.xlsx";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
OutPath = dialog.FileName;
}
if (!Directory.Exists(OutPath))
{
if (string.IsNullOrWhiteSpace(OutPath)) return;
Directory.CreateDirectory(OutPath);
}
PluginServiceInterface.CommonHelper.DelectDir(OutPath);//能删除就删除 删除报错不处理
this.ShowLoading("进行年末报表数据导出……", 0, 0);
JCTJB(LDKZMJ, HDKZMJ);
//视图报表导出
string dbPath = Directory.GetCurrentDirectory() + "\\Temp\\NMKMJHZDataSetOut\\NMKMJHZDB.sqlite";
IRDBHelper dbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
List<DataDicTionary> dicList = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM);//权属代码字典
foreach (Enum.ViewEntityEnum ViewTableitem in System.Enum.GetValues(typeof(Enum.ViewEntityEnum)))
{
string ExcelNameTemp = GetExcelName(ViewTableitem);
var sourcesfile = SysAppPath.GetCurrentAppPath() + string.Format(@"TempalateReports\视图报表模板\{0}", ExcelNameTemp);
Workbook workbook = new Workbook(sourcesfile);
workbook.CalculateFormula(true);
Worksheet sheet = workbook.Worksheets[0];
DataTable ViewTableTemp = dbHelper.ExecuteDatatable(ViewTableitem.ToString(), string.Format("select * from {0}", ViewTableitem.ToString()), true);
string TempPath = string.Format(@"{0}\{1}", OutPath, ExcelNameTemp);
if (ViewTableTemp != null && ViewTableTemp.Rows.Count > 0)
{
WriteExcel(sheet, ViewTableTemp, dicList);
workbook.Save(TempPath);
}
else//若是没有数据复制文件即可
{
WriteExcel(sheet, ViewTableTemp, dicList);
workbook.Save(TempPath);
}
}
this.CloseLoading();
MessageHelper.ShowTips("报表导出成功!");
}
catch (Exception ex)
{
this.CloseLoading();
MessageHelper.ShowError("报表输出错误!");
LogAPI.Debug("报表输出错误:" + ex);
}
}
private void BtnCanel_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void btnSelectedBaseData_Click(object sender, RoutedEventArgs e)
{
try
{
OpenDataDialog pDialog = new OpenDataDialog();
ISpatialDataObjectFilter pOFilter = new FilterGeoDatabasePersonal();
pDialog.AddFilter(pOFilter, true);
pOFilter = new FilterGeoDatabaseFile();
pDialog.AddFilter(pOFilter, true);
pDialog.AllowMultiSelect = false;
pDialog.Title = "选择基础数据";
pDialog.RestoreLocation = true;
pDialog.StartLocation = pDialog.FinalLocation;
System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog();
if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0)
{
ImportDataType = Path.GetExtension(pDialog.FinalLocation).ToUpper().Replace('.', ' ').TrimStart();
if (string.IsNullOrWhiteSpace(ImportDataType) || (ImportDataType != "GDB" && ImportDataType != "MDB"))
{
MessageHelper.Show("选择的数据路径有误,请根据过滤条件,重新选择数据库!!");
return;
}
s_SelPath = pDialog.FinalLocation;
string fileName = string.Empty;
if (ImportDataType == "MDB" && !File.Exists(s_SelPath))
{
if (!Path.GetFileName(s_SelPath).Equals(".mdb"))
{
MessageHelper.ShowTips("请确保文件存在,并且为mdb文件!");
return;
}
}
else if (ImportDataType == "GDB" && !Directory.Exists(s_SelPath))
{
MessageHelper.ShowTips("请确保GDB文件夹存在!");
return;
}
if (!string.IsNullOrWhiteSpace(s_SelPath))
PathNCM.Text = s_SelPath;
}
}
catch (Exception ex)
{
LogAPI.Debug("选择基础数据库失败:" + ex);
MessageHelper.Show("选择基础数据库失败:" + ex);
}
finally
{
if (s_WsAPI != null)
s_WsAPI.CloseWorkspace();
}
}
/// <summary>
/// 表格内容填充
/// </summary>
/// <param name="sheet">表格模板对象</param>
/// <param name="ViewTableTemp">要填充数据</param>
/// <param name="dicList">权属字典</param>
private void WriteExcel(Worksheet sheet, DataTable ViewTableTemp, List<DataDicTionary> dicList)
{
if (ViewTableTemp == null || ViewTableTemp.Rows.Count == 0 || dicList == null)
return;
DataColumnCollection fields = ViewTableTemp.Columns;
for (int i = 0; i < ViewTableTemp.Rows.Count; i++)
{
for (int j = 0; j < fields.Count; j++)
{
Cell cell = sheet.Cells[i + 6, j + 1];
if (j == 0 && fields[0].ColumnName == "XZQMC")
{
string TempCode = ViewTableTemp.Rows[i][fields[j + 1]].ToString();
DataDicTionary dataDicTionary = dicList.FirstOrDefault(x => x.CODE == (TempCode.Length == 12 ? TempCode.PadRight(19, '0') : TempCode));
if (dataDicTionary != null)
cell.PutValue(dataDicTionary.NAME);
}
else
{
cell.PutValue(ViewTableTemp.Rows[i][fields[j]]);
}
}
}
}
private void JCTJB(double xjldmjkzs, double xjhdmjkzs)
{
IFeatureLayer CZC20X_Layer = null;
try
{
IFeatureClass _CZCFc = m_CZCDYDLayer.FeatureClass;//PrjDB.gdb基础库
CZC20X_Layer = GeoDBAPI.CreateFeatureLayerInmemeory("DLTBGX201", "地类图斑更新201数据", (_CZCFc as IGeoDataset).SpatialReference, _CZCFc.ShapeType, _CZCFc.Fields);
IQueryFilter filter = new QueryFilterClass() { WhereClause = "CZCLX='203' or CZCLX='203A'" };
IFeatureClassAPI fcAPI = new FeatureClassAPI(_CZCFc);
fcAPI.FcToFc(CZC20X_Layer.FeatureClass, null, false);
string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\NMKMJHZDataSetOut";//年末库面积汇总数据准备
if (!Directory.Exists(gdbFolder))
{
Directory.CreateDirectory(gdbFolder);
}
PluginServiceInterface.CommonHelper.DelectDir(gdbFolder);//能删除就删除 删除报错不处理
string gdbFileName = Guid.NewGuid().ToString() + ".gdb";
IWorkspaceFactory pFtWsFct = null;
IWorkspaceName workspaceName = null;
Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
object obj = System.Activator.CreateInstance(t);
pFtWsFct = obj as IWorkspaceFactory;
workspaceName = pFtWsFct.Create(gdbFolder, gdbFileName, null, 0);
string path = Path.Combine(gdbFolder, gdbFileName);
GPParamClass gPParamClass = new GPParamClass();
gPParamClass.Tolerance = "0.0001";
this.UpdateMsg("正在进行基础图层数据处理1........");
IFeatureLayer CK_DLTBBGLayer = null;
gPParamClass.FirstFeatureLayer = m_DLTBLayer;
gPParamClass.SecondFeatureLayer = CZC20X_Layer;
gPParamClass.OutFeatureClassPath = path + "\\" + "DLTB2";
gPParamClass.IsGetOutPutFeature = true;
GeoprocessorHelper.UnionAnalysis(gPParamClass, ref CK_DLTBBGLayer);
gPParamClass.FirstFeatureLayer = CK_DLTBBGLayer;
gPParamClass.OutFeatureClassPath = path + "\\" + "DLTB";
gPParamClass.IsGetOutPutFeature = true;
GeoprocessorHelper.MultipartToSinglePath(gPParamClass, ref CK_DLTBBGLayer);
IFeatureCursor cursor = CK_DLTBBGLayer.FeatureClass.Update(null, true);
IFeature f = null;
int idxCZCSXM = CK_DLTBBGLayer.FeatureClass.FindField("CZCSXM");
int idxDLBM = CK_DLTBBGLayer.FeatureClass.FindField("DLBM");
int idxCZCLX = CK_DLTBBGLayer.FeatureClass.FindField("CZCLX");
int idxDLTBOID = CK_DLTBBGLayer.FeatureClass.FindField("FID_DLTB");
int idxTBMJ = CK_DLTBBGLayer.FeatureClass.FindField("TBMJ");
Dictionary<int, Dictionary<int, double>> group = new Dictionary<int, Dictionary<int, double>>();
Dictionary<int, double> dicKZMJ = new Dictionary<int, double>();
this.UpdateMsg("正在进行基础图层数据处理2........");
//建设用地(再包含09)
string F_20DL = "05H1,0508,0601,0602,0603,0701,0702,08H1,08H2,0809,0810,1001,1002,1003,1004,1005,1007,1008,1009,1109,1201";
while ((f = cursor.NextFeature()) != null)
{
int dltbOID = f.Value[idxDLTBOID].ToInt();
double tbmj = f.Value[idxTBMJ].ToDouble(2);
if (!dicKZMJ.ContainsKey(dltbOID))
dicKZMJ.Add(dltbOID, tbmj);//被切割的控制总面积
double area = f.ShapeCopy.GetEllipseArea();
if (group.ContainsKey(dltbOID))
{
group[dltbOID].Add(f.OID, area);//被切割面积
}
else
{
group.Add(dltbOID, new Dictionary<int, double>());
group[dltbOID].Add(f.OID, area);
}
f.Value[idxCZCSXM] = f.Value[idxCZCLX];
string dlbmjctb = f.Value[idxDLBM].ToTrim();
if (!((!string.IsNullOrWhiteSpace(dlbmjctb) && dlbmjctb.Length == 4 && F_20DL.Contains(dlbmjctb)) || dlbmjctb == "09") && !string.IsNullOrWhiteSpace(f.Value[idxCZCLX].ToTrim()) && "204,205".Contains(f.Value[idxCZCLX].ToTrim()))
f.Value[idxCZCSXM] = DBNull.Value;
cursor.UpdateFeature(f);
}
cursor.Flush();
Dictionary<int, double> mjDic = new Dictionary<int, double>();
this.UpdateMsg("正在进行基础图层数据处理3........");
int TBMJIndex = m_DLTBLayer.FeatureClass.FindField("TBMJ");
foreach (var key in group.Keys)
{
if (key == -1) continue;
if (group[key].Count == 1) continue;
Dictionary<int, double> tempDic = group[key].OrderByDescending(o => o.Value).ToDictionary(k => k.Key, v => v.Value);
IFeature dltbF = m_DLTBLayer.FeatureClass.GetFeature(key);
double kzmj = dltbF.ShapeCopy.GetEllipseArea();
foreach (var subKey in tempDic.Keys)
{
//group[key][subKey] = group[key][subKey] / kzmj * dicKZMJ[key];
mjDic.Add(subKey, Math.Round(group[key][subKey] / kzmj * dicKZMJ[key], 2));
}
double cz = dicKZMJ[key] - group[key].Sum(s => s.Value);
cz = Math.Round(cz, 2);
if (cz != 0)
{
foreach (var subKey in tempDic.Keys)
{
mjDic[subKey] = Math.Round(group[key][subKey] + cz, 2);
break;
}
}
Marshal.ReleaseComObject(dltbF);
}
cursor = CK_DLTBBGLayer.FeatureClass.Update(null, true);
while ((f = cursor.NextFeature()) != null)
{
if (!mjDic.ContainsKey(f.OID)) continue;
f.Value[idxTBMJ] = mjDic[f.OID];
cursor.UpdateFeature(f);
}
cursor.Flush();
Marshal.ReleaseComObject(cursor);
this.UpdateMsg("正在进行报表数据处理........");
string dbPath = gdbFolder + "\\NMKMJHZDB.sqlite";
if (!File.Exists(dbPath))//复制新工程模板作为副本,辅助报表导出
File.Copy(SysAppPath.GetCurrentAppPath() + "工作空间\\模板\\新建变更工程\\BGTJ.sqlite", dbPath);
IRDBHelper dbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
Type ts = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
object obj2 = System.Activator.CreateInstance(ts);//解决强制类型转换
IWorkspaceFactory factoryGdb = obj2 as IWorkspaceFactory;
IWorkspace worckspace = factoryGdb.OpenFromFile(path, 0);
IFeatureWorkspace inWs = worckspace as IFeatureWorkspace;
dbHelper.ExecuteSQL(" drop table DLTB ");
IWorkspaceFactory pOutWorkFactory = new SqlWorkspaceFactoryClass();
IWorkspace pOutWork = pOutWorkFactory.OpenFromFile(dbPath, 0);
TableToTable(inWs, pOutWork, "DLTB");
dbHelper.ExecuteSQL("update dltb set kcxs=0 where kcxs is null");
dbHelper.ExecuteSQL("update dltb set kcmj=round(tbmj*kcxs,2)");
dbHelper.ExecuteSQL("update dltb set tbdlmj=round(tbmj-kcmj,2)");
//第一步:清空当前表数据
string deletesql = " delete from MJHZJCTJB";
dbHelper.ExecuteNonQueryWithException(deletesql, CommandType.Text);
deletesql = " delete from MJHZTJB2";
dbHelper.ExecuteNonQueryWithException(deletesql, CommandType.Text);
DropTable(dbHelper, "MJHZTJB3");
DropTable(dbHelper, "MJHZTJB4");
DropTable(dbHelper, "MJHZJCTJBPCQ");
string[] grouparry = new string[] { "QSXZ", "GDLX", "GDPDJB", "CZCSXM", "TBXHDM", "ZZSXDM", "FRDBS" };
foreach (var item in grouparry)
{
dbHelper.ExecuteNonQueryWithException(string.Format("update dltb set {0}=null where {0}=''", item), CommandType.Text);
}
//处理耕地种植属性为耕种的图斑可不标注问题
SetGDZZSXDMIsGZ(dbHelper);
//第二步:按照座落、权属代码、权属性质、耕地类型、耕地坡度级别、城镇村属性码、图斑细化代码、耕地种植属性、描述说明、飞入地标识、地类编码分类汇总图斑地类面积到基础表2
string mjhztj2 = "insert into MJHZTJB2(ZLDWMC,ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,DLBM,TBDLMJ) SELECT ZLDWMC, substr(ZLDWDM,1,12) AS ZLDWDM,substr(QSDWDM,1,12) AS QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,DLBM, Sum(TBDLMJ) FROM MJHZTJB3 GROUP BY ZLDWMC,substr(ZLDWDM,1,12),substr(QSDWDM,1,12),QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,DLBM";
dbHelper.ExecuteNonQueryWithException(mjhztj2, CommandType.Text);
DataTable mjhzdt = dbHelper.ExecuteDatatable("hztjb", "select * from MJHZJCTJB where 1=2", true);
this.UpdateMsg("正在进行增加平方米汇总统计基础表........");
//增加平方米汇总统计基础表
AddMeterMJPC(dbHelper, false);
List<DLBMTJEntity> dlbmlist;
List<string> ejdllist;
GetDLBMListByDT(mjhzdt, out dlbmlist, out ejdllist, false);
string insertc = GetInsertC1(ejdllist);
//insertc += "D201,D202,D203,D204,D205";
string sumc = Getsumc(ejdllist);
//第二步:按照座落、权属代码、权属性质、耕地类型、耕地坡度级别、城镇村属性码、图斑细化代码、耕地种植属性、描述说明、飞入地标识分类汇总面积到基础表,且面积换算为公顷单位,保留两位小数
string cjmjhzdtsql = "insert into MJHZJCTJB(ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,TBZMJ " + insertc + ") SELECT ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM, round(sum(ifnull((TBDLMJ+0.0)/10000 + 0.0000001,0)),2) AS TBZMJ " + sumc + " FROM MJHZTJB2 GROUP BY ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM";
//当前不进行平方米转公顷
//string cjmjhzdtsql = "insert into MJHZJCTJB(ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,TBZMJ " + insertc + ") SELECT ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM, round(sum(ifnull(TBDLMJ,0)),2) AS TBZMJ " + sumc + " FROM MJHZTJB2 GROUP BY ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM";
dbHelper.ExecuteNonQueryWithException(cjmjhzdtsql, CommandType.Text);
dbHelper.ExecuteNonQueryWithException("CREATE TABLE MJHZJCTJBPCQ as SELECT * FROM MJHZJCTJB", CommandType.Text);
#region 年末面积平差
//第四步:图斑总面积平差运算
if (xjldmjkzs > 0)//陆地面积平差
{
this.UpdateMsg("正在进行陆地面积平差........");
MJPC(xjldmjkzs, dbHelper, "00");
}
if (xjhdmjkzs > 0)//海岛面积平差
{
this.UpdateMsg("正在进行海岛面积平差........");
MJPC(xjhdmjkzs, dbHelper, "01");
}
this.UpdateMsg("正在进行内部地类平差........");
//第五步:内部地类平差
EJDLPCData(dbHelper);
#endregion
dbHelper.DisConnect();
}
catch (Exception ex)
{
LogAPI.Debug("报表数据输出失败:" + ex.Message);
LogAPI.Debug(ex);
throw;
}
}
public bool TableToTable(IFeatureWorkspace pInWork, IWorkspace pOutWork, string tableName, IQueryFilter queryFilter = null)
{
try
{
if (pInWork == null || pOutWork == null || string.IsNullOrEmpty(tableName)) return false;
if (pInWork is IWorkspace2 workspace2)
{
if (!workspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, tableName))
{
return false;
}
}
ITable pInTable = pInWork.OpenTable(tableName);
if (pInTable == null) return false;
IDataset pIndataset = (IDataset)pInTable;
IDatasetName pInDatasetName = (IDatasetName)pIndataset.FullName;
IEnumDataset enumDataset = pOutWork.get_Datasets(esriDatasetType.esriDTTable);
IDataset dataset;
enumDataset.Reset();
while ((dataset = enumDataset.Next()) != null)
{
string[] names = dataset.Name.Split('.');
if (string.Equals(names[names.Length - 1], tableName, StringComparison.CurrentCultureIgnoreCase))
{
dataset.Delete();
break;
}
}
IDataset pOutDataset = (IDataset)pOutWork;
IDatasetName pOutDatasetName = new TableNameClass();
pOutDatasetName.WorkspaceName = (IWorkspaceName)pOutDataset.FullName;
pOutDatasetName.Name = tableName;
IFieldChecker fieldChecker = new FieldCheckerClass();
IFields targetFeatureClassFields = pInTable.Fields;
IFields sourceFeatureClassFields = pInTable.Fields;
fieldChecker.InputWorkspace = pInWork as IWorkspace;
fieldChecker.ValidateWorkspace = pOutWork;
fieldChecker.Validate(sourceFeatureClassFields, out IEnumFieldError enumFieldError, out targetFeatureClassFields);
IFeatureDataConverter one2another = new FeatureDataConverterClass();
try
{
one2another.ConvertTable(pInDatasetName, queryFilter, pOutDatasetName, targetFeatureClassFields, "", 1000, 0);
}
finally
{
Marshal.ReleaseComObject(one2another);
}
return true;
}
catch (Exception ex)
{
LogAPI.Debug("执行 TableToTable 函数时失败,异常原因: " + ex + " ; ");
throw ex;
}
}
/// <summary>
/// 末级地类平差
/// </summary>
/// <param name="dbHelper"></param>
private void EJDLPCData(IRDBHelper dbHelper, string tableName = "MJHZJCTJB")
{
DataTable updatedt = dbHelper.ExecuteDatatable(tableName, ("select * from " + tableName), true);
if (updatedt == null || updatedt.Rows.Count == 0)
{
return;
throw new Exception("初始基础统计表错误!");
}
List<DLBMTJEntity> dlbmlist;
List<string> ejdllist;
GetDLBMListByDT(updatedt, out dlbmlist, out ejdllist);
ejdllist.Reverse();
updatedt.PrimaryKey = new DataColumn[] { updatedt.Columns["BSM"] };
for (int i = 0; i < updatedt.Rows.Count; i++)
{
if (i % 100 == 0 || i == updatedt.Rows.Count)
this.UpdateMsg(string.Format("正在进行内部地类平差:({0}/{1})", i, updatedt.Rows.Count));
//updatedt.Rows[i].BeginEdit();
//string strZLDWDM = updatedt.Rows[i]["ZLDWDM"].ToString();
//string strZLDWMC = updatedt.Rows[i]["ZLDWMC"].ToString();
//获取每个小类的集合(平方米)
List<EJDLEntityClass> ejdllist1 = new List<EJDLEntityClass>();
int xh = ejdllist.Count;
foreach (var item in ejdllist)
{
string strPZYT = item;
double dbl = updatedt.Rows[i]["D" + item].ToDouble();
xh--;
EJDLEntityClass ejdlitem = new EJDLEntityClass();
ejdlitem.XH = xh;
ejdlitem.EJDLName = item;
ejdlitem.MetersValue = updatedt.Rows[i]["D" + item].ToDecimal(2);
if (ejdlitem.MetersValue <= 0)
{
ejdlitem.MetersValue = 0;
}
ejdlitem.HectareValue = (ejdlitem.MetersValue * 0.0001m).ToDecimal(2);
updatedt.Rows[i]["D" + item] = ejdlitem.HectareValue;
//dbHelper.ExecuteSQL(string.Format("update {0} set D{1}={2} where BSM={3}", tableName, item, ejdlitem.HectareValue, updatedt.Rows[i]["BSM"]));
if (ejdlitem.MetersValue > 0)
{
ejdllist1.Add(ejdlitem);
}
}
//如果存在大于等于10000平方米的,则小于10000平方米的排除
if (ejdllist1.Count(x => x.MetersValue >= 10000) > 0)
{
while (ejdllist1.Count(x => x.MetersValue < 10000) > 0)
{
ejdllist1.Remove(ejdllist1.FirstOrDefault(x => x.MetersValue < 10000));
}
}
else
{
//去除平方米面积为0的
while (ejdllist1.Count(x => x.MetersValue <= 0) > 0)
{
ejdllist1.Remove(ejdllist1.FirstOrDefault(x => x.MetersValue <= 0));
}
}
bool pc = true;
while (pc)
{
pc = false;
decimal h = 0;
Dictionary<string, decimal> tempupdateejdldic = new Dictionary<string, decimal>();
Dictionary<string, decimal> updateejdldic = new Dictionary<string, decimal>();
foreach (var item in ejdllist)
{
decimal tempv = updatedt.Rows[i]["D" + item].ToDecimal(2);
if (tempv < 0)
{
tempv = 0;
updatedt.Rows[i]["D" + item] = tempv;
//dbHelper.ExecuteSQL(string.Format("update {0} set D{1}={2} where BSM={3}", tableName, item, tempv, updatedt.Rows[i]["BSM"]));
}
h = h + tempv;
//如果平方米当中存在,则添加
if (ejdllist1.Count(x => x.EJDLName == item) > 0)
{
tempupdateejdldic.Add(item, tempv);
}
}
var ejdlquery = from t in ejdllist1 orderby t.MetersValue descending, t.XH descending select t;
foreach (var item in ejdlquery)
{
updateejdldic.Add(item.EJDLName, tempupdateejdldic[item.EJDLName]);
}
decimal g = updatedt.Rows[i]["TBZMJ"].ToDecimal(2);
if (updateejdldic.Count == 0)
{
if (g > 0)
{
updatedt.Rows[i]["D" + ejdllist[0]] = g;
if (ejdllist1.Count == 0)
{
break;
}
pc = true;
continue;
}
}
decimal zfvalue = 1;
decimal mjc = 0;
decimal js = (decimal)0.01;//调平基数0.01
if (h > g)
{
zfvalue = -1;
mjc = h - g;
//为了避免负数,则把0的排除
while (updateejdldic.Count(x => x.Value <= 0) > 0)
{
updateejdldic.Remove(updateejdldic.FirstOrDefault(x => x.Value <= 0).Key);
}
if (updateejdldic.Count == 0)
{
if (mjc > 0)
{
updatedt.Rows[i]["D" + ejdllist[0]] = updatedt.Rows[i]["D" + ejdllist[0]].ToDecimal(2) - mjc;
pc = true;
continue;
}
}
}
else
{
mjc = g - h;
}
//如果面积差值大于0,进行平差
if (mjc > 0)
{
int tpsm = (int)(mjc / js);
int cjzsm = updateejdldic.Count;
if (cjzsm == 0)
continue;
int e = tpsm / cjzsm;
int f = tpsm % cjzsm;
if (f > 0)
{
//余数调平面积值
decimal ftpzmj = (e + 1) * js;
for (int x = 0; x < f; x++)
{
updatedt.Rows[i]["D" + updateejdldic.ElementAt(x).Key] = updateejdldic.ElementAt(x).Value + ftpzmj * zfvalue;
}
}
if (e > 0)
{
//商数调平面积值
decimal ftpzmj = e * js;
for (int x = f; x < cjzsm; x++)
{
updatedt.Rows[i]["D" + updateejdldic.ElementAt(x).Key] = updateejdldic.ElementAt(x).Value + ftpzmj * zfvalue;
}
}
pc = true;
continue;
}
}
//填充一级类汇总面积
foreach (var item in dlbmlist)
{
decimal yjdlmj = 0;
if (item.EJDLList != null && item.EJDLList.Count > 0)
{
foreach (var item2 in item.EJDLList)
{
yjdlmj = yjdlmj + updatedt.Rows[i]["D" + item2].ToDecimal(2);
}
updatedt.Rows[i]["D" + item.YJDL] = yjdlmj;
}
}
string strUpSql = string.Format("update {0} set ", tableName);
foreach (var item in dlbmlist)
{
strUpSql += "D" + item.YJDL + "=" + updatedt.Rows[i]["D" + item.YJDL].ToDecimal(2) + ",";
//decimal yjdlmj = 0;
if (item.EJDLList != null && item.EJDLList.Count > 0)
{
foreach (var item2 in item.EJDLList)
{
strUpSql += "D" + item2 + "=" + updatedt.Rows[i]["D" + item2].ToDecimal(2) + ",";
}
}
}
strUpSql = strUpSql.TrimEnd(',');
strUpSql += string.Format(" where bsm={0}", updatedt.Rows[i]["BSM"]);
dbHelper.ExecuteSQL(strUpSql);
}
}
private List<string> dlbm00List = new List<string>() { "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
/// <summary>
/// 根据统计表列,获取地类编码一级类和二级类集合
/// </summary>
/// <param name="updatedt"></param>
/// <param name="dlbmlist"></param>
/// <param name="ejdllist"></param>
public void GetDLBMListByDT(DataTable updatedt, out List<DLBMTJEntity> dlbmlist, out List<string> ejdllist, bool Is20 = false)
{
dlbmlist = new List<DLBMTJEntity>();
ejdllist = new List<string>();
#region 计算地类编码集合
foreach (DataColumn item in updatedt.Columns)
{
if (item.ColumnName.StartsWith("D20") && Is20) continue;
if (item.ColumnName.IndexOf("D") == 0 && item.ColumnName.Length == 3)
{
DLBMTJEntity dlbmtjitem = new DLBMTJEntity();
dlbmtjitem.YJDL = item.ColumnName.Substring(1);
dlbmtjitem.EJDLList = new List<string>();
foreach (DataColumn item2 in updatedt.Columns)
{
if (dlbmtjitem.YJDL.Equals("00") && dlbm00List.Contains(item2.ColumnName.Substring(1)) && item2.ColumnName.Length > 3)
{
dlbmtjitem.EJDLList.Add(item2.ColumnName.Substring(1));
continue;
}
if (item2.ColumnName.IndexOf(dlbmtjitem.YJDL) == 1 && item2.ColumnName.Length > 3 && !dlbm00List.Contains(item2.ColumnName.Substring(1)))
{
dlbmtjitem.EJDLList.Add(item2.ColumnName.Substring(1));
}
}
dlbmlist.Add(dlbmtjitem);
}
}
foreach (var item in dlbmlist)
{
if (item.EJDLList != null && item.EJDLList.Count > 0)
{
ejdllist.AddRange(item.EJDLList);
}
else
{
ejdllist.Add(item.YJDL);
}
}
#endregion
}
/// <summary>
/// 统计平方米
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="ishz">是否需要自己汇总(任意一个范围的平方米成果数据库,调用此方法就可以出报表)</param>
private void AddMeterMJPC(IRDBHelper dbHelper, bool ishz = true)
{
#region 暂时注释
//if (ishz)
//{
//第一步:清空当前表数据
//string deletesql = " delete from MJHZJCTJB2";
//dbHelper.ExecuteNonQueryWithException(deletesql, CommandType.Text);
//deletesql = " delete from MJHZTJB2";
//dbHelper.ExecuteNonQueryWithException(deletesql, CommandType.Text);
//DropTable(dbHelper, "MJHZTJB3");
//string[] grouparry = new string[] { "QSXZ", "GDLX", "GDPDJB", "CZCSXM", "TBXHDM", "ZZSXDM", "FRDBS" };
//foreach (var item in grouparry)
//{
// dbHelper.ExecuteNonQueryWithException(string.Format("update DLTB set {0}=null where {0}=''", item), CommandType.Text);
//}
////处理耕地种植属性为耕种的图斑可不标注问题
//SetGDZZSXDMIsGZ(dbHelper);
////第二步:按照座落、权属代码、权属性质、耕地类型、耕地坡度级别、城镇村属性码、图斑细化代码、耕地种植属性、描述说明、飞入地标识、地类编码分类汇总图斑地类面积、田坎面积到基础表2
//string mjhztj2 = "insert into MJHZTJB2(ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,DLBM,TBDLMJ,KCMJ) SELECT LEFT(ZLDWDM,12) AS ZLDWDM,LEFT(QSDWDM,12) AS QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,DLBM, Sum(TBDLMJ) ,Sum(KCMJ) FROM MJHZTJB3 GROUP BY LEFT(ZLDWDM,12),LEFT(QSDWDM,12),QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,DLBM";
//dbHelper.ExecuteNonQueryWithException(mjhztj2, CommandType.Text);
//}
#endregion
#region 计算平方米二级类汇总
this.UpdateMsg("正在进行计算平方米二级类汇总........");
DropTable(dbHelper, "MJHZJCTJB2");
DataTable mjhzdt = dbHelper.ExecuteDatatable("hztjb", "select * from MJHZJCTJB where 1=2", true);
GetDLBMListByDT(mjhzdt, out List<DLBMTJEntity> dlbmlist, out List<string> ejdllist);
string insertc = GetInsertC1(ejdllist);
string sumc = Getsumc(ejdllist);
dbHelper.ExecuteNonQueryWithException("CREATE TABLE MJHZJCTJB2 as select * from MJHZJCTJB where 1=2 ", CommandType.Text);
string cjmjhzdtsql2 = "insert into MJHZJCTJB2(ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,TBZMJ " + insertc + ") SELECT ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM, round(Sum(TBDLMJ),2) AS TBZMJ " + sumc + " FROM MJHZTJB2 GROUP BY ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM";
dbHelper.ExecuteNonQueryWithException(cjmjhzdtsql2, CommandType.Text);
//dbHelper.ExecuteNonQueryWithException("UPDATE MJHZJCTJB2 SET D1203=D1203+KCMJ", CommandType.Text);
#endregion
#region 填出二级类到一级类平方米
string updatesetstr = "";
this.UpdateMsg("正在进行填充一级类汇总面积........");
//填充一级类汇总面积
foreach (var item in dlbmlist)
{
if (item.EJDLList != null && item.EJDLList.Count > 0)
{
updatesetstr = updatesetstr + "D" + item.YJDL + "=";
foreach (var item2 in item.EJDLList)
{
updatesetstr = updatesetstr + "D" + item2 + "+";
}
updatesetstr = updatesetstr.TrimEnd('+') + ",";
}
}
dbHelper.ExecuteNonQueryWithException("UPDATE MJHZJCTJB2 SET " + updatesetstr.TrimEnd(','), CommandType.Text);
#endregion
}
/// <summary>
/// 删除表操作
/// </summary>
/// <param name="helper"></param>
/// <param name="tableName"></param>
private void DropTable(IRDBHelper helper, string tableName)
{
try
{
if (helper == null || string.IsNullOrEmpty(tableName))
{
return;
}
string sql = " drop table " + tableName;
int a = helper.ExecuteNonQuery(sql, CommandType.Text);
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
/// <summary>
/// 拼接地类编码SQL语句
/// </summary>
/// <param name="ejdllist"></param>
/// <returns></returns>
private string GetInsertC1(List<string> ejdllist)
{
string resultylstr = string.Empty;
#region 计算地类编码集合
//foreach (var item in ejdllist)
//{
resultylstr = ",D" + string.Join(",D", ejdllist);
//resultylstr = resultylstr + string.Format(" ,D{0} ", item);
//}
#endregion
return resultylstr;
}
/// <summary>
/// 获取所有地类编码
/// </summary>
/// <param name="ejdllist"></param>
/// <returns></returns>
private string Getsumc(List<string> ejdllist, bool IsGQ = false, bool IsPZWJSYT = false)
{
string resultylstr = string.Empty;
if (IsGQ)
{
#region 计算地类编码集合
foreach (var item in ejdllist)
{
if (IsPZWJSYT)
{
resultylstr = resultylstr + string.Format(" ,sum(IIF(PZYT='{0}',DCMJ,0)) as D{0}", item);
}
else
{
if (item.ToUpper().StartsWith("20"))
{
resultylstr = resultylstr + string.Format(" ,sum(case when substr(CZCSXM,1,3)='{0}' then round(sum(ifnull((TBDLMJ+0.0)/10000 + 0.0000001,0)),2) ELSE 0 END) as D{0}", item);
continue;
}
resultylstr = resultylstr + string.Format(" ,sum(case when DLBM='{0}' and CZCSXM is null then round(sum(ifnull((TBDLMJ+0.0)/10000 + 0.0000001,0)),2) ELSE 0 END) as D{0}", item);
}
}
#endregion
}
else
{
#region 计算地类编码集合
foreach (var item in ejdllist)
{
if (IsPZWJSYT)
{
resultylstr = resultylstr + string.Format(" ,sum(IIF(PZYT='{0}',DCMJ,0)) as D{0}", item);
}
else
{
if (item.ToUpper().StartsWith("20"))
{
resultylstr = resultylstr + string.Format(" ,sum(case when substr(CZCSXM,1,3)='{0}' then TBDLMJ ELSE 0 END) as D{0}", item);
continue;
}
resultylstr = resultylstr + string.Format(" ,sum(case when DLBM='{0}' then TBDLMJ ELSE 0 END) as D{0}", item);
}
}
#endregion
}
return resultylstr;
}
/// <summary>
/// 面积平差
/// </summary>
/// <param name="xjmjkzs">县级面积控制数(公顷)</param>
/// <param name="dbHelper"></param>
private void MJPC(double xjmjkzs, IRDBHelper dbHelper, string mssm)
{
bool pc = true;
while (pc)
{
pc = false;
double cjzmj = dbHelper.ExecuteDatatable("cjzmj", "SELECT sum(TBZMJ) FROM MJHZJCTJB where mssm='" + mssm + "' ", true).Rows[0][0].ToDouble(2);
//平差正反值,(后续平差是加,还是减)
double zfvalue = 1;
//面积差值
double mjc = 0;
double js = 0.01;//调平基数0.01
if (cjzmj > xjmjkzs)
{
zfvalue = -1;
mjc = cjzmj - xjmjkzs;
}
else if (cjzmj < xjmjkzs)
{
mjc = xjmjkzs - cjzmj;
}
mjc = mjc.ToDouble(2);
//如果面积差值大于0,进行平差
if (mjc > 0)
{
//调平数目
int tpsm = (int)(mjc / js);
//按照座落代码分组,得到村的个数
//此处sql语句必须要排序,以便最大面积村靠前
DataTable cjzsmdt = dbHelper.ExecuteDatatable("cjzsm", "SELECT ZLDWDM,count(*) as C, sum(TBZMJ) FROM MJHZJCTJB where mssm='" + mssm + "' and TBZMJ>0 group by ZLDWDM order by sum(TBZMJ) desc", true);
//var cjzsmdt2 = dbHelper.ActiveConn.Query("SELECT ZLDWDM,count(*) as C, sum(TBZMJ) AS TBZMJ FROM MJHZJCTJB where mssm='" + mssm + "' and TBZMJ>0 group by ZLDWDM order by sum(TBZMJ) desc").ToList();
int cjzsm = cjzsmdt.Rows.Count;//待调平村级总数目
if (cjzsm == 0) continue;
int e = tpsm / cjzsm;//商数
int f = tpsm % cjzsm;//余数
if (f > 0)
{
//余数村调平面积值
double ftpzmj = (e + 1) * js;
/// <param name="dbHelper"></param>
/// <param name="zfvalue">加减调平数</param>
/// <param name="js">基数(0.01)</param>
/// <param name="cjzsmdt">村级汇总数据表数据</param>
/// <param name="cjzsm">总数量</param>
/// <param name="f">起始值</param>
/// <param name="ftpzmj">调平面积</param>
UpdateTBMJ(dbHelper, zfvalue, js, cjzsmdt, f, 0, ftpzmj, mssm);
}
if (e > 0)
{
//商数村调平面积值
double ftpzmj = e * js;
UpdateTBMJ(dbHelper, zfvalue, js, cjzsmdt, cjzsm, f, ftpzmj, mssm);
}
cjzmj = dbHelper.ExecuteDatatable("cjzmj", "SELECT sum(TBZMJ) FROM MJHZJCTJB where mssm='" + mssm + "'", true).Rows[0][0].ToDouble(2);
//再次确认是否调平?
if (cjzmj != xjmjkzs)
{
pc = true;
continue;
}
}
}
}
/// <summary>
/// 根据视图名称获取Excel表名
/// </summary>
/// <param name="ViewTableitem"></param>
/// <returns></returns>
public string GetExcelName(Enum.ViewEntityEnum ViewTableitem)
{
string ExcelName = string.Empty;
switch (ViewTableitem)
{
case Enum.ViewEntityEnum.V_201NBTDLYXZEJFLMJHZB:
ExcelName = "城市内部土地利用现状表.xlsx";
break;
case Enum.ViewEntityEnum.V_202NBTDLYXZEJFLMJHZB:
ExcelName = "建制镇内部土地利用现状表.xlsx";
break;
case Enum.ViewEntityEnum.V_203NBTDLYXZEJFLMJHZB:
ExcelName = "村庄内部土地利用现状表.xlsx";
break;
case Enum.ViewEntityEnum.V_204NBTDLYXZEJFLMJHZB:
ExcelName = "盐田及工矿用地内部土地利用现状表.xlsx";
break;
case Enum.ViewEntityEnum.V_205NBTDLYXZEJFLMJHZB:
ExcelName = "特殊用地内部土地利用现状表.xlsx";
break;
case Enum.ViewEntityEnum.V_BFXHDLMJHZB:
ExcelName = "部分细化地类面积汇总表.xlsx";
break;
case Enum.ViewEntityEnum.V_CZCJGKYDMJHZB:
ExcelName = "城镇村及工矿用地面积汇总表.xlsx";
break;
case Enum.ViewEntityEnum.V_FQYLJTMXHBZMJHZB:
ExcelName = "废弃与垃圾填埋细化标注汇总统计表.xlsx";
break;
case Enum.ViewEntityEnum.V_GCCDHZB:
ExcelName = "灌丛草地汇总情况统计表.xlsx";
break;
case Enum.ViewEntityEnum.V_GDPDFJMJHZB:
ExcelName = "耕地坡度分级面积汇总表.xlsx";
break;
case Enum.ViewEntityEnum.V_GDZZLXMJHZB:
ExcelName = "耕地种植类型统计表.xlsx";
break;
case Enum.ViewEntityEnum.V_GYYDALXMJHZB:
ExcelName = "工业用地按类型汇总统计表.xlsx";
break;
case Enum.ViewEntityEnum.V_KTZDLMJHZB:
ExcelName = "可调整地类面积汇总表.xlsx";
break;
case Enum.ViewEntityEnum.V_LQZZYYDMJHZB:
ExcelName = "林区范围内园地汇总统计表.xlsx";
break;
case Enum.ViewEntityEnum.V_TDLYXZEJFLMJAQSXZHZB:
ExcelName = "土地利用现状二级分类面积按权属性质汇总表.xlsx";
break;
case Enum.ViewEntityEnum.V_TDLYXZEJFLMJHZB:
ExcelName = "土地利用现状分类面积汇总表.xlsx";
break;
case Enum.ViewEntityEnum.V_TDLYXZYJFLMJAQSXZHZB:
ExcelName = "土地利用现状一级分类面积按权属性质汇总表.xlsx";
break;
default:
ExcelName = string.Empty;
break;
}
return ExcelName;
}
/// <param name="dbHelper"></param>
/// <param name="zfvalue">加减调平数</param>
/// <param name="js">基数(0.01)</param>
/// <param name="cjzsmdt">村级汇总数据表数据</param>
/// <param name="cjzsm">总数量</param>
/// <param name="f">起始值</param>
/// <param name="ftpzmj">村内图标调平总面积</param>
private void UpdateTBMJ(IRDBHelper dbHelper, double zfvalue, double js, DataTable cjzsmdt, int cjzsm, int f, double ftpzmj, string mssm)
{
//已知村的调平面积,调平村内图斑面积
//村内的图斑调平面积=村的调平面积除以调平基数,得到调平数目,用调平数目除以图斑数量,得到商 e2,余数 f2,
string updatedbsql = "update MJHZJCTJB set TBZMJ=TBZMJ{2} where bsm in (select bsm from MJHZJCTJB where ZLDWDM='{0}' and mssm='" + mssm + "' and TBZMJ > 0.01 {3} order by TBZMJ desc,bsm desc limit {1})";//前余数个(f2)图斑的调平sql语句
//string updatedbsql2 = "update MJHZJCTJB set TBZMJ=TBZMJ{2} where bsm in (select top {1} bsm from MJHZJCTJB where ZLDWDM='{0}' and mssm='" + mssm + "' and TBZMJ>0 {3} order by TBZMJ,bsm )";//商数个(f2)图斑的调平sql语句
string updatedbsql2 = "update MJHZJCTJB set TBZMJ=TBZMJ{1} where ZLDWDM='{0}' and mssm='" + mssm + "' and TBZMJ > 0.01 {2} ";//商数个(f2)图斑的调平sql语句
for (int i = f; i < cjzsm; i++)
{
int cjzsm2 = Convert.ToInt32(cjzsmdt.Rows[i]["C"]);//单个村的图斑总数目
int tpsm2 = (int)(ftpzmj / js);//调平数目
if (cjzsm2 == 0)
continue;
int e2 = tpsm2 / cjzsm2;
int f2 = tpsm2 % cjzsm2;//得到调平数e、f
string tbmjwhere = string.Empty;
if (f2 > 0)
{
double ftpzmj2 = (e2 + 1) * js;
//double ftpzmj2 = js;
string tpvalue = string.Empty;
if (zfvalue < 0)
{
tpvalue = "-" + ftpzmj2.ToDecimal(2);
tbmjwhere = " and TBZMJ>=" + ftpzmj2;//为了以防万一出现负数
}
else
{
tpvalue = "+" + ftpzmj2.ToDecimal(2);
}
dbHelper.ExecuteNonQueryWithException(string.Format(updatedbsql, cjzsmdt.Rows[i]["ZLDWDM"], f2, tpvalue, tbmjwhere), CommandType.Text);
}
if (e2 > 0)
{
double ftpzmj2 = e2 * js;
string tpvalue = string.Empty;
if (zfvalue < 0)
{
tpvalue = "-" + ftpzmj2.ToDecimal(2);
tbmjwhere = " and TBZMJ>=" + ftpzmj2;//为了以防万一出现负数
}
else
{
tpvalue = "+" + ftpzmj2.ToDecimal(2);
}
dbHelper.ExecuteNonQueryWithException(string.Format(updatedbsql2, cjzsmdt.Rows[i]["ZLDWDM"], tpvalue, tbmjwhere), CommandType.Text);
}
}
}
private void SetGDZZSXDMIsGZ(IRDBHelper dbHelper)
{
/*
*
* 2018.12.6
*
*/
string mjhztj4 = @"create table MJHZTJB4 as select ZLDWMC,ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM ,DLBM,TBDLMJ from (
SELECT ZLDWMC,substr(ZLDWDM,1,12) AS ZLDWDM,substr(QSDWDM,1,12) AS QSDWDM,QSXZ,'' as GDLX,'' as GDPDJB,CZCSXM,
'' as TBXHDM,'' as ZZSXDM,FRDBS,MSSM,KCDLBM AS DLBM,KCMJ AS TBDLMJ FROM DLTB WHERE KCDLBM IS NOT NULL
AND KCMJ IS NOT NULL AND KCDLBM <> '' AND KCMJ > 0
UNION ALL
SELECT ZLDWMC,substr(ZLDWDM,1,12) AS ZLDWDM,substr(QSDWDM,1,12) AS QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM, DLBM ,TBDLMJ FROM DLTB
)";
dbHelper.ExecuteNonQueryWithException(mjhztj4, CommandType.Text);
mjhztj4 = @"UPDATE MJHZTJB4 set GDLX='' WHERE GDLX IS NULL";
dbHelper.ExecuteNonQueryWithException(mjhztj4, CommandType.Text);
mjhztj4 = @"UPDATE MJHZTJB4 set GDPDJB='' WHERE GDPDJB IS NULL";
dbHelper.ExecuteNonQueryWithException(mjhztj4, CommandType.Text);
mjhztj4 = @"UPDATE MJHZTJB4 set TBXHDM='' WHERE TBXHDM IS NULL";
dbHelper.ExecuteNonQueryWithException(mjhztj4, CommandType.Text);
mjhztj4 = @"UPDATE MJHZTJB4 set ZZSXDM='' WHERE ZZSXDM IS NULL;";
dbHelper.ExecuteNonQueryWithException(mjhztj4, CommandType.Text);
string mjhztj3 = @"create table MJHZTJB3 as select ZLDWMC,ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM ,DLBM,TBDLMJ from (SELECT ZLDWMC,ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,DLBM as DLBM, Sum(TBDLMJ) as TBDLMJ
FROM MJHZTJB4 GROUP BY ZLDWMC,ZLDWDM,QSDWDM,QSXZ,GDLX,GDPDJB,CZCSXM,TBXHDM,ZZSXDM,FRDBS,MSSM,DLBM
)";
dbHelper.ExecuteNonQueryWithException(mjhztj3, CommandType.Text);
DataTable dtmjhztj3 = dbHelper.ExecuteDatatable("dtmjhztj3", " select * from MJHZTJB3 where dlbm like '01%'", true);
if (dtmjhztj3 != null && dtmjhztj3.Rows.Count > 0)
{
for (int i = 0; i < dtmjhztj3.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dtmjhztj3.Rows[i]["ZZSXDM"].ToTrim()))
{
string QSXZ = !string.IsNullOrEmpty(dtmjhztj3.Rows[i]["QSXZ"].ToTrim()) ? " and QSXZ='" + dtmjhztj3.Rows[i]["QSXZ"] + "'" : " and (QSXZ is null or QSXZ='')";
string GDLX = !string.IsNullOrEmpty(dtmjhztj3.Rows[i]["GDLX"].ToTrim()) ? " and GDLX='" + dtmjhztj3.Rows[i]["GDLX"] + "'" : " and (GDLX is null or GDLX='')";
string GDPDJB = !string.IsNullOrEmpty(dtmjhztj3.Rows[i]["GDPDJB"].ToTrim()) ? " and GDPDJB='" + dtmjhztj3.Rows[i]["GDPDJB"] + "'" : " and (GDPDJB is null or GDPDJB='')";
string CZCSXM = !string.IsNullOrEmpty(dtmjhztj3.Rows[i]["CZCSXM"].ToTrim()) ? " and CZCSXM='" + dtmjhztj3.Rows[i]["CZCSXM"] + "'" : " and (CZCSXM is null or CZCSXM='')";
string TBXHDM = !string.IsNullOrEmpty(dtmjhztj3.Rows[i]["TBXHDM"].ToTrim()) ? " and TBXHDM='" + dtmjhztj3.Rows[i]["TBXHDM"] + "'" : " and (TBXHDM is null or TBXHDM='')";
string GDZZSXDM = !string.IsNullOrEmpty(dtmjhztj3.Rows[i]["ZZSXDM"].ToTrim()) ? " and ZZSXDM='" + dtmjhztj3.Rows[i]["ZZSXDM"] + "'" : " and (ZZSXDM is null or ZZSXDM='')";
string FRDBS = !string.IsNullOrEmpty(dtmjhztj3.Rows[i]["FRDBS"].ToTrim()) ? " and FRDBS='" + dtmjhztj3.Rows[i]["FRDBS"] + "'" : " and (FRDBS is null or FRDBS='')";
string dtwhere = string.Format(" DLBM like '01%' and ZLDWDM='{0}' and QSDWDM='{1}' and MSSM='{2}' {3} ", dtmjhztj3.Rows[i]["ZLDWDM"], dtmjhztj3.Rows[i]["QSDWDM"], dtmjhztj3.Rows[i]["MSSM"], QSXZ + GDLX + GDPDJB + CZCSXM + TBXHDM + GDZZSXDM + FRDBS);
dbHelper.ExecuteNonQueryWithException(string.Format("update MJHZTJB3 set ZZSXDM='GZ' where {0}", dtwhere), CommandType.Text);
}
}
}
}
private void RbECTNMK_Click(object sender, RoutedEventArgs e)
{
if (rbNOWNMK.IsChecked == true)
{
SelNMKPath.IsEnabled = false;
}
else
{
SelNMKPath.IsEnabled = true;
}
}
}
}