Nanook.QueenBee.EditorForm.btnQbKeySearch_Click C# (CSharp) Method

btnQbKeySearch_Click() private method

private btnQbKeySearch_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void btnQbKeySearch_Click(object sender, EventArgs e)
        {
            if (!isPakLoaded())
                return;

            try
            {
                this.Cursor = Cursors.WaitCursor;

                if (err.GetError(txtQbKeySearch).Length != 0)
                    return;
                else
                {
                    if (!Regex.IsMatch(txtQbKeySearch.Text, "^[^ ]{2,}$"))
                    {
                        err.SetError(txtQbKeySearch, "Invalid QB Key Search, can not be blank and must be text or an even amount of characters, a valid example is artist or 1A4F98AF");
                        return;
                    }
                }

                lstSearchResults.BeginUpdate();
                lstSearchResults.ListViewItemSorter = null;
                lstSearchResults.Items.Clear();

                string srchOrig = txtQbKeySearch.Text.Trim();
                string srchStr = srchOrig.ToUpper();
                bool isCrc = Regex.IsMatch(txtQbKeySearch.Text, "^([A-F0-9]{2})+$");
                uint srchCrc = 0;

                QbItemQbKey qbq;
                if (isCrc)
                {
                    srchStr = srchStr.PadLeft(8, '0');
                    byte[] b;
                    if (srchStr.Length > 2)
                    {
                        b = new byte[srchStr.Length / 2];
                        for (int c = 0; c < srchStr.Length; c += 2)
                            b[c / 2] = byte.Parse(srchStr.Substring(c, 2), System.Globalization.NumberStyles.HexNumber);
                        if (BitConverter.IsLittleEndian) //convert to the way the Current architecture stores numbers
                            Array.Reverse(b);
                    }
                    else
                        return;

                    srchCrc = BitConverter.ToUInt32(b, 0);
                }
                else
                {
                    srchCrc = QbKey.Create(srchStr).Crc; //allow text searches when there's no debug file (partial text search won't work
                }

                searchQbFile(delegate(QbFile qbFile, QbItemBase item)
                {
                    if ((qbq = (item as QbItemQbKey)) != null)
                    {
                        foreach (QbKey qb in qbq.Values)
                        {
                            if (srchCrc == qb.Crc)
                                addSearchListItem(srchOrig, qbFile, qbq);
                            else if (!isCrc && (srchStr.Length == 0 || qb.Text.ToUpper().Contains(srchStr)))
                                addSearchListItem(qb.Text, qbFile, qbq);
                        }
                    }

                    if (item.ItemQbKey != null)
                    {
                        if (srchCrc == item.ItemQbKey.Crc)
                            addSearchListItem(srchOrig, qbFile, item);
                        else if (!isCrc && (srchStr.Length == 0 || item.ItemQbKey.Text.ToUpper().Contains(srchStr)))
                            addSearchListItem(item.ItemQbKey.Text, qbFile, item);
                    }
                });
                messageIfNoResults();
            }
            catch (Exception ex)
            {
                showException("QbKey Search Error", ex);
            }
            finally
            {
                lstSearchResults.ListViewItemSorter = _lvwSearchColumnSorter;
                lstSearchResults.EndUpdate();

                this.Cursor = Cursors.Default;

            }
        }
EditorForm