⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faxservice.cs

📁 faxcomlib + crystal report
💻 CS
字号:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using CrystalDecisions;
using System.Threading;

using FAXCOMLib;
using log4net;


namespace IFS.ReportFax
{

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class FaxService : System.Web.Services.WebService
    {
        //private System.Collections.ArrayList reportQueue;
        //public const string rootPath = "C:\\Inetpub\\wwwroot\\MyWebService1\\";

        private static log4net.ILog log;
        private static Thread heartBeatThread;
        private static bool runnable = false;

        public FaxService()
        {
        }

        public static void turnOff()
        {
            runnable = false;
        }

        /*[WebMethod]
        public void start()
        {
            if (log == null)
            {
                log = FaxUtil.getLogger();
            }

            if (heartBeatThread == null)
            {
                ThreadStart entryPoint = new ThreadStart(FaxHeartBeat.detectHeartBeat);
                heartBeatThread = new Thread(entryPoint);
                heartBeatThread.Name = "FaxHeartBeatThread";
                heartBeatThread.Start();
                log.Debug("The heartbeat begin.");
            }
            runnable = true;
        }*/

        private void setReportName(string fileName)
        {
            //reportQueue.Add(fileName);
        }

        [WebMethod]
        public int queryStatus(string fileName)
        {
            if (FaxSender.status == FaxStatus.SENDER_SENDING)
            {
                System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(FaxUtil.tempDir);
                System.IO.DirectoryInfo[] dir = dirInfo.GetDirectories();
                for (int i = 0; i < dir.Length; i++)
                    if (fileName.Equals(dir[i].ToString()))
                        return FaxStatus.FAX_SENT;
                return FaxStatus.FAX_UNSENT;
            }
            else
            {
                if (FaxSender.sendAll() == 1)
                    return queryStatus(fileName);
                else
                    return FaxStatus.FAX_ERROR;
            }
        }

        /*[WebMethod]
        public void convertRptToDoc(string fileName)
        {
            CrystalDecisions.Shared.ExportFormatType FileType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;

            CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();  
            report.Load(rootPath+fileName);

            //report.Load(Server.MapPath("CrystalReport.rpt"));


            System.IO.Stream stream = report.ExportToStream(FileType);
            report.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.WordForWindows, "C:\\Inetpub\\wwwroot\\MyWebService1\\" + "test.doc");
            //System.IO.FileStream fStream;

            ////System.IO.StreamWriter s = new System.IO.StreamWriter(stream);

            //System.IO.FileInfo fi = new System.IO.FileInfo(fileName);

            //System.IO.StreamWriter
            //byte[] bytes = new byte[stream.Length];
            //stream.Read(bytes, 0, bytes.Length);
            //stream.Seek(0, System.IO.SeekOrigin.Begin);
        
        }*/

        /*[WebMethod]
        public int docReciever(byte[] bStream, string docName)
        {
            //System.IO.FileInfo fi = new System.IO.FileInfo(fileName);
            //StreamManipulation
            //System.IO.Stream docStream = new System.IO.MemoryStream(bStream);

            //System.IO.StreamWriter docWriter = new System.IO.StreamWriter(rootPath + "tempFiles\\" + bStream.Length);//docName);
            //docWriter.Write(docStream.ToString());
            if (runnable == true)
            {
                try
                {
                    System.IO.FileStream docStream = new System.IO.FileStream(rootPath + "tempFiles\\" + docName, System.IO.FileMode.Create);
                    System.IO.BinaryWriter bDocWriter = new System.IO.BinaryWriter(docStream);
                    bDocWriter.Write(bStream);
                    bDocWriter.Close();
                    docStream.Close();
                    return FaxStatus.SERVICE_RECIEVED;
                }
                catch (Exception e)
                {
                    //if(e.))
                    log.Error("fail to receive the file: " + docName, e);
                    return FaxStatus.SERVICE_RUNNABLE_ERROR;
                }
            }
            else
                return FaxStatus.SERVICE_UNINIT;
        }*/

        [WebMethod]
        public string faxDocument(string filePath, string faxNumber)
        {
            FaxSender faxS = new FaxSender();

            return FaxSender.send(filePath, faxNumber);

        }

        [WebMethod]
        public int killAdobe()
        {
            try
            {
                foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcesses())
                    if (proc.ProcessName.ToLower().Equals("acrord32"))
                    {
                        proc.Kill();
                        return 1;
                    }
                return 0;
            }
            catch (Exception e)
            {
                log.Error("cannot kill proc. ", e);
            }

            return -1;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -