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

129 lines
4.7 KiB

using ESRI.ArcGIS.Controls;
using KGIS.Framework.AE.ExtensionMethod;
using KGIS.Framework.Commands;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.Plugin.BGResultManager.View;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
namespace Kingo.Plugin.BGResultManager.Commands
{
public class BGResultExportCommand : BaseMenuCommand
{
public IHookHelper m_hookHelper;
private EngineEditorClass pEditor = null;
public override void OnCreate(object hook)
{
if (hook == null)
{
return;
}
try
{
if (m_hookHelper == null)
{
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
pEditor = new EngineEditorClass();
}
}
catch
{
m_hookHelper = null;
return;
}
}
public override void OnClick()
{
try
{
if (pEditor == null)
{
pEditor = new EngineEditorClass();
}
if (pEditor.EditState != esriEngineEditState.esriEngineStateNotEditing)
{
MessageHelper.ShowTips("请先关闭编辑!");
return;
}
IRDBHelper dbHelper = null;
string dbPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()), "BGTJ.sqlite");
string existtable = " select count(0) from sqlite_master where type = 'table' and name = 'BGYLB'";
string sql = " select * from BGYLB limit 1";
dbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
if (dbHelper != null)
{
List<DataDicTionary> qsDic = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM);
if (qsDic == null)
{
MessageHelper.Show("请到字典处生成权属单位代码表");
return;
}
var exist = Convert.ToInt32(dbHelper.ExecuteScalar(existtable, CommandType.Text));
if (exist <= 0)
{
dbHelper.DisConnect();
MessageBox.Show("请完成“增量汇总”操作,再进行一键成果导出");
return;
}
else
{
DataTable dtBGYLB = dbHelper.ExecuteDatatable("BGYLB", sql, true);
if (dtBGYLB == null || dtBGYLB.Rows.Count == 0)
{
if (MessageHelper.ShowYesNoAndTips("检测到变化信息表为空,是否继续进行变更成果导出?") == System.Windows.Forms.DialogResult.No)
{
dbHelper.DisConnect();
return;
}
}
FrmResultsExportForBG frm = new FrmResultsExportForBG
{
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
frm.ShowInMainWindow(true);
}
}
}
catch (Exception ex)
{
LogAPI.Debug("成果导出失败:");
LogAPI.Debug(ex);
MessageHelper.ShowError("成果导出失败,可能的原因是:" + ex.Message);
}
}
public override bool Enabled
{
get
{
return JudgeIsHaveTargetPath();
}
}
private bool JudgeIsHaveTargetPath()
{
try
{
ProjectInfo prj = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
if (prj == null)
{
return false;
}
return !string.IsNullOrWhiteSpace(prj.ZLDatabase) && pEditor.EditState == esriEngineEditState.esriEngineStateNotEditing;
}
catch (Exception ex)
{
LogAPI.Debug("判定 变更成果导出 按钮是否有效时失败,异常原因: " + ex + " ; ");
return false;
}
}
}
}