/// <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); } } }
/// <summary> /// Action for the File->Paste command. /// </summary> /// public void Paste_Executed(object target) { var text = Clipboard.GetText(); var reader = new CsvReader(new StringReader(text), false, '\t'); var lines = reader.ReadToEnd(); lines.Reverse(); int startIndex = Values.IndexOf(CurrentCell.Item as SampleViewModel); if (startIndex == -1) { startIndex = Values.Count; } foreach (var line in lines) { var sample = new SampleViewModel(); double value; if (!Double.TryParse(line[0], out value)) { continue; } sample.Value = value; if (line.Length > 1) { double weight = 1; if (Double.TryParse(line[1], out weight)) { sample.Weight = weight; } } Values.Insert(startIndex, sample); } }
/// <summary> /// Action for the File->Paste command. /// </summary> /// public void Paste_Executed(object target) { var text = Clipboard.GetText(); var reader = new CsvReader(new StringReader(text), false, '\t'); var lines = reader.ReadToEnd(); lines.Reverse(); int startIndex = Values.IndexOf(CurrentCell.Item as SampleViewModel); if (startIndex == -1) startIndex = Values.Count; foreach (var line in lines) { var sample = new SampleViewModel(); double value; if (!Double.TryParse(line[0], out value)) continue; sample.Value = value; if (line.Length > 1) { double weight = 1; if (Double.TryParse(line[1], out weight)) sample.Weight = weight; } Values.Insert(startIndex, sample); } }
/// <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.ToArray(); 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); } } }