Beispiel #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (listConnections.SelectedObjects.Count != 1)
            {
                return;
            }

            Connection connection = (Connection)listConnections.SelectedObjects[0];

            Connections connections = new Connections();
            string ret = connections.Load();
            if (ret.Length > 0)
            {
                UserInterface.DisplayErrorMessageBox(this, "An error occurred whilst loading the connections");
                return;
            }

            DialogResult dialogResult = MessageBox.Show(this,
                                                        "Are you sure you want to delete the connection? " + Environment.NewLine + Environment.NewLine +
                                                        "Name: " + connection.Name,
                                                        Application.ProductName,
                                                        MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Question);

            if (dialogResult == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            int numRemoved = connections.Data.RemoveAll(c => c.Name == connection.Name & c.ConnectionString == connection.ConnectionString);
            if (numRemoved == 0)
            {
                UserInterface.DisplayErrorMessageBox(this, "The connection could not be removed");
                return;
            }

            ret = connections.Save();
            if (ret.Length > 0)
            {
                UserInterface.DisplayErrorMessageBox(this, "An error occurred whilst saving the connections");
                return;
            }

            LoadConnections();
        }