123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using WWPipeLine.MapBasic.Conditions;
- using Sunny.UI;
- using WeifenLuo.WinFormsUI.Docking;
- using SuperMap.Mapping;
- using WWPipeLine.MapBasic;
- using SuperMap.Data.Conversion;
- using SuperMap.Data;
- namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi
- {
- public partial class OutDWG : ConditionPanel
- {
- private LayerWithDataListPanel LayerPanel;
- private string fileName = string.Empty;
- private string fileType = string.Empty;
- private string dviName = string.Empty;
- public OutDWG()
- {
- this.ConditionPanelName = "地图输出CAD文件";
- InitializeComponent();
- }
- protected override void OnLoad(EventArgs e)
- {
- LayerPanel = new LayerWithDataListPanel();
- LayerPanel.LoadToVector(true);
- uiGBlayer.Controls.Add(LayerPanel);
- foreach (string v in Enum.GetNames(typeof(CADVersion)))
- { uiRBGlx.Items.Add((object)v); }
- }
- private void uiButton1_Click(object sender, EventArgs e)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
- sfd.Title = "请选择要保存的文件路径";
- sfd.Filter = "所有文件|*.*";
- sfd.RestoreDirectory = true;
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- fileName = sfd.FileName;
- uiTextBox1.Text = fileName;
- }
- }
- public override object Do(DockPanel dockPanel = null)
- {
- this.IsShowResultWindow = false;
- if (string.IsNullOrEmpty(fileName))
- { UIMessageTip.ShowError("请选择要保存文件的路径"); return false; }
- if (string.IsNullOrEmpty(fileType))
- { UIMessageTip.ShowError("请选择要保存文件的格式"); return false; }
- if (LayerPanel.SelectLayers.Count == 0)
- { UIMessageTip.ShowError("请选择要保存文件的图层"); return false; }
- ExportSettingDWG exSetting = new ExportSettingDWG();
- exSetting.TargetFileType = FileType.DWG;
- exSetting.TargetFilePath = fileName;
- exSetting.ExportingExternalData = true;
- exSetting.ExportingXRecord = true;
- exSetting.IsOverwrite = true;
- switch (fileType)
- {
- case "CAD12": exSetting.Version = CADVersion.CAD12; break;
- case "CAD13": exSetting.Version = CADVersion.CAD13; break;
- case "CAD14": exSetting.Version = CADVersion.CAD14; break;
- case "CAD2000": exSetting.Version = CADVersion.CAD2000; break;
- case "CAD2004": exSetting.Version = CADVersion.CAD2004; break;
- case "CAD2007": exSetting.Version = CADVersion.CAD2007; break;
- default: exSetting.Version = CADVersion.CAD12; break;
- }
- dviName = ComsStatic.Datasource.Datasets.GetAvailableDatasetName("OutDWG_dvName");
- DatasetVectorInfo temCad = new DatasetVectorInfo() { Name = dviName, Type = DatasetType.CAD };
- DatasetVector dvFinal = ComsStatic.Datasource.Datasets.Create(temCad);
- DatasetVector dv = null;
- foreach (Layer lyr in LayerPanel.SelectLayers.ToArray())
- {
- dv = lyr.Dataset as DatasetVector;
- dvFinal.Append(dv.GetRecordset(false, CursorType.Static));
- }
- exSetting.SourceData = dvFinal;
- DataExport ex = new DataExport();
- ex.ExportSettings.Add(exSetting);
- ExportResult exResult = ex.Run();
- if (ex.ExportSettings.Count == exResult.SucceedSettings.Length)
- ComsStatic.ShowOKLog(string.Format("地图导出dwg格式,应导出{0}条,共导出{1}条", ex.ExportSettings.Count, exResult.SucceedSettings.Length));
- else
- ComsStatic.ShowErrorLog(string.Format("地图导出dwg格式,应导出{0}条,失败导出{1}条", ex.ExportSettings.Count, exResult.FailedSettings.Length));
- if (ComsStatic.Datasource.Datasets.Contains(dviName))
- ComsStatic.Datasource.Datasets.Delete(dviName);
- return true;
- }
- private void uiRBGlx_ValueChanged(object sender, int index, string text)
- {
- fileType = text;
- }
- }
- }
|