示例#1
0
        private async void barButtonDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                if (applicationControl != null)
                {
                    await applicationControl.DeleteItemButtonClicked();
                }
                else
                {
                    var application = gridViewApplications.GetRow(gridViewApplications.FocusedRowHandle) as SettingsApplication;

                    if (application != null)
                    {
                        if (string.Equals(application.Name, "root") || string.Equals(application.Name, "system"))
                        {
                            MessageBox.Show("This application can not be deleted", "System directory", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (ConfirmMessageBox.Show(string.Format("Are you sure you want to delete application {0} and all its settings?", application.Name)) == DialogResult.OK)
                        {
                            await settingsManager.DeleteApplicationAsync(application.Name);
                            await GetApplications();
                        }
                    }
                }
            }
            catch (SettingsException ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public async Task DeleteItemButtonClicked()
        {
            if (Level == ApplicationControlLevel.Directory)
            {
                var directory = gridViewDirectories.GetRow(gridViewDirectories.FocusedRowHandle) as SettingsDirectory;

                if (directory != null)
                {
                    if (string.Equals(directory.Name, "root") || string.Equals(directory.Name, "system"))
                    {
                        MessageBox.Show("This directory can not be deleted", "System directory", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (ConfirmMessageBox.Show(string.Format("Are you sure you want to delete directory {0} and all its settings?", directory.Name)) == DialogResult.OK)
                    {
                        try
                        {
                            OnShowProgress();

                            await settingsManager.DeleteDirectoryAsync(Application.Name, directory.Name);
                            await RefreshButtonClicked();
                        }
                        finally
                        {
                            OnHideProgress();
                        }
                    }
                }
            }
            else
            {
                var setting = gridViewSettings.GetRow(gridViewSettings.FocusedRowHandle) as Setting;

                if (setting != null)
                {
                    if (ConfirmMessageBox.Show(string.Format("Are you sure you want to delete setting key {0} for Object {1}.?", setting.Key, setting.ObjectId)) == DialogResult.OK)
                    {
                        try
                        {
                            OnShowProgress();

                            await currentDirectory.DeleteAsync(setting.ObjectId, setting.Key);
                            await RefreshButtonClicked();
                        }
                        finally
                        {
                            OnHideProgress();
                        }
                    }
                }
            }
        }