示例#1
0
        public IBxFormula GetFormula(int srcIndex, int trgIndex)
        {
            if (srcIndex == trgIndex)
            {
                return(ParsedFormula.s_sameUnitFormula);
            }

            _SrcUnitFormulas formulas = m_formulas[srcIndex];
            IBxFormula       fml      = formulas.GetFormula(trgIndex);

            if (fml == null)
            {
                if (trgIndex == m_nDefaultUnitIndex)
                {
                    throw new Exception(string.Format("not find the convertion between {0} to default unit {1} \n", this[srcIndex].ID, this[m_nDefaultUnitIndex].ID));
                }

                if (srcIndex == m_nDefaultUnitIndex)
                {
                    IBxFormula temp = GetFormula(trgIndex, srcIndex);
                    if (!(temp is ParsedFormula))
                    {
                        throw new Exception(string.Format("It must be a ParsedFormula between {0] to defaultUnit {1}\n", this[trgIndex].ID, this[srcIndex].ID));
                    }
                    fml = ParsedFormula.Inverse((ParsedFormula)temp);
                    formulas.SetFormula(trgIndex, fml);
                }
                else
                {
                    IBxFormula fml1 = GetFormula(srcIndex, m_nDefaultUnitIndex);
                    IBxFormula fml2 = GetFormula(m_nDefaultUnitIndex, trgIndex);
                    fml = new CombinedFormula(fml1, fml2);
                    formulas.SetFormula(trgIndex, fml);
                }
            }
            return(fml);
        }
示例#2
0
        public IBxFormula GetFormula(int srcIndex, int trgIndex)
        {
            if (srcIndex == trgIndex)
            {
                return(ParsedFormula.s_sameUnitFormula);
            }

            BxSrcUnitFormulas formulas = _formulas[srcIndex];
            IBxFormula        fml      = formulas.GetFormula(trgIndex);

            if (fml == null)
            {
                //取反向的转换关系
                ParsedFormula tempFml = _formulas[trgIndex].GetFormula(srcIndex) as ParsedFormula;
                if (tempFml != null)
                {
                    fml = ParsedFormula.Inverse(tempFml);
                    formulas.SetFormula(trgIndex, fml);
                }
            }
            if (fml == null)
            {
                if ((trgIndex == _nDefaultUnitIndex) || (srcIndex == _nDefaultUnitIndex))
                {
                    throw new Exception(string.Format("缺乏单位{0}和主单位{1}之间的转换关系\n", this[srcIndex].ID, this[trgIndex].ID));
                }
                else
                {
                    IBxFormula fml1 = GetFormula(srcIndex, _nDefaultUnitIndex);
                    IBxFormula fml2 = GetFormula(_nDefaultUnitIndex, trgIndex);
                    fml = new CombinedFormula(fml1, fml2);
                    formulas.SetFormula(trgIndex, fml);
                }
            }
            return(fml);
        }
示例#3
0
 public static ParsedFormula Inverse(ParsedFormula formula)
 {
     return(new ParsedFormula(Inverse(formula.m_rootItem)));
 }
示例#4
0
 static ParsedFormula()
 {
     s_sameUnitFormula = new ParsedFormula(new BUParsedVariant());
 }