Beispiel #1
0
        /// <summary>
        /// 从文件中读取数据
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="relevateFileName">相对路径名</param>
        /// <param name="mapName">地图名</param>
        /// <param name="patrolID">路径ID</param>
        private void LoadPatrolInfo(string fileName, string relevateFileName, string mapName, string patrolID)
        {
            string dataPath = Path.Combine(path, string.Format("data\\source\\maps\\{0}\\{0}.Map.Logical", mapName));
            FileInfo dataFile = new FileInfo(dataPath);

            if(dataFile.Exists)
            {
                ImportData importData = new ImportData(dataPath);
                
                FileInfo fi = new FileInfo(fileName);
                if (fi.Exists)
                {
                    try
                    {
                        StreamReader sr = new StreamReader(fileName, Encoding.GetEncoding("gb2312"));
                        string text = sr.ReadLine();
                        List<string> list = new List<string>();
                        string[] data;
                        int index = -1;
                        string appendText;
                        string patrolName;

                        while (text != null)
                        {
                            data = text.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                            if (index == -1) // 读入第一行,即列数据
                            {
                                if (!loadedFields) // 还没有写列数组
                                {
                                    fields = new string[5 + data.Length];
                                    fields[0] = "FileName";
                                    fields[1] = "MapName";
                                    fields[2] = "PatrolID";                                    
                                    fields[3] = "PatrolName";
                                    fields[4] = "PatrolPointID";

                                    for (int i = 0; i < data.Length; i++)
                                    {
                                        fields[5 + i] = data[i];
                                    }

                                    loadedFields = true;
                                }
                            }
                            else // 读入行数据
                            {
                                patrolName = importData.GetKeyString(string.Format("WayPointSet{0}", int.Parse(patrolID) - 1), "szName");
                                appendText = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t", relevateFileName, mapName, patrolID, patrolName, index - 1);                       
                                list.Add(appendText + text);
                            }

                            index++;
                            text = sr.ReadLine();
                        }

                        valuesList.AddRange(list);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show("在读取路径文件时产生IO异常: " + ex.ToString());
                    }
                }
            }
            else
            {
                FileInfo fi = new FileInfo(fileName);
                if (fi.Exists)
                {
                    try
                    {
                        StreamReader sr = new StreamReader(fileName, Encoding.GetEncoding("gb2312"));
                        string text = sr.ReadLine();
                        List<string> list = new List<string>();
                        string[] data;
                        int index = -1;
                        string appendText;
                        string patrolName;

                        while (text != null)
                        {
                            data = text.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                            if (index == -1) // 读入第一行,即列数据
                            {
                                if (!loadedFields) // 还没有写列数组
                                {
                                    fields = new string[5 + data.Length];
                                    fields[0] = "FileName";
                                    fields[1] = "MapName";
                                    fields[2] = "PatrolID";
                                    fields[3] = "PatrolName";
                                    fields[4] = "PatrolPointID";

                                    for (int i = 0; i < data.Length; i++)
                                    {
                                        fields[5 + i] = data[i];
                                    }

                                    loadedFields = true;
                                }
                            }
                            else // 读入行数据
                            {
                                patrolName = string.Format("路径{0}", index + 1);
                                appendText = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t", relevateFileName, mapName, patrolID, patrolName, index - 1);
                                list.Add(appendText + text);
                            }

                            index++;
                            text = sr.ReadLine();
                        }

                        valuesList.AddRange(list);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show("在读取路径文件时产生IO异常: " + ex.ToString());
                    }
                }
            }            
        } 
Beispiel #2
0
        /// <summary>
        /// 从文件中读取数据
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="relevateFileName">相对路径名</param>
        /// <param name="mapName">地图名</param>
        /// <param name="patrolID">路径ID</param>
        private void LoadPatrolInfo(string fileName, string relevateFileName, string mapName, string patrolID)
        {
            string   dataPath = Path.Combine(path, string.Format("data\\source\\maps\\{0}\\{0}.Map.Logical", mapName));
            FileInfo dataFile = new FileInfo(dataPath);

            if (dataFile.Exists)
            {
                ImportData importData = new ImportData(dataPath);

                FileInfo fi = new FileInfo(fileName);
                if (fi.Exists)
                {
                    try
                    {
                        StreamReader  sr   = new StreamReader(fileName, Encoding.GetEncoding("gb2312"));
                        string        text = sr.ReadLine();
                        List <string> list = new List <string>();
                        string[]      data;
                        int           index = -1;
                        string        appendText;
                        string        patrolName;

                        while (text != null)
                        {
                            data = text.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                            if (index == -1)       // 读入第一行,即列数据
                            {
                                if (!loadedFields) // 还没有写列数组
                                {
                                    fields    = new string[5 + data.Length];
                                    fields[0] = "FileName";
                                    fields[1] = "MapName";
                                    fields[2] = "PatrolID";
                                    fields[3] = "PatrolName";
                                    fields[4] = "PatrolPointID";

                                    for (int i = 0; i < data.Length; i++)
                                    {
                                        fields[5 + i] = data[i];
                                    }

                                    loadedFields = true;
                                }
                            }
                            else // 读入行数据
                            {
                                patrolName = importData.GetKeyString(string.Format("WayPointSet{0}", int.Parse(patrolID) - 1), "szName");
                                appendText = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t", relevateFileName, mapName, patrolID, patrolName, index - 1);
                                list.Add(appendText + text);
                            }

                            index++;
                            text = sr.ReadLine();
                        }

                        valuesList.AddRange(list);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show("在读取路径文件时产生IO异常: " + ex.ToString());
                    }
                }
            }
            else
            {
                FileInfo fi = new FileInfo(fileName);
                if (fi.Exists)
                {
                    try
                    {
                        StreamReader  sr   = new StreamReader(fileName, Encoding.GetEncoding("gb2312"));
                        string        text = sr.ReadLine();
                        List <string> list = new List <string>();
                        string[]      data;
                        int           index = -1;
                        string        appendText;
                        string        patrolName;

                        while (text != null)
                        {
                            data = text.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                            if (index == -1)       // 读入第一行,即列数据
                            {
                                if (!loadedFields) // 还没有写列数组
                                {
                                    fields    = new string[5 + data.Length];
                                    fields[0] = "FileName";
                                    fields[1] = "MapName";
                                    fields[2] = "PatrolID";
                                    fields[3] = "PatrolName";
                                    fields[4] = "PatrolPointID";

                                    for (int i = 0; i < data.Length; i++)
                                    {
                                        fields[5 + i] = data[i];
                                    }

                                    loadedFields = true;
                                }
                            }
                            else // 读入行数据
                            {
                                patrolName = string.Format("路径{0}", index + 1);
                                appendText = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t", relevateFileName, mapName, patrolID, patrolName, index - 1);
                                list.Add(appendText + text);
                            }

                            index++;
                            text = sr.ReadLine();
                        }

                        valuesList.AddRange(list);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show("在读取路径文件时产生IO异常: " + ex.ToString());
                    }
                }
            }
        }