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.
144 lines
6.0 KiB
144 lines
6.0 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using KGIS.Framework.Commands; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo.PluginServiceInterface; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
using KUI.Windows; |
|
|
|
namespace Kingo.Plugin.BGResultManager.Commands |
|
{ |
|
/// <summary> |
|
/// 预判结果导出(导出检测图斑数据到指定表格内) |
|
/// </summary> |
|
public class CmdExportNYJCDataExprot : BaseMenuCommand |
|
{ |
|
IEngineEditor m_pEditor = null; |
|
private IFeatureLayer JCTBLayer = null; |
|
public override void OnClick() |
|
{ |
|
if (m_pEditor.EditState == esriEngineEditState.esriEngineStateEditing) |
|
{ |
|
MessageHelper.ShowTips("请先关闭编辑!"); |
|
return; |
|
} |
|
if (JCTBLayer == null) |
|
JCTBLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB"); |
|
if (JCTBLayer == null || JCTBLayer.FeatureClass.FeatureCount(null) == 0) |
|
{ |
|
MessageHelper.ShowTips("未找到监测图层/当前监测图层没有数据!"); |
|
return; |
|
} |
|
int JCBHIndex = JCTBLayer.FeatureClass.FindField("JCBH"); |
|
int XZQDMIndex = JCTBLayer.FeatureClass.FindField("XZQDM"); |
|
int SFWYIndex = JCTBLayer.FeatureClass.FindField("SFJZ"); |
|
int NYRDDLIndex = JCTBLayer.FeatureClass.FindField("NYRDDL"); |
|
int NYSMIndex = JCTBLayer.FeatureClass.FindField("JZSM"); |
|
IFeatureCursor featureCursorJC = null; |
|
try |
|
{ |
|
var sourcesfile = SysAppPath.GetCurrentAppPath() + string.Format(@"TempalateReports\预判结果导出模板\{0}", "内业处理软件导出模板.xls"); |
|
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(sourcesfile); |
|
workbook.CalculateFormula(true); |
|
Aspose.Cells.Worksheet sheet = workbook.Worksheets[0]; |
|
string xlsFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff"); |
|
string OutPath = string.Empty; |
|
KGIS.Framework.Utils.Dialog.FolderBrowserDialog pBrowser = new KGIS.Framework.Utils.Dialog.FolderBrowserDialog |
|
{ |
|
ShowNewFolderButton = true |
|
}; |
|
if (pBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
|
{ |
|
OutPath = pBrowser.SelectedPath; |
|
} |
|
else |
|
return; |
|
this.ShowLoading("内业预判结果数据导出.......", 0, 0); |
|
string TempPath = string.Format(@"{0}\{1}{2}.xls", OutPath, "内业预判结果", xlsFileName); |
|
int IndexValue = 1;//行 |
|
featureCursorJC = JCTBLayer.FeatureClass.Search(null, true); |
|
IFeature featureJC = null; |
|
while ((featureJC = featureCursorJC.NextFeature()) != null) |
|
{ |
|
for (int j = 0; j < 5; j++) |
|
{ |
|
Aspose.Cells.Cell cell = sheet.Cells[IndexValue, j]; |
|
if (j == 0 && JCBHIndex != -1) |
|
{ |
|
cell.PutValue(featureJC.Value[JCBHIndex].ToString()); |
|
continue; |
|
} |
|
else if (j == 1 && XZQDMIndex != -1) |
|
{ |
|
cell.PutValue(featureJC.Value[XZQDMIndex].ToString()); |
|
continue; |
|
} |
|
else if (j == 2 && SFWYIndex != -1) |
|
{ |
|
cell.PutValue(featureJC.Value[SFWYIndex].ToString()); |
|
continue; |
|
} |
|
else if (j == 3 && NYRDDLIndex != -1) |
|
{ |
|
cell.PutValue(featureJC.Value[NYRDDLIndex].ToString()); |
|
continue; |
|
} |
|
else if (NYSMIndex != -1) |
|
{ |
|
cell.PutValue(featureJC.Value[NYSMIndex].ToString()); |
|
} |
|
} |
|
IndexValue++; |
|
} |
|
workbook.Save(TempPath); |
|
workbook = null; |
|
this.CloseLoading(); |
|
MessageHelper.ShowTips("挂接结果导出成功!"); |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.ShowTips("内业预判结果导出失败:" + ex.Message); |
|
LogAPI.Debug(ex); |
|
} |
|
finally |
|
{ |
|
if (featureCursorJC != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(JCTBLayer); |
|
if (featureCursorJC != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursorJC); |
|
} |
|
} |
|
|
|
public override void OnCreate(object Hook) |
|
{ |
|
m_pEditor = new EngineEditorClass(); |
|
} |
|
|
|
public override bool Enabled => JudgeIsHaveTargetPath(); |
|
|
|
private bool JudgeIsHaveTargetPath() |
|
{ |
|
try |
|
{ |
|
IFeatureLayer JCTBLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB"); |
|
if (!(MapsManager.Instance.MapService.GetProjectInfo() is ProjectInfo prj) || JCTBLayer == null) |
|
{ |
|
return false; |
|
} |
|
return !string.IsNullOrWhiteSpace(prj.BGDatabase) && m_pEditor.EditState == esriEngineEditState.esriEngineStateNotEditing; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("判定 检测结果导出 按钮是否有效时失败,异常原因: " + ex + " ; "); |
|
return false; |
|
} |
|
} |
|
} |
|
|
|
}
|
|
|