Пример #1
0
        private List <ProductItem> ConvertOcrStringLineListToProductItemList(List <string> OcrStringLineList)
        {
            var productItemList = new List <ProductItem>();
            var itemListData    = ConvertOcrStringLineListToItemListData(OcrStringLineList);
            int index           = 1;

            foreach (var shortedString in itemListData)
            {
                var opc         = string.Empty;
                var description = string.Empty;
                if (shortedString.Length == 0)
                {
                    continue;
                }

                if (shortedString.Length > 6)
                {
                    var id = StringToIntConverter(shortedString[0]);
                    //var id = int.TryParse(shortedString[0], out var parsedId) ? parsedId : 0;
                    var lre = shortedString[shortedString.Length - 7];

                    var orderNumber = StringToIntConverter(shortedString[shortedString.Length - 6]);
                    var rcv         = StringToIntConverter(shortedString[shortedString.Length - 5]);
                    var bo          = StringToIntConverter(shortedString[shortedString.Length - 4]);
                    var unitCost    = StringToConverterDouble(shortedString[shortedString.Length - 3].Trim(_trimCharArray), new CultureInfo("en-US"));
                    var orderCost   = StringToConverterDouble(shortedString[shortedString.Length - 2].Trim(_trimCharArray), new CultureInfo("en-US"));
                    var rcvCost     = StringToConverterDouble(shortedString[shortedString.Length - 1].Trim(_trimCharArray), new CultureInfo("en-US"));

                    if (shortedString[1].Contains("."))
                    {
                        shortedString[1] = shortedString[1].Replace(".", "");
                    }

                    shortedString[1] = shortedString[1].Replace(" ", "");
                    if (_validateService.ValidateItemCode(shortedString[1]))
                    {
                        opc = shortedString[1];
                    }

                    for (int i = 2; i < shortedString.Length - 7; i++)
                    {
                        description += shortedString[i] + " ";
                    }
                    var productItem = new ProductItem(id, opc, description, lre, orderNumber, rcv, bo, unitCost, orderCost, rcvCost);
                    index = id + 1;
                    productItemList.Add(productItem);
                }
                else
                {
                    shortedString[0] = shortedString[0].Replace(" ", "");
                    if (_validateService.ValidateItemCode(shortedString[0]))
                    {
                        productItemList.Add(new ProductItem(index, shortedString[0], "", "", 0, 0, 0, 0, 0, 0));
                    }
                    else
                    {
                        productItemList.Add(new ProductItem(index, "", "", "", 0, 0, 0, 0, 0, 0));
                    }

                    index++;
                }
            }
            return(productItemList);
        }