Exemplo n.º 1
0
 public MemTag(MemTagModel memTagModel, string tagname, int? dec, string formula, bool needSaveToDb)
 {
     this.memTagModel = memTagModel;
     this.TagType = MemTagType.Numeric;
     this.TagName = tagname;
     this.Formula = formula;
     this.Dec = dec;
 }
Exemplo n.º 2
0
        public object DoCal(MemTagModel tm)
        {
            OperFactory of = new OperFactory();
            /// 算术符栈
            ArrayList HList = new ArrayList();
            /// 数值栈
            ArrayList Vlist = new ArrayList();

            foreach (var formaItem in this)
            {
                if (formaItem.Typ == FormulaItemType.Number)
                {
                    //如果是数值,则写入数据栈
                    Vlist.Add(formaItem.Name);
                }
                else if (formaItem.Typ == FormulaItemType.Tag)
                {
                    double?val = tm.GetTagValue(formaItem.Name);
                    Vlist.Add(val == null ? "0" : val.ToString());
                }
                else if (formaItem.Name != "=")
                {
                    string opStr = formaItem.Name;

                    while (HList.Count > 0)
                    {
                        //比较优先级
                        if (of.MoreThen(HList[HList.Count - 1].ToString(), opStr))
                        {
                            if (HList[HList.Count - 1].ToString().Equals("("))
                            {
                                if (opStr.Equals(")")) //符号是否可以对消?
                                {
                                    HList.RemoveAt(HList.Count - 1);
                                    if (HList.Count > 0)
                                    {
                                        opStr = HList[HList.Count - 1].ToString();
                                        HList.RemoveAt(HList.Count - 1);
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            else
                            {
                                //如果新来操作符优先级低,则计算前面的运算符
                                IOper p = of.CreateOper(HList[HList.Count - 1].ToString());
                                if (p != null)
                                {
                                    Vlist[Vlist.Count - 2] = p.Oper(Vlist[Vlist.Count - 2], Vlist[Vlist.Count - 1]);
                                    HList.RemoveAt(HList.Count - 1);
                                    Vlist.RemoveAt(Vlist.Count - 1);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (!opStr.Equals(""))
                    {
                        HList.Add(opStr);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (HList.Count > 0)
            {
                IOper p = of.CreateOper(HList[HList.Count - 1].ToString());
                if (p != null)
                {
                    Vlist[Vlist.Count - 2] = p.Oper(Vlist[Vlist.Count - 2], Vlist[Vlist.Count - 1]);
                    HList.RemoveAt(HList.Count - 1);
                    Vlist.RemoveAt(Vlist.Count - 1);
                }
            }
            return(Vlist[0]);
        }
Exemplo n.º 3
0
 public MemTag(MemTagModel memTagModel, string tagname,string strval,bool needSaveToDb)
 {
     this.memTagModel = memTagModel;
     this.TagType = MemTagType.String;
     this.TagName = tagname;
 }