Beispiel #1
0
        public ItemsList(string itemsListFolderPath)
        {
            string[] itemListsFilePaths = Directory.GetFiles(itemsListFolderPath, "*.xml");

            AssertMe.assert(itemListsFilePaths.Length > 0);

            countItemsListXmlFiles = itemListsFilePaths.Length;

            itemListsFilePaths.Reverse();

            foreach (string itemListsFile in itemListsFilePaths)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(itemListsFile);
                listDocumentsItemsList.Add(doc);
                XmlNodeList nodes = doc.GetElementsByTagName("_ItemsList");
                listNodesXml.Add(nodes[0]);

                ItemAttributes attributeItem = new ItemAttributes();

                // ДОРАБОТКА Возможно стоит включить в страйк номер делкарации, тк он теперь необязательный элемент
                attributeItem.nameNumberItemDeclaration = nodes[0].SelectSingleNode("_DeclarationNumber").InnerText.Trim();

                // узнаем тип документа
                attributeItem.ItemsListType = nodes[0].SelectSingleNode("_ItemsType").InnerText.Trim();


                int strike     = 0;
                int itemNumber = -1;
                if (!int.TryParse(nodes[0].SelectSingleNode("_ItemNumber").InnerText.Trim(), out itemNumber))
                {
                    strike++;
                }
                attributeItem.numberItemInList = itemNumber;

                // берем код товара
                attributeItem.nameCodeItemInList = GetStringItemCode(doc.GetElementsByTagName("_ItemsTable"));

                if (string.IsNullOrEmpty(attributeItem.nameCodeItemInList))
                {
                    strike++;
                }

                attributeItem.nodesTableItemsList = doc.GetElementsByTagName("_ItemDescription");

                if (strike == 2)
                {
                    condRecognizeItemsListFileMiss = true;
                    errorItemListFile += " Не удалось обработать файл списка товаров: " + itemListsFile;
                }
                else
                {
                    listAttributesItem.Add(attributeItem);
                }
            }

            listAttributesItem.Reverse();
        }
        public void LoadAdditionalDocs()
        {
            AssertMe.assert(xmlFiles.Length > 1);
            HasAdditionalPages = true;

            if (DocumentPagesCount == xmlFiles.Length)
            {
                pagesCountMatch = true;
            }
            else
            {
                warningGTDParser.Add("Указанное количество страниц в документе: (" + DocumentPagesCount + ") и распознаваемое количество страниц: (" + xmlFiles.Length + ") не совпадают");
            }

            listClassAdditionalDocument = new List <AdditionalDocument>();

            for (int i = 1; i < xmlFiles.Length; i++)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(xmlFiles[i]);
                addDocuments.Add(doc);
            }

            nameNodeAdditionalDocumentDefinition = addDocuments[0].LastChild.FirstChild.FirstChild.Name;

            foreach (XmlDocument doc in addDocuments)
            {
                XmlNodeList itemNodes = doc.GetElementsByTagName("_Items");
                _countItemsCalculate += itemNodes.Count;

                // проверяем, сколько товаров размещено на лист
                // должно быть 3, но бывает, что два
                _numberItemsInList.Add(itemNodes.Count);
            }

            if (pagesCountMatch)
            {
                EnumeratePages();
            }

            GetAddDocumensInfo();
        }
        public bool InitItemsList(string paramFolderName)
        {
            // load items list
            AssertMe.assert(!String.IsNullOrEmpty(paramFolderName));

            pathItemsListFolder = tmpFolderPath + "\\" + paramFolderName;

            string[] arrayFilesTiffItemsList = Directory.GetFiles(pathItemsListFolder, "*.tif");

            tifFilesCollection = tifFilesCollection.Union(arrayFilesTiffItemsList).ToArray();

            try
            {
                classItemsList = new ItemsList(pathItemsListFolder);
            }
            catch (Exception e)
            {
                errorGTDParser.Add("Не удалось инициализировать класс ItemsList." + e);
                return(false);
            }

            return(true);
        }
        bool AddItemsListDataInDocument(XmlDocument documentInject, int numberPage, string paramNameNumberDocument, List <ItemsList.ItemAttributes> paramCopyListItemsAttributes)
        {
            AssertMe.assert(classItemsList != null);

            XmlNodeList nodes = documentInject.GetElementsByTagName("_Items");

            if (nodes.Count == 1)
            {
                numberPage++;
            }
            else
            {
                numberPage = numberPage + 2;
            }


            string[] nameKeyWords = { "товары", "согласно", "прилагаемому", "списку" };

            foreach (XmlNode node in nodes)
            {
                string nameItem = node.SelectSingleNode("_ItemName").InnerText.ToLower();

                // ДОРАБОТКА расширить условие, добавив код товара к условию
                if (nameKeyWords.Any(w => nameItem.Contains(w)))
                {
                    int    numberItem   = -1;
                    string nameCodeItem = "";

                    // пытаемся получить номер товара на странице Декларации
                    if (!int.TryParse(node.SelectSingleNode("_ItemNumber").InnerText, out numberItem))
                    {
                        warningGTDParser.Add("Не удалось извлечь номер для списка товаров из документа " + DeclarationType + ":" +
                                             paramNameNumberDocument + " , страница: " + numberPage.ToString());
                    }

                    // берем код товара
                    nameCodeItem = node.SelectSingleNode("_ItemCode").InnerText.Trim();
                    if (!Regex.IsMatch(nameCodeItem, @"^\d+$"))
                    {
                        nameCodeItem = "";
                        warningGTDParser.Add("Не удалось извлечь код для списка товаров из документа " + DeclarationType + ":" +
                                             paramNameNumberDocument + " , страница: " + numberPage.ToString());
                    }

                    if (numberItem == -1 & String.IsNullOrEmpty(nameCodeItem))
                    {
                        return(false);
                    }

                    // ищем во всех листах списка товаров нужные данные
                    foreach (ItemsList.ItemAttributes singleItemList in classItemsList.listAttributesItem)
                    {
                        // сначала сравниваем номера
                        if (String.Compare(CastDocumentNumber(singleItemList.nameNumberItemDeclaration), CastDocumentNumber(paramNameNumberDocument), true) != 0)
                        {
                            warningGTDParser.Add("Номера документа из " + this.DeclarationType + " №: " + paramNameNumberDocument + " и списка товаров №:" + singleItemList.nameNumberItemDeclaration + " не совпадают");
                        }

                        // если номера товара или код совпадают, делаем вставку данных в Декларацию
                        if (singleItemList.numberItemInList == numberItem || string.Compare(singleItemList.nameCodeItemInList, nameCodeItem, true) == 0)
                        {
                            InjectItemListData(node, singleItemList, documentInject);
                            paramCopyListItemsAttributes.Remove(singleItemList);
                            classItemsList.condMatchedItemListCollection = true;

                            _countItemsCalculate = _countItemsCalculate + singleItemList.nodesTableItemsList.Count - 1;
                        }
                    }

                    if (!classItemsList.condMatchedItemListCollection)
                    {
                        warningGTDParser.Add("Не удалось соспоставить данные из списка товаров №: " + numberItem + " для " + DeclarationType +
                                             " ,страница №: " + numberPage.ToString() + " и по коду товара: " + nameCodeItem);
                        classItemsList.condMatchedItemListCollection = false;
                    }
                }
            }

            return(classItemsList.condMatchedItemListCollection);
        }