/// <summary> /// Import Stats Button Click Event /// </summary> private void ImportBtn_Click(object sender, EventArgs e) { // Make sure PID text box is a valid PID if (!Validator.IsValidPID(PidTextBox.Text)) { MessageBox.Show("The player ID entered is NOT a valid PID. Please try again.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Establist Database connection try { using (StatsDatabase Database = new StatsDatabase()) { // Make sure the PID doesnt exist already int Pid = Int32.Parse(PidTextBox.Text); if (Database.PlayerExists(Pid)) { MessageBox.Show("The player ID entered already exists.", "Import Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // Show Task Form TaskForm.Show(this, "Import ASP Stats", "Importing ASP Stats...", false, ProgressBarStyle.Blocks, 13); // Setup the worker bWorker = new BackgroundWorker(); bWorker.WorkerSupportsCancellation = false; bWorker.WorkerReportsProgress = true; // Run Worker bWorker.DoWork += bWorker_ImportEaStats; bWorker.ProgressChanged += (s, ea) => { TaskForm.Progress.Report(new TaskProgressUpdate(ea.UserState.ToString(), ea.ProgressPercentage)); }; bWorker.RunWorkerCompleted += bWorker_RunWorkerCompleted; bWorker.RunWorkerAsync(PidTextBox.Text); } } catch (DbConnectException Ex) { ExceptionForm.ShowDbConnectError(Ex); HttpServer.Stop(); this.Close(); return; } }
/// <summary> /// Event fired when the Submit button is pushed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdateBtn_Click(object sender, EventArgs e) { int Pid = (int)PlayerID.Value; using (GamespyDatabase Database = new GamespyDatabase()) { // Make sure there is no empty fields! if (AccountNick.Text.Trim().Length < 3) { MessageBox.Show("Please enter a valid account name", "Error"); return; } else if (!Validator.IsValidEmail(AccountEmail.Text)) { MessageBox.Show("Please enter a valid account email", "Error"); return; } else if (Pid != AccountId) { if (!Validator.IsValidPID(Pid.ToString())) { MessageBox.Show("Invalid PID Format. A PID must be 8 or 9 digits in length", "Error"); return; } // Make sure the PID doesnt exist! else if (Database.UserExists(Pid)) { MessageBox.Show("Battlefield 2 PID is already taken. Please try a different PID.", "Error"); return; } } Database.UpdateUser(AccountId, Pid, AccountNick.Text, AccountPass.Text, AccountEmail.Text); } this.Close(); }
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(); }