protected void UpSubirCalendario_FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) { try { if (UpSubirCalendario.UploadedFiles != null && UpSubirCalendario.UploadedFiles.Length > 0) { int validarExiste = 0; LogicaNegocio ln = new LogicaNegocio(); //var dt = new DataTable(); //var a = Path.Combine(AppDomain.CurrentDomain.BaseDirectory); //var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "File1.xlsx"); //var query = "SELECT * C FROM [Hoja1$]"; //using (OleDbConnection cn = new OleDbConnection { ConnectionString = ConnectionString(fileName, "No") }) //{ // using (OleDbCommand cmd = new OleDbCommand { CommandText = query, Connection = cn }) // { // cn.Open(); // OleDbDataReader dr = cmd.ExecuteReader(); // dt.Load(dr); // } //} //if (dt.Rows.Count > 1) //{ // // remove header // dt.Rows[0].Delete(); //} //dt.AcceptChanges(); // //DataRow dr = new DataRow(); string MonedaCertificado = string.Empty; var dtCsv = util.CSVtoDataTable(e.UploadedFile, ";"); for (var i = 0; i < dtCsv.Rows.Count - 1; i++) { var NroCertificado = dtCsv.Rows[i]["NCertificado"].ToString().Trim(); if (string.IsNullOrEmpty(NroCertificado.ToString())) { throw new Exception("El numero de certificado no puede estar vacio, linea " + i); } //validar si existe nro certificado en tabla calendario pago if (i > 0) { if (NroCertificado != dtCsv.Rows[i - 1]["NCertificado"].ToString().Trim()) { validarExiste = ln.CP_VerificarCertificado(NroCertificado); //if(validarExiste != 0) // throw new Exception("El número de certificado ya existe en la tabla calendario de pago, linea " + i); } } else { validarExiste = ln.CP_VerificarCertificado(NroCertificado); } if (validarExiste != 0) { throw new Exception("El número de certificado ya existe en la tabla calendario de pago, linea " + i); } var NroCredito = dtCsv.Rows[i]["NCredito"].ToString().Trim(); if (string.IsNullOrEmpty(NroCredito.ToString())) { throw new Exception("El numero de credito no puede estar vacio, linea " + i); } var CuotaNro = dtCsv.Rows[i]["CuotaN"].ToString().Trim(); if (string.IsNullOrEmpty(CuotaNro.ToString())) { throw new Exception("El numero de cuota no puede estar vacio, linea " + i); } var NroCuotas = dtCsv.Rows[i]["NCuota"].ToString().Trim(); if (string.IsNullOrEmpty(NroCuotas.ToString())) { throw new Exception("El total de cuotas no puede estar vacio, linea " + i); } var FechaVencimiento = dtCsv.Rows[i]["FechaVencimiento"].ToString().Trim(); if (string.IsNullOrEmpty(FechaVencimiento.ToString())) { throw new Exception("La fecha de vencimiento no puede estar vacia, linea " + i); } var ValorCuota = dtCsv.Rows[i]["MontoCuota"].ToString().Trim(); if (string.IsNullOrEmpty(ValorCuota.ToString())) { throw new Exception("El monto de la cuota no puede estar vacio, linea " + i); } var Capital = dtCsv.Rows[i]["Capital"].ToString().Trim(); if (string.IsNullOrEmpty(Capital.ToString())) { throw new Exception("El valor capital no puede estar vacio, linea " + i); } var Interes = dtCsv.Rows[i]["Interes"].ToString().Trim(); if (string.IsNullOrEmpty(Interes.ToString())) { throw new Exception("El valor Interes no puede estar vacio, linea " + i); } //double A = (util.GetValorDouble(Capital) + util.GetValorDouble(Interes)).Redondear(4); if ((Capital.GetValorDouble() + Interes.GetValorDouble()).Redondear(4) != ValorCuota.GetValorDouble().Redondear(4)) { throw new Exception("La suma de capital e interes es distinto del monto cuota, linea " + i); } var TipoMoneda = dtCsv.Rows[i]["Moneda"].ToString().Trim(); if (string.IsNullOrEmpty(TipoMoneda.ToString())) { throw new Exception("El valor Moneda no puede estar vacio, linea " + i); } if (i == 0) { MonedaCertificado = ln.CP_VerificarMonedaOperacion(dtCsv.Rows[i]["NCertificado"].ToString().Trim()); if (MonedaCertificado.ToLower().Trim() != dtCsv.Rows[i]["Moneda"].ToString().ToLower().Trim()) { throw new Exception("La moneda especificada en la operacion es distinta de la ingresada en el archivo excel"); } } } //validar texto capital inicial igual a sumatoria de capital double totalCapital = dtCsv.AsEnumerable().Sum(x => x["Capital"].ToString().GetValorDouble()); if (totalCapital.Redondear(4) != txtCapitalInicial.Text.Trim().GetValorDouble().Redondear(4)) { throw new Exception("el capital inicial ingresado debe ser igual a la sumatoria de la columna capital del excel"); } Page.Session["dtArchivo"] = dtCsv; gvPreCargaCP.DataSource = dtCsv; gvPreCargaCP.DataBind(); e.CallbackData = "OK"; } } catch (Exception ex) { e.CallbackData = ex.Message; } }
protected void UpSubirCC_FileUploadComplete(object sender, FileUploadCompleteEventArgs e) { try { if (e.IsValid) { int validarExiste = 0; LogicaNegocio Ln = new LogicaNegocio(); DataTable dtMotivo = new DataTable("dtMotivo"); DataTable dtCausa = new DataTable("dtCausa"); DataTable dtAcreedores = new DataTable("dtAcreedores"); DataTable dtConceptos = new DataTable("dtConceptos"); dtMotivo = Ln.ListarMotivos(); dtCausa = Ln.ListarCausas(); dtConceptos = Ln.ListarConceptos(); dtAcreedores = Ln.CRUDAcreedores(1, "", 0, "", "", 0, 0, 0, 0, ""); int BuscarMotivo = 0; int BuscarCausa = 0; int BuscarBanco = 0; int BuscarAcreedor = 0; int BuscarConcepto = 0; DataTable dtCsv = util.CSVtoDataTable(e.UploadedFile, ";"); dtCsv.CaseSensitive = false; foreach (DataColumn column in dtCsv.Columns) { column.ColumnName = column.ColumnName.ToLower().Trim(); } for (var i = 0; i < dtCsv.Rows.Count - 1; i++) { //n° cf string NroCertificado = dtCsv.Rows[i]["NCertificado"].ToString().Trim(); if (string.IsNullOrEmpty(NroCertificado)) { throw new Exception("El numero de certificado no puede estar vacio, linea " + (i + 1)); } validarExiste = Ln.CP_VerificarCertificado(NroCertificado); if (validarExiste == 0) { throw new Exception("El número de certificado no esta registrado, cft " + NroCertificado); } //motivo string Motivo = dtCsv.Rows[i]["Motivo"].ToString().Trim(); if (string.IsNullOrEmpty(Motivo)) { throw new Exception("El Motivo ingresado no puede estar vacío, linea " + (i + 1)); } BuscarMotivo = dtMotivo.Select("DescMotivo = '" + Motivo + "'").Length; if (BuscarMotivo <= 0) { throw new Exception("El motivo no existe en la parametrización, linea " + (i + 1)); } //causa string Causa = dtCsv.Rows[i]["Causa"].ToString().Trim(); if (string.IsNullOrEmpty(Causa)) { throw new Exception("La causa ingresada no puede estar vacía, linea " + (i + 1)); } string CausaExiste = string.Format("{0}", "DescCausa = '" + Causa + "'"); BuscarCausa = dtCausa.Select(CausaExiste).Length; if (BuscarCausa <= 0) { throw new Exception("La causa no existe en la parametrización, linea " + (i + 1)); } //concepto string Concepto = dtCsv.Rows[i]["Concepto"].ToString().Trim(); if (string.IsNullOrEmpty(Concepto)) { throw new Exception("el concepto ingresado no puede estar vacío, linea " + (i + 1)); } string ConceptoExiste = string.Format("{0}", "Concepto = '" + Concepto + "'"); BuscarConcepto = dtConceptos.Select(ConceptoExiste).Length; if (BuscarConcepto <= 0) { throw new Exception("El concepto ingresado no existe en la parametrización de conceptos, linea " + (i + 1)); } //fecha cobro string FechaCobro = dtCsv.Rows[i]["FechaCobro"].ToString().Trim(); if (string.IsNullOrEmpty(FechaCobro)) { throw new Exception("La fecha de cobro no puede estar vacia, linea " + (i + 1)); } //fecha pago string FechaPago = dtCsv.Rows[i]["FechaPago"].ToString().Trim(); if (string.IsNullOrEmpty(FechaPago)) { throw new Exception("La Fecha de Pago no puede estar vacía, linea " + (i + 1)); } //banco string banco = System.Web.HttpUtility.HtmlDecode(dtCsv.Rows[i]["Banco"].ToString().Trim()); if (string.IsNullOrEmpty(banco)) { throw new Exception("El banco no puede estar vacio o ser cero, linea " + (i + 1)); } //string BancoExiste = string.Format("{0}", "NombreFinanzas = '" + banco.ToUpper() + "'"); //BuscarBanco = dtAcreedores.Select(BancoExiste).Length; //if (BuscarBanco <= 0) // throw new Exception("El banco no existe en la parametrización, linea " + (i + 1)); //monto string Monto = dtCsv.Rows[i]["Monto"].ToString().Trim(); if (string.IsNullOrEmpty(Monto) || Monto == "0") { throw new Exception("El Monto no puede estar vacio o ser cero, linea " + (i + 1)); } dtCsv.Rows[i]["Monto"] = (dtCsv.Rows[i]["Monto"]).ToString().GetFormatearNumero(0); //acreedor string Acreedor = dtCsv.Rows[i]["Acreedor"].ToString().Trim(); if (string.IsNullOrEmpty(Acreedor)) { throw new Exception("El acreedor no puede estar vacio, linea " + (i + 1)); } string AcreedorExiste = string.Format("{0}", "NombreFinanzas = '" + Acreedor.ToUpper() + "'"); BuscarAcreedor = dtAcreedores.Select(AcreedorExiste).Length; if (BuscarAcreedor <= 0) { throw new Exception("El acreedor no existe en la parametrización, linea " + (i + 1)); } } Page.Session["dtArchivo"] = dtCsv; e.CallbackData = "OK"; } else { throw new Exception("Error de archivo"); } } catch (Exception ex) { e.CallbackData = ex.Message; } }
protected void UpSubirMasivo_FileUploadComplete(object sender, FileUploadCompleteEventArgs e) { try { if (e.IsValid) { int validarExiste = 0; LogicaNegocio ln = new LogicaNegocio(); DataTable dtMotivo = new DataTable("dtMotivo"); DataTable dtCausa = new DataTable("dtCausa"); DataTable dtAcreedores = new DataTable("dtAcreedores"); dtMotivo = ln.ListarMotivos(); dtCausa = ln.ListarCausas(); dtAcreedores = ln.CRUDAcreedores(1, "", 0, "", "", 0, 0, 0, 0, ""); int BuscarMotivo = 0; int BuscarCausa = 0; int BuscarBanco = 0; int BuscarAcreedor = 0; var dtCsv = util.CSVtoDataTable(e.UploadedFile, ";"); for (var i = 0; i < dtCsv.Rows.Count - 1; i++) { var NroCertificado = dtCsv.Rows[i]["NCertificado"].ToString().Trim(); if (string.IsNullOrEmpty(NroCertificado.ToString())) { throw new Exception("El numero de certificado no puede estar vacio, linea " + (i + 1)); } //validar si existe nro certificado en tabla operacion validarExiste = ln.CP_VerificarCertificado(NroCertificado); if (validarExiste == 0) { throw new Exception("El número de certificado no esta registrado, linea " + (i + 1)); } //result = dt.Select("IdCalendario = '" + idCalendario.ToString() + "'"); var Motivo = dtCsv.Rows[i]["Motivo"].ToString().Trim(); if (string.IsNullOrEmpty(Motivo.ToString())) { throw new Exception("El Motivo ingresado no puede estar vacío, linea " + (i + 1)); } //string MotivoExiste = string.Format("{0}{1}", "DescMotivo = ", Motivo.ToString()); BuscarMotivo = dtMotivo.Select("DescMotivo = '" + Motivo.ToString() + "'").Length; if (BuscarMotivo <= 0) { throw new Exception("El motivo no existe en la parametrización, linea " + (i + 1)); } var Causa = dtCsv.Rows[i]["Causa"].ToString().Trim(); if (string.IsNullOrEmpty(Causa.ToString())) { throw new Exception("La causa ingresada no puede estar vacía, linea " + (i + 1)); } string CausaExiste = string.Format("{0}", "DescCausa = '" + Causa + "'"); BuscarCausa = dtCausa.Select(CausaExiste).Length; if (BuscarCausa <= 0) { throw new Exception("La causa no existe en la parametrización, linea " + (i + 1)); } var FechaCobro = dtCsv.Rows[i]["FechaCobro"].ToString().Trim(); if (string.IsNullOrEmpty(FechaCobro.ToString())) { throw new Exception("La fecha de cobro no puede estar vacia, linea " + (i + 1)); } var FechaPago = dtCsv.Rows[i]["FechaPago"].ToString().Trim(); if (string.IsNullOrEmpty(FechaPago.ToString())) { throw new Exception("La Fecha de Pago no puede estar vacía, linea " + (i + 1)); } var banco = dtCsv.Rows[i]["Banco"].ToString().Trim(); if (string.IsNullOrEmpty(banco)) { throw new Exception("El banco no puede estar vacio o ser cero, linea " + (i + 1)); } //var query = dtAcreedores.AsEnumerable().Where(r => r.Field<string>("NombreFinanzas").Contains(banco.ToUpper())).ToList(); string BancoExiste = string.Format("{0}", "NombreFinanzas = '" + banco.ToUpper() + "'"); BuscarBanco = dtAcreedores.Select(BancoExiste).Length; if (BuscarBanco <= 0) { throw new Exception("El banco no existe en la parametrización, linea " + (i + 1)); } var Monto = dtCsv.Rows[i]["Monto"].ToString().Trim(); if (string.IsNullOrEmpty(Monto.ToString()) || Monto.ToString() == "0") { throw new Exception("El Monto no puede estar vacio o ser cero, linea " + (i + 1)); } dtCsv.Rows[i]["Monto"] = util.actualizaMilesSinDecimal(dtCsv.Rows[i]["Monto"].ToString()); var Acreedor = dtCsv.Rows[i]["Acreedor"].ToString().Trim(); if (string.IsNullOrEmpty(Acreedor.ToString())) { throw new Exception("El acreedor no puede estar vacio, linea " + (i + 1)); } string AcreedorExiste = string.Format("{0}", "NombreFinanzas = '" + Acreedor.ToUpper() + "'"); BuscarAcreedor = dtAcreedores.Select(AcreedorExiste).Length; if (BuscarAcreedor <= 0) { throw new Exception("El acreedor no existe en la parametrización, linea " + (i + 1)); } } Page.Session["dtArchivo"] = dtCsv; e.CallbackData = "OK"; } else { throw new Exception("Error de archivo"); } } catch (Exception ex) { e.CallbackData = ex.Message; } }
protected void UpSubirMasivo_FileUploadComplete(object sender, FileUploadCompleteEventArgs e) { try { if (UpSubirMasivo.UploadedFiles != null && UpSubirMasivo.UploadedFiles.Length > 0) { int validarExiste = 0; LogicaNegocio ln = new LogicaNegocio(); DataTable dtMotivo = new DataTable("dtMotivo"); DataTable dtCausa = new DataTable("dtCausa"); DataTable dtAcreedores = new DataTable("dtAcreedores"); dtMotivo = ln.ListarMotivos(); dtCausa = ln.ListarCausas(); dtAcreedores = ln.CRUDAcreedores(1, "", 0, "", "", 0, 0, 0, 0, ""); var dtCsv = util.CSVtoDataTable(e.UploadedFile, ";"); for (var i = 0; i < dtCsv.Rows.Count - 1; i++) { var NroCertificado = dtCsv.Rows[i]["NCertificado"].ToString().Trim(); if (string.IsNullOrEmpty(NroCertificado.ToString())) { throw new Exception("El numero de certificado no puede estar vacio, linea " + i); } //validar si existe nro certificado en tabla operacion validarExiste = ln.CP_VerificarCertificado(NroCertificado); if (validarExiste == 0) { throw new Exception("El número de certificado no esta registrado, linea " + i); } var Motivo = dtCsv.Rows[i]["Motivo"].ToString().Trim(); if (string.IsNullOrEmpty(Motivo.ToString())) { throw new Exception("El Motivo ingresado no existe en la parametrización, linea " + i); } var Causa = dtCsv.Rows[i]["Causa"].ToString().Trim(); if (string.IsNullOrEmpty(Causa.ToString())) { throw new Exception("La causa ingresada no existe en la parametrización, linea " + i); } var Monto = dtCsv.Rows[i]["Monto"].ToString().Trim(); if (string.IsNullOrEmpty(Monto.ToString()) || Monto.ToString() == "0") { throw new Exception("El Monto no puede estar vacio o ser cero, linea " + i); } var FechaCobro = dtCsv.Rows[i]["FechaCobro"].ToString().Trim(); if (string.IsNullOrEmpty(FechaCobro.ToString())) { throw new Exception("La fecha de cobro no puede estar vacia, linea " + i); } var FechaPago = dtCsv.Rows[i]["FechaPago"].ToString().Trim(); if (string.IsNullOrEmpty(FechaPago.ToString())) { throw new Exception("La Fecha de Pago no puede estar vacía, linea " + i); } var Acreedor = dtCsv.Rows[i]["Acreedor"].ToString().Trim(); if (string.IsNullOrEmpty(Acreedor.ToString())) { throw new Exception("El acreedor no puede estar vacio, linea " + i); } //else // dtCsv.Rows[i]["Acreedor"] = System.Web.HttpUtility.HtmlEncode(dtCsv.Rows[i]["Acreedor"].ToString().Trim()); } //System.Web.HttpUtility.HtmlDecode( Page.Session["dtArchivo"] = dtCsv; //HtmlDecodeDataTable(dtCsv); e.CallbackData = "OK"; } } catch (Exception ex) { e.CallbackData = ex.Message; } }