Asp.Net 实现线程传递多个参数。。。。。。。。。。。。。(并利用线程动态替代Word内的书签等)
Posted on 2009-06-30 09:58 且行且思 阅读(1279) 评论(0) 编辑 收藏 举报
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);
}
}
}
}
}
}
}
}
}