示例#1
0
        public Config_Fields GetRecord()
        {
            //**************
            //* Declarações
            //**************
            Config_Fields oConfig    = new Config_Fields();
            DBManager     oDBManager = new DBManager(ConnectionString);
            DataTable     oTable     = new DataTable();
            string        SQL        = string.Empty;

            //****************************
            //* Controla erro de execução
            //****************************
            try
            {
                //*****************
                //* Obtem registro
                //*****************
                SQL    = "SELECT * FROM config WHERE codigo = 1";
                oTable = oDBManager.ExecuteQuery(SQL);

                //************************************
                //* Devolve status e mensagem de erro
                //************************************
                _ErrorText = oDBManager.ErrorMessage;
                _Error     = oDBManager.Error;
            }
            catch (Exception oException)
            {
                //************************************
                //* Devolve status e mensagem de erro
                //************************************
                _ErrorText = oException.Message;
                _Error     = true;
            }

            //*********************************
            //* A pesquisa retornou registros?
            //*********************************
            if (oTable != null)
            {
                //***********************************
                //* A pesquisa localizou o registro?
                //***********************************
                if (oTable.Rows.Count == 1)
                {
                    //*******************************
                    //* Copia dados para a estrutura
                    //*******************************
                    DataRow oRow = oTable.Rows[0];
                    oConfig.SMTP_Autenticacao = !DBNull.Value.Equals(oRow["smtp_autenticacao"]) ? Convert.ToBoolean(oRow["smtp_autenticacao"]) : false;
                    oConfig.SMTP_Endereco     = !DBNull.Value.Equals(oRow["smtp_endereco"]) ? oRow["smtp_endereco"].ToString() : string.Empty;
                    oConfig.SMTP_Porta        = !DBNull.Value.Equals(oRow["smtp_porta"]) ? Convert.ToInt32("0" + oRow["smtp_porta"]) : 0;
                    oConfig.SMTP_Usuario      = !DBNull.Value.Equals(oRow["smtp_usuario"]) ? oRow["smtp_usuario"].ToString() : string.Empty;
                    oConfig.SMTP_Senha        = !DBNull.Value.Equals(oRow["smtp_senha"]) ?  Crypto.DecryptString(oRow["smtp_senha"].ToString()) : string.Empty;
                    oConfig.SMTP_SSL          = !DBNull.Value.Equals(oRow["smtp_ssl"]) ? Convert.ToBoolean(oRow["smtp_ssl"]) : false;
                    oConfig.SMTP_TLS          = !DBNull.Value.Equals(oRow["smtp_tls"]) ? Convert.ToBoolean(oRow["smtp_tls"]) : false;
                }
            }
            else
            {
                //************************************
                //* Devolve status e mensagem de erro
                //************************************
                _ErrorText = "O Resultado da pesquisa retornou nulo";
                _Error     = true;
            }

            //****************
            //* Retorna dados
            //****************
            return(oConfig);
        }
示例#2
0
        public bool ApplyRecord(Config_Fields oConfig)
        {
            //**************
            //* Declarações
            //**************
            DBManager oDBManager = new DBManager(ConnectionString);
            DataTable oTable     = new DataTable();
            string    SQL        = string.Empty;

            //****************************
            //* Controla erro de execução
            //****************************
            try
            {
                //*****************
                //* Obtem registro
                //*****************
                SQL    = "SELECT * FROM config ORDER BY codigo DESC";
                oTable = oDBManager.ExecuteQuery(SQL);

                //************************************
                //* Devolve status e mensagem de erro
                //************************************
                _ErrorText = oDBManager.ErrorMessage;
                _Error     = oDBManager.Error;
            }
            catch (Exception oException)
            {
                //************************************
                //* Devolve status e mensagem de erro
                //************************************
                _ErrorText = oException.Message;
                _Error     = true;
            }

            //*********************************
            //* A pesquisa retornou registros?
            //*********************************
            if (oTable != null)
            {
                //***********************************
                //* A pesquisa localizou o registro?
                //***********************************
                if (oTable.Rows.Count == 0)
                {
                    //****************
                    //* Cria registro
                    //****************
                    SQL  = "INSERT INTO config (";
                    SQL += "codigo,";
                    SQL += "smtp_autenticacao,";
                    SQL += "smtp_endereco,";
                    SQL += "smtp_porta,";
                    SQL += "smtp_usuario,";
                    SQL += "smtp_senha,";
                    SQL += "smtp_ssl,";
                    SQL += "smtp_tls";
                    SQL += ") VALUES (";
                    SQL += "1,";
                    SQL += Convert.ToInt16(oConfig.SMTP_Autenticacao) + ",";
                    SQL += "'" + oConfig.SMTP_Endereco.SQLFilter() + "',";
                    SQL += oConfig.SMTP_Porta + ",";
                    SQL += "'" + oConfig.SMTP_Usuario.SQLFilter() + "',";
                    SQL += "'" + Crypto.EncryptString(oConfig.SMTP_Senha).SQLFilter() + "',";
                    SQL += Convert.ToInt16(oConfig.SMTP_SSL) + ",";
                    SQL += Convert.ToInt16(oConfig.SMTP_TLS) + ")";
                }
                else
                {
                    //***************************
                    //* Obtem código do registro
                    //***************************
                    DataRow oRow = oTable.Rows[0];

                    //********************
                    //* Atualiza registro
                    //********************
                    SQL  = "UPDATE config (";
                    SQL += "smtp_autenticacao = " + Convert.ToInt16(oConfig.SMTP_Autenticacao) + ",";
                    SQL += "smtp_endereco = '" + oConfig.SMTP_Endereco.SQLFilter() + "',";
                    SQL += "smtp_porta = " + oConfig.SMTP_Porta + ",";
                    SQL += "smtp_usuario = '" + oConfig.SMTP_Usuario.SQLFilter() + "',";
                    SQL += "smtp_senha = '" + Crypto.EncryptString(oConfig.SMTP_Senha).SQLFilter() + "',";
                    SQL += "smtp_ssl = " + Convert.ToInt16(oConfig.SMTP_SSL) + ",";
                    SQL += "smtp_tls = " + Convert.ToInt16(oConfig.SMTP_TLS) + " ";
                    SQL += "WHERE config.codigo = " + oRow["codigo"];
                }
            }

            //****************************
            //* Controla erro de execução
            //****************************
            try
            {
                //**************************
                //* Executa comando formado
                //**************************
                oDBManager.ExecuteCommand(SQL);

                //************************************
                //* Devolve status e mensagem de erro
                //************************************
                _ErrorText = oDBManager.ErrorMessage;
                _Error     = oDBManager.Error;
            }
            catch (Exception oException)
            {
                //************************************
                //* Devolve status e mensagem de erro
                //************************************
                _ErrorText = oException.Message;
                _Error     = true;
            }

            //*****************************
            //* Retorna estado de execução
            //*****************************
            return(!oDBManager.Error);
        }