Example #1
0
        /// <summary>
        /// 将规则编码和参数信息更新至巷道信息表
        /// 注意:当传入的参数为null时,说明该巷道未绑定规则编码,此时仍需更新数据库
        /// </summary>
        /// <param name="tunnelID">巷道ID</param>
        /// <param name="info">巷道绑定的所有规则ID和参数信息</param>
        /// <returns>更新成功返回True</returns>
        public static bool UpdateRuleIdsAndParams2TunnelTable(int tunnelID,
                                                              RuleInfo[] info)
        {
            string ruleIds       = "";
            string warningParams = "";

            if (info != null)
            {
                int n = info.Length;
                for (int i = 0; i < n; i++)
                {
                    RuleInfo cvtInfo =
                        PreWarningRulesBLL.ConvertOneRuleCodeAndParamInfo2DBString(info[i]);
                    ruleIds       += cvtInfo.RuleCodesStr;
                    warningParams += cvtInfo.ParamsInfoStr;
                }
            }
            string sql = "UPDATE " +
                         TunnelInfoDbConstNames.TABLE_NAME + " SET " +
                         TunnelInfoDbConstNames.RULE_IDS + "='" + ruleIds + "'," +
                         TunnelInfoDbConstNames.PRE_WARNING_PARAMS + "='" +
                         warningParams + "' WHERE " +
                         TunnelInfoDbConstNames.ID + "=" + tunnelID;
            ManageDataBase db = new
                                ManageDataBase(DATABASE_TYPE.GeologyMeasureDB);

            return(db.OperateDB(sql));
        }
Example #2
0
 public static bool ImportExcelRules2Db(string excelPath)
 {
     string[] sheetNames =
         PreWarningExcelBLL.GetExcelSheetNames(excelPath);
     if (sheetNames != null)
     {
         PreWarningRulesBLL.ClearPreWarningDB();
         int n = sheetNames.Length;
         for (int i = 0; i < n; i++)
         {
             DataSet dsSheet =
                 LibExcelHelper.importExcelSheetToDataSet(excelPath,
                                                          sheetNames[i]);
             if (dsSheet == null)
             {
                 return(false);
             }
             for (int j = 0; j < dsSheet.Tables[0].Rows.Count; j++)
             {
                 string          errorMsg = "";
                 PreWarningRules ent      =
                     PreWarningExcelBLL.ConvertExcelDataRow2PreWarningEntity(dsSheet.Tables[0].Rows[j],
                                                                             out errorMsg);
                 if (errorMsg != "")
                 {
                     if (DialogResult.Yes ==
                         MessageBox.Show("导入Excel预警规则失败:" + errorMsg +
                                         "\r\n是否继续?", "Sheet:" + sheetNames[i] + " 行:" +
                                         (j + 1).ToString(), MessageBoxButtons.YesNo))
                     {
                         continue;
                     }
                     else
                     {
                         return(false);
                     }
                 }
                 if
                 (!PreWarningRulesBLL.InsertPreWarningRulesInfo(ent))
                 {
                     if (DialogResult.Yes ==
                         MessageBox.Show("写入Excel预警规则至数据库失败!\r\n是否继续?",
                                         "Sheet:" + sheetNames[i] + " 行:" + (j +
                                                                             1).ToString(), MessageBoxButtons.YesNo))
                     {
                         continue;
                     }
                     else
                     {
                         return(false);
                     }
                 }
             }
         }
     }
     return(true);
 }
