예제 #1
0
        private void Import()
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            //dlg.FileName = "User.txt"; // Default file name
            dlg.DefaultExt = ".txt";                        // Default file extension
            dlg.Filter     = "Text documents (.txt)|*.txt"; // Filter files by extension
            if (!System.IO.Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "data"))
            {
                System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "data");
            }
            dlg.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + "data";

            // Show save file dialog box
            var result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                try
                {
                    this.SelectedIndex = -1;
                    List <string> lines = FileOperateHelper.ReadFileLines(dlg.FileName);
                    this.Points.Clear();
                    foreach (var line in lines)
                    {
                        string[] temp = line.Split('#');
                        if (temp.Count() != 4)
                        {
                            Debug.WriteLine("路径:" + _selectedValue + ",格式不对");
                            Debug.WriteLine(line);
                            continue;
                        }
                        this.Points.Add(new Point(temp[0], float.Parse(temp[1]), float.Parse(temp[2]), float.Parse(temp[3])));
                    }
                }
                catch (Exception ex)
                {
                    SoftContext.MainWindow.ShowMessageAsync("导入失败", ex.Message);
                }
            }
        }