private void PRO007RViewRC_Load(object sender, EventArgs e) { CrystalDecisions.CrystalReports.Engine.ReportDocument drPrint = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); DataRow oRow = dtPrint.Rows[0]; String sFile = ConfigurationManager.AppSettings["pathpdfRecibos"] + "RC-" + oRow["DOCV_Serie"] + "-" + oRow["DOCV_Numero"] + ".pdf"; try { drPrint.FileName = System.IO.Directory.GetCurrentDirectory() + "\\Reportes\\" + RptFile; drPrint.SetDataSource(dtPrint); for (int p = 0; p <= aParams.Count - 1; p++) { drPrint.SetParameterValue(p, aParams[p]); } if (!File.Exists(sFile)) { drPrint.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, sFile); SendMessage(sFile, oRow); } CrystalReportViewer.ReportSource = drPrint; } catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void PrintTicket() { try { CrystalDecisions.CrystalReports.Engine.ReportDocument etq = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); string spath = System.Windows.Forms.Application.StartupPath; etq.Load(spath + "\\" + @"\Reports\DRE_v3.RPT"); CrystalDecisions.Shared.IConnectionInfo crConnectionInfo = etq.DataSourceConnections[0]; string DbUser = Properties.Settings.Default.DbUserName; string DbPwd = Properties.Settings.Default.DbPassword; string Server = Properties.Settings.Default.Server; string CompanyDB = Properties.Settings.Default.CompanyDB; crConnectionInfo.SetConnection(Server, CompanyDB, DbUser, DbPwd); //Parametro 0 CrystalDecisions.Shared.ParameterField objParameterField = etq.ParameterFields[0]; CrystalDecisions.Shared.ParameterDiscreteValue objParameterDiscreteValue; objParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue(); objParameterField.CurrentValues.Clear(); objParameterDiscreteValue.Description = "2017-10-01"; objParameterDiscreteValue.Value = "2017-10-01"; objParameterField.CurrentValues.Add(objParameterDiscreteValue); //Parametro 1 CrystalDecisions.Shared.ParameterField objParameterField1 = etq.ParameterFields[1]; CrystalDecisions.Shared.ParameterDiscreteValue objParameterDiscreteValue1; objParameterDiscreteValue1 = new CrystalDecisions.Shared.ParameterDiscreteValue(); objParameterField1.CurrentValues.Clear(); objParameterDiscreteValue1.Description = "2017-10-31"; objParameterDiscreteValue1.Value = "2017-10-31"; objParameterField1.CurrentValues.Add(objParameterDiscreteValue1); //etq.PrintOptions.PrinterName = Properties.Settings.Default.PrinterNameTerra; etq.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"C:\Temp\RPT.pdf"); etq.Close(); } catch (Exception ex) { } }
private string generatefiles(DataSet ds, DataTable dt1, string fromdate, string todate, string FirstPath, DataTable mailsetting) { try { DataView dv = new DataView(ds.Tables[0]); string strAttachFirst = string.Empty; string strAttachSecond = string.Empty; bool isSendData = false; System.Collections.ArrayList objList = new ArrayList(); objList.Add(MailSetting(mailsetting)); CrystalDecisions.CrystalReports.Engine.ReportDocument crystalReport; foreach (DataRow Row in dt1.Rows) { MailDetails objMails = new MailDetails(); dv.RowFilter = "SuperZoneID = " + Row["SuperZoneID"].ToString(); crystalReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); crystalReport.Load(Server.MapPath("../Report/MissingRecieptNo.rpt")); crystalReport.SetDataSource(dv.ToTable()); crystalReport.SetParameterValue("FromDP", Convert.ToDateTime(fromdate)); crystalReport.SetParameterValue("TODp", Convert.ToDateTime(todate)); isSendData = dv.ToTable().Rows.Count > 0 ? true : false; strAttachFirst = Server.MapPath(FirstPath + "MissingRecieptNo_" + Convert.ToDateTime(fromdate).ToString("dd-MMM-yyyy") + "_" + Convert.ToDateTime(todate).ToString("dd-MMM-yyyy") + "_" + Row["SuperZoneID"].ToString() + ".pdf"); crystalReport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, strAttachFirst); crystalReport.Close(); crystalReport.Dispose(); crystalReport = null; objMails.Attachment = strAttachSecond != "" ? strAttachFirst + "," + strAttachSecond : strAttachFirst; objMails.Name = Row["SuperZoneName"].ToString(); objMails.EmailId = Row["Email"].ToString(); string makesubject = "Missing Receipts from " + Convert.ToDateTime(fromdate).ToString("dd-MMM-yyyy") + " TO " + Convert.ToDateTime(todate).ToString("dd-MMM-yyyy"); objMails.Subject = makesubject; objMails.Desc = makesubject; if (isSendData) { objList.Add(objMails); } objMails = null; } return(JsonConvert.SerializeObject(objList)); } catch (Exception ex) { throw; } }
public void ReportEngine(string rptNm, string OderID) { using (dbDatabaseDataDataContext db = new dbDatabaseDataDataContext()) { //int sample = int.Parse(Request.QueryString["ApplicationId"]); crReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); crReportDocument.Load(Server.MapPath(rptNm)); //crReportDocument.Refresh(); ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.DatabaseName = ConfigurationManager.AppSettings["DBaseName"]; connectionInfo.UserID = ConfigurationManager.AppSettings["DBUserName"]; connectionInfo.Password = ConfigurationManager.AppSettings["DBPassword"]; connectionInfo.ServerName = ConfigurationManager.AppSettings["DBServerName"]; CrTables = crReportDocument.Database.Tables; connectionInfo.Type = ConnectionInfoType.SQL; TableLogOnInfo tableLogOnInfo = new TableLogOnInfo(); tableLogOnInfo.ConnectionInfo = connectionInfo; crReportDocument.DataSourceConnections[0].SetConnection(tableLogOnInfo.ConnectionInfo.ServerName, tableLogOnInfo.ConnectionInfo.DatabaseName, tableLogOnInfo.ConnectionInfo.UserID, tableLogOnInfo.ConnectionInfo.Password); int GrocerID = int.Parse((Session["GrocId"]).ToString()); crReportDocument.SetParameterValue("@CustOdrID", OderID); crReportDocument.SetParameterValue("@GrocerId", GrocerID); if (System.IO.File.Exists(Server.MapPath("~/DownloadApplication/ItemLIst" + ".pdf"))) { System.IO.File.Delete(Server.MapPath("~/DownloadApplication/ItemLIst" + ".pdf")); } crReportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, Server.MapPath("~/DownloadApplication/ItemLIst" + ".pdf")); ViewState["ApplicationPath"] = "~/DownloadApplication/ItemLIst" + ".pdf"; FilePath1 = Server.MapPath(ViewState["ApplicationPath"].ToString()); System.Net.WebClient User = new System.Net.WebClient(); byte[] FileBuffer = User.DownloadData(FilePath1); if ((FileBuffer != null)) { Response.ContentType = "application/pdf"; Response.AddHeader("content-length", FileBuffer.Length.ToString()); Response.BinaryWrite(FileBuffer); } Response.Redirect(ViewState["ApplicationPath"].ToString()); } }
private void LoadReportTest1() { CrystalDecisions.CrystalReports.Engine.ReportDocument doc = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); doc.Load(@"C:\test1.rpt"); this.CrystalReportViewer1.ReportSource = doc; this.CrystalReportViewer1.HasSearchButton = false; this.CrystalReportViewer1.HasZoomFactorList = false; this.CrystalReportViewer1.HasGotoPageButton = false; CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition fieldDef = doc.DataDefinition.ParameterFields["ids_param"]; CrystalDecisions.Shared.ParameterValues vals = new CrystalDecisions.Shared.ParameterValues(); CrystalDecisions.Shared.ParameterDiscreteValue val = new CrystalDecisions.Shared.ParameterDiscreteValue(); val.Value = 1; vals.Add(val); val = new CrystalDecisions.Shared.ParameterDiscreteValue(); val.Value = 2; vals.Add(val); val = new CrystalDecisions.Shared.ParameterDiscreteValue(); val.Value = 3; vals.Add(val); fieldDef.ApplyCurrentValues(vals); CrystalDecisions.Shared.ConnectionInfo conn = new CrystalDecisions.Shared.ConnectionInfo(); conn.DatabaseName = "DBSALESPP"; conn.ServerName = "."; conn.UserID = "spp"; conn.Password = "******"; CrystalDecisions.Shared.TableLogOnInfo tableLogOn = new CrystalDecisions.Shared.TableLogOnInfo(); tableLogOn.ConnectionInfo = conn; doc.Database.Tables[0].ApplyLogOnInfo(tableLogOn); //System.IO.Stream stream=doc.ExportToStream(CrystalDecisions.Shared.ExportFormatType.HTML32); doc.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"c:\test.pdf"); }
protected void Page_Init(object sender, EventArgs e) { try { var culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB"); culture.NumberFormat.CurrencySymbol = string.Empty; System.Threading.Thread.CurrentThread.CurrentCulture = culture; System.Threading.Thread.CurrentThread.CurrentUICulture = culture; base.InitializeCulture(); string lcomp = Server.MapPath("~/Facturacion/Electronica/Reportes/Iva_Compras.xsd"); System.IO.File.Copy(lcomp, @System.IO.Path.GetTempPath() + "Iva_Compras.xsd", true); oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); bool HayME = false; string reportPath = ""; if (Session["monedasExtranjeras"] != null) { HayME = (bool)Session["monedasExtranjeras"]; } if (!HayME) { reportPath = Server.MapPath("~/Facturacion/Electronica/Reportes/IvaComprasCR.rpt"); } else { reportPath = Server.MapPath("~/Facturacion/Electronica/Reportes/IvaComprasMECR.rpt"); } oRpt.Load(reportPath); Entidades.IvaCompras ivaCompras = new Entidades.IvaCompras(); if (Session["ivaCompras"] != null) { ivaCompras = (Entidades.IvaCompras)Session["ivaCompras"]; DataSet ds = new DataSet(); XmlSerializer objXS = new XmlSerializer(ivaCompras.GetType()); StringWriter objSW = new StringWriter(); objXS.Serialize(objSW, ivaCompras); StringReader objSR = new StringReader(objSW.ToString()); ds.ReadXml(objSR); oRpt.SetDataSource(ds); } else { Response.Redirect("~/Facturacion/Electronica/Reportes/IvaComprasFiltros.aspx", true); } string formatoRptExportar = ""; if (Session["formatoRptExportar"] != null) { formatoRptExportar = (string)Session["formatoRptExportar"]; } if (Session["mostrarFechaYHora"] != null) { if ((bool)Session["mostrarFechaYHora"] == false) { oRpt.DataDefinition.FormulaFields["MostrarFechaYHora"].Text = "'N'"; } } oRpt.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperLetter; oRpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape; oRpt.DataDefinition.FormulaFields["RazSoc"].Text = "'" + ((Entidades.Sesion)Session["Sesion"]).Cuit.RazonSocial + "'"; if (formatoRptExportar == "") { CrystalReportViewer1.GroupTreeStyle.ShowLines = false; CrystalReportViewer1.HasToggleGroupTreeButton = false; CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None; CrystalReportViewer1.ReportSource = oRpt; CrystalReportViewer1.HasPrintButton = true; } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(ivaCompras.Cuit); sb.Append("-"); sb.Append(Convert.ToDateTime(ivaCompras.PeriodoDsd).ToString("yyyyMMdd")); sb.Append("-"); sb.Append(Convert.ToDateTime(ivaCompras.PeriodoHst).ToString("yyyyMMdd")); if (formatoRptExportar == "PDF") { CrystalDecisions.Shared.ExportOptions exportOpts = new CrystalDecisions.Shared.ExportOptions(); CrystalDecisions.Shared.PdfRtfWordFormatOptions pdfOpts = CrystalDecisions.Shared.ExportOptions.CreatePdfRtfWordFormatOptions(); exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; exportOpts.ExportFormatOptions = pdfOpts; oRpt.ExportToHttpResponse(exportOpts, Response, true, sb.ToString()); } if (formatoRptExportar == "Excel") { CrystalDecisions.Shared.ExportOptions exportOpts = new CrystalDecisions.Shared.ExportOptions(); CrystalDecisions.Shared.ExcelFormatOptions pdfOpts = CrystalDecisions.Shared.ExportOptions.CreateExcelFormatOptions(); exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; exportOpts.ExportFormatOptions = pdfOpts; oRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.Excel, Server.MapPath("~/TempExcel/") + sb.ToString() + ".xls"); System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; response.ClearContent(); response.Clear(); response.ContentType = "application/vnd.ms-excel"; response.AddHeader("Content-Disposition", "attachment; filename=" + sb.ToString() + ".xls" + ";"); response.TransmitFile(Server.MapPath("~/TempExcel/" + sb.ToString() + ".xls")); response.Flush(); response.End(); } } } catch (System.Threading.ThreadAbortException) { Trace.Warn("Thread abortado"); } catch (Exception ex) { WebForms.Excepciones.Redireccionar(ex, "~/NotificacionDeExcepcion.aspx"); } }
void GenerarArchivo(Boolean GenerarArchivo) { try { string Co_lin = cboLinea.SelectedIndex == -1 ? null : cboLinea.SelectedValue.ToString().Trim(); string Co_subl = cboSub_lin.SelectedIndex == -1 ? null : cboSub_lin.SelectedValue.ToString().Trim(); string Co_col = cboColores.SelectedIndex == -1 ? null : cboColores.SelectedValue.ToString().Trim(); string Co_cat = cboCat_art.SelectedIndex == -1 ? null : cboCat_art.SelectedValue.ToString().Trim(); string Cod_proc = cboProce.SelectedIndex == -1 ? null : cboProce.SelectedValue.ToString().Trim(); string Grupo; string Archivo; pSeleccionarParametros_Result p = new pSeleccionarParametros_Result(); //Programa e = new Programa(); pSeleccionarReportes_Result r = new pSeleccionarReportes_Result(); //List<pSeleccionarValores_prog_Result> v = new List<pSeleccionarValores_prog_Result>(); //string returnValue = null; using (Profit_RGEntities context = new Profit_RGEntities()) { p = context.pSeleccionarParametros().FirstOrDefault(); r = context.pSeleccionarReportes("006").FirstOrDefault(); Grupo = context.pObtenerGrupo(txtCo_empresa.Text.Trim()).AsParallel().FirstOrDefault().grupo.Trim(); } DataSet ds = new DataSet(); ds.Tables.Add("pAnalisisCompras"); ds.Tables[0].Columns.Add("A", typeof(string)); ds.Tables[0].Columns.Add("co_art", typeof(string)); ds.Tables[0].Columns.Add("art_des", typeof(string)); ds.Tables[0].Columns.Add("referencia", typeof(string)); ds.Tables[0].Columns.Add("comentario", typeof(string)); ds.Tables[0].Columns.Add("lc_descrip2", typeof(string)); ds.Tables[0].Columns.Add("ene", typeof(decimal)); ds.Tables[0].Columns.Add("feb", typeof(decimal)); ds.Tables[0].Columns.Add("mar", typeof(decimal)); ds.Tables[0].Columns.Add("abr", typeof(decimal)); ds.Tables[0].Columns.Add("may", typeof(decimal)); ds.Tables[0].Columns.Add("jun", typeof(decimal)); ds.Tables[0].Columns.Add("jul", typeof(decimal)); ds.Tables[0].Columns.Add("ago", typeof(decimal)); ds.Tables[0].Columns.Add("sep", typeof(decimal)); ds.Tables[0].Columns.Add("oct", typeof(decimal)); ds.Tables[0].Columns.Add("nov", typeof(decimal)); ds.Tables[0].Columns.Add("dic", typeof(decimal)); ds.Tables[0].Columns.Add("uni_ventas", typeof(decimal)); ds.Tables[0].Columns.Add("sugerido", typeof(decimal)); ds.Tables[0].Columns.Add("orden", typeof(Int32)); ds.Tables[0].Columns.Add("costo", typeof(decimal)); ds.Tables[0].Columns.Add("comprar", typeof(decimal)); ds.Tables[0].Columns.Add("total", typeof(decimal)); ds.Tables[0].Clear(); List <Acom> ListaAc = Ac.Where(a => a.comprar > 0).ToList(); if (ListaAc.Count == 0) { MessageBox.Show("Sin datos para mostrar.", "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { for (int i = 0; i < ListaAc.Count; i++) { DataRow row = ds.Tables[0].NewRow(); row["co_art"] = ListaAc[i].co_art; row["art_des"] = ListaAc[i].art_des; row["referencia"] = ListaAc[i].referencia; row["comentario"] = ListaAc[i].comentario; row["LC_DESCRIP2"] = ListaAc[i].lc_descrip2; row["Costo"] = ListaAc[i].costo; row["Comprar"] = ListaAc[i].comprar; row["Total"] = ListaAc[i].costo * ListaAc[i].comprar; ds.Tables[0].Rows.Add(row); ds.Tables[0].AcceptChanges(); } string Filename = r.ruta + @"\" + r.Archivo; CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); oRpt.Load(@Filename); oRpt.SetDataSource(ds); if (GenerarArchivo == false) { FrmRep Fr = new FrmRep(ds, r.Archivo, false); Fr.ShowDialog(); } else { Archivo = ""; Archivo = @p.ruta_pdf + @"\" + r.Archivo.Replace(".rpt", "").Trim() + " " + System.DateTime.Now.ToFileTime() + ".pdf"; oRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Archivo.TrimEnd()); } oRpt.Close(); oRpt.Dispose(); } } catch (EntitySqlException ex) { MessageBox.Show(ex.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (SqlException ex0) { MessageBox.Show(ex0.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex1) { MessageBox.Show(ex1.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected void Page_Load(object sender, EventArgs e) { //this takes request parameters only from the query string string SalesOrderID = Request.QueryString["salesorderid"]; if (SalesOrderID == null) { //SalesOrderID = "QDEMOA0019C7"; //FOR Testing } if (SalesOrderID == null) { Response.Write("No Valid SalesOrderID provided"); } else { try { Sage.Entity.Interfaces.ISalesOrder salesOrder = Sage.Platform.EntityFactory.GetById<Sage.Entity.Interfaces.ISalesOrder>(SalesOrderID); string reportPath = Server.MapPath("CrystalReports\\PickingListDetail.rpt"); CrystalDecisions.CrystalReports.Engine.ReportDocument crReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); crReport.Load(reportPath); crReport.RecordSelectionFormula = "{SALESORDER.SALESORDERID} = '" + salesOrder.Id.ToString() + "'"; //Retrieve connection string information // get the DataService to get a connection string to the database Sage.Platform.Data.IDataService datasvc = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>(); string connectionString = datasvc.GetConnectionString(); System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder(); builder.ConnectionString = connectionString; string password = builder["Password"].ToString(); string username = builder["User ID"].ToString(); string dataSource = datasvc.Server; string initialCatalog = datasvc.Alias; //Define new connection for Crystal Report CrystalDecisions.Shared.ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo(); connectionInfo.DatabaseName = initialCatalog; connectionInfo.UserID = username; connectionInfo.Password = password; connectionInfo.ServerName = dataSource; // set report connection for main report SetDBLogonForReport(connectionInfo, crReport); // set report connection for any subreports SetDBLogonForSubreports(connectionInfo, crReport); //System.IO.MemoryStream ms = (System.IO.MemoryStream)crReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); //Response.BinaryWrite(ms.ToArray()); String filename = "exportedPDF/PickingList" + salesOrder.AlternateKeyPrefix + "-" + salesOrder.AlternateKeySuffix + ".pdf"; crReport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Server.MapPath(filename)); //string popupScript = "<script language='javascript'>" + "window.open('C:/BiWeeklyReport.pdf'); <//script>"; //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popupOpener", "var popup=window.open('" + filename + "');popup.focus();", true); //string jsScript = "window.close();"; //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "AlertJS", jsScript, true); //Page.ClientScript.RegisterOnSubmitStatement(typeof(Page), "closePage", "window.onunload = CloseWindow();"); Response.Redirect(filename); } catch (System.Threading.ThreadAbortException ex) { } finally { //Response.End(); } } }
private string generatefiles(DataSet ds, string FirstPath, DataTable mailsetting) { try { DataView dvmaster = new DataView(ds.Tables[0]); DataView dv = new DataView(ds.Tables[1]); string strAttachFirst = string.Empty; string strAttachSecond = string.Empty; bool isSendData = false; System.Collections.ArrayList objList = new ArrayList(); CrystalDecisions.CrystalReports.Engine.ReportDocument crystalReport; objList.Add(MailSetting(mailsetting)); XmlDocument doc = new XmlDocument(); XmlNode inode = doc.CreateElement("f"); XmlNode fnode = doc.CreateElement("r"); foreach (DataRow Row in ds.Tables[0].Rows) { MailDetails objMails = new MailDetails(); dv.RowFilter = "SubDocId = " + Row["subdocno"].ToString(); dvmaster.RowFilter = "subdocno = " + Row["subdocno"].ToString(); crystalReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); crystalReport.Load(Server.MapPath("../Report/PrintInvoiceMM.rpt")); crystalReport.SetDataSource(dv); isSendData = dv.ToTable().Rows.Count > 0 ? true : false; strAttachFirst = Server.MapPath(FirstPath + dvmaster[0]["CustCode"] + "-" + dvmaster[0]["subdocno"] + ".pdf"); crystalReport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, strAttachFirst); crystalReport.Close(); crystalReport.Dispose(); crystalReport = null; objMails.Attachment = strAttachSecond != "" ? strAttachFirst + "," + strAttachSecond : strAttachFirst; objMails.Name = dvmaster[0]["CustName"].ToString(); objMails.EmailId = Row["EmailID"].ToString(); string makesubject = dvmaster[0]["subject"].ToString(); objMails.Subject = makesubject; objMails.Desc = Row["msg"].ToString(); XmlNode element = doc.CreateElement("i"); inode = doc.CreateElement("subdoc"); inode.InnerText = Row["subdocno"].ToString(); element.AppendChild(inode); inode = doc.CreateElement("fyu"); inode.InnerText = Row["FY"].ToString(); element.AppendChild(inode); inode = doc.CreateElement("mod"); inode.InnerText = Row["module"].ToString(); element.AppendChild(inode); fnode.AppendChild(element); if (isSendData) { objList.Add(objMails); } objMails = null; } Other_Z.OtherBAL ObjBal = new Other_Z.OtherBAL(); ObjBal.UpdateEmailLog(fnode.OuterXml, "", "", ""); return(JsonConvert.SerializeObject(objList)); } catch (Exception ex) { throw; } }
protected void Page_Init(object sender, EventArgs e) { try { var culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB"); culture.NumberFormat.CurrencySymbol = string.Empty; System.Threading.Thread.CurrentThread.CurrentCulture = culture; System.Threading.Thread.CurrentThread.CurrentUICulture = culture; base.InitializeCulture(); string lcomp = Server.MapPath("~/Facturacion/Electronica/Reportes/Iva_Ventas.xsd"); System.IO.File.Copy(lcomp, @System.IO.Path.GetTempPath() + "Iva_Ventas.xsd", true); oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); bool HayME = false; string reportPath = ""; if (Session["monedasExtranjeras"] != null) { HayME = (bool)Session["monedasExtranjeras"]; } if (!HayME) { reportPath = Server.MapPath("~/Facturacion/Electronica/Reportes/IvaVentasCR.rpt"); } else { reportPath = Server.MapPath("~/Facturacion/Electronica/Reportes/IvaVentasMECR.rpt"); } oRpt.Load(reportPath); Entidades.IvaVentas ivaVentas = new Entidades.IvaVentas(); if (Session["ivaVentas"] != null) { ivaVentas = (Entidades.IvaVentas)Session["ivaVentas"]; DataSet ds = new DataSet(); XmlSerializer objXS = new XmlSerializer(ivaVentas.GetType()); StringWriter objSW = new StringWriter(); objXS.Serialize(objSW, ivaVentas); StringReader objSR = new StringReader(objSW.ToString()); ds.ReadXml(objSR); oRpt.SetDataSource(ds); } else { Response.Redirect("~/Facturacion/Electronica/Reportes/IvaVentasFiltros.aspx", true); } string formatoRptExportar = ""; if (Session["formatoRptExportar"] != null) { formatoRptExportar = (string)Session["formatoRptExportar"]; } if (Session["mostrarFechaYHora"] != null) { if ((bool)Session["mostrarFechaYHora"] == false) { oRpt.DataDefinition.FormulaFields["MostrarFechaYHora"].Text = "'N'"; } } oRpt.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperLetter; oRpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape; oRpt.DataDefinition.FormulaFields["RazSoc"].Text = "'" + ((Entidades.Sesion)Session["Sesion"]).Cuit.RazonSocial + "'"; if (formatoRptExportar == "") { CrystalReportViewer1.GroupTreeStyle.ShowLines = false; CrystalReportViewer1.HasToggleGroupTreeButton = false; CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None; CrystalReportViewer1.ReportSource = oRpt; CrystalReportViewer1.HasPrintButton = true; } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(ivaVentas.Cuit); sb.Append("-"); sb.Append(Convert.ToDateTime(ivaVentas.PeriodoDsd).ToString("yyyyMMdd")); sb.Append("-"); sb.Append(Convert.ToDateTime(ivaVentas.PeriodoHst).ToString("yyyyMMdd")); if (formatoRptExportar == "PDF") { CrystalDecisions.Shared.ExportOptions exportOpts = new CrystalDecisions.Shared.ExportOptions(); CrystalDecisions.Shared.PdfRtfWordFormatOptions pdfOpts = CrystalDecisions.Shared.ExportOptions.CreatePdfRtfWordFormatOptions(); exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; exportOpts.ExportFormatOptions = pdfOpts; oRpt.ExportToHttpResponse(exportOpts, Response, true, sb.ToString()); } if (formatoRptExportar == "Excel") { CrystalDecisions.Shared.ExportOptions exportOpts = new CrystalDecisions.Shared.ExportOptions(); CrystalDecisions.Shared.ExcelFormatOptions pdfOpts = CrystalDecisions.Shared.ExportOptions.CreateExcelFormatOptions(); exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; exportOpts.ExportFormatOptions = pdfOpts; oRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.Excel, Server.MapPath("~/TempExcel/") + sb.ToString() + ".xls"); System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; response.ClearContent(); response.Clear(); response.ContentType = "application/vnd.ms-excel"; response.AddHeader("Content-Disposition", "attachment; filename=" + sb.ToString() + ".xls" + ";"); response.TransmitFile(Server.MapPath("~/TempExcel/" + sb.ToString() + ".xls")); response.Flush(); response.End(); } } } catch (System.Threading.ThreadAbortException) { Trace.Warn("Thread abortado"); } catch (Exception ex) { WebForms.Excepciones.Redireccionar(ex, "~/NotificacionDeExcepcion.aspx"); } }
void GenerarArchivo(Int32 Id_evento, Boolean GenerarArchivo) { try { pSeleccionarParametros_Result p = new pSeleccionarParametros_Result(); Programa e = new Programa(); pSeleccionarReportes_Result r = new pSeleccionarReportes_Result(); List <pSeleccionarValores_prog_Result> v = new List <pSeleccionarValores_prog_Result>(); string returnValue = null; using (Profit_RGEntities context = new Profit_RGEntities()) { p = context.pSeleccionarParametros().FirstOrDefault(); e = context.Programas.Where(ev => ev.id_evento == Id_evento).FirstOrDefault(); r = context.pSeleccionarReportes(e.cod_rep.Trim()).FirstOrDefault(); v = context.pSeleccionarValores_prog(e.id_evento).ToList(); } ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["ProfitContenedor.Properties.Settings.Profit_RGConnectionString"]; if (settings != null) { returnValue = settings.ConnectionString; } SqlConnection sqlConn = new SqlConnection(returnValue); SqlCommand comd; comd = new SqlCommand(); comd.Connection = sqlConn; comd.CommandType = CommandType.StoredProcedure; comd.CommandText = r.funcion.Trim(); foreach (var item in v) { switch (item.tipo.Trim()) { case "Char": comd.Parameters.Add(item.parametro.Trim(), SqlDbType.Char); comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_char; break; case "Int": comd.Parameters.Add(item.parametro.Trim(), SqlDbType.Int); comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_int; break; case "Decimal": comd.Parameters.Add(item.parametro.Trim(), SqlDbType.Decimal); comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_dec; break; case "DateTime": comd.Parameters.Add(item.parametro.Trim(), SqlDbType.DateTime); comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_date; break; case "Time": comd.Parameters.Add(item.parametro.Trim(), SqlDbType.Time); comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_time; break; case "Bit": comd.Parameters.Add(item.parametro.Trim(), SqlDbType.Bit); comd.Parameters[comd.Parameters.Count - 1].Value = item.valor_bit; break; } } SqlDataAdapter sqlAdapter = new SqlDataAdapter(); sqlAdapter.SelectCommand = comd; DataSet ds = new DataSet(); sqlAdapter.Fill(ds, r.funcion.Trim()); if (ds.Tables[0].Rows.Count == 0) { MessageBox.Show("Sin datos para mostrar.", "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { string Filename = r.ruta + @"\" + r.Archivo; CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); oRpt.Load(@Filename); oRpt.SetDataSource(ds); if (GenerarArchivo == false) { FrmRep Fr = new FrmRep(ds, r.Archivo, false); Fr.ShowDialog(); } else { Archivo = ""; //string Fecha = ((DateTime.Now.Day < 10) ? "0" : "") + DateTime.Now.Day.ToString() + // ((DateTime.Now.Month < 10) ? "0" : "") + DateTime.Now.Month.ToString() + // (DateTime.Now.Year.ToString()); //string Hora = ((DateTime.Now.Hour < 10) ? "0" : "") + DateTime.Now.Hour.ToString() + // ((DateTime.Now.Minute < 10) ? "0" : "") + DateTime.Now.Minute.ToString() + // ((DateTime.Now.Second < 10) ? "0" : "") + DateTime.Now.Second.ToString(); switch (e.Tipo.Trim()) { case "PDF": //Archivo = @p.ruta_pdf + @"\" + e.descrip.Trim() + " F[" + Fecha + "] H[" + Hora + "].pdf"; Archivo = @p.ruta_pdf + @"\" + e.descrip.Trim() + ".pdf"; oRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Archivo.TrimEnd()); break; case "XLS": Archivo = @p.ruta_pdf + @"\" + e.descrip.Trim() + ".xls"; oRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.ExcelRecord, Archivo.TrimEnd()); break; } } oRpt.Close(); oRpt.Dispose(); } } catch (EntitySqlException ex) { MessageBox.Show(ex.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (SqlException ex0) { MessageBox.Show(ex0.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex1) { MessageBox.Show(ex1.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error); } }