public override void OnClick() { System.Data.IDbConnection resultConnection = CheckApplication.CurrentTask.ResultConnection as System.Data.OleDb.OleDbConnection; if (resultConnection == null) { DevExpress.XtraEditors.XtraMessageBox.Show("当前任务状态被标记为已创建,但结果库可能已被移除。"); return; } System.Windows.Forms.SaveFileDialog dlgShpFile = new System.Windows.Forms.SaveFileDialog(); dlgShpFile.FileName = Environment.CurrentDirectory + "\\" + CheckApplication.CurrentTask.Name + ".xls"; dlgShpFile.Filter = "SHP 文件|*.Shp"; if (dlgShpFile.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } string strFile = dlgShpFile.FileName; string strPath = System.IO.Path.GetDirectoryName(strFile); string strName = System.IO.Path.GetFileNameWithoutExtension(strFile); Hy.Check.Task.Task curTask = CheckApplication.CurrentTask; ErrorExporter exporter = new ErrorExporter(); exporter.BaseWorkspace = curTask.BaseWorkspace; exporter.ResultConnection = curTask.ResultConnection; exporter.SchemaID = curTask.SchemaID; exporter.Topology = curTask.Topology; exporter.ExportToShp(strPath, strName); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { System.Data.IDbConnection resultConnection = CheckApplication.CurrentTask.ResultConnection as System.Data.OleDb.OleDbConnection; if (resultConnection == null) { DevExpress.XtraEditors.XtraMessageBox.Show("当前任务状态被标记为已创建,但结果库可能已被移除。"); return; } System.Windows.Forms.SaveFileDialog dlgShpFile = new System.Windows.Forms.SaveFileDialog(); dlgShpFile.FileName = Environment.CurrentDirectory + "\\" + CheckApplication.CurrentTask.Name + ".shp"; dlgShpFile.Filter = "SHP 文件|*.Shp"; dlgShpFile.OverwritePrompt = true; if (dlgShpFile.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } string strFile = dlgShpFile.FileName; string strPath = System.IO.Path.GetDirectoryName(strFile); string strName = System.IO.Path.GetFileNameWithoutExtension(strFile); // 检查已存在 if (System.IO.File.Exists(strFile)) { //System.IO.File.Delete(dlgShpFile.FileName); try { IWorkspace ws = Hy.Common.Utility.Esri.AEAccessFactory.OpenWorkspace(enumDataType.SHP, strPath); IDataset dsShp = (ws as IFeatureWorkspace).OpenFeatureClass(strName) as IDataset; if (dsShp != null) { dsShp.Delete(); } } catch { try { System.IO.File.Delete(strFile); } catch { XtraMessageBox.Show("文件删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } // 开始导出 CheckApplication.GifProgress.ShowHint("正在导出错误结果到Shp文件,请稍候……"); Hy.Check.Task.Task curTask = CheckApplication.CurrentTask; ErrorExporter exporter = new ErrorExporter(); exporter.BaseWorkspace = curTask.BaseWorkspace; exporter.ResultConnection = curTask.ResultConnection; exporter.SchemaID = curTask.SchemaID; exporter.Topology = curTask.Topology; bool isSucceed = exporter.ExportToShp(strPath, strName); CheckApplication.GifProgress.Hide(); GC.Collect(); if (isSucceed) { XtraMessageBox.Show("导出Shp成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { XtraMessageBox.Show("导出Shp失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }