Example #1
0
        public static string Excluir(TRegistro_DespViagem_X_CCusto val, BancoDados.TObjetoBanco banco)
        {
            bool st_transacao = false;
            TCD_DespViagem_X_CCusto qtb_desp = new TCD_DespViagem_X_CCusto();

            try
            {
                if (banco == null)
                {
                    st_transacao = qtb_desp.CriarBanco_Dados(true);
                }
                else
                {
                    qtb_desp.Banco_Dados = banco;
                }
                qtb_desp.Excluir(val);
                if (st_transacao)
                {
                    qtb_desp.Banco_Dados.Commit_Tran();
                }
                return("OK");
            }
            catch (Exception ex)
            {
                if (st_transacao)
                {
                    qtb_desp.Banco_Dados.RollBack_Tran();
                }
                throw new Exception("Erro excluir registro: " + ex.Message.Trim());
            }
            finally
            {
                if (st_transacao)
                {
                    qtb_desp.deletarBanco_Dados();
                }
            }
        }
Example #2
0
        public static void ProcessarDespCResultado(List <TRegistro_DespesasViagem> lDespesas,
                                                   string CD_CentroResult,
                                                   BancoDados.TObjetoBanco banco)
        {
            bool st_transacao = false;
            TCD_DespViagem_X_CCusto qtb_desp = new TCD_DespViagem_X_CCusto();

            try
            {
                if (banco == null)
                {
                    st_transacao = qtb_desp.CriarBanco_Dados(true);
                }
                else
                {
                    qtb_desp.Banco_Dados = banco;
                }
                if (string.IsNullOrEmpty(CD_CentroResult))
                {
                    throw new Exception("Obrigatório informar centro de resultado.");
                }
                lDespesas.ForEach(p =>
                {
                    //Verificar se despesa possui centro de resultado
                    TCN_DespViagem_X_CCusto.Buscar(p.Id_landespesastr,
                                                   p.Id_viagemstr,
                                                   p.Cd_empresa,
                                                   string.Empty,
                                                   qtb_desp.Banco_Dados).ForEach(v =>
                    {
                        TCN_DespViagem_X_CCusto.Excluir(v, qtb_desp.Banco_Dados);
                        CamadaNegocio.Financeiro.CCustoLan.TCN_LanCCustoLancto.Excluir(
                            new CamadaDados.Financeiro.CCustoLan.TRegistro_LanCCustoLancto()
                        {
                            Id_ccustolan = v.Id_ccustolan
                        }, qtb_desp.Banco_Dados);
                    });
                    //Gravar Lancto Resultado
                    string id = CamadaNegocio.Financeiro.CCustoLan.TCN_LanCCustoLancto.Gravar(
                        new CamadaDados.Financeiro.CCustoLan.TRegistro_LanCCustoLancto()
                    {
                        Cd_empresa      = p.Cd_empresa,
                        Cd_centroresult = CD_CentroResult,
                        Vl_lancto       = p.Vl_subtotal,
                        Dt_lancto       = p.Dt_despesa
                    }, qtb_desp.Banco_Dados);
                    //Amarrar Lancto a Caixa
                    Gravar(new TRegistro_DespViagem_X_CCusto()
                    {
                        Cd_empresa    = p.Cd_empresa,
                        Id_ccustolan  = decimal.Parse(id),
                        Id_landespesa = p.Id_landespesa,
                        Id_viagem     = p.Id_viagem
                    }, qtb_desp.Banco_Dados);
                });
                if (st_transacao)
                {
                    qtb_desp.Banco_Dados.Commit_Tran();
                }
            }
            catch (Exception ex)
            {
                if (st_transacao)
                {
                    qtb_desp.Banco_Dados.RollBack_Tran();
                }
                throw new Exception("Erro processar despesas: " + ex.Message.Trim());
            }
            finally
            {
                if (st_transacao)
                {
                    qtb_desp.deletarBanco_Dados();
                }
            }
        }