public List <Produtos> Pesquisar(int produtoID, string nome) { ProdutosModel pm = new ProdutosModel(); return(pm.Pesquisar(produtoID, nome)); }
// Este método verifica se o produto está ok ou se é necessário comprar ou produzir e alimenta array com essas informações private void VerificaNecessidade(int produtoID, int qntSolicitada, int nivel, string pai) { Array.Resize(ref produtos, produtos.Length + 1); produtos[produtos.Length - 1] = new string[7]; // Verifica se tem quantidade necessária em estoque ProdutosModel p = new ProdutosModel(); List <Produtos> lp = p.Pesquisar(produtoID, ""); int qntDisponivel = lp[0].qntEstoque - lp[0].qntEstoqueReservado; // Estoque de segurança /* * if (nivel == 1) * { * int qntSeguranca = EstoqueSeguro(produtoID); * * if ((qntDisponivel - qntSolicitada) < qntSeguranca) * qntSolicitada = (qntSeguranca + qntSolicitada) - qntDisponivel; * } */ if (qntSolicitada <= qntDisponivel) { produtos[produtos.Length - 1][0] = produtoID.ToString(); produtos[produtos.Length - 1][1] = "0"; produtos[produtos.Length - 1][2] = "Ok"; produtos[produtos.Length - 1][3] = nivel.ToString(); produtos[produtos.Length - 1][4] = pai; produtos[produtos.Length - 1][5] = lp[0].leadTime.ToString(); produtos[produtos.Length - 1][6] = lp[0].nome; } else { ProdutosModel pf = new ProdutosModel(); List <ProdutosFilhos> lpf = pf.PesquisarFilho(produtoID, 0); // Se não tem produtos "filhos" é necessário comprar. if (lpf.Count == 0) { produtos[produtos.Length - 1][0] = produtoID.ToString(); produtos[produtos.Length - 1][1] = (qntSolicitada - qntDisponivel).ToString(); produtos[produtos.Length - 1][2] = "Comprar"; produtos[produtos.Length - 1][3] = nivel.ToString(); produtos[produtos.Length - 1][4] = pai; produtos[produtos.Length - 1][5] = lp[0].leadTime.ToString(); produtos[produtos.Length - 1][6] = lp[0].nome; } else { produtos[produtos.Length - 1][0] = produtoID.ToString(); produtos[produtos.Length - 1][1] = (qntSolicitada - qntDisponivel).ToString(); produtos[produtos.Length - 1][2] = "Produzir"; produtos[produtos.Length - 1][3] = nivel.ToString(); produtos[produtos.Length - 1][4] = pai; produtos[produtos.Length - 1][5] = ((qntSolicitada - qntDisponivel) * lp[0].leadTime).ToString(); produtos[produtos.Length - 1][6] = lp[0].nome; nivel++; for (int i = 0; i < lpf.Count; i++) { int filhoID = lpf[i].filhoID; int qnt = qntSolicitada - qntDisponivel; VerificaNecessidade(filhoID, qnt, nivel, produtoID.ToString()); } } } }