Exemplo n.º 1
0
        public static List <Character> CharasterSerialize()
        {
            var characters = CharactersService.GetCharacters();

            characters.Clear();
            using (FileStream stream = new FileStream(@"C:\Projects\Characters.txt", FileMode.Open))
            {
                var deserializer = new BinaryFormatter();
                characters = deserializer.Deserialize(stream) as List <Character>;
                return(characters);
            }
        }
Exemplo n.º 2
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            var            characters = CharactersService.GetCharacters();
            SaveFileDialog saveFile   = new SaveFileDialog();

            saveFile.FileName         = "Characters";
            saveFile.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            saveFile.InitialDirectory = @"C:\Projects";
            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                Stream stream     = saveFile.OpenFile();
                var    serializer = new BinaryFormatter();
                serializer.Serialize(stream, characters);
                stream.Close();
            }
        }
Exemplo n.º 3
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            var characters = CharactersService.GetCharacters();
            var name       = firstName.Text;
            var lastName   = lasrName.Text;
            var Gender     = bool.Parse(gender.Text);
            var Age        = int.Parse(age.Text);
            var character  = new Character()
            {
                FirstName = name, LastName = lastName, Gender = Gender, Age = Age
            };

            dataGridView1.Rows.Add();
            dataGridView1["firstName", dataGridView1.Rows.Count - 1].Value = character.FirstName;
            dataGridView1["lastName", dataGridView1.Rows.Count - 1].Value  = character.LastName;
            dataGridView1["gender", dataGridView1.Rows.Count - 1].Value    = character.Gender;
            dataGridView1["age", dataGridView1.Rows.Count - 1].Value       = character.Age;
            characters.Add(character);
        }