private void btn_excel_Click(object sender, EventArgs e) { btn_excel.Enabled = false; String codigoagenerar = "20300166611|03" + "|" + txt_Serie.Text + "|" + txt_Numero.Text + "|" + txt_IGV.Text.Trim() + "|" + txt_TotalsinPercep.Text.Trim() + "|" + dpick_Fecha.Value.ToString("dd-MM-yyyy") + "|" + "6|" + txt_Ruc.Text + "|"; String nombreArchivo = txt_Serie.Text + "-" + txt_Numero.Text; String qr = objProceso.genearQr(nombreArchivo, codigoagenerar); formatearFactura(qr); FacturaFecha cr = new FacturaFecha(); // System.Web.HttpResponse res = new System.Web.HttpResponse(); cr.SetDataSource(objListFacturaReporte); saveFileDialog1.FileName = ".xls"; saveFileDialog1.DefaultExt = "xls"; saveFileDialog1.Filter = "Excel files (*.xls)|*.xls"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { cr.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.ExcelRecord, @saveFileDialog1.FileName); } btn_excel.Enabled = true; }
private void btn_excel_Click(object sender, EventArgs e) { try { btn_excel.Enabled = false; int index = grd_Facturas.SelectedCells[0].RowIndex; objDocumentoCab = objListaDocumentoCab[index]; String codigoagenerar = "20300166611|01" + "|" + objDocumentoCab.DocumentoCabSerie + "|" + objDocumentoCab.DocumentoCabNro + "|" + objDocumentoCab.DocumentoCabIGV.ToString("C").Substring(3).Trim() + "|" + objDocumentoCab.DocumentoCabTotal.ToString("C").Substring(3).Trim() + "|" + objDocumentoCab.DocumentoCabFecha.ToString("dd-MM-yyyy") + "|" + "6|" + objDocumentoCab.DocumentoCabClienteDocumento + "|"; String nombreArchivo = objDocumentoCab.DocumentoCabSerie + "-" + objDocumentoCab.DocumentoCabNro; String qr = objProceso.genearQr(nombreArchivo, codigoagenerar); formatearFactura(qr); FacturaFecha cr = new FacturaFecha(); // System.Web.HttpResponse res = new System.Web.HttpResponse(); cr.SetDataSource(objListFacturaReporte); saveFileDialog1.FileName = "20300166611-07-" + objDocumentoCab.DocumentoCabSerie + "-" + objDocumentoCab.DocumentoCabNro + ".xls"; saveFileDialog1.DefaultExt = "xls"; saveFileDialog1.Filter = "Excel files (*.xls)|*.xls"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { cr.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.ExcelRecord, @saveFileDialog1.FileName); } btn_excel.Enabled = true; } catch (Exception ex) { MessageBox.Show("ERROR :" + ex.Message); btn_excel.Enabled = true; } }
private void btn_imprimir_Click(object sender, EventArgs e) { string root = @"N:\PDF"; if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } try { btn_imprimir.Enabled = false; int index = grd_Facturas.SelectedCells[0].RowIndex; objDocumentoCab = objListaDocumentoCab[index]; String codigoagenerar = "20300166611|01" + "|" + objDocumentoCab.DocumentoCabSerie + "|" + objDocumentoCab.DocumentoCabNro + "|" + objDocumentoCab.DocumentoCabIGV.ToString("C").Substring(3).Trim() + "|" + objDocumentoCab.DocumentoCabTotal.ToString("C").Substring(3).Trim() + "|" + objDocumentoCab.DocumentoCabFecha.ToString("dd-MM-yyyy") + "|" + "6|" + objDocumentoCab.DocumentoCabClienteDocumento + "|"; String nombreArchivo = objDocumentoCab.DocumentoCabSerie + "-" + objDocumentoCab.DocumentoCabNro; String qr = objProceso.genearQr(nombreArchivo, codigoagenerar); formatearFactura(qr); FacturaFecha cr = new FacturaFecha(); string rut = @"N:\PDF\20300166611-" + objDocumentoCab.DocumentoCabSerie + "-" + objDocumentoCab.DocumentoCabNro + ".pdf"; // System.Web.HttpResponse res = new System.Web.HttpResponse(); if (File.Exists(rut)) { File.Delete(rut); } cr.SetDataSource(objListNotaReporte); cr.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, rut); using (PrintDialog Dialog = new PrintDialog()) { Dialog.ShowDialog(); ProcessStartInfo printProcessInfo = new ProcessStartInfo() { Verb = "print", CreateNoWindow = true, FileName = rut, WindowStyle = ProcessWindowStyle.Hidden }; Process printProcess = new Process(); printProcess.StartInfo = printProcessInfo; printProcess.Start(); printProcess.WaitForInputIdle(); Thread.Sleep(3000); if (false == printProcess.CloseMainWindow()) { printProcess.Kill(); } } btn_imprimir.Enabled = true; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); btn_imprimir.Enabled = true; } }