private void processCurrencyDB(SqlConnection cnn) { TasaCambioSBO oTasaCambioSBO = new TasaCambioSBO(); List <TasaCambioSBO> oTasasCambio = new List <TasaCambioSBO>(); DateTime Fecha = DateTime.Now; Dictionary <DateTime, Decimal> AuxDict = new Dictionary <DateTime, decimal>(); //String ApiKey = "c5656cd39657cf74083e0da48b1960e7963b4340"; String oSql; int diasAProcesar; // Validar definicion de monedas oSql = "SELECT CurrCode, CurrName , ISOCurrCod " + "FROM OCRN " + "WHERE Locked = 'N' "; var command = new SqlCommand(oSql, cnn); using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { DataTable dataTable = new DataTable(); dataTable.Load(reader); if (SBO_VID_Currency.Properties.Settings.Default.DiasAnterioresAProcesar > 0) { diasAProcesar = 0; } else { diasAProcesar = SBO_VID_Currency.Properties.Settings.Default.DiasAnterioresAProcesar; } oLog.LogMsg("Dias a procesar : " + diasAProcesar, "F", "D"); for (int x = diasAProcesar; x <= 1; x++) { Fecha = Fecha.AddDays(x); string dateFormat = Fecha.ToString("yyyy-MM-dd"); oLog.LogMsg("Dia: " + dateFormat, "F", "D"); string url = SBO_VID_Currency.Properties.Settings.Default.WEBPage; string responseRest = restGETWhitParameter(url, dateFormat); if (responseRest != "[]") { var listTC = JsonConvert.DeserializeObject <List <TC> >(responseRest); foreach (DataRow drow in dataTable.Rows) //monedas en SAP { string moneda = System.Convert.ToString(drow["CurrCode"]); string monedaISO = System.Convert.ToString(drow["ISOCurrCod"]); for (int y = 0; y < listTC.Count; y++) { if (moneda == listTC[y].codigo) { oLog.LogMsg("procesar por CurrCode: " + Fecha + " Currency: " + moneda, "F", "D"); UpdateSBOSAPBD(ref cnn, Fecha, (Double)listTC[y].valor, moneda); y = listTC.Count; } else { if (monedaISO == listTC[y].codigo) { oLog.LogMsg("procesar por ISOCurrCod: " + Fecha + " Currency: " + moneda, "F", "D"); UpdateSBOSAPBD(ref cnn, Fecha, (Double)listTC[y].valor, moneda); y = listTC.Count; } } } } } Fecha = DateTime.Now; } } } }
/// <summary> /// carga los valores que se encuentra en el Webservice /// </summary> /// <param name="oCompany"></param> private void deployCurrency(SAPbobsCOM.Company oCompany) { SAPbobsCOM.Recordset oRS = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); SAPbobsCOM.SBObob pSBObob = (SAPbobsCOM.SBObob)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge); TasaCambioSBO oTasaCambioSBO = new TasaCambioSBO(); List <TasaCambioSBO> oTasasCambio = new List <TasaCambioSBO>(); DateTime Fecha = DateTime.Now; Dictionary <DateTime, Decimal> AuxDict = new Dictionary <DateTime, decimal>(); String oSql; int diasAProcesar; // Validar definicion de monedas if (oCompany.DbServerType == SAPbobsCOM.BoDataServerTypes.dst_HANADB) { oSql = @"SELECT ""CurrCode"", ""CurrName"" , ""ISOCurrCod"" , ""DocCurrCod"" FROM ""OCRN"" WHERE ""Locked"" = 'N' "; } else { oSql = "SELECT CurrCode, CurrName , ISOCurrCod , DocCurrCod " + "FROM OCRN " + "WHERE Locked = 'N' "; } oRS.DoQuery(oSql); if (oRS.RecordCount > 0) { if (SBO_VID_Currency.Properties.Settings.Default.DiasAnterioresAProcesar > 0) { diasAProcesar = 0; } else { diasAProcesar = SBO_VID_Currency.Properties.Settings.Default.DiasAnterioresAProcesar; } oLog.LogMsg("Dias a procesar : " + diasAProcesar, "F", "D"); for (int x = diasAProcesar; x <= 1; x++) { Fecha = Fecha.AddDays(x); string dateFormat = Fecha.ToString("yyyy-MM-dd"); oLog.LogMsg("Dia: " + dateFormat, "F", "D"); string url = SBO_VID_Currency.Properties.Settings.Default.WEBPage; string responseRest = restGETWhitParameter(url, dateFormat); if (responseRest != "[]") { var listTC = JsonConvert.DeserializeObject <List <TC> >(responseRest); for (int i = 0; i < oRS.RecordCount; i++) //Monedas en SAP { string moneda = ((System.String)oRS.Fields.Item("CurrCode").Value).Trim(); string monedaISO = ((System.String)oRS.Fields.Item("ISOCurrCod").Value).Trim(); string monedaInternacional = ((System.String)oRS.Fields.Item("DocCurrCod").Value).Trim(); for (int y = 0; y < listTC.Count; y++) { if (moneda == listTC[y].codigo) { oLog.LogMsg("procesado por CurrCode: " + Fecha + " Currency: " + moneda, "F", "D"); UpdateSBOSAP(ref oCompany, Fecha, (Double)listTC[y].valor, ref pSBObob, moneda); y = listTC.Count; } else { if (monedaISO == listTC[y].codigo) { oLog.LogMsg("procesado por ISOCurrCod: " + Fecha + " Currency: " + monedaISO, "F", "D"); UpdateSBOSAP(ref oCompany, Fecha, (Double)listTC[y].valor, ref pSBObob, moneda); y = listTC.Count; } else { if (monedaInternacional == listTC[y].codigo) { oLog.LogMsg("procesado por DocCurrCod: " + Fecha + " Currency: " + monedaInternacional, "F", "D"); UpdateSBOSAP(ref oCompany, Fecha, (Double)listTC[y].valor, ref pSBObob, moneda); y = listTC.Count; } } } } oRS.MoveNext(); } oRS.MoveFirst(); } Fecha = DateTime.Now; } } }