2
good afternoon!
I would like to ask a question, I am developing a collection code and at a certain time it is necessary a to iterate the values of the list and then save the information in an item... So far so good, but the problem arises because the frame in which I am collecting does not have a certain amount of lines for collection, and can be from 1 line to 50(example).
At this moment my logic is broken, because I can not create conditions following a minimal logic, I would like to know what is possible to leave the is auto interpretative, for when it goes through the values, the next lines of the array that it reads, automatically recognizes the value and value in the specific var.
I ended up not posting the code because I don’t know if it would help much, but follow the excerpt of the for and the link of the page I’m capturing:
foreach (var acumulador in item)
{
var texto = acumulador.SelectNodes("//*[contains(text(),'Código')]/../../descendant-or-self::tr|//*[@class='RelLinhaBranca'][1]//*[contains(text(),'Código')]/../../following-sibling::tr");
for (int j = 0; j < texto.Count; j++)
{
if (texto == null || texto.ToString() == "")
{
continue;
}
else
{
itens.favorecido = new Favorecido() { nome = texto[j + 1].InnerText.CopyUntil("- V").Trim() };
itens.marca = texto[j + 2].InnerText.CopyAfter("Marca").Trim();
itens.valor_unitario = decimal.Parse(texto[j + 3].InnerText.CopyBetween("R$", "Valor").Replace(",", "").Trim(), new CultureInfo("pt-BR"));
itens.valor_total = decimal.Parse(texto[j + 3].InnerText.CopyAfter("Total").Replace("R$", "").Replace(",", "").Trim(), new CultureInfo("pt-BR"));
itens.num_item = texto[j].InnerText.CopyBetween("Código", "Categoria").Trim();
itens.tipo_item = texto[j].InnerText.CopyBetween("Categoria", "Subcategoria").Trim();
itens.descricao = texto[j].InnerText.CopyBetween("Descrição", "Observação").Trim();
itens.quantidade = decimal.Parse(texto[j].InnerText.CopyBetween("Quantidade", "Tipo").Split()[1].Trim(), new CultureInfo("pt-BR"));
itens.unidade = texto[j].InnerText.CopyAfter("Cotacao").Split()[2].Trim();
}
documento.itens.Add(itens);
var ex = "";
}
}
Thanks for the tip, I will try to reproduce your advice and correct the null condition.
– Jonathan Igor Bockorny Pereira