Show() public static method

Shows a custom Toast message with the specified icon
public static Show ( string Message, string SubText, AlertType Type = AlertType.Info ) : void
Message string
SubText string
Type AlertType
return void
Example #1
0
        /// <summary>
        /// Exports player XML sheet
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fromPlayerExportSheetMenuItem_Click(object sender, EventArgs e)
        {
            // Create export directory if it doesnt exist yet
            string sPath = Path.Combine(Paths.DocumentsFolder, "Player Backups");

            if (!Directory.Exists(sPath))
            {
                Directory.CreateDirectory(sPath);
            }

            // Show dialog
            OpenFileDialog Dialog = new OpenFileDialog();

            Dialog.InitialDirectory = sPath;
            Dialog.Title            = "Select Player Import File";
            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    StatsManager.ImportPlayerXml(Dialog.FileName);
                    Notify.Show("Player Imported Successfully", "Operation Successful", AlertType.Success);
                    BuildList();
                }
                catch (Exception E)
                {
                    using (ExceptionForm EForm = new ExceptionForm(E, false))
                    {
                        EForm.Message = "Unable to import player because an exception was thrown!";
                        EForm.ShowDialog();
                    }
                }
            }
        }
 /// <summary>
 /// Clears the stats database of all data
 /// </summary>
 private void ClearStatsBtn_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show(
             "Are you sure you want to clear the stats database? This will ERASE ALL stats data, and cannot be recovered!",
             "Confirm",
             MessageBoxButtons.OKCancel,
             MessageBoxIcon.Warning) == DialogResult.OK)
     {
         try
         {
             using (StatsDatabase Database = new StatsDatabase())
             {
                 Database.Truncate();
             }
             Notify.Show("Database Successfully Cleared!", "All stats have successfully been cleared.", AlertType.Success);
         }
         catch (Exception E)
         {
             MessageBox.Show(
                 "An error occured while clearing the stats database!\r\n\r\nMessage: " + E.Message,
                 "Error",
                 MessageBoxButtons.OK,
                 MessageBoxIcon.Error
                 );
         }
     }
 }
