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) { } }
public void LoadUnitConfigNode(XmlElement cateNode) { FormulaParser parser = new FormulaParser(); try { _id = cateNode.GetAttribute("id"); _code = cateNode.GetAttribute("code"); XmlElement unitsNode = (XmlElement)cateNode.SelectSingleNode("Units"); XmlNodeList unitsNodeList = cateNode.SelectSingleNode("Units").ChildNodes; int count = unitsNodeList.Count; _units = new CategoryUnits(count); _formulas = new BxSrcUnitFormulas[count]; int nIndex = 0; string id = null; string code = null; int dd = 0; foreach (XmlElement one in unitsNodeList) { id = one.GetAttribute("id"); code = one.GetAttribute("code"); if (!Int32.TryParse(one.GetAttribute("decimalDigits"), NumberStyles.Any, CultureInfo.InvariantCulture, out dd)) { //throw new Exception("no decimal digis in unit " + id + " !"); } _units[nIndex] = new BxUnit(id, code, dd, this, nIndex); _formulas[nIndex] = new BxSrcUnitFormulas(nIndex, count); nIndex++; } } catch (System.Exception) { } string srcUnit; string trgUnit; try { XmlElement formulasNode = (XmlElement)cateNode.SelectSingleNode("Formulas"); if (formulasNode == null) { return; } string primaryUnitID = formulasNode.GetAttribute("primaryUnit"); if (string.IsNullOrEmpty(primaryUnitID)) { return; } _nDefaultUnitIndex = ParseEx(primaryUnitID).Index; XmlNodeList formulaNodeList = formulasNode.ChildNodes; 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) { } }