OutDWG.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using WWPipeLine.MapBasic.Conditions;
  11. using Sunny.UI;
  12. using WeifenLuo.WinFormsUI.Docking;
  13. using SuperMap.Mapping;
  14. using WWPipeLine.MapBasic;
  15. using SuperMap.Data.Conversion;
  16. using SuperMap.Data;
  17. namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi
  18. {
  19. public partial class OutDWG : ConditionPanel
  20. {
  21. private LayerWithDataListPanel LayerPanel;
  22. private string fileName = string.Empty;
  23. private string fileType = string.Empty;
  24. private string dviName = string.Empty;
  25. public OutDWG()
  26. {
  27. this.ConditionPanelName = "地图输出CAD文件";
  28. InitializeComponent();
  29. }
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. LayerPanel = new LayerWithDataListPanel();
  33. LayerPanel.LoadToVector(true);
  34. uiGBlayer.Controls.Add(LayerPanel);
  35. foreach (string v in Enum.GetNames(typeof(CADVersion)))
  36. { uiRBGlx.Items.Add((object)v); }
  37. }
  38. private void uiButton1_Click(object sender, EventArgs e)
  39. {
  40. SaveFileDialog sfd = new SaveFileDialog();
  41. sfd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
  42. sfd.Title = "请选择要保存的文件路径";
  43. sfd.Filter = "所有文件|*.*";
  44. sfd.RestoreDirectory = true;
  45. if (sfd.ShowDialog() == DialogResult.OK)
  46. {
  47. fileName = sfd.FileName;
  48. uiTextBox1.Text = fileName;
  49. }
  50. }
  51. public override object Do(DockPanel dockPanel = null)
  52. {
  53. this.IsShowResultWindow = false;
  54. if (string.IsNullOrEmpty(fileName))
  55. { UIMessageTip.ShowError("请选择要保存文件的路径"); return false; }
  56. if (string.IsNullOrEmpty(fileType))
  57. { UIMessageTip.ShowError("请选择要保存文件的格式"); return false; }
  58. if (LayerPanel.SelectLayers.Count == 0)
  59. { UIMessageTip.ShowError("请选择要保存文件的图层"); return false; }
  60. ExportSettingDWG exSetting = new ExportSettingDWG();
  61. exSetting.TargetFileType = FileType.DWG;
  62. exSetting.TargetFilePath = fileName;
  63. exSetting.ExportingExternalData = true;
  64. exSetting.ExportingXRecord = true;
  65. exSetting.IsOverwrite = true;
  66. switch (fileType)
  67. {
  68. case "CAD12": exSetting.Version = CADVersion.CAD12; break;
  69. case "CAD13": exSetting.Version = CADVersion.CAD13; break;
  70. case "CAD14": exSetting.Version = CADVersion.CAD14; break;
  71. case "CAD2000": exSetting.Version = CADVersion.CAD2000; break;
  72. case "CAD2004": exSetting.Version = CADVersion.CAD2004; break;
  73. case "CAD2007": exSetting.Version = CADVersion.CAD2007; break;
  74. default: exSetting.Version = CADVersion.CAD12; break;
  75. }
  76. dviName = ComsStatic.Datasource.Datasets.GetAvailableDatasetName("OutDWG_dvName");
  77. DatasetVectorInfo temCad = new DatasetVectorInfo() { Name = dviName, Type = DatasetType.CAD };
  78. DatasetVector dvFinal = ComsStatic.Datasource.Datasets.Create(temCad);
  79. DatasetVector dv = null;
  80. foreach (Layer lyr in LayerPanel.SelectLayers.ToArray())
  81. {
  82. dv = lyr.Dataset as DatasetVector;
  83. dvFinal.Append(dv.GetRecordset(false, CursorType.Static));
  84. }
  85. exSetting.SourceData = dvFinal;
  86. DataExport ex = new DataExport();
  87. ex.ExportSettings.Add(exSetting);
  88. ExportResult exResult = ex.Run();
  89. if (ex.ExportSettings.Count == exResult.SucceedSettings.Length)
  90. ComsStatic.ShowOKLog(string.Format("地图导出dwg格式,应导出{0}条,共导出{1}条", ex.ExportSettings.Count, exResult.SucceedSettings.Length));
  91. else
  92. ComsStatic.ShowErrorLog(string.Format("地图导出dwg格式,应导出{0}条,失败导出{1}条", ex.ExportSettings.Count, exResult.FailedSettings.Length));
  93. if (ComsStatic.Datasource.Datasets.Contains(dviName))
  94. ComsStatic.Datasource.Datasets.Delete(dviName);
  95. return true;
  96. }
  97. private void uiRBGlx_ValueChanged(object sender, int index, string text)
  98. {
  99. fileType = text;
  100. }
  101. }
  102. }