Exemple #1
0
        private void SaveAs()
        {
            //if (FileOperateHelper.IsExists(_selectedValue.ToString()))
            //{
            //    var result = System.Windows.MessageBox.Show("文件已存在是否覆盖?", "提示", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question);
            //    if (result == System.Windows.MessageBoxResult.No)
            //        return;
            //}
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            //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
                {
                    string content = "";
                    foreach (var p in Points)
                    {
                        content += p.Name + "#" + p.X + "#" + p.Y + "#" + p.Z + "\r\n";
                    }
                    FileOperateHelper.WriteFile(dlg.FileName, content, true);
                    UpdateFiles();
                }
                catch (Exception ex)
                {
                    SoftContext.MainWindow.ShowMessageAsync("保存失败", ex.Message);
                }
            }
        }
Exemple #2
0
        private void SaveList()
        {
            try
            {
                if (_selectedValue == null)
                {
                    SaveAs();
                    return;
                }

                string content = "";
                foreach (var p in Points)
                {
                    content += p.Name + "#" + p.X + "#" + p.Y + "#" + p.Z + "\r\n";
                }
                FileOperateHelper.WriteFile(_selectedValue.ToString(), content, true);
                SoftContext.MainWindow.ShowMessageAsync("保存成功", "路径:" + _selectedValue.ToString());
            }catch (Exception ex)
            {
                SoftContext.MainWindow.ShowMessageAsync("保存失败", ex.Message);
            }
        }