Esempio n. 1
0
        public static bool TesteConexao(string host, string port, string servicename, string user, string password, string driver, string trusted_conn = "True")
        {
            var retorno = true;

            using (var conn = GetConnectionWithParam(host, port, servicename, user, password, driver, trusted_conn))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception e)
                {
                    //MessageBox.Show(e.Message);
                    MessageBox.Show(e.Message, "", MessageBoxButton.OK, MessageBoxImage.Warning);
                    Processos p = new Processos();
                    p.InsereLogInterno(StaticParametersDB.GetDriver(), e, "99", "Teste Conexão", "");
                    retorno = false;
                }
                finally
                {
                    conn.Close();
                }
            }

            return(retorno);
        }
Esempio n. 2
0
 private static dynamic GetAdapter(dynamic comm)
 {
     if (StaticParametersDB.GetDriver() == "oracle")
     {
         return(new OracleDataAdapter(comm));
     }
     else
     {
         return(new SqlDataAdapter(comm));
     }
 }
Esempio n. 3
0
 private static dynamic GetCommand()
 {
     if (StaticParametersDB.GetDriver() == "oracle")
     {
         return(new OracleCommand());
     }
     else
     {
         return(new SqlCommand());
     }
 }
Esempio n. 4
0
        public static void CustomUpdateDB(IList <ProtocoloDB> prot, int tipo)
        {
            using (var conn = GetConnection())
            {
                try
                {
                    conn.Open();

                    using (var comm = GetCommand())
                    {
                        var sql = CriaSQL(prot[0], tipo);
                        query = sql;

                        comm.Connection  = conn;
                        comm.CommandType = CommandType.Text;

                        if (StaticParametersDB.GetDriver() == "sqlserver")
                        {
                            comm.CommandText = "SET DATEFORMAT dmy";
                            comm.ExecuteNonQuery();
                        }

                        using (var command = SqlCommandWithParameters(prot[0], tipo))
                        {
                            command.Connection = conn;
                            command.ExecuteNonQuery();
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionCore e = new ExceptionCore();
                    e.ExBanco(2, ex.Message, StaticParametersDB.GetDriver(), ex, query);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Esempio n. 5
0
        private static dynamic GetConnection()
        {
            if (StaticParametersDB.GetDriver() == "oracle")
            {
                string oradb = $"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST={StaticParametersDB.GetHost()})(PORT={StaticParametersDB.GetPort()}))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={StaticParametersDB.GetServiceName()})));User ID={StaticParametersDB.GetUser()};Password={StaticParametersDB.GetPassword()};";

                return(new OracleConnection(oradb));
            }
            else
            {
                if (StaticParametersDB.GetPort() != "0")
                {
                    var strconnection = $"Data Source={StaticParametersDB.GetHost()},{StaticParametersDB.GetPort()};Network Library=DBMSSOCN;Initial Catalog = {StaticParametersDB.GetServiceName()}; User ID = {StaticParametersDB.GetUser()}; Password = {StaticParametersDB.GetPassword()};";

                    return(new SqlConnection(strconnection));
                }
                else
                {
                    var strconnection = $"Server={StaticParametersDB.GetHost()};Database={StaticParametersDB.GetServiceName()};Trusted_Connection={StaticParametersDB.GetTrustedConn()};User Id={StaticParametersDB.GetUser()};Password = {StaticParametersDB.GetPassword()}; ";

                    return(new SqlConnection(strconnection));
                }
            }
        }
Esempio n. 6
0
        private void BtnSalvar_Click(object sender, RoutedEventArgs e)
        {
            var proc = new Processos();

            if (proc.ReadPermissionFolder() == false || proc.WritePermissionFolder() == false)
            {
                System.Windows.Forms.MessageBox.Show("Ops, você não tem permissão para leitura ou escrita na pasta c:/vch", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (proc.WritePermissionFile() == false || proc.ReadPermissionFile() == false)
            {
                System.Windows.Forms.MessageBox.Show("Ops, você não tem permissão para leitura ou escrita no arquivo dados.db | c:/vch/dados.db", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var sessao         = AuxiliarNhibernate.AbrirSessao();
            var parametroDAO   = new ParametroDAO(sessao);
            var parametroDBDAO = new ParametroDB_DAO(sessao);

            if (proc.VerificaProcessoRun() == false)
            {
                Processos process = new Processos();
                var       ctrl    = 0;
                if (StaticParametros.GetDirToke() != null)
                {
                    if (File.Exists(StaticParametros.GetDirToke()))
                    {
                        ctrl++;
                        if (StaticParametros.GetDirOrigem() != null)
                        {
                            if (Directory.Exists(StaticParametros.GetDirOrigem()))
                            {
                                ctrl++;
                            }
                            else
                            {
                                System.Windows.MessageBox.Show("Ops! Parece que a pasta de origem foi movida");
                                txtFolderIni.Text = "";
                                StaticParametros.SetDirOrigem(null);
                            }
                        }

                        if (StaticParametersDB.GetDriver() != null)
                        {
                            ctrl++;

                            StaticParametros.SetIntegraBanco(true);
                        }

                        if (ctrl >= 2)
                        {
                            var newParam = new Parametro {
                                Id = 1, CaminhoDir = StaticParametros.GetDirOrigem(), CaminhoToke = StaticParametros.GetDirToke(), IntegraBanco = StaticParametros.GetIntegraBanco(), GeraLog = StaticParametros.GetGeraLogs()
                            };
                            parametroDAO.Salvar(newParam);

                            if (StaticParametersDB.GetDriver() != null)
                            {
                                TxtStatusBanco.Text = "Conectado";
                            }
                            else
                            {
                                TxtStatusBanco.Text = "Desconectado";
                            }
                            //Armazenamento.AddParametros(new Parametro { Id = 1, CaminhoDir = StaticParametros.GetDirOrigem(), CaminhoToke = StaticParametros.GetDirToke(), IntegraBanco = StaticParametros.GetIntegraBanco() });
                            OrganizaTelaEvent(2);

                            if (StaticParametros.GetDirOrigem() != null && StaticParametros.GetDirOrigem() != "")
                            {
                                process.CriarPastas();
                            }
                        }
                        else
                        {
                            TxtStatusBanco.Text = "Desconectado";
                            System.Windows.MessageBox.Show("É necessário definir um diretorio ou configurar uma conexão com banco de dados para continuar");
                        }
                    }
                    else
                    {
                        System.Windows.MessageBox.Show("Ops! Parece que o arquivo de token foi movido");
                        txtFolderToken.Text = "";
                        StaticParametros.SetDirToke(null);
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("É necessário definir um token para continuar");
                }
            }

            else
            {
                System.Windows.MessageBox.Show("O serviço está em execução");
            }

            sessao.Close();
        }
        private void init()
        {
            init2();
            BtnDelete.Visibility = Visibility.Hidden;
            CboDriver.Items.Insert(0, "Oracle");
            CboDriver.Items.Insert(1, "SQLServer");

            CboDriver.SelectedIndex = -1;
            var sessao      = AuxiliarNhibernate.AbrirSessao();
            var ParametroDB = new ParametroDB_DAO(sessao);

            try
            {
                var process = new Processos();

                var param = ParametroDB.BuscarPorID(1);//Armazenamento.GetParametrosDB();

                try
                {
                    if (param.Driver == "oracle")
                    {
                        CboDriver.SelectedIndex = 0;
                    }
                    else
                    {
                        CboDriver.SelectedIndex = 1;
                    }
                    TxbHost.Text        = param.Host;
                    TxbPort.Text        = param.Port;
                    TxbServiceName.Text = param.ServiceName;
                    TxbUser.Text        = param.User;


                    StaticParametersDB.SetDriver("oracle");
                    StaticParametersDB.SetHost(TxbHost.Text);
                    StaticParametersDB.SetPort(TxbPort.Text);
                    StaticParametersDB.SetServiceName(TxbServiceName.Text);
                    StaticParametersDB.SetUser(TxbUser.Text);

                    PwbSenha.Password = AESThenHMAC.SimpleDecryptWithPassword(param.Password, process.GetMacAdress());
                    StaticParametersDB.SetPassword(PwbSenha.Password);

                    BtnDelete.Visibility = Visibility.Visible;
                }
                catch (Exception e)
                {
                    if (StaticParametersDB.GetDriver() != null)
                    {
                        var driver = StaticParametersDB.GetDriver();
                        if (driver == "oracle")
                        {
                            CboDriver.SelectedIndex = 0;
                        }
                        else
                        {
                            CboDriver.SelectedIndex = 1;
                        }
                        TxbHost.Text        = StaticParametersDB.GetHost();
                        TxbPort.Text        = StaticParametersDB.GetPort();
                        TxbServiceName.Text = StaticParametersDB.GetServiceName();
                        TxbUser.Text        = StaticParametersDB.GetUser();
                        PwbSenha.Password   = StaticParametersDB.GetPassword();

                        BtnDelete.Visibility = Visibility.Visible;
                    }
                }
            }catch (Exception e)
            {
            }

            sessao.Close();
        }
Esempio n. 8
0
        private static string CriaSQL(ProtocoloDB prot, int tipo)
        {
            var    quote  = '\'';
            string format = "dd-MM-yyyy hh:mm:ss";

            //string format1 = "yyyy-MM-dd hh:mm:ss";

            if (tipo == 1)
            {
                //var data = Convert.ToDateTime(prot.dtconsulta); //RetornaArrayData(prot.dtconsulta);
                var data = ConvertDate(prot.dtconsulta);
                var sql  = "UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET NROPROTOCOLO = :Nrprot, XMLPROTOCOLO = :Xmlprot, MENSAGEMERRO = :Erro, DATARETORNO = :Dtretorno, HORARETORNO = :Hrretorno, STATUS = :Status  WHERE ID = :Idevento AND IDSEQ = :Idseq";
                sql = sql.Replace(":Nrprot", string.Concat(quote + prot.nroProt + quote));
                sql = sql.Replace(":Xmlprot", string.Concat(quote + (prot.xmlProt = prot.xmlProt.Replace("> <", "><")) + quote));
                if (String.IsNullOrEmpty(prot.erros))
                {
                    sql = sql.Replace(":Erro", string.Concat(quote + "null" + quote));
                }
                else
                {
                    sql = sql.Replace(":Erro", string.Concat(quote + prot.erros.Replace("'", "") + quote));
                }
                if (StaticParametersDB.GetDriver() == "oracle")
                {
                    sql = sql.Replace(":Dtretorno", "trunc(SYSDATE)");
                }
                else
                {
                    //CONVERT(DATETIME, '2012-06-05', 102)
                    sql = sql.Replace(":Dtretorno", string.Concat(quote + data.ToString(format) + quote));
                }
                sql = sql.Replace(":Hrretorno", string.Concat(quote + prot.hrconsulta + quote));
                sql = sql.Replace(":Status", string.Concat(quote + prot.status + quote));
                sql = sql.Replace(":Idevento", string.Concat(quote + prot.idEvento + quote));
                sql = sql.Replace(":Idseq", prot.idSeq);

                return(sql);
            }
            else if (tipo == 2)
            {
                //var data = Convert.ToDateTime(prot.dtconsulta);//RetornaArrayData(prot.dtconsulta);
                var data = ConvertDate(prot.dtconsulta);
                var sql  = "UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET NROPROTOCOLO = :nrprot, XMLPROTOCOLO = :xmlprot, NRORECIBO = :nroRec, XMLRECIBO = :xmlRec, DATARETORNO = :Dtretorno, HORARETORNO = :Hrretorno, STATUS = :Status WHERE ID = :Idevento AND IDSEQ = :Idseq";
                sql = sql.Replace(":nrprot", string.Concat(quote + prot.nroProt + quote));
                sql = sql.Replace(":xmlprot", string.Concat(quote + prot.xmlProt + quote));
                sql = sql.Replace(":nroRec", string.Concat(quote + prot.nroRec + quote));
                sql = sql.Replace(":xmlRec", string.Concat(quote + prot.xmlRec + quote));
                if (StaticParametersDB.GetDriver() == "oracle")
                {
                    sql = sql.Replace(":Dtretorno", "trunc(SYSDATE)");
                }
                else
                {
                    //CONVERT(DATETIME, '2012-06-05', 102)
                    sql = sql.Replace(":Dtretorno", string.Concat(quote + data.ToString(format) + quote));
                }
                sql = sql.Replace(":Hrretorno", string.Concat(quote + prot.hrconsulta + quote));
                sql = sql.Replace(":Status", string.Concat(quote + prot.status + quote));
                sql = sql.Replace(":Idevento", string.Concat(quote + prot.idEvento + quote));
                sql = sql.Replace(":Idseq", prot.idSeq);

                return(sql);
            }
            else if (tipo == 3)//novo
            {
                //var data = Convert.ToDateTime(prot.dtenvio);//RetornaArrayData(prot.dtenvio);
                var data = ConvertDate(prot.dtenvio);
                var sql  = "UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET NROPROTOCOLO = :Nrprot, XMLPROTOCOLO = :Xmlprot, STATUS = :Status, DATAENVIO = :Dtenvio, HORAENVIO = :Hrenvio  WHERE ID = :Idevento AND IDSEQ = :Idseq";
                sql = sql.Replace(":Nrprot", string.Concat(quote + prot.nroProt + quote));
                sql = sql.Replace(":Xmlprot", string.Concat(quote + prot.xmlProt + quote));
                sql = sql.Replace(":Status", string.Concat(quote + prot.status + quote));
                if (StaticParametersDB.GetDriver() == "oracle")
                {
                    sql = sql.Replace(":Dtenvio", "trunc(SYSDATE)");
                }
                else
                {
                    //CONVERT(DATETIME, '2012-06-05', 102)
                    sql = sql.Replace(":Dtenvio", string.Concat(quote + data.ToString(format) + quote));
                }
                sql = sql.Replace(":Hrenvio", string.Concat(quote + prot.hrenvio + quote));
                sql = sql.Replace(":Idevento", string.Concat(quote + prot.idEvento + quote));
                sql = sql.Replace(":Idseq", prot.idSeq);

                return(sql);
            }
            else
            {
                //var data = Convert.ToDateTime(prot.dtconsulta);//RetornaArrayData(prot.dtconsulta);
                var data = ConvertDate(prot.dtconsulta);
                var sql  = "UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET DATARETORNO = :Dtretorno, HORARETORNO = :Hrretorno, STATUS = :Status  WHERE ID = :Idevento AND IDSEQ = :Idseq";
                if (StaticParametersDB.GetDriver() == "oracle")
                {
                    sql = sql.Replace(":Dtretorno", "trunc(SYSDATE)");
                }
                else
                {
                    //CONVERT(DATETIME, '2012-06-05', 102)
                    sql = sql.Replace(":Dtretorno", string.Concat(quote + data.ToString(format) + quote));
                }
                sql = sql.Replace(":Hrretorno", string.Concat(quote + prot.hrconsulta + quote));
                sql = sql.Replace(":Status", string.Concat(quote + prot.status + quote));
                sql = sql.Replace(":Idevento", string.Concat(quote + prot.idEvento + quote));
                sql = sql.Replace(":Idseq", prot.idSeq);

                return(sql);
            }
        }
Esempio n. 9
0
        private static dynamic SqlCommandWithParameters(ProtocoloDB prot, int tipo, bool forceUpdate = false)
        {
            string format = "dd-MM-yyyy hh:mm:ss";

            if (StaticParametersDB.GetDriver() == "oracle")
            {
                if (tipo == 1)
                {
                    OracleCommand oraCommand = new OracleCommand("UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET NROPROTOCOLO = :Nrprot, XMLPROTOCOLO = :Xmlprot, MENSAGEMERRO = :Erro, DATARETORNO = :Dtretorno, HORARETORNO = :Hrretorno, STATUS = :Status  WHERE ID = :Idevento AND IDSEQ = :Idseq");
                    oraCommand.Parameters.Add(new OracleParameter(":Nrprot", prot.nroProt));
                    oraCommand.Parameters.Add(new OracleParameter(":Xmlprot", prot.xmlProt));
                    if (String.IsNullOrEmpty(prot.erros))
                    {
                        oraCommand.Parameters.Add(new OracleParameter(":Erro", DBNull.Value));
                    }
                    else
                    {
                        if (forceUpdate == true && prot.erros.Length > 4000)
                        {
                            prot.erros = "Consulte o portal ives para detalhes do erro";
                        }
                        oraCommand.Parameters.Add(new OracleParameter(":Erro", prot.erros.Replace("'", "")));
                    }
                    oraCommand.Parameters.Add(new OracleParameter(":Dtretorno", prot.dtconsulta));
                    oraCommand.Parameters.Add(new OracleParameter(":Hrretorno", prot.hrconsulta));
                    oraCommand.Parameters.Add(new OracleParameter(":Status", prot.status));
                    oraCommand.Parameters.Add(new OracleParameter(":Idevento", prot.idEvento));
                    oraCommand.Parameters.Add(new OracleParameter(":Idseq", prot.idSeq));

                    return(oraCommand);
                }
                else if (tipo == 2)
                {
                    OracleCommand oraCommand = new OracleCommand("UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET NROPROTOCOLO = :nrprot, XMLPROTOCOLO = :xmlprot, NRORECIBO = :nroRec, XMLRECIBO = :xmlRec, DATARETORNO = :Dtretorno, HORARETORNO = :Hrretorno, STATUS = :Status WHERE ID = :Idevento AND IDSEQ = :Idseq");
                    oraCommand.Parameters.Add(new OracleParameter(":nrprot", prot.nroProt));
                    oraCommand.Parameters.Add(new OracleParameter(":xmlprot", prot.xmlProt));
                    oraCommand.Parameters.Add(new OracleParameter(":nroRec", prot.nroRec));
                    oraCommand.Parameters.Add(new OracleParameter(":xmlRec", prot.xmlRec));
                    oraCommand.Parameters.Add(new OracleParameter(":Dtretorno", prot.dtconsulta));
                    oraCommand.Parameters.Add(new OracleParameter(":Hrretorno", prot.hrconsulta));
                    oraCommand.Parameters.Add(new OracleParameter(":Status", prot.status));
                    oraCommand.Parameters.Add(new OracleParameter(":Idevento", prot.idEvento));
                    oraCommand.Parameters.Add(new OracleParameter(":Idseq", prot.idSeq));

                    return(oraCommand);
                }
                else if (tipo == 3)
                {
                    OracleCommand oraCommand = new OracleCommand("UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET NROPROTOCOLO = :Nrprot, XMLPROTOCOLO = :Xmlprot, STATUS = :Status, DATAENVIO = :Dtenvio, HORAENVIO = :Hrenvio  WHERE ID = :Idevento AND IDSEQ = :Idseq");
                    oraCommand.Parameters.Add(new OracleParameter(":Nrprot", prot.nroProt));
                    oraCommand.Parameters.Add(new OracleParameter(":Xmlprot", prot.xmlProt));
                    oraCommand.Parameters.Add(new OracleParameter(":Status", prot.status));
                    oraCommand.Parameters.Add(new OracleParameter(":Dtenvio", prot.dtenvio));
                    oraCommand.Parameters.Add(new OracleParameter(":Hrenvio", prot.hrenvio));
                    oraCommand.Parameters.Add(new OracleParameter(":Idevento", prot.idEvento));
                    oraCommand.Parameters.Add(new OracleParameter(":Idseq", prot.idSeq));
                    return(oraCommand);
                }
                else
                {
                    OracleCommand oraCommand = new OracleCommand("UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET DATARETORNO = :Dtretorno, HORARETORNO = :Hrretorno, STATUS = :Status  WHERE ID = :Idevento AND IDSEQ = :Idseq");
                    oraCommand.Parameters.Add(new OracleParameter(":Dtretorno", prot.dtconsulta));
                    oraCommand.Parameters.Add(new OracleParameter(":Hrretorno", prot.hrconsulta));
                    oraCommand.Parameters.Add(new OracleParameter(":Status", prot.status));
                    oraCommand.Parameters.Add(new OracleParameter(":Idevento", prot.idEvento));
                    oraCommand.Parameters.Add(new OracleParameter(":Idseq", prot.idSeq));
                    return(oraCommand);
                }
            }
            else
            {
                if (tipo == 1)
                {
                    SqlCommand sqlCommand = new SqlCommand("UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET NROPROTOCOLO = @Nrprot, XMLPROTOCOLO = @Xmlprot, MENSAGEMERRO = @Erro, DATARETORNO = @Dtretorno, HORARETORNO = @Hrretorno, STATUS = @Status  WHERE ID = @Idevento AND IDSEQ = @Idseq");
                    sqlCommand.Parameters.Add(new SqlParameter("@Nrprot", prot.nroProt));
                    sqlCommand.Parameters.Add(new SqlParameter("@Xmlprot", prot.xmlProt));
                    if (String.IsNullOrEmpty(prot.erros))
                    {
                        sqlCommand.Parameters.Add(new SqlParameter("@Erro", DBNull.Value));
                    }
                    else
                    {
                        if (forceUpdate == true && prot.erros.Length > 4000)
                        {
                            prot.erros = "Consulte o portal do iVes para obter detalhes do erro";
                        }
                        sqlCommand.Parameters.Add(new SqlParameter("@Erro", prot.erros.Replace("'", "")));
                    }
                    sqlCommand.Parameters.Add(new SqlParameter("@Dtretorno", Convert.ToDateTime(prot.dtconsulta).ToString(format)));
                    sqlCommand.Parameters.Add(new SqlParameter("@Hrretorno", prot.hrconsulta));
                    sqlCommand.Parameters.Add(new SqlParameter("@Status", prot.status));
                    sqlCommand.Parameters.Add(new SqlParameter("@Idevento", prot.idEvento));
                    sqlCommand.Parameters.Add(new SqlParameter("@Idseq", prot.idSeq));

                    return(sqlCommand);
                }
                else if (tipo == 2)
                {
                    SqlCommand sqlCommand = new SqlCommand("UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET NROPROTOCOLO = @nrprot, XMLPROTOCOLO = @xmlprot, NRORECIBO = @nroRec, XMLRECIBO = @xmlRec, DATARETORNO = @Dtretorno, HORARETORNO = @Hrretorno, STATUS = @Status WHERE ID = @Idevento AND IDSEQ = @Idseq");
                    sqlCommand.Parameters.Add(new SqlParameter("@nrprot", prot.nroProt));
                    sqlCommand.Parameters.Add(new SqlParameter("@xmlprot", prot.xmlProt));
                    sqlCommand.Parameters.Add(new SqlParameter("@nroRec", prot.nroRec));
                    sqlCommand.Parameters.Add(new SqlParameter("@xmlRec", prot.xmlRec));
                    sqlCommand.Parameters.Add(new SqlParameter("@Dtretorno", Convert.ToDateTime(prot.dtconsulta).ToString(format)));
                    sqlCommand.Parameters.Add(new SqlParameter("@Hrretorno", prot.hrconsulta));
                    sqlCommand.Parameters.Add(new SqlParameter("@Status", prot.status));
                    sqlCommand.Parameters.Add(new SqlParameter("@Idevento", prot.idEvento));
                    sqlCommand.Parameters.Add(new SqlParameter("@Idseq", prot.idSeq));

                    return(sqlCommand);
                }
                else if (tipo == 3)
                {
                    SqlCommand sqlCommand = new SqlCommand("UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET NROPROTOCOLO = @Nrprot, XMLPROTOCOLO = @Xmlprot, STATUS = @Status, DATAENVIO = @Dtenvio, HORAENVIO = @Hrenvio  WHERE ID = @Idevento AND IDSEQ = @Idseq");
                    sqlCommand.Parameters.Add(new SqlParameter("@Nrprot", prot.nroProt));
                    sqlCommand.Parameters.Add(new SqlParameter("@Xmlprot", prot.xmlProt));
                    sqlCommand.Parameters.Add(new SqlParameter("@Status", prot.status));
                    sqlCommand.Parameters.Add(new SqlParameter("@Dtenvio", Convert.ToDateTime(prot.dtenvio).ToString(format)));
                    sqlCommand.Parameters.Add(new SqlParameter("@Hrenvio", prot.hrenvio));
                    sqlCommand.Parameters.Add(new SqlParameter("@Idevento", prot.idEvento));
                    sqlCommand.Parameters.Add(new SqlParameter("@Idseq", prot.idSeq));
                    return(sqlCommand);
                }
                else
                {
                    SqlCommand sqlCommand = new SqlCommand("UPDATE ZMDATVIVES_EVENTOS_ESOCIAL SET DATARETORNO = @Dtretorno, HORARETORNO = @Hrretorno, STATUS = @Status  WHERE ID = @Idevento AND IDSEQ = @Idseq");
                    sqlCommand.Parameters.Add(new SqlParameter("@Dtretorno", Convert.ToDateTime(prot.dtconsulta).ToString(format)));
                    sqlCommand.Parameters.Add(new SqlParameter("@Hrretorno", prot.hrconsulta));
                    sqlCommand.Parameters.Add(new SqlParameter("@Status", prot.status));
                    sqlCommand.Parameters.Add(new SqlParameter("@Idevento", prot.idEvento));
                    sqlCommand.Parameters.Add(new SqlParameter("@Idseq", prot.idSeq));
                    return(sqlCommand);
                }
            }
        }
Esempio n. 10
0
        public static bool UpdateDB(ProtocoloDB prot)
        {
            bool retorno = true;

            using (var conn = GetConnection())
            {
                try
                {
                    conn.Open();

                    using (var comm = GetCommand())
                    {
                        if (prot.nroRec == null || prot.nroRec == "")
                        {
                            var sql = CriaSQL(prot, 1);
                            query            = sql;
                            comm.Connection  = conn;
                            comm.CommandType = CommandType.Text;
                            if (StaticParametersDB.GetDriver() == "sqlserver")
                            {
                                comm.CommandText = "SET DATEFORMAT dmy";
                                comm.ExecuteNonQuery();
                            }
                            try //Tenta atualizar com tamanho original da mensagem de erro
                            {
                                using (var command = SqlCommandWithParameters(prot, 1))
                                {
                                    command.Connection = conn;
                                    command.ExecuteNonQuery();
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex.HResult == -2146232060 || ex.HResult == -2147467259)       //Banco retorna erros de valor de caracteres excedido.
                                {
                                    using (var command = SqlCommandWithParameters(prot, 1, true)) //Valor true passado por parametro para forcar a atualização, alterando o valor da mensagem.
                                    {
                                        command.Connection = conn;
                                        command.ExecuteNonQuery();
                                    }
                                }
                                else
                                {
                                    throw ex; //Caso seja outro erro, grava log.
                                }
                            }
                        }
                        else
                        {
                            var sql = CriaSQL(prot, 2);
                            query            = sql;
                            comm.Connection  = conn;
                            comm.CommandType = CommandType.Text;
                            if (StaticParametersDB.GetDriver() == "sqlserver")
                            {
                                comm.CommandText = "SET DATEFORMAT dmy";
                                comm.ExecuteNonQuery();
                            }
                            using (var command = SqlCommandWithParameters(prot, 2))
                            {
                                command.Connection = conn;
                                command.ExecuteNonQuery();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionCore e = new ExceptionCore();
                    e.ExBanco(2, ex.Message, StaticParametersDB.GetDriver(), ex, query);

                    retorno = false;
                }
                finally
                {
                    conn.Close();
                }
            }

            return(retorno);
        }
Esempio n. 11
0
        public static void GetData(ISession sessao)
        {
            var ProtocoloDAO = new ProtocoloDB_DAO(sessao);

            using (var conn = GetConnection())
            {
                //Não é possível abrir o banco de dados solicitado pelo logon. Falha de logon.Falha de logon do usuário 'AUTORIDADE NT\SISTEMA'.
                try
                {
                    conn.Open();

                    using (var comm = GetCommand())
                    {
                        comm.Connection  = conn;
                        comm.CommandText = "SELECT ID, XMLEVENTO, IDSEQ FROM ZMDATVIVES_EVENTOS_ESOCIAL WHERE NROPROTOCOLO IS NULL";

                        var adapter   = GetAdapter(comm);
                        var dataTable = new System.Data.DataTable();

                        adapter.Fill(dataTable);
                        Processos proc = new Processos();
                        foreach (System.Data.DataRow row in dataTable.Rows)
                        {
                            try
                            {
                                var Base = proc.DefineBaseEnvioDB(Convert.ToString(row["XMLEVENTO"]), (Convert.ToString(row["ID"]) + "-" + Convert.ToString(row["IDSEQ"]) + "-" + StaticParametersDB.GetId()));
                                var prot = new ProtocoloDB
                                {
                                    id        = string.Concat(Convert.ToString(row["ID"]), "-", Convert.ToString(row["IDSEQ"]), "-" + StaticParametersDB.GetId()),
                                    idEvento  = Convert.ToString(row["ID"]),
                                    idSeq     = Convert.ToString(row["IDSEQ"]),
                                    xmlEvento = Convert.ToString(row["XMLEVENTO"]),
                                    driver    = StaticParametersDB.GetDriver(),
                                    baseEnv   = Convert.ToString(Base),
                                    idDB      = StaticParametersDB.GetId()
                                };
                                ProtocoloDAO.Salvar(prot);
                            }
                            catch (Exception ex)
                            {
                                if (ex.HResult != -2147467261)
                                {
                                    ExceptionCore e = new ExceptionCore();
                                    e.ExBanco(30, "ID Evento: " + (Convert.ToString(row["ID"]) + "-" + Convert.ToString(row["IDSEQ"]) + "-" + StaticParametersDB.GetId()) + " | Erro: " + ex.Message, StaticParametersDB.GetDriver(), ex, "");
                                }
                                else
                                {
                                    UpdateDB(
                                        proc.GeraProtocoloAux("1"
                                                              , Convert.ToString(row["ID"])
                                                              , Convert.ToString(row["IDSEQ"])
                                                              , "<erro>Tag tipo de ambiente não presente no XML</erro>"
                                                              , "0"
                                                              , "Tag tipo de ambiente não presente no XML")
                                        );
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionCore e = new ExceptionCore();
                    e.ExBanco(1, ex.Message, StaticParametersDB.GetDriver(), ex, "");
                }
                finally
                {
                    conn.Close();
                }
            }
        }