Beispiel #1
0
 public void SerializeObject(string filename, ObjectToSerialize objectToSerialize)
 {
     Stream stream = File.Open(filename, FileMode.Create);
     BinaryFormatter bFormatter = new BinaryFormatter();
     bFormatter.Serialize(stream, objectToSerialize);
     stream.Close();
 }
Beispiel #2
0
        public MangeUsers()
        {
            InitializeComponent();

            DataGridView _dgUsers = new DataGridView();

            //users.Add(new User(123, "gilad shoham", 0524219320, "*****@*****.**"));
            //users.Add(new User(456, "גלעד", 0524219320, "*****@*****.**"));
            //users.Add(new User(456, "גלעד", "0524219320", "*****@*****.**"));
            if (File.Exists("users.txt"))
            {
                objectToSerialize = serializer.DeSerializeObject("users.txt");
                users = new BindingList<User>(objectToSerialize.Users);
            }
            else
            {
                users = new BindingList<User>();
            }

            source.DataSource = users;

            //_dgUsers2 = new DataGridView();
            //_dgUsers2.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn idColumn = new DataGridViewTextBoxColumn();
            idColumn.DataPropertyName = "MyID";
            idColumn.HeaderText = "תת.ז";

            DataGridViewTextBoxColumn nameColumn = new DataGridViewTextBoxColumn();
            nameColumn.DataPropertyName = "ColName";
            nameColumn.HeaderText = "שם";

            DataGridViewTextBoxColumn phoneColumn = new DataGridViewTextBoxColumn();
            phoneColumn.DataPropertyName = "ColPhone";
            phoneColumn.HeaderText = "טלפון";

            DataGridViewTextBoxColumn mailColumn = new DataGridViewTextBoxColumn();
            mailColumn.DataPropertyName = "ColMail";
            mailColumn.HeaderText = "מייל";

            DataGridViewTextBoxColumn keyColumn = new DataGridViewTextBoxColumn();
            keyColumn.DataPropertyName = "ColKey";
            keyColumn.HeaderText = "מפתח";

            /*
            _dgUsers2.Columns.Add(idColumn);
            _dgUsers2.Columns.Add(nameColumn);
            _dgUsers2.Columns.Add(phoneColumn);
            _dgUsers2.Columns.Add(mailColumn);
            _dgUsers2.Columns.Add(keyColumn);

            _dgUsers2.DataSource = source;
            */
            //_dgUsers.DataSource = source;

            dataGridView1.AutoGenerateColumns = false;
            //dataGridView1.DataSource = users;

            dataGridView1.DataSource = source;
            //_dgUsers.DataSource = users;

            //dataGridView1.ReadOnly = false;
            dataGridView1.Columns[0].DataPropertyName = "MyID";
            dataGridView1.Columns[1].DataPropertyName = "MyName";
            dataGridView1.Columns[2].DataPropertyName = "MyPhone";
            dataGridView1.Columns[3].DataPropertyName = "MyMail";
            dataGridView1.Columns[4].DataPropertyName = "MyKey";

            //dataGridView1.Columns[0].HeaderText = "תתת";
            //dataGridView1.Columns[0].ReadOnly = false;
            //dataGridView1.Columns[0].
            dataGridView1.AutoGenerateColumns = false;

            //this.Controls.Add(_dgUsers);
        }