public static string Excluir(TRegistro_ItensDevolvidos val, BancoDados.TObjetoBanco banco) { bool st_transacao = false; TCD_ItensDevolvidos qtb_item = new TCD_ItensDevolvidos(); try { if (banco == null) { st_transacao = qtb_item.CriarBanco_Dados(true); } else { qtb_item.Banco_Dados = banco; } //Buscar registro estoque CamadaDados.Estoque.TList_RegLanEstoque lEstoque = new CamadaDados.Estoque.TCD_LanEstoque(qtb_item.Banco_Dados).Select( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.cd_empresa", vOperador = "=", vVL_Busca = "'" + val.Cd_empresa.Trim() + "'" }, new Utils.TpBusca() { vNM_Campo = "a.cd_produto", vOperador = "=", vVL_Busca = "'" + val.Cd_produto.Trim() + "'" }, new Utils.TpBusca() { vNM_Campo = "a.id_lanctoestoque", vOperador = "=", vVL_Busca = val.Id_lanctoestoquestr } }, 0, string.Empty, string.Empty, string.Empty); //Excluir estoque lEstoque.ForEach(p => CamadaNegocio.Estoque.TCN_LanEstoque.CancelarEstoque(p, qtb_item.Banco_Dados)); qtb_item.Excluir(val); if (st_transacao) { qtb_item.Banco_Dados.Commit_Tran(); } return("OK"); } catch (Exception ex) { if (st_transacao) { qtb_item.Banco_Dados.RollBack_Tran(); } throw new Exception("Erro excluir item devolvido: " + ex.Message.Trim()); } finally { if (st_transacao) { qtb_item.deletarBanco_Dados(); } } }
private void bsSintetico_PositionChanged(object sender, EventArgs e) { if (bsSintetico.Current != null) { TpBusca[] filtro = new TpBusca[0]; if (cd_empresa.Text.Trim() != string.Empty) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "a.cd_empresa"; filtro[filtro.Length - 1].vOperador = "="; filtro[filtro.Length - 1].vVL_Busca = "'" + cd_empresa.Text.Trim() + "'"; } if (CD_Produto.Text.Trim() != string.Empty) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "a.cd_produto"; filtro[filtro.Length - 1].vOperador = "="; filtro[filtro.Length - 1].vVL_Busca = "'" + CD_Produto.Text.Trim() + "'"; } if (cd_grupo.Text.Trim() != string.Empty) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "b.cd_grupo"; filtro[filtro.Length - 1].vOperador = "like"; filtro[filtro.Length - 1].vVL_Busca = "'" + cd_grupo.Text.Trim() + "%'"; } //if (tp_produto.Text.Trim() != string.Empty) //{ // Array.Resize(ref filtro, filtro.Length + 1); // filtro[filtro.Length - 1].vNM_Campo = "b.tp_produto"; // filtro[filtro.Length - 1].vOperador = "="; // filtro[filtro.Length - 1].vVL_Busca = "'" + tp_produto.Text.Trim() + "'"; //} if (cbProdSaldoMinimo.Checked) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = string.Empty; filtro[filtro.Length - 1].vOperador = "exists"; filtro[filtro.Length - 1].vVL_Busca = "(select 1 from TB_EST_Produto_QTDEstoque x " + "where x.cd_produto = a.cd_produto " + "and x.cd_empresa = a.cd_empresa " + "and x.qt_min_estoque > a.tot_saldo) "; } if (cbItensSaldo.Checked) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "a.Tot_Saldo"; filtro[filtro.Length - 1].vOperador = ">"; filtro[filtro.Length - 1].vVL_Busca = "0"; } if (!string.IsNullOrEmpty((bsSintetico.Current as DataRowView)["cd_produto"].ToString())) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "a.cd_produto"; filtro[filtro.Length - 1].vOperador = "="; filtro[filtro.Length - 1].vVL_Busca = (bsSintetico.Current as DataRowView)["cd_produto"].ToString(); } object saldo_minimo = new CamadaDados.Estoque.TCD_LanEstoque().BuscarEstoqueSintenticoSaldoEscalar( filtro, " a.tot_saldo"); object requisicao = new CamadaDados.Estoque.TCD_LanEstoque().BuscarEstoqueSintenticoSaldoEscalar( filtro, "qtd_requisicao = (select isnull(sum(o.quantidade),0) from tb_cmp_requisicao o " + " where o.cd_produto = a.cd_produto and a.cd_empresa = o.CD_Empresa "+ " and isnull((select top 1 x.Nr_Pedido from TB_FAT_Pedido_Itens x "+ " inner join TB_CMP_OrdemCompra_X_PedItem y "+ " on x.CD_Produto = y.CD_Produto "+ " and x.Nr_Pedido = y.Nr_Pedido "+ " and x.ID_PedidoItem = y.ID_PedidoItem "+ " inner join TB_CMP_OrdemCompra h "+ " on y.ID_OC = h.ID_OC "+ " join vtb_fat_pedido ped on ped.nr_pedido = x.nr_pedido "+ " where ped.vl_totalfat_entrada > 0 "+ " and a.CD_Empresa = h.CD_Empresa "+ " and a.CD_Produto = x.CD_Produto "+ " and o.ID_Requisicao = h.ID_Requisicao "+ " and h.ST_Registro <> 'C' "+ " and x.ST_Registro <> 'C'), 0) = 0) "); object qtd_orcamento = new CamadaDados.Estoque.TCD_LanEstoque().BuscarEstoqueSintenticoSaldoEscalar( filtro, "qtd_orcamento = ( select isnull(sum(x.quantidade),0) from TB_FAT_Orcamento_Item x " + " join TB_EST_Produto_QTDEstoque z on x.cd_produto = z.cd_produto " + " join vTB_FAT_Orcamento op on x.nr_orcamento = op.NR_Orcamento " + " where x.cd_produto = a.cd_produto and op.st_registro = 'AB') "); object qtd_pedido = new CamadaDados.Estoque.TCD_LanEstoque().BuscarEstoqueSintenticoSaldoEscalar( filtro, "qtd_pedido = (select isnull(sum(o.quantidade),0) from tb_fat_pedido_itens o " + " join TB_EST_Produto_QTDEstoque z on o.cd_produto = z.cd_produto " + " join vtb_fat_pedido pe on o.Nr_Pedido = pe.Nr_Pedido where o.cd_produto = a.cd_produto and pe.vl_totalfat_entrada = 0 and pe.st_pedido <> 'P' ) "); object saldo_total = new CamadaDados.Estoque.TCD_LanEstoque().BuscarEstoqueSintenticoSaldoEscalar( filtro, "saldo_total = ( ( isnull( " + " a.tot_saldo , 0) "+ " + "+ " (select isnull(sum(o.quantidade),0) from tb_cmp_requisicao o "+ " where o.cd_produto = a.cd_produto and a.cd_empresa = o.CD_Empresa "+ " and isnull((select top 1 x.Nr_Pedido from TB_FAT_Pedido_Itens x "+ " inner join TB_CMP_OrdemCompra_X_PedItem y "+ " on x.CD_Produto = y.CD_Produto "+ " and x.Nr_Pedido = y.Nr_Pedido "+ " and x.ID_PedidoItem = y.ID_PedidoItem "+ " inner join TB_CMP_OrdemCompra h "+ " on y.ID_OC = h.ID_OC "+ " join vtb_fat_pedido ped on ped.nr_pedido = x.nr_pedido "+ " where ped.vl_totalfat_entrada > 0 "+ " and a.CD_Empresa = h.CD_Empresa "+ " and a.CD_Produto = x.CD_Produto "+ " and o.ID_Requisicao = h.ID_Requisicao "+ " and h.ST_Registro <> 'C' "+ " and x.ST_Registro <> 'C'), 0) = 0 ) "+ " ) - ( "+ " ( select isnull(sum(x.quantidade),0) from TB_FAT_Orcamento_Item x "+ " join TB_EST_Produto_QTDEstoque z on x.cd_produto = z.cd_produto "+ " join vTB_FAT_Orcamento op on x.nr_orcamento = op.NR_Orcamento "+ " where x.cd_produto = a.cd_produto and op.st_registro = 'AB') "+ " + "+ " (select isnull(sum(o.quantidade),0) from tb_fat_pedido_itens o "+ " join TB_EST_Produto_QTDEstoque z on o.cd_produto = z.cd_produto "+ " join vtb_fat_pedido pe on o.Nr_Pedido = pe.Nr_Pedido where o.cd_produto = a.cd_produto and pe.vl_totalfat_entrada = 0 and pe.st_pedido <> 'P'"+ " ) ) "+ " ) "); StringBuilder sb = new StringBuilder(); sb.AppendLine("Soma dos totais de requisição: " + Convert.ToDecimal(requisicao).ToString("N2", new System.Globalization.CultureInfo("pt-BR", true)) + " + saldo em estoque: " + Convert.ToDecimal(saldo_minimo).ToString("N2", new System.Globalization.CultureInfo("pt-BR", true))); sb.AppendLine("Subtraido pela soma de todos pedidos: " + Convert.ToDecimal(qtd_pedido).ToString("N2", new System.Globalization.CultureInfo("pt-BR", true)) + " + total de orcamentos: " + Convert.ToDecimal(qtd_orcamento).ToString("N2", new System.Globalization.CultureInfo("pt-BR", true))); sb.AppendLine("Saldo total: " + Convert.ToDecimal(saldo_total).ToString("N2", new System.Globalization.CultureInfo("pt-BR", true))); richtbDetalhe.Text = sb.ToString(); } else { richtbDetalhe.Text = ""; } }