private void buttonSave_Click(object sender, EventArgs e) { m = new ModelClass(); StreamWriter sw = null;; try { sw = new StreamWriter(PathFile); m.saveFile(ct, sw); sw.Close(); } catch (Exception ex) { MessageBox.Show("Error writing file: " + ex.Message); } finally { sw.Close(); } }
private void buttonSaveAs_Click(object sender, EventArgs e) { m = new ModelClass(); StreamWriter sw; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "txt files (*.txt)|*.txt"; saveFileDialog1.FilterIndex = 1; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { try { sw = new StreamWriter(saveFileDialog1.FileName); m.saveFile(ct, sw); sw.Close(); } catch (Exception ex) { MessageBox.Show("Error writing file: " + ex.Message); } } }
private void buttonOpen_Click(object sender, EventArgs e) { m = new ModelClass(); StreamReader sr = null; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "txt files (*.txt)|*.txt"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { sr = new StreamReader(openFileDialog1.FileName); m.openFile(ct,sr); Refresh(); } catch (Exception ex) { MessageBox.Show("Error reading file: " + ex.Message); } } }