Ejemplo n.º 1
0
        /// <summary>
        /// Handles when the current player is selected.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">An EventArgs object that contains the
        /// event data.</param>
        private void SelectPlayerClick(object sender, EventArgs e)
        {
            if (m_resultsList.SelectedIndex < 0)
            {
                if (sender == m_okButton)
                {
                    MessageForm.Show(this, (m_machineAccounts) ? Resources.NoMachineSel : Resources.NoPlayerSel);
                }

                return;
            }

            try
            {
                // Create the wait form.
                m_waitForm                     = new WaitForm();
                m_waitForm.WaitImage           = Resources.WaitAnimation;
                m_waitForm.CancelButtonVisible = false;
                m_waitForm.ProgressBarVisible  = false;
                m_waitForm.Cursor              = Cursors.WaitCursor;

                if (m_machineAccounts)
                {
                    m_waitForm.Message = Resources.WaitFormGettingMachine;
                }
                else
                {
                    m_waitForm.Message = Resources.WaitFormGettingPlayer;
                }

                // Create the worker thread and run it.
                m_worker = new BackgroundWorker();
                m_worker.WorkerReportsProgress      = false;
                m_worker.WorkerSupportsCancellation = false;
                m_worker.DoWork             += new DoWorkEventHandler(GetPlayer);
                m_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(GetPlayerComplete);
                m_worker.RunWorkerAsync(((PlayerListItem)m_resultsList.SelectedItem).Id);

                // Block until we are finished getting the player.
                m_waitForm.ShowDialog(this);

                if (m_serverCommFailed)
                {
                    DialogResult = DialogResult.Abort;
                }
                else
                {
                    DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                MessageForm.Show(this, ex.Message);
                DialogResult = DialogResult.Cancel;
            }
            finally
            {
                if (m_waitForm != null)
                {
                    m_waitForm.Dispose();
                    m_waitForm = null;
                }
            }

            Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts a thread to search for players and displays a wait form.
        /// </summary>
        protected void StartPlayerSearch()
        {
            try
            {
                // Create the wait form.
                m_waitForm                     = new WaitForm();
                m_waitForm.WaitImage           = Resources.WaitAnimation;
                m_waitForm.CancelButtonVisible = false;
                m_waitForm.ProgressBarVisible  = false;
                m_waitForm.Cursor              = Cursors.WaitCursor;

                if (m_machineAccounts)
                {
                    m_waitForm.Message = Resources.WaitFormFindingMachines;
                }
                else
                {
                    m_waitForm.Message = Resources.WaitFormFindingPlayers;
                }

                // Set the search params.
                string[] parameters = new string[3];

                if (m_cardSearchRadio.Checked)
                {
                    parameters[0] = m_cardNumber.Text;
                }
                else // Assume search by name.
                {
                    parameters[1] = m_lastName.Text;
                    parameters[2] = m_firstName.Text;
                }

                // Create the worker thread and run it.
                m_worker = new BackgroundWorker();
                m_worker.WorkerReportsProgress      = false;
                m_worker.WorkerSupportsCancellation = false;
                m_worker.DoWork             += new DoWorkEventHandler(SearchPlayers);
                m_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(SearchPlayersComplete);
                m_worker.RunWorkerAsync(parameters);

                // Block until we are finished searching.
                m_waitForm.ShowDialog(this);

                if (m_tryingCardInsteadOfName && m_resultsList.Items.Count > 0)
                {
                    m_firstName.Text = string.Empty;
                }

                if (m_resultsList.Items.Count == 1)
                {
                    m_resultsList.SelectedIndex = 0;
                }

                if (m_cardSearchRadio.Checked)
                {
                    m_cardNumber.Focus();
                }
                else
                {
                    m_firstName.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageForm.Show(this, ex.Message);
            }
            finally
            {
                if (m_waitForm != null)
                {
                    m_waitForm.Dispose();
                    m_waitForm = null;
                }
            }

            // Did we lose the server?
            if (m_serverCommFailed)
            {
                DialogResult = DialogResult.Abort;
                Close();
            }

            if (m_resultsList.Items.Count == 0) //nothing found
            {
                if (m_nameSearchRadio.Checked)  //see if they swiped a card in the name field
                {
                    m_cardSearchRadio.Checked = true;
                    m_tryingCardInsteadOfName = true;

                    if (!m_magCardReader.ProcessString(m_firstName.Text))
                    {
                        m_nameSearchRadio.Checked = true;
                        m_tryingCardInsteadOfName = false;
                    }

                    return;
                }

                if (m_tryingCardInsteadOfName)
                {
                    m_nameSearchRadio.Checked = true;
                    m_cardNumber.Text         = string.Empty;
                    m_firstName.Focus();
                    m_firstName.SelectAll();
                    m_tryingCardInsteadOfName = false;
                }
            }

            m_tryingCardInsteadOfName = false;
        }