示例#1
0
        public void SalvarObjeto(GerenciadorFinanceiro.Dominio.DespesaCombustivel objeto)
        {
            string sSqlInsert = "insert into TB_Despesa_Combustivel (IdVeiculo, KmInicial, KmFinal, QtdLitros, " +
                                "ValorTotal, TipoCombustivel, DataAbastecimento) " +
                                "values (@IdVeiculo, @KmInicial, @KmFinal, @QtdLitros, @Valor, @Combustivel, @DataAbastecimento)";

            try
            {
                Conection.AbrirConexao();
                Conection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
                Conection.Execute(sSqlInsert, objeto.Veiculo.IdVeiculo, objeto.KmInicial, objeto.KmFinal,
                                  objeto.QtdLitros, objeto.ValorTotal, objeto.Combustivel, objeto.DataAbastecimento);
                objeto.IdDespesaCombustivel = Convert.ToInt32(Conection.ExecuteScalar("select @@Identity"));
                Conection.Commit();
            }
            catch (Exception ex)
            {
                Conection.Rollback();
                throw new Exception("Não foi possível Salvar as Despesas de combustivel.", ex);
            }
            finally
            {
                Conection.FecharConexao();
            }
        }
示例#2
0
        public void SalvarObjeto(GerenciadorFinanceiro.Dominio.Categoria objeto)
        {
            string sSqlInsert = "insert into TB_Categoria (Descricao, IdCentroCusto) values (@Descricao, @idCusto)";

            try
            {
                Conection.AbrirConexao();
                Conection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
                Conection.Execute(sSqlInsert, objeto.Descricao, objeto.CategoriaPai.Id);
                objeto.Id = Convert.ToInt32(Conection.ExecuteScalar("Select @@Identity"));
                Conection.Commit();
            }
            catch (Exception ex)
            {
                Conection.Rollback();
                throw new Exception("Não foi possível salvar a Categoria.", ex);
            }
            finally
            {
                Conection.FecharConexao();
            }
        }