Пример #1
0
        /// <summary>
        /// 產生PDF檔案
        /// </summary>
        private void RrintToPDF()
        {
            // 匯出檔名的設定
            string sReportFileName  = @"\rpt\T022_rpt.rpt";
            string sMapPath         = Server.MapPath("");
            string sHost            = Request.Url.Host;
            string sApplicationPath = Request.ApplicationPath;
            string reportID         = DBCenter.GetSystemID();

            string sExportFileName = Server.MapPath("../../") + @"PDF\T022_rpt" + reportID + ".pdf";
            string strPath         = sMapPath + sReportFileName;
            string ReportPath      = "http://" + sHost + sApplicationPath + "/PDF/T022_rpt" + reportID + ".pdf";

            DataSet dsLot = (DataSet)Session["T022View"];

            rptdoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

            rptdoc.Load(strPath);
            rptdoc.SetDataSource(dsLot);

            // 設定匯出路徑及檔名
            DiskFileDestinationOptions df = new DiskFileDestinationOptions();

            df.DiskFileName = sExportFileName;
            rptdoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
            rptdoc.ExportOptions.ExportFormatType      = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
            rptdoc.ExportOptions.DestinationOptions    = df;
            rptdoc.Export();
            rptdoc.Dispose();

            //打開文件
            Response.Write("<script>window.open('" + ReportPath + "','_blank','resizable,scrollbars=no,menubar=no,toolbar=no,location=no,status=no',false);</script> ");

            Response.Write("<script>window.close();</script>");
        }
Пример #2
0
 protected void btn_Export_Click(object sender, EventArgs e)
 {
     try
     {
         RoutewisePaymentAbstract();
         ExportOptions CrExportOptions;
         DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
         PdfRtfWordFormatOptions    CrFormatTypeOptions          = new PdfRtfWordFormatOptions();
         DateTime frmdate = DateTime.ParseExact(txt_FromDate.Text, "dd/MM/yyyy", null);
         string   fdate   = frmdate.ToString("dd" + "_" + "MM" + "_" + "yyyy");
         DateTime todate  = DateTime.ParseExact(txt_ToDate.Text, "dd/MM/yyyy", null);
         string   tdate   = todate.ToString("dd" + "_" + "MM" + "_" + "yyyy");
         string   CurrentCreateFolderName = fdate + "_" + tdate + "_" + DateTime.Now.ToString("ddMMyyyy");
         string   path = @"C:\BILL VYSHNAVI\" + ccode + "_" + "_" + pcode + CurrentCreateFolderName + "\\";
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         CrDiskFileDestinationOptions.DiskFileName = path + ccode + "_" + pcode + "_" + "RoutewiseAbstract.pdf";
         CrExportOptions = cr.ExportOptions;
         {
             CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
             CrExportOptions.ExportFormatType      = ExportFormatType.PortableDocFormat;
             CrExportOptions.DestinationOptions    = CrDiskFileDestinationOptions;
             CrExportOptions.FormatOptions         = CrFormatTypeOptions;
         }
         cr.Export();
         WebMsgBox.Show("Report Export Successfully...");
         string             MFileName = @"C:/BILL VYSHNAVI/" + ccode + "_" + "_" + pcode + CurrentCreateFolderName + "/" + ccode + "_" + pcode + "_" + "RoutewiseAbstract.pdf";
         System.IO.FileInfo file      = new System.IO.FileInfo(MFileName);
         if (File.Exists(MFileName.ToString()))
         {
             FileStream sourceFile = new FileStream(file.FullName, FileMode.Open);
             float      FileSize;
             FileSize = sourceFile.Length;
             byte[] getContent = new byte[(int)FileSize];
             sourceFile.Read(getContent, 0, (int)sourceFile.Length);
             sourceFile.Close();
             Response.ClearContent(); // neded to clear previous (if any) written content
             Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
             Response.AddHeader("Content-Length", file.Length.ToString());
             Response.ContentType = "text/plain";
             Response.BinaryWrite(getContent);
             File.Delete(file.FullName.ToString());
             Response.Flush();
             Response.End();
         }
         else
         {
             Response.Write("File Not Found...");
         }
     }
     catch (Exception ex)
     {
         WebMsgBox.Show("Please Check the ExportPath...");
     }
 }
Пример #3
0
        public void RPT_Sub(Int64 QuotationID, string Code, Boolean _IsList)
        {
            DataTable dt = new DataTable();

            LogoBind(dt);
            mpdfFile = CurrentUser.DocumentPath + @"pdf\Quotation.pdf";
            DataTable dtReport = new DataTable();

            dtReport = CommSelect.SelectRecord(QuotationID, "rpt_Quotation", "Quotation - Report");

            DataTable           dtTNC = new DataTable();
            NameValueCollection para  = new NameValueCollection();

            para.Add("@i_Code", Code);
            para.Add("@i_TNC_Sub", "Quotation");

            dtTNC = objDA.ExecuteDataTableSP("rpt_Quotation_TNC", para, false, ref mException, ref mErrorMsg, "Quotation TNC");

            DataTable dtCompany = new DataTable();

            dtCompany = objDA.ExecuteDataTableSP("rpt_Company", null, false, ref mException, ref mErrorMsg, "Quotation TNC");
            //dtReport.TableName = "Quotation";
            //dtReport.WriteXmlSchema(@"D:\Quotation.xsd");

            if (CommSelect.Exception == null)
            {
                //if (TypeOFSale == "AMC")
                //{
                //    if (System.IO.File.Exists(CurrentUser.ReportPath + "rptQuotation_AMC.rpt"))
                //    {

                //        CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                //        rptDoc.Load(CurrentUser.ReportPath + "rptQuotation_AMC.rpt");

                //        //rptDoc.SetDatabaseLogon("sa", "Un!ek3RP");
                //        CurrentUser.AddReportParameters(rptDoc, dtReport, "", false, false, false, false, false, false, false, false, false, false, false);

                //        rptDoc.Database.Tables[1].SetDataSource(dtCompany);
                //        rptDoc.Subreports[0].DataSourceConnections.Clear();
                //        rptDoc.Subreports[0].Database.Tables[0].SetDataSource(dtTNC);
                //        rptDoc.Refresh();


                //        Reports.frmReportViewer fRptView = new Reports.frmReportViewer();
                //        fRptView.Text = "Quotation - [Page Size: A4]";
                //        fRptView.crViewer.ReportSource = rptDoc;
                //        if (_IsList == true)
                //        {
                //            fRptView.ShowDialog();
                //        }
                //        else if (_IsList == false)
                //        {
                //            ExportOptions CrExportOptions;
                //            DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                //            PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                //            CrDiskFileDestinationOptions.DiskFileName = mpdfFile;
                //            CrExportOptions = rptDoc.ExportOptions;//Report document  object has to be given here
                //            CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                //            CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                //            CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                //            CrExportOptions.FormatOptions = CrFormatTypeOptions;
                //            rptDoc.Export();

                //        }
                //    }
                //    else
                //    {
                //        MessageBox.Show("File is not exist...");
                //    }
                //}
                //else if (TypeOFSale != "AMC")
                //{
                if (System.IO.File.Exists(CurrentUser.ReportPath + "rptQuotation.rpt"))
                {
                    CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                    rptDoc.Load(CurrentUser.ReportPath + "rptQuotation.rpt");
                    //rptDoc.Subreports[0].DataSourceConnections.Clear();
                    rptDoc.Subreports[0].Database.Tables[0].SetDataSource(dtTNC);

                    rptDoc.Database.Tables[1].SetDataSource(dtCompany);
                    rptDoc.Database.Tables[2].SetDataSource(dt);
                    rptDoc.Refresh();
                    CurrentUser.AddReportParameters(rptDoc, dtReport, "", false, false, false, false, false, false, false, false, false, false, false);
                    CurrentUser.AddExtraParameter(rptDoc);
                    if (CurrentCompany.Com_Profile != null || CurrentCompany.Com_Profile.Trim() != "")
                    {
                        rptDoc.SetParameterValue("pCompanyProfile", CurrentCompany.Com_Profile);
                    }
                    Reports.frmReportViewer fRptView = new Reports.frmReportViewer();
                    fRptView.Text = "Quotation - [Page Size: A4]";
                    fRptView.crViewer.ReportSource = rptDoc;

                    if (_IsList == true)
                    {
                        fRptView.ShowDialog();
                    }
                    else if (_IsList == false)
                    {
                        ExportOptions CrExportOptions;
                        DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                        PdfRtfWordFormatOptions    CrFormatTypeOptions          = new PdfRtfWordFormatOptions();
                        CrDiskFileDestinationOptions.DiskFileName = mpdfFile;
                        CrExportOptions = rptDoc.ExportOptions;//Report document  object has to be given here
                        CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                        CrExportOptions.ExportFormatType      = ExportFormatType.PortableDocFormat;
                        CrExportOptions.DestinationOptions    = CrDiskFileDestinationOptions;
                        CrExportOptions.FormatOptions         = CrFormatTypeOptions;
                        rptDoc.Export();
                    }
                }
                else
                {
                    MessageBox.Show("File is not exist...");
                }
                //}
            }
        }
Пример #4
0
        public void RPT_Sub(Int64 PIID, string PurchaseCode, Boolean _IsList)
        {
            mpdfFile = CurrentUser.DocumentPath + @"pdf\Purchase.pdf";
            DataTable dt = new DataTable();

            LogoBind(dt);
            //if (dgvPurchaseInvoice.CurrentRow != null)
            //{
            DataTable           dtReport = new DataTable();
            DataTable           dtTNC    = new DataTable();
            NameValueCollection para     = new NameValueCollection();

            para.Add("@i_Code", PurchaseCode);
            para.Add("@i_TNC_Sub", "Purchase");
            para.Add("@i_CompId", CurrentCompany.CompId.ToString());
            dtTNC = objDA.ExecuteDataTableSP("rpt_Purchase_TNC", para, false, ref mException, ref mErrorMsg, "Purchase TNC");
            //NameValueCollection para = new NameValueCollection();
            //para.Add("@i_RecID", Convert.ToInt64(dgvPurchaseInvoice.CurrentRow.Cells["PIID"].Value).ToString());

            //dtReport = objList.ListOfRecord("rpt_PO", para, "PurchaseInvoice - Report");
            dtReport = CommSelect.SelectRecord(PIID, "rpt_PO", "PurchaseInvoice - Report");

            if (CommSelect.Exception == null)
            {
                if (System.IO.File.Exists(CurrentUser.ReportPath + "rptPurchaseInvoice.rpt"))
                {
                    //dtblPurchaseInvoice.TableName = "PORegister";
                    //dtblPurchaseInvoice.WriteXmlSchema(@"D:\ERP-CRM\Reports Project\POL_IGMS_Reports\DataSets\PORegister.xsd");
                    CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                    rptDoc.Load(CurrentUser.ReportPath + "rptPurchaseInvoice.rpt");

                    rptDoc.Subreports[0].Database.Tables[0].SetDataSource(dtTNC);

                    rptDoc.Database.Tables[1].SetDataSource(dt);
                    rptDoc.Refresh();
                    CurrentUser.AddReportParameters(rptDoc, dtReport, "Purchase Order", true, true, true, true, true, true, true, true, true, true, false);
                    //CurrentUser.AddExtraParameter(rptDoc);
                    Reports.frmReportViewer fRptView = new Reports.frmReportViewer();
                    fRptView.Text = "Purchase Order - [Page Size: A4]";
                    fRptView.crViewer.ReportSource = rptDoc;
                    if (_IsList == true)
                    {
                        fRptView.ShowDialog();
                    }
                    else if (_IsList == false)
                    {
                        ExportOptions CrExportOptions;
                        DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                        PdfRtfWordFormatOptions    CrFormatTypeOptions          = new PdfRtfWordFormatOptions();
                        CrDiskFileDestinationOptions.DiskFileName = mpdfFile;
                        CrExportOptions = rptDoc.ExportOptions;//Report document  object has to be given here
                        CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                        CrExportOptions.ExportFormatType      = ExportFormatType.PortableDocFormat;
                        CrExportOptions.DestinationOptions    = CrDiskFileDestinationOptions;
                        CrExportOptions.FormatOptions         = CrFormatTypeOptions;
                        rptDoc.Export();
                    }
                }
                else
                {
                    MessageBox.Show("File is not exist...");
                }
            }
        }
