コード例 #1
0
        public bool Inativar(int codigo)
        {
            try
            {
                banco.AbrirConexao();

                bool status = false;

                //TODO: Add a tabela VEICULO status
                string SQL_empresa = string.Format("UPDATE TB_Veiculo SET Status = '{0}' WHERE ID_Veiculo = '{1}'", status, codigo);


                if (banco.AtualizarComandoSQL(SQL_empresa) != true)
                {
                    Debug.WriteLine("Erro - Inativar Empresa no BD -> String : " + SQL_empresa);
                }
                else
                {
                    Debug.WriteLine("OK - Inativar Empresa no BD");
                }
            }
            catch (SqlException e)
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
        public bool Atualizar(Funcionario f)
        {
            // QUANDO ABRIRMOS A CONEXAO, ELA JA ESTÁ SENDO ESTANCIADO COMO UMA TRANSAÇÃO.
            IDbTransaction trans = banco.AbrirConexaoComTransacao();

            try
            {
                string SQL_PesFuncionario = string.Format(
                    "UPDATE TB_Pessoa SET " +
                    "CPF = '{0}', " +
                    "RG = '{1}', " +
                    "Nome = '{2}', " +
                    "DataNasc = '{3}', " +
                    "Sexo = '{4}' " +
                    "WHERE ID_Pessoa = '{5}'",
                    f.cpf,
                    f.rg,
                    f.nome,
                    f.dataNasc,
                    f.sexo,
                    f.ID);



                if (banco.AtualizarComandoSQL(SQL_PesFuncionario, trans) != true)
                {
                    Debug.WriteLine("Erro - Atualizar Pessoa Funcionario no BD -> String : " + SQL_PesFuncionario);
                    trans.Rollback();
                    return(false);
                }
                else
                {
                    Debug.WriteLine("OK - Atualizar Pessoa Funcionario no BD -> String : " + SQL_PesFuncionario);
                }



                // Comprimento ? trocar para complemento
                string SQL_endereco = string.Format(
                    "UPDATE TB_Endereco SET " +
                    "ENDE_Rua = '{0}', " +
                    "ENDE_Numero = '{1}', " +
                    "ENDE_Comprimento = '{2}', " +
                    "ENDE_Bairro = '{3}', " +
                    "ENDE_Municipio = '{4}', " +
                    "ENDE_Estado = '{5}', " +
                    "ENDE_CEP = '{6}', " +
                    "ENDE_Cidade = '{7}' " +
                    "WHERE ID_Pessoa = '{8}'",
                    f.endereco.rua,
                    f.endereco.numero,
                    f.endereco.complemento,
                    f.endereco.bairro,
                    f.endereco.municipio,
                    f.endereco.estado,
                    f.endereco.cep,
                    f.endereco.cidade,
                    f.ID);



                if (banco.AtualizarComandoSQL(SQL_endereco, trans) != true)
                {
                    Debug.WriteLine("Erro - Atualizar Endereço de Funcionario -> String : " + SQL_endereco);
                    trans.Rollback();
                    return(false);
                }
                else
                {
                    Debug.WriteLine("OK - Atualizar Endereço de Funcionario -> String : " + SQL_endereco);
                }



                foreach (var telefone in f.Telefone)
                {
                    string SQL_telefone = string.Format(
                        "UPDATE TB_Telefone SET " +
                        "Tel_DDI = '{0}', " +
                        "Tel_DDD = '{1}', " +
                        "Tel_Telefone = '{2}' " +
                        "WHERE ID_PessoaTel = '{3}'",
                        telefone.DDI,
                        telefone.DDD,
                        telefone.telefone,
                        f.ID);


                    if (banco.AtualizarComandoSQL(SQL_telefone, trans) != true)
                    {
                        Debug.WriteLine("Erro - Atualizar Telefone de Funcionario -> String : " + SQL_telefone);
                        trans.Rollback();
                        return(false);
                    }
                    else
                    {
                        Debug.WriteLine("OK - Atualizar Telefone de Funcionario -> String : " + SQL_telefone);
                    }
                }



                string SQL_funcionario = string.Format(
                    "UPDATE TB_Funcionario SET " +
                    "ID_Perfil = '{0}', " +
                    "Salario = '{1}' " +
                    "WHERE ID_Pessoa = '{2}'",
                    f.perfil.ID,
                    f.salario,
                    f.ID);



                if (banco.AtualizarComandoSQL(SQL_funcionario, trans) != true)
                {
                    Debug.WriteLine("Erro - Atualizar Perfil de Funcionario -> String : " + SQL_funcionario);
                    trans.Rollback();
                    return(false);
                }
                else
                {
                    Debug.WriteLine("OK - Atualizar Perfil de Funcionario -> String : " + SQL_funcionario);
                }

                Debug.WriteLine("OK - Atualizar Funcionario");
                trans.Commit();

                return(true);
            }
            catch (SqlException e)
            {
                Debug.Write("Erro - Atualizar Funcionario" + e);
                return(false);
            }
            finally
            {
                banco.FecharConexao();
            }
        }
コード例 #3
0
        public bool Atualizar(Empresa e)
        {
            try
            {
                banco.AbrirConexao();


                string SQL_empresa = string.Format(
                    "UPDATE TB_Empresa SET" +
                    "EMP_CNPJ = '{0}'" +
                    "EMP_RazaoSocial = '{1}'" +
                    "EMP_Email = '{2}'" +
                    "WHERE EMP_ID = '{4}'",
                    e.cnpj,
                    e.razaoSocial,
                    e.email,
                    e.ID);


                if (banco.AtualizarComandoSQL(SQL_empresa) != true)
                {
                    Debug.WriteLine("Erro - Atualizar Inserir Empresa no BD -> String : " + SQL_empresa);
                }
                else
                {
                    Debug.WriteLine("OK - Atualizar Inserir Empresa no BD");
                }


                // Comprimento ? trocar para complemento
                string SQL_endereco = string.Format(
                    "UPDATE TB_Endereco SET" +
                    "ENDE_Rua = '{0}'," +
                    "ENDE_Numero = '{1}'," +
                    "ENDE_Comprimento = '{2}'," +
                    "ENDE_Bairro = '{3}'," +
                    "ENDE_Municipio = '{4}'," +
                    "ENDE_Estado = '{5}'," +
                    "ENDE_CEP = '{6}'," +
                    "ENDE_Cidade = '{7}'," +
                    "WHERE ID_Empresa = '{8}'",
                    e.endereco.rua,
                    e.endereco.numero,
                    e.endereco.complemento,
                    e.endereco.bairro,
                    e.endereco.municipio,
                    e.endereco.estado,
                    e.endereco.cep,
                    e.endereco.cidade,
                    e.ID);


                if (banco.AtualizarComandoSQL(SQL_endereco))
                {
                    Debug.WriteLine("Erro - Atualizar Endereço de Empresa -> String : " + SQL_endereco);
                }
                else
                {
                    Debug.WriteLine("OK - Atualizar Endereço de Empresa");
                }


                foreach (var telefone in e.telefone)
                {
                    string SQL_telefone = string.Format(
                        "UPDATE TB_Telefone SET" +
                        "Tel_DDI = '{0}'," +
                        "Tel_DDD = '{1}'," +
                        "Tel_Telefone = '{2}'," +
                        "WHERE ID_EmpresaTel = '{3}'",
                        telefone.DDI,
                        telefone.DDD,
                        telefone.telefone,
                        e.ID);


                    if (banco.AtualizarComandoSQL(SQL_telefone))
                    {
                        Debug.WriteLine("Erro - Atualizar Telefone de Empresa-> String : " + SQL_telefone);
                    }
                    else
                    {
                        Debug.WriteLine("OK - Atualizar Telefone de Empresa");
                    }
                }


                Debug.WriteLine("OK - Atualizar Empresa");
                return(true);
            }
            catch (SqlException ex)
            {
                Debug.Write("Erro - Atualizar Empresa" + ex);
                return(false);
            }
            finally
            {
                banco.FecharConexao();
            }
        }