|
|
|
|
using KGIS.Framework.Commands;
|
|
|
|
|
using KGIS.Framework.Utils.Helper;
|
|
|
|
|
using KGIS.Framework.Utils;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ESRI.ArcGIS.Controls;
|
|
|
|
|
using KGIS.Framework.Maps;
|
|
|
|
|
using Kingo.PluginServiceInterface;
|
|
|
|
|
using UIShell.OSGi;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using KGIS.Framework.AE;
|
|
|
|
|
using ESRI.ArcGIS.Carto;
|
|
|
|
|
using KGIS.Framework.Platform;
|
|
|
|
|
using Kingo.Framework.LayerStyleConvert.XSDClass;
|
|
|
|
|
using Kingo.Framework.LayerStyleConvert.Common;
|
|
|
|
|
|
|
|
|
|
namespace Kingo.Plugin.BatchDataLoad.Commands
|
|
|
|
|
{
|
|
|
|
|
public class CmdCreateDB : BaseMenuCommand
|
|
|
|
|
{
|
|
|
|
|
private EngineEditorClass pEditor = null;
|
|
|
|
|
private IHookHelper hookHelper = null;
|
|
|
|
|
private IDataCatalogService _DataCatalog = null;
|
|
|
|
|
private SystemConfig2 SystemCfg = null;
|
|
|
|
|
public override void OnClick()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_DataCatalog == null)
|
|
|
|
|
_DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>();
|
|
|
|
|
if (_DataCatalog == null)
|
|
|
|
|
return;
|
|
|
|
|
ProjectInfo ProInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
|
|
|
|
|
if (ProInfo == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (pEditor == null)
|
|
|
|
|
pEditor = new EngineEditorClass();
|
|
|
|
|
if (pEditor.EditState != esriEngineEditState.esriEngineStateNotEditing)
|
|
|
|
|
{
|
|
|
|
|
MessageHelper.ShowTips("请先关闭编辑!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DirectoryCopy(SysAppPath.GetCurrentAppPath() + string.Format("工作空间\\模板\\新建变更工程\\{0}\\BGDB.gdb", (int)Math.Floor(Math.Round(10 / ProInfo.XYResolution))), ProInfo.ProjDir);
|
|
|
|
|
ProInfo.BGDatabase = Path.Combine(ProInfo.ProjDir, "BGDB.gdb");
|
|
|
|
|
string strMxdPath = SysAppPath.GetCurrentAppPath() + "工作空间\\模板\\新建变更工程\\LatersToXMLForBHTBTQ.xml";
|
|
|
|
|
|
|
|
|
|
LayerCfg StrLayerInfo = SerializeAPI.DeserializeToObject2<LayerCfg>(strMxdPath);
|
|
|
|
|
StrLayerInfo.LayerName = ProInfo.ProjName;
|
|
|
|
|
Byte[] bytearr = System.Text.Encoding.Default.GetBytes(SerializeAPI.SerializeToXML<LayerCfg>(StrLayerInfo));
|
|
|
|
|
string strBase64 = Convert.ToBase64String(bytearr);
|
|
|
|
|
ProInfo.TempData = strBase64;
|
|
|
|
|
|
|
|
|
|
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" });
|
|
|
|
|
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "LoadProject", Content = Path.Combine(ProInfo.ProjDir, ProInfo.ProjName + ProInfo.ProjSuffix) });
|
|
|
|
|
//SaveMap();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageHelper.ShowTips("创建数据库失败:" + ex.Message);
|
|
|
|
|
LogAPI.Debug(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void SetILayerSymbol(IFeatureLayer tempLayer, string LayerAliseName)
|
|
|
|
|
{
|
|
|
|
|
IFeatureRenderer result = null;
|
|
|
|
|
LayerCfg layerCfg = SystemCfg.BGLayerLoadCfg.FirstOrDefault(x => x.FcName == LayerAliseName);//默认配置默认不为NULL
|
|
|
|
|
if (layerCfg != null && !string.IsNullOrWhiteSpace(layerCfg.Symbol))
|
|
|
|
|
{
|
|
|
|
|
AdvancedDrawingInfo ad = AdvancedDrawingInfo.FromJson(layerCfg.Symbol);
|
|
|
|
|
if (ad != null)
|
|
|
|
|
{
|
|
|
|
|
if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.SimpleRenderer)
|
|
|
|
|
{
|
|
|
|
|
Symbol symbol1 = (ad.DrawingInfo.Renderer as Framework.LayerStyleConvert.XSDClass.SimpleRenderer).Symbol;
|
|
|
|
|
ISimpleRenderer simpleRander2 = SymbolConvert.Instance().GetSimpleRenderer(symbol1, SymbolTypeEnum.Fill);
|
|
|
|
|
result = simpleRander2 as IFeatureRenderer;
|
|
|
|
|
}
|
|
|
|
|
else if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer)
|
|
|
|
|
{
|
|
|
|
|
Renderer rander = ad.DrawingInfo.Renderer;
|
|
|
|
|
IUniqueValueRenderer uniqueValueRander = SymbolConvert.Instance().GetUniqueValueRenderer(rander, SymbolTypeEnum.Fill);
|
|
|
|
|
result = uniqueValueRander as IFeatureRenderer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 样式
|
|
|
|
|
if (result != null)
|
|
|
|
|
(tempLayer as IGeoFeatureLayer).Renderer = result;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 显示比例设置
|
|
|
|
|
tempLayer.MinimumScale = layerCfg.MinScale;
|
|
|
|
|
tempLayer.MaximumScale = layerCfg.MaxScale;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 图层透明度
|
|
|
|
|
if (tempLayer is ILayerEffects mLayerEffects)//透明度
|
|
|
|
|
mLayerEffects.Transparency = (short)layerCfg.Transparency;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 是否显示
|
|
|
|
|
tempLayer.Visible = layerCfg.Visible;//是否显示
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 是否可选择
|
|
|
|
|
tempLayer.Selectable = layerCfg.Selectable;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 过滤条件
|
|
|
|
|
IFeatureLayerDefinition pFLDefinition = tempLayer as IFeatureLayerDefinition;
|
|
|
|
|
if (pFLDefinition != null)
|
|
|
|
|
{
|
|
|
|
|
pFLDefinition.DefinitionExpression = layerCfg.DefinitionExpression;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private IFeatureRenderer GetSymbol(string pStrSymbol)
|
|
|
|
|
{
|
|
|
|
|
IFeatureRenderer result = null;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(pStrSymbol))
|
|
|
|
|
{
|
|
|
|
|
AdvancedDrawingInfo ad = AdvancedDrawingInfo.FromJson(pStrSymbol);
|
|
|
|
|
if (ad != null)
|
|
|
|
|
{
|
|
|
|
|
if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.SimpleRenderer)
|
|
|
|
|
{
|
|
|
|
|
Symbol symbol1 = (ad.DrawingInfo.Renderer as Framework.LayerStyleConvert.XSDClass.SimpleRenderer).Symbol;
|
|
|
|
|
ISimpleRenderer simpleRander2 = SymbolConvert.Instance().GetSimpleRenderer(symbol1, SymbolTypeEnum.Fill);
|
|
|
|
|
result = simpleRander2 as IFeatureRenderer;
|
|
|
|
|
}
|
|
|
|
|
else if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer)
|
|
|
|
|
{
|
|
|
|
|
Renderer rander = ad.DrawingInfo.Renderer;
|
|
|
|
|
IUniqueValueRenderer uniqueValueRander = SymbolConvert.Instance().GetUniqueValueRenderer(rander, SymbolTypeEnum.Fill);
|
|
|
|
|
result = uniqueValueRander as IFeatureRenderer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnCreate(object Hook)
|
|
|
|
|
{
|
|
|
|
|
if (hookHelper == null)
|
|
|
|
|
hookHelper = new HookHelperClass();
|
|
|
|
|
|
|
|
|
|
hookHelper.Hook = Hook;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Enabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
//验证是否打开工程
|
|
|
|
|
if (!(MapsManager.Instance.MapService.GetProjectInfo() is ProjectInfo ProInfo))
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return string.IsNullOrWhiteSpace(ProInfo.BGDatabase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public bool DirectoryCopy(string sourceDir, string targetDirPath)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(sourceDir)) return false;
|
|
|
|
|
string targetDir = targetDirPath + "\\" + System.IO.Path.GetFileName(sourceDir);
|
|
|
|
|
if (!Directory.Exists(targetDir)) Directory.CreateDirectory(targetDir);
|
|
|
|
|
// 文件及文件夹名称数组
|
|
|
|
|
string[] dirColl = Directory.GetDirectories(sourceDir);
|
|
|
|
|
string[] fileColl = Directory.GetFiles(sourceDir);
|
|
|
|
|
// 便利所有文件
|
|
|
|
|
if (fileColl.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
string fileName;
|
|
|
|
|
foreach (string fileDir in fileColl)
|
|
|
|
|
{
|
|
|
|
|
fileName = System.IO.Path.GetFileName(fileDir);
|
|
|
|
|
File.Copy(sourceDir + "\\" + fileName, targetDir + "\\" + fileName, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 遍历所有文件夹
|
|
|
|
|
if (dirColl.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
string folderName;
|
|
|
|
|
foreach (string dir in dirColl)
|
|
|
|
|
{
|
|
|
|
|
folderName = System.IO.Path.GetFileName(dir);
|
|
|
|
|
// 递归调用
|
|
|
|
|
Directory.CreateDirectory(targetDir + "\\" + folderName);
|
|
|
|
|
DirectoryCopy(dir, targetDir + "\\" + folderName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("新建工程页面中,文件夹复制时失败,异常原因: " + ex + " ; ");
|
|
|
|
|
return false;
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|