/// <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(); }