my Code

jiansheng123 2008-07-24 08:37:21
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
var t;
function Stop()
{
window.clearInterval(t);
}
function StartCall()
{
t=window.setInterval(Call,500);
}

function Call()
{
if(document.getElementById("progressbar").style.width!="100%")
{
CallServer("", "");
}
else
{
window.clearInterval(t);
window.location.href="Display.aspx?parameter=load";
}

}
function LookUpStock()
{
window.setTimeOut(Call, 1000);

}

function ReceiveServerData(rValue)
{
document.getElementById("<%=lblSearchedItems.ClientID%>").innerText = rValue+"%";
document.getElementById("progressbar").style.width=rValue+"%";
document.getElementById("progressbar").style.backgroundColor="Silver";
}


</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button runat="server" ID="btnDoWork" OnClientClick="LookUpStock()" Text="Look Up Stock" OnClick="btnDoWork_Click" />
<asp:Button runat="server" ID="btnCancel" Text="Cancel" OnClick="btnCancel_Click" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<table>
<tr>
<td style="border: solid 1px #006BB2; border-top: none; background-color:#F5F5F5;">
<div style="float:left;width: 200px; text-align:left;">
<div id="progressbar" style="background-color:Silver; width:0%" > </div>
</div>
<div style="float:left; margin-left: -120px">
<asp:Label runat="server" ID="lblSearchedItems" Text="0"></asp:Label> /
<asp:Label runat="server" ID="lblToSearchItems"></asp:Label>
</div>
</td>
</tr>
</table>
</div>


</form>
</body>
private int amount = 0;
private static object obj = new object();
static Dictionary<string, Info> table = new Dictionary<string, Info>();

protected void Page_Load(object sender, EventArgs e)
{
//Response.Write("<script>alert('" + this.Session.SessionID + "');</script>");

String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
try
{
if (Request.QueryString["parameter"].ToString() != "")
{
LoadFile();
}
}
catch
{

}
}

public void DoWork(object session)
{
if (!table.ContainsKey(session.ToString()))
{
Info info1 = new Info();
table.Add(session.ToString(), info1);
}
string filepath = "C:\\test\\" + session.ToString() + "Testing.txt";
FileStream fs = new FileStream(filepath, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
string temp = "abcdefghijklmmopqrstuvwxyz\r\n";
for (int i = 1; i <= 10000; i++)
{

sw.WriteLine(temp);
if (i % 100 == 0)
{
lock (obj)
{
table[session.ToString()].Amount++;
}
Thread.Sleep(100);
}

}
sw.Flush();
sw.Close();
fs.Close();
}

public void RaiseCallbackEvent(String eventArgument)
{
//returnValue = amount.ToString();
}

public String GetCallbackResult()
{

return table[Session["Guid"].ToString()].Amount.ToString();
}


protected void btnDoWork_Click(object sender, EventArgs e)
{
Guid a =Guid.NewGuid();
Session["Guid"] = a;

Thread t = new Thread(DoWork);
t.Start(a);
//String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
//String callbackScript;
//callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + ";}";
//Response.Write("<script>" + callbackScript + "</script>");
//Response.Write("<script> function ReceiveServerData(rValue){ document.getElementById('<%=lblSearchedItems.ClientID%>').Text = rValue;}</script>");
//Response.Write("<script>CallServer(\"\", \"\");</script>");
amount = 0;
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", "window.onload = StartCall;", true);

}


public void LoadFile()
{
string saveFileName = "C:\\Testing.txt";

Response.Clear();
//// Set as Excel as the primary format
Response.AddHeader("Content-Type", "text/plain");
// Save the output as customer.csv
Response.AddHeader("Content-Disposition", "attachment;filename=" + saveFileName);
Response.WriteFile(saveFileName, true);
Response.Flush();
Response.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
protected void btnCancel_Click(object sender, EventArgs e)
{
//Thread.ResetAbort();
}
...全文
76 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
消火栓2019 2008-07-29
  • 打赏
  • 举报
回复
什么意思

3,242

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 SharePoint
社区管理员
  • SharePoint社区
  • 霖雨
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