Esempio n. 1
0
        public void LoadUnitConfigNode(XmlElement cateNode)
        {
            FormulaParser parser = new FormulaParser();

            try
            {
                XmlNodeList unitNodes = cateNode.ChildNodes;
                _subsetUnits = new List <IBxUnit>(unitNodes.Count);
                string  id, name;
                IBxUnit baseUnit;
                int     index = 0;
                foreach (XmlElement one in unitNodes)
                {
                    id       = one.GetAttribute("id");
                    baseUnit = _baseCategory.Parse(id);

                    name = one.GetAttribute("name");
                    if (string.IsNullOrEmpty(name))
                    {
                        name = id;
                    }
                    name = UnitNameConvert.RegularizeUnit(name);

                    _subsetUnits.Add(new BxSubSetUnit(baseUnit, this, name, index));
                    index++;
                }
            }
            catch (System.Exception) { }
        }
Esempio n. 2
0
        public void LoadUnitConfigNode(XmlElement cateNode)
        {
            FormulaParser parser = new FormulaParser();

            try
            {
                m_id  = cateNode.GetAttribute("id");
                _name = cateNode.GetAttribute("name");
                _code = cateNode.GetAttribute("code");

                XmlElement unitsNode   = (XmlElement)cateNode.SelectSingleNode("Units");
                string     defaultUnit = unitsNode.GetAttribute("primaryUnit");

                //获取所有的单位
                XmlNodeList    unitsNodeList = cateNode.SelectSingleNode("Units").ChildNodes;
                List <IBxUnit> units         = new List <IBxUnit>();
                List <string>  fmls          = new List <string>();
                int            nIndex        = 0;
                string         id            = null;
                string         name          = null;
                string         code          = null;
                int            dd            = 0;
                foreach (XmlElement one in unitsNodeList)
                {
                    id = one.GetAttribute("id");
                    if (id == defaultUnit)
                    {
                        m_nDefaultUnitIndex = nIndex;
                    }
                    name = one.GetAttribute("name");
                    if (string.IsNullOrEmpty(name))
                    {
                        name = id;
                    }
                    name = UnitNameConvert.Convert(name);
                    code = one.GetAttribute("code");
                    if (!Int32.TryParse(one.GetAttribute("decimalDigits"), out dd))
                    {
                        throw new Exception("no decimal digis in unit " + id + " !");
                    }

                    units.Add(new BUUnit(id, name, code, dd, this, nIndex));
                    fmls.Add(one.GetAttribute("defaultUnit"));
                    nIndex++;
                }
                m_units = units.ToArray();
                //end

                //生成默认转换公式
                int nCounts = m_units.Length;
                m_formulas = new _SrcUnitFormulas[nCounts];
                nIndex     = 0;
                _SrcUnitFormulas temp = null;
                foreach (IBxUnit one in m_units)
                {
                    temp = new _SrcUnitFormulas(nIndex, nCounts);
                    m_formulas[nIndex] = temp;
                    if (nIndex != m_nDefaultUnitIndex)
                    {
                        parser.Formula = fmls[nIndex];
                        parser.Variant = one.ID;
                        temp.SetFormula(m_nDefaultUnitIndex, new ParsedFormula(parser.Parse()));
                    }
                    nIndex++;
                }
                //end
            }
            catch (System.Exception) { }

            try
            {
                XmlElement  formulasNode    = (XmlElement)cateNode.SelectSingleNode("Formulas");
                XmlNodeList formulaNodeList = formulasNode.ChildNodes;
                string      srcUnit;
                string      trgUnit;
                foreach (XmlElement one in formulaNodeList)
                {
                    srcUnit        = one.GetAttribute("src");
                    trgUnit        = one.GetAttribute("trg");
                    parser.Formula = one.GetAttribute("convertion");
                    parser.Variant = srcUnit;
                    SetFormula(srcUnit, trgUnit, new ParsedFormula(parser.Parse()));
                }
            }
            catch (System.Exception) { }
        }