// copy all contacts that are currently on screen
        // to the addressbook specified in the combobox
        private void copyAll()
        {
            LogManager.Write("copyAll");

            List <Contact> contacts = getCurrentVisibleAddressbook().Contacts;
            string         adb_name = copyAllCombo.Text;

            if (addressbookExists(adb_name))
            {
                LogManager.Write("copyAll_exist");
                Adressbook ad = getAddressbook(adb_name);
                LogManager.Write("copyAll_callback1");
                foreach (Contact contact in contacts)
                {
                    LogManager.Write("copyAll_add");
                    ad.Add(contact);
                }

                // Check if copy contact to another adressbook works
                bool b = false;
                foreach (Contact contact in contacts)
                {
                    b = adressbooks[adressbooks.IndexOf(ad)].contacts.Contains(contact);
                    if (b == false)
                    {
                        break;
                    }
                }
                LogManager.Oracle(": Copy to adressbook", b);
            }

            LogManager.Write("copyAll_callback2");
        }
        // reload contacts list
        public void changeToAddressbook(Adressbook a)
        {
            LogManager.Write("j");

            // unload previous view
            unloadViewAddressbook();

            LogManager.Write("k");

            // when there is a search keyword filled in
            // refreshing the contacts list will only render the search results
            if (search.Text.Length > 0)
            {
                LogManager.Write("l");
                updateSearchbook();
                LogManager.Write("m");
                a = searchbook;
            }

            LogManager.Write("n");

            searchButton.Show();
            search.Show();
            adressbookname.Show();
            addContact.Show();
            contacts.Show();
            contactname.Show();
            emailadress.Show();

            adressbookname.Text = "Adressbook Name: " + a.name;

            // change the visible addressbook
            makeForm(a);

            LogManager.Write("o");

            this.Invalidate();
            this.Refresh();

            // Check if all contacts in a adressbook are displayed when switching views
            // Oracle or code seems to have errors...
            bool b = false;

            for (int j = 0; j < contactnames.Count; j++)
            {
                b = adressbooks[current].Contacts[j].name == contactnames[j].Text;
                if (b == false)
                {
                    break;
                }
            }
            LogManager.Oracle(": All contacts from the current adressboek have labels", b);
        }
        // creating a new addressbook when user pressed the "add" button
        private void addAdressbook_Click(object sender, EventArgs e)
        {
            Adressbook a = new Adressbook(abn.Text);

            if (a.Validate(abn.Text))
            {
                // name of addressbook is valid, create it!
                adressbooks.Add(a);
                current = adressbooks.IndexOf(a);
                changeViewTo("addressbook");
                bool b = (adressbookname.Text == "Adressbook Name: " + abn.Text);
                LogManager.Oracle(": Add adressbook the same name as Label", b);
            }
            else
            {
                MessageBox.Show("Adressbook name too long"); //no valid name
                abn.Text = "";
            }
        }
Esempio n. 4
0
        // fill addressbook with sample contacts
        private void Sample()
        {
            Adressbook a = new Adressbook("sample");

            a.Add(new Contact("Bla", "*****@*****.**"));
            a.Add(new Contact("Pa", "*****@*****.**"));
            a.Add(new Contact("Ma", "*****@*****.**"));
            adressbooks.Add(a);
            a = new Adressbook("sample2");
            a.Add(new Contact("Bas Meesters", "*****@*****.**"));
            a.Add(new Contact("Jarno Le Conte", "*****@*****.**"));
            adressbooks.Add(a);
            a = new Adressbook("sample3");
            a.Add(new Contact("Henk", "*****@*****.**"));
            a.Add(new Contact("Jan", "*****@*****.**"));
            a.Add(new Contact("Piet", "*****@*****.**"));
            a.Add(new Contact("Henkie", "*****@*****.**"));
            a.Add(new Contact("Janneke", "*****@*****.**"));
            a.Add(new Contact("Pieter", "*****@*****.**"));
            a.Add(new Contact("Gerda", "*****@*****.**"));
            a.Add(new Contact("Bettie", "*****@*****.**"));
            a.Add(new Contact("Peter", "*****@*****.**"));
            adressbooks.Add(a);
        }
        // redraw list of contacts from the given addressbook
        private void makeForm(Adressbook a)
        {
            LogManager.Write("p");
            int y = 108;

            // show all contacts
            for (int i = 0; i < a.contacts.Count; i++)
            {
                LogManager.Write("q");

                Contact contact = a.contacts[i];

                contactnames.Add(new Label());
                contactnames[i].Location = new Point(45, y);
                contactnames[i].Text     = a.contacts[i].name;
                this.Controls.Add(contactnames[i]);

                emailadresses.Add(new Label());
                emailadresses[i].Location = new Point(220, y);
                emailadresses[i].Text     = a.contacts[i].email;
                emailadresses[i].Size     = new Size(170, 15);
                this.Controls.Add(emailadresses[i]);

                deletebuttons.Add(new Button());
                deletebuttons[i].Location = new Point(400, y);
                deletebuttons[i].Name     = "Delete Contact " + i;
                deletebuttons[i].Text     = "Delete Contact";
                deletebuttons[i].Click   += delegate(Object o, EventArgs e)
                {
                    delete_Click(o, e, contact);
                };
                this.Controls.Add(deletebuttons[i]);
                y += 22;
            }

            LogManager.Write("r");

            // button to remove all visible contacts
            Button removeAllBtn = new Button();

            removeAllBtn.Location = new Point(45, y + 22);
            removeAllBtn.Text     = "Remove all";
            removeAllBtn.Click   += removeAll_Click;
            this.Controls.Add(removeAllBtn);
            deletebuttons.Add(removeAllBtn);

            // button to copy all contacts to the selected addressbook
            Button copyAllBtn = new Button();

            copyAllBtn.Location = new Point(125, y + 22);
            copyAllBtn.Text     = "Copy all to:";
            copyAllBtn.Click   += copyAll_Click;
            this.Controls.Add(copyAllBtn);
            deletebuttons.Add(copyAllBtn);

            // select a addressbook to copy contact to
            copyAllCombo.Show();
            copyAllCombo.Items.Clear();
            copyAllCombo.Location = new Point(200, y + 23);
            foreach (Adressbook adb in adressbooks)
            {
                LogManager.Write("s");
                Adressbook currentadb = getCurrentAddressbook();
                LogManager.Write("t");
                if (adb != currentadb)
                {
                    LogManager.Write("u");
                    copyAllCombo.Items.Add(adb.name);
                }
                LogManager.Write("v");
            }

            LogManager.Write("w");
        }