private void gridViewItems_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
        {
            var item = e.Row as ReceiptItem;

            if (e.IsGetData)
            {
                if (e.Column.FieldName == "ItemName")
                {
                    var shopping = ShoppingListAccessor.GetItem(item.ShoppingListItemID);
                    if (shopping != null)
                    {
                        e.Value = shopping.Name;
                    }
                    else
                    {
                        e.Value = item.Name;
                    }
                }
                else if (e.Column.FieldName == "ItemQuantity")
                {
                    if (item.Quantity != null)
                    {
                        var qty = item.Quantity;
                        e.Value = string.Format("{0} {1}", qty.Amount, qty.Unit);
                    }
                }
            }
        }
예제 #2
0
        private bool IsMatch(Receipt receipt)
        {
            string text       = options.Text;
            var    candidates = new List <TextScore>();

            foreach (var item in receipt.Items)
            {
                candidates.Add(CreateCandidate(text, item.Name ?? "", item));

                var shoppingListItem = ShoppingListAccessor.GetItem(item.ShoppingListItemID);
                if (shoppingListItem != null)
                {
                    candidates.Add(CreateCandidate(text, shoppingListItem.Name, item));
                }

                if (options.SearchItemCode && !string.IsNullOrWhiteSpace(item.Code))
                {
                    candidates.Add(CreateCandidate(text, item.Code, item));
                }
            }

            double max = candidates.Max(t => t.Score);

            foreach (var candidate in candidates)
            {
                candidate.Score = 1.0 - (candidate.Score / max);
            }

            foreach (var candidate in candidates)
            {
                if (options.IncludeExact)
                {
                    if (string.Equals(candidate.Text, text, StringComparison.InvariantCultureIgnoreCase))
                    {
                        candidate.Item.SearchIDs.Add(searchResultID);
                        return(true);
                    }
                }
                else
                {
                    if (
                        candidate.Text.IndexOf(text, StringComparison.InvariantCultureIgnoreCase) > -1 ||
                        text.IndexOf(candidate.Text, StringComparison.InvariantCultureIgnoreCase) > -1)
                    {
                        candidate.Item.SearchIDs.Add(searchResultID);
                        return(true);
                    }

                    if (options.IncludeSimilar && candidate.Score > 0.85)
                    {
                        candidate.Item.SearchIDs.Add(searchResultID);
                        return(true);
                    }
                }
            }

            return(false);
        }