示例#1
0
        /// <summary>
        /// 从DFX中加载数据,如果必需数据格式与当前的DFD或DFQ匹配时才能正常加载,加载后为D模式。
        /// 返回值表示是否加载成功。
        /// </summary>
        /// <param name="path"></param>
        public static bool LoadFromDFX(QFile qf, string dfxpath)
        {
            if (qf == null || qf.Charactericstics.Count == 0)
            {
                return(false);
            }

            StreamReader sr = new StreamReader(dfxpath, Encoding.Default);

            while (!sr.EndOfStream)
            {
                try
                {
                    //先读取一行进来。
                    string s = sr.ReadLine();

                    //如果为空或长度为0,则继续下一次循环。
                    if (string.IsNullOrEmpty(s))
                    {
                        continue;
                    }

                    //如果取得的数据个数与参数个数不同,则进入下一组数据。
                    QData qd = new QData(s);
                    if (qd.items.Count == qf.Charactericstics.Count)
                    {
                        qf.Data.Add(qd);
                    }
                }
                catch
                {
                }
            }


            return(true);
        }
示例#2
0
        /// <summary>
        /// 用于从文件中加载DFQ文件。
        /// </summary>
        /// <param name="path">DFQ文件的完整路径。</param>
        /// <returns></returns>
        public static QFile LoadFile(string path)
        {
            QFile qf = new QFile();

            //参数列表
            List <QCharacteristic> ps = new List <QCharacteristic>();


            // 文件读取部分,完成了以下几件事:
            // 1、读取每行,生成每行的QLineInfo对象
            // 2、先交给对应的参数处理,如果处理失败,再交给QFile处理
            // 3、如果不是QlineInfo对象,那么交给QFile的Data
            StreamReader sr = new StreamReader(path, Encoding.Default);

            while (!sr.EndOfStream)
            {
                try
                {
                    //先读取一行进来。
                    string s = sr.ReadLine();

                    //如果为空或长度为0,则继续下一次循环。
                    if (string.IsNullOrEmpty(s))
                    {
                        continue;
                    }

                    //去除前缀的空格,如果长度为0,则继续下一次循环。
                    s = s.TrimStart();
                    if (s.Length == 0)
                    {
                        continue;
                    }

                    //如果是K开头,那么就是定义,如果是‘/’那么就是注释,取消,否则就是数据。
                    if (s[0] == 'K' || s[0] == 'k')
                    {
                        QLineInfo line = new QLineInfo(s);

                        //如果是零配件信息,交由QF处理。"K1001 jet2013"
                        if (s[1] == '1')
                        {
                            qf.DealLine(line);
                        }
                        //否则是参数信息,交由参数层处理
                        else if (line.pid > 0)
                        {
                            if (line.pid > ps.Count)
                            {
                                for (int j = ps.Count; j < line.pid; j++)
                                {
                                    QCharacteristic p = new QCharacteristic();
                                    p.id = j + 1;
                                    ps.Add(p);
                                }
                            }
                            ps[line.pid - 1].DealLine(line);
                        }
                    }
                    //如果是/,那么就是注释,忽略。
                    else if (s[0] == '/')
                    {
                    }
                    else
                    {
                        qf.Data.Add(new QData(s));
                    }
                }
                catch { }
            }
            sr.Close();

            //取出生成的参数,添加至QFile中
            for (int i = 0; i < ps.Count; i++)
            {
                if (ps[i].id > 0)
                {
                    qf.Charactericstics.Add(ps[i]);
                }
            }

            //此处将QFile中的Data中的DataItem与
            //每个QPramater的QDataItem数据组一一对应。
            for (int i = 0; i < qf.Data.Count; i++)
            {
                for (int j = 0; j < qf.Data[i].items.Count; j++)
                {
                    qf.Charactericstics[j].data.Add(qf.Data[i].items[j]);
                }
            }

            return(qf);
        }
示例#3
0
        public static QFile LoadFromStrings(string[] data)
        {
            QFile qf = new QFile();

            //开始默认加载100个参数,方便下面的ps[line.pid - 1]的调用
            List <QCharacteristic> ps = new List <QCharacteristic>();

            for (int i = 0; i < 100; i++)
            {
                ps.Add(new QCharacteristic());
            }

            // 文件读取部分,完成了以下几件事:
            // 1、读取每行,生成每行的QLineInfo对象
            // 2、先交给对应的参数处理,如果处理失败,再交给QFile处理
            // 3、如果不是QlineInfo对象,那么交给QFile的Data


            for (int i = 0; i < data.Length; i++)
            {
                string s = data[i];

                if (s == null || s.Length == 0)
                {
                    continue;
                }

                if (s[s.Length - 1] == '\r')
                {
                    s = s.Substring(0, s.Length - 1);
                }

                //如果是K开头,那么就是定义,如果是‘/’那么就是注释,取消,否则就是数据。
                if (s[0] == 'K' || s[0] == 'k')
                {
                    QLineInfo line = new QLineInfo(s);

                    //如果是零配件信息,交由QF处理。
                    if (s[1] == '1')
                    {
                        qf.DealLine(line);
                    }
                    //否则是参数信息,交由参数层处理
                    else if (line.pid > 0)
                    {
                        QCharacteristic p = ps[line.pid - 1];
                        p.DealLine(line);
                    }
                }
                //如果是/,那么就是注释,忽略。
                else if (s[0] == '/')
                {
                }
                else
                {
                    qf.Data.Add(new QData(s));
                }
            }


            //取出生成的参数,添加至QFile中
            for (int i = 0; i < ps.Count; i++)
            {
                if (ps[i].id > 0)
                {
                    qf.Charactericstics.Add(ps[i]);
                }
            }

            //此处将QFile中的Data中的DataItem与
            //每个QPramater的QDataItem数据组一一对应。
            for (int i = 0; i < qf.Data.Count; i++)
            {
                for (int j = 0; j < qf.Data[i].items.Count; j++)
                {
                    qf.Charactericstics[j].data.Add(qf.Data[i].items[j]);
                }
            }

            return(qf);
        }