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

1980 lines
100 KiB

4 months ago
using ESRI.ArcGIS.Geodatabase;
using ExcelDataReader;
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.Helper;
using KGIS.Framework.Utils.Model;
using KGIS.Framework.VCT.Entity;
using KGIS.Framework.VCT.Enums;
using KGIS.Framework.VCT.Helper;
using Kingo.Plugin.YJJK.Interface;
using Kingo.PluginServiceInterface;
using KUI.Windows;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Xml;
namespace Kingo.Plugin.YJJK.ModelEntity
{
public class ExportBGViewModel : ReactiveObject, IScreen
{
private string _OutDir;
public string OutDir
{
get { return _OutDir; }
set { this.RaiseAndSetIfChanged(ref _OutDir, value); }
}
private string _NCDataDir;
public string NCDataDir
{
get { return _NCDataDir; }
set
{
this.RaiseAndSetIfChanged(ref _NCDataDir, value);
}
}
private bool _hasPdt;
public bool HasPDT
{
get { return _hasPdt; }
set { this.RaiseAndSetIfChanged(ref _hasPdt, value); }
}
private bool _IsBL;//是否补充0至19位
public bool IsBL
{
get { return _IsBL; }
set { this.RaiseAndSetIfChanged(ref _IsBL, value); }
}
private System.Windows.Visibility _PDT_Visibility;
public System.Windows.Visibility PDT_Visibility
{
get { return _PDT_Visibility; }
set { this.RaiseAndSetIfChanged(ref _PDT_Visibility, value); }
}
private System.Windows.Visibility _BL_Visibility;
public System.Windows.Visibility BL_Visibility
{
get { return _BL_Visibility; }
set { this.RaiseAndSetIfChanged(ref _BL_Visibility, value); }
}
private System.Windows.Visibility _NCData_Visibility;
public System.Windows.Visibility NCData_Visibility
{
get { return _NCData_Visibility; }
set { this.RaiseAndSetIfChanged(ref _NCData_Visibility, value); }
}
private decimal _BGYear = Convert.ToDecimal(DateTime.Now.Year - 1 < 2019 ? 2019 : DateTime.Now.Month >= 10 ? DateTime.Now.Year : DateTime.Now.Year - 1);
public decimal BGYear
{
get { return _BGYear; }
set
{
this.RaiseAndSetIfChanged(ref _BGYear, value);
//Items = GetResultsCatalog();
//Items = GetResultsCatalogtemp(true);
new Thread((ThreadStart)delegate () { Items = GetResultsCatalogtemp(true); }).Start();
}
}
private List<ResultsCatalog> _Items;
public List<ResultsCatalog> Items
{
get { return _Items; }
set { this.RaiseAndSetIfChanged(ref _Items, value); }
}
/// <summary>
/// 输出成果根目录
/// </summary>
public string OutDataRootDir { get; set; }
public RoutingState Router
{
get;
}
public ReactiveCommand<object> ExportClick { get; protected set; }
public ReactiveCommand<object> DeleteTemplateClick { get; protected set; }
public ReactiveCommand<object> CreateTemplateClick { get; protected set; }
public ReactiveCommand<object> SelectedTemplateClick { get; protected set; }
private List<string> _TemplateList;
public List<string> TemplateList
{
get { return _TemplateList; }
set { this.RaiseAndSetIfChanged(ref _TemplateList, value); }
}
private int _CurrentTemplateIndex;
public int CurrentTemplateIndex
{
get { return _CurrentTemplateIndex; }
set
{
this.RaiseAndSetIfChanged(ref _CurrentTemplateIndex, value);
ReadTemplateLayerInfo();
}
}
private List<BGVCTEntity> _LayerSource;
public List<BGVCTEntity> LayerSource
{
get { return _LayerSource; }
set { this.RaiseAndSetIfChanged(ref _LayerSource, value); }
}
private List<BGVCTEntity> _IncrementalUpdatingSource;
public List<BGVCTEntity> IncrementalUpdatingSource
{
get { return _IncrementalUpdatingSource; }
set { this.RaiseAndSetIfChanged(ref _IncrementalUpdatingSource, value); }
}
//private Dictionary<string, string> dicFeatureCode = null;
public BGVCTEntity GXVCTEntity = null;
public BGVCTEntity GXGCVCTEntity = null;
private Visibility _SelectTemplate;
public Visibility SelectTemplate
{
get { return _SelectTemplate; }
set { this.RaiseAndSetIfChanged(ref _SelectTemplate, value); }
}
private Visibility _IsResultsExport;
public Visibility IsResultsExport
{
get { return _IsResultsExport; }
set { this.RaiseAndSetIfChanged(ref _IsResultsExport, value); }
}
private string sBGCGDir = string.Empty;
public ExportBGViewModel()
{
HasPDT = false;
IsBL = false;
PDT_Visibility = System.Windows.Visibility.Collapsed;
BL_Visibility = System.Windows.Visibility.Collapsed;
IsResultsExport = Visibility.Collapsed;
SelectTemplate = Visibility.Visible;
NCData_Visibility = System.Windows.Visibility.Visible;
#region 创建成果导出路径
OutDir = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).BGResultPath;
sBGCGDir = Path.Combine((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ProjDir, "变更成果模板");
#endregion
Items = GetResultsCatalogtemp(true);
Init();
#region 一键成果导出
ExportClick = ReactiveCommand.Create();
ExportClick.Subscribe(x =>
{
});
#endregion
#region 选择变更成果数据模板
SelectedTemplateClick = ReactiveCommand.Create();
SelectedTemplateClick.Subscribe(x =>
{
Create_Click();
IsResultsExport = Visibility.Visible;
SelectTemplate = Visibility.Collapsed;
});
#endregion
}
#region MyRegion
private void Create_Click()
{
IWorkspaceAPI s_WsAPI = null;
try
{
string currentGDBPath = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ZLDatabase;
s_WsAPI = new WorkspaceAPI(currentGDBPath, WorkspaceTypeEnum.GDBFile);
List<BGVCTEntity> TableMappingList = new List<BGVCTEntity>();
//string sDir = System.IO.Path.Combine(SysAppPath.GetCurrentAppPath(), "工作空间", "模板", "变更成果模板", "成果导出");
string sDir = System.IO.Path.Combine(sBGCGDir, "成果导出");
List<BGVCTEntity> list = GXVCTEntity.SubEntities.FindAll(x => x.IsChecked == true && (x.FeatureClassName.EndsWith("GX") || x.FeatureClassName == "GXZJ"));
list.AddRange((LayerSource as List<BGVCTEntity>)[0].SubEntities.FindAll(x => x.IsChecked == true));
if (list.Count > 0)
{
string sPath = System.IO.Path.Combine(sDir, "VCTTemplate3ForBG.VCT");
FileStream fs = new FileStream(sPath, FileMode.Create);
StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("GB18030"));
GenerateVCTHead(sw);
foreach (BGVCTEntity item in list)
{
TableMappingList.Add(item);
}
GenerateVCTFeatureCode(sw, list, s_WsAPI);
sw.WriteLine("TableStructureBegin");
foreach (BGVCTEntity entity in list)
{
IFeatureClassAPI fcSourceAPI = s_WsAPI.OpenFeatureClass(entity.FeatureClassName);
IFeatureClass fcSource = fcSourceAPI.FeatureClass;
IFields fields = fcSource.Fields;
int FieldCount = 0;
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.Field[i];
if (field.Name == "OBJECTID" || field.Name == "JCTBBSM" || field.Name == "Element" || field.Name == "SHAPE" || field.Name == "SHAPE_Length" || field.Name == "SHAPE_Area")
{
continue;
}
if (entity.FeatureClassName == "DLTBGX" && (field.Name == "XZQTZLX" || field.Name == "ONLYZLBG"))
{
continue;
}
FieldCount++;
}
sw.WriteLine(string.Format("{0},{1}", entity.FeatureClassName, FieldCount));
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.Field[i];
if (field.Name == "OBJECTID" || field.Name == "JCTBBSM" || field.Name == "Element" || field.Name == "SHAPE" || field.Name == "SHAPE_Length" || field.Name == "SHAPE_Area")
{
continue;
}
if (entity.FeatureClassName == "DLTBGX" && (field.Name == "XZQTZLX" || field.Name == "ONLYZLBG"))
{
continue;
}
string strFieldType = GetVCTFieldType(field);
if (strFieldType == "Float")
{
sw.WriteLine(string.Format("{0},{1},{2},2", field.Name, strFieldType, field.Length <= 255 ? field.Length : 255));
}
else
{
sw.WriteLine(string.Format("{0},{1},{2}", field.Name, strFieldType, field.Length <= 255 ? field.Length : 255));
}
}
sw.WriteLine("0");
}
sw.Write("TableStructureEnd");
sw.Close();
sw.Dispose();
fs.Close();
fs.Dispose();
}
#region 一键成果导出的VCT中不包含PDTGX图层及其相关表结构信息 2020-7-29 沈超
list = GXVCTEntity.SubEntities.FindAll(x => x.IsChecked == true && x.FeatureClassName == "PDTGX");
if (list.Count > 0)//创建没有PDTGCX的VCT
{
list = GXVCTEntity.SubEntities.FindAll(x => x.IsChecked == true && (x.FeatureClassName.EndsWith("GX") || x.FeatureClassName == "GXZJ") && x.FeatureClassName != "PDTGX");
if (list.Count > 0)
{
string sPath = System.IO.Path.Combine(sDir, "VCTTemplate3ForBG_WithOutPDXGX.VCT");
FileStream fs = new FileStream(sPath, FileMode.Create);
StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("GB18030"));
GenerateVCTHead(sw);
GenerateVCTFeatureCode(sw, list, s_WsAPI);
sw.WriteLine("TableStructureBegin");
foreach (BGVCTEntity entity in list)
{
IFeatureClassAPI fcSourceAPI = s_WsAPI.OpenFeatureClass(entity.FeatureClassName);
IFeatureClass fcSource = fcSourceAPI.FeatureClass;
IFields fields = fcSource.Fields;
int FieldCount = 0;
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.Field[i];
if (entity.FeatureClassName == "DLTBGX" && field.Name.ToUpper() == "XHMARK")
{
continue;
}
else
{
if (field.Name == "OBJECTID" || field.Name == "JCTBBSM" || field.Name == "Element" ||
field.Name.ToUpper() == "SHAPE" || field.Name.ToUpper() == "SHAPE_LENGTH" || field.Name.ToUpper() == "SHAPE_AREA" ||
field.Name == "BGTBOID")
{
continue;
}
FieldCount++;
}
}
sw.WriteLine(string.Format("{0},{1}", entity.FeatureClassName, FieldCount));
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.Field[i];
if (entity.FeatureClassName == "DLTBGX" && field.Name.ToUpper() == "XHMARK")
{
continue;
}
else
{
if (field.Name == "OBJECTID" || field.Name == "JCTBBSM" || field.Name == "Element" ||
field.Name.ToUpper() == "SHAPE" || field.Name.ToUpper() == "SHAPE_LENGTH" || field.Name.ToUpper() == "SHAPE_AREA" ||
field.Name == "BGTBOID")
{
continue;
}
string strFieldType = GetVCTFieldType(field);
if (strFieldType == "Float")
{
sw.WriteLine(string.Format("{0},{1},{2},2", field.Name, strFieldType, field.Length <= 255 ? field.Length : 255));
}
else
{
sw.WriteLine(string.Format("{0},{1},{2}", field.Name, strFieldType, field.Length <= 255 ? field.Length : 255));
}
}
}
sw.WriteLine("0");
}
sw.Write("TableStructureEnd");
sw.Close();
sw.Dispose();
fs.Close();
fs.Dispose();
}
}
#endregion
list = GXVCTEntity.SubEntities.FindAll(x => x.IsChecked == true && x.FeatureClassName.EndsWith("GXGC"));
if (list.Count > 0)
{
string sPath = System.IO.Path.Combine(sDir, "VCTTemplate3ForBG2.VCT");
FileStream fs = new FileStream(sPath, FileMode.Create);
StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("GB18030"));
GenerateVCTHead(sw);
foreach (BGVCTEntity item in list)
{
TableMappingList.Add(item);
}
GenerateVCTFeatureCode(sw, list, s_WsAPI);
sw.WriteLine("TableStructureBegin");
foreach (BGVCTEntity entity in list)
{
IFeatureClassAPI fcSourceAPI = s_WsAPI.OpenFeatureClass(entity.FeatureClassName);
IFeatureClass fcSource = fcSourceAPI.FeatureClass;
IFields fields = fcSource.Fields;
int FieldCount = 0;
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.Field[i];
if (field.Name == "OBJECTID" || field.Name == "JCTBBSM" || field.Name == "SHAPE" || field.Name == "SHAPE_Length" || field.Name == "SHAPE_Area")
{
continue;
}
if (entity.FeatureClassName == "DLTBGXGC" && (field.Name == "JCZT" || field.Name == "JCJG" || field.Name == "ONLYZLBG" || field.Name == "XMMC" || field.Name == "XMBH" || field.Name == "DKMC"))
{
continue;
}
FieldCount++;
}
sw.WriteLine(string.Format("{0},{1}", entity.FeatureClassName, FieldCount));
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.Field[i];
if (field.Name == "OBJECTID" || field.Name == "JCTBBSM" || field.Name == "SHAPE" || field.Name == "SHAPE_Length" || field.Name == "SHAPE_Area")
{
continue;
}
if (entity.FeatureClassName == "DLTBGXGC" && (field.Name == "JCZT" || field.Name == "JCJG" || field.Name == "ONLYZLBG" || field.Name == "XMMC" || field.Name == "XMBH" || field.Name == "DKMC"))
{
continue;
}
string strFieldType = GetVCTFieldType(field);
if (strFieldType == "Float")
{
sw.WriteLine(string.Format("{0},{1},{2},2", field.Name, strFieldType, field.Length <= 255 ? field.Length : 255));
}
else
{
sw.WriteLine(string.Format("{0},{1},{2}", field.Name, strFieldType, field.Length <= 255 ? field.Length : 255));
}
}
sw.WriteLine("0");
}
sw.Write("TableStructureEnd");
sw.Close();
sw.Dispose();
fs.Close();
fs.Dispose();
}
string TMConfigPath = System.IO.Path.Combine(SysAppPath.GetCurrentAppPath(), "Configs", "BGCheckTableMappingConfig.xml");
CreateBGCheckTableMappingConfig(TMConfigPath, TableMappingList);
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError(ex.Message);
}
finally
{
if (s_WsAPI != null)
{
s_WsAPI.CloseWorkspace();
}
}
}
public void GenerateVCTHead(StreamWriter sw)
{
sw.WriteLine("HeadBegin");
sw.WriteLine("DataMark: LANDUSE-VCT");
sw.WriteLine("Version: 3.0");
sw.WriteLine("CoordinateSystemType:P");
sw.WriteLine("Dim:2");
sw.WriteLine("XAxisDirection:E");
sw.WriteLine("YAxisDirection:N");
sw.WriteLine("XYUnit:M");
sw.WriteLine("ZUnit:M");
sw.WriteLine("Spheroid:CGCS2000,6378137.0,298.257222101");
sw.WriteLine("PrimeMeridian:Greenwich");
sw.WriteLine("Projection:高斯-克吕格投影");
sw.WriteLine("Parameters:0,0,0,0,0,0");
sw.WriteLine("VerticalDatum:1985国家高程基准");
sw.WriteLine("TemporalReferenceSystem:北京时间");
sw.WriteLine("ExtentMin:0,0");
sw.WriteLine("ExtentMax:0,0");
sw.WriteLine("MapScale:5000");
sw.WriteLine("Offset:0,0");
sw.WriteLine("Date:201801");
sw.WriteLine("Separator:,");
sw.WriteLine("HeadEnd");
sw.WriteLine();
}
public void GenerateVCTFeatureCode(StreamWriter sw, List<BGVCTEntity> list, IWorkspaceAPI s_WsAPI)
{
sw.WriteLine("FeatureCodeBegin");
foreach (BGVCTEntity item in list)
{
string FCode = "";
if (dicFeatureCode.ContainsKey(item.FeatureClassName))
{
FCode = dicFeatureCode[item.FeatureClassName];
}
string strGeoType = GetVCTGeometryType(s_WsAPI.OpenFeatureClass(item.FeatureClassName).FeatureClass);
sw.WriteLine(string.Format("{0},{1},{2},{3}", FCode, item.Name, strGeoType, item.FeatureClassName));
}
sw.WriteLine("FeatureCodeEnd");
sw.WriteLine();
}
private string GetVCTGeometryType(IFeatureClass featureClass)
{
string strGType = "";
switch (featureClass.ShapeType)
{
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryNull:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint:
strGType = "Point";
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryLine:
strGType = "Line";
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryCircularArc:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryEllipticArc:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryBezier3Curve:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPath:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryRing:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
strGType = "Polygon";
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryEnvelope:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryAny:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryBag:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultiPatch:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryTriangleStrip:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryTriangleFan:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryRay:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometrySphere:
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryTriangles:
break;
default:
break;
}
return strGType;
}
public void CreateBGCheckTableMappingConfig(string configFilePath, List<BGVCTEntity> list)
{
IWorkspaceAPI s_WsAPI = null;
try
{
//创建XmlDocument对象
XmlDocument xmlDoc = new XmlDocument();
//XML的声明<?xml version="1.0" encoding="UTF-8"?>
XmlDeclaration xmlSM = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
//追加xmldecl位置
xmlDoc.AppendChild(xmlSM);
//创建CheckTableMapping节点
XmlElement MainElement = xmlDoc.CreateElement("", "CheckTableMapping", "");
//追加CheckTableMapping的根节点位置
xmlDoc.AppendChild(MainElement);
string currentGDBPath = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ZLDatabase;
s_WsAPI = new WorkspaceAPI(currentGDBPath, WorkspaceTypeEnum.GDBFile);
foreach (BGVCTEntity entity in list)
{
IFeatureClassAPI fcSourceAPI = s_WsAPI.OpenFeatureClass(entity.FeatureClassName);
IFeatureClass fcSource = fcSourceAPI.FeatureClass;
FeatureClass fc = fcSource as FeatureClass;
XmlElement TableElement = xmlDoc.CreateElement("", "Table", "");
TableElement.SetAttribute("TableName", fc.Name);
TableElement.SetAttribute("Name", fcSource.AliasName);
TableElement.SetAttribute("Type", GetShapeTypeName(fcSource));
TableElement.SetAttribute("IsNecessary", "True");
TableElement.SetAttribute("YSDM", GetYSDMByLayerName(fc.Name));
IFields fields = fcSource.Fields;
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.Field[i];
if (field.Name == "OBJECTID" || field.Name == "JCTBBSM" || field.Name == "SHAPE" || field.Name == "SHAPE_Length" || field.Name == "SHAPE_Area")
{
continue;
}
XmlElement FieldElement = xmlDoc.CreateElement("", "Column", "");
FieldElement.SetAttribute("Name", field.Name);
FieldElement.SetAttribute("AliasName", field.AliasName);
FieldElement.SetAttribute("AllowDBNull", field.IsNullable ? "True" : "False");
FieldElement.SetAttribute("DataType", GetFieldTypeName(field.Type));
if (field.Type == esriFieldType.esriFieldTypeString)
{
FieldElement.SetAttribute("MaxLength", field.Length.ToString());
}
if (field.Type == esriFieldType.esriFieldTypeSingle || field.Type == esriFieldType.esriFieldTypeDouble)
{
FieldElement.SetAttribute("Precision", field.Precision.ToString());
}
TableElement.AppendChild(FieldElement);
}
MainElement.AppendChild(TableElement);
}
xmlDoc.Save(configFilePath);
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
finally
{
if (s_WsAPI != null)
{
s_WsAPI.CloseWorkspace();
}
}
}
public string GetShapeTypeName(IFeatureClass fc)
{
string strType = "";
switch (fc.ShapeType)
{
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
strType = "点";
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryLine:
strType = "线";
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
strType = "面";
break;
default:
if (fc.FeatureType == esriFeatureType.esriFTAnnotation)
{
strType = "注记";
}
else
{
strType = "其他";
}
break;
}
return strType;
}
private string GetYSDMByLayerName(string LayerName)
{
if (LayerName.EndsWith("GX"))
{
LayerName = LayerName.Replace("GX", "");
}
else if (LayerName.EndsWith("GXGC"))
{
LayerName = LayerName.Replace("GXGC", "");
}
KeyValuePair<string, string> kvp = YSDM.FirstOrDefault(x => x.Value == LayerName);
return kvp.Key;
}
private Dictionary<string, string> ysdm = null;
public Dictionary<string, string> YSDM
{
get
{
if (ysdm == null)
{
ysdm = new Dictionary<string, string>();
ysdm.Add("1000110000", "CLKZD");
ysdm.Add("1000110408", "JZKZD");
ysdm.Add("1000119000", "CLKZDZJ");
ysdm.Add("1000600100", "XZQ");
ysdm.Add("1000600200", "XZQJX");
ysdm.Add("1000609000", "XZQZJ");
ysdm.Add("1000600400", "CJDCQ");
ysdm.Add("1000600500", "CJDCQJX");
ysdm.Add("1000608000", "CJDCQZJ");
ysdm.Add("1000710000", "DGX");
ysdm.Add("1000720000", "GCZJD");
ysdm.Add("1000780000", "PDT");
ysdm.Add("2001010100", "DLTB");
ysdm.Add("2001010200", "DLTBZJ");
ysdm.Add("2006010100", "TDQSQ");
ysdm.Add("2006010200", "TDQSQZJ");
ysdm.Add("2006020100", "TDQSQJX");
ysdm.Add("2006020200", "TDQSQJXZJ");
ysdm.Add("2005010300", "YJJBNTTB");
ysdm.Add("2005010900", "YJJBNTTBZJ");
ysdm.Add("2099010100", "LSYD");
ysdm.Add("2099010200", "LSYDZJ");
ysdm.Add("2099020100", "PZWJSTD");
ysdm.Add("2099020200", "PZWJSTBZJ");
ysdm.Add("2099030100", "CZCDYD");
ysdm.Add("2099030200", "CZCDYDZJ");
ysdm.Add("2099040100", "GDDB");
ysdm.Add("2099040200", "GDDBZJ");
ysdm.Add("2099050100", "ZYXMYD");
ysdm.Add("2099050200", "ZYXMYDZJ");
ysdm.Add("2099060100", "KFYQ");
ysdm.Add("2099060200", "KFYQZJ");
ysdm.Add("3001010000", "GJGY");
ysdm.Add("3001020000", "ZRBHQ");
ysdm.Add("3001030000", "SLGY");
ysdm.Add("3001040000", "FJMSQ");
ysdm.Add("3001050000", "DZGY");
ysdm.Add("3001060000", "ZRYCBHQ");
ysdm.Add("3001070000", "SDGY");
ysdm.Add("3001080000", "YYSSYD");
ysdm.Add("3001090000", "SCZZBHQ");
ysdm.Add("3001990000", "QTJZKFQ");
ysdm.Add("3001200000", "ZRBHQZJ");
ysdm.Add("3002010000", "CSKFBJ");
ysdm.Add("3002020000", "CSKFBJZJ");
ysdm.Add("2099110100", "WJMHD");
ysdm.Add("2099100100", "LMFW");
}
return ysdm;
}
}
private string GetFieldTypeName(esriFieldType fieldType)
{
string strTypeName = "";
switch (fieldType)
{
case esriFieldType.esriFieldTypeSmallInteger:
strTypeName = "Int";
break;
case esriFieldType.esriFieldTypeInteger:
strTypeName = "Int";
break;
case esriFieldType.esriFieldTypeSingle:
strTypeName = "Float";
break;
case esriFieldType.esriFieldTypeDouble:
strTypeName = "Double";
break;
case esriFieldType.esriFieldTypeString:
strTypeName = "String";
break;
case esriFieldType.esriFieldTypeDate:
strTypeName = "Date";
break;
case esriFieldType.esriFieldTypeOID:
strTypeName = "Int";
break;
case esriFieldType.esriFieldTypeGeometry:
break;
case esriFieldType.esriFieldTypeBlob:
break;
case esriFieldType.esriFieldTypeRaster:
break;
case esriFieldType.esriFieldTypeGUID:
break;
case esriFieldType.esriFieldTypeGlobalID:
break;
case esriFieldType.esriFieldTypeXML:
break;
default:
break;
}
return strTypeName;
}
#endregion
private static void CopyDirectInfo(string sourceDir, string toDir)
{
if (!Directory.Exists(sourceDir))
{
throw new ApplicationException("未找到文件:" + sourceDir);
}
if (!Directory.Exists(toDir))
{
Directory.CreateDirectory(toDir);
}
DirectoryInfo directInfo = new DirectoryInfo(sourceDir);
FileInfo[] filesInfos = directInfo.GetFiles();
foreach (FileInfo fileinfo in filesInfos)
{
string fileName = fileinfo.Name;
File.Copy(fileinfo.FullName, toDir + @"/" + fileName, true);
}
}
private void Main_Closed(object sender, EventArgs e)
{
string[] temps = System.IO.Directory.GetDirectories(Path.Combine(sBGCGDir));
// System.IO.Directory.GetDirectories(Path.Combine(SysAppPath.GetCurrentAppPath(), "工作空间", "模板", "变更成果模板"));
List<string> tempList = TemplateList;
foreach (var item in temps)
{
DirectoryInfo f = new DirectoryInfo(item);
if (!tempList.Contains(f.Name))
tempList.Add(f.Name);
}
TemplateList = tempList;
}
private void Init()
{
try
{
InitFeatureCodeDic();
string templatePath = sBGCGDir;// Path.Combine(SysAppPath.GetCurrentAppPath(), "工作空间", "模板", "变更成果模板");
if (!Directory.Exists(templatePath))
Directory.CreateDirectory(templatePath);
//string[] temps = System.IO.Directory.GetDirectories(Path.Combine(SysAppPath.GetCurrentAppPath(), "工作空间", "模板", "变更成果模板"));
string[] temps = System.IO.Directory.GetDirectories(Path.Combine(sBGCGDir));
TemplateList = new List<string>();
foreach (var item in temps)
{
DirectoryInfo f = new DirectoryInfo(item);
TemplateList.Add(f.Name);
}
//if (TemplateList.Count > 0)
//{
// CurrentTemplateIndex = 1;
//}
ReadTemplateLayerInfo();
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError(ex.Message);
}
}
private void ReadTemplateLayerInfo()
{
IWorkspaceAPI s_WsAPI = null;
try
{
string templatePath = sBGCGDir;// Path.Combine(SysAppPath.GetCurrentAppPath(), "工作空间", "模板", "变更成果模板");
string vctPath_GX = Path.Combine(templatePath, "模板", "VCTTemplate3ForBG.VCT");//默认模板
string vctPath_GXGC = Path.Combine(templatePath, "模板", "VCTTemplate3ForBG2.VCT");//默认模板
string vctPath_GX0 = Path.Combine(templatePath, "成果导出", "VCTTemplate3ForBG.VCT");
string vctPath_GXGC0 = Path.Combine(templatePath, "成果导出", "VCTTemplate3ForBG2.VCT");
Dictionary<string, string> layers = GetLayersForVCT(vctPath_GX, vctPath_GXGC);//默认模板
Dictionary<string, string> layers0 = GetLayersForVCT(vctPath_GX0, vctPath_GXGC0);
GXVCTEntity = new BGVCTEntity() { Name = "增量更新" };
GXGCVCTEntity = new BGVCTEntity() { Name = "整层更新" };
string currentGDBPath = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ZLDatabase;
s_WsAPI = new WorkspaceAPI(currentGDBPath, WorkspaceTypeEnum.GDBFile);
foreach (KeyValuePair<string, string> kvp in layers)
{
if ("DLTBGX,DLTBGXGC,XZQGX,XZQGXGC,CJDCQGX,CJDCQGXGC,XZQJXGX,CJDCQJXGX,CZCDYDGX,CZCDYDGXGC".Contains(kvp.Value))
{
IFeatureClassAPI fcAPI = s_WsAPI.OpenFeatureClass(kvp.Value);
if (fcAPI != null)
{
IFeatureClass fc = fcAPI.FeatureClass;
GXVCTEntity.SubEntities.Add(new BGVCTEntity() { Name = fc.AliasName, FeatureClassName = kvp.Value, ParentEntity = GXVCTEntity, IsChecked = true });
}
continue;
}
else
{
IFeatureClassAPI fcAPI = s_WsAPI.OpenFeatureClass(kvp.Value);
if (fcAPI != null)
{
IFeatureClass fc = fcAPI.FeatureClass;
if (layers0.ContainsValue(kvp.Value))
{
GXGCVCTEntity.SubEntities.Add(new BGVCTEntity() { Name = fc.AliasName, FeatureClassName = kvp.Value, ParentEntity = GXGCVCTEntity, IsChecked = true });
}
else
{
GXGCVCTEntity.SubEntities.Add(new BGVCTEntity() { Name = fc.AliasName, FeatureClassName = kvp.Value, ParentEntity = GXGCVCTEntity, IsChecked = false });
}
}
}
}
IncrementalUpdatingSource = new List<BGVCTEntity>();
IncrementalUpdatingSource.Add(GXVCTEntity);
LayerSource = new List<BGVCTEntity>();
LayerSource.Add(GXGCVCTEntity);
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError(ex.Message);
}
finally
{
if (s_WsAPI != null)
{
s_WsAPI.CloseWorkspace();
}
}
}
private Dictionary<string, string> dicFeatureCode = null;
private void InitFeatureCodeDic()
{
dicFeatureCode = new Dictionary<string, string>();
dicFeatureCode.Add("CCWJQGX", "2099090100");
dicFeatureCode.Add("GFBQGX", "2099070100");
//dicFeatureCode.Add("LSYDGX", "2099010100");
dicFeatureCode.Add("GCHZZGX", "2099120100");
dicFeatureCode.Add("TTQGX", "2099080100");
dicFeatureCode.Add("DLTBGX", "2001010100");
dicFeatureCode.Add("CLKZDGX", "1000110000");
dicFeatureCode.Add("CZKFBJGX", "3002010000");
dicFeatureCode.Add("CZCDYDGX", "2099030100");
dicFeatureCode.Add("CZCDYDGXGC", "2099030100");
dicFeatureCode.Add("DGXGX", "1000710000");
dicFeatureCode.Add("DZGYGX", "3001050100");
dicFeatureCode.Add("FJMSQGX", "3001040100");
dicFeatureCode.Add("GCZJDGX", "1000720000");
dicFeatureCode.Add("GDDBGX", "2099040100");
dicFeatureCode.Add("GJGYGX", "3001010100");
dicFeatureCode.Add("JZKZDGX", "1000110408");
dicFeatureCode.Add("KFYQGX", "2099060100");
dicFeatureCode.Add("LMFWGX", "2099100100");
dicFeatureCode.Add("PDTGX", "1000780000");
dicFeatureCode.Add("PZWJSTDGX", "2099020100");
dicFeatureCode.Add("QTJZKFQGX", "3001990100");
dicFeatureCode.Add("SCZZBHQGX", "3001090100");
dicFeatureCode.Add("SDGYGX", "3001070100");
dicFeatureCode.Add("SLGYGX", "3001030100");
dicFeatureCode.Add("STBHHXGX", "3003010000");
dicFeatureCode.Add("WJMHDGX", "2099110100");
dicFeatureCode.Add("YYSSYDGX", "3001080100");
dicFeatureCode.Add("ZRBHQGX", "3001020100");
dicFeatureCode.Add("ZRYCBHQGX", "3001060100");
dicFeatureCode.Add("ZYXMYDGX", "2099050100");
dicFeatureCode.Add("XZQGX", "1000600100");
dicFeatureCode.Add("XZQJXGX", "1000600200");
dicFeatureCode.Add("CJDCQGX", "1000600400");
dicFeatureCode.Add("CJDCQJXGX", "1000600500");
dicFeatureCode.Add("YJJBNTTBGX", "2005010300");
dicFeatureCode.Add("DLTBGXGC", "2001010100");
dicFeatureCode.Add("XZQGXGC", "1000600100");
dicFeatureCode.Add("CJDCQGXGC", "1000600400");
}
private Dictionary<string, string> GetLayersForVCT(string pVCTPath, string pVCTPath2)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
StreamReader sr = new StreamReader(pVCTPath, Encoding.GetEncoding("GB18030"));
string line = null;
bool BeginLoad = false;
while ((line = sr.ReadLine()) != null)
{
if (line == "FeatureCodeBegin")
{
BeginLoad = true;
}
if (BeginLoad && line != "FeatureCodeBegin")
{
string[] strs = line.Split(',');
if (strs.Length == 4 && !dic.Keys.Contains(strs[1]))
{
dic.Add(strs[1], strs[3]);
}
}
if (line == "FeatureCodeEnd")
{
BeginLoad = false;
break;
}
}
sr.Close();
sr.Dispose();
StreamReader sr2 = new StreamReader(pVCTPath2, Encoding.GetEncoding("GB18030"));
line = null;
BeginLoad = false;
while ((line = sr2.ReadLine()) != null)
{
if (line == "FeatureCodeBegin")
{
BeginLoad = true;
}
if (BeginLoad && line != "FeatureCodeBegin")
{
string[] strs = line.Split(',');
if (strs.Length == 4 && !dic.Keys.Contains(strs[1]))
{
dic.Add(strs[1], strs[3]);
}
}
if (line == "FeatureCodeEnd")
{
BeginLoad = false;
break;
}
}
sr2.Close();
sr2.Dispose();
return dic;
}
public void CreateCatalogDir(List<ResultsCatalog> pCatalog)
{
try
{
if (pCatalog == null) return;
List<DataDicTionary> qsDic = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM);
string templatePath = sBGCGDir;// Path.Combine(SysAppPath.GetCurrentAppPath(), "工作空间", "模板", "变更成果模板");
string gxVCTPath = Path.Combine(templatePath, "成果导出", "VCTTemplate3ForBG.VCT");
string gxgcVCTPath = Path.Combine(templatePath, "成果导出", "VCTTemplate3ForBG2.VCT");
foreach (ResultsCatalog item in pCatalog)
{
item.Path = item.Path.Replace("县行政区划代码6位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE).Replace("年代代码4位", BGYear.ToString()).Replace("比例尺代码1位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ScaleCode);
item.Name = item.Name.Replace("县行政区划代码6位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE).Replace("年代代码4位", BGYear.ToString()).Replace("比例尺代码1位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ScaleCode);
if (item.IsChecked == false) continue;
string sPath = string.Empty;
switch (item.Type)
{
case "Directory":
this.UpdateMsg(string.Format("正在创建目录:{0}", item.Name));
sPath = System.IO.Path.Combine(OutDir, item.Path);
if (!System.IO.Directory.Exists(sPath))
System.IO.Directory.CreateDirectory(sPath);
if (item.SubCatalog != null)
CreateCatalogDir(item.SubCatalog);
break;
case "MetadataFile":
sPath = System.IO.Path.Combine(OutDir, item.Path);
this.UpdateMsg(string.Format("正在生成元数据【{0}】", item.Name));
ExportMetadata exportMetadata = new ExportMetadata();
exportMetadata.IsBG = true;
exportMetadata.OutPath = System.IO.Path.GetDirectoryName(sPath);
exportMetadata.Scale = new ScaleCodeTable() { Scale = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).Scale, ScaleCode = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ScaleCode };
exportMetadata.Export(BGYear.ToString());
break;
case "ExtractMDBFile":
try
{
sPath = System.IO.Path.Combine(OutDir, item.Path);
this.UpdateMsg(string.Format("正在导出【{0}】", item.Name));
ExportBGMDB exportBGMDB = new ExportBGMDB(gxVCTPath, gxgcVCTPath);
exportBGMDB.Export(sPath);
}
catch (Exception ex)
{
throw ex;
}
break;
case "ExtractGDBFile":
try
{
sPath = System.IO.Path.Combine(OutDir, item.Path);
this.UpdateMsg(string.Format("正在导出【{0}】", item.Name));
ExportBGGDB exportBGGDB = new ExportBGGDB(gxVCTPath, gxgcVCTPath);
exportBGGDB.Export(sPath);
}
catch (Exception ex)
{
throw ex;
}
break;
case "ExtractGDB":
try
{
sPath = System.IO.Path.Combine(OutDir, item.Path);
this.UpdateMsg(string.Format("正在导出【{0}】", item.Name));
ExportBGMDB exportBGMDB = new ExportBGMDB(gxVCTPath, gxgcVCTPath);
exportBGMDB.ExportGDB(sPath);
}
catch (Exception ex)
{
throw ex;
}
break;
case "VCTFile":
this.UpdateMsg(string.Format("正在导出【{0}】", item.Name));
sPath = System.IO.Path.Combine(OutDir, item.Path);
string TempMDBPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), string.Format("temp_vct_{0}.mdb", Guid.NewGuid().ToString().Replace("-", "")));
if (System.IO.File.Exists(TempMDBPath))
{
File.Delete(TempMDBPath);
}
ExportBGMDB exportBGMDB2 = new ExportBGMDB(gxVCTPath, gxgcVCTPath);
string vctpath = null;
if (System.IO.Path.GetFileNameWithoutExtension(sPath).EndsWith("GX"))
{
exportBGMDB2.LayerNameFilter = "GX";
vctpath = Path.Combine(templatePath, TemplateList[CurrentTemplateIndex], "VCTTemplate3ForBG.VCT");
}
else if (System.IO.Path.GetFileNameWithoutExtension(sPath).EndsWith("GXGC"))
{
exportBGMDB2.LayerNameFilter = "GXGC";
vctpath = Path.Combine(templatePath, TemplateList[CurrentTemplateIndex], "VCTTemplate3ForBG2.VCT");
}
exportBGMDB2.Export(TempMDBPath);
System.Threading.Thread.Sleep(2000);
LogAPI.Debug("VCTPath:" + vctpath);
var tmpname = item.Name.Substring(0, item.Name.Length - 4);
CreateVCT(tmpname, vctpath, TempMDBPath, (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, float.Parse((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).FDD), (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ScaleCode, System.IO.Path.GetDirectoryName(sPath).TrimEnd('\\'));
List<string> filenames = new List<string>();
string vctfolderpath = System.IO.Path.GetDirectoryName(sPath);
string[] files = System.IO.Directory.GetFiles(vctfolderpath.TrimEnd());//得到文件
foreach (string file in files)//循环文件
{
if (System.IO.Path.GetExtension(file).ToUpper() == ".VCT")
{
filenames.Add(System.IO.Path.GetFileNameWithoutExtension(file));
}
}
foreach (var name in filenames)
{
tmpname = item.Name.Substring(0, item.Name.Length - 4);
if (name.EndsWith("000000"))
{
if (System.IO.Path.GetFileNameWithoutExtension(sPath).EndsWith("GX"))
{
System.IO.File.Move(vctfolderpath + @"\" + name + ".VCT", vctfolderpath + @"\" + tmpname + ".VCT");
}
else if (System.IO.Path.GetFileNameWithoutExtension(sPath).EndsWith("GXGC"))
{
System.IO.File.Move(vctfolderpath + @"\" + name + ".VCT", vctfolderpath + @"\" + tmpname + ".VCT");
}
}
}
//string[] dirs = System.IO.Directory.GetDirectories(vctfolderpath);//得到目录
//foreach (var name in dirs)
//{
// var tmpname = item.Name.Substring(0, item.Name.Length - 4);
// if (name.EndsWith("000000_idx"))
// {
// if (System.IO.Path.GetFileNameWithoutExtension(sPath).EndsWith("GX"))
// {
// System.IO.Directory.Move(name, vctfolderpath + @"\" + tmpname + "_idx");
// }
// else if (System.IO.Path.GetFileNameWithoutExtension(sPath).EndsWith("GXGC"))
// {
// System.IO.Directory.Move(name, vctfolderpath + @"\" + tmpname + "_idx");
// }
// }
//}
break;
case "ReportExcel":
if (string.IsNullOrWhiteSpace(NCDataDir))
{
continue;
}
this.UpdateMsg(string.Format("正在导出【{0}】", item.Name));
sPath = System.IO.Path.Combine(OutDir, item.Path);
try
{
string dbPath = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite";
IRDBHelper dbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
string saveCurrentPath = string.Format("{0}.xlsx", sPath);
ReportEntityClass reportEntityClass = new ReportEntityClass();
reportEntityClass.ReportType = (ReportTypeEnum)System.Enum.Parse(typeof(ReportTypeEnum), ((ReportTypeEnum)System.Enum.Parse(typeof(ReportTypeEnum), item.FileType)).ToString());
StatisticalReportClass reportClass = new StatisticalReportClass();
reportClass.NULLExport(saveCurrentPath, dbHelper, reportEntityClass, NCDataDir);
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
break;
case "ReportWord":
this.UpdateMsg(string.Format("正在导出【{0}】", item.Name));
sPath = System.IO.Path.Combine(OutDir, item.Path);
IStatisticExport exprotReport2 = new BGExportHelper();
exprotReport2.AreaUnit = ReportFileTypeEnum.DBGQ;
exprotReport2.OutPath = sPath;
exprotReport2.ExportWordReport((ReportTypeEnum)System.Enum.Parse(typeof(ReportTypeEnum), item.FileType));
break;
default:
break;
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
private static string CreateVCT(string idxName, string vctpath, string mdbpath, string xzqdm, float dk, string blc, string rootpath, string ffh = null)
{
string vctfilepath = string.Empty;
try
{
VCTFileConvertHelper h = new VCTFileConvertHelper();
VctVectorData vctdata = h.GetVctVectorData(vctpath, true);
vctdata.VctHead.XZQDM = xzqdm;// KGIS.Common.Utility.EnvironmentVariables.Instance.Project.;
vctdata.VctHead.DK = dk;
MapScaleEnum mapscale = (MapScaleEnum)System.Enum.Parse(typeof(MapScaleEnum), blc);
vctdata.VctHead.MapScale = ((int)mapscale).ToTrim();
MDBToVCTHelper mdbtovct = new MDBToVCTHelper();
mdbtovct.MaxBSM = 1;
mdbtovct.RootPath = rootpath + @"\";
vctfilepath = mdbtovct.MDBToVCT(mdbpath, vctdata, ffh);
LogAPI.Debug("CreateVCT:" + vctfilepath);
//CreateVCTIndex(vctfilepath, idxName);
}
catch (Exception ex)
{
LogAPI.Debug("CreateVCT异常:" + ex.Message + ex.StackTrace);
}
return vctfilepath;
}
private static void CreateVCTIndex(string vctfilepath, string idxName)
{
try
{
//创建索引
VCTIndexHelper vctidxhelper = new VCTIndexHelper();
if (vctidxhelper == null)
{
LogAPI.Debug("CreateVCTIndex异常");
}
vctidxhelper.CreateIdxByVCTFile(vctfilepath, true, idxName);
}
catch (Exception ex)
{
LogAPI.Debug("CreateVCTIndex异常:" + ex.Message + ex.StackTrace);
}
}
/// <summary>
/// 由于权属代码功能没有完善,现需要调用权属功能位置写死,龙城区为例
/// </summary>
/// <returns></returns>
public List<ResultsCatalog> GetResultsCatalogtemp(bool ischeck = false)
{
List<ResultsCatalog> result = new List<ResultsCatalog>();
try
{
XmlDocument doc = new XmlDocument();
string strPath = SysAppPath.GetCurrentAppPath();
strPath += @"Configs\ResultsCatalogCfgForBG2.xml";
doc.Load(strPath);
XmlNode nodeDataCatalog = doc.SelectSingleNode("ResultsCatalog");
if (nodeDataCatalog == null)
return result;
List<DataDicTionary> qsDic = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM);
foreach (XmlNode item in nodeDataCatalog.ChildNodes)
{
if (item.Name == "DataCatalog")
{
ResultsCatalog rootCatalog = new ResultsCatalog();
if (ischeck)
{
rootCatalog.IsChecked = true;
}
rootCatalog.Name = item.Attributes["Name"] == null ? "" : item.Attributes["Name"].Value;
rootCatalog.Path = rootCatalog.Name;
rootCatalog.Type = "Directory";
if (item.ChildNodes != null)
{
List<ResultsCatalog> tree = GetSubCatalog(item, rootCatalog, BGYear.ToString());
if (rootCatalog.SubCatalog == null)
rootCatalog.SubCatalog = new List<ResultsCatalog>();
if (ischeck)
{
foreach (var tr in tree)
{
tr.IsChecked = true;
}
}
rootCatalog.SubCatalog.AddRange(tree);
}
if (qsDic != null && !string.IsNullOrWhiteSpace((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE) && (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE != "000000")
{
DataDicTionary dic = qsDic.FirstOrDefault(f => f.CODE == (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE.Substring(0, 2));
if (dic != null)
{
rootCatalog.Path = rootCatalog.Path.Replace("*省", dic.NAME);
rootCatalog.Name = rootCatalog.Name.Replace("*省", dic.NAME);
}
dic = qsDic.FirstOrDefault(f => f.CODE == (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE.Substring(0, 4));
if (dic != null)
{
rootCatalog.Path = rootCatalog.Path.Replace("*市", dic.NAME);
rootCatalog.Name = rootCatalog.Name.Replace("*市", dic.NAME);
}
dic = qsDic.FirstOrDefault(f => f.CODE == (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE);
if (dic != null)
{
rootCatalog.Path = rootCatalog.Path.Replace("*县", dic.NAME);
rootCatalog.Name = rootCatalog.Name.Replace("*县", dic.NAME);
}
}
rootCatalog.Path = rootCatalog.Path.Replace("县行政区划代码6位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE);
rootCatalog.Name = rootCatalog.Name.Replace("县行政区划代码6位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE).Replace("年代代码4位", BGYear.ToString()).Replace("比例尺代码1位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ScaleCode);
result.Add(rootCatalog);
}
}
return result;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw;
}
}
public List<ResultsCatalog> GetResultsCatalog()
{
List<ResultsCatalog> result = new List<ResultsCatalog>();
try
{
XmlDocument doc = new XmlDocument();
string strPath = SysAppPath.GetBGResultsCataCfgPath();
doc.Load(strPath);
XmlNode nodeDataCatalog = doc.SelectSingleNode("ResultsCatalog");
if (nodeDataCatalog == null)
return result;
List<DataDicTionary> qsDic = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM);
if (qsDic == null)
{
return result;
}
foreach (XmlNode item in nodeDataCatalog.ChildNodes)
{
if (item.Name == "DataCatalog")
{
ResultsCatalog rootCatalog = new ResultsCatalog();
rootCatalog.Name = item.Attributes["Name"] == null ? "" : item.Attributes["Name"].Value;
rootCatalog.Path = rootCatalog.Name;
rootCatalog.Type = "Directory";
if (item.ChildNodes != null)
{
List<ResultsCatalog> tree = GetSubCatalog(item, rootCatalog, BGYear.ToString());
if (rootCatalog.SubCatalog == null)
rootCatalog.SubCatalog = new List<ResultsCatalog>();
rootCatalog.SubCatalog.AddRange(tree);
}
if (qsDic != null)
{
DataDicTionary dic = qsDic.FirstOrDefault(f => f.CODE.Length == 2);
if (dic != null)
{
rootCatalog.Path = rootCatalog.Path.Replace("*省", dic.NAME);
rootCatalog.Name = rootCatalog.Name.Replace("*省", dic.NAME);
}
dic = qsDic.FirstOrDefault(f => f.CODE.Length == 4);
if (dic != null)
{
rootCatalog.Path = rootCatalog.Path.Replace("*市", dic.NAME);
rootCatalog.Name = rootCatalog.Name.Replace("*市", dic.NAME);
}
dic = qsDic.FirstOrDefault(f => f.CODE == (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE);
//dic = qsDic.FindLast(f => == Env.Instance.Project.CODE);
if (dic != null)
{
rootCatalog.Path = rootCatalog.Path.Replace("*县", dic.NAME);
rootCatalog.Name = rootCatalog.Name.Replace("*县", dic.NAME);
}
}
rootCatalog.Path = rootCatalog.Path.Replace("县行政区划代码6位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE);
rootCatalog.Name = rootCatalog.Name.Replace("县行政区划代码6位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE).Replace("年代代码4位", BGYear.ToString()).Replace("比例尺代码1位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ScaleCode);
result.Add(rootCatalog);
}
}
return result;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw;
}
}
public static List<ResultsCatalog> GetSubCatalog(XmlNode pNode, ResultsCatalog pCatalog, string year)
{
List<ResultsCatalog> result = new List<ResultsCatalog>();
if (pNode != null && pNode.ChildNodes != null)
{
string sPName = pNode.Attributes["Name"] == null ? "" : pNode.Attributes["Name"].Value.ToString();
//rootCatalog.Name = rootCatalog.Name.Replace("县行政区划代码6位", Env.Instance.Project.CODE).Replace("年代代码4位", DateTime.Now.Year.ToString()).Replace("比例尺代码1位", "I");
sPName = sPName.Replace("县行政区划代码6位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE).Replace("年代代码4位", year).Replace("比例尺代码1位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ScaleCode);
List<DataDicTionary> qsDic = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM);
if (qsDic != null)
{
DataDicTionary dic = qsDic.FirstOrDefault(f => f.CODE.Length == 2);
if (dic != null)
{
sPName = sPName.Replace("*省", dic.NAME);
}
dic = qsDic.FirstOrDefault(f => f.CODE.Length == 4);
if (dic != null)
{
sPName = sPName.Replace("*市", dic.NAME);
}
dic = qsDic.FirstOrDefault(f => f.CODE == (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE);
if (dic != null)
{
sPName = sPName.Replace("*县", dic.NAME);
}
}
foreach (XmlNode item in pNode.ChildNodes)
{
ResultsCatalog catalog = new ResultsCatalog();
try
{
if (item.Attributes != null && item.Attributes["ShowFilter"] != null)
{
string[] showFilter = item.Attributes["ShowFilter"].Value.ToString().Split('_');
if (!(MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE.StartsWith(showFilter[0]) && !sPName.StartsWith(showFilter[1]))
{
continue;
}
}
catalog.Name = item.Attributes["Name"] == null ? "" : item.Attributes["Name"].Value;
catalog.Path = System.IO.Path.Combine(pCatalog.Path, catalog.Name);
catalog.CopyFile = item.Attributes["CopyFile"] == null ? "" : item.Attributes["CopyFile"].Value;
catalog.Type = item.Name;
catalog.Parent = pCatalog;
if (qsDic != null)
{
DataDicTionary dic = qsDic.FirstOrDefault(f => f.CODE.Length == 2);
if (dic != null)
{
catalog.Path = catalog.Path.Replace("*省", dic.NAME);
catalog.Name = catalog.Name.Replace("*省", dic.NAME);
}
dic = qsDic.FirstOrDefault(f => f.CODE.Length == 4);
if (dic != null)
{
catalog.Path = catalog.Path.Replace("*市", dic.NAME);
catalog.Name = catalog.Name.Replace("*市", dic.NAME);
}
dic = qsDic.FirstOrDefault(f => f.CODE == (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE);
if (dic != null)
{
catalog.Path = catalog.Path.Replace("*县", dic.NAME);
catalog.Name = catalog.Name.Replace("*县", dic.NAME);
}
}
catalog.Path = catalog.Path.Replace("县行政区划代码6位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE);
catalog.Name = catalog.Name.Replace("县行政区划代码6位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE).Replace("年代代码4位", year).Replace("比例尺代码1位", (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ScaleCode);
result.Add(catalog);
}
catch (Exception ex)
{ }
if (item.ChildNodes != null)
{
if ("ReportExcel,ReportWord".Contains(item.Name))
{
ReadAttribute(item, catalog);
}
else
{
catalog.SubCatalog = GetSubCatalog(item, catalog, year);
}
}
}
}
return result;
}
private static void ReadAttribute(XmlNode pNode, ResultsCatalog pCatalog)
{
if (pNode != null && pNode.ChildNodes != null)
{
foreach (XmlNode item in pNode.ChildNodes)
{
switch (item.Name)
{
case "ReportType":
pCatalog.FileType = item.InnerText;
break;
case "TempalateFileName":
pCatalog.FileTempalate = item.InnerText;
break;
default:
break;
}
}
}
}
private void CreateVCTContent()
{
IWorkspaceAPI s_WsAPI = null;
try
{
List<string> fcNameList = new List<string>() { "XZQGX", "XZQJXGX", "CJDCQGX", "CJDCQJXGX", "GXZJ", "XZQGXGC", "CJDCQGXGC" };
string currentGDBPath = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath();
s_WsAPI = new WorkspaceAPI(currentGDBPath, WorkspaceTypeEnum.GDBFile);
Dictionary<string, string> s_FcList = s_WsAPI.GetFeatureClassName(esriDatasetType.esriDTFeatureDataset);
string sPath = System.IO.Path.Combine(SysAppPath.GetCurrentAppPath(), "Z_VCTContent.txt");
FileStream fs = new FileStream(sPath, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
if (s_FcList.Count > 0)
{
foreach (KeyValuePair<string, string> kvp in s_FcList)
{
if (fcNameList.Contains(kvp.Value))
{
IFeatureClassAPI fcSourceAPI = s_WsAPI.OpenFeatureClass(kvp.Value);
IFeatureClass fcSource = fcSourceAPI.FeatureClass;
FeatureClass fc = fcSource as FeatureClass;
IFields fields = fcSource.Fields;
int FieldCount = 0;
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.Field[i];
if (field.Name == "OBJECTID" || field.Name == "SHAPE" || field.Name == "SHAPE_Length" || field.Name == "SHAPE_Area")
{
continue;
}
FieldCount++;
}
sw.WriteLine(string.Format("{0},{1}", fc.Name, FieldCount));
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.Field[i];
if (field.Name == "OBJECTID" || field.Name == "SHAPE" || field.Name == "SHAPE_Length" || field.Name == "SHAPE_Area")
{
continue;
}
sw.WriteLine(string.Format("{0},{1},{2}", field.Name, GetVCTFieldType(field), field.Length <= 254 ? field.Length : 254));
}
sw.WriteLine("0");
}
}
}
sw.Close();
sw.Dispose();
fs.Close();
fs.Dispose();
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (s_WsAPI != null)
{
s_WsAPI.CloseWorkspace();
}
}
}
public string GetVCTFieldType(IField field)
{
string strType = null;
switch (field.Type)
{
case esriFieldType.esriFieldTypeSmallInteger:
strType = "Int";
break;
case esriFieldType.esriFieldTypeInteger:
strType = "Int";
break;
case esriFieldType.esriFieldTypeSingle:
strType = "Float";
break;
case esriFieldType.esriFieldTypeDouble:
strType = "Float";
break;
case esriFieldType.esriFieldTypeString:
if (field.Name.EndsWith("BZ"))
{
strType = "VarChar";
}
else
{
strType = "Char";
}
break;
case esriFieldType.esriFieldTypeDate:
strType = "Date";
break;
case esriFieldType.esriFieldTypeOID:
break;
case esriFieldType.esriFieldTypeGeometry:
break;
case esriFieldType.esriFieldTypeBlob:
break;
case esriFieldType.esriFieldTypeRaster:
break;
case esriFieldType.esriFieldTypeGUID:
break;
case esriFieldType.esriFieldTypeGlobalID:
break;
case esriFieldType.esriFieldTypeXML:
break;
default:
break;
}
return strType;
}
#region 导入表格数据
public void ExcelToDataTable()
{
DataTable dataTable = null;
IRDBHelper rdbHelper = null;
try
{
ProjectInfo prjInfo = MapsManager.Instance.CurrProjectInfo as ProjectInfo;
string filter = "*.xlsx";
if (string.IsNullOrWhiteSpace(NCDataDir)) return;
var files = System.IO.Directory.GetFiles(NCDataDir, filter, SearchOption.AllDirectories);
string dbPath = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite";
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
DirectoryInfo dir = new DirectoryInfo(NCDataDir);
FileInfo[] fileSet = dir.GetFiles("(" + (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + ")*.xlsx", SearchOption.AllDirectories);
foreach (var item in fileSet)
{
var tableName = item.Name.Replace("(", "").Replace(")", "").Replace((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE, "").Replace(item.Extension, "").ToTrim();
using (var streamData = File.Open(item.FullName, FileMode.Open, FileAccess.Read))
{
using (var readerData = ExcelReaderFactory.CreateReader(streamData))
{
var result = readerData.AsDataSet();
dataTable = result.Tables[0];
Dictionary<string, string> dics = Get_Colunms(dataTable);
CreateTableSql(rdbHelper, tableName, dics);
if (dataTable != null && dataTable.Rows.Count > 0)
{
dataTable = DtSelectTop(10, dataTable);
Insert_sql(dataTable, dics, rdbHelper, tableName);
}
}
}
}
string tbName = "土地利用现状分类面积汇总表";
//调整后年初报表平差(涉及行政区调入、调出的情况)
DataTable table = rdbHelper.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, tbName), true);
if (table == null || table.Rows.Count == 0)
{
return;
}
string ColumnName = table.Rows[0][0].ToTrim();
string strViewSQL = string.Empty;
if (ColumnName == "column1")
{
strViewSQL = string.Format(@" create view V_PC_NCMJ as
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, tbName);
}
else if (ColumnName == "column2")
{
strViewSQL = string.Format(@" create view V_PC_NCMJ as
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, tbName);
}
//年初面积
rdbHelper.ExecuteSQL(@"DROP VIEW V_PC_NCMJ");
rdbHelper.ExecuteSQL(strViewSQL);
//调入面积
rdbHelper.ExecuteSQL(@"DROP VIEW V_PC_TRMJ");
strViewSQL = @"CREATE VIEW V_PC_TRMJ as
select Cells_Y,dlbm,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'";
rdbHelper.ExecuteSQL(strViewSQL);
//调出面积
rdbHelper.ExecuteSQL(@"DROP VIEW V_PC_TCMJ");
strViewSQL = @"CREATE VIEW V_PC_TCMJ as
select Cells_Y,dlbm,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 order by bgmj desc
)a left join TDLYXZBGB B on a.DLBM= B.bgh where b.Cells_X='12'";
rdbHelper.ExecuteSQL(strViewSQL);
//计算平差数
rdbHelper.ExecuteSQL(@"DROP VIEW V_PC_PCS");
strViewSQL = @" create view V_PC_PCS as
SELECT round(ifnull(trmj,0)-ifnull(tcmj,0),2) mjc from
(
(select sum(bgmj) trmj from JCTJB_GQ where XZQTZLX='1' or XZQTZLX='3'),
(select sum(bgmj) tcmj from JCTJB_GQ where XZQTZLX='2' or XZQTZLX='4')
)";
rdbHelper.ExecuteSQL(strViewSQL);
dataTable = rdbHelper.ExecuteDatatable("dtPCS", "select * from V_PC_PCS", true);
double pcs = 0;
if (dataTable != null && dataTable.Rows.Count > 0)
{
pcs = dataTable.Rows[0][0].ToDouble();
if (pcs == 0) return;
}
if (prjInfo == null) return;
if (prjInfo.KZMJ == null) return;
double LLMJBHValue = Math.Round(prjInfo.KZMJ.TZH_LDMJ_GQ + prjInfo.KZMJ.TZH_HDMJ_GQ - (prjInfo.KZMJ.TZQ_LDMJ_GQ + prjInfo.KZMJ.TZQ_HDMJ_GQ), 2);
double PCKZS = Math.Round(LLMJBHValue - pcs, 2);
//获取待平差条目
rdbHelper.ExecuteSQL(@"DROP VIEW V_PC_DPCTM");
dataTable = rdbHelper.ExecuteDatatable("dtPCS", "select * from V_PC_TRMJ", true);
double trmj = 0;
if (dataTable != null && dataTable.Rows.Count > 0)
{
trmj = dataTable.Rows[0][0].ToInt();
strViewSQL = $@"CREATE VIEW V_PC_DPCTM as
select * from JCTJB_GQ ORDER by BGMJ desc,BGHDLBM desc,BGHQSXZ,BGHZLDWDM,BGHGDLX,BGHGDPDJB,BGHTBXHDM,BGHZZSXDM,BGHCZCSXM,BGHMSSM LIMIT {Math.Abs(PCKZS) * 100}";
}
else
{
strViewSQL = $@"CREATE VIEW V_PC_DPCTM as
select * from JCTJB_GQ where BGQDLBM=(
select dlbm from (
select dlbm,(ncmj+trmj-tcmj) TZHNCMJ from (
select a.Cells_Y,case when a.dlbm is null then b.dlbm else a.dlbm end dlbm,ifnull(a.NCMJ,0) NCMJ,ifnull(a.TRMJ,0) TRMJ,ifnull(b.BGMJ,0) as TCMJ from
(
select a.Cells_Y,b.dlbm,a.BGMJ as NCMJ,ifnull(b.BGMJ,0) as TRMJ from V_PC_NCMJ a left join V_PC_TRMJ b on a.Cells_Y=b.Cells_Y
)a left join V_PC_TCMJ b on a.Cells_Y=b.Cells_Y
) where dlbm is not null order by tzhncmj desc LIMIT 1
)
) and XZQTZLX='2' and BGQCZCSXM='空' order by bgmj desc,BGQQSXZ,BGQZLDWDM,BGQGDLX,BGQGDPDJB,BGQTBXHDM,BGQZZSXDM,BGQCZCSXM,BGQMSSM LIMIT {Math.Abs(PCKZS) * 100}";
}
rdbHelper.ExecuteSQL(strViewSQL);
if (PCKZS > 0)
{
if (trmj > 0)
{
rdbHelper.ExecuteSQL(@"update JCTJB_GQ set bgmj=bgmj+0.01 where id in
(
select id from V_PC_DPCTM
)");
}
else
{
rdbHelper.ExecuteSQL(@"update JCTJB_GQ set bgmj=bgmj-0.01 where id in
(
select id from V_PC_DPCTM
)");
}
}
else
{
if (trmj > 0)
{
rdbHelper.ExecuteSQL(@"update JCTJB_GQ set bgmj=bgmj-0.01 where id in
(
select id from V_PC_DPCTM
)");
}
else
{
rdbHelper.ExecuteSQL(@"update JCTJB_GQ set bgmj=bgmj+0.01 where id in
(
select id from V_PC_DPCTM
)");
}
}
}
catch (Exception ex)
{
LogAPI.Debug("读取Excel数据错误:" + ex.Message);
}
finally
{
if (dataTable != null)
{
dataTable.Clear();
dataTable = null;
}
}
}
public static DataTable DtSelectTop(int TopItem, DataTable oDT)
{
if (oDT.Rows.Count < TopItem) return oDT;
DataTable NewTable = oDT.Clone();
DataRow[] rows = oDT.Select("1=1");
for (int i = 0; i < TopItem; i++)
{
NewTable.ImportRow((DataRow)rows[i]);
}
return NewTable;
}
/// <summary>
/// 获取列
/// </summary>
/// <param name="dic"></param>
/// <returns></returns>
public static Dictionary<string, string> Get_Colunms(DataTable dic)
{
Dictionary<string, string> dics = new Dictionary<string, string>();
foreach (DataColumn item in dic.Columns)
{
dics.Add(item.ColumnName, "Varchar");
}
return dics;
}
/// <summary>
/// 创建表
/// </summary>
/// <param name="rdbHelper"></param>
/// <param name="tableName"></param>
/// <param name="table"></param>
protected void CreateTableSql(IRDBHelper rdbHelper, string tableName, Dictionary<string, string> table)
{
string result = string.Empty;
try
{
string temp1 = "CREATE TABLE if not exists " + tableName + "(";
foreach (var item in table)
{
temp1 = temp1 + item.Key.Trim().ToLower() + " " + item.Value + ",";
}
result = temp1.TrimEnd(',') + ");";
rdbHelper.ExecuteNonQueryWithException($" DROP TABLE if exists {tableName}");
rdbHelper.ExecuteNonQueryWithException(result);
}
catch (Exception ex)
{
throw ex;
}
}
public void Insert_sql(DataTable dic, Dictionary<string, string> dics, IRDBHelper SqlHelper, string Table)
{
#region 获取所有字段
StringBuilder columns = new StringBuilder();
foreach (var item in dics)
{
columns.Append("," + item.Key);
}
#endregion
#region 数据入库
int CycleIndex = 0;
StringBuilder insertsql = new StringBuilder();
StringBuilder strsql = new StringBuilder();
StringBuilder stringBuilder = new StringBuilder();
var count = dic.Rows.Count;
foreach (DataRow item0 in dic.Rows)
{
CycleIndex++;
StringBuilder data = new StringBuilder();//insert语句插入字段
foreach (var item1 in dics)
{
if (item0[item1.Key].ToString().Trim() == "")
{
data.Append(",null");
}
else
{
data.Append((",'" + item0[item1.Key].ToString().Trim().Replace("'", "''").Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "") + "'"));
}
}
insertsql.Append(string.Format("insert into " + Table + "({0})values({1});", columns.ToString().Substring(1), data.ToString().Substring(1)));
#region 提交数据
if (count < 10000)
{
if (CycleIndex < count)
{
stringBuilder.Append(insertsql.ToString());
insertsql.Clear();
}
else if (CycleIndex == count)
{
stringBuilder.Append(insertsql.ToString());
var num = SqlHelper.ExecuteNonQuery(stringBuilder.ToString(), CommandType.Text);
if (num < 0 && stringBuilder.ToString() != "")
return;
}
}
else
{
strsql.Append(insertsql.ToString());
insertsql.Clear();
}
if (CycleIndex == 10000)
{
try
{
var num = SqlHelper.ExecuteNonQuery(strsql.ToString(), CommandType.Text);
if (num < 0 && strsql.ToString() != "")
return;
insertsql.Clear();
strsql.Clear();
count = count - CycleIndex;
CycleIndex = 0;
}
catch (Exception exc)
{
throw new Exception(exc.Message);
}
finally
{
GC.Collect();
}
}
#endregion
}
#endregion
}
#endregion
}
}