//Metodo que se ejecuta al darle clic en botón Descargar Expediente protected void btnDescargar_OnClick(object sender, EventArgs e) { try { string rfc = null; string pedimento = null; if (Session["RFC"] == null) { Response.Redirect("Login.aspx"); return; } rfc = Session["RFC"].ToString().Trim(); TExpediente res; IExpedienteComercioservice v1 = new IExpedienteComercioservice(); //Recorre el grid para ver si hay registros seleccionados, y si los hay abrir en zip cada registro //Buscar la manera de descargar más de un archivo zip for (int i = 0; i < GridED.VisibleRowCount; i++) { ASPxCheckBox chkConsultar = GridED.FindRowCellTemplateControl(i, (GridViewDataColumn)GridED.Columns["TODO"], "chkConsultar") as ASPxCheckBox; if (chkConsultar.Checked) { pedimento = GridED.GetRowValues(i, "PEDIMENTO ARMADO").ToString(); res = v1.Getzip(rfc, pedimento); string base64BinaryStr = res.Archivo.Trim(); try { Response.Write("<script>window.open('" + base64BinaryStr + "','_blank') </script>"); HttpContext.Current.ApplicationInstance.CompleteRequest(); //Response.End(); } catch (Exception ex) { string msg = ex.Message; } } } } catch (Exception ex) { int idusuario = 0; string mensaje = ""; if (Session["IdUsuario"] != null) { idusuario = int.Parse(Session["IdUsuario"].ToString()); } excepcion.RegistrarExcepcion(idusuario, "DescargaExpediente-DescargarZip", ex, lblCadena.Text, ref mensaje); AlertError("Error al descargar el archivo zipeado, intentelo más tarde"); } }
//Metodo que se ejecuta cuando se da clic en botón eliminar, descargar archivo o procesar archivo protected void ASPxGridView1_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridViewCustomButtonCallbackEventArgs e) { try { if (Session["Cadena"] == null) { Response.Redirect("Login.aspx"); return; } //ds_filesDS.ConnectionString = Session["Cadena"].ToString(); string cmdString = string.Empty; string connString = Session["Cadena"].ToString(); ASPxGridView grid = sender as ASPxGridView; var tmp = grid.GetRowValues(e.VisibleIndex, grid.KeyFieldName); DataTable dt = new DataTable(); if (e.ButtonID == "btnEliminar") { cmdString = "DELETE FROM [FILESDS] WHERE [FILESDSKEY] = @FILESDSKEY"; using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = cmdString; comm.Parameters.Add("@FILESDSKEY", SqlDbType.UniqueIdentifier).Value = tmp; using (SqlDataReader reader = comm.ExecuteReader()) { if (!reader.HasRows) { dt = null; } else { dt.Load(reader); } } } conn.Close(); } //Se actualiza grid UpdateGrid(); AlertSuccess("Archivo eliminado con éxito"); } else if (e.ButtonID == "ID_DOWNLOAD") { byte[] bytes = null; string nombreArchivo = ""; var parent = System.IO.Directory.GetParent(Environment.CurrentDirectory); string path = parent.Parent + "\\DS"; string target = path + ""; //Crea un directorio if (!Directory.Exists(target)) { Directory.CreateDirectory(target); } cmdString = "SELECT TOP 1 ARCHIVO, DSNAME FROM [FILESDS] WHERE [FILESDSKEY] = @val1 "; using (SqlConnection conn = new SqlConnection(connString)) { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = cmdString; comm.Parameters.Add("@val1", SqlDbType.UniqueIdentifier).Value = tmp; conn.Open(); SqlDataReader reader = comm.ExecuteReader(); if (!reader.HasRows) { dt = null; } else { reader.Read(); bytes = (byte[])reader["ARCHIVO"]; nombreArchivo = (string)reader["DSNAME"]; File.WriteAllBytes(path + "\\" + nombreArchivo, bytes); AlertSuccess("Se descargo el archivo: " + nombreArchivo); } } //(sender as ASPxGridView).JSProperties["cpResult"] = "DS\\" + nombreArchivo; conn.Close(); } // Response.Clear(); // Response.ContentType = "application/winrar"; // Response.AddHeader("content-disposition", "attachment;filename=" + nombreArchivo); //// Response.TransmitFile(Server.MapPath(path + "\\" + nombreArchivo)); // Response.TransmitFile(path + "\\" + nombreArchivo); // HttpContext.Current.ApplicationInstance.CompleteRequest(); // Response.End(); } if (e.ButtonID == "ID_PROCESAR") { // AQUI SE DEBE MANDAR A EJECUTAR EL SP QUE PROCESA LOS ARCHIVOS. try { string rfc = Session["RFC"].ToString().Trim(); if (rfc == null) { Response.Redirect("Login.aspx"); return; } TRespuesta res; IExpedienteComercioservice v1 = new IExpedienteComercioservice(); res = v1.Procesads(tmp.ToString(), rfc); string respuesta = res.ToString(); } catch (Exception exc) { int idusuario = 0; string mensaje = ""; if (Session["IdUsuario"] != null) { idusuario = int.Parse(Session["IdUsuario"].ToString()); } excepcion.RegistrarExcepcion(idusuario, "CargasDataStage-ASPxGridView1_CustomButtonCallback", exc, lblCadena.Text, ref mensaje); AlertError("Error al conectarse con el WebServices, intentelo más tarde"); } #region codigo anterior ////Valida de cada fila del grid si el estatus esta Procesado entonces el botón Procesar Archivo queda inhabilitado //DataTable dtU = new DataTable(); //dtU = UpdateGrid(); //Session["Grid"] = dtU; //if (Session["Grid"] != null && ((DataTable)(Session["Grid"])).Rows.Count > 0) //{ // for (int i = 0; i < ((DataTable)(Session["Grid"])).Rows.Count; i++) // { // var status = grid.GetRowValues(i, "STATUSDS"); // if(status.ToString().ToUpper().Trim().Equals("PROCESADO")) // { // ASPxButton button = grid.FindRowCellTemplateControl(i, (GridViewDataColumn)grid.Columns["ACCION"], "ID_PROCESAR") as ASPxButton; // var col = ASPxGridView1. Columns[8] as GridViewCommandColumn; // col.CustomButtons["ID_PROCESAR"].Visibility = GridViewCustomButtonVisibility.Invisible; // } // //ASPxCheckBox chkConsultar = detailGridDocumentos.FindRowCellTemplateControl(i, (GridViewDataColumn)detailGridDocumentos.Columns["PDF"], "chkConsultar") as ASPxCheckBox; // //ASPxCheckBox chkConsultar = Grid2.FindRowCellTemplateControl(i, (GridViewDataColumn)Grid2.Columns["Consultar"], "chkConsultar") as ASPxCheckBox; // //ASPxButton btnProcesarFile = ASPxGridView1.FindRowCellTemplateControl(i, (GridViewDataColumn)ASPxGridView1.Columns["ACCIONES"], "btnProcesarFile") as ASPxButton; // //if (ASPxGridView1.GetRowValues(i, "STATUSDS").ToString().Equals("PROCESADO")) // // btnProcesarFile.Enabled = false; // //else // // btnProcesarFile.Enabled = true; // } // //foreach (DataRow fila in ((DataTable)(Session["Grid"])).Rows) // //{ // // if (fila["STATUSDS"].ToString().Trim().ToUpper().Equals("PROCESADO")) // // { // // } // //} //} #endregion //Se actualiza grid UpdateGrid(); } } catch (Exception ex) { AlertError(ex.Message); int idusuario = 0; string mensaje = ""; if (Session["IdUsuario"] != null) { idusuario = int.Parse(Session["IdUsuario"].ToString()); } excepcion.RegistrarExcepcion(idusuario, "CargasDataStage-ASPxGridView1_CustomButtonCallback", ex, lblCadena.Text, ref mensaje); } }
//Metodo que se ejecuta cuando se da clic en botón eliminar, descargar archivo o procesar archivo protected void ASPxGridView1_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridViewCustomButtonCallbackEventArgs e) { try { if (Session["Cadena"] == null) { Response.Redirect("Login.aspx"); return; } //ds_filesDS.ConnectionString = Session["Cadena"].ToString(); string cmdString = string.Empty; string connString = Session["Cadena"].ToString(); ASPxGridView grid = sender as ASPxGridView; var tmp = grid.GetRowValues(e.VisibleIndex, grid.KeyFieldName); DataTable dt = new DataTable(); if (e.ButtonID == "btnEliminar") { cmdString = "DELETE FROM [FILESPECA] WHERE [FPKEY] = @FPKEY"; using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = cmdString; comm.Parameters.Add("@FPKEY", SqlDbType.UniqueIdentifier).Value = tmp; using (SqlDataReader reader = comm.ExecuteReader()) { if (!reader.HasRows) { dt = null; } else { dt.Load(reader); } } } conn.Close(); } //Se actualiza grid UpdateGrid(); AlertSuccess("Archivo eliminado con éxito"); } else if (e.ButtonID == "ID_DOWNLOAD") { byte[] bytes = null; string nombreArchivo = ""; var parent = System.IO.Directory.GetParent(Environment.CurrentDirectory); string path = parent.Parent + "\\DS"; string target = path + ""; //Crea un directorio if (!Directory.Exists(target)) { Directory.CreateDirectory(target); } cmdString = "SELECT TOP 1 ARCHIVO, PECANAME FROM [FILESPECA] WHERE [FPKEY] = @val1 "; using (SqlConnection conn = new SqlConnection(connString)) { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = cmdString; comm.Parameters.Add("@val1", SqlDbType.UniqueIdentifier).Value = tmp; conn.Open(); SqlDataReader reader = comm.ExecuteReader(); if (!reader.HasRows) { dt = null; } else { reader.Read(); bytes = (byte[])reader["ARCHIVO"]; nombreArchivo = (string)reader["PECANAME"]; File.WriteAllBytes(path + "\\" + nombreArchivo, bytes); AlertSuccess("Se descargo el archivo: " + nombreArchivo); } } //(sender as ASPxGridView).JSProperties["cpResult"] = "DS\\" + nombreArchivo; conn.Close(); } } if (e.ButtonID == "ID_PROCESAR") { // AQUI SE DEBE MANDAR A EJECUTAR EL SP QUE PROCESA LOS ARCHIVOS. try { string rfc = Session["RFC"].ToString().Trim(); if (rfc == null) { Response.Redirect("Login.aspx"); return; } TRespuesta res; IExpedienteComercioservice v1 = new IExpedienteComercioservice(); res = v1.Procesapeca(tmp.ToString(), rfc); string respuesta = res.ToString(); } catch (Exception exc) { int idusuario = 0; string mensaje = ""; if (Session["IdUsuario"] != null) { idusuario = int.Parse(Session["IdUsuario"].ToString()); } excepcion.RegistrarExcepcion(idusuario, "ASPxGridView1_CustomButtonCallback", exc, lblCadena.Text, ref mensaje); AlertError("Error al conectarse con el WebServices, intentelo más tarde"); } //Se actualiza grid UpdateGrid(); } } catch (Exception ex) { AlertError(ex.Message); int idusuario = 0; string mensaje = ""; if (Session["IdUsuario"] != null) { idusuario = int.Parse(Session["IdUsuario"].ToString()); } excepcion.RegistrarExcepcion(idusuario, "CargasPeca-ASPxGridView1_CustomButtonCallback", ex, lblCadena.Text, ref mensaje); } }