default.aspx文件
<style type="text/css">
#filter{ display:none; position:absolute;bottom:0px;right:0px; left:0px; top:0px; z-index:1000;background: #000000;filter:Alpha(opacity=30);opacity:0.3}
#promptbox{display:none; left:50%;top:50%;margin-left:-340px;margin-top:-150px; 680px; height:300px; z-index: 1001;
position: absolute; text-align: center; background-color: White; border:solid 1px #000; padding:0 0 10px}
.lefttit{ 60px; float:left}
#divtotallen{ 500px; height:20px; border:solid 1px #cccccc; float:left}
#divProgr{0px; height: 20px; background-color:Red; float:left}
#spJd{ float:left; 60px}
</style>
<script type="text/javascript">
function showFilter() {
document.getElementById('filter').style.display = 'inline';
document.getElementById('promptbox').style.display = 'inline';
}
function hidFilter() {
document.getElementById('filter').style.display = 'none';
document.getElementById('promptbox').style.display = 'none';
}
var Mouse_Obj = "none", _x, _y;
document.onmousemove=function(e) {
if (Mouse_Obj != "none") {
e = e ? e : window.event;
var obj = document.getElementById(Mouse_Obj);
obj.style.left = _x + e.clientX + "px";
obj.style.top = _y + e.clientY + "px";
event.returnValue = false;
}
}
document.onmouseup= function() {
Mouse_Obj = "none";
}
function m(o, e) {
e = e ? e : window.event;
Mouse_Obj = o;
var obj=document.getElementById(Mouse_Obj);
_x = obj.offsetLeft + 340; //这里的190是下面(syn.css) margin-left:-190px 的偏移值
_y = obj.offsetTop + 150; //这里的80是下面(syn.css) margin-top:-80px; 的偏移值
_x += -e.clientX;
_y += -e.clientY;
}
var strNewID = "";
window.attachEvent("onload", function () {
var obj = document.getElementById("<%=hidNewid.ClientID %>");
if (typeof (obj) != "undefined") {
strNewID = obj.value;
if (strNewID != "") {
showFilter();
GetStatus();
}
}
});
function GetXmlHttpObject() {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function GetStatus() {
var xmlHttp = GetXmlHttpObject();
if (xmlHttp == null) {
alert("您的浏览器不支持AJAX!");
return;
}
var url = "SynProgress.aspx";
url = url + "?id=" + strNewID;
url = url + "&r=" + Math.random();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
try {
var res = xmlHttp.responseText;
if (res != "") {
var ss = res.split("|");
var f = parseFloat(ss[0]);
ControlLableLen(f);
SetMsgValue(ss[1]);
if (f < 1) {
setTimeout(GetStatus, 1000);
}
else {
alert("同步完成!");
}
}
}
catch (ex) {
SetMsgValue("发生意外错误:"+ ex.message);
}
}
};
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function ControlLableLen(f) {
var obj = document.getElementById("divProgr");
var obj2 = document.getElementById("spJd");
var sLen = document.getElementById("divtotallen").clientWidth;
var ttLen = parseInt(sLen);
var jd = parseInt(ttLen * f);
obj.style.width = jd + "px";
obj2.innerHTML = parseInt(100 * f) + "%";
}
function SetMsgValue(msg) {
if (msg != "")
document.getElementById("txtMsg").value += msg;
}
</script>
<body>
<%--遮罩层开始--%>
<input runat="server" type="hidden" id="hidNewid" value="" />
<div id="filter">
</div>
<div id="promptbox" >
<div onmousedown="m('promptbox',event)" style="height: 24px; margin-bottom:20px; background-color: Blue; ">
<span onclick="hidFilter()" style="float: right; height: 24px; line-height:24px; background-color: Red;
font-size: 20px; font-weight: bolder; color: White; cursor:pointer;">×</span></div>
<div style="display:inline-block">
<span class="lefttit">当前进度:</span>
<div id="divtotallen">
<div id="divProgr">
</div>
</div>
<span id="spJd"></span>
</div>
<div style="margin-top:20px"><textarea id="txtMsg" rows="14" cols="100"></textarea> </div>
</div>
<%--遮罩层结束--%>
<asp:Button ID="btnBulkSyn" runat="server" OnClick="btnSyn_Click" OnClientClick="return checkSelect()"
Text="批量同步启动" />
<script>
function checkSelect() {
var ids = document.getElementsByName("ckbID");
if (ids.length > 0) {
for (var i = 0; i < ids.length; i++) {
if (ids[i].checked) return true;
}
}
alert("请选择最少一本书籍!");
return false;
}
</script>
</body>
default.aspx.cs 文件
protected void Page_Load(object sender, EventArgs e)
{
hidNewid.Value = "";
}
protected void btnSyn_Click(object sender, EventArgs e)
{
string newid = BulkAddProcess.AddNewProc(3);//分3步走
BlukSyn bs = new BlukSyn(dtBluk, dtSourceSub, sbSqlRunBefore, sbSqlRunAfter, newid);
Thread t = new Thread(new ThreadStart(bs.SynStart));
t.Start();
hidNewid.Value = newid;
}
BlukSyn.cs 类文件
public BlukSyn(DataTable drSourceMain, DataTable dtSourceSub, StringBuilder sbSqlRunBefore, StringBuilder sbSqlRunAfter,string proid)
{
this.dtSourceMain = drSourceMain;
this.dtSourceSub = dtSourceSub;
this.sbSqlRunBefore = sbSqlRunBefore;
this.sbSqlRunAfter = sbSqlRunAfter;
this.proid = proid;
}
public void SynStart()
{
BulkAddProcess.AddLog(proid,"数据处理开始...");
BulkAddProcess.AddLog(proid,"1开始...");
//......
BulkAddProcess.UpdateProc(proid,1);
BulkAddProcess.AddLog(proid,"1完成...");
BulkAddProcess.AddLog(proid,"2开始...");
//......
BulkAddProcess.UpdateProc(proid,2);
BulkAddProcess.AddLog(proid,"2完成...");
BulkAddProcess.AddLog(proid,"3开始...");
//......
BulkAddProcess.UpdateProc(proid,1);
BulkAddProcess.AddLog(proid,"3完成...");
BulkAddProcess.AddLog(proid,"数据处理完毕!");
}
SynProgress.aspx.cs 文件
string id
{
get
{
return Sxmobi.Tools.GetRequestVal("id", "");
}
}
protected void Page_Load(object sender, EventArgs e)
{
if(id!="")
Response.Write(BulkAddProcess.ReadProgress(id));
Response.End();
}
BulkAddProcess.cs 类文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Text;
class HSAttr
{
public float[] fs = new float[3];
public StringBuilder sbMsg = new StringBuilder();
public HSAttr()
{ }
}
public class BulkAddProcess
{
public static Hashtable hsRroc;
public static string AddNewProc(int iCounts)
{
Guid guid = Guid.NewGuid();
if (hsRroc == null)
hsRroc = new Hashtable();
HSAttr hsa = new HSAttr();
hsa.fs[0] = 0;
hsa.fs[1] = 0;
hsa.fs[2] = (float)iCounts;
hsRroc.Add(guid.ToString(), hsa);
return guid.ToString();
}
public static void UpdateProc(string newid)
{
HSAttr hsa = (HSAttr)hsRroc[newid];
hsa.fs[1] = hsa.fs[1] + 1;
hsa.fs[0] = hsa.fs[1] / hsa.fs[2];
hsRroc[newid] = hsa;
}
public static void UpdateProc(string newid,int iprg)
{
HSAttr hsa = (HSAttr)hsRroc[newid];
hsa.fs[1] = iprg;
hsa.fs[0] = hsa.fs[1] / hsa.fs[2];
hsRroc[newid] = hsa;
}
public static string ReadProgress(string newid)
{
string ret = "";
float f = 1;
try
{
if (hsRroc.Contains(newid))
{
HSAttr hsa = (HSAttr)hsRroc[newid];
float[] fs = (float[])hsa.fs;
f = fs[0];
ret = f + "|" + ReadLogAndClear(newid);
if ((int)fs[0] == 1) RemoveProc(newid);
}
else
{
ret = "1|";
}
}
catch(Exception ex)
{
ret = "1|" + ex.Message;
RemoveProc(newid);
}
return ret;
}
public static void AddLog(string newid,string msg)
{
HSAttr hsa = (HSAttr)hsRroc[newid];
hsa.sbMsg.Append(msg + "\r\n");
hsRroc[newid] = hsa;
}
public static string ReadLogAndClear(string newid)
{
HSAttr hsa = (HSAttr)hsRroc[newid];
string msg = hsa.sbMsg.ToString();
hsa.sbMsg = new StringBuilder();
hsRroc[newid] = hsa;
return msg;
}
public static void RemoveProc(string newid)
{
if (hsRroc == null) return;
if (hsRroc.ContainsKey(newid))
hsRroc.Remove(newid);
}
}