Asp.Net 實現線程傳遞多個參數。。。。。。。。。。。。。(並利用線程動態替代Word內的書籤等)

來源:互聯網
上載者:User

 

using System.IO;
using System.Threading;


            ThreadOutput to1 = new ThreadOutput();
            to1.picName = pic;
            to1.companyName = company;
            to1.chuName = chu;
            to1.traID = traid;
            Thread tThread = new Thread(new ThreadStart(to1.WordSaveAs));
            // 設定為後台線程,主要是為不影響主線程的結束
             tThread.IsBackground = true;
            tThread.Start();

 //*******************
    public class ThreadOutput
    {
        string pic = "";        //抬頭圖片
        string company = "";    //名稱 
        int travelid = -1;      //ID
        string chu = "";  //名稱

        /// <summary>
        /// 抬頭圖片
        /// </summary>
        public string picName
        {
            set { pic = value; }
        }
        /// <summary>
        /// 名稱
        /// </summary>
        public string companyName
        {
            set { company = value; }
        }
        /// <summary>
        /// ID
        /// </summary>
        public int tralID
        {
            set { travelid = value; }
        }
        /// <summary>
        /// 辦事處名稱
        /// </summary>
        public string chuName
        {
            set { banshichu = value; }
        }

        /// <summary>
        /// 要分割的字元
        /// </summary>
        /// <param name="txt">分割的字元</param>
        /// <param name="lex">所取的值</param>
        /// <returns></returns>
        public string splitText(object txt, int lex)
        {
            string label = txt.ToString();
            if (label != "")
            {
                string[] strArr = label.Split('&');

                if (strArr.Length >= lex)
                    return strArr[lex].ToString();
                else
                    return "";
            }
            else
            {
                return "";
            }
        }
  
        //另存抬頭
        public void WordSaveAs()
        {
      
            //擷取檔案清單 
            string sd = AppDomain.CurrentDomain.BaseDirectory + "travel_new\\doc\\";
            string[] files = Directory.GetFiles(sd); 

            foreach (string f in files)
            {
                if (f.LastIndexOf("\\") != -1)
                {
                    string strFile = f.Substring(f.LastIndexOf("\\") + 1);
                    string strLast = strFile.Substring(strFile.Length - 3, 3);
                    if (strLast.ToLower() == "doc")
                    {
                        string strName = strFile.Substring(0, strFile.Length - 4);
                        string fileName = strName + ".doc";//用戶端儲存的檔案名稱 
                        string filePath = AppDomain.CurrentDomain.BaseDirectory + "travel_new\\doc\\" + fileName;//路徑
                        if (company != "")
                        {
                            //判斷行程路線文檔說明是否存在,不存在則建立替代文檔,否則調用已存在的logo文檔。
                            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "travel_new\\doc\\logo\\" + strName + "_" + company + "_logo.doc") == false)
                            {
                                if (pic != "")
                                {
                                    if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\" + pic))
                                    {
                                        //進行logo標誌替代,並另存新檔新文檔。
                                        OutputWod.CreatWordDocument(strName, filePath, fileName, pic, company);
                                    }
                                }
                            }
                        }
                    }
                }
            }

        }
    }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.