示例#1
0
        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();
            }
        }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        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);
                }
            }
        }