Example #3
0
        /// <summary>
        /// 获取巷道绑定的规则ID
        /// </summary>
        /// <param name="tunnelID"></param>
        /// <returns>返回该巷道绑定的所有规则ID。注意:返回值可能为null</returns>
        public static string[] GetTunnelBindingRuleIds(int tunnelID)
        {
            //获取巷道绑定的规则编码ID字符串和预警参数字符串
            string sql = "SELECT " +
                         TunnelInfoDbConstNames.RULE_IDS + " FROM " +
                         TunnelInfoDbConstNames.TABLE_NAME + " WHERE " +
                         TunnelInfoDbConstNames.ID + "=" + tunnelID;
            ManageDataBase db = new
                                ManageDataBase(DATABASE_TYPE.GeologyMeasureDB);
            DataSet ds         = db.ReturnDS(sql);
            string  allRuleIds = "";

            allRuleIds =
                ds.Tables[0].Rows[0][TunnelInfoDbConstNames.RULE_IDS].ToString();
            return(PreWarningRulesBLL.ParseRuleIds(allRuleIds));
        }
        //double CalcNearestDis(Vector3_DW pt, PreWarningSpecialDataCalcBase[] spDataEnts, out Vector3_DW outNearestPt)
        //{
        //    double minDis = 0;
        //    outNearestPt = Vector3_DW.zero;

        //    int nSpecialDataEnts = spDataEnts.Length;
        //    for (int spDataIdx = 0; spDataIdx < nSpecialDataEnts; spDataIdx++)
        //    {
        //        double tmpDis = spDataEnts[spDataIdx].CalcDis(pt, out outNearestPt);
        //        if (spDataIdx == 0)
        //        {
        //            minDis = tmpDis;
        //        }
        //        if (tmpDis < minDis)
        //        {
        //            minDis = tmpDis;
        //        }
        //    }
        //    return minDis;
        //}

        /// <summary>
        /// 计算预警结果
        /// </summary>
        /// <param name="tunnelID">巷道ID</param>
        /// <returns>预警结果列表,注:可能返回空。当该巷道未绑定预警规则时则返回null</returns>
        public PreWarningResultEntity[] CalcPreWarningResult(int tunnelID, DateTime minTime, DateTime maxTime)
        {
            List <PreWarningResultEntity> lstAllResult = new List <PreWarningResultEntity>();

            //查询巷道信息表,获取该巷道使用的规则编码和参数信息列表
            RuleCodeAndParamInfo[] allParamInfo = PreWarningRulesBLL.GetTunnelBindingRuleCodesAndParams(tunnelID);
            if (allParamInfo == null)
            {
                Alert.alert("该巷道未绑定预警规则!");
                //该巷道未绑定预警规则
                return(null);
            }

            //Hashtable htTbls = GetPreWarningDataTableAndBindingTables();
            //查询预警数据表管理表,获取所有的预警数据表和对应的预警数据字段与规则编码对应关系表信息
            DataTblAndBindingTblInfoEntity[] tableInfo = GetPreWarningDataTableAndBindingTablesInfo();
            //int nTables = htTbls.Count;
            int nTables = tableInfo.Length;

            //try
            //{
            //遍历所有的预警数据表
            //foreach (string dataTblName in htTbls.Keys)
            for (int tblIdx = 0; tblIdx < nTables; tblIdx++)
            {
                string dataTblName = tableInfo[tblIdx].DataTableName;
                //获取当前预警数据表中巷道ID、时间等符合条件的所有预警数据。
                DataSet dsData = null;
                if (tableInfo[tblIdx].NeedConstrains == true)
                {
                    dsData = GetPreWarningDatas(dataTblName, tunnelID, minTime, maxTime);
                }
                else
                {
                    dsData = GetPreWarningDatas(dataTblName);
                }
                int nDataCnt = dsData.Tables[0].Rows.Count;
                //遍历当前预警数据表中所有数据
                for (int dataIdx = 0; dataIdx < nDataCnt; dataIdx++)
                {
                    //预警数据表绑定的表名(预警数据字段与规则编码表)
                    //string bindingTableName = htTbls[dataTblName].ToString();
                    string bindingTableName = tableInfo[tblIdx].BindingTableName;
                    //读取当前预警数据表对应的预警数据字段与规则编码关系表,获取预警数据字段与规则编码关系表中所有字段名、规则编码及字段使用方式
                    //string[] fieldNames = GetPreWarningDataBindingTableFieldNames(bindingTableName);
                    BindingTableEntity[] bindingEnt = GetPreWarningDataBindingTableEntity(bindingTableName);
                    //if (fieldNames == null)
                    if (bindingEnt == null)
                    {
                        Alert.alert("表:" + bindingTableName + "中未将数据字段与规则编码绑定!");
                        continue;
                    }
                    //int nFieldCnt = fieldNames.Length;
                    int nFieldCnt = bindingEnt.Length;
                    #region 遍历所有字段名(数据)[字段使用方式为 非直接使用的 一种字段使用方式只能对应一条记录!]
                    for (int fieldIdx = 0; fieldIdx < nFieldCnt; fieldIdx++)
                    {
                        //获取当前记录中的字段
                        //string curFieldName = fieldNames[fieldIdx];
                        string curFieldName = bindingEnt[fieldIdx].ColumnName;
                        //获取当前字段对应的值
                        double fieldValue = 0;
                        try
                        {
                            //当前记录中字段的 字段使用方式 是否为:直接使用
                            if (bindingEnt[fieldIdx].UseManner == COLUMN_USE_MANNER.DIRECT_USE)
                            {
                                fieldValue = Convert.ToDouble(dsData.Tables[0].Rows[dataIdx][curFieldName]);
                            }
                            //需要进行特殊预警数据计算(如:距断层、陷落柱等距离)
                            #region 特殊数据计算
                            else
                            {
                                //根据预警数据表名称获取预警数据实体(如:断层实体、陷落柱实体)
                                PreWarningSpecialDataCalcBase calcDataEnt = GetPreWarningSpecialDataEntitiesByTblName(tableInfo[tblIdx].DataTableName, dsData.Tables[0].Rows[dataIdx]);
                                if (calcDataEnt == null)
                                {
                                    //未对该数据表进行维护
                                    //获取下一预警数据表(此处为了省事,break后会获取下一预警数据,而非下一预警数据表!理论上应该获取下一预警数据表)
                                    break;
                                }
                                //字段使用方式是否为:计算最近距离
                                if (bindingEnt[fieldIdx].UseManner == COLUMN_USE_MANNER.CALC_NEAREST_DIS)
                                {
                                    Vector3_DW ptTunnel = Vector3_DW.zero;
                                    //获取当前巷道当前位置 MARK 尚未实现

                                    Vector3_DW outPtNearest = Vector3_DW.zero;
                                    fieldValue = calcDataEnt.CalcNearestDis(ptTunnel, out outPtNearest);
                                }
                                //字段使用方式是否为:计算值(如探头瓦斯浓度增加值)
                                else if (bindingEnt[fieldIdx].UseManner == COLUMN_USE_MANNER.CALC_VALUE)
                                {
                                    fieldValue = calcDataEnt.CalcValue();
                                }
                                else
                                {
                                    Alert.alert("表:" + dataTblName + " 中数据库中录入的字段使用方式不正确!");
                                    //获取下一记录(字段名、规则编码及字段使用方式)
                                    //如果一个数据表对应多种计算方法,则需要在绑定表中添加一列标识使用哪个函数。
                                    //目前尚未处理一个数据表对应多种计算方法的情况
                                    continue;
                                }
                            }
                            #endregion
                        }//end of try
                        catch (Exception ex)
                        {
                            Alert.alert("获取表(" + bindingTableName + ")中的字段(" + curFieldName + ")对应的值出错:" + ex.Message);
                            continue;
                        }
                        //获取当前字段名对应的所有规则编码
                        //string[] ruleCodes = GetRuleCodesByFieldName(curFieldName, bindingTableName);
                        //当前规则编码在规则编码和参数信息列表中是否存在
                        //int nRuleCodeCnt = ruleCodes.Length;
                        //遍历当前字段名对应的所有规则编码(该步骤不需要!!先前算法绕弯了,速度较慢)
                        //for (int ruleCodeIdx = 0; ruleCodeIdx < nRuleCodeCnt; ruleCodeIdx++)
                        //{
                        //string curRuleCode = ruleCodes[ruleCodeIdx];
                        string curRuleCode = bindingEnt[fieldIdx].BindingWarningRules;
                        //当前规则编码在规则编码和参数信息列表中是否存在
                        RuleCodeAndParamInfo curParamsInfo = null;
                        if (!IsRuleCodeExistInTunnelParamInfo(curRuleCode, allParamInfo, out curParamsInfo))
                        {
                            //不存在
                            continue;
                        }
                        //存在
                        //读取预警规则表,获取当前规则编码的预警规则实体信息
                        PreWarningRulesEntity preWarningEnt = PreWarningRulesBLL.GetPreWarningRulesEntityByRuleCode(curRuleCode);
                        //当前字段值通过预警规则实体中的比较符(注:比较符可能含多个)与规则编码和参数信息中的参数值进行比较,比较结果是否为True。
                        if (GetCompareResultByEntAndParamInfo(fieldValue, preWarningEnt, curParamsInfo))
                        {
                            //比较结果为TRUE
                            PreWarningResultEntity oneResult = new PreWarningResultEntity();
                            if (preWarningEnt.IndicatorType != Const_WM.YES_NO_INDICATOR)
                            {
                                if (!preWarningEnt.UpdateRuleDescriptionByParams(curParamsInfo.PreWarningParams))
                                {
                                    Alert.alert("更新预警规则实体规则描述信息失败!");
                                    continue;
                                }
                            }
                            //预警规则实体信息
                            oneResult.PreWarningRulesEntity = preWarningEnt;

                            //预警数据通用信息
                            PreWarningDataCommonInfoEntity dataEnt = GetWarningDataCommonInfo(dsData.Tables[0].Rows[dataIdx], curFieldName);
                            dataEnt.TunnelID = tunnelID;

                            oneResult.WarningDataCommonInfoEnt = dataEnt;
                            //将当前记录信息及预警规则实体信息添加至预警结果列表
                            lstAllResult.Add(oneResult);
                        }
                        //}//end of 遍历当前字段名对应的所有规则编码
                    } //end of 遍历所有字段名
                    #endregion 遍历所有字段名
                }     //end of 遍历当前预警数据表中所有数据
            }         //end of 遍历所有的预警数据表
            //}//end of try
            //catch (Exception ex)
            //{
            //    Alert.alert(ex.Message);
            //}
            return(lstAllResult.ToArray());
        }//end of function