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.
206 lines
7.6 KiB
206 lines
7.6 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Geometry; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.Commands; |
|
using KGIS.Framework.DBOperator; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo.PluginServiceInterface; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Data; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
using KUI.Windows; |
|
|
|
namespace Kingo.Plugin.BGResultManager.Commands |
|
{ |
|
/// <summary> |
|
/// 日常成果导出 |
|
/// </summary> |
|
public class CmdDailyResultExport : BaseMenuCommand |
|
{ |
|
private EngineEditorClass pEditor = null; |
|
public IHookHelper m_hookHelper; |
|
public override void OnClick() |
|
{ |
|
IFeatureLayer featureLayerGC = null; |
|
ISpatialReference pSR = null; |
|
ProjectInfo projectInfo = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo); |
|
string Code_Name = GetXZQDic(projectInfo.CODE); |
|
IWorkspaceAPI wsAPI = null; |
|
IFeatureClassAPI featureClassAPI = null; |
|
try |
|
{ |
|
if (pEditor == null) |
|
{ |
|
pEditor = new EngineEditorClass(); |
|
} |
|
if (pEditor.EditState != esriEngineEditState.esriEngineStateNotEditing) |
|
{ |
|
MessageHelper.ShowTips("请先关闭编辑!"); |
|
return; |
|
} |
|
featureLayerGC = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBGXGC"); |
|
if (featureLayerGC == null || featureLayerGC.FeatureClass.FeatureCount(null) == 0) |
|
{ |
|
MessageHelper.ShowTips("未加载到“DLTBGXGC”图层数据!"); |
|
return; |
|
} |
|
pSR = (featureLayerGC.FeatureClass as IGeoDataset).SpatialReference; |
|
//弹出文件选择对话框 |
|
var saveFileDialog = new Microsoft.Win32.SaveFileDialog |
|
{ |
|
FileName = "日常成果_" + projectInfo.CODE + Code_Name, |
|
Filter = "MDB文件(*.mdb)|*.mdb" |
|
//Filter = "GDB文件(*.gdb)|*.gdb|MDB文件(*.mdb)|*.mdb" |
|
}; |
|
var result = saveFileDialog.ShowDialog(); |
|
if (result.Value) |
|
{ |
|
this.ShowLoading("正在进行日常成果输出........", 0, 0); |
|
string path = string.Empty; |
|
string MDBpath = string.Empty; |
|
path = saveFileDialog.FileName; |
|
if (File.Exists(path)) |
|
File.Delete(path);//替换同名文件 |
|
// PluginServiceInterface.CommonHelper.DelectDir(saveFile);//能删除就删除(文件占用) 删除报错不处理 |
|
CreateFileMDB(path, System.IO.Path.GetFileName(path)); |
|
wsAPI = new WorkspaceAPI(path, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.MDBFile); |
|
if (wsAPI == null) return; |
|
IFeatureClassAPI classAPI = wsAPI.CreateFeatureClass("DLTBGXGC", pSR, featureLayerGC.FeatureClass.Fields); |
|
featureClassAPI = new FeatureClassAPI(featureLayerGC.FeatureClass); |
|
featureClassAPI.FcToFc(classAPI.FeatureClass, null, false); |
|
if (projectInfo.ProjType != EnumProjType.RCBG_ZJG) |
|
classAPI.DeleteField("DKMC");//日常变更(增减挂钩项目)如果不是增减挂钩项目则不需要该字段 |
|
if (classAPI.FeatureClass.FindField("XMQBH") != -1) |
|
classAPI.DeleteField("XMQBH"); |
|
if (classAPI.FeatureClass.FindField("DKBH") != -1) |
|
classAPI.DeleteField("DKBH");//出现多余字段 |
|
if (classAPI != null) classAPI.CloseFeatureClass(); |
|
this.CloseLoading(); |
|
MessageHelper.ShowTips("日常成果输出完成!"); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.CloseLoading(); |
|
LogAPI.Debug("日常成果导出失败" + ex); |
|
MessageHelper.ShowError("日常成果导出,可能的原因是:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
if (featureClassAPI != null) |
|
featureClassAPI.CloseFeatureClass(); |
|
if (wsAPI != null) wsAPI.CloseWorkspace(); |
|
this.CloseLoading(); |
|
} |
|
} |
|
|
|
public override void OnCreate(object Hook) |
|
{ |
|
try |
|
{ |
|
if (m_hookHelper == null) |
|
{ |
|
m_hookHelper = new HookHelperClass |
|
{ |
|
Hook = Hook |
|
}; |
|
} |
|
if (pEditor == null) |
|
{ |
|
pEditor = new EngineEditorClass(); |
|
} |
|
} |
|
catch |
|
{ |
|
m_hookHelper = null; |
|
return; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 根据区划代码获取县级名称 |
|
/// </summary> |
|
/// <param name="Codes"></param> |
|
/// <returns></returns> |
|
public string GetXZQDic(string Codes) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
string CodeName = string.Empty; |
|
try |
|
{ |
|
string systemPath = SysAppPath.GetDataBasePath() + "System.mdb"; |
|
if (File.Exists(systemPath)) |
|
{ |
|
string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection"); |
|
connStr = string.Format(connStr, systemPath); |
|
rdbHelper = RDBFactory.CreateDbHelper(connStr, DatabaseType.MSAccess); |
|
string strSQL = "select OBJECTID AS ID, XZQ AS CODE,XZQMC AS NAME from XZQ Where XZQ LIKE '" + Codes + "%'"; |
|
DataTable dt = rdbHelper.ExecuteDatatable("Dic", strSQL, true); |
|
if (dt != null) |
|
{ |
|
CodeName = dt.Rows[0]["NAME"].ToString(); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
return CodeName; |
|
} |
|
|
|
/// <summary> |
|
/// 创建FileMDB |
|
/// </summary> |
|
/// <param name="fullPath">路径名</param> |
|
public static void CreateFileMDB(string fullPath, string gdbName) |
|
{ |
|
string temp = SysAppPath.GetTemplatePath() + "Temp.mdb"; |
|
if (File.Exists(temp)) |
|
{ |
|
File.Copy(temp, fullPath); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 是否功能展示 |
|
/// </summary> |
|
public override bool Enabled |
|
{ |
|
get |
|
{ |
|
ProjectInfo pTemp = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo); |
|
if (pTemp == null) |
|
{ |
|
return false; |
|
} |
|
else |
|
{ |
|
if (string.IsNullOrWhiteSpace(pTemp.GetProjFilePath())) |
|
{ |
|
return false; |
|
} |
|
else |
|
{ |
|
return true; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
}
|
|
|