将word文档转换为swf格式小程序---的公开部分代码

88 篇文章 0 订阅

前提是你电脑要安装FlashPaper程序,此程序是借助FlashPaper程序进行转换

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;

namespace To_WCF
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //FlashPaper的安装路径
        private string FlashPaper = @ConfigurationSettings.AppSettings["FlashPaper"].Trim();
        //转换模式
        private int modeType = Convert.ToInt32(ConfigurationSettings.AppSettings["ModeType"].Trim());

        //要转间隔时间,单位秒
        private int Click_Time = Convert.ToInt32(ConfigurationSettings.AppSettings["Click_Time"].Replace(" ", "")) * 1000;
        //超时,单位秒
        private int killer_Time = Convert.ToInt32(ConfigurationSettings.AppSettings["killer_Time"].Replace(" ", "")) * 1000;

        //要转换的文件夹路径
        private string FilePath = @ConfigurationSettings.AppSettings["FilePath"].Trim();
        //存放文件路径
        private string swfPath = @ConfigurationSettings.AppSettings["swfPath"].Trim();
        //文件类型
        private string FileType = ConfigurationSettings.AppSettings["ToType"].Replace(" ", "");

        //源文件类型
        private string file_Type = ConfigurationSettings.AppSettings["file_Type"].Replace(" ", "");

        //流程类型
        private string Flow_Type = ConfigurationSettings.AppSettings["Flow_Type"].Replace(" ", "").Replace("$", ",");

        //转换后的文件是否代原扩展名
        private string ExpandType = ConfigurationSettings.AppSettings["ExpandType"].Replace(" ", "");

        //转换后的文件是否代原扩展名
        private string html_URL = ConfigurationSettings.AppSettings["html_URL"].ToString();
        private string html_Path = ConfigurationSettings.AppSettings["html_Path"].ToString();

        //有效时间段
        private DateTime dt_Start = Convert.ToDateTime(ConfigurationSettings.AppSettings["StarTime_Changer"].Trim());
        private DateTime dt_End = Convert.ToDateTime(ConfigurationSettings.AppSettings["EndTime_Changer"].Trim());
        //不转换文件的标记
        private string NoChanger_File = ConfigurationSettings.AppSettings["NoChanger_File"].ToString();

        //是否只转换文件的标记
        int isSign = Convert.ToInt32(ConfigurationSettings.AppSettings["isSign"].ToString().Trim());
    
        System.Threading.Timer timer = null;
        System.Threading.Timer timerK = null;
        System.Threading.Timer timerUpdate = null;

        string fileInfo = string.Empty;
        public bool IsTurn = false;

        int i = Convert.ToInt32(ConfigurationSettings.AppSettings["Click_Time"].Replace(" ", "")) + 1;
        private class File_SWF
        {
            public string All_Name { set; get; }//文件名称
            public string FName { set; get; }//文件名称
            public string FID { set; get; }//
            public string FType { set; get; }//文件类型
            public int Flog { set; get; }//.swf 标记 0 不是,1swf
         
        }
        private class SWFFile
        {
            public string FileNames { set; get; }//文件名称
            public string FilePaths { set; get; }//文件路径
            public string SwfPaths { set; get; }//swf路径
            public string FileType { set; get; }//文件路径
        }
        private class DBFile
        {
            public int RunID { set; get; }//类型id
            public int TypeId { set; get; }//类型id
            public string New_FileName { set; get; }//新文件名称
            public int logID { set; get; }//文件转换标记 0未转换,1转换
            public string oldName { set; get; }//原文件名称
            public string FileName2 { set; get; }//文件名称 
            public string basePath2 { set; get; }//基础路径  
            public string filePath2 { set; get; }//绝对路径
            public string SwfPaths2 { set; get; }//swf路径
            public string fileType2 { set; get; }//文件路径
            public string DateTime2 { set; get; }//
        
         

        }
        private class NewDBFile
        {
            public int RID { set; get; }//类型id         
            public string New_Name { set; get; }//文件名称
            public string Number_ID{ set; get; }//文件名称 
            public string isLog{ set; get; }//修改标记,1是修改了
        

        }
        /// <summary>
        /// 执行FlashPaper进程
        /// </summary>
        /// <param name="sourceFileName">输入.doc文件路径</param>
        /// <param name="outPutFileName">输出.swf文件路径</param>
        public void ProcessExec(string sourceFileName, string outPutFileName)
        {

            if (!string.IsNullOrEmpty(FlashPaper))
            {

                ExistPath(swfPath);//不存此路径则创建

                //FlashPaper文件路径 可自行设置
                string flashPrinter = FlashPaper;

                Process pc = new Process();
                pc.StartInfo.FileName = flashPrinter;//程序路径和名称
                pc.StartInfo.Arguments = string.Format("{0} {1} -o {2}", "\"" + flashPrinter + "\"", "\"" + sourceFileName + "\"", "\"" + outPutFileName + "\"");

                pc.StartInfo.CreateNoWindow = true;//不创建窗口
                pc.StartInfo.UseShellExecute = false;//不使用系统外壳启动
                pc.StartInfo.RedirectStandardInput = false; //不重定向输入
                pc.StartInfo.RedirectStandardOutput = false;//不重定向输出
                pc.StartInfo.RedirectStandardError = true;
                pc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                try
                {
                    pc.Start();
                    while (!pc.HasExited)
                    {
                        continue;
                    }
                    System.Threading.Thread.Sleep(5000);
                    pc.WaitForExit();
                    pc.Close();
                    pc.Dispose();
                  
                }
                catch
                {
                   
                 
                }

            }
        }
        /// <summary>
        /// 转换后的文件名
        /// </summary>
        /// <param name="fName">文件名</param>
        /// <returns></returns>
        private string getFileNameType(string fName)
        {
            string fileName = "";
            try
            {
                if (!string.IsNullOrEmpty(fName))
                {
                    if (ExpandType == "0")
                    {
                        fileName = fName.Substring(fName.LastIndexOf("\\") + 1, (fName.LastIndexOf(".") - fName.LastIndexOf("\\") - 1));
                    }
                    else
                    {
                        fileName = fName;
                    }
                    if (!string.IsNullOrEmpty(FileType))
                    {
                        fileName = fileName + "." + FileType;
                    }
                    else
                    {
                        fileName =getSWFName( fName) ;
                    }
                }
            }
            catch { }
            return fileName;

        }
        /// <summary>
        /// 得到SWF文件名称
        /// </summary>
        /// <param name="nAme"></param>
        /// <returns></returns>
        private string getSWFName(string nAme)
        {
            string strName = "";

            if (!string.IsNullOrEmpty(nAme))
            {
                strName = nAme + ".swf";
            }
            return strName;
        }
        /// <summary>
        /// 得到SWF文件名称
        /// </summary>
        /// <param name="nAme"></param>
        /// <returns></returns>
        private string getHtml_Name(string nAme)
        {
            string strName = "";

            if (!string.IsNullOrEmpty(nAme))
            {
                strName = nAme + ".html";
            }
            return strName;
        }
        /// <summary>
        /// 文件名 0只有文件名无扩展名
        /// </summary>
        /// <param name="type">0只有文件名无扩展名,其它带扩展名</param>
        /// <param name="fName">文件名称</param>
        /// <returns></returns>
        private string getFileNameType(int type, string fName)
        {
            string fileName = "";
            try
            {
                if (!string.IsNullOrEmpty(fName))
                {
                    if (ExpandType == type.ToString())
                    {
                        fileName = fName.Substring(fName.LastIndexOf("\\") + 1, (fName.LastIndexOf(".") - fName.LastIndexOf("\\") - 1));
                    }
                    else
                    {
                        fileName = fName;
                    }
                }
            }
            catch { }
            return fileName;

        }
        /// <summary>
        /// 得到一个文件下的所有文件
        /// </summary>
        /// <param name="filePath"></param>
        private void GetAllFiles(string filePath, List<SWFFile> swfList)
        {
            try
            {
                DirectoryInfo dInfo = new DirectoryInfo(filePath);
                //遍历该文件夹
                GetFolder(dInfo, swfList);
            }
            catch { }
        }
        /// <summary>
        /// 得到所有文件夹
        /// </summary>
        /// <param name="dInfo">文件路径</param>
        private void GetFolder(DirectoryInfo dInfo, List<SWFFile> swfList)
        {
            try
            {
                //显示其中文件
                GetFile(dInfo, swfList);
                //遍历文件夹中的文件夹
                foreach (DirectoryInfo dir in dInfo.GetDirectories())
                {
                    //递归遍历该文件夹
                    GetFolder(dir, swfList);
                }
            }
            catch { }

        }
        /// <summary>
        /// 得到文件中文件
        /// </summary>
        /// <param name="dInfo">文件路径</param>
        private void GetFile(DirectoryInfo dInfo, List<SWFFile> swfList)
        {
            try
            {
                //遍历文件夹中的文件
                foreach (FileInfo file in dInfo.GetFiles())
                {
                    SWFFile sfile = new SWFFile()
                    {
                        FileNames = file.Name,
                        FilePaths = file.FullName,
                        SwfPaths = swfPath + getFileNameType(file.Name),
                        FileType = file.Name.Substring(file.Name.LastIndexOf("."), file.Name.Length - file.Name.LastIndexOf("."))
                    };
                    swfList.Add(sfile);
                    Application.DoEvents();
                }
            }
            catch { }
        }
        //,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

        /// <summary>
        /// 得到SWF文件夹下的所有文件
        /// </summary>
        /// <param name="filePath"></param>
        private void GetAllFiles_SWF(string filePath, List<File_SWF> swfList)
        {
            try
            {
                DirectoryInfo dInfo = new DirectoryInfo(filePath);
                //遍历该文件夹
                GetFolder_SWF(dInfo, swfList);
            }
            catch { }
        }
        /// <summary>
        /// 得到所有文件夹
        /// </summary>
        /// <param name="dInfo">文件路径</param>
        private void GetFolder_SWF(DirectoryInfo dInfo, List<File_SWF> swfList)
        {
            try
            {
                //显示其中文件
                GetFile_SWF(dInfo, swfList);
                //遍历文件夹中的文件夹
                foreach (DirectoryInfo dir in dInfo.GetDirectories())
                {
                    //递归遍历该文件夹
                    GetFolder_SWF(dir, swfList);
                }
            }
            catch { }

        }
        /// <summary>
        /// 得到文件中文件
        /// </summary>
        /// <param name="dInfo">文件路径</param>
        private void GetFile_SWF(DirectoryInfo dInfo, List<File_SWF> swfList)
        {
            try
            {
                //遍历文件夹中的文件
                foreach (FileInfo file in dInfo.GetFiles())
                {
                    File_SWF sfile = new File_SWF();                 
                    sfile.All_Name = file.Name.Trim();
                    string[] arryName = file.Name.Trim().Split('§');
                    if (arryName.Length >= 2)
                    {                       
                        sfile.FID = arryName[0];
                        sfile.FName = arryName[1].Replace (".swf","");
                    }
                    sfile.FType = file.Name.Substring(file.Name.LastIndexOf("."), file.Name.Length - file.Name.LastIndexOf("."));
                    if (sfile.FType.ToLower() == ".swf")
                    {
                        sfile.Flog = 1;
                    }
                    else
                    {
                        sfile.Flog = 0;
                    }
                    swfList.Add(sfile);
                    Application.DoEvents();
                }
            }
            catch { }
        }
        //,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
        /// <summary>
        ///  路径是否存在,不存在则创建此路径
        ///  存在返回True,否则返回false
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        private void ExistPath(string strPath)
        {
            DirectoryInfo dInfo = new DirectoryInfo(strPath);
            if (!dInfo.Exists)
            {
                dInfo.Create();//不存在则创建此路径
            }
        }
        /// <summary>
        /// 数据库中的文件信息
        /// </summary>
        /// <param name="dbFile">数组</param>
        /// <returns></returns>
        private List<DBFile> DataFile()
        {
            List<DBFile> dbFile = new List<DBFile>();
            try
            {
                if (!string.IsNullOrEmpty(Flow_Type))
                {
                    string strSql = "select  Run_ID,flow_id,attachment_id,attachment_name,BEGIN_TIME from flow_run  where attachment_name!='' and flow_id in(" + Flow_Type + ") order by  RUN_ID  desc";
                    DataTable dt = DataAccess.ExecuteAccessTable(strSql);
                    if (dt != null)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            string[] strArrayID = dt.Rows[i]["attachment_id"].ToString().Split(',');//ID数组
                            string[] strArrayName = dt.Rows[i]["attachment_name"].ToString().Split('*');//名称数组
                            if (strArrayID.Length > 0)
                            {
                                for (int j = 0; j < strArrayID.Length - 1; j++)
                                {
                                    DBFile dbf = new DBFile();

                                    dbf.RunID = Convert.ToInt32(dt.Rows[i]["Run_ID"]);
                                    dbf.TypeId = Convert.ToInt32(dt.Rows[i]["flow_id"]);
                                    dbf.oldName = strArrayName[j].ToString();
                                    dbf.FileName2 = strArrayID[j].Substring(strArrayID[j].LastIndexOf("_") + 1, (strArrayID[j].Length - strArrayID[j].LastIndexOf("_") - 1)) + "." + strArrayName[j];
                                    dbf.basePath2 = strArrayID[j].Substring(0, strArrayID[j].LastIndexOf("_")) + "\\";
                                    dbf.filePath2 = FilePath + dbf.basePath2 + dbf.FileName2;
                                    dbf.SwfPaths2 = swfPath + strArrayID[j].Substring(strArrayID[j].LastIndexOf("_")+1, strArrayID[j].Length - strArrayID[j].LastIndexOf("_")-1) + "§" + getSWFName(dbf.oldName.Trim());
                                    dbf.fileType2 = dbf.FileName2.ToString().Trim().Substring(dbf.FileName2.LastIndexOf("."), dbf.FileName2.Length - dbf.FileName2.LastIndexOf("."));
                                    dbf.DateTime2 = Convert.ToDateTime(dt.Rows[i]["BEGIN_TIME"]).ToString("yyyy-MM-dd");
                                    dbf.New_FileName =dbf.basePath2.Replace ("\\","_")+ strArrayName[j];
                                   
                                    dbFile.Add(dbf);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                timer = null;
                //MessageBox.Show("数据库连接配置有误!");

            }
            return dbFile;

        }


        /// <summary>
        /// 转换数据库中指明的类型文件
        /// </summary>
        private void TurnChangerSWF()
        {
            //数据库中的文件
            List<DBFile> dbFile_List = DataFile();
            try
            {
                for (int i = 0; i < dbFile_List.Count; i++)
                {
                    FileInfo fInfo = new FileInfo(dbFile_List[i].filePath2.Trim());
                    if (fInfo.Exists)//如果原文件存在
                    {
                        FileInfo files = new FileInfo(dbFile_List[i].SwfPaths2.Trim());
                        if (!files.Exists)
                        {
                            if (ExitFileType(dbFile_List[i].fileType2.Trim()))//过滤文件格式
                            {

                                if (isExitIn_Date(dbFile_List[i].DateTime2.ToString()))//在时间段内
                                {
                                    bool isBSign = BoolSign(isSign);//false,不转换带标记的,true 只转换带标记的
                                    if (isBSign)//true 只转换带标记的
                                    {
                                        if (isExit_Flog(dbFile_List[i].FileName2))//过滤标记不转换的文件
                                        {
                                            ///改生成html文件名
                                            CreatHtml(dbFile_List[i].basePath2.Trim(), html_URL.Trim(), dbFile_List[i].SwfPaths2.Trim());//生成html页面
                                            ProcessExec(dbFile_List[i].filePath2.Trim(), dbFile_List[i].SwfPaths2.Trim());//转换文件

                                        }

                                    }
                                    else
                                    {
                                        if (!isExit_Flog(dbFile_List[i].FileName2))//过滤标记不转换的文件
                                        {
                                            ///改生成html文件名
                                            CreatHtml(dbFile_List[i].basePath2.Trim(), html_URL.Trim(), dbFile_List[i].SwfPaths2.Trim());//生成html页面
                                            ProcessExec(dbFile_List[i].filePath2.Trim(), dbFile_List[i].SwfPaths2.Trim());//转换文件

                                        }
                                    }
                                }
                            }
                        }

                    }

                }
            
            }
            catch { }
          
          
        }
        /// <summary>
        /// 是否只转换带标记的,0不转换带标记的,1只转换带标记的。
        /// </summary>
        /// <param name="sign"></param>
        /// <returns></returns>
        private bool BoolSign(int sign)
        {
            if (sign == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        /// <summary>
        /// 转换数据库中指明的类型文件
        /// </summary>
        private List<DBFile> TurnChangerSWF(object obj)
        {
            //数据库中的文件
            List<DBFile> dbFile_List = DataFile();
            try
            {
                for (int i = 0; i < dbFile_List.Count; i++)
                {
                    FileInfo fInfo = new FileInfo(dbFile_List[i].filePath2.Trim());
                    if (fInfo.Exists)//如果原文件存在
                    {
                        FileInfo files = new FileInfo(dbFile_List[i].SwfPaths2.Trim());
                        if (!files.Exists)//如果html文件不存在
                        {
                         
                            if (ExitFileType(dbFile_List[i].fileType2.Trim()))//过滤文件格式
                            {
                                if (isExitIn_Date(dbFile_List[i].DateTime2.ToString()))//在时间段内
                                {
                                    if (!isExit_Flog(dbFile_List[i].FileName2))//过滤标记不转换的文件
                                    {
                                        dbFile_List[i].logID = 0;//0未转换,1转换
                                        dbFile_List[i].New_FileName =getHtml_Name(dbFile_List[i].basePath2.Replace("\\", "_") + getFileNameType(1, dbFile_List[i].FileName2));//转换后的文件名                                      
                                    
                                    }
                                    else
                                    {
                                        dbFile_List[i].logID = 0;//0未转换,1转换
                                    }
                                }
                                else
                                {
                                    dbFile_List[i].logID = 1;//0未转换,1转换
                                }
                            }
                            else
                            {
                                dbFile_List[i].logID = 1;//0未转换,1转换
                            }
                        }
                        else
                        {
                            dbFile_List[i].logID = 1;//0未转换,1转换
                        }

                    }

                }
            }
            catch { }
            return dbFile_List;
        }
        /// <summary>
        /// 是否为合法格式类型
        /// </summary>
        /// <param name="Ftype"></param>
        /// <returns></returns>
        private bool ExitFileType(string Ftype)
        {
            bool b = false;
            try
            {
                string[] arryFileType = file_Type.Split('$');
                if (arryFileType.Length > 0)
                {
                    for (int i = 0; i < arryFileType.Length; i++)
                    {
                        if (Ftype == arryFileType[i].Trim())
                        {
                            b = true;
                            break;
                        }
                    }
                }
            }
            catch { }
            return b;
        }
        /// <summary>
        /// 文件夹到文件夹转换
        /// </summary>
        private void TurnSWF_FileToFile(object obj)
        {
            try
            {
                List<SWFFile> sfile_list = new List<SWFFile>();
                GetAllFiles(FilePath, sfile_list);
                foreach (SWFFile sfile in sfile_list)
                {
                    FileInfo file = new FileInfo(sfile.SwfPaths);
                    if (!file.Exists)
                    {
                        if (ExitFileType(sfile.FileType))//过滤文件格式
                        {
                            if (IsTurn)
                            {
                                MessageBox.Show(sfile.FileNames);
                            }
                            else
                            {
                                ProcessExec(sfile.FilePaths.Trim(), sfile.SwfPaths.Trim());//转换文件
                            }

                        }
                    }

                }
            }
            catch { }
        }
        /// <summary>
        /// 是否存在FlashPaper进程
        /// </summary>
        /// <returns></returns>
        private bool isExitProcess()
        {

            bool b = false;
            try
            {
                System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("FlashPrinter");
                if (process.Length > 0)
                {
                    b = true;
                 

                }
                else
                {
                    b = false;
                 
                }
            }
            catch {
           
            }
            return b;
        }
        private void isExitProcess_world()
        {


            System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("winword");
            if (process.Length > 0)
            {
                foreach (System.Diagnostics.Process p in process)
                {
                    p.Kill();
                }
            }
        }

        /// <summary>
        /// 是否在转换的日期段内
        /// </summary>
        /// <param name="dateFile">文件日期</param>
        /// <returns></returns>
        private bool isExitIn_Date(string dateFile)
        {
            bool b = false;

            if (dt_Start == null || dt_End == null)
            {
                MessageBox.Show("转换文件的日期段不能为空,请配置!");
            }
            else
            {
                if (!string.IsNullOrEmpty(dateFile))
                {
                    DateTime dtF = Convert.ToDateTime(Convert.ToDateTime(dateFile).ToString("yyyy-MM-dd"));
                    if (dt_Start <= dtF && dtF <= dt_End)
                    {
                        b = true;
                    }
                }

            }
            return b;
        }
        /// <summary>
        /// 是否有标记文件,有true,
        /// </summary>
        /// <param name="FfileName">文件名称</param>
        /// <returns></returns>
        private bool isExit_Flog(string FfileName)
        {
            bool b = false;
            string flogs = NoChanger_File.Trim();
            if (string.IsNullOrEmpty(flogs))
            {
                b = false;
            }
            else
            {
                if (!string.IsNullOrEmpty(FfileName))
                {
                    if (FfileName.Contains(flogs))
                    {
                        b = true;
                    }
                    else
                    {
                        b = false;
                    }

                }
            }
            return b;
        }
        /// <summary>
        /// 生成html页面
        /// </summary>
        /// <param name="htmURL">配置的URL地址</param>
        /// <param name="IDpath">swf的路径</param>
        private void CreatHtml(string bathPath,string htmURL,string swfPathss)
        {
            try
            {
                //string pathss = Directory.GetCurrentDirectory();

                //StreamReader sr = new StreamReader(pathss+@"\D35FLASH\scan文档\基本信息.txt", Encoding.GetEncoding("GB2312"));

                //string wen = sr.ReadToEnd().Trim();
                //sr.Close();

                string filName = getFileNameType(0, swfPathss)+".swf";
                ExistPath(html_Path);//路径是否存在
                string htmlPPath = html_Path+bathPath;
                htmlPPath = @htmlPPath;
                //string s = htmlPPath + getFileNameType(0, filName.Substring(0, filName.LastIndexOf('.'))).Replace("§", ".") + ".html";

                string s = htmlPPath + getFileNameType(0, filName).Replace("§", ".") + ".html";

                string htmlPath = htmlPPath + getFileNameType(0, filName) + ".html";//html文件绝对路径

                string realPaths = htmURL + filName;
                string pwdPath = System.Web.HttpUtility.UrlEncode(realPaths, Encoding.GetEncoding("utf-8"));//swf加密后的路径

                if (!string.IsNullOrEmpty(htmURL))
                {
                    string dbString = " URL=" + htmURL + "=" + pwdPath + "\">";
                    //string dbString = "<embed src=\"" + realPaths + "\" autostart=\"true\" width=\"100%\" height=\"700px\"> ";
                    //StreamWriter sw = new StreamWriter(s, false, Encoding.GetEncoding("GB2312"));
                    //sw.Write(dbString);
                    //sw.Flush();
                    //sw.Close();
                    //string dbString = " URL=" + htmURL + "=" + pwdPath + "\">";

                    string dbString = "";
                    dbString += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=7\"><meta http-equiv=\"content-type\" content=\"text/html;charset=gb2312\">  ";
                    dbString += "<meta http-equiv=\"refresh\" content=\"0; URL=" + html_URL.Trim() + "=" + filName + "\">";                  
                    dbString += " </head><body></body></html>";
                    //string dbString2 = "<embed src=\"" + realPaths + "\" autostart=\"true\" width=\"100%\" height=\"700px\"> ";
                    StreamWriter sw = new StreamWriter(s, false, Encoding.GetEncoding("GB2312"));
                    sw.Write(dbString);
                    sw.Flush();
                    sw.Close();

                }
            }
            catch
            {

            }
        }
        /// <summary>
        /// 主程序
        /// </summary>
        /// <param name="obj"></param>
        protected void To_ChangerSWF(object obj)
        {
            try
            {
                if (!isExitProcess())
                {
                    if (modeType == 0)
                    {
                        TurnChangerSWF();
                       
                    }
                    else
                    {
                        TurnSWF_FileToFile("");
                    }
                }
            }
            catch { }

        }

        private void button4_Click(object sender, EventArgs e)
        {

            List<SWFFile> swfFileList = new List<SWFFile>();
            GetAllFiles(FilePath, swfFileList);
            this.dataGridView1.DataSource = swfFileList;

        }

 

        private void button5_Click(object sender, EventArgs e)
        {
            List<DBFile> dfile = TurnChangerSWF("");
            dataGridView1.DataSource = dfile;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            TurnChangerSWF();
            //ProcessExec(file.FullName,swfPath+getFileNameType(file.Name));//转换文件
        }
        private void button1_Click(object sender, EventArgs e)
        {
         
            //启动超时
            timerK = new System.Threading.Timer(new System.Threading.TimerCallback(ReStartProce), null, 0, killer_Time);
            //超时计时器
            timer2.Enabled = !timer2.Enabled;
            if (!timer2.Enabled)
            {
                i = Convert.ToInt32(ConfigurationSettings.AppSettings["killer_Time"].Replace(" ", "")) + 1;
            }
            //启动线程转换程序
            if (timer2.Enabled)
            {
                timer = new System.Threading.Timer(new System.Threading.TimerCallback(TurnSWF_FileToFile), null, 0, Click_Time);
                button1.Text = "转换中...";
            }
            else
            {
                button1.Text = "启动程序";
            
                if (timer != null)
                {
                    timer.Dispose();
                    timer = null;
                }
                if (timerK != null)
                {
                    timerK.Dispose();
                    timerK = null;
                }
                if (timer2 != null)
                {
                    timer2.Dispose();
                    timer2 = null;
                }
            }
         
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //启动超时
            timerK = new System.Threading.Timer(new System.Threading.TimerCallback(ReStartProce), null, 0, killer_Time);

            //计时器
            timer2.Enabled = !timer2.Enabled;
            if (!timer2.Enabled)
            {
                i = Convert.ToInt32(ConfigurationSettings.AppSettings["killer_Time"].Replace(" ", "")) + 1;
            }


            //启动线程转换程序
            if (timer2.Enabled)
            {
                timer = new System.Threading.Timer(new System.Threading.TimerCallback(To_ChangerSWF), null, 0, Click_Time);//转换程序
                timerUpdate = new System.Threading.Timer(new System.Threading.TimerCallback(update_Database), null, 0, Click_Time);//修改数据库
              
                button2.Text = "转换中...";
            }
            else
            {
                button2.Text = "启动程序";
                timerK = null;
                if (timer != null)
                {
                    timer.Dispose();
                    timer = null;
                }
                if (timerK != null)
                {
                    timerK.Dispose();
                    timerK = null;
                }
                if (timerUpdate != null)
                {
                    timerUpdate.Dispose();
                    timerUpdate = null;
                }
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //To_ChangerSWF("");

        }

        private void Form1_Load(object sender, EventArgs e)
        {
         
        }
        private void timer_killer_Tick(object sender, EventArgs e)
        {
            System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("FlashPrinter");
            if (process.Length > 0)
            {
                foreach (System.Diagnostics.Process p in process)
                {
                    p.Kill();
                }
            }
            isExitProcess_world();
 
        }

        private void timer_file_Tick(object sender, EventArgs e)
        {
            TurnSWF_FileToFile("");
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string pathss = Directory.GetCurrentDirectory();
            System.Diagnostics.Process.Start("IExplore.exe", pathss + @"\转换SWF程序使用说明.swf");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("FlashPrinter");
            if (process.Length > 0)
            {
                foreach (System.Diagnostics.Process p in process)
                {
                    p.Kill();
                }
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            --i;
            label1.Text = i.ToString();
            if (i <= 0)
            {
                i = (Click_Time / 1000) + 1;
            }
            CloseUser32();
          
        }
        /// <summary>
        /// 是否找到窗口 是true ,否false
        /// </summary>
        /// <param name="title">窗口标题</param>
        /// <param name="btnName">按钮名称</param>
        private bool  closeWindows_User32(string title,string btnName)
        {
            bool b = false;
            const int BM_CLICK = 0xF5;
            const int WM_CLOSE = 0x0010;
            IntPtr maindHwnd = DataAccess.FindWindow(null, title); //程序句柄
            if (maindHwnd != IntPtr.Zero)
            {
                IntPtr childHwnd = DataAccess.FindWindowEx(maindHwnd, IntPtr.Zero, null, btnName); //获得按钮的句柄
                if (childHwnd != IntPtr.Zero)
                {
                    DataAccess.SendMessage(childHwnd, BM_CLICK, 0, 0); //发送点击按钮的消息
                    b = true;
                }
                else
                {
                    b = false;
                }
            }
            else
            {
                b = false;
            }
            return b;
        }
        /// <summary>
        /// 关闭所有不必要的窗口
        /// </summary>
        /// <returns></returns>
        private bool CloseUser32()
        {
            bool b = false;
            while (closeWindows_User32("Macromedia FlashPaper", "确定"))
            {
                closeWindows_User32("Macromedia FlashPaper", "确定");
            }
            while (closeWindows_User32("Microsoft Office Word", "是(&Y)"))
            {
                closeWindows_User32("Microsoft Office Word", "是(&Y)");
            }
            while (closeWindows_User32("Microsoft Office Word", "确定"))
            {
                closeWindows_User32("Microsoft Office Word", "确定");
            }
            while (closeWindows_User32("文件正在使用", "确定"))
            {
                closeWindows_User32("文件正在使用", "确定");
            }
            while (closeWindows_User32("FlashPaper打印机错误。", "确定"))
            {
                closeWindows_User32("FlashPaper打印机错误。", "确定");
            }
            while (closeWindows_User32("另存为", "取消"))
            {
                closeWindows_User32("另存为", "取消");
            }
            while (closeWindows_User32("Microsoft Office Word", "打开(&O)"))
            {
                closeWindows_User32("Microsoft Office Word", "打开(&O)");
            }
            //if (closeWindows_User32("FlashPaper打印机错误。", "确定") == false && closeWindows_User32("Microsoft Office Word", "是(&Y)") == false && closeWindows_User32("文件正在使用", "确定") == false)
            //{
            //    b = true;
            //}
         
            
          
            return b;
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            ReStartProce("");
          
        }
        private void ReStartProce(object obj)
        {
            System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("FlashPrinter");
            if (process.Length > 0)
            {
                foreach (System.Diagnostics.Process p in process)
                {
                    p.Kill();
                }
            }
            isExitProcess_world();
        }
        private void button7_Click(object sender, EventArgs e)
        {

            List<NewDBFile> list_NewDBFile = new List<NewDBFile>();
            string strSql = "select RUN_ID,flow_id,attachment_id,attachment_name,BEGIN_TIME from flow_run  where attachment_name!='' and flow_id in(" + Flow_Type + ") order by  RUN_ID  desc";
            DataTable dt = DataAccess.ExecuteAccessTable(strSql);
            //string asd = "";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                int RID = Convert.ToInt32(dt.Rows[i]["RUN_ID"]);

                List<DBFile> dfile = TurnChangerSWF("");//已转换文件
                //string sb_ID = "";
                //string sb_Name = "";
                NewDBFile NewDb = new NewDBFile();              
                foreach (DBFile dbf in dfile)
                {
                    if (dbf.logID == 0)//0未转换,1转换
                    {
                        if (dbf.RunID == RID)
                        {

                            string s = dbf.New_FileName;
                            string[] ss = s.Split('.');
                            NewDb.RID = dbf.RunID;
                            NewDb.Number_ID += ss[0].ToString() + ",";
                            NewDb.New_Name += ss[1].ToString() + "." + getHtml_Name(ss[2].ToString()) + ",";
                            //sb_ID += ss[0].ToString() + ",";
                            // sb_Name += ss[1].ToString() + "." + ss[2].ToString()+".swf" + ",";
                            
                        }

                    }
                }
                if (!string.IsNullOrEmpty(NewDb.Number_ID))
                {
                    list_NewDBFile.Add(NewDb);
                }
            }               
            dataGridView1.DataSource = list_NewDBFile;
         

        }

        #region 检查XML文件是否存在

        private bool CheckFile()
        {
            try
            {
                if (System.IO.File.Exists("Restore.xml") == false)
                {
                    //CreateXml();
                    return false;
                }
                else
                {
                   
                    return true;
                    //AddXml();
                   
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        #endregion


        #region 获取xml数据

        private DataTable GetXml()
        {
            try
            {
                System.Data.DataSet AuthorsDataSet = new System.Data.DataSet();
                AuthorsDataSet.ReadXml("Restore.xml");
                DataTable dt = AuthorsDataSet.Tables[0];
                return dt;
            }
            catch
            {
                DataTable dt = new DataTable();
                return dt;
            }
        }

        #endregion


        private void button8_Click(object sender, EventArgs e)
        {
            //update_Database("");
            //string filName = getFileNameType(0, @"D:\MYOA\attach\swf\86878210§基本信息.txt.swf")+".swf";
            //MessageBox.Show(filName);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            List<File_SWF> list_swfF = new List<File_SWF>();
            GetAllFiles_SWF(swfPath,list_swfF);
            dataGridView1.DataSource = list_swfF;
            update_Database("");
        }
        /// <summary>
        /// 程序配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            timerK = new System.Threading.Timer(new System.Threading.TimerCallback(ReStartProce), null, 0, killer_Time);

            if (timer2.Enabled == true )
            {
                timer2.Enabled = false;
                i = Convert.ToInt32(ConfigurationSettings.AppSettings["killer_Time"].Replace(" ", "")) + 1;
                button2.Text = "启动程序";
                timerK = null;

                if (timer != null)
                {
                    timer.Dispose();
                    timer = null;
                }
                if (timerK != null)
                {
                    timerK.Dispose();
                    timerK = null;
                }
                if (timerUpdate != null)
                {
                    timerUpdate.Dispose();
                    timerUpdate = null;
                }
            }

           
            Form2 f = new Form2();
            if (f.ShowDialog() == DialogResult.OK)
            {
                //ReStartProce("");
            }

        }
      
    }
}

 

<?xml version="1.0"?>
<configuration>
  <appSettings>

    <!--FlashPaper的安装路径-->
    <add key="FlashPaper" value="D:\FlashPaper2.2\FlashPrinter.exe"/>
    <!--要转换的文件类型,格式文件类型加$,例:一个时.txt,多种类型.txt$.doc.$docx$.xls-->
    <add key="file_Type" value=".txt$.doc$.docx$.xls$.ppt$.pptx"/>
   
    <!--转换模式-->
    <!--0:在数据库中指定的文件类型,1:是文件夹到文件夹-->
    <add key="ModeType" value="0"/>
    <!--流程类型,只可填写类型ID号,数字加$ 。格式如:例一:8 ; 例二:1$2$6。 -->
    <add key="Flow_Type" value="1$8$21$12"/>
    <!--有效日期范围 Changer_StarTime:开始时间,Changer_EndTime:结束时间.时间格式:yyyy-MM-dd 如:2012-01-01-->
    <add key="StarTime_Changer" value="2011-10-01"/>
    <add key="EndTime_Changer" value="2013-01-10"/>
    <!--不转换的文件标记-->
    <add key="NoChanger_File" value="$不转$"/>
   
    <!--间隔时间,单位秒.为空则执行一次-->
    <add key="Click_Time" value="60"/>
    <!--设置超时-->
    <add key="killer_Time" value="60"/>

    <!--转换格式swf或pdf-->
    <add key="ToType" value="swf"/>
    <!--要转换的文件夹路径-->
    <add key="FilePath" value="D:\MYOA\attach\workflow\"/>
    <!--存放文件路径-->
    <add key="swfPath" value="D:\MYOA\webroot\swf\"/>

    <!--生成Html文件-->
    <add key="html_URL" value=">
    <add key="html_Path" value="D:\attach\workflow\"/>
 


    <!--转换后的文件是否代原扩展名,0是否,1是有-->
    <add key="ExpandType" value="0"/>


    <!--是否只转换带标记的,0不转换带标记的,1只转换带标记的。-->
    <add key="isSign" value="1"/>
   
   

  </appSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bingo_BIG

你的鼓励是我最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值