コード例 #1
0
        public EMunicipios Municipios_Update(EMunicipios item, ref ETransactionResult _transResult)
        {
            EMunicipios itemUpdated = null;

            _transResult = new ETransactionResult();
            SqlTransaction transaction = null;

            try
            {
                using (SqlConnection sqlCon = new SqlConnection(conn))
                {
                    sqlCon.Open();
                    using (SqlCommand sqlCmd = new SqlCommand())
                    {
                        transaction        = sqlCon.BeginTransaction("UpdateTransaction");
                        sqlCmd.Transaction = transaction;
                        sqlCmd.Connection  = sqlCon;
                        sqlCmd.CommandType = CommandType.StoredProcedure;
                        sqlCmd.CommandText = "SP_Municipios_Update";
                        sqlCmd.Parameters.AddWithValue("@Id", item.Id);
                        sqlCmd.Parameters.AddWithValue("@IdEstado", item.IdEstado);
                        sqlCmd.Parameters.AddWithValue("@descripcion", item.descripcion);
                        using (var reader = sqlCmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                itemUpdated             = new EMunicipios();
                                itemUpdated.Id          = (int)reader["Id"];
                                itemUpdated.IdEstado    = (int)reader["IdEstado"];
                                itemUpdated.descripcion = reader["descripcion"] == DBNull.Value ? null : (string)reader["descripcion"];
                            }
                        }
                        transaction.Commit();
                        _transResult.message = "OK";
                        _transResult.result  = 1;
                    }
                }
            }
            catch (Exception ex)
            {
                _transResult.message = ex.Message;
                _transResult.result  = 1;
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollBackEx)
                {
                    _transResult.rollbackMessage = rollBackEx.Message;
                    _transResult.result          = 1;
                }
            }
            return(itemUpdated);
        }
コード例 #2
0
        public List <EMunicipios> Municipios_GetAll(ref ETransactionResult _transResult)
        {
            var list = new List <EMunicipios>();

            _transResult = new ETransactionResult();
            SqlTransaction transaction = null;

            try
            {
                using (SqlConnection sqlCon = new SqlConnection(conn))
                {
                    sqlCon.Open();
                    using (SqlCommand sqlCmd = new SqlCommand())
                    {
                        transaction        = sqlCon.BeginTransaction("SelectAllTranstaction");
                        sqlCmd.Transaction = transaction;
                        sqlCmd.Connection  = sqlCon;
                        sqlCmd.CommandType = CommandType.StoredProcedure;
                        sqlCmd.CommandText = "SP_Municipios_SelectAll";
                        using (var reader = sqlCmd.ExecuteReader())
                            while (reader.Read())
                            {
                                var item = new EMunicipios();
                                item.Id          = (int)reader["Id"];
                                item.IdEstado    = (int)reader["IdEstado"];
                                item.descripcion = reader["descripcion"] == DBNull.Value ? null : (string)reader["descripcion"];
                                list.Add(item);
                            }
                        transaction.Commit();
                        _transResult.message = "OK";
                        _transResult.result  = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                _transResult.message = ex.Message;
                _transResult.result  = 1;
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollBackEx)
                {
                    _transResult.rollbackMessage = rollBackEx.Message;
                    _transResult.result          = 1;
                }
            }
            return(list);
        }
コード例 #3
0
        public void Municipios_Delete(EMunicipios item, ref ETransactionResult _transResult)
        {
            _transResult = new ETransactionResult();
            SqlTransaction transaction = null;

            try
            {
                using (SqlConnection sqlCon = new SqlConnection(conn))
                {
                    sqlCon.Open();
                    using (SqlCommand sqlCmd = new SqlCommand())
                    {
                        transaction        = sqlCon.BeginTransaction("DeleteTransaction");
                        sqlCmd.Transaction = transaction;
                        sqlCmd.Connection  = sqlCon;
                        sqlCmd.CommandType = CommandType.StoredProcedure;
                        sqlCmd.CommandText = "SP_Municipios_Delete";
                        sqlCmd.Parameters.AddWithValue("@Id", item.Id);
                        sqlCmd.Parameters.AddWithValue("@IdEstado", item.IdEstado);
                        sqlCmd.ExecuteNonQuery();
                        transaction.Commit();
                        _transResult.message = "OK";
                        _transResult.result  = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                _transResult.message = ex.Message;
                _transResult.result  = 1;
                try
                {
                    transaction.Rollback();
                }
                catch (Exception rollBackEx)
                {
                    _transResult.rollbackMessage = rollBackEx.Message;
                    _transResult.result          = 1;
                }
            }
        }