public void ExportDetalle() { DateTime FechaFinal2 = Convert.ToDateTime(TxtFecFin.Value, new CultureInfo("es-ES")); FechaFinal2 = FechaFinal2.AddDays(1); string FechaSalida2 = FechaFinal2.ToString("dd/MM/yyyy"); GvDetalleExport.DataSource = obj.ExporPedidoDetalle(TxtFechaInicio.Value.ToString(), FechaSalida2.ToString(), Convert.ToInt32(Request.Cookies["WebNestle"]["DLIdUsuario"]), DDUsuario.SelectedValue.ToString().Trim()); GvDetalleExport.DataBind(); string txtFile2 = string.Empty; foreach (GridViewRow row in GvDetalleExport.Rows) { String TxtCelda = string.Empty; foreach (TableCell cell in row.Cells) { if (cell.Text == " ") { cell.Text = ""; } TxtCelda += cell.Text + "|"; } TxtCelda = TxtCelda.Remove(TxtCelda.Length - 1); txtFile2 += TxtCelda + "\r\n"; } Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=DETALLE_PEDIDO.txt"); Response.Charset = ""; Response.ContentType = "application/text"; Response.Output.Write(txtFile2); Response.Flush(); Response.End(); }
protected void LinkButton2_Click(object sender, EventArgs e) { ultimoCodigo(); if (TxtCorrelativo.Value == "") { String mensajeScriptnm = @"<script type='text/javascript'> swal({ title: ""Ingrese Codigo Externo"", icon: ""warning"", dangerMode: false, }) </script>"; ScriptManager.RegisterStartupScript(this, typeof(Page), "mensaje", mensajeScriptnm, false); return; } Int32 ConCodigo = 0; CodigoExterno = Convert.ToInt32(TxtCorrelativo.Value.ToString()); CodigoExterno = CodigoExterno - 1; DateTime FechaFinal = Convert.ToDateTime(TxtFecFin.Value, new CultureInfo("es-ES")); FechaFinal = FechaFinal.AddDays(1); string FechaSalida = FechaFinal.ToString("dd/MM/yyyy"); DataTable dtCebcera = new DataTable(); dtCebcera = obj.ExporPedidoCabe(TxtFechaInicio.Value.ToString(), FechaSalida.ToString(), Convert.ToInt32(Request.Cookies["WebNestle"]["DLIdUsuario"]), DDUsuario.SelectedValue.ToString().Trim(), ConCodigo); //ALMACENO ID DE PEDIDOS DataTable dtIdOrden = new DataTable(); dtIdOrden.Columns.Add("IDOrden", typeof(int)); foreach (DataRow rows in dtCebcera.Rows) { DataRow row = dtIdOrden.NewRow(); row["IDOrden"] = rows["Nro_Pedido_Interno"].ToString(); dtIdOrden.Rows.Add(row); } GV_IdPedidos.DataSource = dtIdOrden; GV_IdPedidos.DataBind(); //END GvExportTxt.DataSource = dtCebcera; GvExportTxt.DataBind(); DateTime thisDay = DateTime.Now; String str, str2, str3, str4; str = thisDay.ToString(); //.ToString("dd/MM/yyyy hh:mm:ss"); str2 = str.Replace("/", "_"); str3 = str2.Replace(" ", "_"); str4 = str3.Replace(":", "_"); str4 = str3.Replace(":", "_"); String NombreCabecera = "PEDIDO_" + str4 + ".txt"; String NombreDetalle = "DETALLE_PEDIDO_" + str4 + ".txt"; String GuardarCabecera = Server.MapPath("~/ExportPedido/" + NombreCabecera); String GuardarDetallePedido = Server.MapPath("~/ExportPedido/" + NombreDetalle); try { using (System.IO.StreamWriter file = new System.IO.StreamWriter(GuardarCabecera)) { String txtFile = string.Empty; foreach (GridViewRow row in GvExportTxt.Rows) { String TxtCelda = string.Empty; foreach (TableCell cell in row.Cells) { if (cell.Text == " ") { cell.Text = ""; } TxtCelda += cell.Text + "|"; } TxtCelda = TxtCelda.Remove(TxtCelda.Length - 1); txtFile += TxtCelda + "\r\n"; } txtFile = txtFile.Remove(txtFile.Length - 2); file.WriteLine(txtFile); } String IdPedidos = ""; foreach (GridViewRow rows in GV_IdPedidos.Rows) { String TxtCelda = string.Empty; TxtCelda += rows.Cells[0].Text.ToString() + ","; IdPedidos += TxtCelda; } IdPedidos = IdPedidos.Remove(IdPedidos.Length - 1); GvDetalleExport.DataSource = obj.ExporPedidoDetalleXID(IdPedidos.ToString()); GvDetalleExport.DataBind(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(GuardarDetallePedido)) { String txtFile = string.Empty; foreach (GridViewRow row in GvDetalleExport.Rows) { String TxtCelda = string.Empty; foreach (TableCell cell in row.Cells) { if (cell.Text == " ") { cell.Text = ""; } TxtCelda += cell.Text + "|"; } TxtCelda = TxtCelda.Remove(TxtCelda.Length - 1); txtFile += TxtCelda + "\r\n"; } txtFile = txtFile.Remove(txtFile.Length - 2); String Txt = txtFile.ToString(); file.WriteLine(txtFile); } }catch (Exception ex) {} String stripllamar_N = "<script type='text/javascript'> window.open('ExportTxt.ashx?filepath=" + NombreCabecera.ToString() + "'); window.open('ExportTxt.ashx?filepath=" + NombreDetalle.ToString() + "'); </script>"; ScriptManager.RegisterStartupScript(this, typeof(Page), "mensaje", stripllamar_N, false); /* * string txtFile = string.Empty; * * foreach (GridViewRow row in GvExportTxt.Rows) * { * * String TxtCelda = string.Empty; * foreach (TableCell cell in row.Cells) * { * * if (cell.Text == " ") * { * cell.Text = ""; * } * TxtCelda += cell.Text + "|"; * } * TxtCelda = TxtCelda.Remove(TxtCelda.Length - 1); * txtFile += TxtCelda + "\r\n"; * } * Response.Clear(); * Response.Buffer = true; * Response.AddHeader("content-disposition", "attachment;filename=PEDIDO.txt"); * Response.Charset = ""; * Response.ContentType = "application/text"; * Response.Output.Write(txtFile); * Response.Flush(); * Response.End(); * //DETALLE PEDIDO * // ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "none", * //"<script>ExportarCabecera();</script>", false); */ }