Example #3
0
        /// <summary>
        /// Export player menu item click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exportPlayerMenuItem_Click(object sender, EventArgs e)
        {
            // Get players ID and Nick
            int    Pid  = Int32.Parse(DataTable.SelectedRows[0].Cells[1].Value.ToString());
            string Name = DataTable.SelectedRows[0].Cells[2].Value.ToString();

            // Create export directory if it doesnt exist yet
            string sPath = Path.Combine(Paths.DocumentsFolder, "Player Backups");

            if (!Directory.Exists(sPath))
            {
                Directory.CreateDirectory(sPath);
            }

            // Have user select folder
            FolderSelect.FolderSelectDialog Dialog = new FolderSelect.FolderSelectDialog();
            Dialog.InitialDirectory = sPath;
            Dialog.Title            = "Select folder to export player to";
            if (Dialog.ShowDialog())
            {
                try
                {
                    StatsManager.ExportPlayerXml(sPath, Pid, Name);
                    Notify.Show("Player Exported Successfully", String.Format("{0} ({1})", Name, Pid), AlertType.Success);
                }
                catch (Exception E)
                {
                    using (ExceptionForm EForm = new ExceptionForm(E, false))
                    {
                        EForm.Message = "Unable to export player because an exception was thrown!";
                        EForm.ShowDialog();
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Event fired when the save button is clicked
        /// </summary>
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            // Clear old data
            StatsPython.Config.XpackMedalMods.Clear();

            // Loop through each control and grab the checkboxes
            foreach (Control C in panel2.Controls)
            {
                // Make sure the check box is visible
                if (C is CheckBox && (C as CheckBox).Checked)
                {
                    // Get our mod name
                    string modName = C.Tag as String;
                    if (String.IsNullOrWhiteSpace(modName))
                    {
                        continue;
                    }

                    // Add mod
                    StatsPython.Config.XpackMedalMods.Add(modName.ToLowerInvariant());
                }
            }

            // Save Config
            StatsPython.Config.Save();
            Notify.Show("Config saved successfully!", "Xpack Enabled Medals Updated Sucessfully");
            this.Close();
        }
        /// <summary>
        /// Reset Unlocks Button Click Event
        /// </summary>
        private void ResetUnlocksBtn_Click(object sender, EventArgs e)
        {
            try
            {
                // Create New Player Unlock Data
                StringBuilder Query = new StringBuilder("INSERT INTO unlocks VALUES ");

                // Normal unlocks
                for (int i = 11; i < 100; i += 11)
                {
                    Query.AppendFormat("({0}, {1}, 'n'), ", Pid, i);
                }

                // Sf Unlocks
                for (int i = 111; i < 556; i += 111)
                {
                    Query.AppendFormat("({0}, {1}, 'n')", Pid, i);
                    if (i != 555)
                    {
                        Query.Append(", ");
                    }
                }

                // Do driver queries
                using (StatsDatabase Driver = new StatsDatabase())
                    using (DbTransaction T = Driver.BeginTransaction())
                    {
                        try
                        {
                            // Perform queries
                            Driver.Execute("DELETE FROM unlocks WHERE id = " + Pid);
                            Driver.Execute("UPDATE player SET usedunlocks = 0 WHERE id = " + Pid);
                            Driver.Execute(Query.ToString());
                            T.Commit();

                            // Notify user
                            Notify.Show("Player Unlocks Have Been Reset", "This player will be able to select his new unlocks upon logging in.", AlertType.Success);
                        }
                        catch
                        {
                            T.Rollback();
                            throw;
                        }
                    }
            }
            catch (DbConnectException Ex)
            {
                HttpServer.Stop();
                ExceptionForm.ShowDbConnectError(Ex);
                this.Close();
            }
        }
        /// <summary>
        /// Reset stats button click event
        /// </summary>
        private async void ResetStatsBtn_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to reset players stats?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                try
                {
                    TaskForm.Show(this, "Reset Player Stats", "Reseting Player \"" + Player["name"] + "\"'s Stats", false);
                    await Task.Run(() =>
                    {
                        // Delete the players
                        using (StatsDatabase Driver = new StatsDatabase())
                        {
                            // Delete old player statistics
                            Driver.DeletePlayer(Pid, TaskForm.Progress);

                            // Insert a new player record
                            Driver.Execute(
                                "INSERT INTO player(id, name, country, joined, clantag, permban, isbot) VALUES(@P0, @P1, @P2, @P3, @P4, @P5, @P6)",
                                Pid, Player["name"], Player["country"], Player["joined"], Player["clantag"], Player["permban"], Player["isbot"]
                                );
                        }
                    });

                    // Reload player
                    LoadPlayer();
                    Notify.Show("Player Stats Reset Successfully!", "Operation Successful", AlertType.Success);
                }
                catch (DbConnectException Ex)
                {
                    HttpServer.Stop();
                    ExceptionForm.ShowDbConnectError(Ex);
                    TaskForm.CloseForm();
                    this.Close();
                    return;
                }
                catch (Exception E)
                {
                    // Show exception error
                    using (ExceptionForm Form = new ExceptionForm(E, false))
                    {
                        Form.Message = String.Format("Failed to reset player stats!{1}{1}Error: {0}", E.Message, Environment.NewLine);
                        Form.ShowDialog();
                    }
                }
                finally
                {
                    // Close task form
                    TaskForm.CloseForm();
                }
            }
        }
 /// <summary>
 /// Event fired when the Delete button is pushed
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void DeleteBtn_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to delete account?", "Confirm",
                         MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         using (GamespyDatabase Database = new GamespyDatabase())
         {
             if (Database.DeleteUser(AccountId) == 1)
             {
                 Notify.Show("Account deleted successfully!", "Operation Successful", AlertType.Success);
             }
             else
             {
                 Notify.Show("Failed to remove account from database!", "Operation failed", AlertType.Warning);
             }
         }
         this.Close();
     }
 }
        /// <summary>
        /// Saves the current settings to the BF2Statistics.py file
        /// </summary>
        private void SaveButton_Click(object sender, EventArgs e)
        {
            // Medal Data parsing
            string data = "";

            if (MedalData.Text != "Default")
            {
                data = MedalData.Text;
            }

            // Do replacements
            StatsPython.Config.StatsEnabled                   = (RankMode.SelectedIndex == 1);
            StatsPython.Config.DebugEnabled                   = (Debugging.SelectedIndex == 1);
            StatsPython.Config.SnapshotLogging                = Logging.SelectedIndex;
            StatsPython.Config.SnapshotPrefix                 = SnapshotPrefix.Text;
            StatsPython.Config.MedalDataProfile               = data;
            StatsPython.Config.AspAddress                     = System.Net.IPAddress.Parse(AspAddress.Text);
            StatsPython.Config.CentralAspAddress              = System.Net.IPAddress.Parse(CentralAddress.Text);
            StatsPython.Config.AspPort                        = (int)AspPort.Value;
            StatsPython.Config.CentralAspPort                 = (int)CentralPort.Value;
            StatsPython.Config.AspFile                        = AspCallback.Text;
            StatsPython.Config.CentralStatsMode               = CentralDatabase.SelectedIndex;
            StatsPython.Config.CentralAspFile                 = CentralCallback.Text;
            StatsPython.Config.ClanManager.Enabled            = (ClanManager.SelectedIndex == 1);
            StatsPython.Config.ClanManager.ServerMode         = CmServerMode.SelectedIndex;
            StatsPython.Config.ClanManager.ClanTagRequirement = CmClanTag.Text;
            StatsPython.Config.ClanManager.ScoreRequirement   = (int)CmGlobalScore.Value;
            StatsPython.Config.ClanManager.TimeRequirement    = (int)CmGlobalTime.Value;
            StatsPython.Config.ClanManager.KDRatioRequirement = CmKDRatio.Value;
            StatsPython.Config.ClanManager.MaxBanCount        = (int)CmBanCount.Value;
            StatsPython.Config.ClanManager.CountryRequirement = CmCountry.Text;
            StatsPython.Config.ClanManager.RankRequirement    = CmMinRank.SelectedIndex;

            // Save File
            StatsPython.Config.Save();
            Notify.Show("Config saved successfully!", "The BF2Statistics config was sucessfully updated");
            this.Close();
        }
        /// <summary>
        /// Finishes the import process
        /// </summary>
        private void bWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // Close the task form
            TaskForm.CloseForm();

            // Close this form!
            if (e.Error != null)
            {
                Exception E = e.Error as Exception;
                MessageBox.Show(
                    "An error occured while trying to import player stats."
                    + Environment.NewLine + Environment.NewLine + E.Message,
                    "Import Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
                this.Close();
                return;
            }

            Notify.Show("Player Imported Successfully!", "All the players stats and awards are now available on the server.", AlertType.Success);
            this.Close();
        }
        /// <summary>
        /// Delete Account menu item click event
        /// </summary>
        private void menuItemDelete_Click(object sender, System.EventArgs e)
        {
            int    Id   = Int32.Parse(DataTable.SelectedRows[0].Cells[0].Value.ToString());
            string Name = DataTable.SelectedRows[0].Cells[1].Value.ToString();

            if (MessageBox.Show("Are you sure you want to delete account \"" + Name + "\"?",
                                "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                using (GamespyDatabase Database = new GamespyDatabase())
                {
                    if (Database.DeleteUser(Id) == 1)
                    {
                        Notify.Show("Account deleted successfully!", "Operation Successful", AlertType.Success);
                    }
                    else
                    {
                        Notify.Show("Failed to remove account from database!", "Operation Failed", AlertType.Warning);
                    }
                }

                BuildList();
            }
        }
        /// <summary>
        /// Export Player Button Click Event
        /// </summary>
        private void ExportPlayerBtn_Click(object sender, EventArgs e)
        {
            // Create export directory if it doesnt exist yet
            string sPath = Path.Combine(Paths.DocumentsFolder, "Player Backups");

            if (!Directory.Exists(sPath))
            {
                Directory.CreateDirectory(sPath);
            }

            // Have user select folder
            FolderSelect.FolderSelectDialog Dialog = new FolderSelect.FolderSelectDialog();
            Dialog.InitialDirectory = sPath;
            Dialog.Title            = "Select folder to export player to";
            if (Dialog.ShowDialog())
            {
                try
                {
                    StatsManager.ExportPlayerXml(sPath, Pid, Player["name"].ToString());
                    Notify.Show("Player Exported Successfully", String.Format("{0} ({1})", Player["name"].ToString(), Pid), AlertType.Success);
                }
                catch (DbConnectException Ex)
                {
                    HttpServer.Stop();
                    ExceptionForm.ShowDbConnectError(Ex);
                    this.Close();
                }
                catch (Exception E)
                {
                    using (ExceptionForm EForm = new ExceptionForm(E, false))
                    {
                        EForm.Message = "Unable to export player because an exception was thrown!";
                        EForm.ShowDialog();
                    }
                }
            }
        }
        /// <summary>
        /// Delete Player Button Click Event
        /// </summary>
        private async void DeletePlayerBtn_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete player?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                try
                {
                    TaskForm.Show(this, "Delete Player", "Deleting Player \"" + Player["name"] + "\"", false);

                    // Delete the player
                    using (StatsDatabase Driver = new StatsDatabase())
                        await Task.Run(() => Driver.DeletePlayer(Pid, TaskForm.Progress));

                    Notify.Show("Player Deleted Successfully!", "Operation Successful", AlertType.Success);
                }
                catch (DbConnectException Ex)
                {
                    HttpServer.Stop();
                    ExceptionForm.ShowDbConnectError(Ex);
                }
                catch (Exception E)
                {
                    // Show exception error
                    using (ExceptionForm Form = new ExceptionForm(E, false))
                    {
                        Form.Message = String.Format("Failed to remove player from database!{1}{1}Error: {0}", E.Message, Environment.NewLine);
                        Form.ShowDialog();
                    }
                }
                finally
                {
                    // Close task form
                    TaskForm.CloseForm();
                    this.Close();
                }
            }
        }
        private void ExportSettingsMenuItem_Click(object sender, EventArgs e)
        {
            // Warn the user about saved changes
            DialogResult res = MessageBox.Show(
                "Changes made since this window was opened will not reflect in the ScoringSettings.xml file "
                + "without reloading the saved changes. Would you like me to reload the last saved values?",
                "Reload Settings", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question
                );

            // Return if user cancels
            if (res == DialogResult.Cancel)
            {
                return;
            }

            // Show loading form
            LoadingForm.ShowScreen(this);

            // Reload settings!
            if (res == DialogResult.Yes && (!LoadConqFile() || !LoadCoopFile() || !LoadScoringCommon()))
            {
                LoadingForm.CloseForm();
                return;
            }

            try
            {
                // Define our file path and
                string file = Path.Combine(Paths.DocumentsFolder, "ScoringSettings.xml");

                // Generate our mappings
                Dictionary <string, string[]>[] types = { Scores, ConqScores, CoopScores };
                string[] names = { "general", "conquest", "coop" };

                // Create XML Settings
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent          = true;
                settings.IndentChars     = "\t";
                settings.NewLineChars    = Environment.NewLine;
                settings.NewLineHandling = NewLineHandling.Replace;

                // Write to file
                using (FileStream stream = File.Open(file, FileMode.Create))
                    using (XmlWriter Writer = XmlWriter.Create(stream, settings))
                    {
                        // Player Element
                        Writer.WriteStartDocument();

                        // Write editing warning
                        Writer.WriteComment(" Auto Generated :: Please DO NOT Edit Me! ");

                        // Begin
                        Writer.WriteStartElement("settings");

                        // Itterate through all setting catagories
                        for (int i = 0; i < 3; i++)
                        {
                            // Start general Element
                            Writer.WriteStartElement(names[i]);

                            // Add each scoring item to the XML
                            foreach (KeyValuePair <string, string[]> item in types[i])
                            {
                                // Open Row tag
                                Writer.WriteStartElement("item");
                                Writer.WriteAttributeString("name", item.Key);
                                Writer.WriteValue(item.Value[0]);
                                Writer.WriteEndElement();
                            }

                            // Close settings element
                            Writer.WriteEndElement();
                        }

                        // Close Tags and File
                        Writer.WriteEndElement();  // Close general Element
                        Writer.WriteEndDocument(); // End and Save file
                    }

                // Notify user
                Notify.Show("Settings Exported", "Scoring settings were exported successfully!", AlertType.Success);
            }
            finally
            {
                LoadingForm.CloseForm();
            }
        }
        /// <summary>
        /// Imports ASP created BAK files (Mysql Out FILE)
        /// </summary>
        private async void ImportASPBtn_Click(object sender, EventArgs e)
        {
            // Open File Select Dialog
            FolderSelectDialog Dialog = new FolderSelectDialog();

            Dialog.Title            = "Select ASP Database Backup Folder";
            Dialog.InitialDirectory = Path.Combine(Paths.DocumentsFolder, "Database Backups");
            if (Dialog.ShowDialog())
            {
                // Get files list from path
                string   path     = Dialog.SelectedPath;
                string[] BakFiles = Directory.GetFiles(path, "*.bak");
                if (BakFiles.Length > 0)
                {
                    // Open the database connection
                    StatsDatabase Database = null;
                    try {
                        Database = new StatsDatabase();
                    }
                    catch (Exception Ex)
                    {
                        if (Ex is DbConnectException)
                        {
                            ExceptionForm.ShowDbConnectError(Ex as DbConnectException);
                            return;
                        }

                        MessageBox.Show(
                            "Unable to connect to database\r\n\r\nMessage: " + Ex.Message,
                            "Database Connection Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error
                            );
                        return;
                    }
                    finally
                    {
                        if (Database == null)
                        {
                            // Stop the ASP server, and close this form
                            HttpServer.Stop();
                            this.Close();
                        }
                    }

                    // Show task dialog
                    TaskForm.Show(this, "Importing Stats", "Importing ASP Stats Bak Files...", false);
                    this.Enabled = false;

                    // Don't block the GUI
                    await Task.Run(() => ImportFromBakup(BakFiles, Database));

                    // Alert user and close task form
                    Notify.Show("Stats imported successfully!", "Operation Successful", AlertType.Success);
                    TaskForm.CloseForm();
                    this.Enabled = true;

                    // Displose Connection
                    Database.Dispose();
                }
                else
                {
                    // Alert the user and tell them they failed
                    MessageBox.Show(
                        "Unable to locate any .bak files in this folder. Please select an ASP created database backup folder that contains backup files.",
                        "Backup Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                }
            }
        }
        private void CreateBtn_Click(object sender, EventArgs e)
        {
            int Pid = (int)PidBox.Value;

            using (GamespyDatabase Database = new GamespyDatabase())
            {
                // Make sure there is no empty fields!
                if (AccountName.Text.Trim().Length < 3)
                {
                    MessageBox.Show("Please enter a valid account name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (AccountPass.Text.Trim().Length < 3)
                {
                    MessageBox.Show("Please enter a valid account password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (!Validator.IsValidEmail(AccountEmail.Text))
                {
                    MessageBox.Show("Please enter a valid account email", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                // Check if PID exists (for changing PID)
                if (PidSelect.SelectedIndex == 1)
                {
                    if (!Validator.IsValidPID(Pid.ToString()))
                    {
                        MessageBox.Show("Invalid PID Format. A PID must be 8 or 9 digits in length", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    else if (Database.UserExists(Pid))
                    {
                        MessageBox.Show("PID is already in use. Please enter a different PID.", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                // Check if the user exists
                if (Database.UserExists(AccountName.Text))
                {
                    MessageBox.Show("Account name is already in use. Please select a different Account Name.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                try
                {
                    // Attempt to create the account
                    if (PidSelect.SelectedIndex == 1)
                    {
                        Database.CreateUser(Pid, AccountName.Text, AccountPass.Text, AccountEmail.Text, "00");
                    }
                    else
                    {
                        Database.CreateUser(AccountName.Text, AccountPass.Text, AccountEmail.Text, "00");
                    }

                    Notify.Show("Account Created Successfully!", AccountName.Text, AlertType.Success);
                }
                catch (Exception E)
                {
                    MessageBox.Show(E.Message, "Account Create Error");
                }
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }