public void GeneratePDF(string poId)
        {
            ReportDocument rptDoc = new ReportDocument();
            dsPSMS ds = new dsPSMS();
            DataTable dt = new DataTable();

            dt.TableName = "PO";
            dt = getAllPOs();

            ds.Tables["dtPO"].Merge(dt);

            //subreport data table
            dt = new DataTable();
            dt.TableName = "Terms";
            dt = getAllTerms();
            ds.Tables["dtTerms"].Merge(dt);

            rptDoc.Load(Server.MapPath("~/Reports/crPO.rpt"));
            rptDoc.SetDataSource(ds);

            string fileName = "PO" + poId + "_.pdf";

            String targetFolder = Server.MapPath(POAttachmentfolderPath);
            ExportOptions CrExportOptions;
            DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
            PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
            CrDiskFileDestinationOptions.DiskFileName = targetFolder + "\\" + fileName;
            CrExportOptions = rptDoc.ExportOptions;
            {
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions = CrFormatTypeOptions;
            }
            rptDoc.Export();

            string strFields = "";
            string[] strValues = new string[3];
            strFields = "[POID],[FilePath],[Note]";

            string filePath = POAttachmentfolderPath + "/" + fileName;
            string sqlStr = "select [FilePath] from [dbo].[POAttach] where [FilePath]=@FilePath";
            DataTable hasData = am.DataAccess.RecordSet(sqlStr, new string[] { filePath });
            if (hasData.Rows.Count == 0)
            {
                strValues = new string[] { poId.ToString() , filePath , txtAttachmentNote.Text.Trim() };
                am.DataAccess.BatchQuery.Insert("[dbo].[POAttach]", strFields, strValues);
                am.DataAccess.BatchQuery.Execute();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ReportDocument rptDoc = new ReportDocument();
            dsPSMS ds = new dsPSMS();
            DataTable dt = new DataTable();

            dt.TableName = "Items";
            dt = getAllItems();

            ds.Tables["dtItemInfo"].Merge(dt);

            rptDoc.Load(Server.MapPath("../Reports/crItemInfo.rpt"));

            rptDoc.SetDataSource(ds);
            CrystalReportViewer1.ReportSource = rptDoc;
        }
    public void PrintReport(Page _Page, string _ReportName, string _FileName, DataTable[] dts, string[] _DSTableName,
        string[] paramNames = null, string[] paramValues = null)
    {
        paramNames = paramNames == null ? new string[] { } : paramNames;
        paramValues = paramValues == null ? new string[] { } : paramValues;
        dts = dts == null ? new DataTable[] { } : dts;
        _DSTableName = _DSTableName == null ? new string[] { } : _DSTableName;

        ReportDocument rptDoc = new ReportDocument();
        try
        {
            rptDoc.Load(_Page.Server.MapPath("~/Reports/" + _ReportName));

            dsPSMS ds = new dsPSMS();
            for (int i = 0; i < dts.Length; i++)
            {
                ds.Tables[_DSTableName[i]].Merge(dts[i]);
            }
            if (dts.Length > 0)
                rptDoc.SetDataSource(ds);

            if (paramNames.Length == paramValues.Length)
            {
                for (int i = 0; i < paramNames.Length; i++)
                    rptDoc.SetParameterValue(paramNames[i], paramValues[i]);
            }

            rptDoc.SetDatabaseLogon(dbINFO._UID, dbINFO._PWD, dbINFO._SRV, dbINFO._CAT);
            _Page.Response.Buffer = false;
            _Page.Response.ClearContent();
            _Page.Response.ClearHeaders();
            //Export the Report to Response stream in PDF format and file name Customers
            rptDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, _Page.Response, true, _FileName);

            _Page.Response.ClearContent();
            _Page.Response.ClearHeaders();
            _Page.Response.Clear();
            _Page.Response.Close();
        }
        catch (Exception ex)
        {
            //DO NOTHING
        }
        finally
        {
            rptDoc.Close();
            rptDoc.Dispose();
        }
    }