BF2Statistics.MedalData.MedalDataEditor.DelProfileBtn_Click C# (CSharp) Method

DelProfileBtn_Click() private method

Deletes the selected profile
private DelProfileBtn_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void DelProfileBtn_Click(object sender, EventArgs e)
        {
            // Always confirm
            if (MessageBox.Show("Are you sure you want to delete this medal data profile?",
                "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                // Make my typing easier in the future
                string Profile = ProfileSelector.SelectedItem.ToString();
                this.Enabled = false;

                try
                {
                    // Delete medal data files
                    File.Delete(Path.Combine(PythonPath, "medal_data_" + Profile + ".py"));

                    // Set current selected profile to null in the Bf2sConfig
                    if (StatsPython.Config.MedalDataProfile == Profile)
                    {
                        // Unselect this as the default profile
                        ActiveProfile = null;
                        StatsPython.Config.MedalDataProfile = "";
                        StatsPython.Config.Save();
                    }

                    // Update form
                    ActivateProfileBtn.Text = "Set as Server Profile";
                    ActivateProfileBtn.BackgroundImage = Resources.power;
                }
                catch (Exception ex)
                {
                    Notify.Show("Unable to Delete Profile Medaldata Files!", "Error: " + ex.Message, AlertType.Warning);
                    this.Enabled = true;
                    return;
                }

                // Suppress repainting the TreeView until all the objects have been created.
                AwardConditionsTree.Nodes.Clear();
                AwardTree.BeginUpdate();

                // Remove old medal data if applicable
                for (int i = 0; i < 4; i++)
                {
                    AwardTree.Nodes[i].Nodes.Clear();
                    AwardTree.Nodes[i].ForeColor = Color.Black;
                }
                AwardTree.EndUpdate();

                // Disable some form controls
                AwardTree.Enabled = false;
                AwardConditionsTree.Enabled = false;
                DelProfileBtn.Enabled = false;
                ActivateProfileBtn.Enabled = false;
                SaveBtn.Enabled = false;

                // Reset controls
                AwardNameBox.Text = null;
                AwardTypeBox.Text = null;
                AwardPictureBox.Image = null;
                ProfileSelector.SelectedIndex = -1;
                LastSelectedProfile = null;
                LoadProfiles();
                this.Enabled = true;

                // Notify User
                Notify.Show("Medal Data Profile Deleted Successfully.", "Operation Successful", AlertType.Success);
            }
        }