public eTipoCambio TipoDeCambio_Select(DateTime fecha_tipoCambio) { SqlCommand cmd = new SqlCommand("usp_tb_tipoDeCambioSelect"); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@fecha_tipoCambio", SqlDbType.DateTime).Value = fecha_tipoCambio; SqlDataReader reader = ExecuteReader(cmd); eTipoCambio oTipoCambio = null; if (reader.Read()) { oTipoCambio = new eTipoCambio(); oTipoCambio.FechaTipoCambio = reader.GetDateTime(0); oTipoCambio.ValorTipoCambio = reader.GetDecimal(1); } reader.Close(); return(oTipoCambio); }
public void ObtenerTipoDeCambio() { try { GridView grvListado = new GridView(); WSEParts.ServiciosEparts ws = new WSEParts.ServiciosEparts(); ws.Url = ConfigurationManager.AppSettings["WS_EParts"].ToString(); string fechaDesde = DateTime.Today.AddDays(-4).ToShortDateString(); string fechaHasta = DateTime.Today.ToShortDateString(); dia = Convert.ToInt32(fechaDesde.Substring(0, 2)); mes = Convert.ToInt32(fechaDesde.Substring(3, 2)); año = Convert.ToInt32(fechaDesde.Substring(6, 4)); fechaDesde = año.ToString() + mes.ToString() + dia.ToString(); dia = Convert.ToInt32(fechaHasta.Substring(0, 2)); mes = Convert.ToInt32(fechaHasta.Substring(3, 2)); año = Convert.ToInt32(fechaHasta.Substring(6, 4)); fechaHasta = año.ToString() + mes.ToString() + dia.ToString(); object tipoCambio = ws.Tipo_Cambio(WS_Clave, fechaDesde, fechaHasta); string myXMLfile = tipoCambio.ToString(); myXMLfile = myXMLfile.Replace("\n", ""); XmlDocument xm = new XmlDocument(); xm.LoadXml(myXMLfile); XmlNodeReader reader = new XmlNodeReader(xm); DataSet dataSet = new DataSet(); dataSet.ReadXml(reader); grvListado.DataSource = dataSet; grvListado.DataBind(); List <eTipoCambio> lTipoCambioOld = new List <eTipoCambio>(); List <eTipoCambio> lTipoCambio = new List <eTipoCambio>(); int contador = 0; foreach (GridViewRow row in grvListado.Rows) { string fechaSinTrabajar = row.Cells[0].Text; if (fechaSinTrabajar != "19970000") { año = Convert.ToInt32(fechaSinTrabajar.Substring(0, 2)); mes = Convert.ToInt32(fechaSinTrabajar.Substring(4, 2)); dia = Convert.ToInt32(fechaSinTrabajar.Substring(6, 2)); fechaTrabajada = año + "/" + mes + "/" + dia; DateTime fecha = DateTime.Parse(fechaTrabajada); string valor = row.Cells[1].Text; eTipoCambio oTipoCambio = new eTipoCambio(); oTipoCambio.FechaTipoCambio = Convert.ToDateTime(fecha); oTipoCambio.ValorTipoCambio = Convert.ToDecimal(valor); eTipoCambio oTipoCambioOld = cCMS.TipoDeCambio_Select(oTipoCambio.FechaTipoCambio); if (oTipoCambioOld != null) { cCMS.TipoDeCambio_updateCadaUno(oTipoCambio.FechaTipoCambio, oTipoCambio.ValorTipoCambio); lTipoCambioOld.Add(oTipoCambioOld); } else { cCMS.TipoDeCambio_Add(oTipoCambio); lTipoCambio.Add(oTipoCambio); } } contador++; } string xmlOriginal = Util.XML.SerializeObject(lTipoCambio, new System.Xml.Serialization.XmlSerializer(typeof(List <eTipoCambio>))); string xmlModificado = Util.XML.SerializeObject(lTipoCambioOld, new System.Xml.Serialization.XmlSerializer(typeof(List <eTipoCambio>))); RegistrarLogWS(LOG_TIPO_CAMBIO, "WS Tipo de Cambio: " + contador + " actualizados", xmlOriginal, xmlModificado); } catch (Exception ex) { RegistrarLogWS(LOG_TIPO_CAMBIO, "WS Tipo de Cambio (Error): " + ex.Message); } }