Пример #1
0
        public static string Gravar(TRegistro_AlocacaoItem val, BancoDados.TObjetoBanco banco)
        {
            bool             st_transacao = false;
            TCD_AlocacaoItem qtb_aloc     = new TCD_AlocacaoItem();

            try
            {
                if (banco == null)
                {
                    st_transacao = qtb_aloc.CriarBanco_Dados(true);
                }
                else
                {
                    qtb_aloc.Banco_Dados = banco;
                }
                string retorno = qtb_aloc.Gravar(val);
                if (st_transacao)
                {
                    qtb_aloc.Banco_Dados.Commit_Tran();
                }
                return(retorno);
            }
            catch (Exception ex)
            {
                if (st_transacao)
                {
                    qtb_aloc.Banco_Dados.RollBack_Tran();
                }
                throw new Exception("Erro gravar registro: " + ex.Message.Trim());
            }
            finally
            {
                if (st_transacao)
                {
                    qtb_aloc.deletarBanco_Dados();
                }
            }
        }
Пример #2
0
        public static string Excluir(TRegistro_AlocacaoItem val, BancoDados.TObjetoBanco banco)
        {
            bool             st_transacao = false;
            TCD_AlocacaoItem qtb_aloc     = new TCD_AlocacaoItem();

            try
            {
                if (banco == null)
                {
                    st_transacao = qtb_aloc.CriarBanco_Dados(true);
                }
                else
                {
                    qtb_aloc.Banco_Dados = banco;
                }
                //Verificar se a entrega ja nao esta faturada
                object obj = new CamadaDados.Faturamento.NotaFiscal.TCD_LanFaturamento(qtb_aloc.Banco_Dados).BuscarEscalar(
                    new Utils.TpBusca[]
                {
                    new Utils.TpBusca()
                    {
                        vNM_Campo = "isnull(a.st_registro, 'A')",
                        vOperador = "<>",
                        vVL_Busca = "'C'"
                    },
                    new Utils.TpBusca()
                    {
                        vNM_Campo = string.Empty,
                        vOperador = "exists",
                        vVL_Busca = "(select 1 from tb_fat_notafiscal_item_x_estoque x " +
                                    "where x.cd_empresa = a.cd_empresa " +
                                    "and x.nr_lanctofiscal = a.nr_lanctofiscal " +
                                    "and x.id_entrega = " + val.Id_entregastr + ")"
                    }
                }, "a.nr_notafiscal");
                if (obj != null)
                {
                    throw new Exception("Entrega: " + val.Id_entregastr + " ja se encontra faturada.\r\n" +
                                        "Nota Fiscal: " + obj.ToString().Trim() + ".");
                }
                qtb_aloc.Excluir(val);
                //Excluir entrega do pedido
                CamadaNegocio.Faturamento.Pedido.TCN_LanEntregaPedido.Excluir(
                    CamadaNegocio.Faturamento.Pedido.TCN_LanEntregaPedido.Busca(val.Id_entregastr,
                                                                                string.Empty,
                                                                                string.Empty,
                                                                                string.Empty,
                                                                                false,
                                                                                string.Empty,
                                                                                qtb_aloc.Banco_Dados)[0], qtb_aloc.Banco_Dados);
                if (st_transacao)
                {
                    qtb_aloc.Banco_Dados.Commit_Tran();
                }
                return("OK");
            }
            catch (Exception ex)
            {
                if (st_transacao)
                {
                    qtb_aloc.Banco_Dados.RollBack_Tran();
                }
                throw new Exception("Erro excluir registro: " + ex.Message.Trim());
            }
            finally
            {
                if (st_transacao)
                {
                    qtb_aloc.deletarBanco_Dados();
                }
            }
        }