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

10978 lines
570 KiB

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 = "";
/// <summary>
/// 农村土地利用现状一级分类面积按权属性质汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>霍岩 2018-11-28 新增</returns>
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;
}
}
/// <summary>
/// 农村土地利用现状一级分类面积按权属性质汇总表(空)
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>王欢 2018-11-28 新增</returns>
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;
}
}
/// <summary>
/// 获取上级地类数据
/// </summary>
/// <param name="dtRST"></param>
/// <param name="NumColStartIndex">数值列开始索引</param>
/// <param name="NumColEndIndex">数值列结束索引</param>
/// <returns></returns>
private DataTable GetUpLevelData(DataTable dtRST, int NumColStartIndex, int NumColEndIndex)
{
try
{
//获取乡镇行政区代码
var QueryTown = from t in dtRST.AsEnumerable()
group t by new { t1 = t.Field<string>("xzqdm_t") } into m
select new { xzqdm = m.Key.t1 };
//获取县行政区代码
var QueryCounty = from t in dtRST.AsEnumerable()
group t by new { t1 = t.Field<string>("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<DataDicTionary> QSList = null;
/// <summary>
/// 获取行政区名称
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="dtRst"></param>
/// <returns></returns>
private DataTable GetXZQMC(IRDBHelper dbHelper, ref DataTable dtRst, string tblName = "DLTB")
{
try
{
if (dtRst != null)
{
List<BasicDataModel> CountyList = GetXZQDic(1).ToList();
List<BasicDataModel> TownList = GetXZQDic(2).ToList();
List<BasicDataModel> XZQList = GetXZQDic(3).ToList();
List<BasicDataModel> 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<DataDicTionary>(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<BasicDataModel> CountyListHD = GetXZQDic(1).ToList();
List<Dictionary<string, object>> dic = new List<Dictionary<string, object>>();
foreach (BasicDataModel model in CountyListHD)
{
dic.Add(model.Attribures);
}
List<string> hdmclist = new List<string>();
string hdmc = string.Empty;
foreach (Dictionary<string, object> 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<BasicDataModel> bdm2 = TownList.FindAll(x => x.Code == strXZQDM);
if (bdm2 != null && bdm2.Count > 0)
dr["XZQMC"] = bdm2[0].Name;
if (dtRst.Columns.Contains("HDMC"))
{
List<Dictionary<string, object>> diclist2 = new List<Dictionary<string, object>>();
foreach (BasicDataModel model in bdm2)
{
diclist2.Add(model.Attribures);
}
List<string> hdmclist = new List<string>();
string hdmc = string.Empty;
foreach (Dictionary<string, object> 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<BasicDataModel> drcXZQ = XZQList.FindAll(x => x.Code == strXZQDM);
if (drcXZQ != null && drcXZQ.Count > 0)
{
dr["XZQMC"] = drcXZQ[0].Name;
}
if (dtRst.Columns.Contains("HDMC"))
{
List<BasicDataModel> drc = HDList.FindAll(x => x.Code == strXZQDM);
if (drc != null && drc.Count > 0)
{
List<string> hdmclist = new List<string>();
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<BasicDataModel> 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;
}
}
/// <summary>
/// 获取行政区字典数据
/// </summary>
/// <param name="pLevel">行政级别(1:县、2:镇、3:村、4:海岛)</param>
public static BasicDataModel[] GetXZQDic(int pLevel)
{
List<BasicDataModel> result = new List<BasicDataModel>();
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<string, object>();
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<string, object>();
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<string, object>();
//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<string, object>();
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;
}
/// <summary>
/// 农村土地利用现状一级分类面积汇总表(县行政区划码6位)
/// </summary>
/// /// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// 霍岩 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;
}
}
/// <summary>
/// 土地利用现状分类面积汇总表(县行政区划码6位)
/// </summary>
/// /// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// 霍岩 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;
/// <summary>
/// 导出excel(2018-11-23格式调整)
/// </summary>
/// <param name="dt"></param>
/// <param name="columns"></param>
/// <param name="savePath"></param>
/// <param name="tileName"></param>
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<BasicDataModel> CountyList = GetXZQDic(1).ToList();
List<BasicDataModel> TownList = GetXZQDic(2).ToList();
List<BasicDataModel> 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
/// <summary>
/// 面积单位转换值公顷为1,亩为15,默认公顷
/// </summary>
public int MjConvertValue { get; set; } = 1;
private ReportFileTypeEnum reportFileType;
/// <summary>
/// 统计表导出格式类型
/// </summary>
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;
/// <summary>
/// 导出表名(公顷和亩MJHZJCTJB,平方米用 MJHZJCTJB2)
/// </summary>
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导出方法
/// <summary>
/// 移除数据,非当前行政区的,或者行政区代码为空的(主要用途,当选择某一个村的时候,过滤掉其他的数据)
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="xzq"></param>
/// <param name="dt"></param>
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());
// //}
// }
//}
}
/// <summary>
/// 移除数据,非当前行政区的,或者行政区代码为空的(主要用途,当选择某一个村的时候,过滤掉其他的数据)
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="xzq"></param>
/// <param name="dt"></param>
/// <remarks>重载方法 王欢 2018-09-29</remarks>
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\\";
}
/// <summary>
/// 清除---1土地利用现状一级分类面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="sqlwhere">sql条件</param>
/// <param name="dt"></param>
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<double>("KCMJ"));
if (kcmj > 0)
{
continue;
}
}
dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
}
}
}
}
}
}
}
/// <summary>
/// 获取土地利用现状一级分类or二级分类,类名集合
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="isel">是否获取二级分类,默认false</param>
/// <returns></returns>
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城镇村及工矿用地面积汇总表
/// <summary>
/// 4城镇村及工矿用地面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 飞入地——4城镇村及工矿用地面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 4城镇村及工矿用地面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 飞入地——4城镇村及工矿用地面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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<string> columnlist;
List<DLBMTJEntity> dlbmlist;
List<string> 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<string> 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;
}
/// <summary>
/// 4城镇村及工矿用地面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <returns>霍岩 2018-11-29 修改</returns>
private DataTable GetCZCJGKYDMJHZBData(IRDBHelper dbHelper, bool isfrd = false)
{
string[] czcarry = new string[] { "C201", "C202", "C203", "C204", "C205" };
List<string> columnlist;
List<DLBMTJEntity> dlbmlist;
List<string> 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<string> 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;
}
/// <summary>
/// 设置汇总合计值
/// </summary>
/// <param name="czcarry"></param>
/// <param name="dlbmlist"></param>
/// <param name="xjdr"></param>
private void SetDrHZValue(string[] czcarry, List<DLBMTJEntity> 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;
}
}
/// <summary>
/// 获取城镇村及工矿用地表结构
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
private DataTable GetCZCJGKYDMJHZBDT(IRDBHelper dbHelper, string[] czcarry, out List<string> columnlist, out List<DLBMTJEntity> dlbmlist, out List<string> ejdllist, bool IsFRD = false)
{
try
{
columnlist = new List<string>();
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;
}
}
/// <summary>
/// 清除---4城镇村及工矿用地面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="sqlwhere">sql条件</param>
/// <param name="dt"></param>
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<double>("KCMJ"));
//if (kcmj > 0)
//{
// continue;
//}
//}
//dt.Rows[i][item.ColumnName] = 0D;//DBNull.Value;
//}
}
}
}
}
}
}
#endregion
#region 5耕地坡度分级面积汇总表
/// <summary>
/// 5耕地坡度分级面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 5耕地坡度分级面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 5耕地坡度分级面积汇总表(空表)
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns> 王欢 2018-12-07</returns>
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;
}
}
/// <summary>
/// 5耕地坡度分级面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
private DataTable GetGDPDFJMJHZBData(IRDBHelper dbHelper)
{
string[] ttlxarry = new string[] { "TT2", "TT3", "TT4", "TT5" };
string[] pdlxarry = new string[] { "PD2", "PD3", "PD4", "PD5" };
List<string> columnlist = new List<string>();
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;
}
/// <summary>
/// 清除---5耕地坡度分级面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="sqlwhere">sql条件</param>
/// <param name="dt"></param>
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耕地种植类型面积统计表
/// <summary>
/// 6耕地种植类型面积统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 6耕地种植类型面积统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 6耕地种植类型面积统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <returns>霍岩 2018-11-29 修改</returns>
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<string> columnlist;
List<DLBMTJEntity> dlbmlist;
List<string> 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<DataColumn>().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<string> columnlist, out List<DLBMTJEntity> dlbmlist, out List<string> ejdllist, string[] ejdlbms = null, bool IsKHF = false, bool IsFQ = false)
{
columnlist = new List<string>();
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;
}
/// <summary>
/// 清除---6耕地种植类型面积统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="sqlwhere">sql条件</param>
/// <param name="dt"></param>
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林区范围内园地汇总统计表
/// <summary>
/// 7林区范围内园地汇总统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 7林区范围内园地汇总统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 7林区范围内园地汇总统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
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();
}
/// <summary>
/// 清除---7林区范围内园地汇总统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="sqlwhere">sql条件</param>
/// <param name="dt"></param>
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灌丛草地汇总情况统计表
/// <summary>
/// 8灌丛草地汇总情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 8灌丛草地汇总情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 8灌丛草地汇总情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 清除---8灌丛草地汇总情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="sqlwhere">sql条件</param>
/// <param name="dt"></param>
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工业仓储用地按类型汇总统计表
/// <summary>
/// 9工业仓储用地按类型汇总统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 9工业仓储用地按类型汇总统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 9工业仓储用地按类型汇总统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
/// 霍岩 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;
}
/// <summary>
/// 清除---9工业仓储用地按类型汇总统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="sqlwhere">sql条件</param>
/// <param name="dt"></param>
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基本农田外可调整地类面积汇总表
/// <summary>
/// 10基本农田外可调整地类面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 土地利用现状变更表(NULL)
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <param name="selectht"></param>
/// <returns> 王欢 2018-12-03</returns>
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;
}
}/// <summary>
/// 文字输出功能的各个表,输出空文档
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <param name="selectht"></param>
/// <returns> 白明雅 2018-12-08</returns>
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;
}
}
/// <summary>
/// 土地变更一览表 (NULL)
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <param name="selectht"></param>
/// <returns> 王欢 2018-12-03</returns>
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;
}
}
/// <summary>
/// 10可调整地类面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 10基本农田外可调整地类面积汇总表(空表)
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 10可调整地类面积汇总表(通过DLTB属性带K的统计)
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
/// 霍岩 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部分细化地类面积汇总表
/// <summary>
/// 11部分细化地类面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 11部分细化地类面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 11部分细化地类面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 清除---11部分细化地类面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="sqlwhere">sql条件</param>
/// <param name="dt"></param>
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湿地调查面积统计表
/// <summary>
/// 12湿地调查面积统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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耕地细化调查情况统计表
/// <summary>
/// 13耕地细化调查情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 13耕地细化调查情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 13耕地细化调查情况统计表(通过压盖统计)
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
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批准未建设的建设用地用途情况统计表
/// <summary>
/// 14批准未建设的建设用地用途情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 14批准未建设的建设用地用途情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 14批准未建设的建设用地用途情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
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<string, decimal> updateejdldic = new Dictionary<string, decimal>();
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;
}
}
/// <summary>
/// 清除---1土地利用现状一级分类面积汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="cname">列名</param>
/// <param name="dt"></param>
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批准未建设的建设用地现状情况统计表
/// <summary>
/// 15批准未建设的建设用地现状情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 15批准未建设的建设用地现状情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns>多选设置后重载方法 王欢 2018-09-29</returns>
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;
}
}
/// <summary>
/// 15批准未建设的建设用地现状情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
private DataTable PZWJSDJSYDXZQKTJBData(IRDBHelper dbHelper)
{
try
{
string tbl = null;
if (mjconvertvalue2 == "0.0001")
{
tbl = "MJHZJCTJB_PZWJSYD";
}
else
{
tbl = "MJHZJCTJB_PZWJSYD2";
}
List<string> columnlist = new List<string>();
List<DLBMTJEntity> dlbmlist;
List<string> 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;
}
}
/// <summary>
/// 将 批准未建设的建设用地用途情况统计表/批准未建设的建设用地现状情况统计表 数据表中的特殊地类(以A或者K结尾)字段去掉
/// </summary>
/// <param name="dtDealWith"></param>
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;
}
}
/// <summary>
/// 16永久基本农田现状情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 16永久基本农田现状情况统计表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <param name="selectht"></param>
/// <returns></returns>
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<DataColumn> ColList = dtRst.Columns.Cast<DataColumn>().ToList();
//for (int i = 0; i <= 12; i++)
//{
// string colname = string.Format("DL{0:D2}", i);
// string colexpr = string.Empty;
// List<DataColumn> 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<DataColumn> 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;
}
}
/// <summary>
/// 行内平差
/// </summary>
/// <param name="dlbmlist"></param>
/// <param name="cjdr"></param>
private void PZWJSXZPC(List<DLBMTJEntity> dlbmlist, DataRow cjdr)
{
try
{
#region 行内平差
bool pc = true;
while (pc)
{
pc = false;
decimal h = 0;
Dictionary<string, decimal> updateejdldic = new Dictionary<string, decimal>();
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权属单位代码表
/// <summary>
/// 20权属单位代码表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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<DataDicTionary> 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;
}
}
/// <summary>
/// 20权属单位代码表(空表)
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns> 王欢 2018-12-07</returns>
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;
}
}
/// <summary>
/// 20权属单位代码表
/// </summary>
/// <param name="dbHelper"></param>
/// <returns></returns>
private void QSDWDMBData(List<DataDicTionary> dicList, DataTable dt)
{
try
{
//List<DataDicTionary> chlidlist = new List<DataDicTionary>();
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 样方田坎系数测算表输出
/// <summary>
/// 白明雅 2018-12-03 样方田坎系数测算表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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 田坎系数表
/// <summary>
/// 白明雅 2018-12-03 田坎系数表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="savePath"></param>
/// <returns></returns>
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
/// <summary>
/// 导出excel
/// </summary>
/// <param name="dt"></param>
/// <param name="columns"></param>
/// <param name="savePath"></param>
/// <param name="tileName"></param>
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<SheetColumnEntity> SheetColumnslist = new List<SheetColumnEntity>();
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);
}
/// <summary>
/// 导出汇总表
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 验证一键成果导出的报表的年初数据Excel所在地址是否有效
/// </summary>
/// <param name="reportEntity"></param>
/// <param name="ncsjPath"></param>
/// <returns></returns>
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;
}
}
/// <summary>
/// 演示用导出空表使用
/// </summary>
/// <param name="saveCurrentPath"></param>
/// <param name="dbHelper"></param>
/// <param name="reportEntity"></param>
/// <param name="selectht"></param>
/// <returns>王欢 2018-12-11 后面加备注的为当前在用</returns>
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;
}
}
/// <summary>
/// 行政区调整平差
/// </summary>
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<ExcelCell, double> dic = GetDicTDLYXZBHPHTJB();
Dictionary<ExcelCell, double> dicValue = GetDicTDLYXZBHPHTJB();
foreach (KeyValuePair<ExcelCell, double> 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<string> lstDLBM = new List<string>() { "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<ExcelCell, double> 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<string> lst00 = new List<string>() { "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
if (lst00.Contains(kvp.Key.BGHDLBM))
continue;
count = 8; break;
case "01":
List<string> lst01 = new List<string>() { "0101", "0102", "0103" };
if (lst01.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "02":
List<string> lst02 = new List<string>() { "0201", "0202", "0203", "0204" };
if (lst02.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "03":
List<string> lst03 = new List<string>() { "0301", "0302", "0305", "0307" };
if (lst03.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "04":
List<string> lst04 = new List<string>() { "0401", "0403", "0404" };
if (lst04.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "05":
List<string> lst05 = new List<string>() { "05H1", "0508" };
if (lst05.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "06":
List<string> lst06 = new List<string>() { "0601", "0602" };
if (lst06.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "07":
List<string> lst07 = new List<string>() { "0701", "0702" };
if (lst07.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "08":
List<string> lst08 = new List<string>() { "08H1", "08H2", "0809", "0810" };
if (lst08.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "09": continue;
case "10":
List<string> lst10 = new List<string>() { "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009" };
if (lst10.Contains(kvp.Key.BGHDLBM))
continue;
count = 9; break;
case "11":
List<string> lst11 = new List<string>() { "1101", "1102", "1103", "1104", "1107", "1109", "1110" };
if (lst11.Contains(kvp.Key.BGHDLBM))
continue;
count = 7; break;
case "12":
List<string> lst12 = new List<string>() { "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<string> lst00 = new List<string>() { "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
if (lst00.Contains(kvp.Key.BGQDLBM))
continue;
count = 8; break;
case "01":
List<string> lst01 = new List<string>() { "0101", "0102", "0103" };
if (lst01.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "02":
List<string> lst02 = new List<string>() { "0201", "0202", "0203", "0204" };
if (lst02.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "03":
List<string> lst03 = new List<string>() { "0301", "0302", "0305", "0307" };
if (lst03.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "04":
List<string> lst04 = new List<string>() { "0401", "0403", "0404" };
if (lst04.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "05":
List<string> lst05 = new List<string>() { "05H1", "0508" };
if (lst05.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "06":
List<string> lst06 = new List<string>() { "0601", "0602" };
if (lst06.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "07":
List<string> lst07 = new List<string>() { "0701", "0702" };
if (lst07.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "08":
List<string> lst08 = new List<string>() { "08H1", "08H2", "0809", "0810" };
if (lst08.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "09": continue;
case "10":
List<string> lst10 = new List<string>() { "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009" };
if (lst10.Contains(kvp.Key.BGQDLBM))
continue;
count = 9; break;
case "11":
List<string> lst11 = new List<string>() { "1101", "1102", "1103", "1104", "1107", "1109", "1110" };
if (lst11.Contains(kvp.Key.BGQDLBM))
continue;
count = 7; break;
case "12":
List<string> lst12 = new List<string>() { "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<ExcelCell, double> 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<ExcelCell, double> 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<ExcelCell, double> 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<int> lst = new List<int>() { 11, 20, 24, 29, 34, 38, 41, 44, 47, 52, 53, 63, 71 };
List<int> lst1 = new List<int>() { 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<ExcelCell, double> 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<ReportEntityClass> exportTypes = eh.GetReportEntityZLGLClassList();
List<BBPCModel> pcModelList = new List<BBPCModel>();
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<int> NotActiveID = new List<int>();
if (pcModelList.Count > 0)
{
Dictionary<int, int> idNum = new Dictionary<int, int>();
List<int> IDCount = new List<int>();//重复度最高的ID
Dictionary<string, List<int>> directory = new Dictionary<string, List<int>>();
List<PCColumnModel> combination = new List<PCColumnModel>();//列组合
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<int>() { ID });
continue;
}
directory[str].Add(ID);
}
List<int> TbColIndex = new List<int>();
List<int> IDs = new List<int>();
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<string, int>(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);
}
}
}
}
}
//}
}
}
}
/// <summary>
/// 调整后年末面积负值平差
/// </summary>
/// <param name="dbHelper"></param>
/// <param name="ncsjPath"></param>
/// <param name="reportEntity"></param>
public void TZNCMJExportCheckNegative(IRDBHelper dbHelper, string ncsjPath, ReportEntityClass reportEntity)
{
ExportHelper eh = new ExportHelper();
List<ReportEntityClass> exportTypes = eh.GetReportEntityZLGLClassList();
List<BBPCModel> pcModelList = new List<BBPCModel>();
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<int> NotActiveID = new List<int>();
if (pcModelList.Count > 0)
{
Dictionary<int, int> idNum = new Dictionary<int, int>();
List<int> IDCount = new List<int>();//重复度最高的ID
Dictionary<string, List<int>> directory = new Dictionary<string, List<int>>();
List<PCColumnModel> combination = new List<PCColumnModel>();//列组合
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<int>() { ID });
continue;
}
directory[str].Add(ID);
}
List<int> TbColIndex = new List<int>();
List<int> IDs = new List<int>();
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<string, int>(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<BBPCModel> 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<ExcelCell, double> dic = GetDicTDLYXZBHPHTJB();
Dictionary<ExcelCell, double> dicValue = GetDicTDLYXZBHPHTJB();
foreach (KeyValuePair<ExcelCell, double> 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<string> lstDLBM = new List<string>() { "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<ExcelCell, double> 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<string> lst00 = new List<string>() { "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
if (lst00.Contains(kvp.Key.BGHDLBM))
continue;
count = 8; break;
case "01":
List<string> lst01 = new List<string>() { "0101", "0102", "0103" };
if (lst01.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "02":
List<string> lst02 = new List<string>() { "0201", "0202", "0203", "0204" };
if (lst02.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "03":
List<string> lst03 = new List<string>() { "0301", "0302", "0305", "0307" };
if (lst03.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "04":
List<string> lst04 = new List<string>() { "0401", "0403", "0404" };
if (lst04.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "05":
List<string> lst05 = new List<string>() { "05H1", "0508" };
if (lst05.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "06":
List<string> lst06 = new List<string>() { "0601", "0602" };
if (lst06.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "07":
List<string> lst07 = new List<string>() { "0701", "0702" };
if (lst07.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "08":
List<string> lst08 = new List<string>() { "08H1", "08H2", "0809", "0810" };
if (lst08.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "09": continue;
case "10":
List<string> lst10 = new List<string>() { "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009" };
if (lst10.Contains(kvp.Key.BGHDLBM))
continue;
count = 9; break;
case "11":
List<string> lst11 = new List<string>() { "1101", "1102", "1103", "1104", "1107", "1109", "1110" };
if (lst11.Contains(kvp.Key.BGHDLBM))
continue;
count = 7; break;
case "12":
List<string> lst12 = new List<string>() { "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<string> lst00 = new List<string>() { "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
if (lst00.Contains(kvp.Key.BGQDLBM))
continue;
count = 8; break;
case "01":
List<string> lst01 = new List<string>() { "0101", "0102", "0103" };
if (lst01.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "02":
List<string> lst02 = new List<string>() { "0201", "0202", "0203", "0204" };
if (lst02.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "03":
List<string> lst03 = new List<string>() { "0301", "0302", "0305", "0307" };
if (lst03.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "04":
List<string> lst04 = new List<string>() { "0401", "0403", "0404" };
if (lst04.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "05":
List<string> lst05 = new List<string>() { "05H1", "0508" };
if (lst05.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "06":
List<string> lst06 = new List<string>() { "0601", "0602" };
if (lst06.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "07":
List<string> lst07 = new List<string>() { "0701", "0702" };
if (lst07.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "08":
List<string> lst08 = new List<string>() { "08H1", "08H2", "0809", "0810" };
if (lst08.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "09": continue;
case "10":
List<string> lst10 = new List<string>() { "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009" };
if (lst10.Contains(kvp.Key.BGQDLBM))
continue;
count = 9; break;
case "11":
List<string> lst11 = new List<string>() { "1101", "1102", "1103", "1104", "1107", "1109", "1110" };
if (lst11.Contains(kvp.Key.BGQDLBM))
continue;
count = 7; break;
case "12":
List<string> lst12 = new List<string>() { "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<ExcelCell, double> 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<ExcelCell, double> 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<ExcelCell, double> 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<int> lst = new List<int>() { 11, 20, 24, 29, 34, 38, 41, 44, 47, 52, 53, 63, 71 };
List<int> lst1 = new List<int>() { 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<ExcelCell, double> 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>();
}
PCColumnModel coluModel = new PCColumnModel();
coluModel.Ids = new List<int>();
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>();
}
PCColumnModel coluModel = new PCColumnModel();
coluModel.Ids = new List<int>();
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>();
// }
// PCColumnModel coluModel = new PCColumnModel();
// coluModel.Ids = new List<int>();
// 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<ExcelCell, double> dic = GetDicTDLYXZBHPHTJB();
Dictionary<ExcelCell, double> dicValue = GetDicTDLYXZBHPHTJB();
foreach (KeyValuePair<ExcelCell, double> 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<string> lstDLBM = new List<string>() { "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<ExcelCell, double> 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<string> lst01 = new List<string>() { "0101", "0102", "0103" };
if (lst01.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "02":
List<string> lst02 = new List<string>() { "0201", "0202", "0203", "0204" };
if (lst02.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "03":
List<string> lst03 = new List<string>() { "0301", "0302", "0305", "0307" };
if (lst03.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "04":
List<string> lst04 = new List<string>() { "0401", "0403", "0404" };
if (lst04.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "00":
List<string> lst00 = new List<string>() { "0303", "0304", "0306", "0402", "1105", "1106", "1108" };
if (lst00.Contains(kvp.Key.BGHDLBM))
continue;
count = 7; break;
case "11":
List<string> lst11 = new List<string>() { "1101", "1102", "1103", "1104", "1107", "1110" };
if (lst11.Contains(kvp.Key.BGHDLBM))
continue;
count = 6; break;
case "JSYD":
List<string> JSYD = new List<string>() { "JSYD" };
if (JSYD.Contains(kvp.Key.BGHDLBM))
continue;
count = 1; break;
case "20":
List<string> lst20 = new List<string>() { "201", "202", "203", "204", "205" };
if (lst20.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "10":
List<string> lst10 = new List<string>() { "1001", "1002", "1003", "1007", "1008", "1009" };
if (lst10.Contains(kvp.Key.BGHDLBM))
continue;
count = 6; break;
case "1109":
List<string> lst1109 = new List<string>() { "1109" };
if (lst1109.Contains(kvp.Key.BGHDLBM))
continue;
count = 1; break;
case "12":
List<string> lst12 = new List<string>() { "1006", "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 "01":
List<string> lst01 = new List<string>() { "0101", "0102", "0103" };
if (lst01.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "02":
List<string> lst02 = new List<string>() { "0201", "0202", "0203", "0204" };
if (lst02.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "03":
List<string> lst03 = new List<string>() { "0301", "0302", "0305", "0307" };
if (lst03.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "04":
List<string> lst04 = new List<string>() { "0401", "0403", "0404" };
if (lst04.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "00":
List<string> lst00 = new List<string>() { "0303", "0304", "0306", "0402", "1105", "1106", "1108" };
if (lst00.Contains(kvp.Key.BGHDLBM))
continue;
count = 7; break;
case "11":
List<string> lst11 = new List<string>() { "1101", "1102", "1103", "1104", "1107", "1110" };
if (lst11.Contains(kvp.Key.BGHDLBM))
continue;
count = 6; break;
case "JSYD":
List<string> JSYD = new List<string>() { "JSYD" };
if (JSYD.Contains(kvp.Key.BGHDLBM))
continue;
count = 1; break;
case "20":
List<string> lst20 = new List<string>() { "201", "202", "203", "204", "205" };
if (lst20.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "10":
List<string> lst10 = new List<string>() { "1001", "1002", "1003", "1007", "1008", "1009" };
if (lst10.Contains(kvp.Key.BGHDLBM))
continue;
count = 6; break;
case "1109":
List<string> lst1109 = new List<string>() { "1109" };
if (lst1109.Contains(kvp.Key.BGHDLBM))
continue;
count = 1; break;
case "12":
List<string> lst12 = new List<string>() { "1006", "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, 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 = 59;//总列数
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<ExcelCell, double> 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<ExcelCell, double> 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<ExcelCell, double> 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<int> lst = new List<int>() { 11, 20, 24, 29, 34, 38, 41, 44, 47, 52, 53, 63, 71 };
//List<int> lst1 = new List<int>() { 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<ExcelCell, double> 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);
cells[10, 2 + i - startRol].PutValue(tzmj + zjMJ - jsMJ);
cells[10, 2 + i - startRol].SetStyle(style3);
}
}
workbook.Save(saveCurrentPath);
return true;
}
private bool ExportTDLYXZBGB(string saveCurrentPath, IRDBHelper dbHelper, string ncsjPath, bool isHaiDao = false)
{
string ncsjExcelPath = string.Empty;
DirectoryInfo dir = new DirectoryInfo(ncsjPath);
string fileName = string.Empty;
#region 数据赋值
FileInfo[] fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")土地利用现状分类面积汇总表.xlsx", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
fileName = fileSet[0].Name.Replace("(", "").Replace(")", "").Replace((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, "").Replace(fileSet[0].Extension, "");
}
//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);
DataTable resultdataTable = new DataTable();
// where XZQTZLX not in ('1','2','3','4')
DataTable dt = dbHelper.ExecuteDatatable("TDLYXZBGB", @" select Cells_X,Cells_Y,BGMJ from
(
select bgq,bgh,SUM(BGMJ)BGMJ from (
select bgq,bgh,SUM(BGMJ)BGMJ from
(
select
case when bgq in('1001', '1002', '1003', '1007', '1008', '1009', '1109' )or substr(bgq, 1, 2)='20' THEN 'JSYD' ELSE bgq END bgq,
case when bgh in('1001', '1002', '1003', '1007', '1008', '1009', '1109')or substr(bgh, 1, 2)='20' THEN 'JSYD' ELSE bgh END bgh , BGMJ from (select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from (select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A )A
)A WHERE bgq<>bgh and (bgq='JSYD' OR bgh='JSYD' ) GROUP BY bgq,bgh
union ALL
select bgq,bgh,SUM(BGMJ)BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from (select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A
)A WHERE bgq<>bgh GROUP BY bgq,bgh
)A GROUP BY bgq,bgh
)A left JOIN TDLYXZBGB B ON a.bgh = B.bgh and a.bgq = B.bgq where Cells_X NOTNULL and Cells_Y NOTNULL ", true);
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
#endregion
#region 上年末面积
DataTable table = dbHelper.ExecuteDatatable("tab", string.Format(@"select case WHEN column1='{0}' THEN'column1' ELSE 'column2' END ColumnName from {1} WHERE column1='{0}' or column2='{0}' ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, fileName), true);
if (table == null || table.Rows.Count == 0)
{
return false;
}
string ColumnName = table.Rows[0][0].ToTrim();
if (ColumnName == "column1")
{
dt = dbHelper.ExecuteDatatable("SNMMJ", string.Format(@"
select '4' Cells_X, '2' Cells_Y, round(column11,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '3' Cells_Y, round(column12,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '4' Cells_Y, round(column13,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '5' Cells_Y, round(column14,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '6' Cells_Y, round(column15,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '7' Cells_Y, round(column16,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '8' Cells_Y, round(column17,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '9' Cells_Y, round(column18,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '10' Cells_Y, round(column19,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '11' Cells_Y, round(column20,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '12' Cells_Y, round(column21,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '13' Cells_Y, round(column22,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '14' Cells_Y, round(column23,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '15' Cells_Y, round(column24,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '16' Cells_Y, round(column25,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '17' Cells_Y, round(column26,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '18' Cells_Y, round(column27,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '19' Cells_Y, round(column28,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '20' Cells_Y, round(column3,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '21' Cells_Y, round(column4,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '22' Cells_Y, round(column5,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '23' Cells_Y, round(column6,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '24' Cells_Y, round(column7,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '25' Cells_Y, round(column8,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '26' Cells_Y, round(column9,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '27' Cells_Y, round(column10,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '28' Cells_Y, round(column43,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '29' Cells_Y, round(column44,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '30' Cells_Y, round(column45,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '31' Cells_Y, round(column46,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '32' Cells_Y, round(column47,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '33' Cells_Y, round(column48,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '34' Cells_Y, round(column49,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '36' Cells_Y, round(column29,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '37' Cells_Y, round(column30,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '38' Cells_Y, round(column31,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '39' Cells_Y, round(column32,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '40' Cells_Y, round(column33,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '41' Cells_Y, round(column34,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '42' Cells_Y, round(column35,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '43' Cells_Y, round(column36,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '44' Cells_Y, round(column37,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '45' Cells_Y, round(column38,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '46' Cells_Y, round(column39,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '47' Cells_Y, round(column40,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '48' Cells_Y, round(column41,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '49' Cells_Y, round(column42,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '50' Cells_Y, round(column50,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '51' Cells_Y, round(column51,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '52' Cells_Y, round(column52,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '53' Cells_Y, round(column53,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '54' Cells_Y, round(column54,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '55' Cells_Y, round(column55,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '56' Cells_Y, round(column56,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '57' Cells_Y, round(column57,4) BGMJ FROM {2} WHERE {1}='{0}' ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, ColumnName, fileName), true);
}
else if (ColumnName == "column2")
{
dt = dbHelper.ExecuteDatatable("SNMMJ", string.Format(@"
select '4' Cells_X, '2' Cells_Y, round(column12,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '3' Cells_Y, round(column13,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '4' Cells_Y, round(column14,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '5' Cells_Y, round(column15,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '6' Cells_Y, round(column16,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '7' Cells_Y, round(column17,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '8' Cells_Y, round(column18,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '9' Cells_Y, round(column19,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '10' Cells_Y, round(column20,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '11' Cells_Y, round(column21,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '12' Cells_Y, round(column22,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '13' Cells_Y, round(column23,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '14' Cells_Y, round(column24,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '15' Cells_Y, round(column25,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '16' Cells_Y, round(column26,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '17' Cells_Y, round(column27,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '18' Cells_Y, round(column28,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '19' Cells_Y, round(column29,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '20' Cells_Y, round(column4,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '21' Cells_Y, round(column5,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '22' Cells_Y, round(column6,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '23' Cells_Y, round(column7,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '24' Cells_Y, round(column8,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '25' Cells_Y, round(column9,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '26' Cells_Y, round(column10,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '27' Cells_Y, round(column11,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '28' Cells_Y, round(column44,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '29' Cells_Y, round(column45,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '30' Cells_Y, round(column46,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '31' Cells_Y, round(column47,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '32' Cells_Y, round(column48,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '33' Cells_Y, round(column49,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '34' Cells_Y, round(column50,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '36' Cells_Y, round(column30,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '37' Cells_Y, round(column31,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '38' Cells_Y, round(column32,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '39' Cells_Y, round(column33,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '40' Cells_Y, round(column34,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '41' Cells_Y, round(column35,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '42' Cells_Y, round(column36,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '43' Cells_Y, round(column37,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '44' Cells_Y, round(column38,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '45' Cells_Y, round(column39,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '46' Cells_Y, round(column40,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '47' Cells_Y, round(column41,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '48' Cells_Y, round(column42,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '49' Cells_Y, round(column43,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '50' Cells_Y, round(column51,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '51' Cells_Y, round(column52,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '52' Cells_Y, round(column53,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '53' Cells_Y, round(column54,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '54' Cells_Y, round(column55,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '55' Cells_Y, round(column56,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '56' Cells_Y, round(column57,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '57' Cells_Y, round(column58,4) BGMJ FROM {2} WHERE {1}='{0}' ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, ColumnName, fileName), true);
}
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
#endregion
#region 行政区调入
dt = dbHelper.ExecuteDatatable("XZQDR", string.Format(@" select '5' Cells_X,Cells_Y,BGMJ from
(
select case when XZQTZLX='1' then bgq ELSE bgh end dlbm, SUM(BGMJ) BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ,XZQTZLX
from
(
select substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ
)A WHERE XZQTZLX in ('1','3')
)A GROUP BY dlbm
)a left join TDLYXZBGB B on a.DLBM= B.bgh where b.Cells_X='12' "), true);
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
#endregion
#region 行政区调出
dt = dbHelper.ExecuteDatatable("XZQDC", string.Format(@" select '6' Cells_X,Cells_Y,BGMJ from
(
select bgq dlbm, SUM(BGMJ) BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ,XZQTZLX
from
(
select substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ
)A WHERE XZQTZLX in ('2','4')
)A GROUP BY dlbm
)a left join TDLYXZBGB B on a.DLBM= B.bgh where b.Cells_X='12' "), true);
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
CellHelper.SetFileToDisk(resultdataTable, saveCurrentPath, 0);
#endregion
CellHelper.Import(saveCurrentPath);
return true;
}
private BBPCModel ExportTDLYXZBGB_JC(string saveCurrentPath, IRDBHelper dbHelper, string ncsjPath, ref List<BBPCModel> pcModelList)
{
string ncsjExcelPath = string.Empty;
DirectoryInfo dir = new DirectoryInfo(ncsjPath);
BBPCModel result = null;
string fileName = string.Empty;
#region 数据赋值
FileInfo[] fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")土地利用现状分类面积汇总表.xlsx", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
fileName = fileSet[0].Name.Replace("(", "").Replace(")", "").Replace((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, "").Replace(fileSet[0].Extension, "");
}
//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 result;
}
string tempPath = AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\BGTJ\\土地利用现状变更表.xlsx";
saveCurrentPath = saveCurrentPath + "\\土地利用现状变更表.xlsx";
File.Copy(tempPath, saveCurrentPath, true);
DataTable resultdataTable = new DataTable();
DataTable dt = dbHelper.ExecuteDatatable("TDLYXZBGB", @"
select Cells_X,Cells_Y,BGMJ from
(
select bgq,bgh,SUM(BGMJ)BGMJ from (
select bgq,bgh,SUM(BGMJ)BGMJ from
(
select
case when bgq in('05H1', '0508', '0601', '0602', '0603', '0701', '0702', '08H1', '08H2', '0809', '0810', '09', '1001', '1002', '1003', '1004', '1005', '1007', '1008', '1009', '1109', '1201' )or substr(bgq, 1, 2)='20' THEN 'JSYD' ELSE bgq END bgq,
case when bgh in('05H1', '0508', '0601', '0602', '0603', '0701', '0702', '08H1', '08H2', '0809', '0810', '09', '1001', '1002', '1003', '1004', '1005', '1007', '1008', '1009', '1109', '1201')or substr(bgh, 1, 2)='20' THEN 'JSYD' ELSE bgh END bgh , BGMJ from (select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from (select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ where XZQTZLX not in ('1','2','3','4')
)A )A
)A WHERE bgq<>bgh and (bgq='JSYD' OR bgh='JSYD' ) GROUP BY bgq,bgh
union ALL
select bgq,bgh,SUM(BGMJ)BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from (select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ where XZQTZLX not in ('1','2','3','4')
)A
)A WHERE bgq<>bgh GROUP BY bgq,bgh
)A GROUP BY bgq,bgh
)A left JOIN TDLYXZBGB B ON a.bgh = B.bgh and a.bgq = B.bgq where Cells_X NOTNULL and Cells_Y NOTNULL ", true);
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
#endregion
#region 上年末面积
DataTable table = dbHelper.ExecuteDatatable("tab", string.Format(@"select case WHEN column1='{0}' THEN'column1' ELSE 'column2' END ColumnName from {1} WHERE column1='{0}' or column2='{0}' ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, fileName), true);
if (table == null || table.Rows.Count == 0)
{
return result;
}
string ColumnName = table.Rows[0][0].ToTrim();
if (ColumnName == "column1")
{
dt = dbHelper.ExecuteDatatable("SNMMJ", string.Format(@"
select '4' Cells_X, '2' Cells_Y, round(column11,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '3' Cells_Y, round(column12,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '4' Cells_Y, round(column13,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '5' Cells_Y, round(column14,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '6' Cells_Y, round(column15,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '7' Cells_Y, round(column16,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '8' Cells_Y, round(column17,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '9' Cells_Y, round(column18,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '10' Cells_Y, round(column19,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '11' Cells_Y, round(column20,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '12' Cells_Y, round(column21,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '13' Cells_Y, round(column22,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '14' Cells_Y, round(column23,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '15' Cells_Y, round(column24,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '16' Cells_Y, round(column25,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '17' Cells_Y, round(column26,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '18' Cells_Y, round(column27,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '19' Cells_Y, round(column28,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '20' Cells_Y, round(column3,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '21' Cells_Y, round(column4,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '22' Cells_Y, round(column5,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '23' Cells_Y, round(column6,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '24' Cells_Y, round(column7,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '25' Cells_Y, round(column8,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '26' Cells_Y, round(column9,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '27' Cells_Y, round(column10,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '28' Cells_Y, round(column43,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '29' Cells_Y, round(column44,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '30' Cells_Y, round(column45,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '31' Cells_Y, round(column46,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '32' Cells_Y, round(column47,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '33' Cells_Y, round(column48,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '34' Cells_Y, round(column49,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '36' Cells_Y, round(column29,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '37' Cells_Y, round(column30,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '38' Cells_Y, round(column31,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '39' Cells_Y, round(column32,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '40' Cells_Y, round(column33,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '41' Cells_Y, round(column34,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '42' Cells_Y, round(column35,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '43' Cells_Y, round(column36,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '44' Cells_Y, round(column37,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '45' Cells_Y, round(column38,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '46' Cells_Y, round(column39,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '47' Cells_Y, round(column40,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '48' Cells_Y, round(column41,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '49' Cells_Y, round(column42,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '50' Cells_Y, round(column50,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '51' Cells_Y, round(column51,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '52' Cells_Y, round(column52,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '53' Cells_Y, round(column53,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '54' Cells_Y, round(column54,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '55' Cells_Y, round(column55,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '56' Cells_Y, round(column56,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '57' Cells_Y, round(column57,4) BGMJ FROM {2} WHERE {1}='{0}' ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, ColumnName, fileName), true);
}
else if (ColumnName == "column2")
{
dt = dbHelper.ExecuteDatatable("SNMMJ", string.Format(@"
select '4' Cells_X, '2' Cells_Y, round(column12,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '3' Cells_Y, round(column13,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '4' Cells_Y, round(column14,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '5' Cells_Y, round(column15,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '6' Cells_Y, round(column16,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '7' Cells_Y, round(column17,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '8' Cells_Y, round(column18,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '9' Cells_Y, round(column19,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '10' Cells_Y, round(column20,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '11' Cells_Y, round(column21,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '12' Cells_Y, round(column22,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '13' Cells_Y, round(column23,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '14' Cells_Y, round(column24,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '15' Cells_Y, round(column25,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '16' Cells_Y, round(column26,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '17' Cells_Y, round(column27,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '18' Cells_Y, round(column28,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '19' Cells_Y, round(column29,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '20' Cells_Y, round(column4,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '21' Cells_Y, round(column5,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '22' Cells_Y, round(column6,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '23' Cells_Y, round(column7,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
SELECT '4' Cells_X, '24' Cells_Y, round(column8,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '25' Cells_Y, round(column9,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '26' Cells_Y, round(column10,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '27' Cells_Y, round(column11,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '28' Cells_Y, round(column44,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '29' Cells_Y, round(column45,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '30' Cells_Y, round(column46,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '31' Cells_Y, round(column47,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '32' Cells_Y, round(column48,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '33' Cells_Y, round(column49,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '34' Cells_Y, round(column50,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '36' Cells_Y, round(column30,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '37' Cells_Y, round(column31,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '38' Cells_Y, round(column32,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '39' Cells_Y, round(column33,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '40' Cells_Y, round(column34,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '41' Cells_Y, round(column35,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '42' Cells_Y, round(column36,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '43' Cells_Y, round(column37,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '44' Cells_Y, round(column38,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '45' Cells_Y, round(column39,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '46' Cells_Y, round(column40,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '47' Cells_Y, round(column41,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '48' Cells_Y, round(column42,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '49' Cells_Y, round(column43,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '50' Cells_Y, round(column51,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '51' Cells_Y, round(column52,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '52' Cells_Y, round(column53,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '53' Cells_Y, round(column54,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '54' Cells_Y, round(column55,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '55' Cells_Y, round(column56,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '56' Cells_Y, round(column57,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '4' Cells_X, '57' Cells_Y, round(column58,4) BGMJ FROM {2} WHERE {1}='{0}' ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, ColumnName, fileName), true);
}
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
#endregion
#region 行政区调入
dt = dbHelper.ExecuteDatatable("XZQDR", string.Format(@" select '5' Cells_X,Cells_Y,BGMJ from
(
select case when XZQTZLX='1' then bgq ELSE bgh end dlbm, SUM(BGMJ) BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ,XZQTZLX
from
(
select substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ
)A WHERE XZQTZLX in ('1','3')
)A GROUP BY dlbm
)a left join TDLYXZBGB B on a.DLBM= B.bgh where b.Cells_X='12' "), true);
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
#endregion
#region 行政区调出
dt = dbHelper.ExecuteDatatable("XZQDC", string.Format(@" select '6' Cells_X,Cells_Y,BGMJ from
(
select bgq dlbm, SUM(BGMJ) BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ,XZQTZLX
from
(
select substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ
)A WHERE XZQTZLX in ('2','4')
)A GROUP BY dlbm
)a left join TDLYXZBGB B on a.DLBM= B.bgh where b.Cells_X='12' "), true);
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
CellHelper.SetFileToDisk(resultdataTable, saveCurrentPath, 0);
#endregion
CellHelper.Import(saveCurrentPath);
#region 年末面积平差
Workbook workbook = new Workbook(saveCurrentPath);
Worksheet sheet = workbook.Worksheets[0];
Range dataRange = null;
dataRange = sheet.Cells.CreateRange("C11:BG11");
var XJ = new List<int>() { 0, 4, 9, 14, 18, 26, 34, 40, 48 };
for (int i = 0; i < dataRange.ColumnCount; i++)
{
if (XJ.Contains(i)) continue;
var negative = dataRange[0, i].Value.ToDouble();
if (negative < 0)//负值
{
if (result == null)
{
result = new BBPCModel();
result.ReportName = 2;
result.Columns = new List<PCColumnModel>();
}
PCColumnModel coluModel = new PCColumnModel();
coluModel.Ids = new List<int>();
coluModel.IsActive = true;
coluModel.ColumnIndex = i;
coluModel.DiffValue = Math.Abs(negative);
string sql = string.Empty;
if (i == 33)
{
sql = $@"select ID from (select bgq,SUM(BGMJ)BGMJ,group_concat(ID) ID from( select ID,case when bgq in('05H1', '0508', '0601', '0602', '0603', '0701', '0702', '08H1', '08H2', '0809', '0810', '09', '1001', '1002', '1003', '1004', '1005', '1007', '1008', '1009', '1109', '1201' )or substr(bgq, 1, 2)='20' THEN 'JSYD' ELSE bgq END bgq,case when bgh in('05H1', '0508', '0601', '0602', '0603', '0701', '0702', '08H1', '08H2', '0809', '0810', '09', '1001', '1002', '1003', '1004', '1005', '1007', '1008', '1009', '1109', '1201')or substr(bgh, 1, 2)='20' THEN 'JSYD' ELSE bgh END bgh , BGMJ from (select ID,case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from (select ID,substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A )A )A WHERE bgq<>bgh and (bgq='JSYD' OR bgh='JSYD' ) GROUP BY bgq )A WHERE bgq = (select bgh from TDLYXZBGB WHERE Cells_X = '12' AND Cells_Y = '{i + 2}')";
}
else
{
sql = $@" select ID from ( select bgq,SUM(BGMJ)BGMJ,group_concat(ID) ID from ( select ID,case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from (select ID,substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A )A WHERE bgq<>bgh GROUP BY bgq )A WHERE bgq = (select bgh from TDLYXZBGB WHERE Cells_X = '12' AND Cells_Y = '{i + 2}')";
}
DataTable IDsTable = dbHelper.ExecuteDatatable("ids", sql, true);
string ids = string.Empty;
foreach (DataRow row in IDsTable.Rows)
{
string strID = row["ID"].ToString();
if (string.IsNullOrEmpty(strID))
{
for (int j = 0; j < strID.Split(',').Length; j++)
{
coluModel.Ids.Add(Convert.ToInt32(strID.Split(',')[j]));
}
}
}
result.Columns.Add(coluModel);
}
}
#endregion
return result;
}
private BBPCModel ExportTDLYXZBGB(string saveCurrentPath, IRDBHelper dbHelper, string ncsjPath, ref List<BBPCModel> pcModelList)
{
string ncsjExcelPath = string.Empty;
DirectoryInfo dir = new DirectoryInfo(ncsjPath);
BBPCModel result = null;
#region 数据赋值
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 result;
}
string tempPath = AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\BGTJ\\土地利用现状变更表.xlsx";
File.Copy(tempPath, saveCurrentPath, true);
DataTable dt = dbHelper.ExecuteDatatable("TDLYXZBGB", @" select Cells_X,Cells_Y,BGMJ from
(
select bgq,bgh,SUM(BGMJ)BGMJ from (
select bgq,bgh,SUM(BGMJ)BGMJ from
(
select
case when bgq in('05H1', '0508', '0601', '0602', '0603', '0701', '0702', '08H1', '08H2', '0809', '0810', '09', '1001', '1002', '1003', '1004', '1005', '1007', '1008', '1009', '1109', '1201' )or substr(bgq, 1, 2)='20' THEN 'JSYD' ELSE bgq END bgq,
case when bgh in('05H1', '0508', '0601', '0602', '0603', '0701', '0702', '08H1', '08H2', '0809', '0810', '09', '1001', '1002', '1003', '1004', '1005', '1007', '1008', '1009', '1109', '1201')or substr(bgh, 1, 2)='20' THEN 'JSYD' ELSE bgh END bgh , BGMJ from (select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from (select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A )A
)A WHERE bgq<>bgh and (bgq='JSYD' OR bgh='JSYD' ) GROUP BY bgq,bgh
union ALL
select bgq,bgh,SUM(BGMJ)BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from (select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A
)A WHERE bgq<>bgh GROUP BY bgq,bgh
)A GROUP BY bgq,bgh
)A left JOIN TDLYXZBGB B ON a.bgh = B.bgh and a.bgq = B.bgq where Cells_X NOTNULL and Cells_Y NOTNULL ", true);
CellHelper.SetFileToDisk(dt, saveCurrentPath, 0);
#endregion
#region 上年末面积
dt = dbHelper.ExecuteDatatable("SNMMJ", string.Format(@" select '4' Cells_X, '2' Cells_Y, '01' DLBM, column12 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '3' Cells_Y, '0101' DLBM, column13 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '4' Cells_Y, '0102' DLBM, column14 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '5' Cells_Y, '0103' DLBM, column15 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '6' Cells_Y, '02' DLBM, column16 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '7' Cells_Y, '0201' DLBM, column17 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '8' Cells_Y, '0202' DLBM, column18 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '9' Cells_Y, '0203' DLBM, column19 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '10' Cells_Y, '0204' DLBM, column20 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '11' Cells_Y, '03' DLBM, column21 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '12' Cells_Y, '0301' DLBM, column22 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '13' Cells_Y, '0302' DLBM, column23 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '14' Cells_Y, '0305' DLBM, column24 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '15' Cells_Y, '0307' DLBM, column25 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '16' Cells_Y, '04' DLBM, column26 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '17' Cells_Y, '0401' DLBM, column27 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '18' Cells_Y, '0403' DLBM, column28 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '19' Cells_Y, '0404' DLBM, column29 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
SELECT '4' Cells_X, '20' Cells_Y, '00' DLBM,column4 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
SELECT '4' Cells_X, '21' Cells_Y, '0303' DLBM,column5 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
SELECT '4' Cells_X, '22' Cells_Y, '0304' DLBM,column6 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
SELECT '4' Cells_X, '23' Cells_Y, '0306' DLBM,column7 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
SELECT '4' Cells_X, '24' Cells_Y, '0402' DLBM,column8 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '25' Cells_Y, '1105' DLBM, column9 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '26' Cells_Y, '1106' DLBM, column10 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '27' Cells_Y, '1108' DLBM, column11 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '28' Cells_Y, '11' DLBM, column44 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '29' Cells_Y, '1101' DLBM, column45 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '30' Cells_Y, '1102' DLBM, column46 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '31' Cells_Y, '1103' DLBM, column47 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '32' Cells_Y, '1104' DLBM, column48 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '33' Cells_Y, '1107' DLBM, column49 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '34' Cells_Y, '1110' DLBM, column50 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '36' Cells_Y, '20' DLBM, column30 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '37' Cells_Y, '201' DLBM, column31 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '38' Cells_Y, '202' DLBM, column32 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '39' Cells_Y, '203' DLBM, column33 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '40' Cells_Y, '204' DLBM, column34 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '41' Cells_Y, '205' DLBM, column35 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '42' Cells_Y, '10' DLBM, column36 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '43' Cells_Y, '1001' DLBM, column37 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '44' Cells_Y, '1002' DLBM, column38 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '45' Cells_Y, '1003' DLBM, column39 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '46' Cells_Y, '1007' DLBM, column40 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '47' Cells_Y, '1008' DLBM, column41 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '48' Cells_Y, '1009' DLBM, column42 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '49' Cells_Y, '1109' DLBM, column43 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '50' Cells_Y, '12' DLBM, column51 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '51' Cells_Y, '1006' DLBM, column52 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '52' Cells_Y, '1202' DLBM, column53 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '53' Cells_Y, '1203' DLBM, column54 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '54' Cells_Y, '1204' DLBM, column55 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '55' Cells_Y, '1205' DLBM, column56 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '56' Cells_Y, '1206' DLBM, column57 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' UNION ALL
select '4' Cells_X, '57' Cells_Y, '1207' DLBM, column58 BGMJ FROM 土地利用现状分类面积汇总表 WHERE column1='{0}' ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE), true);
CellHelper.SetFileToDisk(dt, saveCurrentPath, 0);
#endregion
#region 行政区调入
dt = dbHelper.ExecuteDatatable("XZQDR", string.Format(@" select '5' Cells_X,Cells_Y,BGMJ from
(
select case WHEN XZQTZLX='1' then bgq ELSE bgh end dlbm, SUM(BGMJ) BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ,XZQTZLX
from
(
select substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ
)A WHERE XZQTZLX in ('1','3')
)A GROUP BY dlbm
)a left join TDLYXZBGB B on a.DLBM= B.bgh where b.Cells_X='12' "), true);
CellHelper.SetFileToDisk(dt, saveCurrentPath, 0);
#endregion
#region 行政区调出
dt = dbHelper.ExecuteDatatable("XZQDC", string.Format(@" select '6' Cells_X,Cells_Y,BGMJ from
(
select bgq dlbm, SUM(BGMJ) BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ,XZQTZLX
from
(
select substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ
)A WHERE XZQTZLX in ('2','4')
)A GROUP BY dlbm
)a left join TDLYXZBGB B on a.DLBM= B.bgh where b.Cells_X='12' "), true);
CellHelper.SetFileToDisk(dt, saveCurrentPath, 0);
#endregion
CellHelper.Import(saveCurrentPath);
#region 年末面积平差
Workbook workbook = new Workbook(saveCurrentPath);
Worksheet sheet = workbook.Worksheets[0];
Range dataRange = null;
dataRange = sheet.Cells.CreateRange("C11:BG11");
var XJ = new List<int>() { 0, 4, 9, 14, 18, 26, 34, 40, 48, 56 };
for (int i = 0; i < dataRange.ColumnCount; i++)
{
if (XJ.Contains(i)) continue;
var xx = dataRange[0, i].Value.ToDouble();
if (xx < 0)
{
if (result == null)
{
result = new BBPCModel();
result.ReportName = 1;
result.Columns = new List<PCColumnModel>();
}
PCColumnModel coluModel = new PCColumnModel();
coluModel.Ids = new List<int>();
coluModel.IsActive = true;
coluModel.ColumnIndex = i;
coluModel.DiffValue = Math.Abs(xx);
string sql = string.Empty;
if (i == 35)
{
sql = $@"select * from (select ID, substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM, substr(BGHCZCSXM, 1, 3) BGHCZCSXM, BGMJ from JCTJB_GQ)A WHERE BGQCZCSXM = '201' and(BGQDLBM <> BGHDLBM or BGQCZCSXM <> BGHCZCSXM) AND BGQDLBM = (select bgh from CSNBTDLYBHTJB WHERE Cells_X = '9' AND Cells_Y = '{i + 2}')";
}
else
{
sql = $@"select * from (select ID, substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM, substr(BGHCZCSXM, 1, 3) BGHCZCSXM, BGMJ from JCTJB_GQ)A WHERE BGQCZCSXM = '201' and(BGQDLBM <> BGHDLBM or BGQCZCSXM <> BGHCZCSXM) AND BGQDLBM = (select bgh from CSNBTDLYBHTJB WHERE Cells_X = '9' AND Cells_Y = '{i + 2}')";
}
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);
}
}
#endregion
return result;
}
public List<Dictionary<string, string>> GetResults_Excel(string sTableName)
{
List<Dictionary<string, string>> result = new List<Dictionary<string, string>>();
try
{
XmlDocument doc = new XmlDocument();
string strPath = SysAppPath.GetCurrentAppPath();
strPath += @"Configs\Results_Excel.xml";
doc.Load(strPath);
XmlNode nodeDataCatalog = doc.SelectSingleNode("TableName");
if (nodeDataCatalog == null)
return result;
XmlNode cnodeDataCatalog = nodeDataCatalog.SelectSingleNode(sTableName);
foreach (XmlNode item in cnodeDataCatalog.ChildNodes)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
foreach (XmlNode citem in item.ChildNodes)
{
dic.Add(citem.Attributes["DLBM"].Value, citem.Attributes["Cells"].Value);
}
result.Add(dic);
}
return result;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw;
}
}
private void GetTDLYXZBHPHTJBXJ(Cells cells, int rol, bool isXJ = true)
{
List<int> lst = new List<int>() { 8, 3, 4, 4, 3, 2, 2, 2, 4, 0, 9, 7, 7 };
int isJump = 0;
if (rol >= 11 & rol <= 19) isJump = 0;
else if (rol >= 20 & rol <= 23) isJump = 1;
else if (rol >= 24 & rol <= 28) isJump = 2;
else if (rol >= 29 & rol <= 33) isJump = 3;
else if (rol >= 34 & rol <= 37) isJump = 4;
else if (rol >= 38 & rol <= 40) isJump = 5;
else if (rol >= 41 & rol <= 43) isJump = 6;
else if (rol >= 43 & rol <= 46) isJump = 7;
else if (rol >= 47 & rol <= 51) isJump = 8;
else if (rol >= 53 & rol <= 62) isJump = 10;
else if (rol >= 63 & rol <= 70) isJump = 11;
else if (rol >= 71 & rol <= 78) isJump = 12;
else isJump = 999;
int num = 0;
int fromCol = 3;
double sumMJ = 0;
foreach (int count in lst)
{
double mj = 0;
if (count != 0)
{
for (int col = fromCol; col < fromCol + count; col++)
{
if (cells[rol, col].Value != null)
{
var value = cells[rol, col].Value;
mj += double.Parse(value == null || value == "" ? 0.ToString() : value.ToString());
}
}
if (isJump != num)
{
if (isXJ)
cells[rol, fromCol - 1].PutValue(mj);
}
}
else
{
if (cells[rol, fromCol - 1].Value != null)
{
var value = cells[rol, fromCol - 1].Value;
if (!"".Equals(value))
{
mj += double.Parse(value.ToString());
}
}
}
sumMJ += mj;
fromCol += count + 1;
num++;
}
cells[rol, 70].PutValue(sumMJ);
}
private Dictionary<ExcelCell, double> GetDicTDLYXZBHPHTJB()
{
Dictionary<ExcelCell, double> dic = new Dictionary<ExcelCell, double>();
//湿地
List<string> lst = new List<string>() { "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 i = 0;
int j = 0;
foreach (string bgqdlbm in lst)
{
j = 0;
foreach (string bghdlbm in lst)
{
dic.Add(new ExcelCell() { BGQDLBM = bgqdlbm, BGHDLBM = bghdlbm, ColIndex = 2 + j, RowIndex = 11 + i }, 0);
j++;
}
i++;
}
return dic;
}
public class ExcelCell
{
public int ColIndex { get; set; }
public int RowIndex { get; set; }
public string BGQDLBM { get; set; }
public string BGHDLBM { get; set; }
}
/// <summary>
/// 三大类土地利用现状变化平衡统计表
/// </summary>
private bool ExportSDLTDLYXZBHPHTJB(string saveCurrentPath, IRDBHelper dbHelper, string ncsjPath)
{
string tempPath = AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\BGTJ\\三大类土地利用现状变更表.xlsx";
File.Copy(tempPath, saveCurrentPath, true);
Workbook workbook = new Workbook(saveCurrentPath);
Cells cells = workbook.Worksheets[0].Cells;
DataTable dtExport = dbHelper.ExecuteDatatable("TDLYXZBHPHTJB_TEMP", " select * from TDLYXZBHPHTJB_TEMP ", true);
DataTable dt = dbHelper.ExecuteDatatable("BGYLB", " select BGQDLBM,BGHDLBM,XZQTZLX,BGMJ from BGYLB ", true);
if (dtExport == null)
return false;
string ncsjExcelPath = string.Empty;
DirectoryInfo dir = new DirectoryInfo(ncsjPath);
//FileInfo[] fileSet = dir.GetFiles("*土地利用现状分类面积汇总表.xlsx", SearchOption.AllDirectories);
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 (!System.IO.File.Exists(ncsjExcelPath))
{
//Common.Utility.LogAPI.Debug("三大类土地利用现状变化平衡统计表 的 土地利用现状分类面积汇总表 不能被 成功 找到\r\n");
return false;
}
//Common.Utility.LogAPI.Debug("三大类土地利用现状变化平衡统计表 的 土地利用现状分类面积汇总表 能被 成功 找到\r\n");
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<ExcelCell, double> dic = GetDicSDLTDLYXZBHPHTJB();
Dictionary<ExcelCell, double> dicValue = GetDicSDLTDLYXZBHPHTJB();
foreach (KeyValuePair<ExcelCell, double> 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<string> lstDLBM = new List<string>() { "NYD_XJ", "NYD00", "0303", "0304", "0306", "0402", "NYD01", "0101", "0102", "0103", "NYD02", "0201", "0202", "0203", "0204", "NYD03", "0301", "0302", "0305", "0307", "NYD04", "0401", "0403", "1006", "NYD11", "1103", "1104", "1107", "NYD12", "1202", "1203", "JSYD_XJ", "0603", "JSYD05", "05H1", "0508", "JSYD06", "0601", "0602", "JSYD07", "0701", "0702", "JSYD08", "08H1", "08H2", "0809", "0810", "09", "JSYD10", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009", "1109", "1201", "WLYD_XJ", "WLYD00", "1105", "1106", "1108", "0404", "WLYD11", "1101", "1102", "1110", "WLYD12", "1204", "1205", "1206", "1207" };
int a = 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[6, 3 + a].PutValue(TRMJ);
cells[6, 3 + a].SetStyle(style3);
a++;
}
//调出面积
a = 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[7, 3 + a].PutValue(TRMJ);
cells[7, 3 + a].SetStyle(style3);
a++;
}
if (ncsjExcelPath != string.Empty)
{
Workbook workbookNC = new Workbook(ncsjExcelPath);
Cells cellsNC = workbookNC.Worksheets[0].Cells;
int valueRow = 0;
for (int i = 0; i < cellsNC.MaxRow; i++)
{
if (cellsNC[i, 0].IsMerged == false && cellsNC[i, 0].Value != null && cellsNC[i, 0].Value.ToString() == "名称")
{
valueRow = i + 2;
break;
}
if (cellsNC[i, 0].IsMerged == true && cellsNC[i, 0].Value != null && cellsNC[i, 0].Value.ToString() == "名称")
{
valueRow = i + cellsNC[i, 0].GetMergedRange().RowCount + 2;
break;
}
}
//年初面积
for (int i = 3; i < cellsNC.MaxColumn + 20; i++)
{
for (int j = 3; j < cellsNC.MaxColumn + 1; j++)
{
if (cellsNC[valueRow - 2, j].Value != null && cells[4, i].Value != null)
{
string[] dlbmNC = null;
dlbmNC = cellsNC[valueRow - 2, j].Value.ToString().Split('(');
if (dlbmNC.Length != 2)
dlbmNC = cellsNC[valueRow - 2, j].Value.ToString().Split('(');
string[] dlbm = cells[4, i].Value.ToString().Split('(');
if (dlbmNC.Length == 2 && dlbm.Length == 2 && dlbmNC[1].Trim().Substring(0, dlbmNC[1].Length - 1) == dlbm[1].Trim().Substring(0, dlbm[1].Length - 1))
{
cells[5, i].PutValue(cellsNC[valueRow - 1, j].Value);
cells[5, i].SetStyle(style3);
}
}
if (cellsNC[valueRow - 3, j].Value != null && cells[3, i].Value != null)
{
if (!cellsNC[valueRow - 3, j].Value.ToString().Contains("特殊用地"))
continue;
if (!cells[3, i].Value.ToString().Contains("特殊用地"))
continue;
string[] dlbmNC = null;
dlbmNC = cellsNC[valueRow - 3, j].Value.ToString().Split('(');
if (dlbmNC.Length != 2)
dlbmNC = cellsNC[valueRow - 3, j].Value.ToString().Split('(');
string[] dlbm = cells[3, i].Value.ToString().Split('(');
if (dlbmNC.Length == 2 && dlbm.Length == 2 && dlbmNC[1].Trim().Substring(0, dlbmNC[1].Length - 1) == dlbm[1].Trim().Substring(0, dlbm[1].Length - 1))
{
cells[5, i].PutValue(cellsNC[valueRow - 1, j].Value);
cells[5, i].SetStyle(style3);
}
}
}
}
//年内增加
for (int i = 9; i < 84; i++)
{
double total = 0;
foreach (KeyValuePair<ExcelCell, double> kvp in dicValue)
{
if (kvp.Key.ColIndex == 3 + i - 9)
{
//一级类相同地类不计算增加减少
bool isContinue = false;
if (i >= 9 && i <= 14 && kvp.Key.RowIndex >= 9 + 3 && kvp.Key.RowIndex <= 14 + 3) isContinue = true;
else if (i >= 15 && i <= 18 && kvp.Key.RowIndex >= 15 + 3 && kvp.Key.RowIndex <= 18 + 3) isContinue = true;
else if (i >= 19 && i <= 23 && kvp.Key.RowIndex >= 19 + 3 && kvp.Key.RowIndex <= 23 + 3) isContinue = true;
else if (i >= 24 && i <= 28 && kvp.Key.RowIndex >= 24 + 3 && kvp.Key.RowIndex <= 28 + 3) isContinue = true;
else if (i >= 29 && i <= 31 && kvp.Key.RowIndex >= 29 + 3 && kvp.Key.RowIndex <= 31 + 3) isContinue = true;
else if (i >= 32 && i <= 32 && kvp.Key.RowIndex >= 32 + 3 && kvp.Key.RowIndex <= 32 + 3) isContinue = true;
else if (i >= 33 && i <= 36 && kvp.Key.RowIndex >= 33 + 3 && kvp.Key.RowIndex <= 36 + 3) isContinue = true;
else if (i >= 37 && i <= 39 && kvp.Key.RowIndex >= 37 + 3 && kvp.Key.RowIndex <= 39 + 3) isContinue = true;
else if (i >= 41 && i <= 41 && kvp.Key.RowIndex >= 41 + 3 && kvp.Key.RowIndex <= 41 + 3) isContinue = true;
else if (i >= 42 && i <= 44 && kvp.Key.RowIndex >= 42 + 3 && kvp.Key.RowIndex <= 44 + 3) isContinue = true;
else if (i >= 45 && i <= 47 && kvp.Key.RowIndex >= 45 + 3 && kvp.Key.RowIndex <= 47 + 3) isContinue = true;
else if (i >= 48 && i <= 50 && kvp.Key.RowIndex >= 48 + 3 && kvp.Key.RowIndex <= 50 + 3) isContinue = true;
else if (i >= 51 && i <= 55 && kvp.Key.RowIndex >= 51 + 3 && kvp.Key.RowIndex <= 55 + 3) isContinue = true;
else if (i >= 56 && i <= 56 && kvp.Key.RowIndex >= 56 + 3 && kvp.Key.RowIndex <= 56 + 3) isContinue = true;
else if (i >= 57 && i <= 65 && kvp.Key.RowIndex >= 57 + 3 && kvp.Key.RowIndex <= 65 + 3) isContinue = true;
else if (i >= 66 && i <= 66 && kvp.Key.RowIndex >= 66 + 3 && kvp.Key.RowIndex <= 66 + 3) isContinue = true;
else if (i >= 67 && i <= 67 && kvp.Key.RowIndex >= 67 + 3 && kvp.Key.RowIndex <= 67 + 3) isContinue = true;
else if (i >= 69 && i <= 72 && kvp.Key.RowIndex >= 69 + 3 && kvp.Key.RowIndex <= 72 + 3) isContinue = true;
else if (i >= 73 && i <= 73 && kvp.Key.RowIndex >= 73 + 3 && kvp.Key.RowIndex <= 73 + 3) isContinue = true;
else if (i >= 74 && i <= 77 && kvp.Key.RowIndex >= 74 + 3 && kvp.Key.RowIndex <= 77 + 3) isContinue = true;
else if (i >= 78 && i <= 82 && kvp.Key.RowIndex >= 78 + 3 && kvp.Key.RowIndex <= 82 + 3) isContinue = true;
if (isContinue)
continue;
if (kvp.Value > 0)
total += kvp.Value;
}
}
cells[9, 3 + i - 9].PutValue(total);
cells[9, 3 + i - 9].SetStyle(style3);
}
//年内减少
for (int i = 3; i < 78; i++)
{
double total = 0;
foreach (KeyValuePair<ExcelCell, double> kvp in dicValue)
{
if (kvp.Key.RowIndex == 12 + i - 3)
{
//一级类相同地类不计算增加减少
bool isContinue = false;
if (i >= 3 && i <= 8 && kvp.Key.ColIndex >= 3 && kvp.Key.ColIndex <= 8) isContinue = true;
else if (i >= 9 && i <= 12 && kvp.Key.ColIndex >= 9 && kvp.Key.ColIndex <= 12) isContinue = true;
else if (i >= 13 && i <= 17 && kvp.Key.ColIndex >= 13 && kvp.Key.ColIndex <= 17) isContinue = true;
else if (i >= 18 && i <= 22 && kvp.Key.ColIndex >= 18 && kvp.Key.ColIndex <= 22) isContinue = true;
else if (i >= 23 && i <= 25 && kvp.Key.ColIndex >= 23 && kvp.Key.ColIndex <= 25) isContinue = true;
else if (i >= 26 && i <= 26 && kvp.Key.ColIndex >= 26 && kvp.Key.ColIndex <= 26) isContinue = true;
else if (i >= 27 && i <= 30 && kvp.Key.ColIndex >= 27 && kvp.Key.ColIndex <= 30) isContinue = true;
else if (i >= 31 && i <= 33 && kvp.Key.ColIndex >= 31 && kvp.Key.ColIndex <= 33) isContinue = true;
else if (i >= 35 && i <= 35 && kvp.Key.ColIndex >= 35 && kvp.Key.ColIndex <= 35) isContinue = true;
else if (i >= 36 && i <= 38 && kvp.Key.ColIndex >= 36 && kvp.Key.ColIndex <= 38) isContinue = true;
else if (i >= 39 && i <= 41 && kvp.Key.ColIndex >= 39 && kvp.Key.ColIndex <= 41) isContinue = true;
else if (i >= 42 && i <= 44 && kvp.Key.ColIndex >= 42 && kvp.Key.ColIndex <= 44) isContinue = true;
else if (i >= 45 && i <= 49 && kvp.Key.ColIndex >= 45 && kvp.Key.ColIndex <= 49) isContinue = true;
else if (i >= 50 && i <= 50 && kvp.Key.ColIndex >= 50 && kvp.Key.ColIndex <= 50) isContinue = true;
else if (i >= 51 && i <= 59 && kvp.Key.ColIndex >= 51 && kvp.Key.ColIndex <= 59) isContinue = true;
else if (i >= 60 && i <= 60 && kvp.Key.ColIndex >= 60 && kvp.Key.ColIndex <= 60) isContinue = true;
else if (i >= 61 && i <= 61 && kvp.Key.ColIndex >= 61 && kvp.Key.ColIndex <= 61) isContinue = true;
else if (i >= 63 && i <= 66 && kvp.Key.ColIndex >= 63 && kvp.Key.ColIndex <= 66) isContinue = true;
else if (i >= 67 && i <= 67 && kvp.Key.ColIndex >= 67 && kvp.Key.ColIndex <= 67) isContinue = true;
else if (i >= 68 && i <= 71 && kvp.Key.ColIndex >= 68 && kvp.Key.ColIndex <= 71) isContinue = true;
else if (i >= 72 && i <= 76 && kvp.Key.ColIndex >= 72 && kvp.Key.ColIndex <= 76) isContinue = true;
if (isContinue)
continue;
total += kvp.Value;
}
}
cells[10, i].PutValue(total);
cells[10, i].SetStyle(style3);
}
#region 插入行政区划入、划出、调整后面积
////行政区划入
//for (int i = 9; i < 84; i++)
//{
// double total = 0;
// foreach (KeyValuePair<ExcelCell, double> kvp in dicXZQTRValue)
// {
// if (kvp.Key.ColIndex == 3 + i - 9)
// {
// //一级类相同地类不计算增加减少
// bool isContinue = false;
// if (i >= 9 && i <= 14 && kvp.Key.RowIndex >= 9 + 3 && kvp.Key.RowIndex <= 14 + 3) isContinue = true;
// else if (i >= 15 && i <= 18 && kvp.Key.RowIndex >= 15 + 3 && kvp.Key.RowIndex <= 18 + 3) isContinue = true;
// else if (i >= 19 && i <= 23 && kvp.Key.RowIndex >= 19 + 3 && kvp.Key.RowIndex <= 23 + 3) isContinue = true;
// else if (i >= 24 && i <= 28 && kvp.Key.RowIndex >= 24 + 3 && kvp.Key.RowIndex <= 28 + 3) isContinue = true;
// else if (i >= 29 && i <= 31 && kvp.Key.RowIndex >= 29 + 3 && kvp.Key.RowIndex <= 31 + 3) isContinue = true;
// else if (i >= 32 && i <= 32 && kvp.Key.RowIndex >= 32 + 3 && kvp.Key.RowIndex <= 32 + 3) isContinue = true;
// else if (i >= 33 && i <= 36 && kvp.Key.RowIndex >= 33 + 3 && kvp.Key.RowIndex <= 36 + 3) isContinue = true;
// else if (i >= 37 && i <= 39 && kvp.Key.RowIndex >= 37 + 3 && kvp.Key.RowIndex <= 39 + 3) isContinue = true;
// else if (i >= 41 && i <= 41 && kvp.Key.RowIndex >= 41 + 3 && kvp.Key.RowIndex <= 41 + 3) isContinue = true;
// else if (i >= 42 && i <= 44 && kvp.Key.RowIndex >= 42 + 3 && kvp.Key.RowIndex <= 44 + 3) isContinue = true;
// else if (i >= 45 && i <= 47 && kvp.Key.RowIndex >= 45 + 3 && kvp.Key.RowIndex <= 47 + 3) isContinue = true;
// else if (i >= 48 && i <= 50 && kvp.Key.RowIndex >= 48 + 3 && kvp.Key.RowIndex <= 50 + 3) isContinue = true;
// else if (i >= 51 && i <= 55 && kvp.Key.RowIndex >= 51 + 3 && kvp.Key.RowIndex <= 55 + 3) isContinue = true;
// else if (i >= 56 && i <= 56 && kvp.Key.RowIndex >= 56 + 3 && kvp.Key.RowIndex <= 56 + 3) isContinue = true;
// else if (i >= 57 && i <= 65 && kvp.Key.RowIndex >= 57 + 3 && kvp.Key.RowIndex <= 65 + 3) isContinue = true;
// else if (i >= 66 && i <= 66 && kvp.Key.RowIndex >= 66 + 3 && kvp.Key.RowIndex <= 66 + 3) isContinue = true;
// else if (i >= 67 && i <= 67 && kvp.Key.RowIndex >= 67 + 3 && kvp.Key.RowIndex <= 67 + 3) isContinue = true;
// else if (i >= 69 && i <= 72 && kvp.Key.RowIndex >= 69 + 3 && kvp.Key.RowIndex <= 72 + 3) isContinue = true;
// else if (i >= 73 && i <= 73 && kvp.Key.RowIndex >= 73 + 3 && kvp.Key.RowIndex <= 73 + 3) isContinue = true;
// else if (i >= 74 && i <= 77 && kvp.Key.RowIndex >= 74 + 3 && kvp.Key.RowIndex <= 77 + 3) isContinue = true;
// else if (i >= 78 && i <= 82 && kvp.Key.RowIndex >= 78 + 3 && kvp.Key.RowIndex <= 82 + 3) isContinue = true;
// if (isContinue)
// continue;
// if (kvp.Value > 0)
// total += kvp.Value;
// }
// }
// cells[6, 3 + i - 9].PutValue(total);
// cells[6, 3 + i - 9].SetStyle(style3);
//}
////行政区划出
//for (int i = 3; i < 78; i++)
//{
// double total = 0;
// foreach (KeyValuePair<ExcelCell, double> kvp in dicXZQTCValue)
// {
// if (kvp.Key.RowIndex == 12 + i - 3)
// {
// //一级类相同地类不计算增加减少
// bool isContinue = false;
// if (i >= 3 && i <= 8 && kvp.Key.ColIndex >= 3 && kvp.Key.ColIndex <= 8) isContinue = true;
// else if (i >= 9 && i <= 12 && kvp.Key.ColIndex >= 9 && kvp.Key.ColIndex <= 12) isContinue = true;
// else if (i >= 13 && i <= 17 && kvp.Key.ColIndex >= 13 && kvp.Key.ColIndex <= 17) isContinue = true;
// else if (i >= 18 && i <= 22 && kvp.Key.ColIndex >= 18 && kvp.Key.ColIndex <= 22) isContinue = true;
// else if (i >= 23 && i <= 25 && kvp.Key.ColIndex >= 23 && kvp.Key.ColIndex <= 25) isContinue = true;
// else if (i >= 26 && i <= 26 && kvp.Key.ColIndex >= 26 && kvp.Key.ColIndex <= 26) isContinue = true;
// else if (i >= 27 && i <= 30 && kvp.Key.ColIndex >= 27 && kvp.Key.ColIndex <= 30) isContinue = true;
// else if (i >= 31 && i <= 33 && kvp.Key.ColIndex >= 31 && kvp.Key.ColIndex <= 33) isContinue = true;
// else if (i >= 35 && i <= 35 && kvp.Key.ColIndex >= 35 && kvp.Key.ColIndex <= 35) isContinue = true;
// else if (i >= 36 && i <= 38 && kvp.Key.ColIndex >= 36 && kvp.Key.ColIndex <= 38) isContinue = true;
// else if (i >= 39 && i <= 41 && kvp.Key.ColIndex >= 39 && kvp.Key.ColIndex <= 41) isContinue = true;
// else if (i >= 42 && i <= 44 && kvp.Key.ColIndex >= 42 && kvp.Key.ColIndex <= 44) isContinue = true;
// else if (i >= 45 && i <= 49 && kvp.Key.ColIndex >= 45 && kvp.Key.ColIndex <= 49) isContinue = true;
// else if (i >= 50 && i <= 50 && kvp.Key.ColIndex >= 50 && kvp.Key.ColIndex <= 50) isContinue = true;
// else if (i >= 51 && i <= 59 && kvp.Key.ColIndex >= 51 && kvp.Key.ColIndex <= 59) isContinue = true;
// else if (i >= 60 && i <= 60 && kvp.Key.ColIndex >= 60 && kvp.Key.ColIndex <= 60) isContinue = true;
// else if (i >= 61 && i <= 61 && kvp.Key.ColIndex >= 61 && kvp.Key.ColIndex <= 61) isContinue = true;
// else if (i >= 63 && i <= 66 && kvp.Key.ColIndex >= 63 && kvp.Key.ColIndex <= 66) isContinue = true;
// else if (i >= 67 && i <= 67 && kvp.Key.ColIndex >= 67 && kvp.Key.ColIndex <= 67) isContinue = true;
// else if (i >= 68 && i <= 71 && kvp.Key.ColIndex >= 68 && kvp.Key.ColIndex <= 71) isContinue = true;
// else if (i >= 72 && i <= 76 && kvp.Key.ColIndex >= 72 && kvp.Key.ColIndex <= 76) isContinue = true;
// if (isContinue)
// continue;
// total += kvp.Value;
// }
// }
// cells[7, i].PutValue(total);
// cells[7, i].SetStyle(style3);
//}
#endregion
for (int row = 5; row < 86; row++)
{
GetXJ(cells, row);
}
for (int row = 5; row < 86; row++)
{
GetXXJ(cells, row);
}
foreach (KeyValuePair<ExcelCell, double> kvp in dicValue)
{
double sumMJ = 0;
if (kvp.Key.BGQDLBM.Length > 4)
{
sumMJ = 0;
int count = 0;
switch (kvp.Key.BGQDLBM)
{
case "NYD_XJ":
List<string> lstNYD_XJ = new List<string>() { "NYD_XJ", "NYD00", "0303", "0304", "0306", "0402", "NYD01", "0101", "0102", "0103", "NYD02", "0201", "0202", "0203", "0204", "NYD03", "0301", "0302", "0305", "0307", "NYD04", "0401", "0403", "1006", "NYD11", "1103", "1104", "1107", "NYD12", "1202", "1203" };
if (lstNYD_XJ.Contains(kvp.Key.BGHDLBM))
continue;
count = 30; break;
case "JSYD_XJ":
List<string> lstJSYD_XJ = new List<string>() { "JSYD_XJ", "0603", "JSYD05", "05H1", "0508", "JSYD06", "0601", "0602", "JSYD07", "0701", "0702", "JSYD08", "08H1", "08H2", "0809", "0810", "09", "JSYD10", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009", "1109", "1201" };
if (lstJSYD_XJ.Contains(kvp.Key.BGHDLBM))
continue;
count = 27; break;
case "WLYD_XJ":
List<string> lstWLYD_XJ = new List<string>() { "WLYD_XJ", "WLYD00", "1105", "1106", "1108", "0404", "WLYD11", "1101", "1102", "1110", "WLYD12", "1204", "1205", "1206", "1207" };
if (lstWLYD_XJ.Contains(kvp.Key.BGHDLBM))
continue;
count = 14; break;
case "NYD00":
List<string> lstNY00 = new List<string>() { "NYD00", "0303", "0304", "0306", "0402" };
if (lstNY00.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "NYD01":
List<string> lstNY01 = new List<string>() { "NYD01", "0101", "0102", "0103" };
if (lstNY01.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "NYD02":
List<string> lstNY02 = new List<string>() { "NYD02", "0201", "0202", "0203", "0204" };
if (lstNY02.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "NYD03":
List<string> lstNY03 = new List<string>() { "NYD03", "0301", "0302", "0305", "0307" };
if (lstNY03.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "NYD04":
List<string> lstNY04 = new List<string>() { "NYD04", "0401", "0403" };
if (lstNY04.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "NYD11":
List<string> lstNY11 = new List<string>() { "NYD11", "1103", "1104", "1107" };
if (lstNY11.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "NYD12":
List<string> lstNY12 = new List<string>() { "NYD12", "1202", "1203" };
if (lstNY12.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "JSYD05":
List<string> lstJSYD05 = new List<string>() { "JSYD05", "05H1", "0508" };
if (lstJSYD05.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "JSYD06":
List<string> lstJSYD06 = new List<string>() { "JSYD06", "0601", "0602" };
if (lstJSYD06.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "JSYD07":
List<string> lstJSYD07 = new List<string>() { "JSYD07", "0701", "0702" };
if (lstJSYD07.Contains(kvp.Key.BGHDLBM))
continue;
count = 2; break;
case "JSYD08":
List<string> lstJSYD08 = new List<string>() { "JSYD08", "08H1", "08H2", "0809", "0810" };
if (lstJSYD08.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
case "JSYD10":
//List<string> lstJSYD10 = new List<string>() { "JSYD10", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009", "1109", "1201" };
List<string> lstJSYD10 = new List<string>() { "JSYD10", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009" };
if (lstJSYD10.Contains(kvp.Key.BGHDLBM))
continue;
count = 8; break;
case "WLYD00":
//List<string> lstWLYD00 = new List<string>() { "WLYD00", "1105", "1106", "1108", "0404" };
List<string> lstWLYD00 = new List<string>() { "WLYD00", "1105", "1106", "1108" };
if (lstWLYD00.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "WLYD11":
List<string> lstWLYD11 = new List<string>() { "WLYD11", "1101", "1102", "1110" };
if (lstWLYD11.Contains(kvp.Key.BGHDLBM))
continue;
count = 3; break;
case "WLYD12":
List<string> lstWLYD12 = new List<string>() { "WLYD12", "1204", "1205", "1206", "1207" };
if (lstWLYD12.Contains(kvp.Key.BGHDLBM))
continue;
count = 4; break;
default:
continue;
}
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());
}
}
if (cells[kvp.Key.RowIndex, kvp.Key.ColIndex].Value.ToString() == "0")
{
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(sumMJ);
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
}
}
if (kvp.Key.BGHDLBM.Length > 4)
{
sumMJ = 0;
int count = 0;
switch (kvp.Key.BGHDLBM)
{
case "NYD_XJ":
List<string> lstNYD_XJ = new List<string>() { "NYD_XJ", "NYD00", "0303", "0304", "0306", "0402", "NYD01", "0101", "0102", "0103", "NYD02", "0201", "0202", "0203", "0204", "NYD03", "0301", "0302", "0305", "0307", "NYD04", "0401", "0403", "1006", "NYD11", "1103", "1104", "1107", "NYD12", "1202", "1203" };
if (lstNYD_XJ.Contains(kvp.Key.BGQDLBM))
continue;
count = 30; break;
case "JSYD_XJ":
List<string> lstJSYD_XJ = new List<string>() { "JSYD_XJ", "0603", "JSYD05", "05H1", "0508", "JSYD06", "0601", "0602", "JSYD07", "0701", "0702", "JSYD08", "08H1", "08H2", "0809", "0810", "09", "JSYD10", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009", "1109", "1201" };
if (lstJSYD_XJ.Contains(kvp.Key.BGQDLBM))
continue;
count = 27; break;
case "WLYD_XJ":
List<string> lstWLYD_XJ = new List<string>() { "WLYD_XJ", "WLYD00", "1105", "1106", "1108", "0404", "WLYD11", "1101", "1102", "1110", "WLYD12", "1204", "1205", "1206", "1207" };
if (lstWLYD_XJ.Contains(kvp.Key.BGQDLBM))
continue;
count = 14; break;
case "NYD00":
List<string> lstNY00 = new List<string>() { "NYD00", "0303", "0304", "0306", "0402" };
if (lstNY00.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "NYD01":
List<string> lstNY01 = new List<string>() { "NYD01", "0101", "0102", "0103" };
if (lstNY01.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "NYD02":
List<string> lstNY02 = new List<string>() { "NYD02", "0201", "0202", "0203", "0204" };
if (lstNY02.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "NYD03":
List<string> lstNY03 = new List<string>() { "NYD03", "0301", "0302", "0305", "0307" };
if (lstNY03.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "NYD04":
List<string> lstNY04 = new List<string>() { "NYD04", "0401", "0403" };
if (lstNY04.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "NYD11":
List<string> lstNY11 = new List<string>() { "NYD11", "1103", "1104", "1107" };
if (lstNY11.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "NYD12":
List<string> lstNY12 = new List<string>() { "NYD12", "1202", "1203" };
if (lstNY12.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "JSYD05":
List<string> lstJSYD05 = new List<string>() { "JSYD05", "05H1", "0508" };
if (lstJSYD05.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "JSYD06":
List<string> lstJSYD06 = new List<string>() { "JSYD06", "0601", "0602" };
if (lstJSYD06.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "JSYD07":
List<string> lstJSYD07 = new List<string>() { "JSYD07", "0701", "0702" };
if (lstJSYD07.Contains(kvp.Key.BGQDLBM))
continue;
count = 2; break;
case "JSYD08":
List<string> lstJSYD08 = new List<string>() { "JSYD08", "08H1", "08H2", "0809", "0810" };
if (lstJSYD08.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
case "JSYD10":
//List<string> lstJSYD10 = new List<string>() { "JSYD10", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009", "1109", "1201" };
List<string> lstJSYD10 = new List<string>() { "JSYD10", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009" };
if (lstJSYD10.Contains(kvp.Key.BGQDLBM))
continue;
count = 8; break;
case "WLYD00":
//List<string> lstWLYD00 = new List<string>() { "WLYD00", "1105", "1106", "1108", "0404" };
List<string> lstWLYD00 = new List<string>() { "WLYD00", "1105", "1106", "1108" };
if (lstWLYD00.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "WLYD11":
List<string> lstWLYD11 = new List<string>() { "WLYD11", "1101", "1102", "1110" };
if (lstWLYD11.Contains(kvp.Key.BGQDLBM))
continue;
count = 3; break;
case "WLYD12":
List<string> lstWLYD12 = new List<string>() { "WLYD12", "1204", "1205", "1206", "1207" };
if (lstWLYD12.Contains(kvp.Key.BGQDLBM))
continue;
count = 4; break;
default:
continue;
}
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());
}
}
if (cells[kvp.Key.RowIndex, kvp.Key.ColIndex].Value.ToString() == "0")
{
//LogAPI.Debug("设置 cells[" + kvp.Key.RowIndex + "," + kvp.Key.ColIndex + "]= " + sumMJ + " ;\r\n ");
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].PutValue(sumMJ);
cells[kvp.Key.RowIndex, kvp.Key.ColIndex].SetStyle(style3);
}
}
}
Get3_XJ(cells);
for (int i = 9; i < 84; i++)
{
double total = 0;
foreach (KeyValuePair<ExcelCell, double> kvp in dicValue)
{
if (kvp.Key.ColIndex == 3 + i - 9)
{
if (kvp.Value > 0)
total += kvp.Value;
}
}
if (total != 0)
{
cells[9, 3 + i - 9].PutValue(total);
cells[9, 3 + i - 9].SetStyle(style3);
}
}
for (int i = 3; i < 78; i++)
{
double total = 0;
foreach (KeyValuePair<ExcelCell, double> kvp in dicValue)
{
if (kvp.Key.RowIndex == 12 + i - 3)
{
total += kvp.Value;
}
}
if (total != 0)
{
cells[10, i].PutValue(total);
cells[10, i].SetStyle(style3);
}
}
Get_NNZJJS_HJ(cells);
for (int i = 3; i < 78; i++)
{
double ncMJ = 0;
double zjMJ = 0;
double jsMJ = 0;
double hrMJ = 0;
double hcMJ = 0;
if (cells[5, i].Value != null && !string.IsNullOrEmpty(cells[5, i].Value.ToString()))
ncMJ = double.Parse(cells[5, i].Value.ToString());
else
cells[5, i].PutValue(0);
if (cells[9, i].Value != null && !string.IsNullOrEmpty(cells[9, i].Value.ToString()))
zjMJ = double.Parse(cells[9, i].Value.ToString());
else
cells[9, i].PutValue(0);
if (cells[10, i].Value != null && !string.IsNullOrEmpty(cells[10, i].Value.ToString()))
jsMJ = double.Parse(cells[10, i].Value.ToString());
else
cells[10, i].PutValue(0);
if (cells[6, i].Value != null && !string.IsNullOrEmpty(cells[6, i].Value.ToString()))
hrMJ = double.Parse(cells[6, i].Value.ToString());
else
cells[6, i].PutValue(0);
if (cells[7, i].Value != null && !string.IsNullOrEmpty(cells[7, i].Value.ToString()))
hcMJ = double.Parse(cells[7, i].Value.ToString());
else
cells[7, i].PutValue(0);
double tzmj = ncMJ + hrMJ - hcMJ;
cells[8, i].PutValue(tzmj);
cells[8, i].SetStyle(style3);
cells[11, i].PutValue(tzmj + zjMJ - jsMJ);
cells[11, i].SetStyle(style3);
}
}
bRecordJudgeLog = false;
//将本地类转本地类行列小计置为0; 2020-7-11 沈超
SetEmptyForTheSameDLTypeChange(cells);
//计算非本地类转非本地类行列小计; 2020-7-18 沈超
SetValueForTheDifferentDLTypeChange(cells);
workbook.Save(saveCurrentPath);
return true;
}
/// <summary>
/// 三大类土地利用现状变更表
/// </summary>
private bool ExportSDLTDLYXZBGB_SQL(string saveCurrentPath, IRDBHelper dbHelper, string ncsjPath)
{
string ncsjExcelPath = string.Empty;
DirectoryInfo dir = new DirectoryInfo(ncsjPath);
string fileName = string.Empty;
#region 数据赋值
FileInfo[] fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")土地利用现状分类面积汇总表.xlsx", SearchOption.AllDirectories);
if (fileSet != null && fileSet.Length > 0)
{
ncsjExcelPath = fileSet[0].FullName;
fileName = fileSet[0].Name.Replace("(", "").Replace(")", "").Replace((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, "").Replace(fileSet[0].Extension, "");
}
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);
DataTable resultdataTable = new DataTable();
DataTable dt = dbHelper.ExecuteDatatable("SDLTDLYXZBGB", @" select Cells_X,Cells_Y,BGMJ from ( select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,SUM(BGMJ) BGMJ from ( select substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A WHERE bgq<>bgh GROUP BY bgq,bgh )A left JOIN SDLTDLYXZBGB B ON a.bgh = B.bgh and a.bgq = B.bgq where Cells_X NOTNULL and Cells_Y NOTNULL ", true);
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
#endregion
#region 上年末面积
DataTable table = dbHelper.ExecuteDatatable("tab", string.Format(@"select case WHEN column1='{0}' THEN'column1' ELSE 'column2' END ColumnName from {1} WHERE column1='{0}' or column2='{0}' ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, fileName), true);
if (table == null || table.Rows.Count == 0)
{
return false;
}
string ColumnName = table.Rows[0][0].ToTrim();
if (ColumnName == "column1")
{
dt = dbHelper.ExecuteDatatable("SNMMJ", string.Format(@"
select '5' Cells_X, '5' Cells_Y, round(column4,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X, '6' Cells_Y, round(column5,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X, '7' Cells_Y, round(column6,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X, '8' Cells_Y, round(column7,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'10' Cells_Y, round(column12,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'11' Cells_Y, round(column13,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'12' Cells_Y, round(column14,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'14' Cells_Y, round(column16,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'15' Cells_Y, round(column17,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'16' Cells_Y, round(column18,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'17' Cells_Y, round(column19,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'19' Cells_Y, round(column21,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'20' Cells_Y, round(column22,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'21' Cells_Y, round(column23,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'22' Cells_Y, round(column24,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'24' Cells_Y, round(column26,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'25' Cells_Y, round(column27,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'26' Cells_Y, round(column51,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'28' Cells_Y, round(column46,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'29' Cells_Y, round(column47,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'30' Cells_Y, round(column48,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'32' Cells_Y, round(column52,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'33' Cells_Y, round(column53,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'36' Cells_Y, round(column30,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'37' Cells_Y, round(column31,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'38' Cells_Y, round(column32,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'39' Cells_Y, round(column33,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'40' Cells_Y, round(column34,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'42' Cells_Y, round(column36,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'43' Cells_Y, round(column37,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'44' Cells_Y, round(column38,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'45' Cells_Y, round(column39,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'46' Cells_Y, round(column40,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'47' Cells_Y, round(column41,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'48' Cells_Y, round(column42,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'51' Cells_Y, round(column8,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'52' Cells_Y, round(column9,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'53' Cells_Y, round(column10,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'54' Cells_Y, round(column28,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'56' Cells_Y, round(column44,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'57' Cells_Y, round(column45,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'58' Cells_Y, round(column49,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'60' Cells_Y, round(column54,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'61' Cells_Y, round(column55,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'62' Cells_Y, round(column56,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'63' Cells_Y, round(column57,4) BGMJ FROM {2} WHERE {1}='{0}' ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, ColumnName, fileName), true);
}
else if (ColumnName == "column2")
{
dt = dbHelper.ExecuteDatatable("SNMMJ", string.Format(@"
select '5' Cells_X, '5' Cells_Y, round(column5,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X, '6' Cells_Y, round(column6,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X, '7' Cells_Y, round(column7,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X, '8' Cells_Y, round(column8,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'10' Cells_Y, round(column13,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'11' Cells_Y, round(column14,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'12' Cells_Y, round(column15,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'14' Cells_Y, round(column17,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'15' Cells_Y, round(column18,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'16' Cells_Y, round(column19,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'17' Cells_Y, round(column20,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'19' Cells_Y, round(column22,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'20' Cells_Y, round(column23,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'21' Cells_Y, round(column24,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'22' Cells_Y, round(column25,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'24' Cells_Y, round(column27,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'25' Cells_Y, round(column28,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'26' Cells_Y, round(column52,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'28' Cells_Y, round(column47,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'29' Cells_Y, round(column48,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'30' Cells_Y, round(column49,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'32' Cells_Y, round(column53,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'33' Cells_Y, round(column54,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'36' Cells_Y, round(column31,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'37' Cells_Y, round(column32,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'38' Cells_Y, round(column33,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'39' Cells_Y, round(column34,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'40' Cells_Y, round(column35,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'42' Cells_Y, round(column37,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'43' Cells_Y, round(column38,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'44' Cells_Y, round(column39,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'45' Cells_Y, round(column40,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'46' Cells_Y, round(column41,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'47' Cells_Y, round(column42,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'48' Cells_Y, round(column43,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'51' Cells_Y, round(column9,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'52' Cells_Y, round(column10,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'53' Cells_Y, round(column11,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'54' Cells_Y, round(column29,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'56' Cells_Y, round(column45,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'57' Cells_Y, round(column46,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'58' Cells_Y, round(column50,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'60' Cells_Y, round(column55,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'61' Cells_Y, round(column56,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'62' Cells_Y, round(column57,4) BGMJ FROM {2} WHERE {1}='{0}' UNION ALL
select '5' Cells_X,'63' Cells_Y, round(column58,4) BGMJ FROM {2} WHERE {1}='{0}' ", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, ColumnName, fileName), true);
}
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
#endregion
#region 行政区调入
dt = dbHelper.ExecuteDatatable("XZQDR", string.Format(@"select '6' Cells_X,Cells_Y,BGMJ from
(
select case when XZQTZLX='1' then bgq ELSE bgh end dlbm, SUM(BGMJ) BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ,XZQTZLX
from
(
select substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ
)A WHERE XZQTZLX in ('1','3')
)A GROUP BY dlbm
)a left join SDLTDLYXZBGB B on a.DLBM= B.bgh where b.Cells_X='14'"), true);
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
#endregion
#region 行政区调出
dt = dbHelper.ExecuteDatatable("XZQDC", string.Format(@"select '7' Cells_X,Cells_Y,BGMJ from
(
select bgq dlbm, SUM(BGMJ) BGMJ from
(
select case when BGQCZCSXM='空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ,XZQTZLX
from
(
select substr(BGQDLBM, 1, 4) BGQDLBM, substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ
)A WHERE XZQTZLX in ('2','4')
)A GROUP BY dlbm
)a left join SDLTDLYXZBGB B on a.DLBM= B.bgh where b.Cells_X='14'"), true);
if (dt != null && dt.Rows.Count > 0)
{
resultdataTable.Merge(dt);
}
CellHelper.SetFileToDisk(resultdataTable, saveCurrentPath, 0);
#endregion
CellHelper.Import(saveCurrentPath);
return true;
}
private bool ExportJBNTTJB(string saveCurrentPath, IRDBHelper dbHelper, string ncsjPath)
{
string tempPath = AppDomain.CurrentDomain.BaseDirectory + "TempalateReports\\统一时点更新统计表\\原样表\\基本农田统计汇总表.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 = 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;
workbook.Save(saveCurrentPath);
return true;
}
#region 将本地类转本地类行列小计置为0
public List<int> iNeedRList;
public List<int> iNeedCList;
/// <summary>
/// 本地类转本地类行列小计置为0
/// </summary>
public void SetEmptyForTheSameDLTypeChange(Cells cells)
{
iNeedRList = new List<int>();
iNeedCList = new List<int>();
try
{
GetTheSameTypeDLCells(ref iNeedRList, ref iNeedCList);
if (iNeedRList == null || iNeedRList.Count <= 0 ||
iNeedCList == null || iNeedCList.Count <= 0)
{
LogAPI.Debug("本地类转本地类小计置空 失败 ; ");
return;
}
int iRTemp_ = 0;
int iCTemp_ = 0;
double dTemp = 0.00;
for (int u = 0; u < iNeedRList.Count(); u++)
{
iRTemp_ = iNeedRList[u];
iCTemp_ = iNeedCList[u];
if (cells[iRTemp_ - 1, iCTemp_ - 1].Value == null)
{
if (bRecordJudgeLog == true)
{
LogAPI.Debug("行号:" + iRTemp_ + "; 列号:" + iCTemp_ + " 无值不处理;");
}
continue;
}
else
{
dTemp = cells[iRTemp_ - 1, iCTemp_ - 1].Value.ToDouble();
if (dTemp == 0)
{
if (bRecordJudgeLog == true)
{
LogAPI.Debug("行号:" + iRTemp_ + "; 列号:" + iCTemp_ + " 值为0不处理;");
}
continue;
}
else
{
cells[iRTemp_ - 1, iCTemp_ - 1].PutValue(0);
if (bRecordJudgeLog == true)
{
LogAPI.Debug("行号:" + iRTemp_ + "; 列号:" + iCTemp_ + " 值为" + dTemp + ",置为0;");
}
}
}
}
return;
}
catch (Exception ex)
{
LogAPI.Debug("本地类转本地类小计置空 失败,异常原因: " + ex + " ; ");
return;
}
finally
{
if (iNeedRList != null && iNeedRList.Count > 0)
{
iNeedRList = null;
}
if (iNeedCList != null && iNeedCList.Count > 0)
{
iNeedCList = null;
}
}
}
/// <summary>
/// 获取本地类转本地类需要置空的行列编号字典
/// </summary>
/// <param name="ListR"></param>
/// <param name="ListC"></param>
public void GetTheSameTypeDLCells(ref List<int> ListR, ref List<int> ListC)
{
int iRowStartNum = 13;
int iColumnStartNum = 4;
int iTempR = 0;
int iTempC = 0;
int iRT = 0;
List<int> intervalList = new List<int>() { 4, 3, 4, 4, 2, 0, 3, 2, 0, 0, 2, 2, 2, 4, 0, 8, 0, 0, 0, 3, 0, 3, 4 };
try
{
for (int i = 0; i < intervalList.Count(); i++)
{
iTempR = iRowStartNum + 1;
iTempC = iColumnStartNum + 1;
ListR.Add(iTempR);
ListC.Add(iTempC);
iRT = iTempR;
for (int j = 0; j < intervalList[i]; j++)
{
iTempR += 1;
ListR.Add(iTempR);
ListC.Add(iTempC);
}
for (int k = 0; k < intervalList[i]; k++)
{
iTempC += 1;
ListR.Add(iRT);
ListC.Add(iTempC);
}
iRowStartNum += intervalList[i] + 1;
iColumnStartNum += intervalList[i] + 1;
}
return;
}
catch (Exception ex)
{
LogAPI.Debug("获取本地类转本地类需要置空的行列编号字典 失败,异常原因: " + ex + " ; ");
return;
}
finally
{
if (intervalList != null && intervalList.Count > 0)
{
intervalList = null;
}
}
}
#endregion
#region 计算非本地类转非本地类行列小计
public List<int> iS_XJ_RList;
public List<int> iS_XJ_CList;
public List<int> iAllNeedXJ_RList;
public List<int> iAllNeedXJ_CList;
public List<int> theIntervalList;
public List<int> theIntervalList_;//间隔要往下累加的数量
public bool bRecordJudgeLog;
/// <summary>
/// 计算非本地类转非本地类行列小计
/// </summary>
/// <param name="theCells"></param>
public void SetValueForTheDifferentDLTypeChange(Cells theCells)
{
try
{
iS_XJ_RList = new List<int>();
iS_XJ_CList = new List<int>();
theIntervalList = new List<int>() { 4, 3, 4, 4, 2, 0, 3, 2, 0, 0, 2, 2, 2, 4, 0, 8, 0, 0, 0, 3, 0, 3, 4 };
theIntervalList_ = new List<int>() { 4, 3, 4, 4, 2, 3, 2, 2, 2, 2, 4, 8, 3, 3, 4 };
iAllNeedXJ_RList = new List<int>() { 14, 19, 23, 28, 33, 37, 41, 46, 49, 52, 55, 61, 73, 78, 82 };
iAllNeedXJ_CList = new List<int>() { 5, 10, 14, 19, 24, 27, 28, 32, 36, 37, 40, 43, 46, 51, 52, 61, 62, 64, 68, 69, 73 };
//获取地类间转化的行列编号字典等信息
GetDLTypeRCXJCellsMsg(ref iS_XJ_RList, ref iS_XJ_CList);
int iR_Now = 0;
int iC_Now = 0;
if (iS_XJ_RList == null || iS_XJ_RList.Count <= 0 ||
iS_XJ_CList == null || iS_XJ_CList.Count <= 0)
{
return;
}
int iIndex_Temp = 0;//临时索引值
int iPassMark_C = 0;//需要跳过的列编号标记
int iNeedAddCount_Temp = 0;//需要增加的行数
double dTheTemp = 0.00;
double dTheTempSum = 0.00;
int iR_Temp_1 = 0;//临时行标记
//获取全部的本类转本类的行列小计
for (int i = 0; i < iAllNeedXJ_RList.Count(); i++)
{
iNeedAddCount_Temp = theIntervalList_[i];
iR_Now = iAllNeedXJ_RList[i];
iPassMark_C = 0;
iIndex_Temp = iS_XJ_RList.IndexOf(iR_Now);
if (iIndex_Temp == -1)
{
iPassMark_C = 0;
}
else
{
iPassMark_C = iS_XJ_CList[iIndex_Temp];
}
for (int j = 0; j < iAllNeedXJ_CList.Count(); j++)
{
iC_Now = iAllNeedXJ_CList[j];
dTheTemp = 0.00;
dTheTempSum = 0.00;
dTheTemp = theCells[iR_Now - 1, iC_Now - 1].Value.ToDouble();
if (bRecordJudgeLog == true)
{
LogAPI.Debug("要处理的 行号:" + iR_Now + "; 列号:" + iC_Now + " 值 ; 原先值为" + dTheTemp + " ; ");
}
if (iC_Now == iPassMark_C)
{
if (bRecordJudgeLog == true)
{
LogAPI.Debug("此单元格 跳过执行 ; \r\n");
}
continue;
}
else
{
iR_Temp_1 = iR_Now;
for (int g = 0; g < iNeedAddCount_Temp; g++)
{
iR_Temp_1 += 1;
if (bRecordJudgeLog == true)
{
LogAPI.Debug("dTheTempSum 加行(" + iR_Temp_1 + ")列(" + iC_Now + ")之前: " + dTheTempSum + " ; ");
}
dTheTempSum += theCells[iR_Temp_1 - 1, iC_Now - 1].Value.ToDouble();
if (bRecordJudgeLog == true)
{
LogAPI.Debug("dTheTempSum 加之后: " + dTheTempSum + " ; ");
}
}
theCells[iR_Now - 1, iC_Now - 1].PutValue(dTheTempSum);
if (bRecordJudgeLog == true)
{
LogAPI.Debug("行号:" + iR_Now + "; 列号:" + iC_Now + " 将值设为" + dTheTempSum + " ; \r\n");
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("计算非本地类转非本地类行列小计异常: " + ex + " ; ");
return;
}
finally
{
if (iS_XJ_RList != null && iS_XJ_RList.Count > 0)
{
iS_XJ_RList = null;
}
if (iS_XJ_CList != null && iS_XJ_CList.Count > 0)
{
iS_XJ_CList = null;
}
}
}
/// <summary>
/// 获取地类间转化的行列编号字典等信息
/// </summary>
/// <param name="iS_XJ_RList"></param>
/// <param name="iS_XJ_CList"></param>
public void GetDLTypeRCXJCellsMsg(ref List<int> iS_XJ_RList, ref List<int> iS_XJ_CList)
{
int i_RowStartNum = 13;
int i_ColumnStartNum = 4;
int i_TempR = 0;
int i_TempC = 0;
try
{
for (int i = 0; i < theIntervalList.Count(); i++)
{
i_TempR = i_RowStartNum + 1;
i_TempC = i_ColumnStartNum + 1;
iS_XJ_RList.Add(i_TempR);
iS_XJ_CList.Add(i_TempC);
i_RowStartNum += theIntervalList[i] + 1;
i_ColumnStartNum += theIntervalList[i] + 1;
}
return;
}
catch (Exception ex)
{
LogAPI.Debug("获取所有地类间转化的行列编号字典 失败,异常原因: " + ex + " ; ");
return;
}
finally
{
if (theIntervalList != null && theIntervalList.Count > 0)
{
theIntervalList = null;
}
}
}
#endregion
private void Get_NNZJJS_HJ(Cells cells)
{
double nnzjMJ = 0;
double nnjsMJ = 0;
for (int i = 4; i < 78; i++)
{
if (cells[4, i].Value != null && cells[4, i].Value.ToString().Contains("("))
{
nnzjMJ += double.Parse(cells[9, i].Value == null ? "0" : cells[9, i].Value.ToString());
nnjsMJ += double.Parse(cells[10, i].Value == null ? "0" : cells[10, i].Value.ToString());
}
}
cells[9, 77].PutValue(nnzjMJ);
//for (int i = 4; i < 78; i++)
//{
// if (cells[4, i].Value != null && cells[4, i].Value.ToString().Contains("("))
// {
// nnjsMJ += double.Parse(cells[7, i].Value.ToString());
// }
//}
cells[10, 77].PutValue(nnjsMJ);
for (int row = 12; row < 86; row++)
{
double hzmj = 0;
for (int i = 4; i < 78; i++)
{
if (cells[4, i].Value != null && cells[4, i].Value.ToString().Contains("("))
{
//LogAPI.Debug("cell【4," + i + "】 有值= " + double.Parse(cells[row, i].Value.ToString()) + " ; ");
//LogAPI.Debug("当前 hzmj= " + hzmj + " ; ");
hzmj += double.Parse(cells[row, i].Value == null ? "0" : cells[row, i].Value.ToString());
}
}
//LogAPI.Debug("cell【" + row + ",77】 值= " + hzmj + " ;/r/n ");
//LogAPI.Debug("/r/n");
cells[row, 77].PutValue(hzmj);
}
}
private void GetXJ(Cells cells, int rol)
{
List<int> lst = new List<int>() { 30, 27, 14 };
int isJump = 0;
if (rol >= 9 + 3 & rol <= 39 + 3) isJump = 0;
else if (rol >= 40 + 3 & rol <= 67 + 3) isJump = 1;
else if (rol >= 68 + 3 & rol <= 82 + 3) isJump = 2;
else isJump = 999;
int num = 0;
int fromCol = 4;
double sumMJ = 0;
foreach (int count in lst)
{
if (isJump != num)
{
double mj = 0;
for (int col = fromCol; col < fromCol + count; col++)
{
if (cells[rol, col].Value != null && cells[rol, col].Value != "")
mj += double.Parse(cells[rol, col].Value.ToString());
}
cells[rol, fromCol - 1].PutValue(mj);
sumMJ += mj;
}
fromCol += count + 1;
num++;
}
cells[rol, 77].PutValue(sumMJ);
}
private void Get3_XJ(Cells cells)
{
double nydmj = double.Parse(cells[43, 3].Value.ToString()) + double.Parse(cells[71, 3].Value.ToString());
cells[9, 3].PutValue(nydmj);
double jsyxmj = double.Parse(cells[12, 34].Value.ToString()) + double.Parse(cells[71, 34].Value.ToString());
cells[9, 34].PutValue(jsyxmj);
double wlydmj = double.Parse(cells[43, 62].Value.ToString()) + double.Parse(cells[12, 62].Value.ToString());
cells[9, 62].PutValue(wlydmj);
double nydmj_js = double.Parse(cells[12, 34].Value.ToString()) + double.Parse(cells[12, 62].Value.ToString());
cells[10, 3].PutValue(nydmj_js);
double jsyxmj_js = double.Parse(cells[43, 3].Value.ToString()) + double.Parse(cells[43, 62].Value.ToString());
cells[10, 34].PutValue(jsyxmj_js);
double wlydmj_js = double.Parse(cells[71, 3].Value.ToString()) + double.Parse(cells[71, 34].Value.ToString());
cells[10, 62].PutValue(wlydmj_js);
}
private void GetXXJ(Cells cells, int rol)
{
List<int> lst = new List<int>() { 4, 3, 4, 4, 2, 0, 3, 2, 0, 0, 2, 2, 2, 4, 0, 8, 0, 0, 0, 3, 0, 3, 4 };
int isJump = 0;
if (rol >= 10 + 3 & rol <= 14 + 3) isJump = 0;
else if (rol >= 15 + 3 & rol <= 18 + 3) isJump = 1;
else if (rol >= 19 + 3 & rol <= 23 + 3) isJump = 2;
else if (rol >= 24 + 3 & rol <= 28 + 3) isJump = 3;
else if (rol >= 29 + 3 & rol <= 31 + 3) isJump = 4;
else if (rol >= 33 + 3 & rol <= 36 + 3) isJump = 6;
else if (rol >= 37 + 3 & rol <= 39 + 3) isJump = 7;
else if (rol >= 42 + 3 & rol <= 44 + 3) isJump = 10;
else if (rol >= 45 + 3 & rol <= 47 + 3) isJump = 11;
else if (rol >= 48 + 3 & rol <= 50 + 3) isJump = 12;
else if (rol >= 51 + 3 & rol <= 55 + 3) isJump = 13;
else if (rol >= 57 + 3 & rol <= 65 + 3) isJump = 14;
else if (rol >= 69 + 3 & rol <= 72 + 3) isJump = 18;
else if (rol >= 74 + 3 & rol <= 77 + 3) isJump = 20;
else if (rol >= 78 + 3 & rol <= 82 + 3) isJump = 21;
else isJump = 999;
int num = 0;
int fromCol = 5;
foreach (int count in lst)
{
if (isJump != num)
{
if (count != 0)
{
double mj = 0;
for (int col = fromCol; col < fromCol + count; col++)
{
if (cells[rol, col].Value != null && cells[rol, col].Value != "")
mj += double.Parse(cells[rol, col].Value.ToString());
}
cells[rol, fromCol - 1].PutValue(mj);
if (rol > 60 & rol <= 68)
{
cells[rol, 51].PutValue(0);
}
}
}
fromCol += count + 1;
num++;
}
}
private void GetHJ(Cells cells, int rol)
{
List<int> lst = new List<int>() { 3, 34, 62 };
double sumMJ = 0;
foreach (int col in lst)
{
if (cells[rol, col].Value != null)
sumMJ += double.Parse(cells[rol, col].Value.ToString());
}
cells[rol, 77].PutValue(sumMJ);
}
private Dictionary<ExcelCell, double> GetDicSDLTDLYXZBHPHTJB()
{
Dictionary<ExcelCell, double> dic = new Dictionary<ExcelCell, double>();
//湿地
List<string> lst = new List<string>() { "NYD_XJ", "NYD00", "0303", "0304", "0306", "0402", "NYD01", "0101", "0102", "0103", "NYD02", "0201", "0202", "0203", "0204", "NYD03", "0301", "0302", "0305", "0307", "NYD04", "0401", "0403", "1006", "NYD11", "1103", "1104", "1107", "NYD12", "1202", "1203", "JSYD_XJ", "0603", "JSYD05", "05H1", "0508", "JSYD06", "0601", "0602", "JSYD07", "0701", "0702", "JSYD08", "08H1", "08H2", "0809", "0810", "09", "JSYD10", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009", "1109", "1201", "WLYD_XJ", "WLYD00", "1105", "1106", "1108", "0404", "WLYD11", "1101", "1102", "1110", "WLYD12", "1204", "1205", "1206", "1207" };
int i = 0;
int j = 0;
foreach (string bgqdlbm in lst)
{
j = 0;
foreach (string bghdlbm in lst)
{
dic.Add(new ExcelCell() { BGQDLBM = bgqdlbm, BGHDLBM = bghdlbm, ColIndex = 3 + j, RowIndex = 12 + i }, 0);
j++;
}
i++;
}
return dic;
}
}
}