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;
            }
        }
Ejemplo n.º 2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            this.Hide();
            Exception eError    = null;
            string    fieldVale = txtValue.Text.ToString();    //字段值

            if (fieldVale == "")
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "请填写关键字!");
                return;
            }
            string strMatch = cmbMatch.Text.Trim();       //匹配类型

            #region 申明表格并进行绑定

            DataTable resalutDT = ModDBOperator.CreateDataInfoTable();
            //清空表格
            if (m_Hook.DataInfoGrid.DataSource != null)
            {
                m_Hook.DataInfoGrid.DataSource = null;
            }
            //绑定
            m_Hook.DataInfoGrid.DataSource    = resalutDT;
            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;
            #endregion

            #region 连接数据库

            if (ConnStr == "")
            {
                return;
            }
            SysCommon.DataBase.SysTable pSysDB = new SysCommon.DataBase.SysTable();
            pSysDB.SetDbConnection(ConnStr, SysCommon.enumDBConType.ORACLE, SysCommon.enumDBType.ORACLE, out eError);
            if (eError != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "连接元数据库失败!");
                pSysDB.CloseDbConnection();
                return;
            }
            #endregion
            #region 首先查询成果索引表,获得符合条件的数据ID
            string dataIDStandarStr    = ""; //标准图幅过滤条件
            string dataIDNonStandarStr = ""; //非标准图幅过滤条件

            string dataIDControlStr = "";    //控制点过滤条件

            string wherestr = GetWhereStr(); //过滤条件
            string str2     = "";
            if (wherestr != "")
            {
                str2 = "select * from ProductIndexTable where " + wherestr; //查询成果索引表

                DataTable tempDt = pSysDB.GetSQLTable(str2, out eError);
                if (eError != null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "查询成果索引表失败!");
                    pSysDB.CloseDbConnection();
                    return;
                }
                for (int i = 0; i < tempDt.Rows.Count; i++)
                {
                    int  dataType = Convert.ToInt32(tempDt.Rows[i]["数据类型编号"].ToString());
                    long pDataId  = Convert.ToInt64(tempDt.Rows[i]["数据ID"].ToString());
                    if (dataType == 0)
                    {
                        //标准图幅
                        dataIDStandarStr += pDataId + ",";
                    }
                    else if (dataType == 1)
                    {
                        //非标准图幅

                        dataIDNonStandarStr += pDataId + ",";
                    }
                    else if (dataType == 2)
                    {
                        //控制点数据

                        dataIDControlStr += pDataId + ",";
                    }
                }
                if (dataIDStandarStr != "")
                {
                    dataIDStandarStr = dataIDStandarStr.Substring(0, dataIDStandarStr.Length - 1);
                }
                if (dataIDNonStandarStr != "")
                {
                    dataIDNonStandarStr = dataIDNonStandarStr.Substring(0, dataIDNonStandarStr.Length - 1);
                }
                if (dataIDControlStr != "")
                {
                    dataIDControlStr = dataIDControlStr.Substring(0, dataIDControlStr.Length - 1);
                }
            }
            #endregion
            //再次进行过滤查询表格
            string pTableName  = "";
            string restrainStr = "";
            if (cmbType.Text == "标准图幅")
            {
                pTableName = "StandardMapMDTable";
                if (dataIDStandarStr != "")
                {
                    restrainStr = dataIDStandarStr;
                }
            }
            else if (cmbType.Text == "非标准图幅")
            {
                pTableName = "NonstandardMapMDTable";
                if (dataIDNonStandarStr != "")
                {
                    restrainStr = dataIDNonStandarStr;
                }
            }
            else if (cmbType.Text == "控制点数据")
            {
                pTableName = "ControlPointMDTable";
                if (dataIDControlStr != "")
                {
                    restrainStr = dataIDControlStr;
                }
            }
            //DataTable mTable = pSysDB.GetTable(pTableName, out eError);
            //if (eError != null)
            //{
            //    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "获取源数据信息表失败!");
            //    return;
            //}

            try
            {
                if (cmbField.Text == "所有字段")
                {
                    if (m_FieldDic == null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "没有可用的字段!");
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    foreach (KeyValuePair <string, Type> pField in m_FieldDic)
                    {
                        string fName = pField.Key.Trim();
                        Type   fType = pField.Value;
                        string pSQL  = GetSQL(fName, fieldVale, fType, strMatch, out eError);
                        if (eError != null)
                        {
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        string str1 = "";
                        if (m_Hook.ProjectTree.SelectedNode.DataKey.ToString() == EnumTreeNodeType.DATABASE.ToString())
                        {
                            //如果是数据库节点没有任何限制条件
                            str1 = "select * from " + pTableName + " where " + pSQL;
                        }
                        else
                        {
                            //如果是其他的节点则肯定 有限制条件

                            if (restrainStr != "")
                            {
                                //查询到数据

                                str1 = "select * from " + pTableName + " where ID in (" + restrainStr + ") and " + pSQL;
                            }
                            else
                            {
                                //查不到数据

                                return;
                            }
                        }
                        //str1 = "select * from " + pTableName + " where ID in (" + restrainStr + ") and 数据文件名 like '%3%'";
                        DataTable pTable = pSysDB.GetSQLTable(str1, out eError);
                        if (eError != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "获取源数据信息表失败!");
                            return;
                        }
                        //DataRow[] pRowArr = mTable.Select(pSQL);

                        showResault(pSysDB, pTable, resalutDT, out eError);
                        if (eError != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", eError.Message);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                    }
                }
                else
                {
                    string fieldName = cmbField.Text.Trim();
                    Type   fieldType = m_FieldDic[fieldName];
                    string selSQL    = GetSQL(fieldName, fieldVale, fieldType, strMatch, out eError);
                    if (eError != null)
                    {
                        pSysDB.CloseDbConnection();
                        return;
                    }
                    string str1 = "";
                    if (m_Hook.ProjectTree.SelectedNode.DataKey.ToString() == EnumTreeNodeType.DATABASE.ToString())
                    {
                        //如果是数据库节点没有任何限制条件
                        str1 = "select * from " + pTableName + " where " + selSQL;
                    }
                    else
                    {
                        //如果是其他的节点则肯定 有限制条件

                        if (restrainStr != "")
                        {
                            //查询到数据

                            str1 = "select * from " + pTableName + " where " + selSQL + " and ID in (" + restrainStr + ")";
                        }
                        else
                        {
                            //查不到数据

                            m_Hook.DataInfoGrid.Update();
                            m_Hook.DataInfoGrid.Refresh();
                            return;
                        }
                    }
                    DataTable pTable = pSysDB.GetSQLTable(str1, out eError);
                    if (eError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "获取源数据信息表失败!");
                        return;
                    }
                    //DataRow[] pRowsArr = mTable.Select(selSQL);

                    showResault(pSysDB, pTable, resalutDT, out eError);
                    if (eError != null)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", eError.Message);
                        pSysDB.CloseDbConnection();
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", ex.Message);
            }
            pSysDB.CloseDbConnection();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }