private void OnSearch(string searchKey)
        {
            if (_allDto.Count == 0)
            {
                return;
            }

            List <DanhMucDto> itemsForListBox = new List <DanhMucDto>();
            bool isTimTheoTen = false;

            _allDto.FindAll(
                delegate(DanhMucDto dto)
            {
                bool found = false;
                if (dto.Ma.ToUpper().Equals(searchKey.ToUpper()))
                {
                    found = true;
                    itemsForListBox.Add(dto);
                }
                return(found);
            });

            if (itemsForListBox.Count == 0)
            {
                _allDto.FindAll(
                    delegate(DanhMucDto dto)
                {
                    bool found = false;
                    if (VnStringHelper.toEnglish(dto.Ten.ToUpper()).Equals(VnStringHelper.toEnglish(searchKey).ToUpper()))
                    {
                        found = true;
                        itemsForListBox.Add(dto);
                    }
                    return(found);
                });
                isTimTheoTen = true;
            }

            if (itemsForListBox.Count == 1)
            {
                _selectedDto      = itemsForListBox[0];
                txtSearchKey.Text = _selectedDto.Ten;
            }
            else if (itemsForListBox.Count > 1)
            {
                OnShowLov(txtSearchKey.Text.Trim(), isTimTheoTen);
            }
            else
            {
                _selectedDto = null;
            }
        }
Example #2
0
        private List <DanhMucDto> OnSearch(string searchKey, string keyType)
        {
            var itemsForTable = new List <DanhMucDto>();

            _allDto.FindAll(
                delegate(DanhMucDto dto)
            {
                bool found = false;
                int indexOf;
                switch (keyType)
                {
                case MA_KEY:
                    indexOf = dto.Ma.IndexOf(searchKey, StringComparison.InvariantCultureIgnoreCase);
                    if (indexOf >= 0)
                    {
                        found = true;
                        itemsForTable.Add(dto);
                    }
                    break;

                case TEN_KEY:

                    indexOf = VnStringHelper.toEnglish(dto.Ten).IndexOf(VnStringHelper.toEnglish(searchKey), StringComparison.InvariantCultureIgnoreCase);
                    if (indexOf >= 0)
                    {
                        found = true;
                        itemsForTable.Add(dto);
                    }
                    break;

                default:
                    break;
                }
                return(found);
            });
            return(itemsForTable);
        }