Example #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            button2.Enabled        = false;
            label2.Enabled         = false;
            numericUpDown1.Enabled = false;
            button3.Enabled        = false;

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Files|*.dat";
            DialogResult    result    = openFileDialog1.ShowDialog();
            BinaryFormatter formatter = new BinaryFormatter();

            if (result == DialogResult.OK)
            {
                using (FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open))
                {
                    ExternalForest extForest = (ExternalForest)formatter.Deserialize(fs);
                    forest           = extForest.forest;
                    codifier         = extForest.codifier;
                    attributes       = extForest.attributes;
                    target_attribute = extForest.target_attribute;
                }

                ForestForm forest_form = new ForestForm(this);
                forest_form.Show();
                forest_form.label1.Text = "The forest loaded!";
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "Files|*.dat";
            saveFileDialog1.ShowDialog();
            if (saveFileDialog1.FileName != "")
            {
                BinaryFormatter formatter = new BinaryFormatter();

                using (FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile())
                {
                    ExternalForest extForest = new ExternalForest(forest, codifier, attributes, target_attribute);
                    formatter.Serialize(fs, extForest);
                }

                MessageBox.Show("Forest saved!");
            }
        }