Esempio n. 1
0
 public NodeFormula()
 {
     XFormula          = new WeightFormula();
     XFormula.NodePath = "X轴坐标";
     YFormula          = new WeightFormula();
     YFormula.NodePath = "Y轴坐标";
 }
Esempio n. 2
0
 public NodeFormula(string name)
 {
     NodeName          = name;
     XFormula          = new WeightFormula();
     XFormula.NodePath = "X轴坐标";
     YFormula          = new WeightFormula();
     YFormula.NodePath = "Y轴坐标";
 }
Esempio n. 3
0
 public WeightFormula this[int index]
 {
     get
     {
         return((index == 0) ? XFormula : YFormula);
     }
     set
     {
         if (index == 0)
         {
             XFormula = value;
         }
         else
         {
             YFormula = value;
         }
     }
 }
        public WeightFormula Clone()
        {
            WeightFormula formula = new WeightFormula();

            formula.NodePath = this.NodePath;
            formula.Formula  = this.Formula;
            formula.Value    = this.Value;

            List <WeightParameter> paraList = new List <WeightParameter>();

            foreach (WeightParameter para in ParaList)
            {
                paraList.Add(para.Clone());
            }
            formula.ParaList = paraList;

            return(formula);
        }
Esempio n. 5
0
        public List <WeightParameter> GetParaList()
        {
            List <WeightParameter> paraList = new List <WeightParameter>();

            foreach (NodeFormula nf in FormulaList)
            {
                for (int i = 0; i < 2; ++i)
                {
                    WeightFormula wf = nf[i];
                    paraList.AddRange(
                        from item in wf.ParaList
                        where !paraList.Contains(item)
                        select item
                        );
                }
            }

            return(paraList.OrderBy(l => l.ParaType).ToList());
        }
        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);
        }
Esempio n. 7
0
 public NodeFormula(string name, WeightFormula xf, WeightFormula yf)
 {
     NodeName = name;
     XFormula = xf;
     YFormula = yf;
 }
Esempio n. 8
0
        public bool WriteArithmeticFile(string filepath, bool bOverWritePrompt)
        {
            System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            if (bOverWritePrompt)
            {
                if (System.IO.File.Exists(filepath))
                {
                    if (MessageBox.Show("文件\"" + filepath + "\"已存在,是否覆盖?", "文件已存在", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return(false);
                    }
                }
            }

            XmlTextWriter writeXml = null;

            try
            {
                writeXml = new XmlTextWriter(filepath, Encoding.GetEncoding("gb2312"));
            }
            catch
            {
                MessageBox.Show("创建或写入文件失败!");
                return(false);
            }

            writeXml.Formatting  = Formatting.Indented;
            writeXml.Indentation = 5;
            writeXml.WriteStartDocument();

            writeXml.WriteStartElement("重量算法");
            {
                writeXml.WriteStartElement("算法名称");
                writeXml.WriteString(Name);
                writeXml.WriteEndElement();

                //writeXml.WriteStartElement("重量分类");
                //writeXml.WriteString(SortName);
                //writeXml.WriteEndElement();

                writeXml.WriteStartElement("算法创建时间");
                writeXml.WriteString(CreateTime);
                writeXml.WriteEndElement();

                writeXml.WriteStartElement("算法最后修改时间");
                writeXml.WriteString(LastModifyTime);
                writeXml.WriteEndElement();

                writeXml.WriteStartElement("算法备注");
                writeXml.WriteString(Remark);
                writeXml.WriteEndElement();

                writeXml.WriteStartElement("节点列表");
                {
                    foreach (NodeFormula nf in FormulaList)
                    {
                        writeXml.WriteStartElement("节点");
                        {
                            writeXml.WriteStartElement("节点名称");
                            writeXml.WriteString(nf.NodeName);
                            writeXml.WriteEndElement();

                            for (int i = 0; i < 2; ++i)
                            {
                                WeightFormula wf = nf[i];
                                writeXml.WriteStartElement(wf.NodePath);
                                {
                                    writeXml.WriteStartElement("公式");
                                    writeXml.WriteString(wf.Formula);
                                    writeXml.WriteEndElement();

                                    writeXml.WriteStartElement("参数表");
                                    {
                                        foreach (WeightParameter wp in wf.ParaList)
                                        {
                                            writeXml.WriteStartElement("参数");
                                            {
                                                writeXml.WriteStartElement("参数名称");
                                                writeXml.WriteString(wp.ParaName);
                                                writeXml.WriteEndElement();
                                                writeXml.WriteStartElement("参数数值");
                                                writeXml.WriteValue(wp.ParaValue);
                                                writeXml.WriteEndElement();
                                                writeXml.WriteStartElement("单位");
                                                writeXml.WriteString(wp.ParaUnit);
                                                writeXml.WriteEndElement();
                                                writeXml.WriteStartElement("参数分类");
                                                writeXml.WriteValue(wp.ParaType);
                                                writeXml.WriteEndElement();
                                                writeXml.WriteStartElement("备注");
                                                writeXml.WriteString(wp.ParaRemark);
                                                writeXml.WriteEndElement();
                                            }
                                            writeXml.WriteEndElement();
                                        }
                                    }
                                    writeXml.WriteEndElement();

                                    writeXml.WriteStartElement("结果数值");
                                    writeXml.WriteValue(wf.Value);
                                    writeXml.WriteEndElement();
                                }
                                writeXml.WriteEndElement();
                            }
                        }
                        writeXml.WriteEndElement();
                    }
                }
                writeXml.WriteEndElement();
            }
            writeXml.WriteEndElement();
            writeXml.Close();

            return(true);
        }