/// <summary> /// 通过工程获取图层列表 /// </summary> /// <param name="ex"></param> private void GetConnectInfo(out Exception ex) { ex = null; if (string.IsNullOrEmpty(this.com_Project.Text)) { //SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "请选择一个工程!"); return; } if (string.IsNullOrEmpty(this.com_DataBase.Text)) { //SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "请选择一个库体!"); return; } string ProjectName = this.com_Project.Text.Trim(); string DataBaseName = this.com_DataBase.Text.Trim(); //////////////获取相应的库体的连接信息 string type = string.Empty; string server = string.Empty; string servername = string.Empty; string databasepath = string.Empty; string user = string.Empty; string password = string.Empty; string version = string.Empty; ///////////////// XmlDocument XmlDoc = new XmlDocument(); //cyf 20110713 modify XmlDoc.Load(ModData.v_projectDetalXML); //XmlDoc.Load(ModData.v_projectXML); if (null == XmlDoc) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取工程信息失败!"); return; } XmlElement ProjectEle = XmlDoc.SelectSingleNode(".//工程管理/工程[@名称='" + ProjectName + "']") as XmlElement; if (ProjectEle == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据库工程记录文件中无法找到工程:" + ProjectName); return; } XmlElement DataBaseEle = ProjectEle.SelectSingleNode(".//内容/" + DataBaseName) as XmlElement; if (null == DataBaseEle) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据库工程记录文件中无法找到工程:" + ProjectName + "中库体:" + DataBaseName); return; } XmlElement ConnectInfo = DataBaseEle.SelectSingleNode(".//连接信息") as XmlElement; this._ConnectInfo = ConnectInfo; XmlElement Base = DataBaseEle.SelectSingleNode(".//连接信息/库体") as XmlElement; type = ConnectInfo.GetAttribute("类型"); server = ConnectInfo.GetAttribute("服务器"); servername = ConnectInfo.GetAttribute("服务名"); databasepath = ConnectInfo.GetAttribute("数据库"); user = ConnectInfo.GetAttribute("用户"); password = ConnectInfo.GetAttribute("密码"); version = ConnectInfo.GetAttribute("版本"); /////////////////////////////使用连接信息进行连接数据库 pGisDT = new SysCommon.Gis.SysGisDataSet(); if (string.IsNullOrEmpty(type)) { ex = new Exception("库体未初始化!"); return; } if (type == "SDE") { pGisDT.SetWorkspace(server, servername, databasepath, user, password, version, out ex); if (ex != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据库连接失败!"); return; } } else if (type == "GDB") { pGisDT.SetWorkspace(databasepath, SysCommon.enumWSType.GDB, out ex); if (ex != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据库连接失败!"); return; } } else if (type == "PDB") { pGisDT.SetWorkspace(databasepath, SysCommon.enumWSType.PDB, out ex); if (ex != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据库连接失败!"); return; } } }
/// <summary> /// 获取数据库的图层列表 /// </summary> private void GetDataBaseLayer() { if (this._ConnectInfo == null) { return; } //////////////获取相应的库体的连接信息 string type = string.Empty; string server = string.Empty; string servername = string.Empty; string databasepath = string.Empty; string user = string.Empty; string password = string.Empty; string version = string.Empty; ///////////////// XmlElement ConnectInfo = this._ConnectInfo; try { type = ConnectInfo.GetAttribute("类型"); server = ConnectInfo.GetAttribute("服务器"); servername = ConnectInfo.GetAttribute("服务名"); databasepath = ConnectInfo.GetAttribute("数据库"); user = ConnectInfo.GetAttribute("用户"); password = ConnectInfo.GetAttribute("密码"); version = ConnectInfo.GetAttribute("版本"); } catch (Exception e) { //******************************************************************* //guozheng added if (ModData.SysLog != null) { ModData.SysLog.Write(e, null, DateTime.Now); } else { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); ModData.SysLog.Write(e, null, DateTime.Now); } //******************************************************************** SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取连接信息失败!"); return; } /////////////////////////////使用连接信息进行连接数据库 pGisDT = new SysCommon.Gis.SysGisDataSet(); if (string.IsNullOrEmpty(type)) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "库体未初始化!"); return; } Exception ex = null; if (type == "SDE") { pGisDT.SetWorkspace(server, servername, databasepath, user, password, version, out ex); if (ex != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据库连接失败!"); return; } } else if (type == "GDB") { pGisDT.SetWorkspace(databasepath, SysCommon.enumWSType.GDB, out ex); if (ex != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据库连接失败!"); return; } } else if (type == "PDB") { pGisDT.SetWorkspace(databasepath, SysCommon.enumWSType.PDB, out ex); if (ex != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据库连接失败!"); return; } } if (rbServer.Checked == true) { //获得数据库中的所有要素类添加到图层列表中供用户选择 List <IDataset> LstDT = pGisDT.GetAllFeatureClass(); List <ILayer> LstLayer = new List <ILayer>(); for (int i = 0; i < LstDT.Count; i++) { IFeatureClass pFeaCls = LstDT[i] as IFeatureClass; //************************************************* //////判断用户库与历史库 if (this.com_DataBase.Text == "现势库") { if (LstDT[i].Name.EndsWith("_GOH") || LstDT[i].Name.EndsWith("_GOH")) { continue; } } else if (this.com_DataBase.Text == "历史库") { if (!LstDT[i].Name.EndsWith("_GOH") && !LstDT[i].Name.EndsWith("_GOH")) { continue; } } else { continue; } //************************************************ if (pFeaCls.FeatureType == esriFeatureType.esriFTAnnotation) { continue; } if (pFeaCls.ShapeType == esriGeometryType.esriGeometryPolyline || pFeaCls.ShapeType == esriGeometryType.esriGeometryPolygon) { //只添加线与面的图层 IFeatureLayer pFeaLayer = new FeatureLayerClass(); pFeaLayer.FeatureClass = pFeaCls; ILayer pLayer = pFeaLayer as ILayer; if (!LstLayer.Contains(pLayer)) { LstLayer.Add(pLayer); } } } if (LstLayer.Count == 0) { return; } //在图层列表中添加待选择图层 this.list_JoinLayer.Items.Clear(); for (int j = 0; j < LstLayer.Count; j++) { string layername = ((LstLayer[j] as IFeatureLayer).FeatureClass as IDataset).Name; this.list_JoinLayer.Items.Add(layername); } if (rbExistdata.Checked == true) { this.com_MapFrameList.Items.Clear(); if (this.list_JoinLayer.Items.Count == 0) { return; } for (int i = 0; i < this.list_JoinLayer.Items.Count; i++) { this.com_MapFrameList.Items.Add(this.list_JoinLayer.Items[i].ToString()); } } } }
private void radioButton2_CheckedChanged(object sender, EventArgs e) { /////从外部mdb文件选择图幅结合表 Exception ex = null; this.com_MapFrameList.Text = ""; if (rbOutdata.Checked == true) { this.com_MapNoField.Items.Clear(); this.com_MapFrameList.Text = ""; this.com_MapFrameList.Items.Clear(); OpenFileDialog openFile = new OpenFileDialog(); openFile.Title = "选择任务范围"; openFile.Filter = "ESRI个人数据库(*.mdb)|*.mdb"; if (openFile.ShowDialog() != DialogResult.OK) { rbExistdata.Checked = true; return; } label_loadState.Visible = true; label_loadState.Text = "正在获取图层"; System.Windows.Forms.Application.DoEvents(); string smdbPah = openFile.FileName; MapFramepGisDT = new SysCommon.Gis.SysGisDataSet(); MapFramepGisDT.SetWorkspace(smdbPah, SysCommon.enumWSType.PDB, out ex); List <IDataset> LstDT = MapFramepGisDT.GetAllFeatureClass(); List <ILayer> LstLayer = new List <ILayer>(); for (int i = 0; i < LstDT.Count; i++) { IFeatureClass pFeaCls = LstDT[i] as IFeatureClass; if (pFeaCls.FeatureType == esriFeatureType.esriFTAnnotation) { continue; } if (pFeaCls.ShapeType == esriGeometryType.esriGeometryPolygon) { //只添面图层 IFeatureLayer pFeaLayer = new FeatureLayerClass(); pFeaLayer.FeatureClass = pFeaCls; ILayer pLayer = pFeaLayer as ILayer; if (!LstLayer.Contains(pLayer)) { LstLayer.Add(pLayer); label_loadState.Text = "正在添加图层:" + pLayer.Name; System.Windows.Forms.Application.DoEvents(); } } } if (LstLayer.Count == 0) { return; } //在图层列表中添加待选择图层 for (int j = 0; j < LstLayer.Count; j++) { string layername = ((LstLayer[j] as IFeatureLayer).FeatureClass as IDataset).Name; this.com_MapFrameList.Items.Add(layername); } if (com_MapFrameList.Items.Count > 0) { com_MapFrameList.SelectedIndex = 0; //默认选择第一个 xisheng } label_loadState.Visible = false; } }