Example #1
0
 protected void GenerateReport(int rptId, string name)
 {
     try
     {
         int     productid = Convert.ToInt32(ddlType.SelectedValue);
         DataSet rptDS     = new DataSet();
         rptDoc = new ReportDocument();
         CrystalReportViewer1.HasToggleGroupTreeButton = false;
         CrystalReportViewer1.BestFitPage = false;
         CrystalReportViewer1.Width       = 920;
         string type = "";
         if (rptId == 1)
         {
             type = "IN_CLEAN_ROOM";
         }
         else if (rptId == 2)
         {
             type = "OUT_CLEAN_ROOM";
         }
         else if (rptId == 3)
         {
             type = "IN_WAREHOUSE";
         }
         else if (rptId == 4)
         {
             type = "OUT_WAREHOUSE";
         }
         DataTable dt = us_dll.GetInventoryReportData(productid, type);
         if (dt.Rows.Count > 0)
         {
             rptDoc.Load(Server.MapPath("~/Reports/rptInventory.rpt"));
             rptDoc.SetParameterValue("@TYPE", type);
             rptDoc.SetParameterValue("@PRODUCTID", productid);
             rptDoc.SetDataSource(dt);
             rptDoc.SetDatabaseLogon("sa", "Pass2012", "GBLNJ4", "GPLS");
             rptDoc.DataSourceConnections[0].SetConnection("GBLNJ4", "GPLS", "sa", "Pass2012");
             CrystalReportViewer1.Page.Title = name;
             rptDoc.SummaryInfo.ReportTitle  = name;
             rptDoc.DataDefinition.FormulaFields["cTitle"].Text = "'" + name + "'";
             CrystalReportViewer1.ReportSource = rptDoc;
             Response.ClearContent();
             Response.ClearHeaders();
             Response.ContentType = "application/pdf";
             rptDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat,
                                         Response, true, name);
             CrystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
             CrystalReportViewer1.SeparatePages = true;
             CrystalReportViewer1.DataBind();
             CrystalReportViewer1.HasExportButton = false;
             Response.Flush();
             Response.Close();
         }
         else
         {
             ErrorMessage("Current selection does not have data");
         }
     }
     catch (System.Threading.ThreadAbortException)
     {
         // ignore it
     }
     catch (Exception ex)
     {
         ErrorMessage(ex.Message);
     }
 }