public override void OnClick() { Exception eError = null; SysCommon.DataBase.SysTable pSysDB = new SysCommon.DataBase.SysTable(); try { //设置查询条件后,执行查询操作 ///连接数据库 /// //string ipStr = v_DBNode.Text.Trim();//ip //if (ipStr == "") return; //string ipStr = "//" + ipStr + "//MetaDataBase//MetaDataBase.mdb";//元数据库路径 XmlElement dbElem = v_DBNode.Tag as XmlElement; if (dbElem == null) { return; } string ipStr = dbElem.GetAttribute("MetaDBConn"); //string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ipStr + ";Persist Security Info=True";//元数据连接字符串 //pSysDB.SetDbConnection(ConnStr, SysCommon.enumDBConType.OLEDB, SysCommon.enumDBType.ACCESS, out eError); pSysDB.SetDbConnection(ipStr, SysCommon.enumDBConType.ORACLE, SysCommon.enumDBType.ORACLE, out eError); if (eError != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "连接元数据库失败!"); pSysDB.CloseDbConnection(); return; } if (v_CondiStr == "") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "请设置查询条件!"); pSysDB.CloseDbConnection(); return; } DataTable resultDT = pSysDB.GetSQLTable(v_CondiStr, out eError); if (eError != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询成果索引表出错!"); pSysDB.CloseDbConnection(); return; } ///将查询到的结果在界面上表现出来(查询结果包括数据信息和元信息) #region 将结果保存在DataTable中 DataTable tempDT = ModDBOperator.CreateDataInfoTable(); for (int i = 0; i < resultDT.Rows.Count; i++) { string dataID = ""; //数据ID string DataName = ""; //数据文件名 string projectID = ""; //项目ID string productID = ""; //产品ID string projectName = ""; //项目名称 string productName = ""; //产品名称 string scale = ""; //比例尺 string rangNO = ""; //范围号 string dataFormatID = ""; //数据格式ID string dataTypeID = ""; //数据类型ID string dataFormat = ""; //数据格式名 string dataType = ""; //数据类型名 //string saveTime = ""; //存储时间 string savePath = ""; //存储路径 string fromDate = ""; //生产日期 dataID = resultDT.Rows[i]["数据ID"].ToString().Trim(); projectID = resultDT.Rows[i]["项目ID"].ToString().Trim(); productID = resultDT.Rows[i]["产品ID"].ToString().Trim(); scale = resultDT.Rows[i]["比例尺分母"].ToString().Trim(); rangNO = resultDT.Rows[i]["范围号"].ToString().Trim(); dataFormatID = resultDT.Rows[i]["数据格式编号"].ToString().Trim(); dataTypeID = resultDT.Rows[i]["数据类型编号"].ToString().Trim(); //saveTime = resultDT.Rows[i]["存储时间"].ToString().Trim(); savePath = resultDT.Rows[i]["存储位置"].ToString().Trim(); fromDate = resultDT.Rows[i]["生产日期"].ToString().Trim(); projectName = ModDBOperator.GetProjectName(long.Parse(projectID), pSysDB, out eError); if (eError != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取项目名称出错!"); pSysDB.CloseDbConnection(); return; } productName = ModDBOperator.GetProductName(long.Parse(productID), pSysDB, out eError); if (eError != null || productName == "") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取产品名称出错!"); pSysDB.CloseDbConnection(); return; } if (dataTypeID == "") { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "为填写数据类型,请检查!"); pSysDB.CloseDbConnection(); return; } DataName = GetDataName(int.Parse(dataTypeID), long.Parse(dataID), pSysDB, out eError); if (eError != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据文件名称出错!"); pSysDB.CloseDbConnection(); return; } switch (int.Parse(dataFormatID)) { case 0: dataFormat = "DLG"; break; case 1: dataFormat = "DEM"; break; case 2: dataFormat = "DOM"; break; case 3: dataFormat = "DRG"; break; } switch (int.Parse(dataTypeID)) { case 0: dataType = "标准图幅数据"; break; case 1: dataType = "非标准图幅数据"; break; case 2: dataType = "控制点数据"; break; } DataRow newRow = tempDT.NewRow(); newRow["ID"] = dataID; newRow["项目名称"] = projectName; newRow["产品名称"] = productName; newRow["数据文件名"] = DataName; newRow["数据类型"] = dataType; newRow["比例尺"] = scale; newRow["范围号"] = rangNO; newRow["存储位置"] = savePath; //newRow["存储时间"] = saveTime; newRow["生产日期"] = fromDate; newRow["项目ID"] = projectID.ToString(); newRow["产品ID"] = productID.ToString(); tempDT.Rows.Add(newRow); } #endregion #region 将DataTable与DataGrid进行绑定 //清空表格 if (m_Hook.DataInfoGrid.DataSource != null) { m_Hook.DataInfoGrid.DataSource = null; } //绑定 m_Hook.DataInfoGrid.DataSource = tempDT; m_Hook.DataInfoGrid.ReadOnly = true; m_Hook.DataInfoGrid.Visible = true; m_Hook.DataInfoGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; for (int j = 0; j < m_Hook.DataInfoGrid.Columns.Count; j++) { //m_Hook.DataInfoGrid.Columns[j].Width = (m_Hook.DataInfoGrid.Width - 20) / m_Hook.DataInfoGrid.Columns.Count; m_Hook.DataInfoGrid.Columns[j].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; } m_Hook.DataInfoGrid.RowHeadersWidth = 20; m_Hook.DataInfoGrid.Refresh(); pSysDB.CloseDbConnection(); #endregion } catch (Exception eR) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未知错误:" + eR.Message); pSysDB.CloseDbConnection(); return; } }