Пример #5
0
        private void ConvertToPdf(string tran_id, string tran_cd, string sp_nm, string rep_nm, string rep_desc)
        {
            CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
            DataSet ds = objFLRep.REPORT_TRANSACTION(tran_id, tran_cd, sp_nm);

            CrystalDecisions.CrystalReports.Engine.ReportDocument doc;
            if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0)
            {
                doc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                doc.Load(AppDomain.CurrentDomain.BaseDirectory + objIni.GetKeyFieldValue("SQL", "initial catalog") + @"\" + rep_nm + ".rpt");
                doc.SetDataSource(ds.Tables[0]);
                //if (objLicense.License_code == "sZLKa7BcYsepmYbILRVBlg==")
                if (ObjBLFD.ObjLoginUser != null && (ObjBLFD.ObjLoginUser.License_type == "SUPPORT LICENSE" || ObjBLFD.ObjLoginUser.License_type == "DEMO LICENSE"))
                {
                    Report_Modification(doc);
                }

                Type           t = typeof(Company);
                PropertyInfo[] publicFieldInfos = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);

                ParameterFieldDefinitions crParameterdef;
                crParameterdef = doc.DataDefinition.ParameterFields;
                foreach (PropertyInfo field in publicFieldInfos)
                {
                    foreach (ParameterFieldDefinition def in crParameterdef)
                    {
                        if (null != field)
                        {
                            if (def.Name.Equals("ORG." + field.Name.ToLower()))                                                                                                                   // check if parameter exists in report
                            {
                                doc.SetParameterValue("ORG." + field.Name.ToLower(), field.GetValue(ObjBLFD.ObjCompany, null) == null ? string.Empty : field.GetValue(ObjBLFD.ObjCompany, null)); // set the parameter value in the report
                            }
                        }
                    }
                }
                string strApproval = string.Empty;
                //DataSet dsetTable = objDL_ADAPTER.dsquery("select i_approved from " + ObjBLFD.Main_tbl_nm + " main_tbl inner join tran_set on main_tbl.tran_cd=tran_set.code where tran_set.isApprove=1 and tran_set.tran_type='Transaction' and "+objBLFD.Primary_id+"='" + tran_id + "' and tran_set.code='" + ObjBLFD.Code + "' and tran_set.compid=" + ObjBLFD.ObjCompany.Compid);
                //if (dsetTable != null && dsetTable.Tables.Count != 0 && dsetTable.Tables[0].Rows.Count != 0)
                //{
                //    if (dsetTable.Tables[0].Rows[0]["i_approved"] != null && dsetTable.Tables[0].Rows[0]["i_approved"].ToString() != "" && bool.Parse(dsetTable.Tables[0].Rows[0]["i_approved"].ToString()))
                //    {
                //        strApproval = "APPROVE";
                //    }
                //    else
                //    {
                //        strApproval = "PENDING";
                //    }
                //}
                DataSet dsetTable1 = objDL_ADAPTER.dsquery("select code,Main_tbl_nm,Approve_tbl_nm,isReqAuthority from tran_set where isApprove=1 and tran_type='Transaction' and code='" + ObjBLFD.Code + "' and compid=" + ObjBLFD.ObjCompany.Compid);
                if (dsetTable1 != null && dsetTable1.Tables.Count != 0 && dsetTable1.Tables[0].Rows.Count != 0)
                {
                    DataSet dsetTable = new DataSet();
                    if (bool.Parse(dsetTable1.Tables[0].Rows[0]["isReqAuthority"] != null && dsetTable1.Tables[0].Rows[0]["isReqAuthority"].ToString() != "" ? dsetTable1.Tables[0].Rows[0]["isReqAuthority"].ToString() : "False"))
                    {
                        // dsetTable = objDL_ADAPTER.dsquery("select i_approved=case when(authorse_by='NOT APPLICABLE') then 1 else i_approved end from " + ObjBLFD.Main_tbl_nm + " main_tbl inner join tran_set on main_tbl.tran_cd=tran_set.code where tran_set.isApprove=1 and tran_set.tran_type='Transaction' and " + ObjBLFD.Primary_id + "='" + tran_id + "' and tran_set.code='" + ObjBLFD.Code + "' and tran_set.compid=" + ObjBLFD.ObjCompany.Compid);
                        dsetTable = objDL_ADAPTER.dsquery("select i_approved=case when(authorse_by='NOT APPLICABLE') then 'True' else i_approved end from " + ObjBLFD.Main_tbl_nm + " main_tbl where " + ObjBLFD.Primary_id + "='" + tran_id + "' and main_tbl.tran_cd='" + ObjBLFD.Code + "' and main_tbl.compid=" + ObjBLFD.ObjCompany.Compid);
                    }
                    else
                    {
                        //dsetTable = objDL_ADAPTER.dsquery("select i_approved from " + ObjBLFD.Main_tbl_nm + " main_tbl inner join tran_set on main_tbl.tran_cd=tran_set.code where tran_set.isApprove=1 and tran_set.tran_type='Transaction' and " + ObjBLFD.Primary_id + "='" + tran_id + "' and tran_set.code='" + ObjBLFD.Code + "' and tran_set.compid=" + ObjBLFD.ObjCompany.Compid);
                        dsetTable = objDL_ADAPTER.dsquery("select i_approved from " + ObjBLFD.Main_tbl_nm + " main_tbl where " + ObjBLFD.Primary_id + "='" + tran_id + "' and main_tbl.code='" + ObjBLFD.Code + "' and main_tbl.compid=" + ObjBLFD.ObjCompany.Compid);
                    }
                    if (dsetTable != null && dsetTable.Tables.Count != 0 && dsetTable.Tables[0].Rows.Count != 0)
                    {
                        if (dsetTable.Tables[0].Rows[0]["i_approved"] != null && dsetTable.Tables[0].Rows[0]["i_approved"].ToString() != "" && bool.Parse(dsetTable.Tables[0].Rows[0]["i_approved"].ToString()))
                        {
                            strApproval = "APPROVE";
                        }
                        else
                        {
                            strApproval = "PENDING";
                        }
                    }
                }
                foreach (ParameterFieldDefinition def in crParameterdef)
                {
                    if (def.Name.Equals("approval"))                    // check if parameter exists in report
                    {
                        doc.SetParameterValue("approval", strApproval); // set the parameter value in the report
                    }
                }
                crystalReportViewer1.ReportSource = doc;
                crystalReportViewer1.Visible      = false;

                CrystalDecisions.Shared.ExportOptions CrExportOptions;
                DiskFileDestinationOptions            CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();

                CrExportOptions = doc.ExportOptions;
                {
                    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

                    CrDiskFileDestinationOptions.DiskFileName = AppDomain.CurrentDomain.BaseDirectory + objBLFD.ObjCompany.Db_nm + "\\FILES\\" + rep_desc.Replace(" ", "_") + tran_id + tran_cd + ".pdf";
                    CrExportOptions.ExportFormatType          = ExportFormatType.PortableDocFormat;

                    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                    CrExportOptions.FormatOptions      = CrFormatTypeOptions;
                }
                doc.Export();

                if (_hashSendMailAttachements == null || !_hashSendMailAttachements.Contains(rep_nm.Replace(".rpt", "_") + tran_id + tran_cd))
                {
                    _hashSendMailAttachements[rep_nm.Replace(".rpt", "_") + tran_id + tran_cd] = AppDomain.CurrentDomain.BaseDirectory + objBLFD.ObjCompany.Db_nm + "\\FILES\\" + rep_desc.Replace(" ", "_") + tran_id + tran_cd + ".pdf";
                }
            }
            else
            {
                AutoClosingMessageBox.Show("error in report", "Error");
            }
        }
    protected void btn_Export_Click(object sender, EventArgs e)
    {
        try
        {
            pcode = ddl_plantcode.SelectedItem.Value;
            CurentRateChartCheck1();

            ExportOptions CrExportOptions;
            DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
            PdfRtfWordFormatOptions    CrFormatTypeOptions          = new PdfRtfWordFormatOptions();


            string path = @"C:\BILL VYSHNAVI\" + ccode + "_" + "_" + pcode + "\\";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            CrDiskFileDestinationOptions.DiskFileName = path + ccode + "_" + pcode + "_" + "CurrentRateChart.pdf";

            CrExportOptions = cr.ExportOptions;
            {
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType      = ExportFormatType.PortableDocFormat;
                CrExportOptions.DestinationOptions    = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions         = CrFormatTypeOptions;
            }
            cr.Export();
            WebMsgBox.Show("Report Export Successfully...");

            //
            string MFileName = string.Empty;

            MFileName = @"C:/BILL VYSHNAVI/" + ccode + "_" + "_" + pcode + "/" + ccode + "_" + pcode + "_" + "CurrentRateChart.pdf";

            System.IO.FileInfo file = new System.IO.FileInfo(MFileName);
            if (File.Exists(MFileName.ToString()))
            {
                //
                FileStream sourceFile = new FileStream(file.FullName, FileMode.Open);
                float      FileSize;
                FileSize = sourceFile.Length;
                byte[] getContent = new byte[(int)FileSize];
                sourceFile.Read(getContent, 0, (int)sourceFile.Length);
                sourceFile.Close();
                //
                Response.ClearContent(); // neded to clear previous (if any) written content
                Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.ContentType = "text/plain";
                Response.BinaryWrite(getContent);
                File.Delete(file.FullName.ToString());
                Response.Flush();
                Response.End();
            }
            else
            {
                Response.Write("File Not Found...");
            }
            //
        }
        catch (Exception ex)
        {
            WebMsgBox.Show("Please Check the ExportPath...");
        }
    }