//清除选中图层 private void btnClearAll_Click(object sender, EventArgs e) { if (cbLayerName.SelectedItem == null) { MessageBox.Show("请选择要清除的图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //获取选中的图层信息 string layerName = cbLayerName.SelectedItem.ToString(); //获得临时库图层数据 string ProName = cbProName.SelectedItem.ToString(); XmlDocument xmlPro = new XmlDocument(); xmlPro.Load(ModData.v_projectDetalXML); XmlElement pTempConElement = xmlPro.SelectSingleNode("//工程[@名称='" + ProName + "']//内容//临时库//连接信息") as XmlElement; IWorkspace LTempWorkspace = ModDBOperator.GetDBInfoByXMLNode(pTempConElement, "") as IWorkspace; string TempDatasetName = xmlPro.SelectSingleNode("//工程[@名称='" + ProName + "']//内容//临时库//数据集").Attributes["名称"].Value.ToString(); List <IFeatureClass> listTempFeatureClass = clsLogicCheck.GetFeatureClass(LTempWorkspace, TempDatasetName); IFeatureClass pTempFeatureClass = GetFeatureClassByName(listTempFeatureClass, layerName); Exception errorMsg = null; clsInputTempDate.DeleteFeatureClass(pTempFeatureClass, "", layerName, out errorMsg); if (errorMsg != null) { MessageBox.Show("清除临时库图层失败!" + errorMsg.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { MessageBox.Show("成功清除临时库图层:" + layerName, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//主检查函数,针对临时库检查 ygc 2013-01-24 public static Dictionary <IFeatureClass, Dictionary <string, int> > GetLogicCheck(out Exception ex) { //获取工程配置文件 ex = null; Dictionary <IFeatureClass, Dictionary <string, int> > newdic = new Dictionary <IFeatureClass, Dictionary <string, int> >(); XmlDocument xmlPro = new XmlDocument(); xmlPro.Load(ModData.v_projectDetalXML); XmlNodeList xmlProList = xmlPro.SelectNodes("//工程"); for (int t = 0; t < xmlProList.Count; t++) { XmlElement xmlproCon = xmlProList[t].SelectSingleNode("//工程[@名称='" + xmlProList[t].Attributes["名称"].Value.ToString() + "']//内容//临时库//连接信息") as XmlElement; IWorkspace pWorkspace = ModDBOperator.GetDBInfoByXMLNode(xmlproCon, "") as IWorkspace; string DatasetName = xmlProList[t].SelectSingleNode("//工程[@名称='" + xmlProList[t].Attributes["名称"].Value.ToString() + "']//内容//临时库//数据集").Attributes["名称"].Value.ToString(); List <IFeatureClass> listfeatureClass = GetFeatureClass(pWorkspace, DatasetName); Dictionary <string, string> dicCondition = GetCheckCondition(); for (int i = 0; i < listfeatureClass.Count; i++) { Dictionary <string, int> dicCheckResult = CheckFeautreClass(listfeatureClass[i], dicCondition, out ex); newdic.Add(listfeatureClass[i], dicCheckResult); } } return(newdic); }
/// <summary> /// 初始化数据库连接 /// </summary> private void InitialDB(out Exception err) { err = null; //cyf 20110625 modify List <IDataset> lstDataset = new List <IDataset>(); XmlDocument xml = new XmlDocument(); if (!File.Exists(ModData.v_projectDetalXML)) { err = new Exception(ModData.v_projectDetalXML + "不存在"); return; } xml.Load(ModData.v_projectDetalXML); XmlElement elementTemp = xml.SelectSingleNode("//现势库/连接信息[@类型!='']") as XmlElement;//取得矢量数据 //end IWorkspace TempWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace; if (TempWorkSpace == null) { err = new Exception("连接数据库失败!"); return; } XmlElement elementTemp2 = xml.SelectSingleNode("//现势库/数据集[@名称!='']") as XmlElement; string datasetname = elementTemp2.GetAttribute("名称"); SysCommon.Gis.SysGisDataSet sysGisDataset = new SysCommon.Gis.SysGisDataSet(TempWorkSpace); //cyf 20110625 modify: IFeatureDataset dataset = sysGisDataset.GetFeatureDataset(datasetname, out err); //end if (err != null) { err = new Exception("获取数据失败!"); return; } lstDataset = sysGisDataset.GetFeatureClass(dataset); if (lstDataset == null || lstDataset.Count == 0) { err = new Exception("库体要素类为空!"); } m_LstDataset = lstDataset; }
//cyf 2011065 modify public override void OnClick() { Exception err = null; /////获取工程项目名称 DevComponents.AdvTree.Node ProjectNode = new DevComponents.AdvTree.Node(); ProjectNode = m_Hook.ProjectTree.SelectedNode; while (ProjectNode.Parent != null) { ProjectNode = ProjectNode.Parent; } //cyf 20110625 add: DevComponents.AdvTree.Node DBNode = new DevComponents.AdvTree.Node(); //数据库树节点 //获取数据库节点 DBNode = m_Hook.ProjectTree.SelectedNode; while (DBNode.Parent != null && DBNode.DataKeyString != "DB") { DBNode = DBNode.Parent; } if (DBNode.DataKeyString != "DB") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据库节点失败!"); return; } DevComponents.AdvTree.Node DtSetNode = new DevComponents.AdvTree.Node(); //数据集树节点 #region 获取数据集节点 if (DBNode.Text == "现势库" || DBNode.Text == "历史库" || DBNode.Text == "临时库") //.DataKeyString == "现势库" { //获取数据集节点 DtSetNode = m_Hook.ProjectTree.SelectedNode; while (DtSetNode.Parent != null && DtSetNode.DataKeyString != "FD") { DtSetNode = DtSetNode.Parent; } if (DtSetNode.DataKeyString != "FD") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集节点失败!"); return; } } else if (DBNode.Text == "栅格数据库") { //cyf 20110626 add:获取栅格数据库图层节点 DtSetNode = m_Hook.ProjectTree.SelectedNode; if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "RC") { while (DtSetNode.Parent != null && DtSetNode.DataKeyString != "RC") { DtSetNode = DtSetNode.Parent; } if (DtSetNode.DataKeyString != "RC") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集节点失败!"); return; } } else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "RD") { while (DtSetNode.Parent != null && DtSetNode.DataKeyString != "RD") { DtSetNode = DtSetNode.Parent; } if (DtSetNode.DataKeyString != "RD") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集节点失败!"); return; } } //end } #endregion XmlElement elementTemp = (DBNode.Tag as XmlElement).SelectSingleNode(".//连接信息") as XmlElement; IWorkspace TempWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace; if (TempWorkSpace == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接数据库失败!"); return; } //cyf 20110625 modify ILayer player = null; //ILayer player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, m_Hook.ProjectTree.SelectedNode.DataKeyString + "_" + ProjectNode.Text); if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FD") { player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, m_Hook.ProjectTree.SelectedNode.Text + "_" + ProjectNode.Text); } else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FC") { player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, DtSetNode.Text + "_" + ProjectNode.Text); } //cyf 20110626 add:添加获取栅格数据图层 else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "RC" || m_Hook.ProjectTree.SelectedNode.DataKeyString == "RD") { //获取栅格数据图层 player = ModDBOperator.GetGroupLayer(m_Hook.MapControl, DtSetNode.Text + "_" + ProjectNode.Text); } //end if (player != null) { m_Hook.MapControl.Map.DeleteLayer(player); m_Hook.TOCControl.Update(); } //end IGroupLayer pGroupLayer = new GroupLayerClass(); //cyf 20110625 if (DBNode.Text == "现势库" || DBNode.Text == "历史库" || DBNode.Text == "临时库") //.DataKeyString == "现势库" { /////////若为历史库管理状态退出该状态,加载现势库 m_Hook.MapControl.Map.ClearLayers(); Plugin.Interface.ICommandRef HisBaseCommand = null; bool GetSeccess = Plugin.ModuleCommon.DicCommands.TryGetValue("GeoDBATool.ControlsDBHistoryManage", out HisBaseCommand); if (GetSeccess) { HisCommand = HisBaseCommand as ControlsDBHistoryManage; if (HisCommand.Checked) { HisCommand.IsHistory = false;//判断是不是历史库点的加载,若是现势库就卸载掉历史库,若是历史库就不操作 HisCommand.OnClick(); } } #region 加载数据 SysCommon.Gis.SysGisDataSet sysGisDataset = new SysCommon.Gis.SysGisDataSet(TempWorkSpace); //cyf 20110625 modify IFeatureDataset featureDataset = null; //数据集 if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FD") { featureDataset = sysGisDataset.GetFeatureDataset(m_Hook.ProjectTree.SelectedNode.Text, out err); if (err != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集失败,请检查该数据集是否存在!"); return; } pGroupLayer.Name = m_Hook.ProjectTree.SelectedNode.Text + "_" + ProjectNode.Text; } else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FC") { featureDataset = sysGisDataset.GetFeatureDataset(DtSetNode.Text, out err); if (err != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集失败!"); return; } pGroupLayer.Name = DtSetNode.Text + "_" + ProjectNode.Text; } //end List <IDataset> lstDataset = sysGisDataset.GetFeatureClass(featureDataset); //遍历要素类,加载图层 string dbType = ""; string userName = "";//用户名 userName = elementTemp.GetAttribute("用户"); dbType = elementTemp.GetAttribute("类型"); foreach (IDataset dataset in lstDataset) { IFeatureClass pFeatureClass = dataset as IFeatureClass; if (pFeatureClass == null) { continue; } IFeatureLayer pFeatureLayer = new FeatureLayerClass(); if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) { pFeatureLayer = new FDOGraphicsLayerClass(); } pFeatureLayer.FeatureClass = pFeatureClass; if (dbType.Trim().ToUpper() == "SDE") { //cyf 20110706 modify:修改为不去掉用户名 changed by xisheng 0906 去掉用户名 if (dataset.Name.ToUpper().Contains(userName.Trim().ToUpper())) { //SDE用户图层名去掉用户名 pFeatureLayer.Name = dataset.Name.Substring(userName.Trim().Length + 1); } else { pFeatureLayer.Name = dataset.Name; } //end } else { pFeatureLayer.Name = dataset.Name; } //cyf 20110625 modify if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FC") { //加载指定的图层 if (m_Hook.ProjectTree.SelectedNode.Text != pFeatureLayer.Name) { continue; } } else if (m_Hook.ProjectTree.SelectedNode.DataKeyString == "FD") { //加载具备权限的图层 XmlElement feaclsElem = null; try { feaclsElem = (m_Hook.ProjectTree.SelectedNode.Tag as XmlElement).SelectSingleNode(".//图层名") as XmlElement; } catch { } if (feaclsElem != null) { if (!feaclsElem.GetAttribute("名称").Contains(pFeatureLayer.Name)) { //若不具备数据权限,则不进行加载 continue; } } } //end pGroupLayer.Add(pFeatureLayer as ILayer); } m_Hook.MapControl.Map.AddLayer(pGroupLayer); #endregion } //else if (DBNode.Text == "历史库") //{ // //历史库加载 // //ModDBOperator.WriteLog("GetCommand"); // Plugin.Interface.ICommandRef HisBaseCommand = null; // bool GetSeccess = Plugin.ModuleCommon.DicCommands.TryGetValue("GeoDBATool.ControlsDBHistoryManage", out HisBaseCommand); // if (GetSeccess) // { // HisCommand = HisBaseCommand as ControlsDBHistoryManage; // //判断是不是历史库点的加载,若是现势库就卸载掉历史库,若是历史库就不操作 // HisCommand.IsHistory = true; // HisCommand.OnClick(); // if (HisCommand.MyControlHistoryBar != null) // { // string HisDBType = elementTemp.GetAttribute("类型"); // string[] strTemp = new string[] { elementTemp.GetAttribute("服务器"), elementTemp.GetAttribute("服务名"), elementTemp.GetAttribute("数据库"), elementTemp.GetAttribute("用户"), elementTemp.GetAttribute("密码"), elementTemp.GetAttribute("版本") }; // HisCommand.MyControlHistoryBar.AddHistoryData(strTemp, HisDBType); // } // } //} //加载sde数据后,注册版本 //if (dbType.Trim().ToUpper() == "SDE") //{ // IDataset pFeaDt = featureDataset as IDataset; // if (pFeaDt != null) // { // IVersionedObject pVerObj = pFeaDt as IVersionedObject; // if (!pVerObj.IsRegisteredAsVersioned) // { // //注册版本 // pVerObj.RegisterAsVersioned(true); // } // else // { // pVerObj.RegisterAsVersioned(false); // } // } //} else if (DBNode.Text == "栅格数据库") { //栅格数据加载,分为两种情况:栅格数据集、栅格编目 //cyf 20110625 modify pGroupLayer.Name = m_Hook.ProjectTree.SelectedNode.Text + "_" + ProjectNode.Text; //end string rasterDBType = (m_Hook.ProjectTree.SelectedNode.Tag as XmlElement).GetAttribute("存储类型"); elementTemp = (DBNode.Tag as XmlElement).SelectSingleNode(".//连接信息") as XmlElement; //cyf 20110626 TempWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace; if (TempWorkSpace == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接数据库失败!"); return; } IRasterWorkspaceEx pRasterWS = TempWorkSpace as IRasterWorkspaceEx; if (pRasterWS == null) { return; } //string feaclsName = (elementTemp.FirstChild as XmlElement).GetAttribute("名称"); string feaclsName = m_Hook.ProjectTree.SelectedNode.Text; try { if (rasterDBType.Trim() == "栅格编目") { //栅格编目数据加载 IRasterCatalog pRasterCatalog = pRasterWS.OpenRasterCatalog(feaclsName); IGdbRasterCatalogLayer pGDBRCLayer = new GdbRasterCatalogLayerClass(); if (!pGDBRCLayer.Setup(pRasterCatalog as ITable)) { return; } IFeatureLayer mFeaLayer = pGDBRCLayer as IFeatureLayer; pGroupLayer.Add(mFeaLayer as ILayer); //IFeatureClass pFeaCls = pRasterCatalog as IFeatureClass; //if (pFeaCls == null) return; //IFeatureCursor pFeaCursor=pFeaCls.Search(null,false); //if(pFeaCursor==null) return; //IFeature pFea=pFeaCursor.NextFeature(); //while (pFea != null) //{ // IRasterCatalogItem pRCItem = pFea as IRasterCatalogItem; // IRasterDataset pRasterDt = pRCItem.RasterDataset; // IRasterLayer mRasterLayer = new RasterLayerClass(); // mRasterLayer.CreateFromDataset(pRasterDt); // if (mRasterLayer == null) return; // pGroupLayer.Add(mRasterLayer as ILayer); // pFea = pFeaCursor.NextFeature(); // //IFeatureLayer pFeaLayer = new FeatureLayerClass(); // //pFeaLayer.FeatureClass = pFeaCls as IFeatureClass; // //pFeaLayer.Name = feaclsName; // //pGroupLayer.Add(pFeaLayer as ILayer); //} } else if (rasterDBType.Trim() == "栅格数据集") { //栅格数据集加载 IRasterDataset pRasterDataset = pRasterWS.OpenRasterDataset(feaclsName); //IRasterPyramid pRasterPyramid = pRasterDataset as IRasterPyramid; //if(!pRasterPyramid.Present) //{ // if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "未构建金字塔,是否构建金字塔?")) // { // pRasterPyramid.Create(); // } //} IRasterLayer pRasterLayer = new RasterLayerClass(); pRasterLayer.CreateFromDataset(pRasterDataset); if (pRasterLayer == null) { return; } pGroupLayer.Add(pRasterLayer as ILayer); } m_Hook.MapControl.Map.AddLayer(pGroupLayer); } 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); } //******************************************************************** return; } } //对图层进行排序 SysCommon.Gis.ModGisPub.LayersCompose(m_Hook.MapControl); //符号化 去掉加载的符号化 20111025 席胜 //GeoUtilities.ControlsRenderLayerByMxd RenderLayerByMxd = new GeoUtilities.ControlsRenderLayerByMxd(); //RenderLayerByMxd.OnCreate(m_Hook); //RenderLayerByMxd.OnClick(); }
private void btnOK_Click(object sender, EventArgs e) { Exception eError = null; //判断源数据是否连接 if (this.textBoxUptRange.Text == "") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "请设置更新范围数据连接"); return; } if (this.textBoxUptData.Text == "") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "请设置更新数据连接"); return; } ClsBatchUpdate pClsBatchUpdate = new ClsBatchUpdate(); //从数据树图中获取现势库和历史库节点 DevComponents.AdvTree.Node pCurNode = pClsBatchUpdate.GetNodeOfProjectTree(v_AppGIS.ProjectTree, "DB", "现势库"); DevComponents.AdvTree.Node pHisNode = pClsBatchUpdate.GetNodeOfProjectTree(v_AppGIS.ProjectTree, "DB", "历史库"); if (pCurNode == null || pHisNode == null) { return; } //获取现势库连接 XmlElement elementTemp = (pCurNode.Tag as XmlElement).SelectSingleNode(".//连接信息") as XmlElement; IWorkspace pCurWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace; if (pCurWorkSpace == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接现势库失败!"); return; } //获取历史库连接 elementTemp = (pHisNode.Tag as XmlElement).SelectSingleNode(".//连接信息") as XmlElement; IWorkspace pHisWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace; if (pHisWorkSpace == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接历史库失败!"); return; } //获取更新数据库连接 SysCommon.Gis.SysGisDataSet pUptSysGisDT = new SysCommon.Gis.SysGisDataSet();//更新库连接 SysCommon.enumWSType pUptType = SysCommon.enumWSType.PDB; if (this.textBoxUptData.Tag == "PDB") { pUptType = SysCommon.enumWSType.PDB; } else if (this.textBoxUptData.Tag == "GDB") { pUptType = SysCommon.enumWSType.GDB; } Exception ERR0 = null; pUptSysGisDT.SetWorkspace(this.textBoxUptData.Text, pUptType, out ERR0); IWorkspace pUptWorkSpace = pUptSysGisDT.WorkSpace; //获取更新范围 IGeometry pUptGeometry = null; pUptGeometry = SysCommon.ModPublicFun.GetPolyGonFromFile(this.textBoxUptRange.Text); this.Hide(); FrmProcessBar frmbar = new FrmProcessBar(); frmbar.Show(); if (pUptGeometry != null) { pClsBatchUpdate.DoBatchUpdate(pCurWorkSpace, pHisWorkSpace, pUptWorkSpace, pUptGeometry, pCurNode, pHisNode, frmbar); } frmbar.Close(); this.Close(); }
//将数据导入到临时库中 private void btnDoInput_Click(object sender, EventArgs e) { if (dgvInputList.Rows.Count == 0) { MessageBox.Show("请先添加要入库的文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } for (int i = 0; i < dgvInputList.Rows.Count; i++) { #region 获取源图层 //获取源文件名称和图层名称 string SourceFile = dgvInputList.Rows[i].Cells["SourceLayerName"].Value.ToString(); IFeatureClass pSourceFeatureClass = null; if (SourceFile.Contains("--")) { string filePath = SourceFile.Substring(0, SourceFile.IndexOf("--")); string layerName = SourceFile.Substring(SourceFile.IndexOf("--") + 2, SourceFile.Length - SourceFile.IndexOf("--") - 2); pSourceFeatureClass = GetFeatureClassByName(filePath, layerName); } else { string layerName1 = SourceFile.Substring(SourceFile.LastIndexOf("\\") + 1, SourceFile.Length - 5 - SourceFile.LastIndexOf("\\")); pSourceFeatureClass = GetFeatureClassByName(SourceFile, layerName1); } //通过工程名称和表格目标层,获取目标图层 if (!File.Exists(ModData.v_projectDetalXML)) { MessageBox.Show("无法获取工程配置文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #endregion #region 获取目标图层 string ProName = dgvInputList.Rows[i].Cells["ProName"].Value.ToString(); string targetLayerName = dgvInputList.Rows[i].Cells["TargetLayerName"].FormattedValue.ToString(); XmlDocument xmlPro = new XmlDocument(); xmlPro.Load(ModData.v_projectDetalXML); XmlElement xmlConElement = xmlPro.SelectSingleNode("//工程[@名称='" + ProName + "']//内容//临时库//连接信息") as XmlElement; IWorkspace pTargetWorkspace = ModDBOperator.GetDBInfoByXMLNode(xmlConElement, "") as IWorkspace; XmlNode xmlDataset = xmlPro.SelectSingleNode("//工程[@名称='" + ProName + "']//内容//临时库//数据集"); string datasetName = xmlDataset.Attributes["名称"].Value.ToString(); IFeatureClass pTargetFeatureClass = GetFeatureClass(pTargetWorkspace, targetLayerName, datasetName); #endregion dgvInputList.Rows[i].Cells["InputState"].Value = "正在入库"; Exception error = null; List <string> listXianCode = GetUniqueValues(pSourceFeatureClass, "xian", ""); List <string> listExitCode = null; //循环判断临时库中是否存在该县的数据 if (listXianCode == null || listXianCode.Count == 0) { CopySourceFeatureClass(pSourceFeatureClass, pTargetFeatureClass, null, "", out error); } else { string xianName = CheckXianData(pTargetFeatureClass, listXianCode, "xian", out listExitCode); if (xianName != "") { if (MessageBox.Show("当前临时库已存在:" + xianName + "的数据,是否覆盖?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes) { //清空已有县数据 for (int t = 0; t < listExitCode.Count; t++) { string tableName = pTargetFeatureClass.AliasName; tableName = tableName.Substring(tableName.IndexOf(".") + 1, tableName.Length - tableName.IndexOf(".") - 1); clsInputTempDate.DeleteFeatureClass(pTargetFeatureClass, "xian='" + listExitCode[t] + "'", tableName, out error); CopySourceFeatureClass(pSourceFeatureClass, pTargetFeatureClass, null, "", out error); } } else { return; } } else { CopySourceFeatureClass(pSourceFeatureClass, pTargetFeatureClass, null, "", out error); } } if (error != null) { dgvInputList.Rows[i].Cells["InputState"].Value = "入库失败"; dgvInputList.Rows[i].Cells["InputLog"].Value = error.Message.ToString(); } else { dgvInputList.Rows[i].Cells["InputState"].Value = "入库成功"; } } MessageBox.Show("完成入库操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
//added by chulili 2012-01-12 modify public override void OnClick() { Exception err = null; /////获取工程项目名称 DevComponents.AdvTree.Node vSelectedNode = null; vSelectedNode = m_Hook.ProjectTree.SelectedNode; DevComponents.AdvTree.Node ProjectNode = null; ProjectNode = vSelectedNode; while (ProjectNode.Parent != null) { ProjectNode = ProjectNode.Parent; } //cyf 20110625 add: DevComponents.AdvTree.Node DBNode = null; //数据库树节点 //获取数据库节点 DBNode = vSelectedNode; while (DBNode.Parent != null && DBNode.DataKeyString != "DB") { DBNode = DBNode.Parent; } if (DBNode.DataKeyString != "DB") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据库节点失败!"); return; } DevComponents.AdvTree.Node DtSetNode = vSelectedNode; //数据集树节点 if (DBNode.Text != "现势库") { return; } XmlElement elementTemp = (DBNode.Tag as XmlElement).SelectSingleNode(".//连接信息") as XmlElement; IWorkspace TempWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace; if (TempWorkSpace == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "连接数据库失败!"); return; } SysCommon.Gis.SysGisDataSet sysGisDataset = new SysCommon.Gis.SysGisDataSet(TempWorkSpace); //cyf 20110625 modify IFeatureDataset featureDataset = null; //数据集 if (vSelectedNode.DataKeyString == "FD") { featureDataset = sysGisDataset.GetFeatureDataset(vSelectedNode.Text, out err); if (err != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集失败,请检查该数据集是否存在!"); return; } } if (featureDataset != null) { bool bRes = InitialHisDBstructure(featureDataset); if (bRes) { MessageBox.Show("初始化历史库结构成功!"); } } }
private void btnInputTempData_Click(object sender, EventArgs e) { if (cbProNameList.SelectedItem == null) { MessageBox.Show("请选择要入库的工程!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #region 获取库中要素 string ProName = cbProNameList.SelectedItem.ToString(); //通过配置文件获取成果库图层集合 XmlDocument xmlPro = new XmlDocument(); xmlPro.Load(ModData.v_projectDetalXML); XmlElement xmlCHGConElement = xmlPro.SelectSingleNode("//工程[@名称='" + ProName + "']//内容//现势库//连接信息") as XmlElement; IWorkspace pCHGWorkspace = ModDBOperator.GetDBInfoByXMLNode(xmlCHGConElement, "") as IWorkspace; //获得成果库数据集名称 string CHGDatasetName = xmlPro.SelectSingleNode("//工程[@名称='" + ProName + "']//内容//现势库//数据集").Attributes["名称"].Value.ToString(); //获得成果库图层数据 List <IFeatureClass> listCHGFeatureClass = clsLogicCheck.GetFeatureClass(pCHGWorkspace, CHGDatasetName); //获得历史库图层数据 XmlElement pLSConElement = xmlPro.SelectSingleNode("//工程[@名称='" + ProName + "']//内容//历史库//连接信息") as XmlElement; IWorkspace pLSWorkspace = ModDBOperator.GetDBInfoByXMLNode(pLSConElement, "") as IWorkspace; string LSDatasetName = xmlPro.SelectSingleNode("//工程[@名称='" + ProName + "']//内容//历史库//数据集").Attributes["名称"].Value.ToString(); List <IFeatureClass> listLSFeatureClass = clsLogicCheck.GetFeatureClass(pLSWorkspace, LSDatasetName); //获得临时库图层数据 XmlElement pTempConElement = xmlPro.SelectSingleNode("//工程[@名称='" + ProName + "']//内容//临时库//连接信息") as XmlElement; IWorkspace LTempWorkspace = ModDBOperator.GetDBInfoByXMLNode(pTempConElement, "") as IWorkspace; string TempDatasetName = xmlPro.SelectSingleNode("//工程[@名称='" + ProName + "']//内容//临时库//数据集").Attributes["名称"].Value.ToString(); List <IFeatureClass> listTempFeatureClass = clsLogicCheck.GetFeatureClass(LTempWorkspace, TempDatasetName); if (listCHGFeatureClass.Count == 0) { MessageBox.Show("无法获取成果库图层信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #endregion Exception ErrorMSG; prbInputTempData.Maximum = listCHGFeatureClass.Count; prbInputTempData.Minimum = 0; prbInputTempData.Step = 1; prbInputTempData.Value = 0; //进行入库操作 for (int i = 0; i < listCHGFeatureClass.Count; i++) { lblState.Text = "正在导入图层" + listCHGFeatureClass[i].AliasName; prbInputTempData.Value = i; //将成果库数据导入到历史库中 IFeatureClass pCHGFeatureClass = listCHGFeatureClass[i]; string newFeatureName = GetNewString(pCHGFeatureClass.AliasName); IFeatureClass pLSFeatureClass = GetFeatureClassByName(listLSFeatureClass, newFeatureName + "_GOH"); clsInputTempDate.CopySourceFeatureClass(pCHGFeatureClass, pLSFeatureClass, null, "", out ErrorMSG); if (ErrorMSG != null) { MessageBox.Show("写入历史库出错!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //将成果库中数据删除 clsInputTempDate.DeleteFeatureClass(pCHGFeatureClass, "", pCHGFeatureClass.AliasName, out ErrorMSG); if (ErrorMSG != null) { MessageBox.Show("删除成果库出错!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //将临时库中数据导入到成果库中 IFeatureClass pTempFeatureClass = GetFeatureClassByName(listTempFeatureClass, newFeatureName + "_GOT"); clsInputTempDate.CopySourceFeatureClass(pTempFeatureClass, pCHGFeatureClass, null, "", out ErrorMSG); if (ErrorMSG != null) { MessageBox.Show("写入成果库出错!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //将临时库中数据删除 clsInputTempDate.DeleteFeatureClass(pTempFeatureClass, "", pTempFeatureClass.AliasName, out ErrorMSG); if (ErrorMSG != null) { MessageBox.Show("删除临时库出错!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } MessageBox.Show("成功导入临时库!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
//added by chulili 20110719 根据数据集加载历史数据 public void AddHistoryDataByFD(string[] strTemp, string strType) { Mapcontrol.ClearLayers(); Toccontrol.Update(); Application.DoEvents(); //加载历史数据 Exception err = null; SysCommon.Gis.SysGisDataSet sourceSysGisDataSet = new SysCommon.Gis.SysGisDataSet(); switch (strType) { case "SDE": sourceSysGisDataSet.SetWorkspace(strTemp[0], strTemp[1], strTemp[2], strTemp[3], strTemp[4], strTemp[5], out err); break; case "PDB": sourceSysGisDataSet.SetWorkspace(strTemp[2], SysCommon.enumWSType.PDB, out err); break; case "GDB": sourceSysGisDataSet.SetWorkspace(strTemp[2], SysCommon.enumWSType.GDB, out err); break; } if (err != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("连接数据库失败", "原因:" + err.Message); return; } //cyf 20110706 add DevComponents.AdvTree.Node ProjectNode = new DevComponents.AdvTree.Node(); ProjectNode = m_ProTree.SelectedNode; while (ProjectNode.Parent != null) { ProjectNode = ProjectNode.Parent; } //cyf 20110625 add: DevComponents.AdvTree.Node DBNode = new DevComponents.AdvTree.Node(); //数据库树节点 //获取数据库节点 DBNode = m_ProTree.SelectedNode; while (DBNode.Parent != null && DBNode.DataKeyString != "DB") { DBNode = DBNode.Parent; } if (DBNode.DataKeyString != "DB") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据库节点失败!"); return; } DevComponents.AdvTree.Node DtSetNode = new DevComponents.AdvTree.Node(); //数据集树节点 if (DBNode.Text == "现势库" || DBNode.Text == "历史库") //.DataKeyString == "现势库" { //获取数据集节点 DtSetNode = m_ProTree.SelectedNode; while (DtSetNode.Parent != null && DtSetNode.DataKeyString != "FD") { DtSetNode = DtSetNode.Parent; } if (DtSetNode.DataKeyString != "FD") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集节点失败!"); return; } } //end //added by chulili 20110719 XmlElement elementTemp = (DBNode.Tag as XmlElement).SelectSingleNode(".//连接信息") as XmlElement; IWorkspace TempWorkSpace = ModDBOperator.GetDBInfoByXMLNode(elementTemp, "") as IWorkspace; SysCommon.Gis.SysGisDataSet sysGisDataset = new SysCommon.Gis.SysGisDataSet(TempWorkSpace); IFeatureDataset featureDataset = null; //数据集 IGroupLayer pGroupLayer = new GroupLayerClass(); if (m_ProTree.SelectedNode.DataKeyString == "FD") { featureDataset = sysGisDataset.GetFeatureDataset(m_ProTree.SelectedNode.Text, out err); if (err != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集失败,请检查该数据集是否存在!"); return; } pGroupLayer.Name = m_ProTree.SelectedNode.Text + "_" + ProjectNode.Text; } else if (m_ProTree.SelectedNode.DataKeyString == "FC") { featureDataset = sysGisDataset.GetFeatureDataset(DtSetNode.Text, out err); if (err != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据集失败!"); return; } pGroupLayer.Name = DtSetNode.Text + "_" + ProjectNode.Text; } List <IDataset> lstDataset = sysGisDataset.GetFeatureClass(featureDataset); //end added by chulili //List<string> lstNames = sourceSysGisDataSet.GetFeatureClassNames(); XmlElement feaclsElem = null; try { feaclsElem = (m_ProTree.SelectedNode.Tag as XmlElement).SelectSingleNode(".//图层名") as XmlElement; } catch { } foreach (IDataset dataset in lstDataset) { IFeatureClass pFeatureClass = dataset as IFeatureClass; if (pFeatureClass == null) { continue; } IFeatureLayer pFeatureLayer = new FeatureLayerClass(); if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) { pFeatureLayer = new FDOGraphicsLayerClass(); } pFeatureLayer.FeatureClass = pFeatureClass; pFeatureLayer.Name = dataset.Name; if (m_ProTree.SelectedNode.DataKeyString == "FC") { //加载指定的图层 if (m_ProTree.SelectedNode.Text != pFeatureLayer.Name) { continue; } } else if (m_ProTree.SelectedNode.DataKeyString == "FD") { if (feaclsElem != null) { if (!feaclsElem.GetAttribute("名称").Contains(pFeatureLayer.Name)) { //若不具备数据权限,则不进行加载 continue; } } } pGroupLayer.Add(pFeatureLayer as ILayer); } Mapcontrol.Map.AddLayer(pGroupLayer); SysCommon.Gis.ModGisPub.LayersCompose(Mapcontrol); InitialSliderItem(Mapcontrol); }