/// <summary> /// ObterListaIndicesGradual - busca lista de índices Gradual /// </summary> /// <returns></returns> public List <IndiceGradual.ItemIndice> ObterListaIndicesGradual() { List <IndiceGradual.ItemIndice> listaIndice = new List <IndiceGradual.ItemIndice>(); SqlConnection conn = null; try { conn = new SqlConnection(ConfigurationManager.AppSettings["OMSProducao"]); conn.Open(); SqlCommand Command = new SqlCommand(); Command.CommandType = CommandType.StoredProcedure; Command.Connection = conn; Command.CommandText = "prc_tbCotacaoIndice_lst"; SqlDataReader dtDados = Command.ExecuteReader(); if (dtDados.HasRows) { while (dtDados.Read()) { IndiceGradual.ItemIndice item = new IndiceGradual.ItemIndice(); item.indice = dtDados.GetSqlString(1).Value; item.codigoIndice = dtDados.IsDBNull(0) ? 0 : dtDados.GetInt32(0); item.cotacaoAtual = dtDados.IsDBNull(2) ? 0 : dtDados.GetSqlDecimal(2).ToDouble(); item.fechamentoAnterior = dtDados.IsDBNull(3) ? 0 : dtDados.GetSqlDecimal(3).ToDouble(); item.variacao = dtDados.IsDBNull(4) ? 0 : dtDados.GetSqlDecimal(4).ToDouble(); item.dataCotacao = dtDados.IsDBNull(5) ? new DateTime(1970, 1, 1) : dtDados.GetDateTime(5); listaIndice.Add(item); } } } catch (SqlException ex) { logger.Error("ObterListaIndicesGradual(): " + ex.Message + "-" + ex.ErrorCode, ex); } catch (Exception ex) { logger.Error("ObterListaIndicesGradual(): " + ex.Message, ex); } finally { if (conn != null && conn.State == ConnectionState.Open) { conn.Close(); conn.Dispose(); } } return(listaIndice); }
/// <summary> /// AtualizarComposicaoIndiceGradual - atualiza item na tabela tbIndiceGradual. /// </summary> /// <returns></returns> public void AtualizarCotacaoIndice(IndiceGradual.ItemIndice item) { SqlConnection conn = null; try { conn = new SqlConnection(ConfigurationManager.AppSettings["OMSProducao"]); conn.Open(); SqlCommand Command = new SqlCommand(); Command.CommandType = CommandType.StoredProcedure; Command.Connection = conn; Command.CommandText = "prc_tbCotacaoIndice_ins"; Command.Parameters.AddWithValue("@dsIndice", item.indice); Command.Parameters.AddWithValue("@CotacaoAtual", item.cotacaoAtual); Command.Parameters.AddWithValue("@FechAnterior", item.fechamentoAnterior); Command.Parameters.AddWithValue("@Variacao", item.variacao); Command.Parameters.AddWithValue("@dtCotacao", item.dataCotacao); Command.ExecuteNonQuery(); Command.Dispose(); } catch (SqlException ex) { logger.Error("AtualizarCotacaoIndice(): " + ex.Message + "-" + ex.ErrorCode, ex); } catch (Exception ex) { logger.Error("AtualizarCotacaoIndice(): " + ex.Message, ex); } finally { if (conn != null && conn.State == ConnectionState.Open) { conn.Close(); conn.Dispose(); } } }