/// <summary> /// Action for the File->Save command. /// </summary> /// public void Save_Execute(object parameter) { string option = (parameter as string); if (!String.IsNullOrEmpty(lastSavePath) && option != "SaveAs") { save(); return; } var dlg = new SaveFileDialog() { FileName = "Sample", DefaultExt = ".csv", Filter = saveFormats.GetFilterString(false), InitialDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Samples\\") }; if (!String.IsNullOrEmpty(lastSavePath)) { dlg.InitialDirectory = lastSavePath; } // Show save file dialog box var result = dlg.ShowDialog(); if (result == true) { // Get the chosen format lastSaveFormat = saveFormats[dlg.FilterIndex - 1]; lastSavePath = dlg.FileName; save(); } }
/// <summary> /// Action for the File->Open command. /// </summary> /// public void Open_Execute(object sender) { var dlg = new OpenFileDialog() { FileName = "Sample", DefaultExt = ".csv", Filter = loadFormats.GetFilterString(true), FilterIndex = loadFormats.IndexOf("*.csv") + 1, InitialDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Samples\\") }; if (!String.IsNullOrEmpty(lastSavePath)) { dlg.InitialDirectory = lastSavePath; } // Show open file dialog box var result = dlg.ShowDialog(); if (result == true) { // Get the chosen format var fmt = loadFormats[dlg.FilterIndex - 1]; DataTable table = fmt.Read(new FileStream(dlg.FileName, FileMode.Open)); double[][] values = table.ToJagged(); Values.Clear(); foreach (double[] row in values) { var sample = new SampleViewModel(); sample.Value = row[0]; if (row.Length > 1) { sample.Weight = row[1]; } Values.Add(sample); } } }