using Aspose.Cells;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.AE;
using KGIS.Framework.AE.Enum;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Utility;
using Kingo.Plugin.BGResultManager.Model;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml;
namespace Kingo.Plugin.BGResultManager.Utility
{
public class StatisticalReportClass
{
#region 之前的导出方法
public string MDBpath = "";
///
/// 农村土地利用现状一级分类面积按权属性质汇总表
///
///
///
///
/// 霍岩 2018-11-28 新增
public bool ExportReportByLYXZYJFL_QSXZ(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht = null, string COND1 = "", string COND2 = "", int DWJB = 12, string sNMKMDBPath = "")
{
try
{
MDBpath = sNMKMDBPath;
string reportTempaltePath = GetTPath() + reportEntity.Name + ".xlsx";
string xzqdm = string.Empty;
string xzqmc = string.Empty;
DataTable dtRst = null;
if (COND1.ToUpper().Contains("FRDBS"))
{
//获取县级飞入地
dtRst = GetLYXZYJFLQSXZData(dbHelper, reportEntity, selectht, COND1, COND2, 6);
//获取乡镇飞入地
dtRst.Merge(GetLYXZYJFLQSXZData(dbHelper, reportEntity, selectht, COND1, COND2, 9), true, MissingSchemaAction.Ignore);
//获取村级飞入地
dtRst.Merge(GetLYXZYJFLQSXZData(dbHelper, reportEntity, selectht, COND1, COND2, 12), true, MissingSchemaAction.Ignore);
dtRst.Columns.Add("rowId", typeof(int));
dtRst.Columns["rowId"].SetOrdinal(0);
for (int i = 0; i < dtRst.Rows.Count; i++)
{
DataRow dr = dtRst.Rows[i];
dr.BeginEdit();
dr["rowId"] = i + 1;
dr.EndEdit();
}
}
else
{
dtRst = GetLYXZYJFLQSXZData(dbHelper, reportEntity, selectht, COND1, COND2);
}
OutExcel2(dtRst, savePath, reportTempaltePath, xzqdm, xzqmc, 6, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
private DataTable GetLYXZYJFLQSXZData(IRDBHelper dbHelper, ReportEntityClass reportEntity, System.Collections.Hashtable selectht = null, string COND1 = "", string COND2 = "", int DWJB = 12)
{
try
{
StringBuilder sbSQL = new StringBuilder();
sbSQL.Append("select ");
sbSQL.Append(" '' as XZQMC");
if (COND1.ToUpper().Contains("FRDBS"))
{
if (dbHelper.DataBase == DatabaseType.SQLite)
{
sbSQL.Append(",substr(ZLDWDM,1, {2}) as xzqdm");
}
else
{
sbSQL.Append(",LEFT(ZLDWDM, {2}) as xzqdm");
}
}
else
{
sbSQL.Append(",ZLDWDM as xzqdm");
}
if (COND1.ToUpper().Contains("FRDBS"))
{
sbSQL.Append(",'' as QSXZQMC");
if (dbHelper.DataBase == DatabaseType.SQLite)
{
sbSQL.Append(",substr(QSDWDM,1, {2}) as QSXZQDM");
}
else
{
sbSQL.Append(",LEFT(QSDWDM, {2}) as QSXZQDM");
}
}
if (dbHelper.DataBase == DatabaseType.SQLite)
{
sbSQL.Append(",SUM(TBZMJ) as ZMJ");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20') then TBZMJ else 0 end ) as GMJ");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then TBZMJ else 0.00 end ) as JMJ");
sbSQL.Append(",SUM(D00) as ZD00");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D00 else 0 end ) as GJD00");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D00 else 0.00 end ) as JD00");
sbSQL.Append(",SUM(D01) as ZD01");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D01 else 0 end ) as GJD01");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D01 else 0.00 end ) as JD01");
sbSQL.Append(",SUM(D02) as ZD02");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D02 else 0 end ) as GJD02");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D02 else 0.00 end ) as JD02");
sbSQL.Append(",SUM(D03) as ZD03");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D03 else 0 end) as GJD03");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D03 else 0.00 end) as JD03");
sbSQL.Append(",SUM(D04) as ZD04");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D04 else 0 end) as GJD04");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D04 else 0.00 end) as JD04");
sbSQL.Append(",SUM(D05) as ZD05");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D05 else 0 end) as GJD05");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D05 else 0.00 end) as JD05");
sbSQL.Append(",SUM(D06) as ZD06");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D06 else 0 end) as GJD06");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D06 else 0.00 end) as JD06");
sbSQL.Append(",SUM(D07) as ZD07");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D07 else 0 end) as GJD07");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D07 else 0.00 end) as JD07");
sbSQL.Append(",SUM(D08) as ZD08");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D08 else 0 end) as GJD08");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D08 else 0.00 end) as JD08");
sbSQL.Append(",SUM(D09) as ZD09");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D09 else 0 end) as GJD09");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D09 else 0.00 end) as JD09");
sbSQL.Append(",SUM(D10) as ZD10");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D10 else 0 end) as GJD10");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D10 else 0.00 end) as JD10");
sbSQL.Append(",SUM(D11) as ZD11");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D11 else 0 end) as GJD11");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D11 else 0.00 end) as JD11");
sbSQL.Append(",SUM(D12) as ZD12 ");
sbSQL.Append(",SUM(case when QSXZ IN ('10', '20')then D12 else 0 end) as GJD12");
sbSQL.Append(",SUM(case when QSXZ IN ('30', '31', '32', '33', '34', '40')then D12 else 0.00 end) as JD12");
}
else
{
sbSQL.Append(",SUM(TBZMJ) as ZMJ");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), TBZMJ, 0)) as GMJ");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), TBZMJ, 0)) as JMJ");
sbSQL.Append(",SUM(D00) as ZD00");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D00, 0)) as GJD00");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D00, 0)) as JD00");
sbSQL.Append(",SUM(D01) as ZD01");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D01, 0)) as GJD01");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D01, 0)) as JD01");
sbSQL.Append(",SUM(D02) as ZD02");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D02, 0)) as GJD02");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D02, 0)) as JD02");
sbSQL.Append(",SUM(D03) as ZD03");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D03, 0)) as GJD03");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D03, 0)) as JD03");
sbSQL.Append(",SUM(D04) as ZD04");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D04, 0)) as GJD04");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D04, 0)) as JD04");
sbSQL.Append(",SUM(D05) as ZD05");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D05, 0)) as GJD05");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D05, 0)) as JD05");
sbSQL.Append(",SUM(D06) as ZD06");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D06, 0)) as GJD06");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D06, 0)) as JD06");
sbSQL.Append(",SUM(D07) as ZD07");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D07, 0)) as GJD07");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D07, 0)) as JD07");
sbSQL.Append(",SUM(D08) as ZD08");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D08, 0)) as GJD08");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D08, 0)) as JD08");
sbSQL.Append(",SUM(D09) as ZD09");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D09, 0)) as GJD09");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D09, 0)) as JD09");
sbSQL.Append(",SUM(D10) as ZD10");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D10, 0)) as GJD10");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D10, 0)) as JD10");
sbSQL.Append(",SUM(D11) as ZD11");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D11, 0)) as GJD11");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D11, 0)) as JD11");
sbSQL.Append(",SUM(D12) as ZD12 ");
sbSQL.Append(",SUM(iif(QSXZ IN ('10', '20'), D12, 0)) as GJD12");
sbSQL.Append(",SUM(iif(QSXZ IN ('30', '31', '32', '33', '34', '40'), D12, 0)) as JD12");
}
if (!COND1.ToUpper().Contains("FRDBS"))
{
if (dbHelper.DataBase == DatabaseType.SQLite)
{
sbSQL.Append(",substr(ZLDWDM,1, 9) as xzqdm_t");
sbSQL.Append(",substr(ZLDWDM,1, 6) as xzqdm_c");
}
else
{
sbSQL.Append(",LEFT(ZLDWDM, 9) as xzqdm_t");
sbSQL.Append(",LEFT(ZLDWDM, 6) as xzqdm_c");
}
}
sbSQL.Append(" from ");
if (COND1.ToUpper().Contains("FRDBS"))
{
if (dbHelper.DataBase == DatabaseType.SQLite)
{
sbSQL.Append("{0} where 1=1 {1} and substr(ZLDWDM,1, {2}) <> substr(QSDWDM,1, {2})");
sbSQL.Append(" group by substr(ZLDWDM,1, {2}), substr(QSDWDM,1, {2})");
sbSQL.Append(" ORDER BY substr(ZLDWDM,1, {2}), substr(QSDWDM,1, {2})");
}
else
{
sbSQL.Append("{0} where 1=1 {1} and LEFT(ZLDWDM, {2}) <> LEFT(QSDWDM, {2})");
sbSQL.Append(" group by LEFT(ZLDWDM, {2}), LEFT(QSDWDM, {2})");
sbSQL.Append(" ORDER BY LEFT(ZLDWDM, {2}), LEFT(QSDWDM, {2})");
}
}
else
{
sbSQL.Append(" {0} where 1=1 {1}");
sbSQL.Append(" group by ZLDWDM");
sbSQL.Append(" ORDER BY ZLDWDM");
}
string reportSql = sbSQL.ToString();
DataTable dtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(reportSql, ReportTableName, COND1, DWJB), true);
if (selectht == null)
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref dtRst);
else
RemoveDRByXZQDM(dbHelper, selectht, ref dtRst);
if (string.IsNullOrEmpty(COND1))
dtRst = GetUpLevelData(dtRst, 2, dtRst.Columns.Count - 3);
GetXZQMC(dbHelper, ref dtRst);
return dtRst;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 农村土地利用现状一级分类面积按权属性质汇总表(空)
///
///
///
///
/// 王欢 2018-11-28 新增
public bool ExportReportByLYXZYJFL_NULLQSXZ(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht = null, string COND1 = "", string COND2 = "")
{
try
{
string reportTempaltePath = GetZLPath() + reportEntity.TempalateFileName + ".xlsx";
string newPath = System.IO.Path.GetDirectoryName(savePath);// + selectht[item].ToString();
string newFile = "(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")" + System.IO.Path.GetFileName(savePath);
if (!System.IO.Directory.Exists(newPath))
{
System.IO.Directory.CreateDirectory(newPath);
}
string newsavePath = newPath + "\\" + newFile;
OutExcel(null, newsavePath, reportTempaltePath, 7, 1, 2);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 获取上级地类数据
///
///
/// 数值列开始索引
/// 数值列结束索引
///
private DataTable GetUpLevelData(DataTable dtRST, int NumColStartIndex, int NumColEndIndex)
{
try
{
//获取乡镇行政区代码
var QueryTown = from t in dtRST.AsEnumerable()
group t by new { t1 = t.Field("xzqdm_t") } into m
select new { xzqdm = m.Key.t1 };
//获取县行政区代码
var QueryCounty = from t in dtRST.AsEnumerable()
group t by new { t1 = t.Field("xzqdm_c") } into m
select new { xzqdm = m.Key.t1 };
foreach (var item in QueryTown.ToList())
{
string strXZQDM = item.xzqdm;
DataRow dr = dtRST.NewRow();
if (string.IsNullOrWhiteSpace(strXZQDM))
{
continue;
}
dr["xzqdm"] = strXZQDM;
for (int i = NumColStartIndex; i <= NumColEndIndex; i++)
{
string strNumColName = dtRST.Columns[i].ColumnName;
if (dtRST.Columns[i].DataType != typeof(double) || !string.IsNullOrWhiteSpace(dtRST.Columns[i].Expression))
continue;
dr[i] = dtRST.Compute(string.Format("SUM({0})", strNumColName), string.Format("xzqdm_t = '{0}'", strXZQDM));
}
dtRST.Rows.Add(dr);
}
foreach (var item in QueryCounty.ToList())
{
string strXZQDM = item.xzqdm;
if (string.IsNullOrWhiteSpace(strXZQDM))
{
continue;
}
DataRow dr = dtRST.NewRow();
dr["xzqdm"] = strXZQDM;
for (int i = NumColStartIndex; i <= NumColEndIndex; i++)
{
string strNumColName = dtRST.Columns[i].ColumnName;
if (dtRST.Columns[i].DataType != typeof(double) || !string.IsNullOrWhiteSpace(dtRST.Columns[i].Expression))
continue;
dr[i] = dtRST.Compute(string.Format("SUM({0})", strNumColName), string.Format("xzqdm_c = '{0}'", strXZQDM));
}
dtRST.Rows.Add(dr);
}
dtRST.Columns.Remove("xzqdm_c");
dtRST.Columns.Remove("xzqdm_t");
DataRow[] drcRST = dtRST.Select(null, "xzqdm ASC");
if (drcRST.Length > 0)
dtRST = drcRST.CopyToDataTable();
return dtRST;
}
catch (Exception ex)
{
throw ex;
}
}
private List QSList = null;
///
/// 获取行政区名称
///
///
///
///
private DataTable GetXZQMC(IRDBHelper dbHelper, ref DataTable dtRst, string tblName = "DLTB")
{
try
{
if (dtRst != null)
{
List CountyList = GetXZQDic(1).ToList();
List TownList = GetXZQDic(2).ToList();
List XZQList = GetXZQDic(3).ToList();
List HDList = GetXZQDic(4).ToList();
if (QSList == null)
{
string dbPath = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetDicDataPath();
if (!string.IsNullOrWhiteSpace(dbPath))
{
string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection");
connStr = string.Format(connStr, dbPath);
IRDBHelper rdbHelper = RDBFactory.CreateDbHelper(connStr, DatabaseType.MSAccess);
string strSQL = "select a.* from Sys_DicDetail AS a INNER JOIN Sys_DicManage AS b ON CStr(b.ID) = a.OWNERDIC WHERE b.ALIASNAME = 'QSDM'";
DataTable dtDic = rdbHelper.ExecuteDatatable("Dic", strSQL, true);
if (dtDic != null)
{
//Bug-12137 霍岩 2018-11-14 使用CODE字段按顺序排序
QSList = TBToList.ToList(dtDic).OrderBy(x => x.CODE).ToList();
QSList.ForEach(x => x.DisplayName = x.CODE + "-" + x.NAME);
}
}
}
foreach (DataRow dr in dtRst.Rows)
{
string strXZQDM = dr["XZQDM"].ToString();
if (string.IsNullOrWhiteSpace(strXZQDM))
continue;
dr.BeginEdit();
switch (strXZQDM.Length)
{
case 6:
BasicDataModel bdm = CountyList.Find(x => x.Code == strXZQDM);
if (bdm != null)
dr["XZQMC"] = bdm.Name;
if (dtRst.Columns.Contains("HDMC"))
{
List CountyListHD = GetXZQDic(1).ToList();
List> dic = new List>();
foreach (BasicDataModel model in CountyListHD)
{
dic.Add(model.Attribures);
}
List hdmclist = new List();
string hdmc = string.Empty;
foreach (Dictionary model in dic)
{
if (model.ContainsKey("HDMC"))
{
if (!hdmclist.Exists(x => x == model["HDMC"].ToString()))
{
hdmclist.Add(model["HDMC"].ToString());
if (string.IsNullOrEmpty(hdmc))
{
hdmc = model["HDMC"].ToString();
}
else
{
hdmc = hdmc + "、" + model["HDMC"].ToString();
}
}
}
}
dr["HDMC"] = hdmc;
}
break;
case 9:
List bdm2 = TownList.FindAll(x => x.Code == strXZQDM);
if (bdm2 != null && bdm2.Count > 0)
dr["XZQMC"] = bdm2[0].Name;
if (dtRst.Columns.Contains("HDMC"))
{
List> diclist2 = new List>();
foreach (BasicDataModel model in bdm2)
{
diclist2.Add(model.Attribures);
}
List hdmclist = new List();
string hdmc = string.Empty;
foreach (Dictionary model in diclist2)
{
if (model.ContainsKey("HDMC"))
{
if (!hdmclist.Exists(x => x == model["HDMC"].ToString()))
{
hdmclist.Add(model["HDMC"].ToString());
if (string.IsNullOrEmpty(hdmc))
{
hdmc = model["HDMC"].ToString();
}
else
{
hdmc = hdmc + "、" + model["HDMC"].ToString();
}
}
}
}
dr["HDMC"] = hdmc;
}
break;
default:
List drcXZQ = XZQList.FindAll(x => x.Code == strXZQDM);
if (drcXZQ != null && drcXZQ.Count > 0)
{
dr["XZQMC"] = drcXZQ[0].Name;
}
if (dtRst.Columns.Contains("HDMC"))
{
List drc = HDList.FindAll(x => x.Code == strXZQDM);
if (drc != null && drc.Count > 0)
{
List hdmclist = new List();
string hdmc = string.Empty;
for (int i = 0; i < drc.Count; i++)
{
if (!string.IsNullOrEmpty(drc[i].Name.ToString()))
{
//string str = drc[i]["HDMC"].ToString().Substring(0, drc[i]["HDMC"].ToString().Length - 2);
string str = drc[i].Name.ToString();
if (!hdmclist.Exists(x => x == str))
{
hdmclist.Add(str);
if (string.IsNullOrEmpty(hdmc))
{
hdmc = str;
}
else
{
hdmc = hdmc + "、" + str;
}
}
}
}
dr["HDMC"] = hdmc;
}
}
break;
}
if (dtRst.Columns.Contains("QSXZQDM"))
{
string strQSXZQDM = dr["QSXZQDM"].ToString();
DataDicTionary qsData = null;
if (strQSXZQDM.Length == 12)
{
qsData = QSList.Find(x => x.CODE == strQSXZQDM.PadRight(19, '0'));
}
else
{
qsData = QSList.Find(x => x.CODE == strQSXZQDM);
}
if (qsData != null)
{
dr["QSXZQMC"] = qsData.NAME;
}
else
{
if (strQSXZQDM.Length == 6 || strQSXZQDM.Length == 9)
{
List drc = XZQList.FindAll(x => x.Code == strQSXZQDM);
if (drc != null && drc.Count > 0)
dr["QSXZQMC"] = drc[0].Name;
}
}
}
dr.EndEdit();
}
}
return dtRst;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取行政区字典数据
///
/// 行政级别(1:县、2:镇、3:村、4:海岛)
public static BasicDataModel[] GetXZQDic(int pLevel)
{
List result = new List();
if (pLevel == 1)
{
IRDBHelper helper = null;
DataTable dtData = null;
try
{
string strConn = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection");
strConn = string.Format(strConn, SysAppPath.GetDataBaseRoot() + "System.mdb");
if (string.IsNullOrWhiteSpace(strConn))
{
result = null;
}
helper = RDBFactory.CreateDbHelper(strConn, DatabaseType.MSAccess);
string strSQL = string.Format("SELECT * FROM {0} where XZQ ='{1}'", "XZQ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo)
.CODE);
dtData = helper.ExecuteDatatable("dtData", strSQL, true);
if (dtData != null)
{
foreach (DataRow row in dtData.Rows)
{
BasicDataModel node = new BasicDataModel();
node.Name = row["XZQMC"] is DBNull ? "" : row["XZQMC"].ToString();
node.Code = row["XZQ"].ToString();
node.DisplayName = string.Format("({0}){1}", node.Code, node.Name);
node.Attribures = new Dictionary();
foreach (DataColumn col in dtData.Columns)
{
node.Attribures.Add(col.ColumnName, row[col]);
}
result.Add(node);
}
}
return result.ToArray();
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
finally
{
if (dtData != null)
{
dtData.Clear();
dtData.Dispose();
}
if (helper != null)
{
helper.DisConnect();
}
}
}
else if (pLevel == 2)
{
ICursor pCur = null;
IWorkspaceAPI s_WsAPI = null;
try
{
string connStr = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath();
s_WsAPI = new WorkspaceAPI(connStr, WorkspaceTypeEnum.GDBFile);
//获取基础mdb中的tbmj之和
IQueryDef pQDef = (s_WsAPI.CurrentWorkspace as IFeatureWorkspace).CreateQueryDef();
pQDef.Tables = "JC_XZQ";
pQDef.SubFields = "*";
pCur = pQDef.Evaluate();
IRow pRow = null;
while ((pRow = pCur.NextRow()) != null)
{
BasicDataModel node = new BasicDataModel();
node.Name = pRow.get_Value(pRow.Fields.FindField("XZQMC")) is DBNull ? "" : pRow.get_Value(pRow.Fields.FindField("XZQMC")).ToString();
node.Code = pRow.get_Value(pRow.Fields.FindField("XZQDM")).ToString();
node.DisplayName = string.Format("({0}){1}", node.Code, node.Name);
node.Attribures = new Dictionary();
for (int i = 0; i < pRow.Fields.FieldCount; i++)
{
IField field = pRow.Fields.get_Field(i);
if (field.Name.ToUpper() != "SHAPE")
{
node.Attribures.Add(field.Name, pRow.get_Value(pRow.Fields.FindField(field.Name)));
}
}
result.Add(node);
}
return result.ToArray();
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
finally
{
if (pCur != null)
{
Marshal.ReleaseComObject(pCur);
}
if (s_WsAPI != null)
{
s_WsAPI.CloseWorkspace();
}
}
}
else if (pLevel == 3)
{
ICursor pCur = null;
IWorkspaceAPI s_WsAPI = null;
try
{
string connStr = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath();
s_WsAPI = new WorkspaceAPI(connStr, WorkspaceTypeEnum.GDBFile);
//获取基础mdb中的tbmj之和
IQueryDef pQDef = (s_WsAPI.CurrentWorkspace as IFeatureWorkspace).CreateQueryDef();
pQDef.Tables = "CJDCQ";
pQDef.SubFields = "distinct ZLDWDM,ZLDWMC";
pCur = pQDef.Evaluate();
IRow pRow = null;
while ((pRow = pCur.NextRow()) != null)
{
BasicDataModel node = new BasicDataModel();
node.Name = pRow.get_Value(pRow.Fields.FindField("ZLDWMC")) is DBNull ? "" : pRow.get_Value(pRow.Fields.FindField("ZLDWMC")).ToString();
node.Code = pRow.get_Value(pRow.Fields.FindField("ZLDWDM")).ToString().Substring(0, 12);
node.DisplayName = string.Format("({0}){1}", node.Code, node.Name);
node.Attribures = new Dictionary();
//for (int i = 0; i < pRow.Fields.FieldCount; i++)
//{
// IField field = pRow.Fields.get_Field(i);
// if (field.Name.ToUpper() != "SHAPE")
// {
// node.Attribures.Add(field.Name, pRow.get_Value(pRow.Fields.FindField(field.Name)));
// }
//}
result.Add(node);
}
return result.ToArray();
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
finally
{
if (pCur != null)
{
Marshal.ReleaseComObject(pCur);
}
if (s_WsAPI != null)
{
s_WsAPI.CloseWorkspace();
}
}
}
else if (pLevel == 4)
{
ICursor pCur = null;
IWorkspaceAPI s_WsAPI = null;
try
{
string connStr = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath();
s_WsAPI = new WorkspaceAPI(connStr, WorkspaceTypeEnum.GDBFile);
//获取基础mdb中的tbmj之和
IQueryDef pQDef = (s_WsAPI.CurrentWorkspace as IFeatureWorkspace).CreateQueryDef();
pQDef.Tables = "CJDCQ";
pQDef.SubFields = "distinct ZLDWDM,HDMC";
pCur = pQDef.Evaluate();
IRow pRow = null;
while ((pRow = pCur.NextRow()) != null)
{
BasicDataModel node = new BasicDataModel();
node.Name = pRow.get_Value(pRow.Fields.FindField("HDMC")) is DBNull ? "" : pRow.get_Value(pRow.Fields.FindField("HDMC")).ToString();
node.Code = pRow.get_Value(pRow.Fields.FindField("ZLDWDM")).ToString().Substring(0, 12);
node.DisplayName = string.Format("({0}){1}", node.Code, node.Name);
node.Attribures = new Dictionary();
result.Add(node);
}
return result.ToArray();
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
finally
{
if (pCur != null)
{
Marshal.ReleaseComObject(pCur);
}
if (s_WsAPI != null)
{
s_WsAPI.CloseWorkspace();
}
}
}
return null;
}
///
/// 农村土地利用现状一级分类面积汇总表(县行政区划码6位)
///
/// ///
///
///
/// 霍岩 2018-11-27 新增
private bool ExportReportNCTDLYXZYJFLMJHZB_CountyXZQDM6(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht = null, string COND1 = "", string COND2 = "", int DWJB = 12, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
string xzqdm = string.Empty;
string xzqmc = string.Empty;
DataTable dtRst = null;
if (COND1.ToUpper().Contains("FRDBS"))
{
//获取县级飞入地
dtRst = GetDLYXZYJFLMJHZB(dbHelper, reportEntity, selectht, COND1, COND2, 6);
//获取乡镇飞入地
dtRst.Merge(GetDLYXZYJFLMJHZB(dbHelper, reportEntity, selectht, COND1, COND2, 9), true, MissingSchemaAction.Ignore);
//获取村级飞入地
dtRst.Merge(GetDLYXZYJFLMJHZB(dbHelper, reportEntity, selectht, COND1, COND2, 12), true, MissingSchemaAction.Ignore);
dtRst.Columns.Add("rowId", typeof(int));
dtRst.Columns["rowId"].SetOrdinal(0);
for (int i = 0; i < dtRst.Rows.Count; i++)
{
DataRow dr = dtRst.Rows[i];
dr.BeginEdit();
dr["rowId"] = i + 1;
dr.EndEdit();
}
}
else
{
dtRst = GetDLYXZYJFLMJHZB(dbHelper, reportEntity, selectht, COND1, COND2);
if (COND1.ToUpper().Contains("MSSM"))
{
dtRst.Columns.Add("rowId", typeof(int));
dtRst.Columns["rowId"].SetOrdinal(0);
for (int i = 0; i < dtRst.Rows.Count; i++)
{
DataRow dr = dtRst.Rows[i];
dr.BeginEdit();
dr["rowId"] = i + 1;
dr.EndEdit();
}
}
}
OutExcel2(dtRst, savePath, reportTempaltePath, xzqdm, xzqmc, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
private DataTable GetDLYXZYJFLMJHZB(IRDBHelper dbHelper, ReportEntityClass reportEntity, System.Collections.Hashtable selectht = null, string COND1 = "", string COND2 = "", int DWJB = 12)
{
try
{
StringBuilder sbSQL = new StringBuilder();
sbSQL.Append("SELECT ");
sbSQL.Append(" '' as XZQMC");
if (COND1.ToUpper().Contains("FRDBS"))
{
if (dbHelper.DataBase == DatabaseType.SQLite)
{
sbSQL.Append(",substr(ZLDWDM,1, {2}) as xzqdm");
}
else
{
sbSQL.Append(",LEFT(ZLDWDM, {2}) as xzqdm");
}
}
else
{
sbSQL.Append(",ZLDWDM as xzqdm");
}
if (!string.IsNullOrWhiteSpace(COND1) && COND1.Contains("01"))
{
sbSQL.Append(",'' as hdmc");
}
if (COND1.ToUpper().Contains("FRDBS"))
{
sbSQL.Append(",'' as QSXZQMC");
if (dbHelper.DataBase == DatabaseType.SQLite)
{
sbSQL.Append(",substr(QSDWDM,1,{2}) as QSXZQDM");
}
else
{
sbSQL.Append(",LEFT(QSDWDM, {2}) as QSXZQDM");
}
}
sbSQL.Append(",SUM(TBZMJ) as XZQYZMJ");
sbSQL.Append(",SUM(D00) AS DL00");
sbSQL.Append(",SUM(D01) as DL01");
sbSQL.Append(",SUM(D02) as DL02");
sbSQL.Append(",SUM(D03) as DL03");
sbSQL.Append(",SUM(D04) as DL04");
sbSQL.Append(",SUM(D05) as DL05");
sbSQL.Append(",SUM(D06) as DL06");
sbSQL.Append(",SUM(D07) as DL07");
sbSQL.Append(",SUM(D08) as DL08");
sbSQL.Append(",SUM(D09) as DL09");
sbSQL.Append(",SUM(D10) as DL10");
sbSQL.Append(",SUM(D11) as DL11");
sbSQL.Append(",SUM(D12) as DL12 ");
if (!COND1.ToUpper().Contains("FRDBS"))
{
if (dbHelper.DataBase == DatabaseType.SQLite)
{
sbSQL.Append(",substr(ZLDWDM,1, 9) as xzqdm_t");
sbSQL.Append(",substr(ZLDWDM,1, 6) as xzqdm_c");
}
else
{
sbSQL.Append(",LEFT(ZLDWDM, 9) as xzqdm_t");
sbSQL.Append(",LEFT(ZLDWDM, 6) as xzqdm_c");
}
}
sbSQL.Append(" from ");
if (COND1.ToUpper().Contains("FRDBS"))
{
if (dbHelper.DataBase == DatabaseType.SQLite)
{
sbSQL.Append("{0} where 1=1 {1} and substr(ZLDWDM,1, {2}) <> substr(QSDWDM,1, {2})");
sbSQL.Append(" group by substr(ZLDWDM,1, {2}), substr(QSDWDM,1, {2})");
sbSQL.Append(" ORDER BY substr(ZLDWDM,1, {2}), substr(QSDWDM,1, {2})");
}
else
{
sbSQL.Append("{0} where 1=1 {1} and LEFT(ZLDWDM, {2}) <> LEFT(QSDWDM, {2})");
sbSQL.Append(" group by LEFT(ZLDWDM, {2}), LEFT(QSDWDM, {2})");
sbSQL.Append(" ORDER BY LEFT(ZLDWDM, {2}), LEFT(QSDWDM, {2})");
}
}
else
{
sbSQL.Append("{0} where 1=1 {1}");
sbSQL.Append(" group by ZLDWDM");
sbSQL.Append(" ORDER BY ZLDWDM");
}
string reportSql = sbSQL.ToString();
if (COND1.ToUpper().Contains("FRDBS"))
{
reportSql = string.Format(reportSql, ReportTableName, COND1, DWJB);
}
else
{
reportSql = string.Format(reportSql, ReportTableName, COND1);
}
DataTable dtRst = dbHelper.ExecuteDatatable("statisticType", reportSql, true);
if (selectht == null)
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref dtRst);
else
RemoveDRByXZQDM(dbHelper, selectht, ref dtRst);
ClaerNullByDT1(dbHelper, COND2, ref dtRst);
//飞入地不进行上级行政区汇总
if (!COND1.ToUpper().Contains("FRDBS"))
dtRst = GetUpLevelData(dtRst, 2, dtRst.Columns.Count - 3);
GetXZQMC(dbHelper, ref dtRst);
return dtRst;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 土地利用现状分类面积汇总表(县行政区划码6位)
///
/// ///
///
///
/// 霍岩 2018-11-27 新增
private bool ExportReportNCTDLYXZFLMJHZB_CountyXZQDM6(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht = null, string COND1 = "", string COND2 = "", int DWJB = 12, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.Name + ".xlsx";
string xzqdm = string.Empty;
string xzqmc = string.Empty;
DataTable dtRst = null;
if (COND1.ToUpper().Contains("FRDBS"))
{
//获取县级飞入地
dtRst = GetDLYXZFLMJHZBData(dbHelper, reportEntity, selectht, COND1, COND2, 6);
//获取乡镇飞入地
dtRst.Merge(GetDLYXZFLMJHZBData(dbHelper, reportEntity, selectht, COND1, COND2, 9), true, MissingSchemaAction.Ignore);
//获取村级飞入地
dtRst.Merge(GetDLYXZFLMJHZBData(dbHelper, reportEntity, selectht, COND1, COND2, 12), true, MissingSchemaAction.Ignore);
dtRst.Columns.Add("rowId", typeof(int));
dtRst.Columns["rowId"].SetOrdinal(0);
for (int i = 0; i < dtRst.Rows.Count; i++)
{
DataRow dr = dtRst.Rows[i];
dr.BeginEdit();
dr["rowId"] = i + 1;
dr.EndEdit();
}
}
else
{
dtRst = GetDLYXZFLMJHZBData(dbHelper, reportEntity, selectht, COND1, COND2);
if (COND1.ToUpper().Contains("MSSM"))
{
dtRst.Columns.Add("rowId", typeof(int));
dtRst.Columns["rowId"].SetOrdinal(0);
for (int i = 0; i < dtRst.Rows.Count; i++)
{
DataRow dr = dtRst.Rows[i];
dr.BeginEdit();
dr["rowId"] = i + 1;
dr.EndEdit();
}
}
}
OutExcel2(dtRst, savePath, reportTempaltePath, xzqdm, xzqmc, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
private DataTable GetDLYXZFLMJHZBData(IRDBHelper dbHelper, ReportEntityClass reportEntity, System.Collections.Hashtable selectht = null, string COND1 = "", string COND2 = "", int DWJB = 12)
{
try
{
StringBuilder sbSQL = new StringBuilder();
sbSQL.Append("select ");
sbSQL.Append(" '' as XZQMC");
if (COND1.ToUpper().Contains("FRDBS"))
{
sbSQL.Append(",substr(ZLDWDM,1, {2}) as xzqdm");
}
else
{
sbSQL.Append(",ZLDWDM as xzqdm");
}
if (!string.IsNullOrWhiteSpace(COND1) && COND1.Contains("01"))
{
sbSQL.Append(",'' as hdmc");
}
if (COND1.ToUpper().Contains("FRDBS"))
{
sbSQL.Append(",'' as QSXZQMC");
sbSQL.Append(",substr(QSDWDM,1, {2}) as QSXZQDM");
}
sbSQL.Append(",SUM(TBZMJ) as XZQYZMJ");
sbSQL.Append(",SUM(D00) as DL00");
sbSQL.Append(",SUM(D0303) as DL0303");
sbSQL.Append(",SUM(D0304) as DL0304");
sbSQL.Append(",SUM(D0306) as DL0306");
sbSQL.Append(",SUM(D0402) as DL0402");
sbSQL.Append(",SUM(D0603) as DL0603");
sbSQL.Append(",SUM(D1105) as DL1105");
sbSQL.Append(",SUM(D1106) as DL1106");
sbSQL.Append(",SUM(D1108) as DL1108");
sbSQL.Append(",SUM(D01) as DL01");
sbSQL.Append(",SUM(D0101) as DL0101");
sbSQL.Append(",SUM(D0102) as DL0102");
sbSQL.Append(",SUM(D0103) as DL0103");
sbSQL.Append(",SUM(D02) as DL02");
sbSQL.Append(",SUM(D0201) + SUM(D0201K) as DL0201");
sbSQL.Append(",SUM(D0202) + SUM(D0202K) as DL0202");
sbSQL.Append(",SUM(D0203) + SUM(D0203K) as DL0203");
sbSQL.Append(",SUM(D0204) + SUM(D0204K) as DL0204");
sbSQL.Append(",SUM(D03) as DL03");
sbSQL.Append(",SUM(D0301) + SUM(D0301K) as DL0301");
sbSQL.Append(",SUM(D0302) + SUM(D0302K) as DL0302");
sbSQL.Append(",SUM(D0305) as DL0305");
sbSQL.Append(",SUM(D0307) + SUM(D0307K) as DL0307");
sbSQL.Append(",SUM(D04) as DL04");
sbSQL.Append(",SUM(D0401) as DL0401");
sbSQL.Append(",SUM(D0403) + SUM(D0403K) as DL0403");
sbSQL.Append(",SUM(D0404) as DL0404");
sbSQL.Append(",SUM(D05) as DL05");
sbSQL.Append(",SUM(D05H1) as DL05H1");
sbSQL.Append(",SUM(D0508) as DL0508");
sbSQL.Append(",SUM(D06) as DL06");
sbSQL.Append(",SUM(D0601) as DL0601");
sbSQL.Append(",SUM(D0602) as DL0602");
sbSQL.Append(",SUM(D07) as DL07");
sbSQL.Append(",SUM(D0701) as DL0701");
sbSQL.Append(",SUM(D0702) as DL0702");
sbSQL.Append(",SUM(D08) as DL08");
sbSQL.Append(",SUM(D08H1) as DL08H1");
sbSQL.Append(",SUM(D08H2) + SUM(D08H2A) as DL08H2");
sbSQL.Append(",SUM(D0809) as DL0809");
sbSQL.Append(",SUM(D0810) + SUM(D0810A) as DL0810");
sbSQL.Append(",SUM(D09) as DL09");
sbSQL.Append(",SUM(D10) as DL10");
sbSQL.Append(",SUM(D1001) as DL1001");
sbSQL.Append(",SUM(D1002) as DL1002");
sbSQL.Append(",SUM(D1003) as DL1003");
sbSQL.Append(",SUM(D1004) as DL1004");
sbSQL.Append(",SUM(D1005) as DL1005");
sbSQL.Append(",SUM(D1006) as DL1006");
sbSQL.Append(",SUM(D1007) as DL1007");
sbSQL.Append(",SUM(D1008) as DL1008");
sbSQL.Append(",SUM(D1009) as DL1009");
sbSQL.Append(",SUM(D11) as DL11");
sbSQL.Append(",SUM(D1101) as DL1101");
sbSQL.Append(",SUM(D1102) as DL1102");
sbSQL.Append(",SUM(D1103) as DL1103");
sbSQL.Append(",SUM(D1104) + SUM(D1104A) + SUM(D1104K) as DL1104");
sbSQL.Append(",SUM(D1107) + SUM(D1107A) as DL1107");
sbSQL.Append(",SUM(D1109) as DL1109");
sbSQL.Append(",SUM(D1110) as DL1110");
sbSQL.Append(",SUM(D12) as DL12 ");
sbSQL.Append(",SUM(D1201) as DL1201");
sbSQL.Append(",SUM(D1202) as DL1202");
sbSQL.Append(",SUM(D1203) as DL1203");
sbSQL.Append(",SUM(D1204) as DL1204");
sbSQL.Append(",SUM(D1205) as DL1205");
sbSQL.Append(",SUM(D1206) as DL1206");
sbSQL.Append(",SUM(D1207) as DL1207");
if (!COND1.ToUpper().Contains("FRDBS"))
{
sbSQL.Append(",substr(ZLDWDM,1, 9) as xzqdm_t");
sbSQL.Append(",substr(ZLDWDM,1, 6) as xzqdm_c");
}
sbSQL.AppendLine(" from ");
if (COND1.ToUpper().Contains("FRDBS"))
{
sbSQL.AppendLine("{0} where 1=1 {1} and substr(ZLDWDM,1, {2}) <> substr(QSDWDM,1, {2})");
//if (DWJB > 6)
//{
// sbSQL.AppendLine("and LEFT(ZLDWDM, {2} - 3) = LEFT(QSDWDM, {2} - 3)");
//}
sbSQL.AppendLine(" group by substr(ZLDWDM,1, {2}), substr(QSDWDM,1, {2})");
sbSQL.AppendLine(" ORDER BY substr(ZLDWDM,1, {2}), substr(QSDWDM,1, {2})");
}
else
{
sbSQL.AppendLine("{0} where 1=1 {1}");
sbSQL.AppendLine(" group by ZLDWDM");
sbSQL.AppendLine(" ORDER BY ZLDWDM");
}
string reportSql = sbSQL.ToString();
if (COND1.ToUpper().Contains("FRDBS"))
{
reportSql = string.Format(reportSql, ReportTableName, COND1, DWJB);
}
else
{
reportSql = string.Format(reportSql, ReportTableName, COND1);
}
DataTable dtRst = dbHelper.ExecuteDatatable("statisticType", reportSql, true);
if (selectht == null)
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref dtRst);
else
RemoveDRByXZQDM(dbHelper, selectht, ref dtRst);
ClaerNullByDT1(dbHelper, COND2, ref dtRst);
//飞入地不进行上级行政区汇总
if (!COND1.ToUpper().Contains("FRDBS"))
dtRst = GetUpLevelData(dtRst, 2, dtRst.Columns.Count - 3);
GetXZQMC(dbHelper, ref dtRst);
return dtRst;
}
catch (Exception ex)
{
throw ex;
}
}
private DataTable dtXZQ2 = null;
///
/// 导出excel(2018-11-23格式调整)
///
///
///
///
///
private void OutExcel2(DataTable dt, string savePath, string templatePath, string xzqdm, string xzqmc, int startRowIndex, string tblName = "DLTB", string sNMKMDBPath = "")
{
Workbook workbook = new Workbook(templatePath);
workbook.CalculateFormula(true);
Worksheet sheet = workbook.Worksheets[0];
//Bug-13390 霍岩 2018-12-17 添加原Sheet名前加六位县行政区代码
sheet.Name = string.Format("({0})", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE) + System.IO.Path.GetFileNameWithoutExtension(templatePath);
startRowIndex--;
if (dt == null)
{
workbook.Save(savePath);
return;
}
//导出报错 王欢 2018-12-11
if ((!System.IO.Path.GetFileNameWithoutExtension(templatePath).Contains("海岛") && !System.IO.Path.GetFileNameWithoutExtension(templatePath).Contains("飞入地")) || System.IO.Path.GetFileNameWithoutExtension(templatePath).Contains("无居民"))
{
string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection");
string SourcePath = string.Format(connStr, SysAppPath.GetDataBaseRoot() + "System.mdb");
if (string.IsNullOrWhiteSpace(sNMKMDBPath) == false)
{
SourcePath = string.Format(connStr, sNMKMDBPath);
}
//创建数据库连接
//IRDBHelper dbHelper = RDBFactory.CreateDbHelper(SourcePath, Framework.DBOperator.DatabaseType.MSAccess);
//if (dtXZQ2 == null)
//{
// dtXZQ2 = dbHelper.ExecuteDatatable("XZQ", "SELECT DISTINCT left(ZLDWDM, 12) AS XZQDM, ZLDWMC AS XZQMC FROM CJDCQ", true);
// if (dtXZQ2.Rows.Count > 0)
// {
// dtXZQ2 = dtXZQ2.Select(null, "XZQDM ASC").CopyToDataTable();
// }
//}
List CountyList = GetXZQDic(1).ToList();
List TownList = GetXZQDic(2).ToList();
List dtXZQ2 = GetXZQDic(3).ToList();
foreach (BasicDataModel drXZQ in dtXZQ2)
{
DataRow[] drc = dt.Select(string.Format("XZQDM = '{0}'", drXZQ.Code));
if (drc.Length > 0)
continue;
DataRow dr = dt.NewRow();
foreach (DataColumn dc in dt.Columns)
{
if (dc.ColumnName.ToUpper() == "XZQMC")
{
dr["XZQMC"] = drXZQ.Name;// drXZQ["XZQMC"];
}
else if (dc.ColumnName.ToUpper() == "XZQDM")
{
dr["XZQDM"] = drXZQ.Code;// drXZQ["XZQDM"];
}
else if (dc.DataType != typeof(string))
{
if (dc.DataType == typeof(double))
{
dr[dc.ColumnName] = 0D;
}
else if (dc.DataType == typeof(decimal))
{
dr[dc.ColumnName] = decimal.Zero;
}
else if (dc.DataType == typeof(int))
{
dr[dc.ColumnName] = 0;
}
}
}
dt.Rows.Add(dr);
}
foreach (BasicDataModel bdm in TownList)
{
DataRow[] drc = dt.Select(string.Format("XZQDM = '{0}'", bdm.Code));
if (drc.Length > 0)
continue;
DataRow dr = dt.NewRow();
foreach (DataColumn dc in dt.Columns)
{
if (dc.ColumnName.ToUpper() == "XZQMC")
{
dr["XZQMC"] = bdm.Name;
}
else if (dc.ColumnName.ToUpper() == "XZQDM")
{
dr["XZQDM"] = bdm.Code;
}
else
{
if (dc.DataType == typeof(double))
{
dr[dc.ColumnName] = 0D;
}
else if (dc.DataType == typeof(decimal))
{
dr[dc.ColumnName] = decimal.Zero;
}
else if (dc.DataType == typeof(int))
{
dr[dc.ColumnName] = 0;
}
}
}
dt.Rows.Add(dr);
}
foreach (BasicDataModel bdm in CountyList)
{
DataRow[] drc = dt.Select(string.Format("XZQDM = '{0}'", bdm.Code));
if (drc.Length > 0)
continue;
DataRow dr = dt.NewRow();
foreach (DataColumn dc in dt.Columns)
{
if (dc.ColumnName.ToUpper() == "XZQMC")
{
dr["XZQMC"] = bdm.Name;
}
else if (dc.ColumnName.ToUpper() == "XZQDM")
{
dr["XZQDM"] = bdm.Code;
}
else
{
if (dc.DataType == typeof(double))
{
dr[dc.ColumnName] = 0D;
}
else if (dc.DataType == typeof(decimal))
{
dr[dc.ColumnName] = decimal.Zero;
}
else if (dc.DataType == typeof(int))
{
dr[dc.ColumnName] = 0;
}
}
}
dt.Rows.Add(dr);
}
}
bool IsFRD = false;
if (templatePath.Contains("飞入地"))
{
IsFRD = true;
}
if (!IsFRD)
{
if (dt.Rows.Count > 0)
{
dt = dt.Select(null, "XZQDM ASC").CopyToDataTable();
}
}
sheet.Cells.InsertRows(startRowIndex, dt.Rows.Count);
Aspose.Cells.Row startRow = sheet.Cells.Rows[startRowIndex];
int BlankRowCount = 0;
//行循环
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
string strXZQDM = ObjectToString(dr["XZQDM"]);
//各乡镇之间空一行
if (IsFRD)
{
if (i > 0)
{
string strPrevXZQDM = dt.Rows[i - 1]["XZQDM"].ToString();
if (strPrevXZQDM.Length != strXZQDM.Length)
{
sheet.Cells.InsertRows(i + startRowIndex + BlankRowCount, 1);
BlankRowCount++;
}
}
}
else
{
if (strXZQDM.Length == 9)
{
sheet.Cells.InsertRows(i + startRowIndex + BlankRowCount, 1);
BlankRowCount++;
}
}
//列循环
for (int j = 0; j < dt.Columns.Count; j++)
{
//获取要赋值的单元格Cell
Cell cell = sheet.Cells[i + startRowIndex + BlankRowCount, j];
//根据数据源字段类型设置单元格格式,如果是Double或Decimal类型则设置为保留两位小数
DataColumn dc = dt.Columns[j];
if (dc.DataType == typeof(double) || dc.DataType == typeof(decimal))
{
Style CellStyle = cell.GetStyle();
CellStyle.Number = 2;
cell.SetStyle(CellStyle);
}
if (!string.IsNullOrWhiteSpace(cell.Formula))
continue;
object objValue = dr[j];
//Bug-14569 霍岩 添加Decimal类型,当列为Decimal类型时乘以单位换算系数
if (dt.Columns[j].DataType.Name == typeof(double).Name || dt.Columns[j].DataType.Name == typeof(decimal).Name)
{
if (!string.IsNullOrEmpty(dr[j].ToTrim()))
{
cell.PutValue(Math.Round(ObjectToDouble(objValue), 2) * MjConvertValue);
}
}
else
{
cell.PutValue(ObjectToString(objValue));
}
}
}
//根据单位修改单位Cell文本
if (mjconvertvalue2 != "0.0001")
{
string strUnitText = null;
int MaxRow = 10;
for (int i = 0; i < sheet.Cells.Rows.Count; i++)
{
if (i == MaxRow)
break;
bool IsBreak = false;
for (int j = 0; j < sheet.Cells.Columns.Count; j++)
{
Cell cell = sheet.Cells[i, j];
if (cell.StringValue.Contains("单位"))
{
switch (mjconvertvalue2)
{
case "0.0015":
strUnitText = cell.StringValue.Replace("公顷", "亩");
cell.PutValue(strUnitText);
break;
case "1":
strUnitText = cell.StringValue.Replace("公顷", "平方米");
cell.PutValue(strUnitText);
break;
default:
break;
}
IsBreak = true;
break;
}
}
if (IsBreak)
break;
}
}
workbook.Save(savePath);
}
#endregion
///
/// 面积单位转换值公顷为1,亩为15,默认公顷
///
public int MjConvertValue { get; set; } = 1;
private ReportFileTypeEnum reportFileType;
///
/// 统计表导出格式类型
///
public ReportFileTypeEnum ReportFileType
{
get { return reportFileType; }
set
{
reportFileType = value;
if (reportFileType == ReportFileTypeEnum.DBMETERS)
{
reporttablename = "MJHZJCTJB2";
mjconvertvalue2 = "1";
}
else if (reportFileType == ReportFileTypeEnum.DBM)
{
reporttablename = "MJHZJCTJB";
mjconvertvalue2 = "0.0015";
}
else
{
reporttablename = "MJHZJCTJB";
mjconvertvalue2 = "0.0001";
}
}
}
private string reporttablename;
///
/// 导出表名(公顷和亩MJHZJCTJB,平方米用 MJHZJCTJB2)
///
public string ReportTableName
{
get
{
if (string.IsNullOrWhiteSpace(reporttablename))
{
reporttablename = "MJHZJCTJB";
}
return reporttablename;
}
set { reporttablename = value; }
}
private string mjconvertvalue2;
private string ObjectToString(object obj)
{
if (obj == null) return "";
return obj.ToString();
}
public double ObjectToDouble(object obj)
{
double rst = 0.0;
if (obj != null)
double.TryParse(obj.ToString(), out rst);
return rst;
}
#region 2017-12-27导出方法
///
/// 移除数据,非当前行政区的,或者行政区代码为空的(主要用途,当选择某一个村的时候,过滤掉其他的数据)
///
///
///
///
public void RemoveDRByXZQDM(IRDBHelper dbHelper, XZQTreeNode xzq, ref DataTable dt)
{
if (xzq != null && dt != null && dt.Rows.Count > 0 && xzq.XZQDM.Length > 6)
{
//移除错误的数据,非当前行政区的,或者行政区代码为空的
DataRow[] s = dt.Select("XZQDM not like '" + xzq.XZQDM + "%' or XZQDM is null");
if (s != null && s.Length > 0)
{
for (int j = 0; j < s.Length; j++)
{
dt.Rows.Remove(s[j]);
}
}
}
//DataTable xzqdt = dbHelper.ExecuteDatatable("statisticType", "select left(zldwdm,12) as zldwdm,zldwmc,left(qsdwdm,12) as qsdwdm,qsdwmc from dltb group by left(zldwdm,12),zldwmc,left(qsdwdm,12),qsdwmc", true);
//if ((xzq != null || (xzqdt != null && xzqdt.Rows.Count > 0)) && dt != null && dt.Rows.Count > 0)
//{
// for (int i = 0; i < dt.Rows.Count; i++)
// {
// string strXZQMC = GetXZQMCByXZQDM(xzqdt, xzq, dt.Rows[i]["XZQDM"].ToTrim());
// dt.Rows[i]["XZQMC"] = strXZQMC;
// //if (dt.Columns.Contains("QSXZQMC") && dt.Columns.Contains("QSXZQDM"))
// //{
// // dt.Rows[i]["QSXZQMC"] = GetXZQMCByXZQDM(xzqdt, xzq, dt.Rows[i]["QSXZQDM"].ToTrim());
// //}
// }
//}
}
///
/// 移除数据,非当前行政区的,或者行政区代码为空的(主要用途,当选择某一个村的时候,过滤掉其他的数据)
///
///
///
///
/// 重载方法 王欢 2018-09-29
public void RemoveDRByXZQDM(IRDBHelper dbHelper, System.Collections.Hashtable selectht, ref DataTable dt)
{
if (selectht != null)
{
//***************************************************
//BUG12717 郑英杰 2018-10-11
//***************************************************
if (dt != null)//非空控制 dt.Select 王欢 2012-12-11
{
//foreach (var item in selectht.Keys)
//{
// string sb = string.Format("XZQDM not like '{0}%' or XZQDM is null", item);
// DataRow[] s = dt.Select(sb);
// if (s != null && s.Length > 0)
// {
// for (int i = 0; i < s.Length; i++)
// {
// dt.Rows.Remove(s[i]);
// }
// }
//}
StringBuilder sb = new StringBuilder();
foreach (var item in selectht.Keys)
{
sb.Append(" XZQDM not like '" + item + "%' and");
}
if (sb.Length != 0)
{
sb.Remove(sb.Length - 4, 4);
sb.Append(" or XZQDM is null");
//移除错误的数据,非当前行政区的,或者行政区代码为空的
DataRow[] s = dt.Select(sb.ToString());
if (s != null && s.Length > 0)
{
for (int j = 0; j < s.Length; j++)
{
dt.Rows.Remove(s[j]);
}
}
}
}
}
DataTable xzqdt = dbHelper.ExecuteDatatable("statisticType", "select left(zldwdm,12) as zldwdm,zldwmc,left(qsdwdm,12) as qsdwdm,qsdwmc from dltb group by left(zldwdm,12),zldwmc,left(qsdwdm,12),qsdwmc", true);
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
dt.Rows[i]["XZQMC"] = GetXZQMCByXZQDM(xzqdt, selectht, dt.Rows[i]["XZQDM"].ToTrim());
if (dt.Columns.Contains("QSXZQMC") && dt.Columns.Contains("QSXZQDM"))
{
dt.Rows[i]["QSXZQMC"] = GetXZQMCByXZQDM(xzqdt, selectht, dt.Rows[i]["QSXZQDM"].ToTrim());
}
}
}
}
public string GetXZQMCByXZQDM(DataTable xzqdt, System.Collections.Hashtable selectht, string xzqdm)
{
string result = string.Empty;
try
{
if (selectht != null)
{
foreach (System.Collections.DictionaryEntry item in selectht)
{
if (item.Key.ToString() == xzqdm && item.Value != null)
{
result = item.Value.ToString();
break;
}
}
}
if (string.IsNullOrEmpty(result) && xzqdt != null && xzqdt.Rows.Count > 0)
{
DataRow[] s = xzqdt.Select("ZLDWDM='" + xzqdm + "'");
if (s != null && s.Length > 0)
{
result = s[0]["ZLDWMC"].ToTrim();
}
else
{
s = xzqdt.Select("QSDWDM='" + xzqdm + "'");
if (s != null && s.Length > 0)
{
result = s[0]["QSDWMC"].ToTrim();
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
return result;
}
public string GetTPath()
{
//白明雅 2018-12-24 AppDomain.CurrentDomain.BaseDirectory获取到的路径结尾已经存在“\\”
//return AppDomain.CurrentDomain.BaseDirectory + "\\TempalateReports\\DBGQ\\";
return AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\DBGQ\\";
}
public string GetZLPath()
{
return AppDomain.CurrentDomain.BaseDirectory + "\\TempalateReports\\DBZL\\";
}
///
/// 清除---1土地利用现状一级分类面积汇总表
///
///
/// sql条件
///
public void ClaerNullByDT1(IRDBHelper dbHelper, string sqlwhere, ref DataTable dt)
{
if (dt != null && dt.Rows.Count > 0)
{
DataTable mjhztjb2 = dbHelper.ExecuteDatatable("tempdt", "select ZLDWDM,DLBM,sum(kcmj) as KCMJ from mjhztjb2 " + sqlwhere + " group by zldwdm,dlbm", true);
if (mjhztjb2 == null || mjhztjb2.Rows.Count == 0)
{
return;
}
mjhztjb2.PrimaryKey = new DataColumn[] { mjhztjb2.Columns["ZLDWDM"], mjhztjb2.Columns["DLBM"] };
for (int i = 0; i < dt.Rows.Count; i++)
{
string XZQDM = dt.Rows[i]["XZQDM"].ToTrim();
if (string.IsNullOrWhiteSpace(XZQDM))
{
continue;
}
foreach (DataColumn item in dt.Columns)
{
if (item.ColumnName.IndexOf("D") == 0)
{
if (dt.Rows[i][item.ColumnName].ToTrim() == "0")
{
string c = item.ColumnName.Substring(1);
DataRow[] findrows = mjhztjb2.Select(string.Format("ZLDWDM like '{0}%' and DLBM like '{1}%'", XZQDM, c));
if (findrows == null || findrows.Length == 0)
{
if (c == "1203")
{
var kcmj = mjhztjb2.Select(string.Format("ZLDWDM like '{0}%'", XZQDM)).Sum(rows => rows.Field("KCMJ"));
if (kcmj > 0)
{
continue;
}
}
dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
}
}
}
}
}
}
}
///
/// 获取土地利用现状一级分类or二级分类,类名集合
///
///
/// 是否获取二级分类,默认false
///
private string GetTDLYXZYJFLOrEJFLColunms(IRDBHelper dbHelper, string TableName = "MJHZJCTJB")
{
DataTable mjhzdt = dbHelper.ExecuteDatatable("hztjb", "select * from " + TableName + " where 1=2", true);
string resultylstr = string.Empty;
#region 计算地类编码集合
foreach (DataColumn item in mjhzdt.Columns)
{
if (item.ColumnName.IndexOf("D") == 0 && item.ColumnName.Length >= 3)
{
resultylstr = resultylstr + string.Format(" ,sum({0}) as {0} ", item.ColumnName);
}
}
#endregion
return resultylstr;
}
#endregion
#region 4城镇村及工矿用地面积汇总表
///
/// 4城镇村及工矿用地面积汇总表
///
///
///
///
///
public bool ExportReportCZCJGKYDMJHZB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetCZCJGKYDMJHZBData(dbHelper);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT3(dbHelper, "", ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 6, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 飞入地——4城镇村及工矿用地面积汇总表
///
///
///
///
///
public bool ExportReportCZCJGKYDMJHZB_FRD(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetCZCJGKYDMJHZBFRDData(dbHelper, true, 6);
rest.Merge(GetCZCJGKYDMJHZBFRDData(dbHelper, true, 9), true, MissingSchemaAction.Ignore);
rest.Merge(GetCZCJGKYDMJHZBFRDData(dbHelper, true, 12), true, MissingSchemaAction.Ignore);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT3(dbHelper, " and FRDBS='1'", ref rest);
GetXZQMC(dbHelper, ref rest);
rest.Columns.Add("rowId", typeof(int));
rest.Columns["rowId"].SetOrdinal(0);
for (int i = 0; i < rest.Rows.Count; i++)
{
DataRow dr = rest.Rows[i];
dr.BeginEdit();
dr["rowId"] = i + 1;
dr.EndEdit();
}
OutExcel2(rest, savePath, reportTempaltePath, null, null, 6, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 4城镇村及工矿用地面积汇总表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportCZCJGKYDMJHZB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetCZCJGKYDMJHZBData(dbHelper);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT3(dbHelper, "", ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 6);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 飞入地——4城镇村及工矿用地面积汇总表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportCZCJGKYDMJHZB_FRD(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetCZCJGKYDMJHZBFRDData(dbHelper, true, 6);
rest.Merge(GetCZCJGKYDMJHZBFRDData(dbHelper, true, 9), true, MissingSchemaAction.Ignore);
rest.Merge(GetCZCJGKYDMJHZBFRDData(dbHelper, true, 12), true, MissingSchemaAction.Ignore);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT3(dbHelper, " and FRDBS='1'", ref rest);
GetXZQMC(dbHelper, ref rest);
rest.Columns.Add("rowId", typeof(int));
rest.Columns["rowId"].SetOrdinal(0);
for (int i = 0; i < rest.Rows.Count; i++)
{
DataRow dr = rest.Rows[i];
dr.BeginEdit();
dr["rowId"] = i + 1;
dr.EndEdit();
}
OutExcel2(rest, savePath, reportTempaltePath, null, null, 6);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
private DataTable GetCZCJGKYDMJHZBFRDData(IRDBHelper dbHelper, bool isFRD = true, int DWJB = 12)
{
//Bug-13545 霍岩 2018-12-10 报表数据源重复数据修正
string[] czcarry = new string[] { "C201", "C202", "C203", "C204", "C205" };
List columnlist;
List dlbmlist;
List ejdllist;
DataTable result = GetCZCJGKYDMJHZBDT(dbHelper, czcarry, out columnlist, out dlbmlist, out ejdllist, isFRD);
//分别查询出县、镇、村个数代码
string lyxzyjflcolumnstr = GetTDLYXZYJFLOrEJFLColunms(dbHelper, ReportTableName);
string xzqdmdt = @"select substr(ZLDWDM,1,{0}) AS XZQDM, substr(QSDWDM,1,{0}) AS QSXZQDM from " + ReportTableName + " WHERE FRDBS='1' and CZCSXM LIKE '20%' and substr(ZLDWDM,1,{0}) <> substr(QSDWDM,1,{0}) group by substr(ZLDWDM,1,{0}),substr(QSDWDM,1,{0}) ORDER BY substr(ZLDWDM,1,{0}),substr(QSDWDM,1,{0})";
string sumSql = @"select substr(zldwdm,1,{1}) as XZQDM, substr(QSDWDM,1, {1}) AS QSXZQDM, substr(CZCSXM,1,3) AS CZCSXM, sum(TBZMJ) as XZQYZMJ {0} from " + ReportTableName + " where FRDBS='1' and CZCSXM LIKE '20%' and substr(ZLDWDM,1,{1}) <> substr(QSDWDM,1,{1}) group by substr(zldwdm,1,{1}),substr(QSDWDM,1,{1}),substr(CZCSXM,1,3)";
//if (DWJB > 6)
//{
// xzqdmdt = @"select LEFT(ZLDWDM,{0}) AS XZQDM, LEFT(QSDWDM,{0}) AS QSXZQDM from " + ReportTableName + " WHERE FRDBS='1' and CZCSXM LIKE '20%' and LEFT(ZLDWDM,{0}) <> LEFT(QSDWDM,{0}) and LEFT(ZLDWDM,{0} - 3) = LEFT(QSDWDM, {0} - 3) group by LEFT(ZLDWDM,{0}),LEFT(QSDWDM,{0}) ORDER BY LEFT(ZLDWDM,{0}),LEFT(QSDWDM,{0})";
//}
DataTable xjdmdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, DWJB), true);
//if (xjdmdtRst == null || xjdmdtRst.Rows.Count == 0)
//{
// return xjdmdtRst;
//}
//if (DWJB > 6)
//{
// sumSql = @"select left(zldwdm,{1}) as XZQDM, LEFT(QSDWDM, {1}) AS QSXZQDM, LEFT(CZCSXM,3) AS CZCSXM, sum(TBZMJ) as XZQYZMJ {0} from " + ReportTableName + " where FRDBS='1' and CZCSXM LIKE '20%' and LEFT(ZLDWDM,{1}) <> LEFT(QSDWDM,{1}) and LEFT(ZLDWDM,{1} - 3) = LEFT(QSDWDM,{1} - 3) group by left(zldwdm,{1}),LEFT(QSDWDM,{1}),LEFT(CZCSXM,3)";
//}
DataTable xjdtRst3 = dbHelper.ExecuteDatatable("statisticType", string.Format(sumSql, lyxzyjflcolumnstr, DWJB), true);
//if (xjdtRst3 == null || xjdtRst3.Rows.Count == 0)
//{
// return xjdmdtRst;
//}
for (int i = 0; i < xjdmdtRst.Rows.Count; i++)
{
DataRow dr = result.NewRow();
dr["XZQDM"] = xjdmdtRst.Rows[i]["XZQDM"];
dr["XZQMC"] = "";
dr["QSXZQDM"] = xjdmdtRst.Rows[i]["QSXZQDM"];
dr["QSXZQMC"] = "";
foreach (var citem in czcarry)
{
DataRow[] s = xjdtRst3.Select(string.Format(" XZQDM='{0}' and QSXZQDM LIKE '" + xjdmdtRst.Rows[i]["QSXZQDM"] + "%' and CZCSXM LIKE'{1}%' ", xjdmdtRst.Rows[i]["XZQDM"], citem.Substring(1, 3)));
var querycolumnlist = columnlist.Where(x => x.IndexOf(citem) == 0);
foreach (var citem2 in querycolumnlist)
{
if (s != null && s.Length > 0)
{
string dlbmstr = citem2.Substring(4);
if (!char.IsNumber(dlbmstr, dlbmstr.Length - 1))
{
continue;
}
string strSum = null;
var dlbmstrs = querycolumnlist.Where(x => x.Contains(dlbmstr));
List list = dlbmstrs.ToList();
if (s.Length == 1)
{
if (result.Columns.Contains(citem2))
{
dr[citem2] = s[0][list[0].Substring(4)];
for (int j = 1; j < list.Count; j++)
{
double dbl1 = 0D;
double dbl2 = 0D;
double.TryParse(dr[citem2].ToString(), out dbl1);
double.TryParse(s[0][list[j].Substring(4)].ToString(), out dbl2);
dr[citem2] = dbl1 + dbl2;
}
}
}
else
{
strSum = string.Format("SUM({0})", list[0].Substring(4));
for (int j = 1; j < list.Count; j++)
{
strSum = string.Format("{0} + SUM({1})", strSum, list[j].Substring(4));
}
dr[citem2] = s.CopyToDataTable().Compute(strSum, null);
}
}
else
{
if (result.Columns.Contains(citem2))
dr[citem2] = 0;
}
}
}
SetDrHZValue(czcarry, dlbmlist, dr, result);
result.Rows.Add(dr);
}
return result;
}
///
/// 4城镇村及工矿用地面积汇总表
///
///
/// 霍岩 2018-11-29 修改
private DataTable GetCZCJGKYDMJHZBData(IRDBHelper dbHelper, bool isfrd = false)
{
string[] czcarry = new string[] { "C201", "C202", "C203", "C204", "C205" };
List columnlist;
List dlbmlist;
List ejdllist;
DataTable result = GetCZCJGKYDMJHZBDT(dbHelper, czcarry, out columnlist, out dlbmlist, out ejdllist, isfrd);
//分别查询出县、镇、村个数代码
string lyxzyjflcolumnstr = GetTDLYXZYJFLOrEJFLColunms(dbHelper, ReportTableName);
DataTable xjdmdtRst = null;
DataTable xjdmdtRst2 = null;
DataTable xjdmdtRst3 = null;
DataTable xjdtRst3 = null;
//string xzqdmdt = @"select LEFT(ZLDWDM,{0}) AS XZQDM from " + ReportTableName + " WHERE CZCSXM LIKE '20%' group by LEFT(ZLDWDM,{0}) ORDER BY LEFT(ZLDWDM,{0})";
string xzqdmdt = @"select substr(ZLDWDM,1,{0}) AS XZQDM from " + ReportTableName + " WHERE CZCSXM LIKE '20%' group by substr(ZLDWDM,1,{0}) ORDER BY substr(ZLDWDM,1,{0})";
//string sumSql = @"select left(zldwdm,12) as XZQDM, LEFT(CZCSXM,3) AS CZCSXM, sum(TBZMJ) as XZQYZMJ {0} from " + ReportTableName + " where CZCSXM LIKE '20%' group by left(zldwdm,12),LEFT(CZCSXM,3)";
string sumSql = @"select substr(zldwdm,1,12) as XZQDM, substr(CZCSXM,1,3) AS CZCSXM, sum(TBZMJ) as XZQYZMJ {0} from " + ReportTableName + " where CZCSXM LIKE '20%' group by substr(zldwdm,1,12),substr(CZCSXM,1,3)";
xjdmdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 6), true);
if (xjdmdtRst == null || xjdmdtRst.Rows.Count == 0)
{
return xjdmdtRst;
}
xjdmdtRst2 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 9), true);
xjdmdtRst3 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 12), true);
xjdtRst3 = dbHelper.ExecuteDatatable("statisticType", string.Format(sumSql, lyxzyjflcolumnstr), true);
if (xjdtRst3 == null || xjdtRst3.Rows.Count == 0)
{
return xjdmdtRst;
}
//计算出多少个县
for (int i = 0; i < xjdmdtRst.Rows.Count; i++)
{
#region 添加县
DataRow xjdr = result.NewRow();
xjdr["XZQDM"] = xjdmdtRst.Rows[i]["XZQDM"];
xjdr["XZQMC"] = "";
foreach (var citem in columnlist)
{
if (result.Columns.Contains(citem))
xjdr[citem] = 0;
}
result.Rows.Add(xjdr);
#endregion
DataRow[] zjdmdtRst = xjdmdtRst2.Select(" XZQDM like '" + xjdmdtRst.Rows[i]["XZQDM"] + "%'");
for (int z = 0; z < zjdmdtRst.Length; z++)
{
#region 添加镇
DataRow zjdr = result.NewRow();
zjdr["XZQDM"] = zjdmdtRst[z]["XZQDM"];
zjdr["XZQMC"] = "";
foreach (var citem in columnlist)
{
if (result.Columns.Contains(citem))
zjdr[citem] = 0;
}
result.Rows.Add(zjdr);
#endregion
DataRow[] cjdmdtRst = xjdmdtRst3.Select(" XZQDM like '" + zjdmdtRst[z]["XZQDM"] + "%' ");
for (int c = 0; c < cjdmdtRst.Length; c++)
{
#region 添加村
DataRow cjdr = result.NewRow();
cjdr["XZQDM"] = cjdmdtRst[c]["XZQDM"];
cjdr["XZQMC"] = "";
foreach (var citem in czcarry)
{
DataRow[] s = xjdtRst3.Select(string.Format(" XZQDM='{0}' and CZCSXM LIKE'{1}%' ", cjdmdtRst[c]["XZQDM"], citem.Substring(1, 3)));
var querycolumnlist = columnlist.Where(x => x.IndexOf(citem) == 0);
foreach (var citem2 in querycolumnlist)
{
if (s != null && s.Length > 0)
{
string dlbmstr = citem2.Substring(4);
if (!char.IsNumber(dlbmstr, dlbmstr.Length - 1))
{
continue;
}
string strSum = null;
var dlbmstrs = querycolumnlist.Where(x => x.Contains(dlbmstr));
List list = dlbmstrs.ToList();
if (s.Length == 1)
{
if (result.Columns.Contains(citem2))
{
cjdr[citem2] = s[0][list[0].Substring(4)];
for (int j = 1; j < list.Count; j++)
{
double dbl1 = 0D;
double dbl2 = 0D;
double.TryParse(cjdr[citem2].ToString(), out dbl1);
double.TryParse(s[0][list[j].Substring(4)].ToString(), out dbl2);
cjdr[citem2] = dbl1 + dbl2;
}
}
}
else
{
strSum = string.Format("SUM({0})", list[0].Substring(4));
for (int j = 1; j < list.Count; j++)
{
strSum = string.Format("{0} + SUM({1})", strSum, list[j].Substring(4));
}
cjdr[citem2] = s.CopyToDataTable().Compute(strSum, null);
}
}
else
{
if (result.Columns.Contains(citem2))
cjdr[citem2] = 0;
}
if (result.Columns.Contains(citem2))
zjdr[citem2] = zjdr[citem2].ToDecimal(2) + cjdr[citem2].ToDecimal(2);
}
}
SetDrHZValue(czcarry, dlbmlist, cjdr, result);
result.Rows.Add(cjdr);
#endregion
}
#region 设置镇合计值
foreach (var citem in columnlist)
{
if (result.Columns.Contains(citem))
xjdr[citem] = xjdr[citem].ToDecimal(2) + zjdr[citem].ToDecimal(2);
}
SetDrHZValue(czcarry, dlbmlist, zjdr, result);
#endregion
}
#region 设置县合计值
SetDrHZValue(czcarry, dlbmlist, xjdr, result);
#endregion
}
return result;
}
///
/// 设置汇总合计值
///
///
///
///
private void SetDrHZValue(string[] czcarry, List dlbmlist, DataRow xjdr, DataTable table)
{
//第一步:计算201、202等的二级类到一级类汇总
foreach (var czcitem in czcarry)
{
//if (czcitem == "C204")
// continue;
foreach (var yjitem in dlbmlist)
{
if (yjitem.EJDLList != null && yjitem.EJDLList.Count > 0)
{
decimal yjdlmj = 0;
foreach (var ejitem in yjitem.EJDLList)
{
if (table.Columns.Contains(czcitem + "D" + ejitem))
yjdlmj = yjdlmj + xjdr[czcitem + "D" + ejitem].ToDecimal(2);
}
if (table.Columns.Contains(czcitem + "D" + yjitem.YJDL))
xjdr[czcitem + "D" + yjitem.YJDL] = yjdlmj;
}
}
}
string czcitem2 = "C20";
//第二步:计算20的二级类汇总
foreach (var yjitem in dlbmlist)
{
if (yjitem.EJDLList != null && yjitem.EJDLList.Count > 0)
{
foreach (var ejitem in yjitem.EJDLList)
{
decimal tdlmj = 0;
foreach (var czcitem in czcarry)
{
//if (czcitem == "C204")
// continue;
if (table.Columns.Contains(czcitem + "D" + ejitem))
tdlmj = tdlmj + xjdr[czcitem + "D" + ejitem].ToDecimal(2);
}
if (table.Columns.Contains(czcitem2 + "D" + ejitem))
xjdr[czcitem2 + "D" + ejitem] = tdlmj;
}
}
else
{
decimal tdlmj = 0;
foreach (var czcitem in czcarry)
{
//if (czcitem == "C204")
// continue;
if (table.Columns.Contains(czcitem + "D" + yjitem.YJDL))
tdlmj = tdlmj + xjdr[czcitem + "D" + yjitem.YJDL].ToDecimal(2);
}
if (table.Columns.Contains(czcitem2 + "D" + yjitem.YJDL))
xjdr[czcitem2 + "D" + yjitem.YJDL] = tdlmj;
}
}
//第三步:计算20的二级类到一级类汇总
foreach (var yjitem in dlbmlist)
{
if (yjitem.EJDLList != null && yjitem.EJDLList.Count > 0)
{
decimal yjdlmj = 0;
foreach (var ejitem in yjitem.EJDLList)
{
if (table.Columns.Contains(czcitem2 + "D" + ejitem))
yjdlmj = yjdlmj + xjdr[czcitem2 + "D" + ejitem].ToDecimal(2);
}
if (table.Columns.Contains(czcitem2 + "D" + yjitem.YJDL))
xjdr[czcitem2 + "D" + yjitem.YJDL] = yjdlmj;
}
}
//第四步:计算汇总合计
decimal hj = 0;
foreach (var yjitem in dlbmlist)
{
if (table.Columns.Contains(czcitem2 + "D" + yjitem.YJDL))
hj = hj + xjdr[czcitem2 + "D" + yjitem.YJDL].ToDecimal(2);
}
xjdr["C20HJ"] = hj;
foreach (var item in czcarry)
{
//if (item == "C204")
// continue;
hj = 0;
foreach (var yjitem in dlbmlist)
{
if (table.Columns.Contains(item + "D" + yjitem.YJDL))
hj = hj + xjdr[item + "D" + yjitem.YJDL].ToDecimal(2);
}
if (table.Columns.Contains(item + "HJ"))
xjdr[item + "HJ"] = hj;
}
}
///
/// 获取城镇村及工矿用地表结构
///
///
///
private DataTable GetCZCJGKYDMJHZBDT(IRDBHelper dbHelper, string[] czcarry, out List columnlist, out List dlbmlist, out List ejdllist, bool IsFRD = false)
{
try
{
columnlist = new List();
DataTable mjhzdt = dbHelper.ExecuteDatatable("hztjb", "select * from " + ReportTableName + " where 1=2", true);
DataTable result = new DataTable();
result.Columns.Add(new DataColumn("XZQMC", typeof(string)));
result.Columns.Add(new DataColumn("XZQDM", typeof(string)));
if (IsFRD)
{
result.Columns.Add(new DataColumn("QSXZQMC", typeof(string)));
result.Columns.Add(new DataColumn("QSXZQDM", typeof(string)));
}
result.Columns.Add(new DataColumn("C20HJ", typeof(double)));
#region 计算地类编码集合
MJHZJCTJBHelper mh = new MJHZJCTJBHelper();
mh.GetDLBMListByDT(mjhzdt, out dlbmlist, out ejdllist);
//C20开头
foreach (var yjitem in dlbmlist)
{
result.Columns.Add(new DataColumn("C20D" + yjitem.YJDL, typeof(double)));
if (yjitem.EJDLList != null && yjitem.EJDLList.Count > 0)
{
foreach (var ejitem in yjitem.EJDLList)
{
if (char.IsNumber(ejitem, ejitem.Length - 1))
{
result.Columns.Add(new DataColumn("C20D" + ejitem, typeof(double)));
}
columnlist.Add("C20D" + ejitem);
}
}
}
//C201 ~ C205开头
foreach (string item in czcarry)
{
//if (item == "C201" || item == "C202" || item == "C203")
//{
//}
result.Columns.Add(new DataColumn(item + "HJ", typeof(double)));
foreach (var yjitem in dlbmlist)
{
result.Columns.Add(new DataColumn(item + "D" + yjitem.YJDL, typeof(double)));
if (yjitem.EJDLList != null && yjitem.EJDLList.Count > 0)
{
foreach (var ejitem in yjitem.EJDLList)
{
columnlist.Add(item + "D" + ejitem);
if (char.IsNumber(ejitem, ejitem.Length - 1))
result.Columns.Add(new DataColumn(item + "D" + ejitem, typeof(double)));
}
}
else
{
columnlist.Add(item + "D" + yjitem.YJDL);
}
}
}
//result.Columns.Add(new DataColumn("C204HJ", typeof(double)));
//result.Columns.Add(new DataColumn("C204D0602", typeof(double)));
//result.Columns.Add(new DataColumn("C204D0603", typeof(double)));
//result.Columns.Add(new DataColumn("C204D1201", typeof(double)));
//result.Columns["C204HJ"].Expression = "C204D0602 + C204D0603 + C204D1201";
//columnlist.Add("C204D0602");
//columnlist.Add("C204D0603");
//columnlist.Add("C204D1201");
//result.Columns.Add(new DataColumn("C205D09", typeof(double)));
//columnlist.Add("C205D09");
#endregion
return result;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw;
}
}
///
/// 清除---4城镇村及工矿用地面积汇总表
///
///
/// sql条件
///
public void ClaerNullByDT3(IRDBHelper dbHelper, string sqlwhere, ref DataTable dt)
{
if (dt != null && dt.Rows.Count > 0)
{
DataTable mjhztjb2 = dbHelper.ExecuteDatatable("tempdt", "select ZLDWDM,DLBM,CZCSXM,sum(kcmj) as KCMJ from mjhztjb2 where CZCSXM LIKE '20%' " + sqlwhere + " group by zldwdm,dlbm,CZCSXM", true);
if (mjhztjb2 == null || mjhztjb2.Rows.Count == 0)
{
return;
}
mjhztjb2.PrimaryKey = new DataColumn[] { mjhztjb2.Columns["ZLDWDM"], mjhztjb2.Columns["DLBM"], mjhztjb2.Columns["CZCSXM"] };
for (int i = 0; i < dt.Rows.Count; i++)
{
string XZQDM = dt.Rows[i]["XZQDM"].ToTrim();
if (string.IsNullOrWhiteSpace(XZQDM))
{
continue;
}
foreach (DataColumn item in dt.Columns)
{
if (!string.IsNullOrWhiteSpace(item.Expression))
continue;
if (item.ColumnName.IndexOf("C") == 0)
{
if (dt.Rows[i][item.ColumnName].ToTrim() == "0")
{
string temp1 = item.ColumnName.Substring(1);
string czcsxm = string.Empty;
string dlbm = string.Empty;
string selectwhere = string.Empty;
if (temp1.IndexOf("D") > 0)
{
czcsxm = temp1.Substring(0, temp1.IndexOf("D"));
dlbm = temp1.Substring(temp1.IndexOf("D") + 1);
selectwhere = string.Format("ZLDWDM like '{0}%' and CZCSXM like '{1}%' and DLBM like '{2}%'", XZQDM, czcsxm, dlbm);
}
else if (temp1.IndexOf("H") > 0)//必须要把H,放在后面
{
czcsxm = temp1.Substring(0, temp1.IndexOf("H"));
selectwhere = string.Format("ZLDWDM like '{0}%' and CZCSXM like '{1}%'", XZQDM, czcsxm);
}
else
{
continue;
}
//DataRow[] findrows = mjhztjb2.Select(selectwhere);
//if (findrows == null || findrows.Length == 0)
//{
//if (!string.IsNullOrEmpty(dlbm) && dlbm == "1203")
//{
//var kcmj = mjhztjb2.Select(string.Format("ZLDWDM like '{0}%' and CZCSXM like '{1}%'", XZQDM, czcsxm)).Sum(rows => rows.Field("KCMJ"));
//if (kcmj > 0)
//{
// continue;
//}
//}
//dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
//}
}
}
}
}
}
}
#endregion
#region 5耕地坡度分级面积汇总表
///
/// 5耕地坡度分级面积汇总表
///
///
///
///
///
public bool ExportReportGDPDFJMJHZB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetGDPDFJMJHZBData(dbHelper);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT4(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 6, 1, 16);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 6, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 5耕地坡度分级面积汇总表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportGDPDFJMJHZB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetGDPDFJMJHZBData(dbHelper);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT4(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 6, 1, 16);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 6);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 5耕地坡度分级面积汇总表(空表)
///
///
///
///
/// 王欢 2018-12-07
public bool ExportReportGDPDFJMJHZBNULL(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
//权属单位代码表 文件命名有问题 为满足需求暂定是现在
//if (selectht != null)
//{
// foreach (var item in selectht.Keys)
// {
string reportTempaltePath = GetZLPath() + reportEntity.TempalateFileName + ".xlsx";
string newPath = System.IO.Path.GetDirectoryName(savePath);// + selectht[item].ToString();
string newFile = "(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")" + System.IO.Path.GetFileName(savePath);// item.ToString().Substring(6) + System.IO.Path.GetFileName(savePath);
if (!System.IO.Directory.Exists(newPath))
{
System.IO.Directory.CreateDirectory(newPath);
}
string newsavePath = newPath + "\\" + newFile;
OutExcel(null, newsavePath, reportTempaltePath, 7, 1, 2);
// }
//}
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 5耕地坡度分级面积汇总表
///
///
///
private DataTable GetGDPDFJMJHZBData(IRDBHelper dbHelper)
{
string[] ttlxarry = new string[] { "TT2", "TT3", "TT4", "TT5" };
string[] pdlxarry = new string[] { "PD2", "PD3", "PD4", "PD5" };
List columnlist = new List();
columnlist.Add("TT1PD1");
for (int i = 0; i < pdlxarry.Length; i++)
{
columnlist.Add(string.Format("{0}{1}", ttlxarry[i], pdlxarry[i]));
columnlist.Add(ttlxarry[i]);
columnlist.Add(pdlxarry[i]);
}
//分别查询出县、镇、村个数代码
//string xzqdmdt = @"select '' as xzqmc,LEFT(ZLDWDM,{0}) AS XZQDM,sum(D01) as D01 from " + ReportTableName + " WHERE D01>0 group by LEFT(ZLDWDM,{0}) ORDER BY LEFT(ZLDWDM,{0})";
string xzqdmdt = @"select '' as xzqmc,substr(ZLDWDM,1,{0}) AS XZQDM,sum(D01) as D01 from " + ReportTableName + " WHERE D01>0 group by substr(ZLDWDM,1,{0}) ORDER BY substr(ZLDWDM,1,{0})";
DataTable xjdmdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 6), true);
if (xjdmdtRst == null || xjdmdtRst.Rows.Count == 0)
{
return xjdmdtRst;
}
DataTable xjdmdtRst2 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 9), true);
DataTable xjdmdtRst3 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 12), true);
//string sumSql = @"SELECT LEFT(ZLDWDM,12) AS XZQDM, GDLX,GDPDJB,SUM(D01) AS D01 FROM " + ReportTableName + " WHERE D01>0 and ((GDLX='PD' or GDLX='TT') or GDPDJB in ('1','2','3','4','5')) GROUP BY LEFT(ZLDWDM,12),GDLX,GDPDJB ORDER BY LEFT(ZLDWDM,12),GDLX,GDPDJB";
string sumSql = @"SELECT substr(ZLDWDM,1,12) AS XZQDM, GDLX,GDPDJB,SUM(D01) AS D01 FROM " + ReportTableName + " WHERE D01>0 and ((GDLX='PD' or GDLX='TT') or GDPDJB in ('1','2','3','4','5')) GROUP BY substr(ZLDWDM,1,12),GDLX,GDPDJB ORDER BY substr(ZLDWDM,1,12),GDLX,GDPDJB";
DataTable xjdtRst3 = dbHelper.ExecuteDatatable("statisticType", sumSql, true);
if (xjdtRst3 == null || xjdtRst3.Rows.Count == 0)
{
return xjdmdtRst;
}
foreach (var citem in columnlist.Where(x => x.Length == 6))
{
xjdmdtRst.Columns.Add(new DataColumn(citem, typeof(double)));
if (citem != "TT1PD1")
{
xjdmdtRst.Columns.Add(new DataColumn(citem.Substring(0, 3), typeof(double)));
xjdmdtRst.Columns.Add(new DataColumn(citem.Substring(3, 3), typeof(double)));
xjdmdtRst.Columns[citem].Expression = string.Format("{0} + {1}", citem.Substring(0, 3), citem.Substring(3, 3));
}
xjdmdtRst2.Columns.Add(new DataColumn(citem, typeof(double)));
if (citem != "TT1PD1")
{
xjdmdtRst2.Columns.Add(new DataColumn(citem.Substring(0, 3), typeof(double)));
xjdmdtRst2.Columns.Add(new DataColumn(citem.Substring(3, 3), typeof(double)));
xjdmdtRst2.Columns[citem].Expression = string.Format("{0} + {1}", citem.Substring(0, 3), citem.Substring(3, 3));
}
xjdmdtRst3.Columns.Add(new DataColumn(citem, typeof(double)));
if (citem != "TT1PD1")
{
xjdmdtRst3.Columns.Add(new DataColumn(citem.Substring(0, 3), typeof(double)));
xjdmdtRst3.Columns.Add(new DataColumn(citem.Substring(3, 3), typeof(double)));
xjdmdtRst3.Columns[citem].Expression = string.Format("{0} + {1}", citem.Substring(0, 3), citem.Substring(3, 3));
}
}
DataRow xjdr = xjdmdtRst.Rows[0];
foreach (var citem in columnlist)
{
if (!xjdmdtRst.Columns.Contains(citem))
continue;
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
xjdr[citem] = 0;
}
for (int z = 0; z < xjdmdtRst2.Rows.Count; z++)
{
DataRow zjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
zjdr[item.ColumnName] = xjdmdtRst2.Rows[z][item.ColumnName];
}
foreach (var citem in columnlist)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
zjdr[citem] = 0D;
}
xjdmdtRst.Rows.Add(zjdr);
DataRow[] cjdmdtRst = xjdmdtRst3.Select(" XZQDM like '" + xjdmdtRst2.Rows[z]["XZQDM"] + "%'");
for (int c = 0; c < cjdmdtRst.Length; c++)
{
#region 添加村
DataRow cjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
cjdr[item.ColumnName] = cjdmdtRst[c][item.ColumnName];
}
foreach (var citem in columnlist)
{
if (!xjdmdtRst.Columns.Contains(citem))
continue;
if (!string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
continue;
string strQuery = null;
if (citem == "TT1PD1")
strQuery = string.Format(" XZQDM='{0}' AND GDPDJB='1'", cjdmdtRst[c]["XZQDM"]);
else
strQuery = string.Format(" XZQDM='{0}' and GDLX='{1}' AND GDPDJB='{2}' ", cjdmdtRst[c]["XZQDM"], citem.Substring(0, 2), citem.Substring(2));
DataRow[] s = xjdtRst3.Select(strQuery);
if (s != null && s.Length > 0)
{
if (s.Length == 1)
cjdr[citem] = s[0]["D01"];
else
{
cjdr[citem] = s.CopyToDataTable().Compute("SUM(D01)", null);
}
}
else
{
cjdr[citem] = 0;
}
}
xjdmdtRst.Rows.Add(cjdr);
//平差
//GDLXPC(columnlist, cjdr, cjdr["D01"].ToDecimal(2));
zjdr.BeginEdit();
foreach (var citem in columnlist)
{
if (xjdmdtRst.Columns.Contains(citem))
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
zjdr[citem] = zjdr[citem].ToDecimal(2) + cjdr[citem].ToDecimal(2);
}
}
zjdr.EndEdit();
#endregion
}
xjdr.BeginEdit();
foreach (var citem in columnlist)
{
if (xjdmdtRst.Columns.Contains(citem))
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
xjdr[citem] = xjdr[citem].ToDecimal(2) + zjdr[citem].ToDecimal(2);
}
}
xjdr.EndEdit();
//DataRow xdr3 = xjdmdtRst.NewRow();
//foreach (DataColumn item in xjdmdtRst.Columns)
//{
// xdr3[item.ColumnName] = DBNull.Value;
//}
//xjdmdtRst.Rows.Add(xdr3);
}
return xjdmdtRst;
}
///
/// 清除---5耕地坡度分级面积汇总表
///
///
/// sql条件
///
public void ClaerNullByDT4(IRDBHelper dbHelper, ref DataTable dt)
{
if (dt != null && dt.Rows.Count > 0)
{
DataTable mjhztjb2 = dbHelper.ExecuteDatatable("tempdt", "select ZLDWDM,GDLX,GDPDJB from mjhztjb2 where DLBM LIKE '01%' and (GDLX='PD' or GDLX='TT') and GDPDJB in ('1','2','3','4','5') group by zldwdm,GDLX,GDPDJB", true);
if (mjhztjb2 == null || mjhztjb2.Rows.Count == 0)
{
return;
}
mjhztjb2.PrimaryKey = new DataColumn[] { mjhztjb2.Columns["ZLDWDM"], mjhztjb2.Columns["GDLX"], mjhztjb2.Columns["GDPDJB"] };
for (int i = 0; i < dt.Rows.Count; i++)
{
string XZQDM = dt.Rows[i]["XZQDM"].ToTrim();
if (string.IsNullOrWhiteSpace(XZQDM))
{
continue;
}
foreach (DataColumn item in dt.Columns)
{
if (!string.IsNullOrWhiteSpace(item.Expression))
continue;
if (item.ColumnName.IndexOf("P") == 0 || item.ColumnName.IndexOf("T") == 0)
{
if (dt.Rows[i][item.ColumnName].ToTrim() == "0")
{
string GDLX = item.ColumnName.Substring(0, 2);
string GDPDJB = item.ColumnName.Substring(2);
string selectwhere = string.Format("ZLDWDM like '{0}%' and GDLX = '{1}' and GDPDJB ='{2}'", XZQDM, GDLX, GDPDJB);
DataRow[] findrows = mjhztjb2.Select(selectwhere);
if (findrows == null || findrows.Length == 0)
{
dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
}
}
}
}
}
}
}
#endregion
#region 6耕地种植类型面积统计表
///
/// 6耕地种植类型面积统计表
///
///
///
///
///
public bool ExportReportGDZZLXMJTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetGDZZLXMJTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT5(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 6耕地种植类型面积统计表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportGDZZLXMJTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetGDZZLXMJTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT5(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 38);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 6耕地种植类型面积统计表
///
///
/// 霍岩 2018-11-29 修改
private DataTable GetGDZZLXMJTJBData(IRDBHelper dbHelper, bool IsKHF = false, bool IsFQ = false)
{
try
{
string[] zzlxarry = null;
if (IsFQ)
{
zzlxarry = new string[] { "FQ", "LJTM" };
}
else if (IsKHF)
{
zzlxarry = new string[] { "JKHF", "GCHF" };
}
else
{
zzlxarry = new string[] { "LS", "FLS", "LYFL", "XG", "LLJZ", "WG" };
}
List columnlist;
List dlbmlist;
List ejdllist;
string[] dlbms = null;
if (IsFQ)
{
dlbms = new string[] { "0602", "1001", "1003", "0301", "0302", "0305", "0307", "0404" };
}
else if (IsKHF)
{
dlbms = new string[] { "0201", "0201K", "0202", "0202K", "0203", "0203K", "0204", "0204K", "0301", "0301K", "0302", "0302K", "0305", "0307", "0307K", "0403K", "0404", "1104", "1104K" };
}
string gdc = GetGDZZLXMJTJBDT(dbHelper, zzlxarry, out columnlist, out dlbmlist, out ejdllist, dlbms, IsKHF, IsFQ);
//分别查询出县、镇、村个数代码
string xzqdmdt = null;
if (IsFQ)
{
xzqdmdt = @"select '' as xzqmc, substr(ZLDWDM,1,{0}) AS XZQDM from " + ReportTableName + " group by substr(ZLDWDM,1,{0}) ORDER BY substr(ZLDWDM,1,{0})";
}
else if (IsKHF)
{
xzqdmdt = @"select '' as xzqmc, substr(ZLDWDM,1,{0}) AS XZQDM from " + ReportTableName + " group by substr(ZLDWDM,1,{0}) ORDER BY substr(ZLDWDM,1,{0})";
}
else
{
xzqdmdt = @"select '' as xzqmc, substr(ZLDWDM,1,{0}) AS XZQDM from " + ReportTableName + " group by substr(ZLDWDM,1,{0}) ORDER BY substr(ZLDWDM,1,{0})";
}
DataTable xjdmdtRst = dbHelper.ExecuteDatatable("xjdmdtRst", string.Format(xzqdmdt, 6), true);
if (xjdmdtRst == null)
{
return xjdmdtRst;
}
DataTable xjdmdtRst2 = dbHelper.ExecuteDatatable("xjdmdtRst2", string.Format(xzqdmdt, 9), true);
DataTable xjdmdtRst3 = dbHelper.ExecuteDatatable("xjdmdtRst3", string.Format(xzqdmdt, 12), true);
string sumSql = null;
if (IsFQ)
{
sumSql = @"SELECT substr(ZLDWDM,1,12) AS XZQDM, ZZSXDM " + gdc + " FROM " + ReportTableName + " WHERE TBXHDM IN ('FQ', 'LJTM') GROUP BY substr(ZLDWDM,1,12),ZZSXDM";
}
else if (IsKHF)
{
sumSql = @"SELECT substr(ZLDWDM,1,12) AS XZQDM, ZZSXDM " + gdc + " FROM " + ReportTableName + " WHERE ZZSXDM IS NOT NULL AND ZZSXDM <> '' GROUP BY substr(ZLDWDM,1,12),ZZSXDM";
}
else
{
sumSql = @"SELECT substr(ZLDWDM,1,12) AS XZQDM, ZZSXDM " + gdc + " FROM " + ReportTableName + " WHERE D01>0 AND (ZZSXDM IS NOT NULL AND ZZSXDM <> '') GROUP BY substr(ZLDWDM,1,12),ZZSXDM";
}
DataTable xjdtRst3 = dbHelper.ExecuteDatatable("xjdtRst3", sumSql, true);
if (xjdtRst3 == null)
{
return xjdmdtRst;
}
foreach (string citem in columnlist)
{
xjdmdtRst.Columns.Add(new DataColumn(citem, typeof(double)));
xjdmdtRst2.Columns.Add(new DataColumn(citem, typeof(double)));
xjdmdtRst3.Columns.Add(new DataColumn(citem, typeof(double)));
}
string[] dlbmarry = null;
if (IsFQ)
{
dlbmarry = new string[] { "D0602", "D1001", "D1003", "D0301", "D0302", "D0305", "D0307", "D0404" };
}
else if (IsKHF)
{
dlbmarry = new string[] { "D0201", "D0201K", "D0202", "D0202K", "D0203", "D0203K", "D0204", "D0204K", "D0301", "D0301K", "D0302", "D0302K", "D0305", "D0307", "D0307K", "D0403K", "D0404", "D1104", "D1104K" };
}
else
{
dlbmarry = new string[] { "D01", "D0101", "D0102", "D0103" };
}
if (IsKHF)
{
xjdmdtRst.Columns.Add("HJ", typeof(double));
xjdmdtRst.Columns["HJ"].SetOrdinal(2);
xjdmdtRst.Columns.Add("JKHF", typeof(double));
xjdmdtRst.Columns["JKHF"].SetOrdinal(3);
xjdmdtRst.Columns.Add("GCHF", typeof(double));
xjdmdtRst.Columns["GCHF"].SetOrdinal(23);
for (int j = 0; j < zzlxarry.Length; j++)
{
string zzlx = zzlxarry[j];
string strExpr = null;
for (int i = 0; i < dlbmarry.Length; i++)
{
string dlbm = dlbmarry[i];
if (!xjdmdtRst.Columns.Contains(zzlx + dlbm))
continue;
if (dlbm.Length > 5)
continue;
if (i == 0)
strExpr = zzlx + dlbm;
else
strExpr = strExpr + " + " + zzlx + dlbm;
}
strExpr = string.Format("{0} + {1}D0403K", strExpr, zzlx);
xjdmdtRst.Columns[zzlx].Expression = strExpr;
}
xjdmdtRst.Columns["HJ"].Expression = "JKHF + GCHF";
xjdmdtRst2.Columns.Add("HJ", typeof(double));
xjdmdtRst.Columns["HJ"].SetOrdinal(2);
xjdmdtRst2.Columns.Add("JKHF", typeof(double));
xjdmdtRst2.Columns["JKHF"].SetOrdinal(3);
xjdmdtRst2.Columns.Add("GCHF", typeof(double));
xjdmdtRst2.Columns["GCHF"].SetOrdinal(23);
for (int j = 0; j < zzlxarry.Length; j++)
{
string zzlx = zzlxarry[j];
string strExpr = null;
for (int i = 0; i < dlbmarry.Length; i++)
{
string dlbm = dlbmarry[i];
if (!xjdmdtRst2.Columns.Contains(zzlx + dlbm))
continue;
if (dlbm.Length > 5)
continue;
if (i == 0)
strExpr = zzlx + dlbm;
else
strExpr = strExpr + " + " + zzlx + dlbm;
}
strExpr = string.Format("{0} + {1}D0403K", strExpr, zzlx);
xjdmdtRst2.Columns[zzlx].Expression = strExpr;
}
xjdmdtRst2.Columns["HJ"].Expression = "JKHF + GCHF";
xjdmdtRst3.Columns.Add("HJ", typeof(double));
xjdmdtRst.Columns["HJ"].SetOrdinal(2);
xjdmdtRst3.Columns.Add("JKHF", typeof(double));
xjdmdtRst3.Columns["JKHF"].SetOrdinal(3);
xjdmdtRst3.Columns.Add("GCHF", typeof(double));
xjdmdtRst3.Columns["GCHF"].SetOrdinal(23);
for (int j = 0; j < zzlxarry.Length; j++)
{
string zzlx = zzlxarry[j];
string strExpr = null;
for (int i = 0; i < dlbmarry.Length; i++)
{
string dlbm = dlbmarry[i];
if (!xjdmdtRst3.Columns.Contains(zzlx + dlbm))
continue;
if (dlbm.Length > 5)
continue;
if (i == 0)
strExpr = zzlx + dlbm;
else
strExpr = strExpr + " + " + zzlx + dlbm;
}
strExpr = string.Format("{0} + {1}D0403K", strExpr, zzlx);
xjdmdtRst3.Columns[zzlx].Expression = strExpr;
}
xjdmdtRst3.Columns["HJ"].Expression = "JKHF + GCHF";
}
else if (IsFQ)
{
xjdmdtRst.Columns.Add("FQ", typeof(double));
xjdmdtRst.Columns["FQ"].SetOrdinal(2);
xjdmdtRst.Columns.Add("LJTM", typeof(double));
xjdmdtRst.Columns["LJTM"].SetOrdinal(6);
for (int j = 0; j < zzlxarry.Length; j++)
{
string zzlx = zzlxarry[j];
string strExpr = null;
for (int i = 0; i < dlbmarry.Length; i++)
{
string dlbm = dlbmarry[i];
if (!xjdmdtRst.Columns.Contains(zzlx + dlbm))
continue;
if (i == 0)
strExpr = zzlx + dlbm;
else
strExpr = strExpr + " + " + zzlx + dlbm;
}
xjdmdtRst.Columns[zzlx].Expression = strExpr;
}
xjdmdtRst2.Columns.Add("FQ", typeof(double));
xjdmdtRst2.Columns["FQ"].SetOrdinal(2);
xjdmdtRst2.Columns.Add("LJTM", typeof(double));
xjdmdtRst2.Columns["LJTM"].SetOrdinal(6);
for (int j = 0; j < zzlxarry.Length; j++)
{
string zzlx = zzlxarry[j];
string strExpr = null;
for (int i = 0; i < dlbmarry.Length; i++)
{
string dlbm = dlbmarry[i];
if (!xjdmdtRst2.Columns.Contains(zzlx + dlbm))
continue;
if (i == 0)
strExpr = zzlx + dlbm;
else
strExpr = strExpr + " + " + zzlx + dlbm;
}
xjdmdtRst2.Columns[zzlx].Expression = strExpr;
}
xjdmdtRst3.Columns.Add("FQ", typeof(double));
xjdmdtRst3.Columns["FQ"].SetOrdinal(2);
xjdmdtRst3.Columns.Add("LJTM", typeof(double));
xjdmdtRst3.Columns["LJTM"].SetOrdinal(6);
for (int j = 0; j < zzlxarry.Length; j++)
{
string zzlx = zzlxarry[j];
string strExpr = null;
for (int i = 0; i < dlbmarry.Length; i++)
{
string dlbm = dlbmarry[i];
if (!xjdmdtRst3.Columns.Contains(zzlx + dlbm))
continue;
if (i == 0)
strExpr = zzlx + dlbm;
else
strExpr = strExpr + " + " + zzlx + dlbm;
}
xjdmdtRst3.Columns[zzlx].Expression = strExpr;
}
}
else
{
int n = 0;
for (int j = 0; j < dlbmarry.Length; j++)
{
string dlbm = dlbmarry[j];
xjdmdtRst.Columns.Add("Z" + dlbm, typeof(double));
xjdmdtRst.Columns["Z" + dlbm].SetOrdinal(2 + zzlxarry.Length * j + n);
n++;
string strExpr = null;
for (int i = 0; i < zzlxarry.Length; i++)
{
string zzlx = zzlxarry[i];
if (i == 0)
strExpr = zzlx + dlbm;
else
strExpr = strExpr + " + " + zzlx + dlbm;
}
xjdmdtRst.Columns["Z" + dlbm].Expression = strExpr;
}
n = 0;
for (int j = 0; j < dlbmarry.Length; j++)
{
string dlbm = dlbmarry[j];
xjdmdtRst2.Columns.Add("Z" + dlbm, typeof(double));
xjdmdtRst2.Columns["Z" + dlbm].SetOrdinal(2 + zzlxarry.Length * j + n);
n++;
string strExpr = null;
for (int i = 0; i < zzlxarry.Length; i++)
{
string zzlx = zzlxarry[i];
if (i == 0)
strExpr = zzlx + dlbm;
else
strExpr = strExpr + " + " + zzlx + dlbm;
}
xjdmdtRst2.Columns["Z" + dlbm].Expression = strExpr;
}
n = 0;
for (int j = 0; j < dlbmarry.Length; j++)
{
string dlbm = dlbmarry[j];
xjdmdtRst3.Columns.Add("Z" + dlbm, typeof(double));
xjdmdtRst3.Columns["Z" + dlbm].SetOrdinal(2 + zzlxarry.Length * j + n);
n++;
string strExpr = null;
for (int i = 0; i < zzlxarry.Length; i++)
{
string zzlx = zzlxarry[i];
if (i == 0)
strExpr = zzlx + dlbm;
else
strExpr = strExpr + " + " + zzlx + dlbm;
}
xjdmdtRst3.Columns["Z" + dlbm].Expression = strExpr;
}
}
if (xjdmdtRst.Rows.Count == 0)
{
return xjdmdtRst;
}
DataRow xjdr = xjdmdtRst.Rows[0];
foreach (var citem in columnlist)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
xjdr[citem] = 0;
}
for (int z = 0; z < xjdmdtRst2.Rows.Count; z++)
{
DataRow zjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
zjdr[item.ColumnName] = xjdmdtRst2.Rows[z][item.ColumnName];
}
foreach (var citem in columnlist)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
zjdr[citem] = 0;
}
xjdmdtRst.Rows.Add(zjdr);
DataRow[] cjdmdtRst = xjdmdtRst3.Select(" XZQDM like '" + xjdmdtRst2.Rows[z]["XZQDM"] + "%'");
for (int c = 0; c < cjdmdtRst.Length; c++)
{
#region 添加村
DataRow cjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
cjdr[item.ColumnName] = cjdmdtRst[c][item.ColumnName];
}
foreach (var citem in zzlxarry)
{
DataRow[] s = null;
if (IsFQ)
{
s = xjdtRst3.Select(string.Format(" XZQDM='{0}'", cjdmdtRst[c]["XZQDM"]));
}
else
{
s = xjdtRst3.Select(string.Format(" XZQDM='{0}' and ZZSXDM='{1}'", cjdmdtRst[c]["XZQDM"], citem));
}
var queryclist = columnlist.Where(x => x.IndexOf(citem) == 0);
foreach (var citem2 in queryclist)
{
if (!string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem2].Expression))
continue;
if (s != null && s.Length > 0)
{
if (s.Length == 1)
//Bug-14475 霍岩 2019-02-21 二级种植类型编码减去一级种植类型编码得到地类编码
cjdr[citem2] = s[0][citem2.Replace(citem, "")];
else
{
cjdr[citem2] = s.CopyToDataTable().Compute(string.Format("SUM({0})", citem2.Replace(citem, "")), null);
}
}
else
{
cjdr[citem2] = 0;
}
//Bug-15257 霍岩 2019-04-08 三级地类数据汇总到二级地类
if (IsKHF || IsFQ)
{
foreach (DataColumn col in xjdtRst3.Columns.Cast().ToList().Where(x => x.ColumnName.IndexOf(citem2.Replace(citem, "")) == 0))
{
//if (IsKHF && col.ColumnName == "D1104")
//{
// if (s != null && s.Length > 0)
// {
// if (s.Length == 1)
// cjdr[citem2] = cjdr[citem2].ToDecimal(2) + s[0]["D1104A"].ToDecimal(2);
// else
// {
// cjdr[citem2] = cjdr[citem2].ToDecimal(2) + s.CopyToDataTable().Compute("SUM(D1104A)", null).ToDecimal(2);
// }
// }
//}
if (IsKHF || IsFQ)
{
if (col.ColumnName == citem2.Replace(citem, ""))
continue;
if (s != null && s.Length > 0)
{
if (s.Length == 1)
cjdr[citem2] = cjdr[citem2].ToDecimal(2) + s[0][col.ColumnName].ToDecimal(2);
else
{
cjdr[citem2] = cjdr[citem2].ToDecimal(2) + s.CopyToDataTable().Compute(string.Format("SUM({0})", col.ColumnName), null).ToDecimal(2);
}
}
}
}
}
}
}
xjdmdtRst.Rows.Add(cjdr);
//平差
//GDZZLXPC(zzlxarry, dlbmlist, cjdr);
zjdr.BeginEdit();
foreach (var citem in columnlist)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
zjdr[citem] = zjdr[citem].ToDecimal(2) + cjdr[citem].ToDecimal(2);
}
zjdr.EndEdit();
#endregion
}
xjdr.BeginEdit();
foreach (var citem in columnlist)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
xjdr[citem] = xjdr[citem].ToDecimal(2) + zjdr[citem].ToDecimal(2);
}
xjdr.EndEdit();
//DataRow xdr3 = xjdmdtRst.NewRow();
//foreach (DataColumn item in xjdmdtRst.Columns)
//{
// xdr3[item.ColumnName] = DBNull.Value;
//}
//xjdmdtRst.Rows.Add(xdr3);
}
//xjdmdtRst.Select(null, "XZQDM ASC").CopyToDataTable();
return xjdmdtRst.Select(null, "XZQDM ASC").CopyToDataTable();
}
catch (Exception ex)
{
throw ex;
}
}
private string GetGDZZLXMJTJBDT(IRDBHelper dbHelper, string[] zzlxarry, out List columnlist, out List dlbmlist, out List ejdllist, string[] ejdlbms = null, bool IsKHF = false, bool IsFQ = false)
{
columnlist = new List();
DataTable mjhzdt = dbHelper.ExecuteDatatable("hztjb", "select * from " + ReportTableName + " where 1=2", true);
#region 计算地类编码集合
MJHZJCTJBHelper mh = new MJHZJCTJBHelper();
mh.GetDLBMListByDT(mjhzdt, out dlbmlist, out ejdllist);
if (ejdlbms == null)
{
dlbmlist = dlbmlist.Where(x => x.YJDL == "01").ToList();
}
string result = string.Empty;
if (ejdlbms == null)
{
foreach (var yjitem in dlbmlist)
{
result = result + string.Format(" ,sum(D{0}) as D{0} ", yjitem.YJDL);
foreach (var item in zzlxarry)
{
columnlist.Add(item + "D" + yjitem.YJDL);
}
if (yjitem.EJDLList != null && yjitem.EJDLList.Count > 0)
{
foreach (var ejitem in yjitem.EJDLList)
{
result = result + string.Format(" ,sum(D{0}) as D{0} ", ejitem);
foreach (var item in zzlxarry)
{
columnlist.Add(item + "D" + ejitem);
}
}
}
}
}
else
{
foreach (var item in zzlxarry)
{
foreach (var yjitem in dlbmlist)
{
if (yjitem.EJDLList != null && yjitem.EJDLList.Count > 0)
{
foreach (var ejitem in yjitem.EJDLList)
{
if (ejdlbms.Contains(ejitem))
{
columnlist.Add(item + "D" + ejitem);
}
}
}
}
}
if (IsFQ)
{
columnlist.Remove("FQD0301");
columnlist.Remove("FQD0302");
columnlist.Remove("FQD0305");
columnlist.Remove("FQD0307");
columnlist.Remove("FQD0404");
columnlist.Remove("LJTMD0602");
columnlist.Remove("LJTMD1001");
columnlist.Remove("LJTMD1003");
}
foreach (var yjitem in dlbmlist)
{
if (yjitem.EJDLList != null && yjitem.EJDLList.Count > 0)
{
foreach (var ejitem in yjitem.EJDLList)
{
if (ejdlbms.Contains(ejitem))
{
if (IsKHF)
{
if (ejitem == "1104")
{
foreach (var itemSub in yjitem.EJDLList.Where(x => x.Contains(ejitem)))
{
result = result + string.Format(" ,sum(D{0}) as D{0} ", itemSub);
}
}
else if (ejitem != "1104K")
{
result = result + string.Format(" ,sum(D{0}) as D{0} ", ejitem);
}
}
else
{
foreach (var itemSub in yjitem.EJDLList.Where(x => x.Contains(ejitem)))
{
result = result + string.Format(" ,sum(D{0}) as D{0} ", itemSub);
}
}
}
}
}
}
}
#endregion
return result;
}
///
/// 清除---6耕地种植类型面积统计表
///
///
/// sql条件
///
public void ClaerNullByDT5(IRDBHelper dbHelper, ref DataTable dt)
{
if (dt != null && dt.Rows.Count > 0)
{
DataTable mjhztjb2 = dbHelper.ExecuteDatatable("tempdt", @"SELECT substr(ZLDWDM,1,12) AS ZLDWDM,case when (ZZSXDM = '' OR ZZSXDM IS NULL) then 'GZ' else ZZSXDM end AS ZZSXDM ,DLBM FROM mjhztjb2 WHERE dlbm like '01%' GROUP BY substr(ZLDWDM,1,12),case when ZZSXDM = '' OR ZZSXDM IS NULL then 'GZ' else ZZSXDM end ,DLBM", true);
if (mjhztjb2 == null || mjhztjb2.Rows.Count == 0)
{
return;
}
mjhztjb2.PrimaryKey = new DataColumn[] { mjhztjb2.Columns["ZLDWDM"], mjhztjb2.Columns["DLBM"], mjhztjb2.Columns["ZZSXDM"] };
for (int i = 0; i < dt.Rows.Count; i++)
{
string XZQDM = dt.Rows[i]["XZQDM"].ToTrim();
if (string.IsNullOrWhiteSpace(XZQDM))
{
continue;
}
foreach (DataColumn item in dt.Columns)
{
if (!string.IsNullOrWhiteSpace(item.Expression))
continue;
if (dt.Rows[i][item.ColumnName].ToTrim() == "0")
{
string dlbm = string.Empty;
string ZZSXDM = string.Empty;
string selectwhere = string.Empty;
if (item.ColumnName.IndexOf('D') == 0)
{
dlbm = item.ColumnName.Substring(1);
selectwhere = string.Format("ZLDWDM like '{0}%' and DLBM like '{1}%' ", XZQDM, dlbm);
}
else if (item.ColumnName.IndexOf('D') > 0)
{
dlbm = item.ColumnName.Substring(item.ColumnName.IndexOf('D') + 1);
ZZSXDM = item.ColumnName.Substring(0, item.ColumnName.IndexOf('D'));
selectwhere = string.Format("ZLDWDM like '{0}%' and DLBM like '{1}%' and ZZSXDM='{2}' ", XZQDM, dlbm, ZZSXDM);
}
else
{
continue;
}
DataRow[] findrows = mjhztjb2.Select(selectwhere);
if (findrows == null || findrows.Length == 0)
{
dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
}
}
}
}
}
}
#endregion
#region 7林区范围内园地汇总统计表
///
/// 7林区范围内园地汇总统计表
///
///
///
///
///
public bool ExportReportLXFWNYDHZTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetLXFWNYDHZTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT6(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 7林区范围内园地汇总统计表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportLXFWNYDHZTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetLXFWNYDHZTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT6(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 7);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 7林区范围内园地汇总统计表
///
///
///
private DataTable GetLXFWNYDHZTJBData(IRDBHelper dbHelper)
{
//县
string xjsumSql = @"select '' as xzqmc, substr(zldwdm,1,6) as XZQDM, sum(D0201+D0201K+D0202+D0202K+D0203+D0203K+D0204+D0204K) as DL02, sum(D0201+D0201K) as DL0201, sum(D0202+D0202K) as DL0202, sum(D0203+D0203K) as DL0203, sum(D0204+D0204K) as DL0204 from " + ReportTableName + " WHERE TBXHDM='LQYD' group by substr(zldwdm,1,6) order by substr(zldwdm,1,6)";
//镇
string zjsumSql = @"select '' as xzqmc, substr(zldwdm,1,9) as XZQDM, sum(D0201+D0201K+D0202+D0202K+D0203+D0203K+D0204+D0204K) as DL02, sum(D0201+D0201K) as DL0201, sum(D0202+D0202K) as DL0202, sum(D0203+D0203K) as DL0203, sum(D0204+D0204K) as DL0204 from " + ReportTableName + " WHERE TBXHDM='LQYD' group by substr(zldwdm,1,9) order by substr(zldwdm,1,9)";
//村
string cjsumSql = @"select '' as xzqmc, substr(zldwdm,1,12) as XZQDM, sum(D0201+D0201K+D0202+D0202K+D0203+D0203K+D0204+D0204K) as DL02, sum(D0201+D0201K) as DL0201, sum(D0202+D0202K) as DL0202, sum(D0203+D0203K) as DL0203, sum(D0204+D0204K) as DL0204 from " + ReportTableName + " WHERE TBXHDM='LQYD' AND zldwdm LIKE '{0}%' group by substr(zldwdm,1,12) order by substr(zldwdm,1,12)";
DataTable xjdtRst = dbHelper.ExecuteDatatable("statisticType", xjsumSql, true);
DataTable zjdtRst = dbHelper.ExecuteDatatable("statisticType", zjsumSql, true);
if (xjdtRst == null || zjdtRst == null || xjdtRst.Rows.Count == 0 || zjdtRst.Rows.Count == 0)
{
return xjdtRst;
}
for (int i = 0; i < zjdtRst.Rows.Count; i++)
{
string zjxzqdm = zjdtRst.Rows[i]["XZQDM"].ToTrim();
DataRow xdr = xjdtRst.NewRow();
foreach (DataColumn item in xjdtRst.Columns)
{
xdr[item.ColumnName] = zjdtRst.Rows[i][item.ColumnName];
}
xjdtRst.Rows.Add(xdr);
DataTable cjdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(cjsumSql, zjxzqdm), true);
if (cjdtRst != null && cjdtRst.Rows.Count > 0)
{
for (int j = 0; j < cjdtRst.Rows.Count; j++)
{
DataRow xdr2 = xjdtRst.NewRow();
foreach (DataColumn item in xjdtRst.Columns)
{
xdr2[item.ColumnName] = cjdtRst.Rows[j][item.ColumnName];
}
xjdtRst.Rows.Add(xdr2);
}
}
//DataRow xdr3 = xjdtRst.NewRow();
//foreach (DataColumn item in xjdtRst.Columns)
//{
// xdr3[item.ColumnName] = DBNull.Value;
//}
//xjdtRst.Rows.Add(xdr3);
}
return xjdtRst.Select(null, "XZQDM ASC").CopyToDataTable();
}
///
/// 清除---7林区范围内园地汇总统计表
///
///
/// sql条件
///
public void ClaerNullByDT6(IRDBHelper dbHelper, ref DataTable dt)
{
if (dt != null && dt.Rows.Count > 0)
{
DataTable mjhztjb2 = dbHelper.ExecuteDatatable("tempdt", @"SELECT substr(ZLDWDM,1,12) AS ZLDWDM,DLBM FROM mjhztjb2 WHERE TBXHDM='LQYD' AND DLBM LIKE '02%' GROUP BY substr(ZLDWDM,1,12),DLBM", true);
if (mjhztjb2 == null || mjhztjb2.Rows.Count == 0)
{
return;
}
mjhztjb2.PrimaryKey = new DataColumn[] { mjhztjb2.Columns["ZLDWDM"], mjhztjb2.Columns["DLBM"] };
for (int i = 0; i < dt.Rows.Count; i++)
{
string XZQDM = dt.Rows[i]["XZQDM"].ToTrim();
if (string.IsNullOrWhiteSpace(XZQDM))
{
continue;
}
foreach (DataColumn item in dt.Columns)
{
if (dt.Rows[i][item.ColumnName].ToTrim() == "0")
{
string dlbm = string.Empty;
string selectwhere = string.Empty;
if (item.ColumnName.IndexOf('D') == 0)
{
dlbm = item.ColumnName.Substring(1);
selectwhere = string.Format("ZLDWDM like '{0}%' and DLBM like '{1}%' ", XZQDM, dlbm);
}
else
{
continue;
}
DataRow[] findrows = mjhztjb2.Select(selectwhere);
if (findrows == null || findrows.Length == 0)
{
dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
}
}
}
}
}
}
#endregion
#region 8灌丛草地汇总情况统计表
///
/// 8灌丛草地汇总情况统计表
///
///
///
///
///
public bool ExportReportGCCDXSCDHZQKTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetGCCDXSCDHZQKTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT7(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 8灌丛草地汇总情况统计表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportGCCDXSCDHZQKTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetGCCDXSCDHZQKTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT7(dbHelper, ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 12);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 8灌丛草地汇总情况统计表
///
///
///
private DataTable GetGCCDXSCDHZQKTJBData(IRDBHelper dbHelper)
{
//县
string xjsumSql = @"select '' as xzqmc, substr(zldwdm,1,6) as XZQDM, sum(case when TBXHDM='GCCD'then D0401 else 0 end ) as GCCDD0401, sum(case when TBXHDM='GCCD'then D0402 else 0 end) as GCCDD0402, sum(case when TBXHDM='GCCD' then D0403+D0403K else 0 end ) as GCCDD0403, sum(case when TBXHDM='GCCD'then D0404 else 0 end ) as GCCDD0404 from " + ReportTableName + " WHERE TBXHDM='GCCD' group by substr(zldwdm,1,6) ORDER BY substr(zldwdm,1,6)";
//镇
string zjsumSql = @"select '' as xzqmc, substr(zldwdm,1,9) as XZQDM, sum(case when TBXHDM='GCCD'then D0401 else 0 end) as GCCDD0401, sum(case when TBXHDM='GCCD' then D0402 else 0 end ) as GCCDD0402, sum(case when TBXHDM='GCCD'then D0403+D0403K else 0 end) as GCCDD0403, sum(case when TBXHDM='GCCD'then D0404 else 0 end ) as GCCDD0404 from " + ReportTableName + " WHERE TBXHDM='GCCD' group by substr(zldwdm,1,9) ORDER BY substr(zldwdm,1,9)";
//村
string cjsumSql = @"select '' as xzqmc, substr(zldwdm,1,12) as XZQDM, sum(case when TBXHDM='GCCD'then D0401 else 0 end) as GCCDD0401, sum(case when TBXHDM='GCCD' then D0402 else 0 end ) as GCCDD0402, sum(case when TBXHDM='GCCD'then D0403+D0403K else 0 end) as GCCDD0403, sum(case when TBXHDM='GCCD' then D0404 else 0 end ) as GCCDD0404 from " + ReportTableName + " WHERE TBXHDM='GCCD' AND zldwdm LIKE '{0}%' group by substr(zldwdm,1,12) ORDER BY substr(zldwdm,1,12)";
DataTable xjdtRst = dbHelper.ExecuteDatatable("statisticType", xjsumSql, true);
xjdtRst.Columns.Add("GCCDD04", typeof(double));
xjdtRst.Columns["GCCDD04"].SetOrdinal(2);
xjdtRst.Columns["GCCDD04"].Expression = "GCCDD0401 + GCCDD0402 + GCCDD0403 + GCCDD0404";
DataTable zjdtRst = dbHelper.ExecuteDatatable("statisticType", zjsumSql, true);
zjdtRst.Columns.Add("GCCDD04", typeof(double));
zjdtRst.Columns["GCCDD04"].SetOrdinal(2);
zjdtRst.Columns["GCCDD04"].Expression = "GCCDD0401 + GCCDD0402 + GCCDD0403 + GCCDD0404";
if (xjdtRst == null || zjdtRst == null || xjdtRst.Rows.Count == 0 || zjdtRst.Rows.Count == 0)
{
return xjdtRst;
}
for (int i = 0; i < zjdtRst.Rows.Count; i++)
{
string zjxzqdm = zjdtRst.Rows[i]["XZQDM"].ToTrim();
DataRow xdr = xjdtRst.NewRow();
foreach (DataColumn item in xjdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
xdr[item.ColumnName] = zjdtRst.Rows[i][item.ColumnName];
}
xjdtRst.Rows.Add(xdr);
DataTable cjdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(cjsumSql, zjxzqdm), true);
cjdtRst.Columns.Add("GCCDD04", typeof(double));
cjdtRst.Columns["GCCDD04"].SetOrdinal(2);
cjdtRst.Columns["GCCDD04"].Expression = "GCCDD0401 + GCCDD0402 + GCCDD0403 + GCCDD0404";
if (cjdtRst != null && cjdtRst.Rows.Count > 0)
{
for (int j = 0; j < cjdtRst.Rows.Count; j++)
{
DataRow xdr2 = xjdtRst.NewRow();
foreach (DataColumn item in xjdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
xdr2[item.ColumnName] = cjdtRst.Rows[j][item.ColumnName];
}
xjdtRst.Rows.Add(xdr2);
}
}
//DataRow xdr3 = xjdtRst.NewRow();
//foreach (DataColumn item in xjdtRst.Columns)
//{
// xdr3[item.ColumnName] = DBNull.Value;
//}
//xjdtRst.Rows.Add(xdr3);
}
return xjdtRst;
}
///
/// 清除---8灌丛草地汇总情况统计表
///
///
/// sql条件
///
public void ClaerNullByDT7(IRDBHelper dbHelper, ref DataTable dt)
{
if (dt != null && dt.Rows.Count > 0)
{
DataTable mjhztjb2 = dbHelper.ExecuteDatatable("tempdt", @"SELECT substr(ZLDWDM,1,12) AS ZLDWDM,DLBM,TBXHDM FROM mjhztjb2 WHERE (TBXHDM='GCCD' OR TBXHDM='XSCD' ) AND DLBM LIKE '04%' GROUP BY substr(ZLDWDM,1,12),DLBM,TBXHDM", true);
if (mjhztjb2 == null || mjhztjb2.Rows.Count == 0)
{
return;
}
mjhztjb2.PrimaryKey = new DataColumn[] { mjhztjb2.Columns["ZLDWDM"], mjhztjb2.Columns["TBXHDM"], mjhztjb2.Columns["DLBM"] };
for (int i = 0; i < dt.Rows.Count; i++)
{
string XZQDM = dt.Rows[i]["XZQDM"].ToTrim();
if (string.IsNullOrWhiteSpace(XZQDM))
{
continue;
}
foreach (DataColumn item in dt.Columns)
{
if (!string.IsNullOrWhiteSpace(item.Expression))
continue;
if (dt.Rows[i][item.ColumnName].ToTrim() == "0")
{
string dlbm = item.ColumnName.Substring(5);
string tbxhdm = item.ColumnName.Substring(0, 4);
string selectwhere = string.Format("ZLDWDM like '{0}%' and DLBM like '{1}%' and TBXHDM='{2}' ", XZQDM, dlbm, tbxhdm);
DataRow[] findrows = mjhztjb2.Select(selectwhere);
if (findrows == null || findrows.Length == 0)
{
dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
}
}
}
}
}
}
#endregion
#region 9工业仓储用地按类型汇总统计表
///
/// 9工业仓储用地按类型汇总统计表
///
///
///
///
///
public bool ExportReportGYYDALXHZTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GYYDALXHZTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT8(dbHelper, ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 9);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 9工业仓储用地按类型汇总统计表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportGYYDALXHZTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GYYDALXHZTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT8(dbHelper, ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 9);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 9工业仓储用地按类型汇总统计表
///
///
///
/// 霍岩 2018-11-30 修改
private DataTable GYYDALXHZTJBData(IRDBHelper dbHelper)
{
//***************************************************
//BUG12717 郑英杰 2018-10-11
//***************************************************
//string[] gycclxarry = new string[] { "HDGY", "GTGY", "MKGY", "SNGY", "BLGY", "DLGY" };
//县
string xjsumSql = @"select '' as xzqmc, substr(zldwdm,1,6) as XZQDM, sum(case when TBXHDM='HDGY' then D0601 else 0 end ) as HDGYD0601, sum(case when TBXHDM='GTGY' then D0601 else 0 end ) as GTGYD0601, sum(case when TBXHDM='MTGY' then D0601 else 0 end ) as MTGYD0601, sum(case when TBXHDM='SNGY' then D0601 else 0 end ) as SNGYD0601, sum(case when TBXHDM='BLGY' then D0601 else 0 end ) as BLGYD0601, sum(case when TBXHDM='DLGY' then D0601 else 0 end ) as DLGYD0601 from " + ReportTableName + " WHERE (TBXHDM='HDGY' or TBXHDM='GTGY'or TBXHDM='MTGY'or TBXHDM='SNGY'or TBXHDM='BLGY'or TBXHDM='DLGY') and D0601>0 group by substr(zldwdm,1,6) order by substr(zldwdm,1,6)";
//镇
string zjsumSql = @"select '' as xzqmc, substr(zldwdm,1,9) as XZQDM, sum(case when TBXHDM='HDGY' then D0601 else 0 end ) as HDGYD0601, sum(case when TBXHDM='GTGY' then D0601 else 0 end ) as GTGYD0601, sum(case when TBXHDM='MTGY' then D0601 else 0 end ) as MTGYD0601, sum(case when TBXHDM='SNGY' then D0601 else 0 end ) as SNGYD0601, sum(case when TBXHDM='BLGY' then D0601 else 0 end ) as BLGYD0601, sum(case when TBXHDM='DLGY' then D0601 else 0 end ) as DLGYD0601 from " + ReportTableName + " WHERE (TBXHDM='HDGY' or TBXHDM='GTGY'or TBXHDM='MTGY'or TBXHDM='SNGY'or TBXHDM='BLGY'or TBXHDM='DLGY') and D0601>0 group by substr(zldwdm,1,9) order by substr(zldwdm,1,9)";
//村
string cjsumSql = @"select '' as xzqmc, substr(zldwdm,1,12) as XZQDM, sum(case when TBXHDM='HDGY' then D0601 else 0 end ) as HDGYD0601, sum(case when TBXHDM='GTGY' then D0601 else 0 end ) as GTGYD0601, sum(case when TBXHDM='MTGY' then D0601 else 0 end ) as MTGYD0601, sum(case when TBXHDM='SNGY' then D0601 else 0 end ) as SNGYD0601, sum(case when TBXHDM='BLGY' then D0601 else 0 end ) as BLGYD0601, sum(case when TBXHDM='DLGY' then D0601 else 0 end ) as DLGYD0601 from " + ReportTableName + " WHERE (TBXHDM='HDGY' or TBXHDM='GTGY'or TBXHDM='MTGY'or TBXHDM='SNGY'or TBXHDM='BLGY'or TBXHDM='DLGY') and D0601>0 AND zldwdm LIKE '{0}%' group by substr(zldwdm,1,12) order by substr(zldwdm,1,12)";
DataTable xjdtRst = dbHelper.ExecuteDatatable("statisticType", xjsumSql, true);
xjdtRst.Columns.Add("GYD06", typeof(double));
xjdtRst.Columns["GYD06"].SetOrdinal(2);
xjdtRst.Columns["GYD06"].Expression = "HDGYD0601 + GTGYD0601 + MTGYD0601 + SNGYD0601 + BLGYD0601 + DLGYD0601";
DataTable zjdtRst = dbHelper.ExecuteDatatable("statisticType", zjsumSql, true);
zjdtRst.Columns.Add("GYD06", typeof(double));
zjdtRst.Columns["GYD06"].SetOrdinal(2);
zjdtRst.Columns["GYD06"].Expression = "HDGYD0601 + GTGYD0601 + MTGYD0601 + SNGYD0601 + BLGYD0601 + DLGYD0601";
if (xjdtRst == null || zjdtRst == null || xjdtRst.Rows.Count == 0 || zjdtRst.Rows.Count == 0)
{
return xjdtRst;
}
for (int i = 0; i < zjdtRst.Rows.Count; i++)
{
string zjxzqdm = zjdtRst.Rows[i]["XZQDM"].ToTrim();
DataRow xdr = xjdtRst.NewRow();
foreach (DataColumn item in xjdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
xdr[item.ColumnName] = zjdtRst.Rows[i][item.ColumnName];
}
xjdtRst.Rows.Add(xdr);
DataTable cjdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(cjsumSql, zjxzqdm), true);
cjdtRst.Columns.Add("GYD06", typeof(double));
cjdtRst.Columns["GYD06"].SetOrdinal(2);
cjdtRst.Columns["GYD06"].Expression = "HDGYD0601 + GTGYD0601 + MTGYD0601 + SNGYD0601 + BLGYD0601 + DLGYD0601";
if (cjdtRst != null && cjdtRst.Rows.Count > 0)
{
for (int j = 0; j < cjdtRst.Rows.Count; j++)
{
DataRow xdr2 = xjdtRst.NewRow();
foreach (DataColumn item in xjdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
xdr2[item.ColumnName] = cjdtRst.Rows[j][item.ColumnName];
}
xjdtRst.Rows.Add(xdr2);
}
}
//DataRow xdr3 = xjdtRst.NewRow();
//foreach (DataColumn item in xjdtRst.Columns)
//{
// xdr3[item.ColumnName] = DBNull.Value;
//}
//xjdtRst.Rows.Add(xdr3);
}
return xjdtRst;
}
///
/// 清除---9工业仓储用地按类型汇总统计表
///
///
/// sql条件
///
public void ClaerNullByDT8(IRDBHelper dbHelper, ref DataTable dt)
{
if (dt != null && dt.Rows.Count > 0)
{
DataTable mjhztjb2 = dbHelper.ExecuteDatatable("tempdt", @"SELECT substr(ZLDWDM,1,12) AS ZLDWDM,TBXHDM FROM mjhztjb2 WHERE (TBXHDM='HDGY' or TBXHDM='GTGY'or TBXHDM='MKGY'or TBXHDM='SNGY'or TBXHDM='BLGY'or TBXHDM='DLGY') AND DLBM LIKE '0601%' GROUP BY substr(ZLDWDM,1,12),TBXHDM", true);
if (mjhztjb2 == null || mjhztjb2.Rows.Count == 0)
{
return;
}
mjhztjb2.PrimaryKey = new DataColumn[] { mjhztjb2.Columns["ZLDWDM"], mjhztjb2.Columns["TBXHDM"] };
for (int i = 0; i < dt.Rows.Count; i++)
{
string XZQDM = dt.Rows[i]["XZQDM"].ToTrim();
if (string.IsNullOrWhiteSpace(XZQDM))
{
continue;
}
foreach (DataColumn item in dt.Columns)
{
if (!string.IsNullOrWhiteSpace(item.Expression))
continue;
if (dt.Rows[i][item.ColumnName].ToTrim() == "0")
{
string tbxhdm = item.ColumnName.Substring(0, 4);
string selectwhere = string.Format("ZLDWDM like '{0}%' and TBXHDM='{1}' ", XZQDM, tbxhdm);
DataRow[] findrows = mjhztjb2.Select(selectwhere);
if (findrows == null || findrows.Length == 0)
{
dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
}
}
}
}
}
}
#endregion
#region 10基本农田外可调整地类面积汇总表
///
/// 10基本农田外可调整地类面积汇总表
///
///
///
///
///
public bool ExportReportKTZDLMJHZB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
//DataTable rest = JBNTWKTZDLMJHZBData(dbHelper);//通过压盖统计
DataTable rest = KTZDLMJHZBData2(dbHelper);//通过DLTB属性带K的统计
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT1(dbHelper, "", ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 12);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 土地利用现状变更表(NULL)
///
///
///
///
///
/// 王欢 2018-12-03
public bool ExportReportNULLTDLYXZBGB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
//if (selectht!=null)
//{
// foreach (var item in selectht.Keys)
// {
string reportTempaltePath = GetZLPath() + reportEntity.TempalateFileName + ".xlsx";
string newPath = System.IO.Path.GetDirectoryName(savePath);// + selectht[item].ToString();
string newFile = "(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")" + System.IO.Path.GetFileName(savePath);// item.ToString().Substring(6) + System.IO.Path.GetFileName(savePath);
if (!System.IO.Directory.Exists(newPath))
{
System.IO.Directory.CreateDirectory(newPath);
}
string newsavePath = newPath + "\\" + newFile;
OutExcel(null, newsavePath, reportTempaltePath, 7, 1, 2);
// }
//}
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}///
/// 文字输出功能的各个表,输出空文档
///
///
///
///
///
/// 白明雅 2018-12-08
public bool ExportReportDSCGTDC(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".docx";
if (!System.IO.File.Exists(reportTempaltePath))
return false;
string newPath = System.IO.Path.GetDirectoryName(savePath);
if (!System.IO.Directory.Exists(newPath))
{
System.IO.Directory.CreateDirectory(newPath);
}
System.IO.File.Copy(reportTempaltePath, savePath, true);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 土地变更一览表 (NULL)
///
///
///
///
///
/// 王欢 2018-12-03
public bool ExportReportNULLTDBGYLB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
//if (selectht != null)
//{
// foreach (var item in selectht.Keys)
// {
string reportTempaltePath = GetZLPath() + reportEntity.TempalateFileName + ".xlsx";
string newPath = System.IO.Path.GetDirectoryName(savePath);// + selectht[item].ToString();
string newFile = "(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")" + System.IO.Path.GetFileName(savePath);// item.ToString().Substring(6) + System.IO.Path.GetFileName(savePath);
if (!System.IO.Directory.Exists(newPath))
{
System.IO.Directory.CreateDirectory(newPath);
}
string newsavePath = newPath + "\\" + newFile;
OutExcel(null, newsavePath, reportTempaltePath, 7, 1, 2);
// }
//}
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 10可调整地类面积汇总表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportKTZDLMJHZB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = KTZDLMJHZBData2(dbHelper);//通过DLTB属性带K的统计
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT1(dbHelper, "", ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 12);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 10基本农田外可调整地类面积汇总表(空表)
///
///
///
///
/// 王欢 2018-09-29
public bool ExportReportKTZDLMJHZBNULL(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
//权属单位代码表 文件命名有问题 为满足需求暂定是现在
//if (selectht != null)
//{
// foreach (var item in selectht.Keys)
// {
string reportTempaltePath = GetZLPath() + reportEntity.TempalateFileName + ".xlsx";
string newPath = System.IO.Path.GetDirectoryName(savePath);// + selectht[item].ToString();
string newFile = "(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")" + System.IO.Path.GetFileName(savePath);// item.ToString().Substring(6) + System.IO.Path.GetFileName(savePath);
if (!System.IO.Directory.Exists(newPath))
{
System.IO.Directory.CreateDirectory(newPath);
}
string newsavePath = newPath + "\\" + newFile;
OutExcel(null, newsavePath, reportTempaltePath, 7, 1, 2);
// }
//}
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 10可调整地类面积汇总表(通过DLTB属性带K的统计)
///
///
///
/// 霍岩 2018-11-30 修改
private DataTable KTZDLMJHZBData2(IRDBHelper dbHelper)
{
string[] jbntwktzarry = new string[] { "D0201K", "D0202K", "D0203K", "D0204K", "D0301K", "D0302K", "D0307K", "D0403K", "D1104K" };
string sumsql = string.Empty;
string sumsql2 = string.Empty;
string dlwheresql = string.Empty;
foreach (var item in jbntwktzarry)
{
if (string.IsNullOrWhiteSpace(sumsql))
sumsql = string.Format(" SUM({0}) AS {0}", item).Replace("AS D", "AS DL");
else
sumsql = sumsql + string.Format(" , SUM({0}) AS {0}", item).Replace("AS D", "AS DL");
if (string.IsNullOrWhiteSpace(sumsql2))
{
sumsql2 = item;
}
else
{
sumsql2 = sumsql2 + "+" + item;
}
if (string.IsNullOrWhiteSpace(dlwheresql))
dlwheresql = string.Format(" {0}>0", item);
else
dlwheresql = dlwheresql + string.Format(" or {0}>0", item);
}
//dlwheresql = dlwheresql.TrimEnd('r').TrimEnd('o');
//县
string xjsumSql = @"select '' as xzqmc, substr(zldwdm,1,6) as XZQDM, sum(" + sumsql2 + ") as HJ, {0} from " + ReportTableName + " where ({1}) group by substr(zldwdm,1,6) ORDER BY substr(zldwdm,1,6)";
//镇
string zjsumSql = @"select '' as xzqmc, substr(zldwdm,1,9) as XZQDM, sum(" + sumsql2 + ") as HJ, {0} from " + ReportTableName + " where ({1}) group by substr(zldwdm,1,9) ORDER BY substr(zldwdm,1,9)";
//村
string cjsumSql = @"select '' as xzqmc, substr(zldwdm,1,12) as XZQDM, sum(" + sumsql2 + ") as HJ, {0} from " + ReportTableName + " where zldwdm like '{1}%' and ({2}) group by substr(zldwdm,1,12) ORDER BY substr(zldwdm,1,12)";
DataTable xjdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(xjsumSql, sumsql, dlwheresql), true);
DataTable zjdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(zjsumSql, sumsql, dlwheresql), true);
if (xjdtRst == null || zjdtRst == null || xjdtRst.Rows.Count == 0 || zjdtRst.Rows.Count == 0)
{
return xjdtRst;
}
for (int i = 0; i < zjdtRst.Rows.Count; i++)
{
string zjxzqdm = zjdtRst.Rows[i]["XZQDM"].ToTrim();
DataRow xdr = xjdtRst.NewRow();
foreach (DataColumn item in xjdtRst.Columns)
{
xdr[item.ColumnName] = zjdtRst.Rows[i][item.ColumnName];
}
xjdtRst.Rows.Add(xdr);
DataTable cjdtRst = cjdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(cjsumSql, sumsql, zjxzqdm, dlwheresql), true);
if (cjdtRst != null && cjdtRst.Rows.Count > 0)
{
for (int j = 0; j < cjdtRst.Rows.Count; j++)
{
DataRow xdr2 = xjdtRst.NewRow();
foreach (DataColumn item in xjdtRst.Columns)
{
xdr2[item.ColumnName] = cjdtRst.Rows[j][item.ColumnName];
}
xjdtRst.Rows.Add(xdr2);
}
}
//DataRow xdr3 = xjdtRst.NewRow();
//foreach (DataColumn item in xjdtRst.Columns)
//{
// xdr3[item.ColumnName] = DBNull.Value;
//}
//xjdtRst.Rows.Add(xdr3);
}
return xjdtRst;
}
#endregion
#region 11部分细化地类面积汇总表
///
/// 11部分细化地类面积汇总表
///
///
///
///
///
public bool ExportReportBFXHDLMJHZB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = BFXHDLMJHZBData(dbHelper);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT11(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 10);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 11部分细化地类面积汇总表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportBFXHDLMJHZB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = BFXHDLMJHZBData(dbHelper);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT11(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 10);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 11部分细化地类面积汇总表
///
///
///
private DataTable BFXHDLMJHZBData(IRDBHelper dbHelper)
{
//string[] dlbmarry = new string[] { "D08H2A", "D0810A", "D1104A", "D1107A" };
string[] czcbsarry = new string[] { "D201A", "D202A", "D203A" };
//分别查询出县、镇、村个数代码
string xzqdmdt = @"SELECT '' AS XZQMC, substr(ZLDWDM,1,{0}) AS XZQDM, SUM(D08H2A) AS D08H2A,SUM(D0810A) AS D0810A,SUM(D1104A) + SUM(D1104K) AS D1104A,SUM(D1107A) AS D1107A FROM " + ReportTableName + " GROUP BY substr(ZLDWDM,1,{0}) ORDER BY substr(ZLDWDM,1,{0})";
DataTable xjdmdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 6), true);
if (xjdmdtRst == null || xjdmdtRst.Rows.Count == 0)
{
return xjdmdtRst;
}
DataTable xjdmdtRst2 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 9), true);
DataTable xjdmdtRst3 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 12), true);
string sumSql2 = @"select substr(ZLDWDM,1,12) AS XZQDM,CZCSXM,SUM(TBZMJ) AS TBDLMJ from " + ReportTableName + " where CZCSXM IN ('201A','202A','203A') group by substr(ZLDWDM,1,12) ,CZCSXM";
DataTable cccbsRst = dbHelper.ExecuteDatatable("statisticType", sumSql2, true);
xjdmdtRst.Columns.Add("D20A", typeof(double));
xjdmdtRst2.Columns.Add("D20A", typeof(double));
xjdmdtRst3.Columns.Add("D20A", typeof(double));
foreach (var citem in czcbsarry)
{
xjdmdtRst.Columns.Add(new DataColumn(citem, typeof(double)));
xjdmdtRst2.Columns.Add(new DataColumn(citem, typeof(double)));
xjdmdtRst3.Columns.Add(new DataColumn(citem, typeof(double)));
}
xjdmdtRst.Columns["D20A"].Expression = "D201A + D202A + D203A";
xjdmdtRst2.Columns["D20A"].Expression = "D201A + D202A + D203A";
xjdmdtRst3.Columns["D20A"].Expression = "D201A + D202A + D203A";
DataRow xjdr = xjdmdtRst.Rows[0];
for (int z = 0; z < xjdmdtRst2.Rows.Count; z++)
{
DataRow zjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
zjdr[item.ColumnName] = xjdmdtRst2.Rows[z][item.ColumnName];
}
DataRow[] cjdmdtRst = xjdmdtRst3.Select(" XZQDM like '" + xjdmdtRst2.Rows[z]["XZQDM"] + "%'");
int citycount = 0;
for (int c = 0; c < cjdmdtRst.Length; c++)
{
#region 添加村
bool isadd = false;
DataRow cjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (!string.IsNullOrWhiteSpace(item.Expression))
continue;
cjdr[item.ColumnName] = cjdmdtRst[c][item.ColumnName];
if (item.DataType.Name == typeof(double).Name)
{
if (cjdr[item.ColumnName].ToDecimal(2) > 0)
{
isadd = true;
}
}
}
//foreach (var dlbmitem in dlbmarry)
//{
// DataRow[] s = dlbmRst.Select(string.Format(" XZQDM='{0}' and DLBM='{1}' ", cjdmdtRst[c]["XZQDM"], dlbmitem.Substring(1)));
// if (s != null && s.Length > 0)
// {
// isadd = true;
// if (s[0]["TBDLMJ"].ToDecimal(2) > cjdr[dlbmitem.Substring(0, 5)].ToDecimal(2))
// {
// //防止统计出的值大于平差后的值
// cjdr[dlbmitem] = cjdr[dlbmitem.Substring(0, 5)];
// }
// else
// {
// cjdr[dlbmitem] = s[0]["TBDLMJ"];
// }
// }
// else
// {
// cjdr[dlbmitem] = 0;
// }
//}
foreach (var citem in czcbsarry)
{
if (!string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
continue;
DataRow[] s = cccbsRst.Select(string.Format(" XZQDM='{0}' and CZCSXM='{1}' ", cjdmdtRst[c]["XZQDM"], citem.Substring(1)));
if (s != null && s.Length > 0)
{
isadd = true;
if (s.Length == 1)
cjdr[citem] = s[0]["TBDLMJ"];
else
{
cjdr[citem] = s.CopyToDataTable().Compute("SUM(TBDLMJ)", null);
}
}
else
{
cjdr[citem] = 0;
}
}
if (!isadd)
{
continue;
}
////平差(不能超过当前村最大值)
//BFXHPC(dlbmarry, cjdr);
//foreach (var dlbmitem in dlbmarry)
//{
// zjdr[dlbmitem] = zjdr[dlbmitem].ToDecimal(2) + cjdr[dlbmitem].ToDecimal(2);
//}
foreach (var citem in czcbsarry)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
zjdr[citem] = zjdr[citem].ToDecimal(2) + cjdr[citem].ToDecimal(2);
}
if (citycount == 0)
{
if (xjdmdtRst.Rows.Count > 1)//表示最少已经存在一个镇了
{
DataRow xdr3 = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
xdr3[item.ColumnName] = DBNull.Value;
}
xjdmdtRst.Rows.Add(xdr3);
}
xjdmdtRst.Rows.Add(zjdr);
}
xjdmdtRst.Rows.Add(cjdr);
citycount++;
#endregion
}
if (citycount == 0)
{
continue;
}
//foreach (var dlbmitem in dlbmarry)
//{
// xjdr[dlbmitem] = xjdr[dlbmitem].ToDecimal(2) + zjdr[dlbmitem].ToDecimal(2);
//}
foreach (var citem in czcbsarry)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem].Expression))
xjdr[citem] = xjdr[citem].ToDecimal(2) + zjdr[citem].ToDecimal(2);
}
}
return xjdmdtRst;
}
///
/// 清除---11部分细化地类面积汇总表
///
///
/// sql条件
///
public void ClaerNullByDT11(IRDBHelper dbHelper, ref DataTable dt)
{
if (dt != null && dt.Rows.Count > 0)
{
DataTable mjhztjb1 = dbHelper.ExecuteDatatable("tempdt", "select ZLDWDM,DLBM from mjhztjb2 where dlbm like '%A' group by zldwdm,dlbm", true);
DataTable mjhztjb2 = dbHelper.ExecuteDatatable("tempdt", "select ZLDWDM,CZCSXM from mjhztjb2 where CZCSXM IN ('201A','202A','203A') group by zldwdm,CZCSXM", true);
mjhztjb1.PrimaryKey = new DataColumn[] { mjhztjb1.Columns["ZLDWDM"], mjhztjb1.Columns["DLBM"] };
mjhztjb2.PrimaryKey = new DataColumn[] { mjhztjb2.Columns["ZLDWDM"], mjhztjb2.Columns["CZCSXM"] };
for (int i = 0; i < dt.Rows.Count; i++)
{
string XZQDM = dt.Rows[i]["XZQDM"].ToTrim();
if (string.IsNullOrWhiteSpace(XZQDM))
{
dt.Rows[i].Delete();
}
foreach (DataColumn item in dt.Columns)
{
if (!string.IsNullOrWhiteSpace(item.Expression))
continue;
if (item.ColumnName.IndexOf("D2") == 0)
{
if (dt.Rows[i][item.ColumnName].ToTrim() == "0")
{
string c = item.ColumnName.Substring(1);
DataRow[] findrows = mjhztjb2.Select(string.Format("ZLDWDM like '{0}%' and CZCSXM = '{1}'", XZQDM, c));
if (findrows == null || findrows.Length == 0)
{
dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
}
}
}
else if (item.ColumnName.IndexOf("D") == 0)
{
if (dt.Rows[i][item.ColumnName].ToTrim() == "0")
{
string c = item.ColumnName.Substring(1);
DataRow[] findrows = mjhztjb1.Select(string.Format("ZLDWDM like '{0}%' and DLBM ='{1}'", XZQDM, c));
if (findrows == null || findrows.Length == 0)
{
dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
}
}
}
}
}
dt.AcceptChanges();
}
}
#endregion
#region 12湿地调查面积统计表
///
/// 12湿地调查面积统计表
///
///
///
///
///
public bool ExportReportSDDCMJTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
//D0101+D0303+D0304+D0306+D0402+D0603+D1101+D1102+D1103+D1104+D1105+D1106+D1107+D1108
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
//DataTable rest = GetTDLYXZYJFLOrEJFLData(dbHelper);
//RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 17);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
#endregion
#region 13耕地细化调查情况统计表
///
/// 13耕地细化调查情况统计表
///
///
///
///
///
public bool ExportReportGDXHDCQKTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
//DataTable rest = GDXHDCQKTJBData(dbHelper);//通过压盖统计
DataTable rest = GDXHDCQKTJBData(dbHelper);//通过DLTB属性带K的统计
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
//ClaerNullByDT13(dbHelper, ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 23);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 13耕地细化调查情况统计表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportGDXHDCQKTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GDXHDCQKTJBData(dbHelper);//通过DLTB属性带K的统计
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
//ClaerNullByDT13(dbHelper, ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 23);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 13耕地细化调查情况统计表(通过压盖统计)
///
///
///
private DataTable GDXHDCQKTJBData(IRDBHelper dbHelper)
{
string[] dlbmarry = new string[] { "D0101", "D0102", "D0103" };
string[] gdxhlxarry = new string[] { "HDGD", "HQGD", "LQGD", "MQGD", "SHGD", "SMGD", "YJGD" };
//分别查询出县、镇、村个数代码
string xzqdmdt = @"SELECT DISTINCT '' AS XZQMC, substr(ZLDWDM,1,{0}) AS XZQDM FROM " + ReportTableName + " where TBXHDM IS NOT NULL AND TBXHDM IN ('HDGD', 'HQGD', 'LQGD', 'MQGD', 'SHGD', 'SMGD', 'YJGD') AND (D0101>0 or D0102>0 or D0103>0 ) GROUP BY substr(ZLDWDM,1,{0}), TBXHDM";
DataTable xjdmdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 6), true);
if (xjdmdtRst == null || xjdmdtRst.Rows.Count == 0)
{
return xjdmdtRst;
}
DataTable xjdmdtRst2 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 9), true);
DataTable xjdmdtRst3 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 12), true);
string sumSql = @"select substr(ZLDWDM,1,12) AS XZQDM,TBXHDM, SUM(D0101) AS D0101, SUM(D0102) AS D0102, SUM(D0103) as D0103 from " + ReportTableName + " where TBXHDM is not null and TBXHDM IN ('HDGD', 'HQGD', 'LQGD', 'MQGD', 'SHGD', 'SMGD', 'YJGD') AND (D0101>0 or D0102>0 or D0103>0 ) group by substr(ZLDWDM,1,12) ,TBXHDM ORDER BY substr(ZLDWDM,1,12), TBXHDM";
DataTable xjdtRst3 = dbHelper.ExecuteDatatable("statisticType", sumSql, true);
if (xjdtRst3 == null || xjdtRst3.Rows.Count == 0)
{
return xjdmdtRst;
}
//添加总合计列
xjdmdtRst.Columns.Add("HJ", typeof(double));
xjdmdtRst2.Columns.Add("HJ", typeof(double));
xjdmdtRst3.Columns.Add("HJ", typeof(double));
foreach (var citem in gdxhlxarry)
{
//添加耕地类型合计列
xjdmdtRst.Columns.Add(citem + "01", typeof(double));
xjdmdtRst2.Columns.Add(citem + "01", typeof(double));
xjdmdtRst3.Columns.Add(citem + "01", typeof(double));
foreach (var dlbmitem in dlbmarry)
{
xjdmdtRst.Columns.Add(new DataColumn(citem + dlbmitem, typeof(double)));
xjdmdtRst2.Columns.Add(new DataColumn(citem + dlbmitem, typeof(double)));
xjdmdtRst3.Columns.Add(new DataColumn(citem + dlbmitem, typeof(double)));
}
xjdmdtRst.Columns[citem + "01"].Expression = string.Format("{0}D0101 + {0}D0102 + {0}D0103", citem);
xjdmdtRst2.Columns[citem + "01"].Expression = string.Format("{0}D0101 + {0}D0102 + {0}D0103", citem);
xjdmdtRst3.Columns[citem + "01"].Expression = string.Format("{0}D0101 + {0}D0102 + {0}D0103", citem);
}
xjdmdtRst.Columns["HJ"].Expression = "HDGDD0101+HDGDD0102+HDGDD0103+HQGDD0101+HQGDD0102+HQGDD0103+LQGDD0101+LQGDD0102+LQGDD0103+MQGDD0101+MQGDD0102+MQGDD0103+SHGDD0101+SHGDD0102+SHGDD0103+SMGDD0101+SMGDD0102+SMGDD0103+YJGDD0101+YJGDD0102+YJGDD0103";
xjdmdtRst2.Columns["HJ"].Expression = "HDGDD0101+HDGDD0102+HDGDD0103+HQGDD0101+HQGDD0102+HQGDD0103+LQGDD0101+LQGDD0102+LQGDD0103+MQGDD0101+MQGDD0102+MQGDD0103+SHGDD0101+SHGDD0102+SHGDD0103+SMGDD0101+SMGDD0102+SMGDD0103+YJGDD0101+YJGDD0102+YJGDD0103";
xjdmdtRst3.Columns["HJ"].Expression = "HDGDD0101+HDGDD0102+HDGDD0103+HQGDD0101+HQGDD0102+HQGDD0103+LQGDD0101+LQGDD0102+LQGDD0103+MQGDD0101+MQGDD0102+MQGDD0103+SHGDD0101+SHGDD0102+SHGDD0103+SMGDD0101+SMGDD0102+SMGDD0103+YJGDD0101+YJGDD0102+YJGDD0103";
DataRow xjdr = xjdmdtRst.Rows[0];
foreach (var citem in gdxhlxarry)
{
foreach (var dlbmitem in dlbmarry)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem + dlbmitem].Expression))
xjdr[citem + dlbmitem] = 0;
}
}
for (int z = 0; z < xjdmdtRst2.Rows.Count; z++)
{
DataRow zjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
zjdr[item.ColumnName] = xjdmdtRst2.Rows[z][item.ColumnName];
}
xjdmdtRst.Rows.Add(zjdr);
foreach (var citem in gdxhlxarry)
{
foreach (var dlbmitem in dlbmarry)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem + dlbmitem].Expression))
zjdr[citem + dlbmitem] = 0;
}
}
DataRow[] cjdmdtRst = xjdmdtRst3.Select(" XZQDM like '" + xjdmdtRst2.Rows[z]["XZQDM"] + "%'");
for (int c = 0; c < cjdmdtRst.Length; c++)
{
#region 添加村
DataRow cjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
cjdr[item.ColumnName] = cjdmdtRst[c][item.ColumnName];
}
xjdmdtRst.Rows.Add(cjdr);
foreach (var citem in gdxhlxarry)
{
foreach (var dlbmitem in dlbmarry)
{
if (!string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem + dlbmitem].Expression))
continue;
DataRow[] s = xjdtRst3.Select(string.Format(" XZQDM='{0}' and TBXHDM='{1}' ", cjdmdtRst[c]["XZQDM"], citem, dlbmitem));
if (s != null && s.Length > 0)
{
if (s.Length == 1)
cjdr[citem + dlbmitem] = s[0][dlbmitem];
else
cjdr[citem + dlbmitem] = s.CopyToDataTable().Compute(string.Format("SUM({0})", dlbmitem), null);
}
else
{
cjdr[citem + dlbmitem] = 0;
}
}
}
//平差(不能超过当前村最大值)
//GDXHPC(gdxhlxarry, dlbmarry, cjdr);
foreach (var citem in gdxhlxarry)
{
foreach (var dlbmitem in dlbmarry)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem + dlbmitem].Expression))
zjdr[citem + dlbmitem] = zjdr[citem + dlbmitem].ToDecimal(2) + cjdr[citem + dlbmitem].ToDecimal(2);
}
}
#endregion
}
foreach (var citem in gdxhlxarry)
{
foreach (var dlbmitem in dlbmarry)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[citem + dlbmitem].Expression))
xjdr[citem + dlbmitem] = xjdr[citem + dlbmitem].ToDecimal(2) + zjdr[citem + dlbmitem].ToDecimal(2);
}
}
//DataRow xdr3 = xjdmdtRst.NewRow();
//foreach (DataColumn item in xjdmdtRst.Columns)
//{
// xdr3[item.ColumnName] = DBNull.Value;
//}
//xjdmdtRst.Rows.Add(xdr3);
}
return xjdmdtRst;
}
#endregion
#region 14批准未建设的建设用地用途情况统计表
///
/// 14批准未建设的建设用地用途情况统计表
///
///
///
///
///
public bool ExportReportPZWJSDJSYDYTQKTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = PZWJSDJSYDYTQKTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT14(dbHelper, "PZYT", ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 28);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 14批准未建设的建设用地用途情况统计表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportPZWJSDJSYDYTQKTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selelctht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = PZWJSDJSYDYTQKTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, selelctht, ref rest);
ClaerNullByDT14(dbHelper, "PZYT", ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 28);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 14批准未建设的建设用地用途情况统计表
///
///
///
private DataTable PZWJSDJSYDYTQKTJBData(IRDBHelper dbHelper)
{
try
{
string tbl = null;
if (mjconvertvalue2 == "0.0001")
{
tbl = "MJHZJCTJB_PZWJSYD_YT";
}
else
{
tbl = "MJHZJCTJB_PZWJSYD_YT2";
}
string[] dlbmarry = new string[] { "D00", "D0603", "D05", "D05H1", "D0508", "D06", "D0601", "D0602", "D07", "D0701", "D0702", "D08", "D08H1", "D08H2", "D08H2A", "D0809", "D0810", "D0810A", "D09", "D10", "D1001", "D1002", "D1003", "D1004", "D1005", "D1007", "D1008", "D1009", "D11", "D1109" };
//分别查询出县、镇、村个数代码
string xzqdmdt = @"SELECT DISTINCT '' AS XZQMC, substr(ZLDWDM,1,{0}) AS XZQDM FROM " + tbl + " GROUP BY substr(ZLDWDM,1,{0})";
DataTable xjdmdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 6), true);
if (xjdmdtRst == null)
{
RemoveSpecialDLColumns(ref xjdmdtRst);
return xjdmdtRst;
}
DataTable xjdmdtRst2 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 9), true);
DataTable xjdmdtRst3 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 12), true);
//分别查询出县、镇、村个数代码
string lyxzyjflcolumnstr = GetTDLYXZYJFLOrEJFLColunms(dbHelper, ReportTableName);
string sumSql = string.Format(@"SELECT ZLDWDM AS XZQDM {0} FROM " + tbl + " GROUP BY ZLDWDM", lyxzyjflcolumnstr);
DataTable xjdtRst3 = dbHelper.ExecuteDatatable("statisticType", sumSql, true);
if (xjdtRst3 == null)
{
RemoveSpecialDLColumns(ref xjdmdtRst);
return xjdmdtRst;
}
//string hjsql = @"SELECT ZLDWDM AS XZQDM,SUM(TBMJ) AS TBMJ FROM " + tbl + " GROUP BY ZLDWDM";
//DataTable hjdt = dbHelper.ExecuteDatatable("statisticType", hjsql, true);
xjdmdtRst.Columns.Add(new DataColumn("HJ", typeof(decimal)));
xjdmdtRst2.Columns.Add(new DataColumn("HJ", typeof(decimal)));
xjdmdtRst3.Columns.Add(new DataColumn("HJ", typeof(decimal)));
foreach (var dlbmitem in dlbmarry)
{
xjdmdtRst.Columns.Add(new DataColumn(dlbmitem, typeof(decimal)));
xjdmdtRst2.Columns.Add(new DataColumn(dlbmitem, typeof(decimal)));
xjdmdtRst3.Columns.Add(new DataColumn(dlbmitem, typeof(decimal)));
}
xjdmdtRst.Columns["D00"].Expression = "D0603";
xjdmdtRst.Columns["D05"].Expression = "D05H1 + D0508";
xjdmdtRst.Columns["D06"].Expression = "D0601 + D0602";
xjdmdtRst.Columns["D07"].Expression = "D0701 + D0702";
xjdmdtRst.Columns["D08"].Expression = "D08H1+D08H2+D0809+D0810";
xjdmdtRst.Columns["D10"].Expression = "D1001+D1002+D1003+D1004+D1005+D1007+D1008+D1009";
xjdmdtRst.Columns["D11"].Expression = "D1109";
xjdmdtRst2.Columns["D00"].Expression = "D0603";
xjdmdtRst2.Columns["D05"].Expression = "D05H1 + D0508";
xjdmdtRst2.Columns["D06"].Expression = "D0601 + D0602";
xjdmdtRst2.Columns["D07"].Expression = "D0701 + D0702";
xjdmdtRst2.Columns["D08"].Expression = "D08H1+D08H2+D0809+D0810";
xjdmdtRst2.Columns["D10"].Expression = "D1001+D1002+D1003+D1004+D1005+D1007+D1008+D1009";
xjdmdtRst2.Columns["D11"].Expression = "D1109";
xjdmdtRst3.Columns["D00"].Expression = "D0603";
xjdmdtRst3.Columns["D05"].Expression = "D05H1 + D0508";
xjdmdtRst3.Columns["D06"].Expression = "D0601 + D0602";
xjdmdtRst3.Columns["D07"].Expression = "D0701 + D0702";
xjdmdtRst3.Columns["D08"].Expression = "D08H1+D08H2+D0809+D0810";
xjdmdtRst3.Columns["D10"].Expression = "D1001+D1002+D1003+D1004+D1005+D1007+D1008+D1009";
xjdmdtRst3.Columns["D11"].Expression = "D1109";
if (xjdmdtRst.Rows.Count == 0)
{
RemoveSpecialDLColumns(ref xjdmdtRst);
return xjdmdtRst;
}
DataRow xjdr = xjdmdtRst.Rows[0];
foreach (var dlbmitem in dlbmarry)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[dlbmitem].Expression))
xjdr[dlbmitem] = decimal.Zero;
}
for (int z = 0; z < xjdmdtRst2.Rows.Count; z++)
{
DataRow zjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
zjdr[item.ColumnName] = xjdmdtRst2.Rows[z][item.ColumnName];
}
xjdmdtRst.Rows.Add(zjdr);
foreach (var dlbmitem in dlbmarry)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[dlbmitem].Expression))
zjdr[dlbmitem] = 0M;
}
DataRow[] cjdmdtRst = xjdmdtRst3.Select(" XZQDM like '" + xjdmdtRst2.Rows[z]["XZQDM"] + "%'");
for (int c = 0; c < cjdmdtRst.Length; c++)
{
#region 添加村
DataRow cjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
if (string.IsNullOrWhiteSpace(item.Expression))
cjdr[item.ColumnName] = cjdmdtRst[c][item.ColumnName];
}
xjdmdtRst.Rows.Add(cjdr);
foreach (var dlbmitem in dlbmarry)
{
DataRow[] s = xjdtRst3.Select(string.Format(" XZQDM='{0}'", cjdmdtRst[c]["XZQDM"]));
if (s != null && s.Length > 0)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[dlbmitem].Expression))
{
if (s.Length == 1)
cjdr[dlbmitem] = s[0][dlbmitem].ToDecimal();
else
cjdr[dlbmitem] = s.CopyToDataTable().Compute(string.Format("SUM({0})", dlbmitem), null);
}
}
else
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[dlbmitem].Expression))
cjdr[dlbmitem] = 0M;
}
cjdr["HJ"] = cjdr["HJ"].ToDecimal(2) + cjdr[dlbmitem].ToDecimal(2);
}
//行内平差
PZWJSYTPC(dlbmarry, cjdr, xjdmdtRst);
foreach (var dlbmitem in dlbmarry)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[dlbmitem].Expression))
zjdr[dlbmitem] = zjdr[dlbmitem].ToDecimal(2) + cjdr[dlbmitem].ToDecimal(2);
}
zjdr["HJ"] = zjdr["HJ"].ToDecimal(2) + cjdr["HJ"].ToDecimal(2);
#endregion
}
foreach (var dlbmitem in dlbmarry)
{
if (string.IsNullOrWhiteSpace(xjdmdtRst.Columns[dlbmitem].Expression))
xjdr[dlbmitem] = xjdr[dlbmitem].ToDecimal(2) + zjdr[dlbmitem].ToDecimal(2);
}
xjdr["HJ"] = xjdr["HJ"].ToDecimal(2) + zjdr["HJ"].ToDecimal(2);
}
foreach (DataRow dr in xjdmdtRst.Rows)
{
foreach (DataColumn dc in xjdmdtRst.Columns)
{
string strColName = dc.ColumnName;
if (!char.IsNumber(strColName, strColName.Length - 1) && strColName.Substring(0, 1) == "D")
{
string strColName2 = strColName.Substring(0, strColName.Length - 1);
if (xjdmdtRst.Columns.Contains(strColName2))
{
dr[strColName2] = dr[strColName2].ToDecimal(2) + dr[strColName].ToDecimal(2);
}
}
}
}
RemoveSpecialDLColumns(ref xjdmdtRst);
return xjdmdtRst;
}
catch (Exception ex)
{
LogAPI.Debug("获取 批准未建设的建设用地用途情况统计表 数据异常: " + ex + " ; ");
return null;
}
}
private void PZWJSYTPC(string[] dlbmarry, DataRow cjdr, DataTable dt)
{
try
{
#region 行内平差
bool pc = true;
while (pc)
{
pc = false;
decimal h = 0;
Dictionary updateejdldic = new Dictionary();
foreach (var dlbmitem in dlbmarry)
{
if (!string.IsNullOrWhiteSpace(dt.Columns[dlbmitem].Expression))
continue;
decimal tempv = 0;
tempv = cjdr[dlbmitem].ToDecimal(2);
if (tempv < 0)
{
tempv = 0;
cjdr[dlbmitem] = tempv;
}
h = h + tempv;
if (tempv > 0)
{
updateejdldic.Add(dlbmitem, tempv);
}
}
decimal g = cjdr["HJ"].ToDecimal(2);
decimal zfvalue = 1;
decimal mjc = 0;
decimal js = (decimal)0.01;//调平基数0.01
if (h > g)
{
zfvalue = -1;
mjc = h - g;
}
else
{
mjc = g - h;
}
//如果面积差值大于0,进行平差
if (mjc > 0)
{
int tpsm = (int)(mjc / js);
int cjzsm = updateejdldic.Count;
int e = tpsm / cjzsm;
int f = tpsm % cjzsm;
if (f > 0)
{
//余数村调平面积值
decimal ftpzmj = (e + 1) * js;
for (int x = 0; x < f; x++)
{
if (string.IsNullOrWhiteSpace(dt.Columns[updateejdldic.ElementAt(x).Key].Expression))
cjdr[updateejdldic.ElementAt(x).Key] = updateejdldic.ElementAt(x).Value + ftpzmj * zfvalue;
}
}
if (e > 0)
{
//商数村调平面积值
decimal ftpzmj = e * js;
for (int x = f; x < cjzsm; x++)
{
if (string.IsNullOrWhiteSpace(dt.Columns[updateejdldic.ElementAt(x).Key].Expression))
cjdr[updateejdldic.ElementAt(x).Key] = updateejdldic.ElementAt(x).Value + ftpzmj * zfvalue;
}
}
pc = true;
continue;
}
}
#endregion
}
catch (Exception ex)
{
LogAPI.Debug("批准未建设的建设用地用途情况统计表 行内平差异常: " + ex + " ; ");
return;
}
}
///
/// 清除---1土地利用现状一级分类面积汇总表
///
///
/// 列名
///
public void ClaerNullByDT14(IRDBHelper dbHelper, string cname, ref DataTable dt)
{
if (dt != null && dt.Rows.Count > 0)
{
DataTable mjhztjb2 = dbHelper.ExecuteDatatable("tempdt", "select ZLDWDM," + cname + " as DLBM from DLTB_PZWJSTD group by zldwdm," + cname, true);
if (mjhztjb2 == null || mjhztjb2.Rows.Count == 0)
{
return;
}
mjhztjb2.PrimaryKey = new DataColumn[] { mjhztjb2.Columns["ZLDWDM"], mjhztjb2.Columns["DLBM"] };
for (int i = 0; i < dt.Rows.Count; i++)
{
string XZQDM = dt.Rows[i]["XZQDM"].ToTrim();
if (string.IsNullOrWhiteSpace(XZQDM))
{
continue;
}
foreach (DataColumn item in dt.Columns)
{
if (!string.IsNullOrWhiteSpace(item.Expression))
continue;
if (item.ColumnName.IndexOf("D") == 0)
{
if (dt.Rows[i][item.ColumnName].ToTrim() == "0")
{
string c = item.ColumnName.Substring(1);
DataRow[] findrows = mjhztjb2.Select(string.Format("ZLDWDM like '{0}%' and DLBM like '{1}%'", XZQDM, c));
if (findrows == null || findrows.Length == 0)
{
dt.Rows[i][item.ColumnName] = 0D.ToDecimal(2);
}
}
}
}
}
}
}
#endregion
#region 15批准未建设的建设用地现状情况统计表
///
/// 15批准未建设的建设用地现状情况统计表
///
///
///
///
///
public bool ExportReportPZWJSDJSYDXZQKTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = PZWJSDJSYDXZQKTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT14(dbHelper, "DLBM", ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 68);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 15批准未建设的建设用地现状情况统计表
///
///
///
///
/// 多选设置后重载方法 王欢 2018-09-29
public bool ExportReportPZWJSDJSYDXZQKTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = PZWJSDJSYDXZQKTJBData(dbHelper);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT14(dbHelper, "DLBM", ref rest);
//OutExcel(rest, savePath, reportTempaltePath, 5, 1, 68);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 15批准未建设的建设用地现状情况统计表
///
///
///
private DataTable PZWJSDJSYDXZQKTJBData(IRDBHelper dbHelper)
{
try
{
string tbl = null;
if (mjconvertvalue2 == "0.0001")
{
tbl = "MJHZJCTJB_PZWJSYD";
}
else
{
tbl = "MJHZJCTJB_PZWJSYD2";
}
List columnlist = new List();
List dlbmlist;
List ejdllist;
DataTable mjhzdt = dbHelper.ExecuteDatatable("hztjb", "select * from " + tbl + " where 1=2", true);
MJHZJCTJBHelper mh = new MJHZJCTJBHelper();
mh.GetDLBMListByDT(mjhzdt, out dlbmlist, out ejdllist);
string xzqdmdt = @"SELECT '' AS XZQMC, substr(ZLDWDM,1,{0}) AS XZQDM, SUM(TBZMJ) AS HJ FROM " + tbl + " GROUP BY substr(ZLDWDM,1,{0})";
DataTable xjdmdtRst = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 6), true);
if (xjdmdtRst == null)
{
RemoveSpecialDLColumns(ref xjdmdtRst);
return xjdmdtRst;
}
DataTable xjdmdtRst2 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 9), true);
DataTable xjdmdtRst3 = dbHelper.ExecuteDatatable("statisticType", string.Format(xzqdmdt, 12), true);
//分别查询出县、镇、村个数代码
string lyxzyjflcolumnstr = GetTDLYXZYJFLOrEJFLColunms(dbHelper, ReportTableName);
string sumSql = string.Format(@"SELECT ZLDWDM AS XZQDM {0} FROM " + tbl + " GROUP BY ZLDWDM", lyxzyjflcolumnstr);
DataTable xjdtRst3 = dbHelper.ExecuteDatatable("statisticType", sumSql, true);
if (xjdtRst3 == null)
{
RemoveSpecialDLColumns(ref xjdmdtRst);
return xjdmdtRst;
}
//string hjsql = @"SELECT ZLDWDM AS XZQDM,SUM(TBMJ) AS TBMJ FROM " + tbl + " GROUP BY ZLDWDM";
//DataTable hjdt = dbHelper.ExecuteDatatable("statisticType", hjsql, true);
//xjdmdtRst.Columns.Add(new DataColumn("HJ", typeof(double)));
//xjdmdtRst2.Columns.Add(new DataColumn("HJ", typeof(double)));
//xjdmdtRst3.Columns.Add(new DataColumn("HJ", typeof(double)));
//columnlist.Add("HJ");
foreach (var dlbmitem in dlbmlist)
{
columnlist.Add("D" + dlbmitem.YJDL);
xjdmdtRst.Columns.Add(new DataColumn("D" + dlbmitem.YJDL, typeof(double)));
xjdmdtRst2.Columns.Add(new DataColumn("D" + dlbmitem.YJDL, typeof(double)));
xjdmdtRst3.Columns.Add(new DataColumn("D" + dlbmitem.YJDL, typeof(double)));
if (dlbmitem.EJDLList != null && dlbmitem.EJDLList.Count > 0)
{
foreach (var ejdlitem in dlbmitem.EJDLList)
{
columnlist.Add("D" + ejdlitem);
xjdmdtRst.Columns.Add(new DataColumn("D" + ejdlitem, typeof(double)));
xjdmdtRst2.Columns.Add(new DataColumn("D" + ejdlitem, typeof(double)));
xjdmdtRst3.Columns.Add(new DataColumn("D" + ejdlitem, typeof(double)));
}
}
}
if (xjdmdtRst.Rows.Count == 0)
{
RemoveSpecialDLColumns(ref xjdmdtRst);
return xjdmdtRst;
}
DataRow xjdr = xjdmdtRst.Rows[0];
for (int z = 0; z < xjdmdtRst2.Rows.Count; z++)
{
DataRow zjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
zjdr[item.ColumnName] = xjdmdtRst2.Rows[z][item.ColumnName];
}
xjdmdtRst.Rows.Add(zjdr);
foreach (var dlbmitem in columnlist)
{
zjdr[dlbmitem] = 0;
}
DataRow[] cjdmdtRst = xjdmdtRst3.Select("XZQDM like '" + xjdmdtRst2.Rows[z]["XZQDM"] + "%'");
for (int c = 0; c < cjdmdtRst.Length; c++)
{
#region 添加村
DataRow cjdr = xjdmdtRst.NewRow();
foreach (DataColumn item in xjdmdtRst.Columns)
{
cjdr[item.ColumnName] = cjdmdtRst[c][item.ColumnName];
}
xjdmdtRst.Rows.Add(cjdr);
foreach (var dlbmitem in dlbmlist)
{
if (dlbmitem.EJDLList != null && dlbmitem.EJDLList.Count > 0)
{
foreach (var ejdlitem in dlbmitem.EJDLList)
{
if (!xjdmdtRst.Columns.Contains("D" + ejdlitem))
continue;
DataRow[] s = xjdtRst3.Select(string.Format("XZQDM = '{0}'", cjdmdtRst[c]["XZQDM"]));
if (s != null && s.Length > 0)
{
if (s.Length == 1)
{
cjdr["D" + ejdlitem] = s[0]["D" + ejdlitem];
}
else
{
cjdr["D" + ejdlitem] = s.CopyToDataTable().Compute(string.Format("SUM(D{0})", ejdlitem), null);
}
}
else
{
cjdr["D" + ejdlitem] = 0D;
}
cjdr["D" + dlbmitem.YJDL] = cjdr["D" + dlbmitem.YJDL].ToDecimal(2) + cjdr["D" + ejdlitem].ToDecimal(2);
}
}
else
{
if (!xjdmdtRst.Columns.Contains("D" + dlbmitem.YJDL))
continue;
DataRow[] s = xjdtRst3.Select(string.Format("XZQDM = '{0}'", cjdmdtRst[c]["XZQDM"]));
if (s != null && s.Length > 0)
{
if (s.Length == 1)
{
cjdr["D" + dlbmitem.YJDL] = s[0]["D" + dlbmitem.YJDL];
}
else
{
cjdr["D" + dlbmitem.YJDL] = s.CopyToDataTable().Compute(string.Format("SUM(D{0})", dlbmitem.YJDL), null);
}
}
else
{
cjdr["D" + dlbmitem.YJDL] = 0;
}
}
//cjdr["HJ"] = cjdr["HJ"].ToDecimal(2) + cjdr["D" + dlbmitem.YJDL].ToDecimal(2);
}
//cjdr["HJ"] = hjdt.Select(" XZQDM = '" + cjdmdtRst[c]["XZQDM"] + "'")[0]["TBMJ"];
//行内平差
PZWJSXZPC(dlbmlist, cjdr);
foreach (var dlbmitem in columnlist)
{
zjdr[dlbmitem] = zjdr[dlbmitem].ToDecimal(2) + cjdr[dlbmitem].ToDecimal(2);
}
#endregion
}
foreach (var dlbmitem in columnlist)
{
xjdr[dlbmitem] = xjdr[dlbmitem].ToDecimal(2) + zjdr[dlbmitem].ToDecimal(2);
}
//DataRow xdr3 = xjdmdtRst.NewRow();
//foreach (DataColumn item in xjdmdtRst.Columns)
//{
// xdr3[item.ColumnName] = DBNull.Value;
//}
//xjdmdtRst.Rows.Add(xdr3);
}
foreach (DataRow dr in xjdmdtRst.Rows)
{
foreach (DataColumn dc in xjdmdtRst.Columns)
{
string strColName = dc.ColumnName;
if (!char.IsNumber(strColName, strColName.Length - 1) && strColName.Substring(0, 1) == "D")
{
string strColName2 = strColName.Substring(0, strColName.Length - 1);
if (xjdmdtRst.Columns.Contains(strColName2))
{
dr[strColName2] = dr[strColName2].ToDecimal(2) + dr[strColName].ToDecimal(2);
}
}
}
}
RemoveSpecialDLColumns(ref xjdmdtRst);
return xjdmdtRst;
}
catch (Exception ex)
{
LogAPI.Debug("批准未建设的建设用地现状情况统计表 导出异常: " + ex + " ; ");
return null;
}
}
///
/// 将 批准未建设的建设用地用途情况统计表/批准未建设的建设用地现状情况统计表 数据表中的特殊地类(以A或者K结尾)字段去掉
///
///
public void RemoveSpecialDLColumns(ref DataTable dtDealWith)
{
bool bRecordLog_ = false;
string strColName = "";
DataColumn dc = null;
try
{
if (dtDealWith.Columns == null || dtDealWith.Columns.Count <= 0)
{
return;
}
int iRemoveCount_Temp = 0;
for (int i = dtDealWith.Columns.Count - 1; i >= 0; i--)
{
dc = dtDealWith.Columns[i];
strColName = dc.ColumnName;
if (bRecordLog_ == true)
{
LogAPI.Debug("当前判断的字段:[" + strColName + "];\r\n");
}
if (!char.IsNumber(strColName, strColName.Length - 1) && strColName.Substring(0, 1) == "D")
{//当前判断的字段列 最后一个不是数字,且以D开头;
if (bRecordLog_ == true)
{
LogAPI.Debug("当前判断的字段列: " + strColName + " ; ");
LogAPI.Debug("移除的字段列: " + dc + " ; ");
}
dtDealWith.Columns.Remove(dc);
iRemoveCount_Temp += 1;
}
}
if (bRecordLog_ == true)
{
LogAPI.Debug("本次操作共移除字段 " + iRemoveCount_Temp + " 个;\r\n");
}
return;
}
catch (Exception ex)
{
LogAPI.Debug("排除 批准未建设的建设用地现状情况统计表 中的A或K结尾的字段信息时异常: " + ex + " ; ");
return;
}
}
///
/// 16永久基本农田现状情况统计表
///
///
///
///
///
public bool ExportReportYJJBNTXZQKTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
//AE.WorkspaceAPI worksapi = new AE.WorkspaceAPI(Env.Instance.Project.GetProjMDBPath(), AE.Enum.WorkspaceTypeEnum.MDBFile);
//worksapi.DeleteFeatureClass("DLTB_YJJBNTTB");
DataTable rest = YJJBNTXZQKTJBData(dbHelper, reportEntity);
//System.Threading.Thread.Sleep(1000);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
//ClaerNullByDT14(dbHelper, "DLBM", ref rest);
rest = GetUpLevelData(rest, 2, rest.Columns.Count - 3);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 16永久基本农田现状情况统计表
///
///
///
///
///
///
public bool ExportReportYJJBNTXZQKTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
//AE.WorkspaceAPI worksapi = new AE.WorkspaceAPI(Env.Instance.Project.GetProjMDBPath(), AE.Enum.WorkspaceTypeEnum.MDBFile);
//worksapi.DeleteFeatureClass("DLTB_YJJBNTTB");
DataTable rest = YJJBNTXZQKTJBData(dbHelper, reportEntity);
System.Threading.Thread.Sleep(500);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
System.Threading.Thread.Sleep(500);
//ClaerNullByDT14(dbHelper, "DLBM", ref rest);
rest = GetUpLevelData(rest, 2, rest.Columns.Count - 3);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
return true;
}
private DataTable YJJBNTXZQKTJBData(IRDBHelper dbHelper, ReportEntityClass reportEntity)
{
StringBuilder sbSQL = new StringBuilder();
sbSQL.Append("SELECT ");
sbSQL.Append(" ZLDWMC as XZQMC");
sbSQL.Append(" ,substr(ZLDWDM,1, 12) as xzqdm");
sbSQL.Append(" ,SUM(TBZMJ) * {0} as XZQYZMJ");
//sbSQL.AppendLine(" ,Round(0) as DL01");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0101', TBMJ, 0)) * {0} as DL0101");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0102', TBMJ, 0)) * {0} as DL0102");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0103', TBMJ, 0)) * {0} as DL0103");
//sbSQL.AppendLine(" ,Round(0) as HJ");
//sbSQL.AppendLine(" ,Round(0) as DL00");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0303', TBMJ, 0)) * {0} as DL0001");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0304', TBMJ, 0)) * {0} as DL0002");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0306', TBMJ, 0)) * {0} as DL0003");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0402', TBMJ, 0)) * {0} as DL0004");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0603', TBMJ, 0)) * {0} as DL0005");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1105', TBMJ, 0)) * {0} as DL0006");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1106', TBMJ, 0)) * {0} as DL0007");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1108', TBMJ, 0)) * {0} as DL0008");
//sbSQL.AppendLine(" ,Round(0) as DL02");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0201', TBMJ, 0)) * {0} + SUM(iif(DLBM = '0201K', TBMJ, 0)) * {0} as DL0201");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0202', TBMJ, 0)) * {0} + SUM(iif(DLBM = '0202K', TBMJ, 0)) * {0} as DL0202");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0203', TBMJ, 0)) * {0} + SUM(iif(DLBM = '0203K', TBMJ, 0)) * {0} as DL0203");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0204', TBMJ, 0)) * {0} + SUM(iif(DLBM = '0204K', TBMJ, 0)) * {0} as DL0204");
//sbSQL.AppendLine(" ,Round(0) as DL03");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0301', TBMJ, 0)) * {0} + SUM(iif(DLBM = '0301K', TBMJ, 0)) * {0} as DL0301");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0302', TBMJ, 0)) * {0} + SUM(iif(DLBM = '0302K', TBMJ, 0)) * {0} as DL0302");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0305', TBMJ, 0)) * {0} as DL0305");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0307', TBMJ, 0)) * {0} + SUM(iif(DLBM = '0307K', TBMJ, 0)) * {0} as DL0307");
//sbSQL.AppendLine(" ,Round(0) as DL04");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0401', TBMJ, 0)) * {0} as DL0401");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0403', TBMJ, 0)) * {0} + SUM(iif(DLBM = '0403K', TBMJ, 0)) * {0} as DL0403");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0404', TBMJ, 0)) * {0} as DL0404");
//sbSQL.AppendLine(" ,Round(0) as DL05");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '05H1', TBMJ, 0)) * {0} as DL05H1");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0508', TBMJ, 0)) * {0} as DL0508");
//sbSQL.AppendLine(" ,Round(0) as DL06");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0601', TBMJ, 0)) * {0} as DL0601");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0602', TBMJ, 0)) * {0} as DL0602");
//sbSQL.AppendLine(" ,Round(0) as DL07");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0701', TBMJ, 0)) * {0} as DL0701");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0702', TBMJ, 0)) * {0} as DL0702");
//sbSQL.AppendLine(" ,Round(0) as DL08");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '08H1', TBMJ, 0)) * {0} as DL08H1");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '08H2', TBMJ, 0)) * {0} + SUM(iif(DLBM = '08H2A', TBMJ, 0)) * {0} as DL08H2");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0809', TBMJ, 0)) * {0} as DL0809");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '0810', TBMJ, 0)) * {0} + SUM(iif(DLBM = '0810A', TBMJ, 0)) * {0} as DL0810");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '09', TBMJ, 0)) * {0} as DL09");
//sbSQL.AppendLine(" ,Round(0) as DL10");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1001', TBMJ, 0)) * {0} as DL1001");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1002', TBMJ, 0)) * {0} as DL1002");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1003', TBMJ, 0)) * {0} as DL1003");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1004', TBMJ, 0)) * {0} as DL1004");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1005', TBMJ, 0)) * {0} as DL1005");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1006', TBMJ, 0)) * {0} as DL1006");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1007', TBMJ, 0)) * {0} as DL1007");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1008', TBMJ, 0)) * {0} as DL1008");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1009', TBMJ, 0)) * {0} as DL1009");
//sbSQL.AppendLine(" ,Round(0) as DL11");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1101', TBMJ, 0)) * {0} as DL1101");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1102', TBMJ, 0)) * {0} as DL1102");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1103', TBMJ, 0)) * {0} as DL1103");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1104', TBMJ, 0)) * {0} + SUM(iif(DLBM = '1104A', TBMJ, 0)) * {0} + SUM(iif(DLBM = '1104K', TBMJ, 0)) * {0} as DL1104");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1107', TBMJ, 0)) * {0} + SUM(iif(DLBM = '1107A', TBMJ, 0)) * {0} as DL1107");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1109', TBMJ, 0)) * {0} as DL1109");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1110', TBMJ, 0)) * {0} as DL1110");
//sbSQL.AppendLine(" ,Round(0) as DL12 ");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1201', TBMJ, 0)) * {0} as DL1201");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1202', TBMJ, 0)) * {0} as DL1202");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1203', TBMJ, 0)) * {0} as DL1203");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1204', TBMJ, 0)) * {0} as DL1204");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1205', TBMJ, 0)) * {0} as DL1205");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1206', TBMJ, 0)) * {0} as DL1206");
//sbSQL.AppendLine(" ,SUM(iif(DLBM = '1207', TBMJ, 0)) * {0} as DL1207");
sbSQL.Append(" ,SUM(D01) * {0} as DL01");
sbSQL.Append(" ,SUM(D0101) * {0} as DL0101");
sbSQL.Append(" ,SUM(D0102) * {0} as DL0102");
sbSQL.Append(" ,SUM(D0103) * {0} as DL0103");
sbSQL.Append(" ,Round(0) * {0} as HJ");
sbSQL.Append(" ,SUM(D00) * {0} as DL00");
sbSQL.Append(" ,SUM(D02) * {0} as DL02");
sbSQL.Append(" ,SUM(D03) * {0} as DL03");
sbSQL.Append(" ,SUM(D04) * {0} as DL04");
sbSQL.Append(" ,SUM(D05) * {0} as DL05");
sbSQL.Append(" ,SUM(D06) * {0} as DL06");
sbSQL.Append(" ,SUM(D07) * {0} as DL07");
sbSQL.Append(" ,SUM(D08) * {0} as DL08");
sbSQL.Append(" ,SUM(D09) * {0} as DL09");
sbSQL.Append(" ,SUM(D10) * {0} as DL10");
sbSQL.Append(" ,SUM(D11) * {0} as DL11");
sbSQL.Append(" ,SUM(D12) * {0} as DL12 ");
sbSQL.Append(" ,substr(ZLDWDM,1, 9) as xzqdm_t");
sbSQL.Append(" ,substr(ZLDWDM,1, 6) as xzqdm_c");
sbSQL.Append(" FROM ");
object obj = dbHelper.ExecuteScalar("SELECT count(OBJECTID) FROM YJJBNTTB", CommandType.Text);
int cnt = int.Parse(obj.ToString());
if (cnt == 0)
{
sbSQL.AppendLine(" MJHZJCTJB");
sbSQL.AppendLine(" WHERE 0 = 1");
}
else
{
sbSQL.AppendLine(" MJHZJCTJB_YJJBNTTB");
}
sbSQL.Append(" GROUP BY ZLDWDM, ZLDWMC");
sbSQL.Append(" ORDER BY substr(ZLDWDM,1, 12)");
string reportSql = sbSQL.ToString();
if (mjconvertvalue2 == "0.0001")
{
reportSql = string.Format(reportSql, "1");
}
else if (mjconvertvalue2 == "0.0015")
{
reportSql = string.Format(reportSql, "15");
}
else if (mjconvertvalue2 == "1")
{
reportSql = string.Format(reportSql, "10000");
}
DataTable dtRst = dbHelper.ExecuteDatatable("YJJBNTXZQKTJB", reportSql, true);
dtRst.Columns["HJ"].Expression = "DL00 + DL02 + DL03 + DL04 + DL05 + DL06 + DL07 + DL08 + DL09 + DL10 + DL11 + DL12";
//List ColList = dtRst.Columns.Cast().ToList();
//for (int i = 0; i <= 12; i++)
//{
// string colname = string.Format("DL{0:D2}", i);
// string colexpr = string.Empty;
// List list = ColList.Where(x => x.ColumnName.Contains(colname) && x.ColumnName != colname).ToList();
// for (int j = 0; j < list.Count; j++)
// {
// DataColumn dc = list[j];
// if (j == 0)
// colexpr = string.Format("[{0}]", dc.ColumnName);
// else
// colexpr = string.Format("{0} + [{1}]", colexpr, dc.ColumnName);
// }
// //Bug-14566 霍岩 2018-03-21 09地类无子地类不参与相加
// if (i != 9)
// dtRst.Columns[colname].Expression = colexpr;
//}
//List list2 = ColList.Where(x => x.ColumnName.Contains("DL") && x.ColumnName.Length > 4 || x.ColumnName == "DL09").ToList();
//string colexpr2 = string.Empty;
//for (int j = 0; j < list2.Count; j++)
//{
// DataColumn dc = list2[j];
// if (j == 0)
// colexpr2 = string.Format("[{0}]", dc.ColumnName);
// else
// colexpr2 = string.Format("{0} + [{1}]", colexpr2, dc.ColumnName);
//}
//dtRst.Columns["XZQYZMJ"].Expression = colexpr2;
//string colexpr3 = string.Empty;
//for (int j = 0; j < list2.Count; j++)
//{
// DataColumn dc = list2[j];
// if (dc.ColumnName.Contains("DL01"))
// continue;
// if (j == 3)
// colexpr3 = string.Format("[{0}]", dc.ColumnName);
// else
// colexpr3 = string.Format("{0} + [{1}]", colexpr3, dc.ColumnName);
//}
//dtRst.Columns["HJ"].Expression = colexpr3;
//dtRst = GetUpLevelData(dtRst, 2, dtRst.Columns.Count - 3);
//ColList.RemoveAt(ColList.Count - 1);
//ColList.RemoveAt(ColList.Count - 1);
//for (int i = ColList.Count - 1; i >= 0; i--)
//{
// DataColumn dc = ColList[i];
// if (dc.ColumnName.Contains("DL") && !dc.ColumnName.Contains("DL01") && dc.ColumnName.Length > 4)
// ColList.RemoveAt(i);
//}
//string[] strColNames = new string[ColList.Count];
//for (int i = 0; i < strColNames.Length; i++)
//{
// strColNames[i] = ColList[i].ColumnName;
//}
//DataTable dtRST2 = dtRst.DefaultView.ToTable(false, strColNames);
//dtRst = GetUpLevelData(dtRst, 2, dtRst.Columns.Count - 3);
//dtRst.Columns.RemoveAt(dtRst.Columns.Count - 1);
//dtRst.Columns.RemoveAt(dtRst.Columns.Count - 1);
return dtRst;
}
public bool ExportReportWJMHDTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = WJMHDTJBData(dbHelper, reportEntity);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
//ClaerNullByDT14(dbHelper, "DLBM", ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 6, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
public bool ExportReportWJMHDTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = WJMHDTJBData(dbHelper, reportEntity);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
//ClaerNullByDT14(dbHelper, "DLBM", ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 6);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
private DataTable WJMHDTJBData(IRDBHelper dbHelper, ReportEntityClass reportEntity)
{
StringBuilder sbSQL = new StringBuilder();
sbSQL.Append("SELECT");
sbSQL.Append(" ZLDWMC AS XZQMC");
sbSQL.Append(" ,substr(ZLDWDM,1, 12) AS XZQDM");
sbSQL.Append(" ,Round(0) as HDZMJ");
sbSQL.Append(" ,Round(0) as HD1");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i101'then MJ else 0 end) * {0}, 2) AS HD101");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i102'then MJ else 0 end) * {0}, 2) AS HD102");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i103'then MJ else 0 end) * {0}, 2) AS HD103");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i104'then MJ else 0 end) * {0}, 2) AS HD104");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i105'then MJ else 0 end) * {0}, 2) AS HD105");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i106'then MJ else 0 end) * {0}, 2) AS HD106");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i107'then MJ else 0 end) * {0}, 2) AS HD107");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i108'then MJ else 0 end) * {0}, 2) AS HD108");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i109'then MJ else 0 end) * {0}, 2) AS HD109");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i110'then MJ else 0 end) * {0}, 2) AS HD110");
sbSQL.Append(" ,Round(0) AS HD2");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i201'then MJ else 0 end ) * {0}, 2) AS HD201");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i202'then MJ else 0 end ) * {0}, 2) AS HD202");
sbSQL.Append(" ,Round(0) AS HD202_1");
sbSQL.Append(" ,ROUND(SUM(case when LYXZFLBM = 'i203' then MJ else 0 end) * {0}, 2) AS HD203");
sbSQL.Append(" ,substr(ZLDWDM,1, 9) as xzqdm_t");
sbSQL.Append(" ,substr(ZLDWDM,1, 6) as xzqdm_c");
sbSQL.Append(" FROM ");
sbSQL.Append(" WJMHD ");
sbSQL.Append(" GROUP BY ZLDWDM, ZLDWMC");
sbSQL.Append(" ORDER BY ZLDWDM");
string reportSql = sbSQL.ToString();
if (mjconvertvalue2 == "0.0001")
{
reportSql = string.Format(reportSql, "0.0001");
}
else if (mjconvertvalue2 == "15")
{
reportSql = string.Format(reportSql, "0.0015");
}
else
{
reportSql = string.Format(reportSql, "1");
}
DataTable dtRst = dbHelper.ExecuteDatatable("WJMHDTJB", reportSql, true);
dtRst.Columns["HD1"].Expression = "HD101 + HD102 + HD103 + HD104 + HD105 + HD106 + HD107 + HD108 + HD109 + HD110";
dtRst.Columns["HD2"].Expression = "HD201 + HD202 + HD203";
dtRst.Columns["HDZMJ"].Expression = string.Format("{0} + {1}", dtRst.Columns["HD1"].Expression, dtRst.Columns["HD2"].Expression);
dtRst = GetUpLevelData(dtRst, 2, dtRst.Columns.Count - 3);
return dtRst;
}
public bool ExportReportJKHFGCHFZZTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetGDZZLXMJTJBData(dbHelper, true);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT5(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
public bool ExportReportJKHFGCHFZZTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetGDZZLXMJTJBData(dbHelper, true);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT5(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
public bool ExportReportFQXHBZTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, string sNMKMDBPath = "")
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetGDZZLXMJTJBData(dbHelper, false, true);
RemoveDRByXZQDM(dbHelper, reportEntity.XZQTreeNode, ref rest);
ClaerNullByDT5(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5, "DLTB", sNMKMDBPath);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
public bool ExportReportFQXHBZTJB(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = GetGDZZLXMJTJBData(dbHelper, false, true);
RemoveDRByXZQDM(dbHelper, selectht, ref rest);
ClaerNullByDT5(dbHelper, ref rest);
GetXZQMC(dbHelper, ref rest);
OutExcel2(rest, savePath, reportTempaltePath, null, null, 5);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 行内平差
///
///
///
private void PZWJSXZPC(List dlbmlist, DataRow cjdr)
{
try
{
#region 行内平差
bool pc = true;
while (pc)
{
pc = false;
decimal h = 0;
Dictionary updateejdldic = new Dictionary();
foreach (var dlbmitem in dlbmlist)
{
decimal tempv = 0;
if (dlbmitem.EJDLList != null && dlbmitem.EJDLList.Count > 0)
{
foreach (var ejdlitem in dlbmitem.EJDLList)
{
tempv = cjdr["D" + ejdlitem].ToDecimal(2);
if (tempv < 0)
{
tempv = 0;
cjdr["D" + ejdlitem] = tempv;
}
h = h + tempv;
if (tempv > 0)
{
updateejdldic.Add("D" + ejdlitem, tempv);
}
}
}
else
{
tempv = cjdr["D" + dlbmitem.YJDL].ToDecimal(2);
if (tempv < 0)
{
tempv = 0;
cjdr["D" + dlbmitem.YJDL] = tempv;
}
h = h + tempv;
if (tempv > 0)
{
updateejdldic.Add("D" + dlbmitem.YJDL, tempv);
}
}
}
decimal g = cjdr["HJ"].ToDecimal(2);
decimal zfvalue = 1;
decimal mjc = 0;
decimal js = (decimal)0.01;//调平基数0.01
if (h > g)
{
zfvalue = -1;
mjc = h - g;
}
else
{
mjc = g - h;
}
//如果面积差值大于0,进行平差
if (mjc > 0)
{
int tpsm = (int)(mjc / js);
int cjzsm = updateejdldic.Count;
int e = tpsm / cjzsm;
int f = tpsm % cjzsm;
if (f > 0)
{
//余数村调平面积值
decimal ftpzmj = (e + 1) * js;
for (int x = 0; x < f; x++)
{
cjdr[updateejdldic.ElementAt(x).Key] = updateejdldic.ElementAt(x).Value + ftpzmj * zfvalue;
}
}
if (e > 0)
{
//商数村调平面积值
decimal ftpzmj = e * js;
for (int x = f; x < cjzsm; x++)
{
cjdr[updateejdldic.ElementAt(x).Key] = updateejdldic.ElementAt(x).Value + ftpzmj * zfvalue;
}
}
pc = true;
continue;
}
}
foreach (var dlbmitem in dlbmlist)
{
decimal h = 0;
decimal tempv = 0;
if (dlbmitem.EJDLList != null && dlbmitem.EJDLList.Count > 0)
{
foreach (var ejdlitem in dlbmitem.EJDLList)
{
tempv = cjdr["D" + ejdlitem].ToDecimal(2);
if (tempv < 0)
{
tempv = 0;
cjdr["D" + ejdlitem] = tempv;
}
h = h + tempv;
}
cjdr["D" + dlbmitem.YJDL] = h;
}
}
#endregion
}
catch (Exception ex)
{
LogAPI.Debug("行内平差 异常: " + ex + " ; ");
return;
}
}
#endregion
#region 20权属单位代码表
///
/// 20权属单位代码表
///
///
///
///
///
public bool ExportReportQSDWDMB(ReportEntityClass reportEntity, string savePath)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable result = new DataTable();
result.Columns.Add(new DataColumn("DM"));
result.Columns.Add(new DataColumn("MC"));
List dicList = Platform.Instance.DicHelper.GetDic(DicTypeEnum.QSDM, true);
if (dicList != null && dicList.Count > 0)
{
QSDWDMBData(dicList, result);
}
OutExcel(result, savePath, reportTempaltePath, 7, 1, 2);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 20权属单位代码表(空表)
///
///
///
///
/// 王欢 2018-12-07
public bool ExportReportNULLQSDWDMB(ReportEntityClass reportEntity, string savePath, System.Collections.Hashtable selectht)
{
try
{
//权属单位代码表 文件命名有问题 为满足需求暂定是现在
//if (selectht != null)
//{
// foreach (var item in selectht.Keys)
// {
string reportTempaltePath = GetZLPath() + reportEntity.TempalateFileName + ".xlsx";
string newPath = System.IO.Path.GetDirectoryName(savePath);// + selectht[item].ToString();
string newFile = "(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")" + System.IO.Path.GetFileName(savePath);// item.ToString().Substring(6) + System.IO.Path.GetFileName(savePath);
if (!System.IO.Directory.Exists(newPath))
{
System.IO.Directory.CreateDirectory(newPath);
}
string newsavePath = newPath + "\\" + newFile;
OutExcel(null, newsavePath, reportTempaltePath, 7, 1, 2);
// }
//}
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
///
/// 20权属单位代码表
///
///
///
private void QSDWDMBData(List dicList, DataTable dt)
{
try
{
//List chlidlist = new List();
foreach (DataDicTionary dic in dicList)
{
DataRow dr = dt.NewRow();
dr["DM"] = dic.CODE;
dr["MC"] = dic.NAME;
dt.Rows.Add(dr);
if (dic.SubDic != null && dic.SubDic.Count > 0)
{
QSDWDMBData(dic.SubDic, dt);
//chlidlist.AddRange(dic.SubDic);
}
}
//if (chlidlist.Count > 0)
//{
//}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
#endregion
#region 样方田坎系数测算表输出
///
/// 白明雅 2018-12-03 样方田坎系数测算表
///
///
///
///
///
public bool ExportReportYFTKXSCS(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = new DataTable();//此处为输出数据,暂时为空
OutExcel(rest, savePath, reportTempaltePath, 6, 1, 15);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
#endregion
#region 田坎系数表
///
/// 白明雅 2018-12-03 田坎系数表
///
///
///
///
///
public bool ExportReportTKXS(IRDBHelper dbHelper, ReportEntityClass reportEntity, string savePath)
{
try
{
string reportTempaltePath = GetTPath() + reportEntity.TempalateFileName + ".xlsx";
DataTable rest = new DataTable();//此处为输出数据,暂时为空
OutExcel(rest, savePath, reportTempaltePath, 4, 1, 10);
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
#endregion
///
/// 导出excel
///
///
///
///
///
private void OutExcel(DataTable dt, string savePath, string templatePath, int headbeginRowIndex, int headbeginColumnsIndex, int headEndColumnsIndex)
{
Workbook workbook = new Workbook(templatePath);
Worksheet sheet = workbook.Worksheets[0];
if (headbeginColumnsIndex > headEndColumnsIndex || headbeginColumnsIndex < 1 || headbeginRowIndex < 1)
{
workbook.Save(savePath);
return;
}
if (ReportFileType != ReportFileTypeEnum.DBGQ)
{
bool isbreak = false;
for (int i = 0; i < headEndColumnsIndex; i++)
{
for (int r = 0; r < headbeginRowIndex; r++)
{
Cell cellNew = sheet.Cells[r, i];
string cname = ObjectToString(cellNew.Value);
if (cname.IndexOf("公顷") >= 0)
{
switch (ReportFileType)
{
case ReportFileTypeEnum.DBGQ:
break;
case ReportFileTypeEnum.DBM:
cname = cname.Replace("公顷", "亩");
break;
case ReportFileTypeEnum.DBMETERS:
cname = cname.Replace("公顷", "平方米");
break;
case ReportFileTypeEnum.FBM:
break;
default:
break;
}
cellNew.PutValue(cname);
isbreak = true;
break;
}
}
if (isbreak)
{
break;
}
}
}
List SheetColumnslist = new List();
headbeginRowIndex = headbeginRowIndex - 1;
headbeginColumnsIndex = headbeginColumnsIndex - 1;
if (dt == null || dt.Rows.Count <= 0)
{
sheet.Cells.DeleteRow(headbeginRowIndex);
workbook.Save(savePath);
return;
}
Aspose.Cells.Row startRow = sheet.Cells.Rows[headbeginColumnsIndex];
for (int i = headbeginColumnsIndex; i < headEndColumnsIndex; i++)
{
Cell cellNew = sheet.Cells[headbeginRowIndex, i];
string cname = ObjectToString(cellNew.Value);
SheetColumnEntity scentity = new SheetColumnEntity();
scentity.ColumnName = cname;
scentity.Index = i;
SheetColumnslist.Add(scentity);
}
int tempbeginrowindex = headbeginRowIndex + 2;
sheet.Cells.InsertRows(tempbeginrowindex, dt.Rows.Count);//插一行
for (int i = tempbeginrowindex; i < tempbeginrowindex + dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i - tempbeginrowindex];
foreach (var item in SheetColumnslist)
{
Aspose.Cells.Cell cell2 = sheet.Cells[i, item.Index];
if (item.ColumnName.IndexOf("+") > 0)
{
string[] carry = item.ColumnName.Split('+');
decimal value = 0;
bool isput = false;
foreach (var citem in carry)
{
if (dr[citem] == DBNull.Value)
{
continue;
}
value = value + dr[citem].ToDecimal(2) * MjConvertValue;
isput = true;
}
if (isput)
{
//白明雅 2018-11-15 BUG9956---------------------
if (value == 0)
{
cell2.PutValue(null);
continue;
}
//--------------------------------------
cell2.PutValue(value);
}
}
else
{
decimal value2 = 0;//白明雅 2018-11-15 BUG9956
if (dt.Columns[item.ColumnName].DataType.Name == typeof(double).Name)
{
if (dr[item.ColumnName] == DBNull.Value)
{
continue;
}
////白明雅 2018-11-15 BUG9956--------------
value2 = dr[item.ColumnName].ToDecimal(2) * MjConvertValue;
if (value2 == 0)
{
cell2.PutValue(null);
continue;
}
cell2.PutValue(value2);
//------------------------------
//cell2.PutValue(dr[item.ColumnName].ToDecimal(2) * mjConvertValue);
}
else
{
cell2.PutValue(dr[item.ColumnName]);
}
}
}
}
if (dt.Rows[dt.Rows.Count - 1][0] == DBNull.Value)
{
sheet.Cells.DeleteRow(tempbeginrowindex + dt.Rows.Count - 1);
}
sheet.Cells.DeleteRow(tempbeginrowindex - 1);
sheet.Cells.DeleteRow(tempbeginrowindex - 2);
workbook.Save(savePath);
}
///
/// 导出汇总表
///
///
///
///
public bool Export(string saveCurrentPath, IRDBHelper dbHelper, ReportEntityClass reportEntity, string sNMKMDBPath = "")
{
try
{
bool isRst = true;
switch (reportEntity.ReportType)
{
case ReportTypeEnum.TDLYXZYJFLMJHZB:
//isRst = ExportReportTDLYXZYJFLMJHZB(dbHelper, reportEntity, saveCurrentPath);
isRst = ExportReportNCTDLYXZYJFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, null, "", "", 12, sNMKMDBPath);
break;
case ReportTypeEnum.HDTDLYXZYJFLMJHZB:
//isRst = ExportReportTDLYXZYJFLMJHZB_HD(dbHelper, reportEntity, saveCurrentPath);
isRst = ExportReportNCTDLYXZYJFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, null, " AND MSSM = '01'", "WHERE MSSM = '01'", 12, sNMKMDBPath);
break;
case ReportTypeEnum.FRDTDLYXZYJFLMJHZB:
//isRst = ExportReportTDLYXZYJFLMJHZB_FRD(dbHelper, reportEntity, saveCurrentPath);
isRst = ExportReportNCTDLYXZYJFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, null, " AND FRDBS = '1'", "WHERE FRDBS = '1'", 12, sNMKMDBPath);
break;
case ReportTypeEnum.TDLYXZEJFLMJHZB:
//isRst = ExportReportTDLYXZEJFLMJHZB(dbHelper, reportEntity, saveCurrentPath);
isRst = ExportReportNCTDLYXZFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, null, "", "", 12, sNMKMDBPath);
break;
case ReportTypeEnum.HDTDLYXZEJFLMJHZB:
//isRst = ExportReportTDLYXZEJFLMJHZB_HD(dbHelper, reportEntity, saveCurrentPath);
isRst = ExportReportNCTDLYXZFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, null, " AND MSSM = '01'", "WHERE MSSM = '01'", 12, sNMKMDBPath);
break;
case ReportTypeEnum.FRDTDLYXZEJFLMJHZB:
//isRst = ExportReportTDLYXZEJFLMJHZB_FRD(dbHelper, reportEntity, saveCurrentPath);
isRst = ExportReportNCTDLYXZFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, null, " AND FRDBS = '1'", "WHERE FRDBS = '1'", 12, sNMKMDBPath);
break;
case ReportTypeEnum.TDLYXZYJFLMJAQSXZHZB:
//isRst = ExportReportTDLYXZYJFLMJAQSXZHZB(dbHelper, reportEntity, saveCurrentPath);
isRst = ExportReportByLYXZYJFL_QSXZ(dbHelper, reportEntity, saveCurrentPath, null, "", "", 12, sNMKMDBPath);
break;
case ReportTypeEnum.FRDTDLYXZYJFLMJAQSXZHZB:
//isRst = ExportReportTDLYXZYJFLMJAQSXZHZB_FRD(dbHelper, reportEntity, saveCurrentPath);
isRst = ExportReportByLYXZYJFL_QSXZ(dbHelper, reportEntity, saveCurrentPath, null, "AND FRDBS = '1'", "WHERE FRDBS = '1'", 12, sNMKMDBPath);
break;
case ReportTypeEnum.CZCJGKYDMJHZB:
//isRst = ExportReportCZCJGKYDMJHZB(dbHelper, reportEntity, saveCurrentPath);
isRst = ExportReportCZCJGKYDMJHZB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.FRDCZCJGKYDMJHZB:
isRst = ExportReportCZCJGKYDMJHZB_FRD(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.GDPDFJMJHZB:
isRst = ExportReportGDPDFJMJHZB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.GDZZLXMJTJB:
isRst = ExportReportGDZZLXMJTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.LXFWNYDHZTJB:
isRst = ExportReportLXFWNYDHZTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.GCCDXSCDHZQKTJB:
isRst = ExportReportGCCDXSCDHZQKTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.GYYDALXHZTJB:
isRst = ExportReportGYYDALXHZTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.KTZDLMJHZB:
isRst = ExportReportKTZDLMJHZB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.BFXHDLMJHZB:
isRst = ExportReportBFXHDLMJHZB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.SDDCMJTJB:
isRst = ExportReportSDDCMJTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.GDXHDCQKTJB:
isRst = ExportReportGDXHDCQKTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.PZWJSDJSYDYTQKTJB:
isRst = ExportReportPZWJSDJSYDYTQKTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.PZWJSDJSYDXZQKTJB:
isRst = ExportReportPZWJSDJSYDXZQKTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.YJJBNTXZQKTJB:
isRst = ExportReportYJJBNTXZQKTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.WJMHDTJB:
isRst = ExportReportWJMHDTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.JKHFGCHFZZTJB:
isRst = ExportReportJKHFGCHFZZTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.FQXHBZTJB:
isRst = ExportReportFQXHBZTJB(dbHelper, reportEntity, saveCurrentPath, sNMKMDBPath);
break;
case ReportTypeEnum.DSCGTDCYGQKTJB:
case ReportTypeEnum.TDDCJLB:
case ReportTypeEnum.YFTKXSCSB:
case ReportTypeEnum.KCXS:
System.IO.File.Copy(GetTPath() + reportEntity.TempalateFileName + ".xlsx", saveCurrentPath, true);
break;
case ReportTypeEnum.QSDWDMB:
isRst = ExportReportQSDWDMB(reportEntity, saveCurrentPath);
break;
case ReportTypeEnum.YFTKXSCS:
isRst = ExportReportYFTKXSCS(dbHelper, reportEntity, saveCurrentPath);
break;
case ReportTypeEnum.TKXS:
isRst = ExportReportTKXS(dbHelper, reportEntity, saveCurrentPath);
break;
case ReportTypeEnum.GTDCGZBG://白明雅 2018-12-08 输出临时word
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, null);
break;
case ReportTypeEnum.GTDCJSBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, null);
break;
case ReportTypeEnum.GTDCSJKJSBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, null);
break;
case ReportTypeEnum.GTDCCGFXBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, null);
break;
case ReportTypeEnum.CZCZTDLYXZFXBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, null);
break;
case ReportTypeEnum.TDDCSJKZLJCBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, null);
break;
case ReportTypeEnum.ZXDCCGBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, null);
break;
case ReportTypeEnum.HDDCCGBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, null);
break;
default:
break;
}
return isRst;
}
catch
{
return false;
}
}
public bool Export(string saveCurrentPath, IRDBHelper dbHelper, ReportEntityClass reportEntity, System.Collections.Hashtable selectht)
{
try
{
bool isRst = true;
switch (reportEntity.ReportType)
{
case ReportTypeEnum.TDLYXZYJFLMJHZB:
isRst = ExportReportNCTDLYXZYJFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.HDTDLYXZYJFLMJHZB:
isRst = ExportReportNCTDLYXZYJFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, selectht, " AND MSSM = '01'", "WHERE MSSM = '01'");
break;
case ReportTypeEnum.FRDTDLYXZYJFLMJHZB:
isRst = ExportReportNCTDLYXZYJFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, selectht, " AND FRDBS = '1'", "WHERE FRDBS = '1'");
break;
case ReportTypeEnum.TDLYXZEJFLMJHZB:
isRst = ExportReportNCTDLYXZFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.HDTDLYXZEJFLMJHZB:
isRst = ExportReportNCTDLYXZFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, selectht, " AND MSSM = '01'", "WHERE MSSM = '01'");
break;
case ReportTypeEnum.FRDTDLYXZEJFLMJHZB:
isRst = ExportReportNCTDLYXZFLMJHZB_CountyXZQDM6(dbHelper, reportEntity, saveCurrentPath, selectht, " AND FRDBS = '1'", "WHERE FRDBS = '1'");
break;
case ReportTypeEnum.TDLYXZYJFLMJAQSXZHZB://WAHU 农村土地利用现状一级分类面积按权属性质汇总表
isRst = ExportReportByLYXZYJFL_QSXZ(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.FRDTDLYXZYJFLMJAQSXZHZB:
isRst = ExportReportByLYXZYJFL_QSXZ(dbHelper, reportEntity, saveCurrentPath, selectht, " AND FRDBS = '1'", "WHERE FRDBS = '1'");
break;
case ReportTypeEnum.CZCJGKYDMJHZB:
isRst = ExportReportCZCJGKYDMJHZB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.FRDCZCJGKYDMJHZB:
isRst = ExportReportCZCJGKYDMJHZB_FRD(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.GDPDFJMJHZB://WAHU 耕地坡度分级面积汇总表
isRst = ExportReportGDPDFJMJHZB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.GDZZLXMJTJB:
isRst = ExportReportGDZZLXMJTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.LXFWNYDHZTJB:
isRst = ExportReportLXFWNYDHZTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.GCCDXSCDHZQKTJB:
isRst = ExportReportGCCDXSCDHZQKTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.GYYDALXHZTJB:
isRst = ExportReportGYYDALXHZTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.KTZDLMJHZB://WAHU 可调整地类面积汇总表
isRst = ExportReportKTZDLMJHZB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.BFXHDLMJHZB:
isRst = ExportReportBFXHDLMJHZB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.SDDCMJTJB:
isRst = ExportReportSDDCMJTJB(dbHelper, reportEntity, saveCurrentPath);
break;
case ReportTypeEnum.GDXHDCQKTJB:
isRst = ExportReportGDXHDCQKTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.PZWJSDJSYDYTQKTJB:
isRst = ExportReportPZWJSDJSYDYTQKTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.PZWJSDJSYDXZQKTJB:
isRst = ExportReportPZWJSDJSYDXZQKTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.YJJBNTXZQKTJB:
isRst = ExportReportYJJBNTXZQKTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.WJMHDTJB:
isRst = ExportReportWJMHDTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.JKHFGCHFZZTJB:
isRst = ExportReportJKHFGCHFZZTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break; ;
case ReportTypeEnum.FQXHBZTJB:
isRst = ExportReportFQXHBZTJB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.DSCGTDCYGQKTJB:
case ReportTypeEnum.TDDCJLB:
case ReportTypeEnum.YFTKXSCSB:
case ReportTypeEnum.KCXS:
System.IO.File.Copy(GetTPath() + reportEntity.TempalateFileName + ".xlsx", saveCurrentPath, true);
break;
case ReportTypeEnum.QSDWDMB:
isRst = ExportReportQSDWDMB(reportEntity, saveCurrentPath);
break;
case ReportTypeEnum.TDLYXZBGB://土地利用现状变更表(NULL) 王欢 2018-11-03
isRst = ExportReportNULLTDLYXZBGB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.TDBGYLB://土地变更一览表(NULL) 王欢 2018-11-03
isRst = ExportReportNULLTDBGYLB(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.GTDCGZBG://白明雅 2018-12-08 输出临时word
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.GTDCJSBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.GTDCSJKJSBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.GTDCCGFXBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.CZCZTDLYXZFXBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.TDDCSJKZLJCBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.ZXDCCGBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.HDDCCGBG:
isRst = ExportReportDSCGTDC(dbHelper, reportEntity, saveCurrentPath, selectht);
break;
case ReportTypeEnum.TKXS:
isRst = ExportReportTKXS(dbHelper, reportEntity, saveCurrentPath);
break;
case ReportTypeEnum.YFTKXSCS:
isRst = ExportReportYFTKXSCS(dbHelper, reportEntity, saveCurrentPath);
break;
default:
break;
}
return isRst;
}
catch
{
return false;
}
}
///
/// 验证一键成果导出的报表的年初数据Excel所在地址是否有效
///
///
///
///
public bool JudgeNCSJExcelPathIsExist(ReportEntityClass reportEntity, string ncsjPath)
{
bool iJudgeResultTemp_1 = false;
string sReportNameNow = "";
string sNeedReportNameNow = "";
string sNeedExcelNameTemp_1 = "";
DirectoryInfo dirTemp = null;
string sXZQCodeNow_Temp = "";
try
{
//if (Env.Instance.Project == null)
//{
// return false;
//}
if (string.IsNullOrWhiteSpace((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE) == true)
{
return false;
}
sXZQCodeNow_Temp = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE;
if (reportEntity == null)
{
return false;
}
if (reportEntity.ReportType == ReportTypeEnum.土地变更一览表)
{
return true;
}
//if (reportEntity.ReportType == ReportTypeEnum.土地变更一览表 || reportEntity.ReportType == ReportTypeEnum.基本农田统计汇总表)
//{
// return true;
//}
if (string.IsNullOrWhiteSpace(ncsjPath) == true)
{
return false;
}
dirTemp = new DirectoryInfo(ncsjPath);
if (Directory.Exists(dirTemp.FullName) == false)
{
return false;
}
switch (reportEntity.ReportType)
{
//case ReportTypeEnum.变更一览表:
// return true;
// break;
case ReportTypeEnum.土地利用现状变更表:
sReportNameNow = "土地利用现状变更表";
sNeedReportNameNow = "土地利用现状分类面积汇总表";
break;
case ReportTypeEnum.土地利用现状一级分类面积按权属性质变化统计表:
sReportNameNow = "土地利用现状一级分类面积按权属性质变化统计表";
sNeedReportNameNow = "土地利用现状一级分类面积按权属性质汇总表";
break;
case ReportTypeEnum.土地利用现状二级分类面积按权属性质变化统计表:
sReportNameNow = "土地利用现状二级分类面积按权属性质变化统计表";
sNeedReportNameNow = "土地利用现状二级分类面积按权属性质汇总表";
break;
case ReportTypeEnum.城镇村及工矿用地面积变化统计表:
sReportNameNow = "城镇村及工矿用地面积变化统计表";
sNeedReportNameNow = "城镇村及工矿用地面积汇总表";
break;
case ReportTypeEnum.城市内部土地利用变化统计表:
sReportNameNow = "城市内部土地利用变化统计表";
sNeedReportNameNow = "城市内部土地利用现状表";
break;
case ReportTypeEnum.建制镇内部土地利用变化统计表:
sReportNameNow = "建制镇内部土地利用变化统计表";
sNeedReportNameNow = "建制镇内部土地利用现状表";
break;
case ReportTypeEnum.村庄内部土地利用变化统计表:
sReportNameNow = "村庄内部土地利用变化统计表";
sNeedReportNameNow = "城市内部土地利用现状表";
break;
case ReportTypeEnum.特殊用地内部土地利用变化统计表:
sReportNameNow = "特殊用地内部土地利用变化统计表";
sNeedReportNameNow = "特殊用地内部土地利用现状表";
break;
case ReportTypeEnum.耕地坡度分级面积变化统计表:
sReportNameNow = "耕地坡度分级面积变化统计表";
sNeedReportNameNow = "耕地坡度分级面积汇总表";
break;
case ReportTypeEnum.耕地种植类型面积变化统计表:
sReportNameNow = "耕地种植类型面积变化统计表";
sNeedReportNameNow = "耕地种植类型面积统计表";
break;
//case ReportTypeEnum.即可恢复与工程恢复种植属性变化统计表:
// sReportNameNow = "即可恢复与工程恢复种植属性变化统计表";
// sNeedReportNameNow = "即可恢复与工程恢复种植属性汇总统计表";
// break;
case ReportTypeEnum.林区范围内园地变化统计表:
sReportNameNow = "林区范围内园地变化统计表";
sNeedReportNameNow = "林区范围内园地变化统计表";
break;
case ReportTypeEnum.灌丛草地汇总情况变化统计表:
sReportNameNow = "灌丛草地汇总情况变化统计表";
sNeedReportNameNow = "灌丛草地汇总情况统计表";
break;
case ReportTypeEnum.工业用地按类型汇总变化统计表:
sReportNameNow = "工业用地按类型汇总变化统计表";
sNeedReportNameNow = "工业用地按类型汇总统计表";
break;
case ReportTypeEnum.可调整地类面积变化统计表:
sReportNameNow = "可调整地类面积变化统计表";
sNeedReportNameNow = "可调整地类面积汇总表";
break;
case ReportTypeEnum.部分细化地类面积变化统计表:
sReportNameNow = "部分细化地类面积变化统计表";
sNeedReportNameNow = "部分细化地类面积汇总表";
break;
case ReportTypeEnum.废弃与垃圾填埋细化标注变化统计表:
sReportNameNow = "废弃与垃圾填埋细化标注变化统计表";
sNeedReportNameNow = "废弃与垃圾填埋细化标注汇总统计表";
break;
//case ReportTypeEnum.耕地细化调查情况变化统计表:
// sReportNameNow = "耕地细化调查情况变化统计表";
// sNeedReportNameNow = "耕地细化调查情况统计表";
// break;
//case ReportTypeEnum.海岛土地利用现状变化平衡统计表:
// sReportNameNow = "海岛土地利用现状变化平衡统计表";
// sNeedReportNameNow = "海岛土地利用现状分类面积汇总表";
// break;
case ReportTypeEnum.三大类土地利用现状变更表:
sReportNameNow = "三大类土地利用现状变化平衡统计表";
sNeedReportNameNow = "土地利用现状分类面积汇总表";
break;
default:
break;
}
if (string.IsNullOrWhiteSpace(sNeedReportNameNow) == true)
{
return false;
}
sNeedExcelNameTemp_1 = "(" + sXZQCodeNow_Temp + ")" + sNeedReportNameNow + ".xlsx";
FileInfo[] fileSet_Temp = dirTemp.GetFiles(sNeedExcelNameTemp_1, SearchOption.AllDirectories);
if (fileSet_Temp != null && fileSet_Temp.Length > 0)
{
iJudgeResultTemp_1 = true;
//LogAPI.Debug(sReportNameNow + "能被 成功 找到\r\n");
}
else
{
sNeedExcelNameTemp_1 = "(" + sXZQCodeNow_Temp + ")" + sNeedReportNameNow + ".xls";
fileSet_Temp = dirTemp.GetFiles(sNeedExcelNameTemp_1, SearchOption.AllDirectories);
if (fileSet_Temp != null && fileSet_Temp.Length > 0)
{
iJudgeResultTemp_1 = true;
}
else
{
iJudgeResultTemp_1 = false;
}
//LogAPI.Debug(sReportNameNow + "不能被 成功 找到\r\n");
}
return iJudgeResultTemp_1;
}
catch (Exception ex)
{
LogAPI.Debug("验证一键成果导出的(" + sReportNameNow + ")报表的年初数据Excel所在地址是否有效 异常: " + ex + " ; ");
return false;
}
}
///
/// 演示用导出空表使用
///
///
///
///
///
/// 王欢 2018-12-11 后面加备注的为当前在用
public bool NULLExport(string saveCurrentPath, IRDBHelper dbHelper, ReportEntityClass reportEntity, string ncsjPath)
{
try
{
bool isRst = true;
if (ReportTypeEnum.土地变更一览表 == reportEntity.ReportType)//导出报表时 只执行一次年末面积平差
{
try
{
ExportCheckNegative(dbHelper, ncsjPath, reportEntity);
}
catch (Exception ex)
{
LogAPI.Debug("年末面积平差时发生异常,异常信息如下:");
LogAPI.Debug(ex);
}
}
switch (reportEntity.ReportType)
{
case ReportTypeEnum.土地变更一览表:
isRst = ExportBGYLB(saveCurrentPath, dbHelper);
break;
case ReportTypeEnum.土地利用现状变更表:
isRst = ExportTDLYXZBGB(saveCurrentPath, dbHelper, ncsjPath);
break;
case ReportTypeEnum.土地利用现状一级分类面积按权属性质变化统计表:
isRst = (new ExportQSXZBHTJB()).Export_SQL_1(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.土地利用现状二级分类面积按权属性质变化统计表:
isRst = (new ExportQSXZBHTJB()).Export_SQL_2(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.城镇村及工矿用地面积变化统计表:
isRst = (new ExportCZCJGKYDMJBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.城市内部土地利用变化统计表:
isRst = (new ExportCSNBTDLYBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.建制镇内部土地利用变化统计表:
isRst = (new ExportJZZNBTDLYBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.村庄内部土地利用变化统计表:
isRst = (new ExportCZNBTDLYBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.工矿用地内部土地利用变化统计表:
isRst = (new ExportYTJGKYDNBTDLYBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.特殊用地内部土地利用变化统计表:
isRst = (new ExportTSYDNBTDLYBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.耕地坡度分级面积变化统计表:
isRst = (new ExportGDPDFJMJBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.耕地种植类型面积变化统计表:
isRst = (new ExportGDZZLXMJBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.林区范围内园地变化统计表:
isRst = (new ExportZZYYDBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.灌丛草地汇总情况变化统计表:
isRst = (new ExportGCCDHZQKBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.工业用地按类型汇总变化统计表:
isRst = (new ExportGYYDALXHZBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.可调整地类面积变化统计表:
isRst = (new ExportKTZDLMJBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.部分细化地类面积变化统计表:
isRst = (new ExportBFXHDLMJBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.废弃与垃圾填埋细化标注变化统计表:
isRst = (new ExportXHBZBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper);
break;
case ReportTypeEnum.三大类土地利用现状变更表:
isRst = ExportSDLTDLYXZBGB_SQL(saveCurrentPath, dbHelper, ncsjPath);
break;
default:
break;
}
return isRst;
}
catch (Exception ex)
{
LogAPI.Debug("导出报表异常: " + ex + " ; ");
return false;
}
}
///
/// 行政区调整平差
///
public void XZQTZCheck(IRDBHelper dbHelper, string ncsjPath)
{
ICursor pCur = null;
try
{
//实际变化值:调入部分条目变更面积的合计值-调出部分条目变更面积的合计值
string sql = "select sum(bgmj) from JCTJB_GQ where XZQTZLX in ('1','3')";
double TRMJ = Convert.ToDouble(dbHelper.ExecuteScalar(sql));
sql = "select sum(bgmj) from JCTJB_GQ where XZQTZLX in ('2','4')";
double TCMJ = Convert.ToDouble(dbHelper.ExecuteScalar(sql));
double SJTZMJ = TRMJ - TCMJ;//实际值
//理论变化值:行政区调整后的控制面积-行政区调整前的控制面积
double JCDCMJ = 0;
IFeatureClass jcXZQ = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑").FeatureClass;
IQueryDef pQDef = ((jcXZQ as FeatureClass).Workspace as IFeatureWorkspace).CreateQueryDef();
pQDef.Tables = "JC_DLTB";
pQDef.SubFields = "sum(TBMJ)";
pCur = pQDef.Evaluate();
IRow pRow = pCur.NextRow();
if (pRow != null)
{
JCDCMJ = pRow.get_Value(0).ToString().ToDouble(2);
}
Marshal.ReleaseComObject(pCur);
//调整后面积
double TZHMJ = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).DCMJ + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).DCMJHD;
double LLTZMJ = TZHMJ - JCDCMJ;//理论值
if (SJTZMJ != LLTZMJ)
{
//计算调平控制数
double KZS = Math.Round(LLTZMJ - SJTZMJ, 2);
if (TRMJ > 0)
{
//存在行政区调入
sql = "select ID,BGMJ from JCTJB_GQ where XZQTZLX in('1','3') order by BGMJ desc,BGHDLBM desc,BGHQSXZ,BGHZLDWDM,BGHGDLX,BGHGDPDJB,BGHTBXHDM,BGHZZSXDM,BGHCZCSXM,BGHMSSM";
}
else
{
//《土地利用现状变更表》找到调整后年初面积最大的地类
string dlbm = CheckNegative_TDLYXZBHPHTJB(ncsjPath, dbHelper);
sql = "select ID,BGMJ from JCTJB_GQ where BGQDLBM like '" + dlbm + "%' and XZQTZLX in('2','4') order by BGMJ desc,BGQQSXZ,BGQZLDWDM,BGQGDLX,BGQGDPDJB,BGQTBXHDM,BGQZZSXDM,BGQCZCSXM,BGQMSSM";
}
DataTable dt = dbHelper.ExecuteDatatable("ids", sql, true);
if (KZS > 0 && TRMJ > 0)//若调平控制数Δ为正 + 对调入部分平差,则平差单元为正
{
foreach (DataRow row in dt.Rows)
{
if (KZS > 0)
{
dbHelper.ExecuteSQL(string.Format("update jctjb_gq set bgmj={0} where ID={1}", Math.Round(dt.Rows[1].ToDouble() + 0.01, 2), dt.Rows[0]));
KZS = Math.Round(KZS - 0.01, 2);
}
else
{
break;
}
}
}
else if (KZS > 0 && TRMJ == 0)//若调平控制数Δ为正 + 对调出部分平差,则平差单元为负
{
foreach (DataRow row in dt.Rows)
{
if (KZS > 0)
{
dbHelper.ExecuteSQL(string.Format("update jctjb_gq set bgmj={0} where ID={1}", Math.Round(dt.Rows[1].ToDouble() - 0.01, 2), dt.Rows[0]));
KZS = Math.Round(KZS - 0.01, 2);
}
else
{
break;
}
}
}
else if (KZS < 0 && TRMJ > 0)//若调平控制数Δ为负 + 对调入部分平差,则平差单元为负
{
foreach (DataRow row in dt.Rows)
{
if (KZS < 0)
{
dbHelper.ExecuteSQL(string.Format("update jctjb_gq set bgmj={0} where ID={1}", Math.Round(dt.Rows[1].ToDouble() - 0.01, 2), dt.Rows[0]));
KZS = Math.Round(KZS + 0.01, 2);
}
else
{
break;
}
}
}
else if (KZS < 0 && TRMJ == 0)//若调平控制数Δ为负 + 对调出部分平差,则平差单元为正
{
foreach (DataRow row in dt.Rows)
{
if (KZS < 0)
{
dbHelper.ExecuteSQL(string.Format("update jctjb_gq set bgmj={0} where ID={1}", Math.Round(dt.Rows[1].ToDouble() + 0.01, 2), dt.Rows[0]));
KZS = Math.Round(KZS + 0.01, 2);
}
else
{
break;
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("行政区调整平差失败:" + ex.Message);
}
}
public string CheckNegative_TDLYXZBHPHTJB(string ncsjPath, IRDBHelper dbHelper)
{
double MaxTZMJ = 0;
string DLBM = "";
DataTable dtExport = null;
string ncsjExcelPath = string.Empty;
DirectoryInfo dir = new DirectoryInfo(ncsjPath);
DataTable dt = dbHelper.ExecuteDatatable("BGYLB", " select BGQDLBM,BGHDLBM,XZQTZLX,BGMJ from BGYLB ", true);
string tempPath = string.Empty;
string tempFile = string.Empty;
FileInfo[] fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")土地利用现状分类面积汇总表.xlsx", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
}
else
{
fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")土地利用现状分类面积汇总表.xls", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
}
}
if (String.IsNullOrWhiteSpace(ncsjExcelPath) == true)
{
return "";
}
tempPath = AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\BGTJ\\土地利用现状变更表.xlsx";
//File.Copy(tempPath, saveCurrentPath, true);
dtExport = dbHelper.ExecuteDatatable("TDLYXZBHPHTJB_TEMP", " select * from TDLYXZBHPHTJB_TEMP ", true);
if (dtExport == null)
return "";
Workbook workbook = new Workbook(tempPath);
Cells cells = workbook.Worksheets[0].Cells;
Style style3 = workbook.CreateStyle();//.Styles[workbook.Styles.Add()];//新增样式
style3.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style3.VerticalAlignment = TextAlignmentType.Center;//文字居中
style3.Font.Name = "宋体";//文字字体
style3.Font.Size = 10;//文字大小
style3.Font.IsBold = false;
style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
Dictionary dic = GetDicTDLYXZBHPHTJB();
Dictionary dicValue = GetDicTDLYXZBHPHTJB();
foreach (KeyValuePair kvp in dic)
{
DataRow[] drSet = dtExport.Select(string.Format(" BGQDLBM='{0}' and BGHDLBM='{1}' ", kvp.Key.BGQDLBM, kvp.Key.BGHDLBM));
if (drSet != null && drSet.Length > 0)
{
double gqmj = double.Parse(drSet[0]["MJ"].ToString());
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(gqmj.ToString("f2"));
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
dicValue[new ExcelCell() { BGQDLBM = kvp.Key.BGQDLBM, BGHDLBM = kvp.Key.BGHDLBM, ColIndex = kvp.Key.ColIndex, RowIndex = kvp.Key.RowIndex }] = double.Parse(gqmj.ToString("f2"));
}
else
{
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(0);
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
}
}
//调入面积
List lstDLBM = new List() { "00", "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108", "01", "0101", "0102", "0103", "02", "0201", "0202", "0203", "0204", "03", "0301", "0302", "0305", "0307", "04", "0401", "0403", "0404", "05", "05H1", "0508", "06", "0601", "0602", "07", "0701", "0702", "08", "08H1", "08H2", "0809", "0810", "09", "10", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009", "11", "1101", "1102", "1103", "1104", "1107", "1109", "1110", "12", "1201", "1202", "1203", "1204", "1205", "1206", "1207" };
int j = 0;
foreach (string item in lstDLBM)
{
DataRow[] drSet = dt.Select(string.Format(" BGHDLBM='{0}' and (XZQTZLX='1' or XZQTZLX='3') ", item));
double TRMJ = 0;
if (drSet != null && drSet.Length > 0)
{
foreach (DataRow dr in drSet)
{
TRMJ += Convert.ToDouble(dr["BGMJ"] == null ? "0" : dr["BGMJ"].ToString());
}
}
cells[5, 2 + j].PutValue(TRMJ);
cells[5, 2 + j].SetStyle(style3);
j++;
}
//调出面积
j = 0;
foreach (string item in lstDLBM)
{
DataRow[] drSet = dt.Select(string.Format(" BGQDLBM='{0}' and (XZQTZLX='2' or XZQTZLX='4') ", item));
double TRMJ = 0;
if (drSet != null && drSet.Length > 0)
{
foreach (DataRow dr in drSet)
{
TRMJ += Convert.ToDouble(dr["BGMJ"] == null ? "0" : dr["BGMJ"].ToString());
}
}
cells[6, 2 + j].PutValue(TRMJ);
cells[6, 2 + j].SetStyle(style3);
j++;
}
foreach (KeyValuePair kvp in dicValue)
{
double sumMJ = 0;
if (kvp.Key.BGQDLBM.Length == 2 && kvp.Key.BGHDLBM.Length != 2)
{
sumMJ = 0;
int count = 0;
switch (kvp.Key.BGQDLBM)
{
case "00":
List lst00 = new List() { "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
if (lst00.Contains(kvp.Key.BGHDLBM))
continue;
count = 8; break;
case "01":
List lst01 = new List() { "0101", "0102", "0103" };
if (lst01.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "02":
List lst02 = new List() { "0201", "0202", "0203", "0204" };
if (lst02.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "03":
List lst03 = new List() { "0301", "0302", "0305", "0307" };
if (lst03.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "04":
List lst04 = new List() { "0401", "0403", "0404" };
if (lst04.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "05":
List lst05 = new List() { "05H1", "0508" };
if (lst05.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "06":
List lst06 = new List() { "0601", "0602" };
if (lst06.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "07":
List lst07 = new List() { "0701", "0702" };
if (lst07.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "08":
List lst08 = new List() { "08H1", "08H2", "0809", "0810" };
if (lst08.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "09": continue;
case "10":
List lst10 = new List() { "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009" };
if (lst10.Contains(kvp.Key.BGHDLBM))
continue;
count = 9; break;
case "11":
List lst11 = new List() { "1101", "1102", "1103", "1104", "1107", "1109", "1110" };
if (lst11.Contains(kvp.Key.BGHDLBM))
continue;
count = 7; break;
case "12":
List lst12 = new List() { "1201", "1202", "1203", "1204", "1205", "1206", "1207" };
if (lst12.Contains(kvp.Key.BGHDLBM))
continue;
count = 7; break;
}
for (int i = 1; i < count + 1; i++)
{
var value = cells[kvp.Key.RowIndex + i, kvp.Key.ColIndex].Value;
if (value != null)
{
sumMJ += double.Parse(value.ToString());
}
}
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(sumMJ);
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
}
if (kvp.Key.BGQDLBM.Length != 2 && kvp.Key.BGHDLBM.Length == 2)
{
sumMJ = 0;
int count = 0;
switch (kvp.Key.BGHDLBM)
{
case "00":
List lst00 = new List() { "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
if (lst00.Contains(kvp.Key.BGQDLBM))
continue;
count = 8; break;
case "01":
List lst01 = new List() { "0101", "0102", "0103" };
if (lst01.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "02":
List lst02 = new List() { "0201", "0202", "0203", "0204" };
if (lst02.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "03":
List lst03 = new List() { "0301", "0302", "0305", "0307" };
if (lst03.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "04":
List lst04 = new List() { "0401", "0403", "0404" };
if (lst04.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "05":
List lst05 = new List() { "05H1", "0508" };
if (lst05.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "06":
List lst06 = new List() { "0601", "0602" };
if (lst06.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "07":
List lst07 = new List() { "0701", "0702" };
if (lst07.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "08":
List lst08 = new List() { "08H1", "08H2", "0809", "0810" };
if (lst08.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "09": continue;
case "10":
List lst10 = new List() { "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009" };
if (lst10.Contains(kvp.Key.BGQDLBM))
continue;
count = 9; break;
case "11":
List lst11 = new List() { "1101", "1102", "1103", "1104", "1107", "1109", "1110" };
if (lst11.Contains(kvp.Key.BGQDLBM))
continue;
count = 7; break;
case "12":
List lst12 = new List() { "1201", "1202", "1203", "1204", "1205", "1206", "1207" };
if (lst12.Contains(kvp.Key.BGQDLBM))
continue;
count = 7; break;
}
for (int i = 1; i < count + 1; i++)
{
var value = cells[kvp.Key.RowIndex, kvp.Key.ColIndex + i].Value;
if (value != null)
{
sumMJ += double.Parse(value.ToString());
}
}
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(sumMJ);
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
}
}
if (ncsjExcelPath != string.Empty)
{
int startRol;
int mcRol;
int rolFirst;
int colFirst;
int MaxCol;
Workbook workbookNC = new Workbook(ncsjExcelPath);
Cells cellsNC = workbookNC.Worksheets[0].Cells;
int valueRow = 0;
//土地类型的表结构
startRol = 3;
mcRol = 0;
rolFirst = 11;
colFirst = 2;
MaxCol = 71;//总列数
for (int i = 0; i < cellsNC.MaxRow; i++)
{
if (cellsNC[i, mcRol].IsMerged == false && cellsNC[i, mcRol].Value != null && cellsNC[i, mcRol].Value.ToString() == "名称")
{
valueRow = i + 1;
break;
}
if (cellsNC[i, mcRol].IsMerged == true && cellsNC[i, mcRol].Value != null && cellsNC[i, mcRol].Value.ToString() == "名称")
{
valueRow = i + cellsNC[i, 0].GetMergedRange().RowCount + 1;
break;
}
}
//上年末面积
for (int i = startRol; i < MaxCol; i++)
{
cells[4, 2 + i - startRol].PutValue(cellsNC[valueRow, i].Value);
cells[4, 2 + i - startRol].SetStyle(style3);
}
//年内增加
for (int i = startRol; i < MaxCol; i++)
{
double total = 0;
foreach (KeyValuePair kvp in dicValue)
{
if (kvp.Key.ColIndex == 2 + i - startRol)
{
//一级类相同地类不计算增加减少
bool isContinue = false;
if (i >= startRol && i <= startRol + 8 && kvp.Key.RowIndex >= rolFirst && kvp.Key.RowIndex <= rolFirst + 8) isContinue = true;
else if (i >= startRol + 9 && i <= startRol + 12 && kvp.Key.RowIndex >= rolFirst + 9 && kvp.Key.RowIndex <= rolFirst + 12) isContinue = true;
else if (i >= startRol + 13 && i <= startRol + 17 && kvp.Key.RowIndex >= rolFirst + 13 && kvp.Key.RowIndex <= rolFirst + 17) isContinue = true;
else if (i >= startRol + 18 && i <= startRol + 22 && kvp.Key.RowIndex >= rolFirst + 18 && kvp.Key.RowIndex <= rolFirst + 22) isContinue = true;
else if (i >= startRol + 23 && i <= startRol + 26 && kvp.Key.RowIndex >= rolFirst + 23 && kvp.Key.RowIndex <= rolFirst + 26) isContinue = true;
else if (i >= startRol + 27 && i <= startRol + 29 && kvp.Key.RowIndex >= rolFirst + 27 && kvp.Key.RowIndex <= rolFirst + 29) isContinue = true;
else if (i >= startRol + 30 && i <= startRol + 32 && kvp.Key.RowIndex >= rolFirst + 30 && kvp.Key.RowIndex <= rolFirst + 32) isContinue = true;
else if (i >= startRol + 33 && i <= startRol + 35 && kvp.Key.RowIndex >= rolFirst + 33 && kvp.Key.RowIndex <= rolFirst + 35) isContinue = true;
else if (i >= startRol + 36 && i <= startRol + 40 && kvp.Key.RowIndex >= rolFirst + 36 && kvp.Key.RowIndex <= rolFirst + 40) isContinue = true;
else if (i >= startRol + 41 && i <= startRol + 41 && kvp.Key.RowIndex >= rolFirst + 41 && kvp.Key.RowIndex <= rolFirst + 41) isContinue = true;
else if (i >= startRol + 42 && i <= startRol + 51 && kvp.Key.RowIndex >= rolFirst + 42 && kvp.Key.RowIndex <= rolFirst + 51) isContinue = true;
else if (i >= startRol + 52 && i <= startRol + 59 && kvp.Key.RowIndex >= rolFirst + 52 && kvp.Key.RowIndex <= rolFirst + 59) isContinue = true;
else if (i >= startRol + 60 && i <= startRol + 67 && kvp.Key.RowIndex >= rolFirst + 60 && kvp.Key.RowIndex <= rolFirst + 67) isContinue = true;
if (isContinue)
continue;
if (kvp.Value > 0)
total += kvp.Value;
}
}
cells[8, 2 + i - startRol].PutValue(total);
cells[8, 2 + i - startRol].SetStyle(style3);
}
//年内减少
for (int i = startRol; i < MaxCol; i++)
{
double total = 0;
foreach (KeyValuePair kvp in dicValue)
{
if (kvp.Key.RowIndex == 11 + i - startRol)
{
//一级类相同地类不计算增加减少
bool isContinue = false;
if (i >= startRol && i <= startRol + 8 && kvp.Key.ColIndex >= colFirst && kvp.Key.ColIndex <= colFirst + 8) isContinue = true;
else if (i >= startRol + 9 && i <= startRol + 12 && kvp.Key.ColIndex >= colFirst + 9 && kvp.Key.ColIndex <= colFirst + 12) isContinue = true;
else if (i >= startRol + 13 && i <= startRol + 17 && kvp.Key.ColIndex >= colFirst + 13 && kvp.Key.ColIndex <= colFirst + 17) isContinue = true;
else if (i >= startRol + 18 && i <= startRol + 22 && kvp.Key.ColIndex >= colFirst + 18 && kvp.Key.ColIndex <= colFirst + 22) isContinue = true;
else if (i >= startRol + 23 && i <= startRol + 26 && kvp.Key.ColIndex >= colFirst + 23 && kvp.Key.ColIndex <= colFirst + 26) isContinue = true;
else if (i >= startRol + 27 && i <= startRol + 29 && kvp.Key.ColIndex >= colFirst + 27 && kvp.Key.ColIndex <= colFirst + 29) isContinue = true;
else if (i >= startRol + 30 && i <= startRol + 32 && kvp.Key.ColIndex >= colFirst + 30 && kvp.Key.ColIndex <= colFirst + 32) isContinue = true;
else if (i >= startRol + 33 && i <= startRol + 35 && kvp.Key.ColIndex >= colFirst + 33 && kvp.Key.ColIndex <= colFirst + 35) isContinue = true;
else if (i >= startRol + 36 && i <= startRol + 40 && kvp.Key.ColIndex >= colFirst + 36 && kvp.Key.ColIndex <= colFirst + 40) isContinue = true;
else if (i >= startRol + 41 && i <= startRol + 41 && kvp.Key.ColIndex >= colFirst + 41 && kvp.Key.ColIndex <= colFirst + 41) isContinue = true;
else if (i >= startRol + 42 && i <= startRol + 51 && kvp.Key.ColIndex >= colFirst + 42 && kvp.Key.ColIndex <= colFirst + 51) isContinue = true;
else if (i >= startRol + 52 && i <= startRol + 59 && kvp.Key.ColIndex >= colFirst + 52 && kvp.Key.ColIndex <= colFirst + 59) isContinue = true;
else if (i >= startRol + 60 && i <= startRol + 67 && kvp.Key.ColIndex >= colFirst + 60 && kvp.Key.ColIndex <= colFirst + 67) isContinue = true;
if (isContinue)
continue;
total += kvp.Value;
}
}
cells[9, 2 + i - startRol].PutValue(total);
cells[9, 2 + i - startRol].SetStyle(style3);
}
for (int i = 4; i < 79; i++)
{
GetTDLYXZBHPHTJBXJ(cells, i);
}
for (int i = startRol; i < MaxCol; i++)
{
double total = 0;
foreach (KeyValuePair kvp in dicValue)
{
if (kvp.Key.ColIndex == 2 + i - startRol)
{
if (kvp.Value > 0)
total += kvp.Value;
}
}
if (total != 0)
{
cells[8, 2 + i - startRol].PutValue(total);
cells[8, 2 + i - startRol].SetStyle(style3);
}
}
#region 特殊用地赋值
List lst = new List() { 11, 20, 24, 29, 34, 38, 41, 44, 47, 52, 53, 63, 71 };
List lst1 = new List() { 8, 3, 4, 4, 3, 2, 2, 2, 4, 0, 9, 7, 7 };
var index = 0;
foreach (var item in lst)
{
var mj = 0.00;
for (int i = item; i <= item + lst1[index]; i++)
{
var value = cells[i, 43].Value;
mj += value == null ? 0.00 : Convert.ToDouble(value);
}
cells[item, 43].PutValue(mj);
cells[item, 43].SetStyle(style3);
index += 1;
}
#endregion
for (int i = startRol; i < MaxCol; i++)
{
double total = 0;
foreach (KeyValuePair kvp in dicValue)
{
if (kvp.Key.RowIndex == 11 + i - startRol)
{
total += kvp.Value;
}
}
if (total != 0)
{
cells[9, 2 + i - startRol].PutValue(total);
cells[9, 2 + i - startRol].SetStyle(style3);
}
}
for (int i = 4; i < 79; i++)//76标识表格的总行数
{
GetTDLYXZBHPHTJBXJ(cells, i, false);
}
startRol = 3;
for (int i = startRol; i < 72; i++)//<72 表示表格总共有71列
{
double ncMJ = 0;
double zjMJ = 0;
double jsMJ = 0;
double hrMJ = 0;
double hcMJ = 0;
if (cells[4, 2 + i - startRol].Value != null)
{
var value = cells[4, 2 + i - startRol].Value;
if (!"".Equals(value))
{
ncMJ = double.Parse(value.ToString());
}
}
if (cells[5, 2 + i - startRol].Value != null)
{
var value = cells[5, 2 + i - startRol].Value;
if (!"".Equals(value))
{
hrMJ = double.Parse(value.ToString());
}
}
if (cells[6, 2 + i - startRol].Value != null)
{
var value = cells[6, 2 + i - startRol].Value;
if (!"".Equals(value))
{
hcMJ = double.Parse(value.ToString());
}
}
if (cells[8, 2 + i - startRol].Value != null)
{
var value = cells[8, 2 + i - startRol].Value;
if (!"".Equals(value))
{
zjMJ = double.Parse(value.ToString());
}
}
if (cells[9, 2 + i - startRol].Value != null)
{
var value = cells[9, 2 + i - startRol].Value;
if (!"".Equals(value))
{
jsMJ = double.Parse(value.ToString());
}
}
double tzmj = ncMJ + hrMJ - hcMJ;
cells[7, 2 + i - startRol].PutValue(tzmj);
cells[7, 2 + i - startRol].SetStyle(style3);
//查找最大调整面积的地类
if (tzmj > MaxTZMJ)
{
MaxTZMJ = tzmj;
ExcelCell cell = dic.Where(c => c.Key.ColIndex == (2 + i - startRol)).FirstOrDefault().Key;
if (cell == null || cell.BGHDLBM.Length == 2)
{
continue;
}
DLBM = cell.BGHDLBM;
}
}
}
return DLBM;
}
public void ExportCheckNegative(IRDBHelper dbHelper, string ncsjPath, ReportEntityClass reportEntity)
{
ExportHelper eh = new ExportHelper();
List exportTypes = eh.GetReportEntityZLGLClassList();
List pcModelList = new List();
BBPCModel pc = null;
string saveCurrentPath = AppDomain.CurrentDomain.BaseDirectory + "Temp";
foreach (var item in exportTypes)
{
switch (item.ReportType)
{
case ReportTypeEnum.土地利用现状变更表:
pc = ExportTDLYXZBGB_JC(saveCurrentPath, dbHelper, ncsjPath, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.土地利用现状二级分类面积按权属性质变化统计表:
pc = (new ExportQSXZBHTJB()).Export_SQL_2(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.城市内部土地利用变化统计表:
pc = (new ExportCSNBTDLYBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.建制镇内部土地利用变化统计表:
pc = (new ExportJZZNBTDLYBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.村庄内部土地利用变化统计表:
pc = (new ExportCZNBTDLYBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.工矿用地内部土地利用变化统计表:
pc = (new ExportYTJGKYDNBTDLYBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.特殊用地内部土地利用变化统计表:
pc = (new ExportTSYDNBTDLYBHTJB()).Export_SQL(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.部分细化地类面积变化统计表:
pc = (new ExportBFXHDLMJBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.可调整地类面积变化统计表:
pc = (new ExportKTZDLMJBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.耕地坡度分级面积变化统计表:
pc = (new ExportGDPDFJMJBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.耕地种植类型面积变化统计表:
pc = (new ExportGDZZLXMJBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.林区范围内园地变化统计表:
pc = (new ExportZZYYDBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.灌丛草地汇总情况变化统计表:
pc = (new ExportGCCDHZQKBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.工业用地按类型汇总变化统计表:
pc = (new ExportGYYDALXHZBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
case ReportTypeEnum.废弃与垃圾填埋细化标注变化统计表:
pc = (new ExportXHBZBHTJB()).Export(saveCurrentPath, ncsjPath, dbHelper, ref pcModelList);
if (pc != null)
{
pcModelList.Add(pc);
}
break;
default:
break;
}
}
List NotActiveID = new List();
if (pcModelList.Count > 0)
{
Dictionary idNum = new Dictionary();
List IDCount = new List();//重复度最高的ID
Dictionary> directory = new Dictionary>();
List combination = new List();//列组合
double pcs = 0;
#region 获取重复度
foreach (var Columns in pcModelList)
{
foreach (var item in Columns.Columns)
{
if (item.DiffValue == 0 || !item.IsActive)
continue;
foreach (var id in item.Ids)
{
if (idNum.Keys.Contains(id))
{
idNum[id]++;
continue;
}
idNum.Add(id, 1);
}
}
}
if (idNum.Count == 0)
{
return;
}
int maxNum = idNum.Values.Max();
var maxnumids = idNum.Where(x => x.Value == maxNum);
foreach (var item in maxnumids)
{
IDCount.Add(item.Key);
}
#endregion
if (IDCount.Count == 0)
{
return;
}
#region 列组合
foreach (var ID in IDCount)//统计表总条数
{
string str = string.Empty;
foreach (var item in pcModelList)//涉及到的表个数
{
foreach (var col in item.Columns)//表中对应的列数
{
if (col.DiffValue == 0 || !col.IsActive)
continue;
if (col.Ids.Contains(ID))
{
str += $"{item.ReportName}-{col.ColumnIndex},";
}
}
}
if (!directory.Keys.Contains(str))
{
directory.Add(str, new List() { ID });
continue;
}
directory[str].Add(ID);
}
List TbColIndex = new List();
List IDs = new List();
foreach (var item in directory)
{
string[] strKey = item.Key.Substring(0, item.Key.Length - 1).Split(',');
foreach (var str in strKey)
{
int[] i = Array.ConvertAll(str.Split('-'), delegate (string s) { return int.Parse(s); });
if (TbColIndex.Count == 0)
{
TbColIndex.Add(i[0]);
TbColIndex.Add(i[1]);
IDs = item.Value;
}
else
{
if (TbColIndex[0] > i[0])
{
TbColIndex[0] = i[0];
TbColIndex[1] = i[1];
IDs = item.Value;
}
else if (TbColIndex[1] > i[1] && TbColIndex[0] == i[0])
{
TbColIndex[0] = i[0];
TbColIndex[1] = i[1];
IDs = item.Value;
}
}
}
}
#endregion
foreach (var Columns in pcModelList)
{
foreach (var item in Columns.Columns)
{
if (item.Ids.All(x => IDs.Any(c => c.Equals(x))))
{
if (pcs > item.DiffValue || pcs == 0)
{
pcs = item.DiffValue;
}
}
}
}
{
if (pcs == 0)
return;
string strIDWhere = string.Empty;
foreach (var item in IDs)
{
if (NotActiveID.Contains(item))
continue;
strIDWhere += item + ",";
}
strIDWhere = strIDWhere.TrimEnd(',');
if (string.IsNullOrWhiteSpace(strIDWhere))
{
return;
}
DataTable dt = dbHelper.ExecuteDatatable("tb", string.Format("select id,bgmj from jctjb_gq where ID in({0}) order by abs(BGMJ) desc,BGQDLBM desc,BGQQSXZ,BGQZLDWDM,BGQGDLX,BGQGDPDJB,BGQTBXHDM,BGQZZSXDM,BGQCZCSXM,BGQMSSM,BGHDLBM desc,BGHQSXZ,BGHZLDWDM,BGHGDLX,BGHGDPDJB,BGHTBXHDM,BGHZZSXDM,BGHCZCSXM,BGHMSSM ", strIDWhere), true);
//if (dt.Rows.Count >= pcs * 100)
//{
double pcs2 = pcs;
while (pcs2.ToDouble(2) > 0 && dt.Rows.Count > 0)
{
foreach (DataRow item in dt.Rows)
{
if (item[1].ToDouble() == 0 && dt.Rows.Count == 1)
{
pcs2 = 0;
break;
}
if (item[1].ToDouble() == 0) continue;
if (pcs2 == 0) break;
dbHelper.ExecuteSQL(string.Format("update jctjb_gq set bgmj={0} where ID={1}", Math.Round(item[1].ToDouble() - 0.01, 2), item[0]));
item[1] = Math.Round(item[1].ToDouble() - 0.01, 2);
pcs2 = pcs2 - 0.01;
}
}
//for (int i = 0; i < Math.Floor(Math.Round(pcs, 2) * 100); i++)
//{
// dbHelper.ExecuteSQL(string.Format("update jctjb_gq set bgmj={0} where ID={1}", Math.Round(dt.Rows[i][1].ToDouble() - 0.01, 2), dt.Rows[i][0]));
//}
string[] ids = strIDWhere.Split(',');
foreach (var id in ids)
{
if (NotActiveID.Contains(Convert.ToInt32(id)))
continue;
foreach (var item in pcModelList)
{
foreach (var col in item.Columns)
{
if (col.Ids.Contains(Convert.ToInt32(id)))
{
if (col.DiffValue != 0)
col.DiffValue = Math.Round(col.DiffValue - pcs, 2);
if (col.DiffValue == 0)
{
col.IsActive = false;
NotActiveID.AddRange(col.Ids);
}
}
}
}
}
//}
}
}
}
///
/// 调整后年末面积负值平差
///
///
///
///
public void TZNCMJExportCheckNegative(IRDBHelper dbHelper, string ncsjPath, ReportEntityClass reportEntity)
{
ExportHelper eh = new ExportHelper();
List exportTypes = eh.GetReportEntityZLGLClassList();
List pcModelList = new List();
foreach (var item in exportTypes)
{
switch (item.ReportType)
{
//case ReportTypeEnum.土地利用现状变化平衡统计表:
// CheckNegative_TDLYXZBHPHTJB(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.土地利用现状一级分类面积按权属性质变化统计表:
// (new ExportQSXZBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.城镇村及工矿用地面积变化统计表:
// (new ExportCZCJGKYDMJBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.耕地坡度分级面积变化统计表:
// (new ExportGDPDFJMJBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.耕地种植类型面积变化统计表:
// (new ExportGDZZLXMJBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.即可恢复与工程恢复种植属性变化统计表:
// (new ExportHFZZSXBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.林区范围内种植园用地变化统计表:
// (new ExportZZYYDBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.灌丛草地汇总情况变化统计表:
// (new ExportGCCDHZQKBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.工业用地按类型汇总变化统计表:
// (new ExportGYYDALXHZBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.可调整地类面积变化统计表:
// (new ExportKTZDLMJBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.部分细化地类面积变化统计表:
// (new ExportBFXHDLMJBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.废弃与垃圾填埋细化标注变化统计表:
// (new ExportXHBZBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.耕地细化调查情况变化统计表:
// (new ExportGDXHDCQKBHTJB()).CheckNegative(ncsjPath, dbHelper, true, ref pcModelList);
// break;
//case ReportTypeEnum.海岛土地利用现状变化平衡统计表:
// CheckNegative_TDLYXZBHPHTJB(ncsjPath, dbHelper, true, ref pcModelList, true);
// break;
//default:
// break;
}
}
List NotActiveID = new List();
if (pcModelList.Count > 0)
{
Dictionary idNum = new Dictionary();
List IDCount = new List();//重复度最高的ID
Dictionary> directory = new Dictionary>();
List combination = new List();//列组合
double pcs = 0;
#region 获取重复度
foreach (var Columns in pcModelList)
{
foreach (var item in Columns.Columns)
{
if (item.DiffValue == 0 || !item.IsActive)
continue;
foreach (var id in item.Ids)
{
if (idNum.Keys.Contains(id))
{
idNum[id]++;
continue;
}
idNum.Add(id, 1);
}
}
}
if (idNum.Count == 0)
{
return;
}
int maxNum = idNum.Values.Max();
var maxnumids = idNum.Where(x => x.Value == maxNum);
foreach (var item in maxnumids)
{
IDCount.Add(item.Key);
}
#endregion
if (IDCount.Count == 0)
{
return;
}
#region 列组合
foreach (var ID in IDCount)//统计表总条数
{
string str = string.Empty;
foreach (var item in pcModelList)//涉及到的表个数
{
foreach (var col in item.Columns)//表中对应的列数
{
if (col.DiffValue == 0 || !col.IsActive)
continue;
if (col.Ids.Contains(ID))
{
str += $"{item.ReportName}-{col.ColumnIndex},";
}
}
}
if (!directory.Keys.Contains(str))
{
directory.Add(str, new List() { ID });
continue;
}
directory[str].Add(ID);
}
List TbColIndex = new List();
List IDs = new List();
foreach (var item in directory)
{
string[] strKey = item.Key.Substring(0, item.Key.Length - 1).Split(',');
foreach (var str in strKey)
{
int[] i = Array.ConvertAll(str.Split('-'), delegate (string s) { return int.Parse(s); });
if (TbColIndex.Count == 0)
{
TbColIndex.Add(i[0]);
TbColIndex.Add(i[1]);
IDs = item.Value;
}
else
{
if (TbColIndex[0] > i[0])
{
TbColIndex[0] = i[0];
TbColIndex[1] = i[1];
IDs = item.Value;
}
else if (TbColIndex[1] > i[1] && TbColIndex[0] == i[0])
{
TbColIndex[0] = i[0];
TbColIndex[1] = i[1];
IDs = item.Value;
}
}
}
}
#endregion
foreach (var Columns in pcModelList)
{
foreach (var item in Columns.Columns)
{
if (item.Ids.All(x => IDs.Any(c => c.Equals(x))))
{
if (pcs > item.DiffValue || pcs == 0)
{
pcs = item.DiffValue;
}
}
}
}
{
if (pcs == 0)
return;
string strIDWhere = string.Empty;
foreach (var item in IDs)
{
if (NotActiveID.Contains(item))
continue;
strIDWhere += item + ",";
}
strIDWhere = strIDWhere.TrimEnd(',');
if (string.IsNullOrWhiteSpace(strIDWhere))
{
return;
}
DataTable dt = dbHelper.ExecuteDatatable("tb", string.Format("select id,bgmj from jctjb_gq where ID in({0}) order by abs(BGMJ) desc,BGQDLBM desc,BGQQSXZ,BGQZLDWDM,BGQGDLX,BGQGDPDJB,BGQTBXHDM,BGQZZSXDM,BGQCZCSXM,BGQMSSM ", strIDWhere), true);
if (dt.Rows.Count >= pcs * 100)
{
for (int i = 0; i < Math.Floor(Math.Round(pcs, 2) * 100); i++)
{
dbHelper.ExecuteSQL(string.Format("update jctjb_gq set bgmj={0} where ID={1}", Math.Round(dt.Rows[i][1].ToDouble() - 0.01, 2), dt.Rows[i][0]));
}
string[] ids = strIDWhere.Split(',');
foreach (var id in ids)
{
if (NotActiveID.Contains(Convert.ToInt32(id)))
continue;
foreach (var item in pcModelList)
{
foreach (var col in item.Columns)
{
if (col.Ids.Contains(Convert.ToInt32(id)))
{
if (col.DiffValue != 0)
col.DiffValue = Math.Round(col.DiffValue - pcs, 2);
if (col.DiffValue == 0)
{
col.IsActive = false;
NotActiveID.AddRange(col.Ids);
}
}
}
}
}
}
}
}
}
public BBPCModel CheckNegative_TDLYXZBHPHTJB(string ncsjPath, IRDBHelper dbHelper, bool isTZMJPC, ref List TZNCbBPCModels, bool isHaiDao = false)
{
BBPCModel result = null;
BBPCModel TZresult = null;
DataTable dtExport = null;
string ncsjExcelPath = string.Empty;
DirectoryInfo dir = new DirectoryInfo(ncsjPath);
DataTable dt = dbHelper.ExecuteDatatable("BGYLB", " select BGQDLBM,BGHDLBM,XZQTZLX,BGMJ from BGYLB ", true);
string tempPath = string.Empty;
string tempFile = string.Empty;
if (isHaiDao)
{
FileInfo[] fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")海岛土地利用现状分类面积汇总表.xlsx", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
}
else
{
fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")海岛土地利用现状分类面积汇总表.xls", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
}
}
if (String.IsNullOrWhiteSpace(ncsjExcelPath) == true)
{
//LogAPI.Debug("海岛土地利用现状分类面积汇总表 不能被 成功 找到\r\n");
return result;
}
//LogAPI.Debug("海岛土地利用现状分类面积汇总表 能被 成功 找到\r\n");
tempPath = AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\BGTJ\\无居民海岛现状调查分类面积变化统计表.xlsx";
//File.Copy(tempPath, saveCurrentPath, true);
dtExport = dbHelper.ExecuteDatatable("HDTDLYXZBHPHTJB_TEMP", " select * from HDTDLYXZBHPHTJB_TEMP ", true);
}
else
{
FileInfo[] fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")土地利用现状分类面积汇总表.xlsx", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
}
else
{
fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")土地利用现状分类面积汇总表.xls", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
}
}
if (String.IsNullOrWhiteSpace(ncsjExcelPath) == true)
{
//LogAPI.Debug("土地利用现状分类面积汇总表 不能被 成功 找到\r\n");
return result;
}
//LogAPI.Debug("土地利用现状分类面积汇总表 能被 成功 找到\r\n");
tempPath = AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\BGTJ\\土地利用现状变更表.xlsx";
//File.Copy(tempPath, saveCurrentPath, true);
dtExport = dbHelper.ExecuteDatatable("TDLYXZBHPHTJB_TEMP", " select * from TDLYXZBHPHTJB_TEMP ", true);
}
if (dtExport == null)
return result;
Workbook workbook = new Workbook(tempPath);
Cells cells = workbook.Worksheets[0].Cells;
Style style3 = workbook.CreateStyle();//.Styles[workbook.Styles.Add()];//新增样式
style3.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style3.VerticalAlignment = TextAlignmentType.Center;//文字居中
style3.Font.Name = "宋体";//文字字体
style3.Font.Size = 10;//文字大小
style3.Font.IsBold = false;
style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
Dictionary dic = GetDicTDLYXZBHPHTJB();
Dictionary dicValue = GetDicTDLYXZBHPHTJB();
foreach (KeyValuePair kvp in dic)
{
DataRow[] drSet = dtExport.Select(string.Format(" BGQDLBM='{0}' and BGHDLBM='{1}' ", kvp.Key.BGQDLBM, kvp.Key.BGHDLBM));
if (drSet != null && drSet.Length > 0)
{
double gqmj = double.Parse(drSet[0]["MJ"].ToString());
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(gqmj.ToString("f2"));
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
dicValue[new ExcelCell() { BGQDLBM = kvp.Key.BGQDLBM, BGHDLBM = kvp.Key.BGHDLBM, ColIndex = kvp.Key.ColIndex, RowIndex = kvp.Key.RowIndex }] = double.Parse(gqmj.ToString("f2"));
}
else
{
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(0);
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
}
}
//调入面积
List lstDLBM = new List() { "00", "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108", "01", "0101", "0102", "0103", "02", "0201", "0202", "0203", "0204", "03", "0301", "0302", "0305", "0307", "04", "0401", "0403", "0404", "05", "05H1", "0508", "06", "0601", "0602", "07", "0701", "0702", "08", "08H1", "08H2", "0809", "0810", "09", "10", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009", "11", "1101", "1102", "1103", "1104", "1107", "1109", "1110", "12", "1201", "1202", "1203", "1204", "1205", "1206", "1207" };
int j = 0;
foreach (string item in lstDLBM)
{
DataRow[] drSet = dt.Select(string.Format(" BGHDLBM='{0}' and (XZQTZLX='1' or XZQTZLX='3') ", item));
double TRMJ = 0;
if (drSet != null && drSet.Length > 0)
{
foreach (DataRow dr in drSet)
{
TRMJ += Convert.ToDouble(dr["BGMJ"] == null ? "0" : dr["BGMJ"].ToString());
}
}
cells[5, 2 + j].PutValue(TRMJ);
cells[5, 2 + j].SetStyle(style3);
j++;
}
//调出面积
j = 0;
foreach (string item in lstDLBM)
{
DataRow[] drSet = dt.Select(string.Format(" BGQDLBM='{0}' and (XZQTZLX='2' or XZQTZLX='4') ", item));
double TRMJ = 0;
if (drSet != null && drSet.Length > 0)
{
foreach (DataRow dr in drSet)
{
TRMJ += Convert.ToDouble(dr["BGMJ"] == null ? "0" : dr["BGMJ"].ToString());
}
}
cells[6, 2 + j].PutValue(TRMJ);
cells[6, 2 + j].SetStyle(style3);
j++;
}
foreach (KeyValuePair kvp in dicValue)
{
double sumMJ = 0;
if (kvp.Key.BGQDLBM.Length == 2 && kvp.Key.BGHDLBM.Length != 2)
{
sumMJ = 0;
int count = 0;
switch (kvp.Key.BGQDLBM)
{
case "00":
List lst00 = new List() { "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
if (lst00.Contains(kvp.Key.BGHDLBM))
continue;
count = 8; break;
case "01":
List lst01 = new List() { "0101", "0102", "0103" };
if (lst01.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "02":
List lst02 = new List() { "0201", "0202", "0203", "0204" };
if (lst02.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "03":
List lst03 = new List() { "0301", "0302", "0305", "0307" };
if (lst03.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "04":
List lst04 = new List() { "0401", "0403", "0404" };
if (lst04.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "05":
List lst05 = new List() { "05H1", "0508" };
if (lst05.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "06":
List lst06 = new List() { "0601", "0602" };
if (lst06.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "07":
List lst07 = new List() { "0701", "0702" };
if (lst07.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "08":
List lst08 = new List() { "08H1", "08H2", "0809", "0810" };
if (lst08.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "09": continue;
case "10":
List lst10 = new List() { "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009" };
if (lst10.Contains(kvp.Key.BGHDLBM))
continue;
count = 9; break;
case "11":
List lst11 = new List() { "1101", "1102", "1103", "1104", "1107", "1109", "1110" };
if (lst11.Contains(kvp.Key.BGHDLBM))
continue;
count = 7; break;
case "12":
List lst12 = new List() { "1201", "1202", "1203", "1204", "1205", "1206", "1207" };
if (lst12.Contains(kvp.Key.BGHDLBM))
continue;
count = 7; break;
}
for (int i = 1; i < count + 1; i++)
{
var value = cells[kvp.Key.RowIndex + i, kvp.Key.ColIndex].Value;
if (value != null)
{
sumMJ += double.Parse(value.ToString());
}
}
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(sumMJ);
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
}
if (kvp.Key.BGQDLBM.Length != 2 && kvp.Key.BGHDLBM.Length == 2)
{
sumMJ = 0;
int count = 0;
switch (kvp.Key.BGHDLBM)
{
case "00":
List lst00 = new List() { "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
if (lst00.Contains(kvp.Key.BGQDLBM))
continue;
count = 8; break;
case "01":
List lst01 = new List() { "0101", "0102", "0103" };
if (lst01.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "02":
List lst02 = new List() { "0201", "0202", "0203", "0204" };
if (lst02.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "03":
List lst03 = new List() { "0301", "0302", "0305", "0307" };
if (lst03.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "04":
List lst04 = new List() { "0401", "0403", "0404" };
if (lst04.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "05":
List lst05 = new List() { "05H1", "0508" };
if (lst05.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "06":
List lst06 = new List() { "0601", "0602" };
if (lst06.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "07":
List lst07 = new List() { "0701", "0702" };
if (lst07.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "08":
List lst08 = new List() { "08H1", "08H2", "0809", "0810" };
if (lst08.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "09": continue;
case "10":
List lst10 = new List() { "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009" };
if (lst10.Contains(kvp.Key.BGQDLBM))
continue;
count = 9; break;
case "11":
List lst11 = new List() { "1101", "1102", "1103", "1104", "1107", "1109", "1110" };
if (lst11.Contains(kvp.Key.BGQDLBM))
continue;
count = 7; break;
case "12":
List lst12 = new List() { "1201", "1202", "1203", "1204", "1205", "1206", "1207" };
if (lst12.Contains(kvp.Key.BGQDLBM))
continue;
count = 7; break;
}
for (int i = 1; i < count + 1; i++)
{
var value = cells[kvp.Key.RowIndex, kvp.Key.ColIndex + i].Value;
if (value != null)
{
sumMJ += double.Parse(value.ToString());
}
}
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(sumMJ);
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
}
}
if (ncsjExcelPath != string.Empty)
{
int startRol;
int mcRol;
int rolFirst;
int colFirst;
int MaxCol;
Workbook workbookNC = new Workbook(ncsjExcelPath);
Cells cellsNC = workbookNC.Worksheets[0].Cells;
int valueRow = 0;
if (isHaiDao)//海岛的表结构
{
startRol = 5;
mcRol = 5;
rolFirst = 8;
colFirst = 2;
MaxCol = 73;//总列数
for (int i = 0; i < cellsNC.MaxRow; i++)
{
if (cellsNC[i, mcRol].IsMerged == false && cellsNC[i, mcRol].Value != null && (cellsNC[i, mcRol].Value.ToString().Trim().Contains("小计") && cellsNC[i, mcRol].Value.ToString().Trim().Contains("00")))
{
valueRow = i + 1;
break;
}
if (cellsNC[i, mcRol].IsMerged == true && cellsNC[i, mcRol].Value != null && (cellsNC[i, mcRol].Value.ToString().Trim().Contains("小计") && cellsNC[i, mcRol].Value.ToString().Trim().Contains("00")))
{
valueRow = i + cellsNC[i, 0].GetMergedRange().RowCount + 1;
break;
}
}
}
else
{
//土地类型的表结构
startRol = 3;
mcRol = 0;
rolFirst = 11;
colFirst = 2;
MaxCol = 71;//总列数
for (int i = 0; i < cellsNC.MaxRow; i++)
{
if (cellsNC[i, mcRol].IsMerged == false && cellsNC[i, mcRol].Value != null && cellsNC[i, mcRol].Value.ToString() == "名称")
{
valueRow = i + 1;
break;
}
if (cellsNC[i, mcRol].IsMerged == true && cellsNC[i, mcRol].Value != null && cellsNC[i, mcRol].Value.ToString() == "名称")
{
valueRow = i + cellsNC[i, 0].GetMergedRange().RowCount + 1;
break;
}
}
}
//上年末面积
for (int i = startRol; i < MaxCol; i++)
{
cells[4, 2 + i - startRol].PutValue(cellsNC[valueRow, i].Value);
cells[4, 2 + i - startRol].SetStyle(style3);
}
//年内增加
for (int i = startRol; i < MaxCol; i++)
{
double total = 0;
foreach (KeyValuePair kvp in dicValue)
{
if (kvp.Key.ColIndex == 2 + i - startRol)
{
//一级类相同地类不计算增加减少
bool isContinue = false;
if (i >= startRol && i <= startRol + 8 && kvp.Key.RowIndex >= rolFirst && kvp.Key.RowIndex <= rolFirst + 8) isContinue = true;
else if (i >= startRol + 9 && i <= startRol + 12 && kvp.Key.RowIndex >= rolFirst + 9 && kvp.Key.RowIndex <= rolFirst + 12) isContinue = true;
else if (i >= startRol + 13 && i <= startRol + 17 && kvp.Key.RowIndex >= rolFirst + 13 && kvp.Key.RowIndex <= rolFirst + 17) isContinue = true;
else if (i >= startRol + 18 && i <= startRol + 22 && kvp.Key.RowIndex >= rolFirst + 18 && kvp.Key.RowIndex <= rolFirst + 22) isContinue = true;
else if (i >= startRol + 23 && i <= startRol + 26 && kvp.Key.RowIndex >= rolFirst + 23 && kvp.Key.RowIndex <= rolFirst + 26) isContinue = true;
else if (i >= startRol + 27 && i <= startRol + 29 && kvp.Key.RowIndex >= rolFirst + 27 && kvp.Key.RowIndex <= rolFirst + 29) isContinue = true;
else if (i >= startRol + 30 && i <= startRol + 32 && kvp.Key.RowIndex >= rolFirst + 30 && kvp.Key.RowIndex <= rolFirst + 32) isContinue = true;
else if (i >= startRol + 33 && i <= startRol + 35 && kvp.Key.RowIndex >= rolFirst + 33 && kvp.Key.RowIndex <= rolFirst + 35) isContinue = true;
else if (i >= startRol + 36 && i <= startRol + 40 && kvp.Key.RowIndex >= rolFirst + 36 && kvp.Key.RowIndex <= rolFirst + 40) isContinue = true;
else if (i >= startRol + 41 && i <= startRol + 41 && kvp.Key.RowIndex >= rolFirst + 41 && kvp.Key.RowIndex <= rolFirst + 41) isContinue = true;
else if (i >= startRol + 42 && i <= startRol + 51 && kvp.Key.RowIndex >= rolFirst + 42 && kvp.Key.RowIndex <= rolFirst + 51) isContinue = true;
else if (i >= startRol + 52 && i <= startRol + 59 && kvp.Key.RowIndex >= rolFirst + 52 && kvp.Key.RowIndex <= rolFirst + 59) isContinue = true;
else if (i >= startRol + 60 && i <= startRol + 67 && kvp.Key.RowIndex >= rolFirst + 60 && kvp.Key.RowIndex <= rolFirst + 67) isContinue = true;
if (isContinue)
continue;
if (kvp.Value > 0)
total += kvp.Value;
}
}
cells[8, 2 + i - startRol].PutValue(total);
cells[8, 2 + i - startRol].SetStyle(style3);
}
//年内减少
for (int i = startRol; i < MaxCol; i++)
{
double total = 0;
foreach (KeyValuePair kvp in dicValue)
{
if (kvp.Key.RowIndex == 11 + i - startRol)
{
//一级类相同地类不计算增加减少
bool isContinue = false;
if (i >= startRol && i <= startRol + 8 && kvp.Key.ColIndex >= colFirst && kvp.Key.ColIndex <= colFirst + 8) isContinue = true;
else if (i >= startRol + 9 && i <= startRol + 12 && kvp.Key.ColIndex >= colFirst + 9 && kvp.Key.ColIndex <= colFirst + 12) isContinue = true;
else if (i >= startRol + 13 && i <= startRol + 17 && kvp.Key.ColIndex >= colFirst + 13 && kvp.Key.ColIndex <= colFirst + 17) isContinue = true;
else if (i >= startRol + 18 && i <= startRol + 22 && kvp.Key.ColIndex >= colFirst + 18 && kvp.Key.ColIndex <= colFirst + 22) isContinue = true;
else if (i >= startRol + 23 && i <= startRol + 26 && kvp.Key.ColIndex >= colFirst + 23 && kvp.Key.ColIndex <= colFirst + 26) isContinue = true;
else if (i >= startRol + 27 && i <= startRol + 29 && kvp.Key.ColIndex >= colFirst + 27 && kvp.Key.ColIndex <= colFirst + 29) isContinue = true;
else if (i >= startRol + 30 && i <= startRol + 32 && kvp.Key.ColIndex >= colFirst + 30 && kvp.Key.ColIndex <= colFirst + 32) isContinue = true;
else if (i >= startRol + 33 && i <= startRol + 35 && kvp.Key.ColIndex >= colFirst + 33 && kvp.Key.ColIndex <= colFirst + 35) isContinue = true;
else if (i >= startRol + 36 && i <= startRol + 40 && kvp.Key.ColIndex >= colFirst + 36 && kvp.Key.ColIndex <= colFirst + 40) isContinue = true;
else if (i >= startRol + 41 && i <= startRol + 41 && kvp.Key.ColIndex >= colFirst + 41 && kvp.Key.ColIndex <= colFirst + 41) isContinue = true;
else if (i >= startRol + 42 && i <= startRol + 51 && kvp.Key.ColIndex >= colFirst + 42 && kvp.Key.ColIndex <= colFirst + 51) isContinue = true;
else if (i >= startRol + 52 && i <= startRol + 59 && kvp.Key.ColIndex >= colFirst + 52 && kvp.Key.ColIndex <= colFirst + 59) isContinue = true;
else if (i >= startRol + 60 && i <= startRol + 67 && kvp.Key.ColIndex >= colFirst + 60 && kvp.Key.ColIndex <= colFirst + 67) isContinue = true;
if (isContinue)
continue;
total += kvp.Value;
}
}
cells[9, 2 + i - startRol].PutValue(total);
cells[9, 2 + i - startRol].SetStyle(style3);
}
for (int i = 4; i < 79; i++)
{
GetTDLYXZBHPHTJBXJ(cells, i);
}
for (int i = startRol; i < MaxCol; i++)
{
double total = 0;
foreach (KeyValuePair kvp in dicValue)
{
if (kvp.Key.ColIndex == 2 + i - startRol)
{
if (kvp.Value > 0)
total += kvp.Value;
}
}
if (total != 0)
{
cells[8, 2 + i - startRol].PutValue(total);
cells[8, 2 + i - startRol].SetStyle(style3);
}
}
#region 特殊用地赋值
List lst = new List() { 11, 20, 24, 29, 34, 38, 41, 44, 47, 52, 53, 63, 71 };
List lst1 = new List() { 8, 3, 4, 4, 3, 2, 2, 2, 4, 0, 9, 7, 7 };
var index = 0;
foreach (var item in lst)
{
var mj = 0.00;
for (int i = item; i <= item + lst1[index]; i++)
{
var value = cells[i, 43].Value;
mj += value == null ? 0.00 : Convert.ToDouble(value);
}
cells[item, 43].PutValue(mj);
cells[item, 43].SetStyle(style3);
index += 1;
}
#endregion
for (int i = startRol; i < MaxCol; i++)
{
double total = 0;
foreach (KeyValuePair kvp in dicValue)
{
if (kvp.Key.RowIndex == 11 + i - startRol)
{
total += kvp.Value;
}
}
if (total != 0)
{
cells[9, 2 + i - startRol].PutValue(total);
cells[9, 2 + i - startRol].SetStyle(style3);
}
}
for (int i = 4; i < 79; i++)//76标识表格的总行数
{
GetTDLYXZBHPHTJBXJ(cells, i, false);
}
startRol = 3;
for (int i = startRol; i < 72; i++)//<72 表示表格总共有71列
{
double ncMJ = 0;
double zjMJ = 0;
double jsMJ = 0;
double hrMJ = 0;
double hcMJ = 0;
if (cells[4, 2 + i - startRol].Value != null)
{
var value = cells[4, 2 + i - startRol].Value;
if (!"".Equals(value))
{
ncMJ = double.Parse(value.ToString());
}
}
if (cells[5, 2 + i - startRol].Value != null)
{
var value = cells[5, 2 + i - startRol].Value;
if (!"".Equals(value))
{
hrMJ = double.Parse(value.ToString());
}
}
if (cells[6, 2 + i - startRol].Value != null)
{
var value = cells[6, 2 + i - startRol].Value;
if (!"".Equals(value))
{
hcMJ = double.Parse(value.ToString());
}
}
if (cells[8, 2 + i - startRol].Value != null)
{
var value = cells[8, 2 + i - startRol].Value;
if (!"".Equals(value))
{
zjMJ = double.Parse(value.ToString());
}
}
if (cells[9, 2 + i - startRol].Value != null)
{
var value = cells[9, 2 + i - startRol].Value;
if (!"".Equals(value))
{
jsMJ = double.Parse(value.ToString());
}
}
double tzmj = ncMJ + hrMJ - hcMJ;
cells[7, 2 + i - startRol].PutValue(tzmj);
cells[7, 2 + i - startRol].SetStyle(style3);
//调整年初面积负值,调整行政区划出的面积
if (isTZMJPC && tzmj < 0)
{
if (TZresult == null)
{
TZresult = new BBPCModel();
TZresult.ReportName = 1;
TZresult.Columns = new List();
}
PCColumnModel coluModel = new PCColumnModel();
coluModel.Ids = new List();
coluModel.IsActive = true;
coluModel.ColumnIndex = i;
coluModel.DiffValue = Math.Abs(tzmj);
ExcelCell cell = dic.Where(c => c.Key.ColIndex == (2 + i - startRol)).FirstOrDefault().Key;
if (cell == null || cell.BGHDLBM.Length == 2)
{
continue;
}
string sql = string.Empty;
sql = $"select ID from JCTJB_GQ where BGQDLBM='{cell.BGHDLBM}' and XZQTZLX in ('2','4')";
DataTable IDsTable = dbHelper.ExecuteDatatable("ids", sql, true);
string ids = string.Empty;
foreach (DataRow row in IDsTable.Rows)
{
coluModel.Ids.Add(Convert.ToInt32(row[0]));
}
TZresult.Columns.Add(coluModel);
TZNCbBPCModels.Add(TZresult);
}
//年末面积负值,不包括行政区划入、划出
if (tzmj + zjMJ - jsMJ < 0)
{
if (result == null)
{
result = new BBPCModel();
result.ReportName = 1;
result.Columns = new List();
}
PCColumnModel coluModel = new PCColumnModel();
coluModel.Ids = new List();
coluModel.IsActive = true;
coluModel.ColumnIndex = i;
coluModel.DiffValue = Math.Abs(ncMJ + zjMJ - jsMJ); //Math.Abs(cells[7, 2 + i - startRol].ToDouble());
ExcelCell cell = dic.Where(c => c.Key.ColIndex == (2 + i - startRol)).FirstOrDefault().Key;
if (cell == null || cell.BGHDLBM.Length == 2)
{
continue;
}
string sql = string.Empty;
sql = $"select ID from JCTJB_GQ where BGQDLBM='{cell.BGHDLBM}' and BGHDLBM != '{cell.BGHDLBM}' and XZQTZLX='0'";
DataTable IDsTable = dbHelper.ExecuteDatatable("ids", sql, true);
string ids = string.Empty;
foreach (DataRow row in IDsTable.Rows)
{
coluModel.Ids.Add(Convert.ToInt32(row[0]));
}
result.Columns.Add(coluModel);
}
cells[10, 2 + i - startRol].PutValue(tzmj + zjMJ - jsMJ);
cells[10, 2 + i - startRol].SetStyle(style3);
}
}
// cells[10, 2 + i - startRol].PutValue(ncMJ + zjMJ - jsMJ);
// cells[10, 2 + i - startRol].SetStyle(style3);
// if ((ncMJ + zjMJ - jsMJ) < 0)
// {
// if (result == null)
// {
// result = new BBPCModel();
// result.ReportName = 1;
// result.Columns = new List();
// }
// PCColumnModel coluModel = new PCColumnModel();
// coluModel.Ids = new List();
// coluModel.IsActive = true;
// coluModel.ColumnIndex = i;
// coluModel.DiffValue = Math.Abs(ncMJ + zjMJ - jsMJ); //Math.Abs(cells[7, 2 + i - startRol].ToDouble());
// ExcelCell cell = dic.Where(c => c.Key.ColIndex == (2 + i - startRol)).FirstOrDefault().Key;
// if (cell == null || cell.BGHDLBM.Length == 2)
// {
// continue;
// }
// string sql = string.Empty;
// sql = $"select ID from JCTJB_GQ where BGQDLBM='{cell.BGHDLBM}' and BGHDLBM != '{cell.BGHDLBM}'";
// DataTable IDsTable = dbHelper.ExecuteDatatable("ids", sql, true);
// string ids = string.Empty;
// foreach (DataRow row in IDsTable.Rows)
// {
// coluModel.Ids.Add(Convert.ToInt32(row[0]));
// }
// result.Columns.Add(coluModel);
// }
// }
//}
return result;
}
private bool ExportBGYLB(string saveCurrentPath, IRDBHelper dbHelper)
{
DataTable dtExport = null;
try
{
dtExport = dbHelper.ExecuteDatatable("BGYLB", " select * from BGYLB", true);
if (dtExport != null && dtExport.Rows.Count > 0)
{
dtExport.Columns.RemoveAt(dtExport.Columns.Count - 1);
string tempPath = AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\BGTJ\\土地变更一览表.xlsx";
File.Copy(tempPath, saveCurrentPath, true);
Workbook workbook = new Workbook(saveCurrentPath);
Cells cells = workbook.Worksheets[0].Cells;
Style style3 = workbook.CreateStyle();//.Styles[workbook.Styles.Add()];//新增样式
style3.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style3.VerticalAlignment = TextAlignmentType.Center;//文字居中
style3.Font.Name = "宋体";//文字字体
style3.Font.Size = 11;//文字大小
style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
//插入年份
//cells[1, 7].PutValue("(2020年)");
int i = 4;
foreach (DataRow dr in dtExport.Rows)
{
for (int col = 0; col < dtExport.Columns.Count; col++)
{
cells[i, col].PutValue(dr[col]);
cells[i, col].SetStyle(style3);
}
i++;
}
workbook.Save(saveCurrentPath);
return true;
}
else
{
string tempPath = AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\BGTJ\\土地变更一览表.xlsx";
File.Copy(tempPath, saveCurrentPath, true);
return false;
}
}
catch (Exception ex)
{
LogAPI.Debug("土地变更一览表生成失败" + ex.Message);
throw ex;
}
}
private bool ExportTDLYXZBHPHTJB(string saveCurrentPath, IRDBHelper dbHelper, string ncsjPath, bool isHaiDao = false)
{
DataTable dtExport = null;
string ncsjExcelPath = string.Empty;
DirectoryInfo dir = new DirectoryInfo(ncsjPath);
DataTable dt = dbHelper.ExecuteDatatable("BGYLB", " select BGQDLBM,BGHDLBM,XZQTZLX,BGMJ from BGYLB ", true);
FileInfo[] fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")土地利用现状分类面积汇总表.xlsx", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
}
else
{
fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")土地利用现状分类面积汇总表.xls", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
}
}
if (String.IsNullOrWhiteSpace(ncsjExcelPath) == true)
{
return false;
}
string tempPath = AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\BGTJ\\土地利用现状变更表.xlsx";
File.Copy(tempPath, saveCurrentPath, true);
dtExport = dbHelper.ExecuteDatatable("TDLYXZBHPHTJB_TEMP", " select * from TDLYXZBHPHTJB_TEMP ", true);
if (dtExport == null)
return false;
Workbook workbook = new Workbook(saveCurrentPath);
Cells cells = workbook.Worksheets[0].Cells;
Style style3 = workbook.CreateStyle();//.Styles[workbook.Styles.Add()];//新增样式
style3.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style3.VerticalAlignment = TextAlignmentType.Center;//文字居中
style3.Font.Name = "宋体";//文字字体
style3.Font.Size = 10;//文字大小
style3.Font.IsBold = false;
style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
Dictionary dic = GetDicTDLYXZBHPHTJB();
Dictionary dicValue = GetDicTDLYXZBHPHTJB();
foreach (KeyValuePair kvp in dic)
{
DataRow[] drSet = dtExport.Select(string.Format(" BGQDLBM='{0}' and BGHDLBM='{1}' ", kvp.Key.BGQDLBM, kvp.Key.BGHDLBM));
if (drSet != null && drSet.Length > 0)
{
double gqmj = double.Parse(drSet[0]["MJ"].ToString());
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(gqmj.ToString("f2"));
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
dicValue[new ExcelCell() { BGQDLBM = kvp.Key.BGQDLBM, BGHDLBM = kvp.Key.BGHDLBM, ColIndex = kvp.Key.ColIndex, RowIndex = kvp.Key.RowIndex }] = double.Parse(gqmj.ToString("f2"));
}
else
{
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(0);
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
}
}
//调入面积
List lstDLBM = new List() { "01", "0101", "0102", "0103", "02", "0201", "0202", "0203", "0204", "03", "0301", "0302", "0305", "0307", "04", "0401", "0403", "0404", "00", "0303", "0304", "0306", "0402", "1105", "1106", "1108", "11", "1101", "1102", "1103", "1104", "1107", "1110", "JSYD", "20", "201", "202", "203", "204", "205", "10", "1001", "1002", "1003", "1007", "1008", "1009", "1109", "12", "1006", "1202", "1203", "1204", "1205", "1206", "1207" };
int j = 0;
foreach (string item in lstDLBM)
{
DataRow[] drSet = dt.Select(string.Format(" BGHDLBM='{0}' and (XZQTZLX='1' or XZQTZLX='3') ", item));
double TRMJ = 0;
if (drSet != null && drSet.Length > 0)
{
foreach (DataRow dr in drSet)
{
TRMJ += Convert.ToDouble(dr["BGMJ"] == null ? "0" : dr["BGMJ"].ToString());
}
}
cells[5, 2 + j].PutValue(TRMJ);
cells[5, 2 + j].SetStyle(style3);
j++;
}
//调出面积
j = 0;
foreach (string item in lstDLBM)
{
DataRow[] drSet = dt.Select(string.Format(" BGQDLBM='{0}' and (XZQTZLX='2' or XZQTZLX='4') ", item));
double TRMJ = 0;
if (drSet != null && drSet.Length > 0)
{
foreach (DataRow dr in drSet)
{
TRMJ += Convert.ToDouble(dr["BGMJ"] == null ? "0" : dr["BGMJ"].ToString());
}
}
cells[6, 2 + j].PutValue(TRMJ);
cells[6, 2 + j].SetStyle(style3);
j++;
}
foreach (KeyValuePair kvp in dicValue)
{
double sumMJ = 0;
if (kvp.Key.BGQDLBM.Length == 2 && kvp.Key.BGHDLBM.Length != 2)
{
sumMJ = 0;
int count = 0;
switch (kvp.Key.BGQDLBM)
{
case "01":
List lst01 = new List