public static List <WeightParameter> FindGlobleParameters(string name, string unit) { List <List <WeightParameter> > WeightParaList = WeightParameter.GetWeightParameterList(); List <WeightParameter> lstPara = new List <WeightParameter>(); for (int i = 0; i < WeightParaList.Count; ++i) { foreach (WeightParameter temp in WeightParaList[i]) { if (temp.ParaName == name) { if (unit == null || (temp.ParaUnit == unit)) { lstPara.Add(temp); } } } } if (lstPara.Count == 0) { lstPara.Add(null); } return(lstPara); }
static public WeightArithmetic ReadArithmeticData(string filename) { System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory); XmlDocument doc = new XmlDocument(); try { doc.Load(filename); } catch { MessageBox.Show("打开文件错误!"); return(null); } XmlNode xmlnode = doc.SelectSingleNode("重量算法/算法名称"); if (xmlnode == null) { MessageBox.Show("错误的算法文件!"); return(null); } WeightArithmetic wa = new WeightArithmetic(); wa.Name = xmlnode.InnerText; xmlnode = doc.SelectSingleNode("重量算法/算法创建时间"); wa.CreateTime = xmlnode.InnerText; xmlnode = doc.SelectSingleNode("重量算法/重量分类"); wa.SortName = xmlnode.InnerText; xmlnode = doc.SelectSingleNode("重量算法/算法最后修改时间"); wa.LastModifyTime = xmlnode.InnerText; xmlnode = doc.SelectSingleNode("重量算法/算法备注"); wa.Remark = xmlnode.InnerText; xmlnode = doc.SelectSingleNode("重量算法/公式列表"); Dictionary <WeightParameter, WeightParameter> wpDict = new Dictionary <WeightParameter, WeightParameter>(); foreach (XmlNode xmlsubnode in xmlnode.ChildNodes) { WeightFormula wf = new WeightFormula(); wf.NodePath = xmlsubnode.ChildNodes[0].InnerText; wf.Formula = xmlsubnode.ChildNodes[1].InnerText; foreach (XmlNode paranode in xmlsubnode.ChildNodes[2].ChildNodes) { string name = paranode.ChildNodes[0].InnerText; string unit = paranode.ChildNodes[2].InnerText; WeightParameter wpGlobal = FindGlobleParameters(name, unit)[0]; WeightParameter wp = null; if (wpGlobal == null) { wp = new WeightParameter(); wp.ParaName = name; wp.ParaUnit = unit; wp.ParaType = 10;// int.Parse(paranode.ChildNodes[2].InnerText); wp.ParaValue = double.Parse(paranode.ChildNodes[1].InnerText); wp.ParaRemark = paranode.ChildNodes[4].InnerText; WeightParameter temp10wp = new WeightParameter(wp); WeightParameter.GetWeightParameterList()[10].Add(temp10wp); wpDict.Add(temp10wp, wp); } else { if (!wpDict.ContainsKey(wpGlobal)) { wp = new WeightParameter(wpGlobal); wpDict.Add(wpGlobal, wp); } else { wp = wpDict[wpGlobal]; } } wf.ParaList.Add(wp); } if (xmlsubnode.ChildNodes.Count >= 4) { wf.Value = double.Parse(xmlsubnode.ChildNodes[3].InnerText); } wa.FormulaList.Add(wf); } return(wa); }