private void SaveToolStripButton_Click(object sender, EventArgs e)
        {
            CharacterSaveFileDialog.FileName         = "Character.txt";
            CharacterSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            CharacterSaveFileDialog.Filter           = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";


            var result = CharacterSaveFileDialog.ShowDialog();

            if (result != DialogResult.Cancel)
            {
                using (StreamWriter streamWriter = new StreamWriter(
                           File.Open(CharacterSaveFileDialog.FileName, FileMode.Create)))
                {
                    streamWriter.WriteLine(Program.character.Identity.FirstName);
                    streamWriter.WriteLine(Program.character.Identity.LastName);
                    streamWriter.WriteLine(Program.character.Dexterity);
                    streamWriter.WriteLine(Program.character.Education);
                    streamWriter.WriteLine(Program.character.Endurance);
                    streamWriter.WriteLine(Program.character.Intellect);
                    streamWriter.WriteLine(Program.character.SocialStanding);
                    streamWriter.WriteLine(Program.character.Strength);
                    foreach (var skill in Program.character.Skills)
                    {
                        streamWriter.WriteLine(skill);
                    }
                    streamWriter.Close();
                    streamWriter.Dispose();
                }
                MessageBox.Show("File saved succesfully", "Saving", MessageBoxButtons.OK);
            }
        }
        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            //configure save file dialog box
            CharacterSaveFileDialog.FileName         = "Character.txt";
            CharacterSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            CharacterSaveFileDialog.Filter           = "Text files (*.txt)|*.txt|All files (*.*)|*.*";

            //Open Svae File Dialog
            var ShowDialog = CharacterSaveFileDialog.ShowDialog();

            if (ShowDialog != DialogResult.Cancel)
            {
                //open Sterem Writer to write
                using (StreamWriter outputString = new StreamWriter(
                           File.Open(CharacterSaveFileDialog.FileName, FileMode.Create)))
                {
                    //Write strings to File
                    outputString.WriteLine(Program.character.HeroName);
                    outputString.WriteLine(Program.character.FirstName);
                    outputString.WriteLine(Program.character.LastName);
                    outputString.WriteLine(Program.character.Fighting);
                    outputString.WriteLine(Program.character.Agility);
                    outputString.WriteLine(Program.character.Strength);
                    outputString.WriteLine(Program.character.Endurance);
                    outputString.WriteLine(Program.character.Reason);
                    outputString.WriteLine(Program.character.Intution);
                    outputString.WriteLine(Program.character.Psyche);
                    outputString.WriteLine(Program.character.Popularity);
                    outputString.WriteLine(Program.character.HeroName);
                    outputString.WriteLine(Program.character.HeroName);
                    outputString.WriteLine(Program.character.HeroName);
                    outputString.WriteLine(Program.character.HeroName);
                    // close
                    outputString.Close();
                    outputString.Dispose();
                }

                MessageBox.Show("File Saved Succesfully!", "Saved",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// This is the method for saving the Character Porfolio to a file
        /// </summary>
        private void SaveFile()
        {
            // configure the file dialog
            CharacterSaveFileDialog.FileName         = "Character.txt";
            CharacterSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            CharacterSaveFileDialog.Filter           = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";

            // open the file dialog
            var result = CharacterSaveFileDialog.ShowDialog();

            if (result != DialogResult.Cancel)
            {
                // open the stream for writing
                using (StreamWriter outputStream = new StreamWriter(
                           File.Open(CharacterSaveFileDialog.FileName, FileMode.Create)))
                {
                    // write content - string type - to the file
                    outputStream.WriteLine(Program.characterPortfolio.Identity.FirstName);
                    outputStream.WriteLine(Program.characterPortfolio.Identity.LastName);
                    outputStream.WriteLine(Program.characterPortfolio.Strength);
                    outputStream.WriteLine(Program.characterPortfolio.Dexterity);
                    outputStream.WriteLine(Program.characterPortfolio.Endurance);
                    outputStream.WriteLine(Program.characterPortfolio.Intellect);
                    outputStream.WriteLine(Program.characterPortfolio.Education);
                    outputStream.WriteLine(Program.characterPortfolio.SocialStanding);
                    outputStream.WriteLine(Program.characterPortfolio.Skills[0].Name);
                    outputStream.WriteLine(Program.characterPortfolio.Skills[1].Name);
                    outputStream.WriteLine(Program.characterPortfolio.Skills[2].Name);
                    outputStream.WriteLine(Program.characterPortfolio.Skills[3].Name);

                    // cleanup
                    outputStream.Close();
                    outputStream.Dispose();

                    // give feedback to the user that the file has been saved
                    MessageBox.Show("File Saved...", "Saving File...",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        private void OpenToolStripButton_Click(object sender, EventArgs e)
        {
            // configure the file dialog
            CharacterSaveFileDialog.FileName         = "Character.txt";
            CharacterSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            CharacterSaveFileDialog.Filter           = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";

            //open file dialog - Modal Form
            var result = CharacterSaveFileDialog.ShowDialog();

            if (result != DialogResult.Cancel)
            {
                //open file to write
                using (StreamReader InputStream = new StreamReader(
                           File.Open(CharacterSaveFileDialog.FileName, FileMode.Create)))
                {
                    //write stuff to the file
                    Program.character.FirstName = InputStream.ReadLine();
                    (Program.character.Strength); outputStream.WriteLine
                        (Program.character.Dexterity); outputStream.WriteLine
                        (Program.character.Constitution) outputStream.WriteLine;
                    (Program.character.Intelligence)outputStream.WriteLine;
                    (Program.character.Wisdom); outputStream.WriteLine
                        (Program.character.Charisma); outputStream.WriteLine
                        (Program.character.Inventory[0]) outputStream.WriteLine;
                    (Program.character.Inventory[1])outputStream.WriteLine;
                    (Program.character.Inventory[2])outputStream.WriteLine;
                    (Program.character.Inventory[3])outputStream.WriteLine;

                    //close the file
                    outputStream.Close();

                    //dispose of the memory
                    outputStream.Dispose();
                }

                MessageBox.Show("File Saved", "Saving...", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            CharacterSaveFileDialog.FileName         = "Character.txt";
            CharacterSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            CharacterSaveFileDialog.Filter           = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";

            // open file dialog - Modal Form
            var result = CharacterSaveFileDialog.ShowDialog();

            if (result != DialogResult.Cancel)
            {
                // open file to write

                using (StreamWriter outputStream = new StreamWriter(

                           File.Open(CharacterSaveFileDialog.FileName, FileMode.Create)))
                {
                    // write stuff to the file

                    outputStream.WriteLine(Program.character.FirstName);
                    outputStream.WriteLine(Program.character.LastName);
                    outputStream.WriteLine(Program.character.Strength);
                    outputStream.WriteLine(Program.character.Dexterity);
                    outputStream.WriteLine(Program.character.Constitution);
                    outputStream.WriteLine(Program.character.Intelligence);
                    outputStream.WriteLine(Program.character.Wisdom);
                    outputStream.WriteLine(Program.character.Charisma);
                    outputStream.WriteLine(Program.character.Inventory[0].Description);
                    outputStream.WriteLine(Program.character.Inventory[1].Description);
                    outputStream.WriteLine(Program.character.Inventory[2].Description);
                    outputStream.WriteLine(Program.character.Inventory[3].Description);
                    // close the file
                    outputStream.Close();
                    // dispose of the memory
                    outputStream.Dispose();
                }
            }
        }
        /// <summary>
        /// this is an event hanlder for saveButton click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // configure the file dialog
            CharacterSaveFileDialog.FileName         = "Character.txt";
            CharacterSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory();

            CharacterSaveFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";



            // open file dialog - Modal Form

            var result = CharacterSaveFileDialog.ShowDialog();

            if (result != DialogResult.Cancel)
            {
                // open file to write
                using (StreamWriter outputStream = new StreamWriter(
                           File.Open(CharacterSaveFileDialog.FileName, FileMode.Create)))
                {
                    // write stuff to the file

                    outputStream.WriteLine(Program.characters.Firstname);
                    outputStream.WriteLine(Program.characters.Lastname);
                    outputStream.WriteLine(Program.characters.Strength);
                    outputStream.WriteLine(Program.characters.Dexterity);
                    outputStream.WriteLine(Program.characters.Constitution);
                    outputStream.WriteLine(Program.items);
                    // close the file
                    outputStream.Close();
                    // dispose of the memory
                    outputStream.Dispose();
                }

                MessageBox.Show("File Saved", "Saving...", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void SaveToolStripButton_Click(object sender, EventArgs e)
        {
            CharacterSaveFileDialog.FileName = "character.txt";
            CharacterSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            CharacterSaveFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";

            // open file dialog - Modal Form
            var result = CharacterSaveFileDialog.ShowDialog();
            if (result != DialogResult.Cancel)
            {
                // open file to write
                using (StreamWriter outputStream = new StreamWriter(
                    File.Open(CharacterSaveFileDialog.FileName, FileMode.Create)))
                {
                    // write stuff to the file
                    outputStream.WriteLine(Program.chapo.Identity.FirstName);
                    outputStream.WriteLine(Program.chapo.Identity.LastName);
                    outputStream.WriteLine(Program.chapo.Strength);
                    outputStream.WriteLine(Program.chapo.Dexterity);
                    outputStream.WriteLine(Program.chapo.Endurance);
                    outputStream.WriteLine(Program.chapo.Education);
                    outputStream.WriteLine(Program.chapo.Intellect);
                    outputStream.WriteLine(Program.chapo.SocialStanding);
                    outputStream.WriteLine(Program.chapo.SkillsList.ToString());


                    // close the file
                    outputStream.Close();

                    // dispose of the memory
                    outputStream.Dispose();
                }

                MessageBox.Show("File Saved", "Saving...",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// This is the shared event handler for the saveToolStringMenuItem Click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // configuration for saveFileDialog
            CharacterSaveFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); // set the default
            CharacterSaveFileDialog.FileName         = "Character.txt";                 // set the default
            CharacterSaveFileDialog.Filter           = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";


            var result = CharacterSaveFileDialog.ShowDialog();

            if (result != DialogResult.Cancel)
            {
                // open a stream to write
                using (StreamWriter outputStream = new StreamWriter(
                           File.Open(CharacterSaveFileDialog.FileName, FileMode.Create)))
                {
                    // write stuff to the file
                    outputStream.WriteLine(Program.character.FirstName);
                    outputStream.WriteLine(Program.character.LastName);
                    outputStream.WriteLine(Program.character.Fighting);
                    outputStream.WriteLine(Program.character.Agility);
                    outputStream.WriteLine(Program.character.Reason);
                    outputStream.WriteLine(Program.character.Endurance);
                    outputStream.WriteLine(Program.character.Intuition);
                    outputStream.WriteLine(Program.character.Psyche);
                    outputStream.WriteLine(Program.character.Popularity);

                    // cleanup
                    outputStream.Close();
                    outputStream.Dispose();
                }

                MessageBox.Show("File Saved Successfully!", "Saving...",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #9
0
 /// <summary>
 /// The Clicl Events for SaveButton and OpenButton. These events show the appropriate file dialogue.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SaveButton_Click(object sender, EventArgs e)
 {
     CharacterSaveFileDialog.FileName         = "Character.txt";
     CharacterSaveFileDialog.InitialDirectory = "..//..//Data";
     CharacterSaveFileDialog.ShowDialog();
 }