Example #1
0
        private void loadData()
        {
            // First load books
            string           sql     = "select * from books";
            SQLiteCommand    command = new SQLiteCommand(sql, DManager.getSQLConn());
            SQLiteDataReader reader  = command.ExecuteReader();

            while (reader.Read())
            {
                Book b = new Book((string)reader["name"], (int)reader["id"]);
                Console.WriteLine("Book loaded: " + b.name + ", " + b.id);
                b.isSaved = true;
                books.Add(b);
            }

            // Second load contacts into books
            sql     = "select * from contacts";
            command = new SQLiteCommand(sql, DManager.getSQLConn());
            reader  = command.ExecuteReader();
            while (reader.Read())
            {
                Book b = getBookById((int)reader["book"]);
                if (b == null)
                {
                    continue;
                }

                Contact c = new Contact(b, (string)reader["first"], (int)reader["id"]);
                c.isSaved = true;
                b.addPerson(c);
            }
            Books_ListBox.DataSource = books;
            isSaved = true;
        }
Example #2
0
        private void AddContact_Button_Click(object sender, EventArgs e)
        {
            Contact c = new Contact(selectedBook);

            selectedBook.addPerson(c);
            Contacts_ListBox.DataSource    = null;
            Contacts_ListBox.DataSource    = selectedBook.getContacts();
            Contacts_ListBox.SelectedIndex = selectedBook.getContacts().Count - 1;
            selectedBook.isSaved           = false;
            c.isSaved = false;

            update(true);
        }