Пример #1
0
        /// <summary>
        /// 增加位号到队列
        /// </summary>
        /// <param name="modelHead"></param>
        /// <param name="strCurrTagExp"></param>
        /// <returns></returns>
        private static bool AddTagModel(ExpHeadModel modelHead, string strCurrTagExp)
        {
            //结束上一次表达式,并加入到队列中
            ExpTagModel model = new ExpTagModel();

            try
            {
                if (HanaTech.Lib.TypeParse.IsDouble(strCurrTagExp))
                {
                    return(true);
                }

                int nCurrTagIndex = strCurrTagExp.IndexOf(":");

                if (nCurrTagIndex > 0)
                {
                    //如果当前位号有自定义位号前缀,那么获取本身的位号前缀
                    model.ExpServerName = strCurrTagExp.Substring(0, nCurrTagIndex).Trim();
                    model.ExpTagName    = strCurrTagExp.Substring(nCurrTagIndex + 1).Trim();
                }
                else
                {
                    model.ExpServerName = modelHead.ExpHeadServerName.Trim();
                    model.ExpTagName    = strCurrTagExp.Trim();
                }

                model.ExpTagKey = strCurrTagExp.Trim();

                modelHead.ExpTagModel.Add(model);
            }
            catch (Exception ex)
            {
                HanaTech.Lib.LogHelper.WriteLog(ex);
                return(false);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// 1、PHDXTB:(PHDXTB:FIC001 + PHDXTB:FIC002 + PHDXTB:FIC003) *0.2 + PHDFTB:FIC0004
        ///   返回:{PHDXTB,FIC001},{PHDXTB,FIC002},{PHDXTB,FIC003},{PHDFTB,FIC0004}
        /// 2、PHDXTB:FIC001*0.1
        ///   返回:{PHDXTB,FIC001}
        /// 3、PHDXTB:FIC001 + FIC002
        ///   返回:{PHDXTB,FIC001},{PHDXTB,FIC002}
        /// 4、PHDXTB:FIC001 + 4
        ///   返回:{PHDXTB,FIC001}
        /// </summary>
        /// <param name="strFlowChartExpression">流程图位号</param>
        /// <returns>公式包含的位号列表</returns>
        public static ExpHeadModel Run(string strFlowChartExpression)
        {
            ExpHeadModel modelHead = new ExpHeadModel();

            modelHead.ExpTagModel = new List <ExpTagModel>();
            ExpTagModel model = new ExpTagModel();

            string strCurrTagExp = "";    //当前表达式对象
            bool   isFlag        = false; //进入引号模式

            //首先截取位号前缀,截取方式
            int nExpIndex = strFlowChartExpression.IndexOf(":");

            if (nExpIndex <= 0)
            {
                return(modelHead);
            }

            //截取位号前缀
            modelHead.ExpHeadServerName = strFlowChartExpression.Substring(0, nExpIndex);
            modelHead.ExpHeadName       = strFlowChartExpression.Substring(nExpIndex + 1);
            modelHead.ExpHeadFullName   = strFlowChartExpression;

            for (int i = 0; i < modelHead.ExpHeadName.Length; i++)
            {
                string strExp = Convert.ToString(modelHead.ExpHeadName[i]);

                //if (strExp == "(" || strExp == ")")
                if (strExp == "(")
                {
                    continue;
                }

                //解决公式为:PHDLYB:FIC1001/(22+FIC1002)的场景
                if (strExp == ")" && isFlag == false && !string.IsNullOrEmpty(strCurrTagExp))
                {
                    AddTagModel(modelHead, strCurrTagExp);

                    //重新当前位号表达式
                    strCurrTagExp = "";

                    continue;
                }

                if (strExp == "\"")
                {
                    if (isFlag == false)
                    {
                        isFlag = true;
                    }
                    else
                    {
                        AddTagModel(modelHead, string.Format("{0}{1}", strCurrTagExp, strExp));

                        //重新当前位号表达式
                        strCurrTagExp = "";

                        isFlag = false;

                        continue;
                    }
                }

                //if (strExp == "+" || strExp == "-" || strExp == "*" || strExp == "/")
                if (isOperator(strExp))
                {
                    if (isFlag == false && !string.IsNullOrEmpty(strCurrTagExp))
                    {
                        AddTagModel(modelHead, strCurrTagExp);

                        //重新当前位号表达式
                        strCurrTagExp = "";

                        continue;
                    }
                    else if (isFlag == false && string.IsNullOrEmpty(strCurrTagExp))
                    {
                        continue;
                    }
                }

                strCurrTagExp += strExp;

                if (i == modelHead.ExpHeadName.Length - 1 && !string.IsNullOrEmpty(strCurrTagExp))
                {
                    AddTagModel(modelHead, strCurrTagExp);
                }
            }

            return(modelHead);
        }