예제 #1
0
        private void Serializer(string filename, Drivers drivers)
        {
            BinaryFormatter binary = new BinaryFormatter();

            File.Delete(filename);

            using (FileStream fstream = new FileStream(filename, FileMode.OpenOrCreate))
            {
                binary.Serialize(fstream, drivers);
            }
        }
예제 #2
0
        private void SaveTheFile_Click(object sender, EventArgs e)
        {
            Drivers drivers = new Drivers();

            foreach (ListViewItem item in ListView.Items)
            {
                if (item.Tag != null)
                {
                    drivers.DriversList.Add((Driver)item.Tag);
                }
            }

            if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            string filename = saveFileDialog.FileName;

            Serializer(filename, drivers);
        }
예제 #3
0
        private void LoadTheFile_Click(object sender, EventArgs e)
        {
            ListView.Items.Clear();

            if (openFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            string filename = openFileDialog.FileName;

            Drivers drivers = Deserializer(filename);

            foreach (Driver driver in drivers.DriversList)
            {
                string       fio  = driver.DName[0] + ". " + driver.DThirdname[0] + ". " + driver.DSurname;
                ListViewItem list = new ListViewItem(fio);

                list.Tag = driver;

                ListView.Items.Add(list);
            }
        }