示例#1
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();
            }
        }
示例#2
0
        public bool Inserir(Veiculo v)
        {
            // QUANDO ABRIRMOS A CONEXAO, ELA JA ESTÁ SENDO ESTANCIADO COMO UMA TRANSAÇÃO.
            IDbTransaction trans = banco.AbrirConexaoComTransacao();

            try
            {
                //TODO : Alterado no BD placa para varchar, criar alter table
                //TODO : Excluido Campo ID_marca Repetido, criar alter table
                // O BD esta com 2 campos para marca
                string SQL_Veiculo = string.Format(
                    "INSERT INTO TB_Veiculo" +
                    "(Vei_Placa," +
                    "Vei_Marca," +
                    "Vei_Modelo," +
                    "Vei_Renavam," +
                    "Vei_Cor," +
                    "ID_EmpresaV)" +
                    "VALUES ('{0}','{1}','{2}','{3}','{4}','{5}')" +
                    "SELECT SCOPE_IDENTITY()",
                    v.placa,
                    v.marca,
                    v.modelo,
                    v.renavam,
                    v.cor,
                    v.empresa.ID);

                int id = banco.ExecutarComandoSQL(SQL_Veiculo, trans);

                if (id <= 0)
                {
                    Debug.WriteLine("Erro - Inserir Veiculo no BD -> String : " + SQL_Veiculo);
                    trans.Rollback();
                    return(false);
                }
                else
                {
                    Debug.WriteLine("OK - Inserir Veiculo no BD -> String : " + SQL_Veiculo);
                }



                //CASO NADA DE ERRADO EM NENHUMA DAS EXECUÇÕES DOS COMANDOS SQL, SERÁ DADO O COMMIT.
                trans.Commit();

                Debug.WriteLine("OK - Veiculo");

                return(true);
            }
            catch (SqlException e)
            {
                //SE ALGO DER ERRADO EM ALGUMA DAS INSERÇÕES, SERÁ DADO O ROLLBACK,ONDE VOLTARA AO SEU ESTADO ANTERIOR
                trans.Rollback();

                Debug.Write("Erro - 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();
            }
        }
        public bool Inserir(Motorista m)
        {
            // QUANDO ABRIRMOS A CONEXAO, ELA JA ESTÁ SENDO ESTANCIADO COMO UMA TRANSAÇÃO.
            IDbTransaction trans = banco.AbrirConexaoComTransacao();

            try
            {
                string SQL_PesMotorista = string.Format(
                    "INSERT INTO TB_Pessoa" +
                    "(CPF," +
                    "RG," +
                    "Nome," +
                    "DataNasc," +
                    "Sexo)" +
                    "VALUES ('{0}','{1}','{2}','{3}','{4}')" +
                    "SELECT SCOPE_IDENTITY()",
                    m.cpf,
                    m.rg,
                    m.nome,
                    m.dataNasc,
                    m.sexo);

                int id = banco.ExecutarComandoSQL(SQL_PesMotorista, trans);

                if (id <= 0)
                {
                    Debug.WriteLine("Erro - Inserir Pessoa Motorista no BD -> String : " + SQL_PesMotorista);
                    trans.Rollback();
                    return(false);
                }
                else
                {
                    Debug.WriteLine("OK - Inserir Pessoa Motorista no BD -> String : " + SQL_PesMotorista);
                }

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


                if (banco.ExecutarComandoSQL(SQL_endereco, trans) < 0)
                {
                    Debug.WriteLine("Erro - Endereço de Motorista -> String : " + SQL_endereco);
                    trans.Rollback();
                    return(false);
                }
                else
                {
                    Debug.WriteLine("OK - Endereço de Motorista -> String : " + SQL_endereco);
                }



                foreach (var telefone in m.Telefone)
                {
                    string SQL_telefone = string.Format(
                        "INSERT INTO TB_Telefone" +
                        "(Tel_DDI," +
                        "Tel_DDD," +
                        "Tel_Telefone," +
                        "ID_PessoaTel)" +
                        "values ('{0}','{1}','{2}','{3}')",
                        telefone.DDI,
                        telefone.DDD,
                        telefone.telefone,
                        id);

                    if (banco.ExecutarComandoSQL(SQL_telefone, trans) < 0)
                    {
                        Debug.WriteLine("Erro - Telefone de Motorista -> String : " + SQL_telefone);
                        trans.Rollback();
                        return(false);
                    }
                    else
                    {
                        Debug.WriteLine("OK - Telefone de Motorista -> String : " + SQL_telefone);
                    }
                }

                string SQL_motorista = string.Format(
                    "INSERT INTO TB_Motorista" +
                    "(CNH," +
                    "ID_PessoaM," +
                    "ID_EmpresaM)" +
                    "values ('{0}','{1}','{2}')",
                    m.cnh,
                    id,
                    m.empresa.ID);

                if (banco.ExecutarComandoSQL(SQL_motorista, trans) < 0)
                {
                    Debug.WriteLine("Erro - Tebela Motorista -> String : " + SQL_motorista);
                    trans.Rollback();
                    return(false);
                }
                else
                {
                    Debug.WriteLine("OK - Tebela Motorista -> String : " + SQL_motorista);
                }

                //CASO NADA DE ERRADO EM NENHUMA DAS EXECUÇÕES DOS COMANDOS SQL, SERÁ DADO O COMMIT.
                trans.Commit();
                Debug.WriteLine("OK - Motorista");

                return(true);
            }
            catch (SqlException e)
            {
                //SE ALGO DER ERRADO EM ALGUMA DAS INSERÇÕES, SERÁ DADO O ROLLBACK,ONDE VOLTARA AO SEU ESTADO ANTERIOR
                trans.Rollback();

                Debug.Write("Erro - Funcionario" + e);
                return(false);
            }
            finally
            {
                banco.FecharConexao();
            }
        }