Exemplo n.º 1
0
        public static void AtualizarDadosMDFe(string Cd_empresa,
                                              string Id_lote,
                                              string Id_mdfe,
                                              string cStat,
                                              string xMotivo,
                                              string dhRecbto,
                                              string nProt,
                                              string digVal,
                                              BancoDados.TObjetoBanco banco)
        {
            bool            st_transacao = false;
            TCD_Lote_X_MDFe qtb_mdfe     = new TCD_Lote_X_MDFe();

            try
            {
                if (banco == null)
                {
                    st_transacao = qtb_mdfe.CriarBanco_Dados(true);
                }
                else
                {
                    qtb_mdfe.Banco_Dados = banco;
                }
                System.Collections.Hashtable hs = new System.Collections.Hashtable();
                hs.Add("@P_EMPRESA", Cd_empresa);
                hs.Add("@P_LOTE", Id_lote);
                hs.Add("@P_ID_MDFE", Id_mdfe);
                hs.Add("@P_DT_PROC", DateTime.Parse(dhRecbto));
                hs.Add("@P_STAT", cStat);
                hs.Add("@P_MOTIVO", xMotivo);
                hs.Add("@P_NPROT", nProt);
                hs.Add("@P_DIGVAL", digVal);

                qtb_mdfe.executarSql("update tb_ctr_loteMDFe set cStat = '104', xMotivo = 'Arquivo processado', dhRecbto = @P_DT_PROC, dt_alt = getdate() " +
                                     "where cd_empresa = @P_EMPRESA and id_lote = @P_LOTE\r\n" +
                                     "update TB_CTR_Lote_X_MDFe set cStat = @P_STAT, xMotivo = @P_MOTIVO, " +
                                     "dhRecbto = @P_DT_PROC, nProt = @P_NPROT, digval = @P_DIGVAL, " +
                                     "dt_alt = getdate() where cd_empresa = @P_EMPRESA and id_lote = @P_LOTE and id_mdfe = @P_ID_MDFE", hs);
                if (st_transacao)
                {
                    qtb_mdfe.Banco_Dados.Commit_Tran();
                }
            }
            catch (Exception ex)
            {
                if (st_transacao)
                {
                    qtb_mdfe.Banco_Dados.RollBack_Tran();
                }
                throw new Exception("Erro atualizar dados MDF-e: " + ex.Message.Trim());
            }
            finally
            {
                if (st_transacao)
                {
                    qtb_mdfe.deletarBanco_Dados();
                }
            }
        }
Exemplo n.º 2
0
        public static void ReabrirMDFeProcessar(TRegistro_Lote_X_MDFe val, BancoDados.TObjetoBanco banco)
        {
            bool            st_transacao = false;
            TCD_Lote_X_MDFe qtb_nfe      = new TCD_Lote_X_MDFe();

            try
            {
                if (banco == null)
                {
                    st_transacao = qtb_nfe.CriarBanco_Dados(true);
                }
                else
                {
                    qtb_nfe.Banco_Dados = banco;
                }
                qtb_nfe.Excluir(val);
                //Verificar se existe mais alguma MDF-e amarrada ao lote
                object obj = qtb_nfe.BuscarEscalar(
                    new Utils.TpBusca[]
                {
                    new Utils.TpBusca()
                    {
                        vNM_Campo = "a.id_lote",
                        vOperador = "=",
                        vVL_Busca = val.Id_lote.ToString()
                    }
                }, "1");
                if (obj == null)
                {
                    TCN_LoteMDFe.Excluir(new TRegistro_LoteMDFe()
                    {
                        Cd_empresa = val.Cd_empresa,
                        Id_lote    = val.Id_lote
                    }, qtb_nfe.Banco_Dados);
                }
                if (st_transacao)
                {
                    qtb_nfe.Banco_Dados.Commit_Tran();
                }
            }
            catch (Exception ex)
            {
                if (st_transacao)
                {
                    qtb_nfe.Banco_Dados.RollBack_Tran();
                }
                throw new Exception("Erro reabrir MDF-e processar: " + ex.Message.Trim());
            }
            finally
            {
                if (st_transacao)
                {
                    qtb_nfe.deletarBanco_Dados();
                }
            }
        }
Exemplo n.º 3
0
        public static string Excluir(TRegistro_Lote_X_MDFe val, BancoDados.TObjetoBanco banco)
        {
            bool            st_transacao = false;
            TCD_Lote_X_MDFe qtb_lote     = new TCD_Lote_X_MDFe();

            try
            {
                if (banco == null)
                {
                    st_transacao = qtb_lote.CriarBanco_Dados(true);
                }
                else
                {
                    qtb_lote.Banco_Dados = banco;
                }
                qtb_lote.Excluir(val);
                if (st_transacao)
                {
                    qtb_lote.Banco_Dados.Commit_Tran();
                }
                return("OK");
            }
            catch (Exception ex)
            {
                if (st_transacao)
                {
                    qtb_lote.Banco_Dados.RollBack_Tran();
                }
                throw new Exception("Erro excluir registro: " + ex.Message.Trim());
            }
            finally
            {
                if (st_transacao)
                {
                    qtb_lote.deletarBanco_Dados();
                }
            }
        }