Esempio n. 1
0
        private void addConnectionItem()
        {
            tabControl.SelectTab("tabPageConnections");
            ConnectionWindow window = new ConnectionWindow();
            DialogResult result = window.ShowDialog();
            if (result == DialogResult.OK)
            {
                ConnectionObject conObj = window.getConnectionObject();
                if (conObj != null)
                {
                    // Add to local collection
                    SettingsObject.ListConnections.Add(conObj);

                    // Get object from foreign key
                    HostConfigObject pop3Obj = SettingsObject.ListPOP3[conObj.Pop3ID];
                    HostConfigObject smtpObj = SettingsObject.ListSMTP[conObj.SmtpID];
                    AddressObject addObj = SettingsObject.ListAddress[conObj.AddressID];

                    // Add listview entry
                    ListViewItem item = new ListViewItem(new string[] { "", pop3Obj.Description, smtpObj.Description, addObj.AddressName });
                    item.Checked = true;
                    this.listViewConnections.Items.Add(item);
                    this.listViewConnections.Sort();
                }
            }
        }
Esempio n. 2
0
        private void editConnectionItem()
        {
            tabControl.SelectTab("tabPageConnections");

            ListView.SelectedIndexCollection selectedItems = this.listViewConnections.SelectedIndices;
            if (selectedItems != null && selectedItems.Count > 0)
            {
                ConnectionObject currentConObj = SettingsObject.ListConnections[selectedItems[0]];
                ConnectionWindow window = new ConnectionWindow(currentConObj);
                DialogResult result = window.ShowDialog();
                if (result == DialogResult.OK)
                {
                    ConnectionObject newConObj = window.getConnectionObject();
                    if (newConObj != null)
                    {
                        // Remove old object from collection
                        SettingsObject.ListConnections.Remove(currentConObj);

                        // Add new object to collection
                        SettingsObject.ListConnections.Add(newConObj);

                        // Remove old listview entry
                        this.listViewConnections.Items.RemoveAt(selectedItems[0]);

                        // Get object from foreign key
                        HostConfigObject pop3Obj = SettingsObject.ListPOP3[newConObj.Pop3ID];
                        HostConfigObject smtpObj = SettingsObject.ListSMTP[newConObj.SmtpID];
                        AddressObject addObj = SettingsObject.ListAddress[newConObj.AddressID];

                        // Add new listview entry
                        ListViewItem item = new ListViewItem(new string[] { "", pop3Obj.Description, smtpObj.Description, addObj.AddressName });
                        item.Checked = newConObj.Active;
                        this.listViewConnections.Items.Add(item);
                        this.listViewConnections.Sort();
                    }
                }
            }
        }