public void AtualizarDados(string Usuario, string Senha) { string Extract(string s, string tag) { var startTag = "<" + tag + ">"; int startIndex = s.IndexOf(startTag) + startTag.Length; int endIndex = s.IndexOf("</" + tag + ">", startIndex); if (endIndex - startIndex < 0) { return(""); } else { return(s.Substring(startIndex, endIndex - startIndex)); } } Dictionary <string, decimal> CotasBase = CotasCompleto().ToDictionary(Key => Key.CODFUND.ToString() + Key.DATA.ToString("ddMMyyyy"), Value => Value.COTA); List <long> Fundos = new BL_FIQ().Dados().Select(x => x.CODFUND).ToList(); Fundos.AddRange(new BL_Master().Dados().Select(X => X.CODFUND)); string[] linhas; try { linhas = new DownloadArquivoServiceService().cotacaoXML(Usuario, Senha, "991259").Split(Convert.ToChar("\n")); } catch { linhas = new string[0]; } for (int i = 0; i < linhas.Length; i++) { if (linhas[i].Length > 13 && (linhas[i].Contains("</CDFDO>"))) { BL_Cota CotaNew = new BL_Cota { CODFUND = Convert.ToInt64(Extract(linhas[i], "CDFDO")), DATA = DateTime.ParseExact(Extract(linhas[i + 1], "DTAPROCE"), "yyyyMMdd", CultureInfo.InvariantCulture), COTA = Convert.ToDecimal(Extract(linhas[i + 2], "VLCOTAP")) / 10000000, }; if (!Fundos.Contains(CotaNew.CODFUND)) { continue; } if (CotasBase.Keys.Contains(CotaNew.KEY)) { if (CotasBase[CotaNew.KEY] != CotaNew.COTA) { Editar(CotaNew.CODFUND, CotaNew.DATA, CotaNew.COTA); } } else { Inserir(CotaNew.CODFUND, CotaNew.DATA, CotaNew.COTA); } } } }
public void ImportaCSV(string DADOS) { Dictionary <string, decimal> CotasBase = CotasCompleto().ToDictionary(Key => Key.CODFUND.ToString() + Key.DATA.ToString("ddMMyyyy"), Value => Value.COTA); List <long> Fundos = new BL_FIQ().Dados().Select(x => x.CODFUND).ToList(); Fundos.AddRange(new BL_Master().Dados().Select(X => X.CODFUND)); string[] linhas; try { linhas = DADOS.Split(Convert.ToChar("\n")); } catch { linhas = new string[0]; } for (int i = 0; i < linhas.Length; i++) { BL_Cota CotaNew = new BL_Cota { CODFUND = Convert.ToInt64(linhas[i].Split(';')[0]), DATA = Convert.ToDateTime(linhas[i].Split(';')[1]), COTA = Convert.ToDecimal(linhas[i].Split(';')[2]) }; if (!Fundos.Contains(CotaNew.CODFUND)) { continue; } if (CotasBase.Keys.Contains(CotaNew.KEY)) { if (CotasBase[CotaNew.KEY] != CotaNew.COTA) { Editar(CotaNew.CODFUND, CotaNew.DATA, CotaNew.COTA); } } else { Inserir(CotaNew.CODFUND, CotaNew.DATA, CotaNew.COTA); } } }
//Métodos de Dados #region public void AtualizarDados(string Usuario, string Senha) { string Extract(string s, string tag) { var startTag = "<" + tag + ">"; int startIndex = s.IndexOf(startTag) + startTag.Length; int endIndex = s.IndexOf("</" + tag + ">", startIndex); if (endIndex - startIndex < 0) { return(""); } else { return(s.Substring(startIndex, endIndex - startIndex)); } } List <long> Fundos = new BL_FIQ().Dados().Select(x => x.CODFUND).ToList(); Fundos.AddRange(new BL_Master().Dados().Select(X => X.CODFUND)); string[] linhas; linhas = new DownloadArquivoServiceService().saldosCotaFechamentoD0XMLNoZIP(Usuario, Senha, "991259").Split(Convert.ToChar("\n")); //Deletar(); List <BL_Saldo> Saldos = new BL_Saldo().DadosCompletos(); for (int i = 0; i < linhas.Length; i++) { if (linhas[i].Contains("</CDFDO>")) { BL_Saldo Saldo; long CAUTELA_Aux = Convert.ToInt64(Extract(linhas[i + 9], "CDAPL")); string CODAUX = Extract(linhas[i + 2], "AGENCIA") + Extract(linhas[i + 3], "CDCTA") + Extract(linhas[i + 4], "DAC10"); long CODCOT_Aux = Convert.ToInt64(CODAUX); long CODFUND_Aux = Convert.ToInt64(Extract(linhas[i], "CDFDO")); decimal QNTCOTAS_Aux = Convert.ToDecimal(Extract(linhas[i + 14], "QTCOTPAT")) / 100000; string TIPOREGISTRO_Aux = Extract(linhas[i + 8], "IDTIPREG") == "20" ? "Simples" : "Total"; //DateTime DATACOTA_Aux = DateTime.ParseExact(Extract(linhas[i + 16], "DTACOTA"), "yyyyMMdd", CultureInfo.InvariantCulture); //decimal COTA_Aux = Convert.ToDecimal(Extract(linhas[i + 17], "VLRCOT")) / 10000000; if (CAUTELA_Aux != 0) { Saldo = Saldos.FirstOrDefault(x => x.CAUTELA == CAUTELA_Aux); } else { Saldo = Saldos.FirstOrDefault(x => x.CODCOT == CODCOT_Aux && x.CODFUND == CODFUND_Aux && x.TIPOREGISTRO == "Total"); } if (Saldo == null) //Inserir nova linha { DateTime DTLANCT_Aux; if (TIPOREGISTRO_Aux == "Simples") { DTLANCT_Aux = DateTime.ParseExact(Extract(linhas[i + 6], "DTLANCT"), "yyyyMMdd", CultureInfo.InvariantCulture); } else { DTLANCT_Aux = new DateTime(1753, 1, 1); } decimal VLCOTAP_Aux = Convert.ToDecimal(Extract(linhas[i + 11], "VLCOTAP")) / 10000000; Inserir(CODCOT_Aux, CODFUND_Aux, DTLANCT_Aux, VLCOTAP_Aux, TIPOREGISTRO_Aux, CAUTELA_Aux, QNTCOTAS_Aux); continue; } if (TIPOREGISTRO_Aux == "Simples" && (CODCOT_Aux != Saldo.CODCOT || CODFUND_Aux != Saldo.CODFUND || QNTCOTAS_Aux != Saldo.QNTCOTAS)) { EditarSimples(CODCOT_Aux, CODFUND_Aux, TIPOREGISTRO_Aux, CAUTELA_Aux, QNTCOTAS_Aux); } if (TIPOREGISTRO_Aux == "Total" && (QNTCOTAS_Aux != Saldo.QNTCOTAS)) { EditarTotal(CODCOT_Aux, CODFUND_Aux, QNTCOTAS_Aux); } Saldos.Remove(Saldo); } } foreach (BL_Saldo Resto in Saldos) { if (Resto.TIPOREGISTRO == "Simples") { DeletarSimples(Resto.CAUTELA); } else if (Resto.TIPOREGISTRO == "Total") { DeletarTotal(Resto.CODCOT, Resto.CODFUND); } } linhas = null; }