private void DefaultToolStripButton_Click(object sender, EventArgs e)
    {
        if (!ConfigHandler.RegistryModifyAccess)
        {
            if (ConfigHandler.UseTranslation)
            {
                MessageBox.Show(Translator.GetText("ModifyDefaultSearchNoAccess"));
            }
            else
            {
                MessageBox.Show("Logged in user does not have necessary rights to modify the default search.\r\n\r\nUser needs modify access to HKLM in RegEdit.", GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return;
        }

        if (toolStripDropDownButton1.Text == _defaultSavedSearch)
        {
            RegistryHandler.Delete(string.Format("DefaultSavedSearch_{0}", _registryName));
            defaultToolStripButton.Image = Resources.star1;
            _defaultSavedSearch          = "";
        }
        else
        {
            RegistryHandler.SaveToRegistry(string.Format("DefaultSavedSearch_{0}", _registryName), toolStripDropDownButton1.Text);
            defaultToolStripButton.Image = Resources.star;
            _defaultSavedSearch          = toolStripDropDownButton1.Text;
        }

        string selectedSavedSearch = toolStripDropDownButton1.Text;

        PopulateSavedSearchesToolStrip();
        toolStripDropDownButton1.Text = selectedSavedSearch;
    }
예제 #2
0
    public static string Encode(string connectionString, string keyName)
    {
        if (connectionString == "")
        {
            return("");
        }

        SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(connectionString);

        string regKeyName = string.Format("Password_{0}", keyName);

        if (!connBuilder.IntegratedSecurity)
        {
            string clearTextPassword = connBuilder.Password;
            string ecryptedPassword  = AesEncrypt(clearTextPassword, _cipherKey);
            byte[] protectedPassword = ProtectedData.Protect(Encoding.UTF8.GetBytes(ecryptedPassword), null, DataProtectionScope.CurrentUser);
            RegistryHandler.SaveByte(regKeyName, protectedPassword);
            connBuilder.Password = "";
        }
        else
        {
            RegistryHandler.Delete(regKeyName);
        }

        return(connBuilder.ToString());
    }
    private void DeleteLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        string text = "Delete the saved password?";

        if (ConfigHandler.UseTranslation)
        {
            text = Translator.GetText("DeleteSavedValue");
        }

        DialogResult result = OutputHandler.Show(text, GenericHelper.ApplicationName, MessageBoxButtons.YesNo, MessageBoxIcon.Information);

        if (result == DialogResult.Yes)
        {
            if (ConfigHandler.RegistryModifyAccess)
            {
                RegistryHandler.Delete("Password_ConnectionString");
                passwordTextBox.Text = "";
            }
            else
            {
                if (ConfigHandler.UseTranslation)
                {
                    MessageBox.Show(Translator.GetText("DeletePasswordNoAccess"));
                }
                else
                {
                    MessageBox.Show("Logged in user does not have necessary rights to delete the saved password.\r\n\r\nUser needs modify access to HKLM in RegEdit.", GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
    }
    private void DeleteToolStripButton_Click(object sender, EventArgs e)
    {
        if (!ConfigHandler.RegistryModifyAccess)
        {
            if (ConfigHandler.UseTranslation)
            {
                MessageBox.Show(Translator.GetText("DeleteSearchNoAccess"));
            }
            else
            {
                MessageBox.Show("Logged in user does not have necessary rights to delete the saved search.\r\n\r\nUser needs modify access to HKLM in RegEdit.", GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return;
        }

        string savedSearchName = toolStripDropDownButton1.Text;

        if (SavedSearchesHandler.IsSystemObject(savedSearchName, _registryName))
        {
            string text1 = "The selected search is a system object and can not be deleted.";

            if (ConfigHandler.UseTranslation)
            {
                text1 = Translator.GetText("CanNotDeleteSystemObject");
            }

            OutputHandler.Show(text1, GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);

            return;
        }

        string text = "Delete search \"{0}\"?";

        if (ConfigHandler.UseTranslation)
        {
            text = Translator.GetText("DeleteSearch");
        }

        DialogResult result = OutputHandler.Show(string.Format(text, savedSearchName), GenericHelper.ApplicationName, MessageBoxButtons.YesNo, MessageBoxIcon.Information);

        if (result == DialogResult.Yes)
        {
            SavedSearchesHandler.Delete(savedSearchName, _registryName);
            deleteToolStripButton.Enabled = false;
            PopulateSavedSearchesToolStrip();

            if (savedSearchName == _defaultSavedSearch)
            {
                RegistryHandler.Delete(string.Format("DefaultSavedSearch_{0}", _registryName));
                defaultToolStripButton.Image = Resources.star1;
                _defaultSavedSearch          = "";
            }
        }
    }