<%@ Page Language="C#" AutoEventWireup="true" debug="true"  Inherits="WinLibClass.Form.Admin.EmailSend.Schedule" IsAdd="1" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	
<html  xmlns="http://www.w3.org/1999/xhtml">

<head >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>邮件发送进度......</title>

<script type="text/javascript" src="/Public/js/jquery.1.3.2.js"></script>
<script type="text/javascript" src="/artDialog4.1.1/artDialog.js?skin=default"></script>
<script type="text/javascript" src="/artDialog4.1.1/artDialog.iframeTools.js"></script>

<script type="text/javascript" src="/PaiPaiJS/Common_Main.js?t=2010"></script>
<script type="text/javascript" src="/PaiPaiJS/Common_Utils.js?t=2010"></script>

<link rel="stylesheet" href="../images/dlgbox.css" type="text/css" media="all" />

</head>



<script language="javascript">

var _TimeLength=10;
var _IdList = "1";

function AjaxUpdateUI(id,Vid)
{
	jQuery.ajax({
		type: "POST",
		url: "/admin/EmailSend/Update.aspx?IsAdd=20",
		data:{"VendueID":Vid,"id":id},
		cache: false,
		success: function(msg){
			Common.EditDialg ("EmailSendUpdate","批量发邮件管理 - 编辑",msg);
			if(jQuery("#IsChecked").val()==1)Common.EditDialgAddButtonEvent("EmailSendUpdate",'',null);
			else Common.EditDialgAddButtonEvent("EmailSendUpdate",'确定',SaveSub);
		}
	});
	//将本行设置为选中颜色
	SetActive(id);
}

function AjaxCreateSendQueryUI(id,Vid)
{
	jQuery.ajax({
		type: "POST",
		url: "/admin/EmailSend/CreateSendQuery.aspx?IsAdd=30",
		data:{"VendueID":Vid,"id":id},
		cache: false,
		success: function(msg){
			Common.EditDialg ("EmailSendUpdate","批量邮件生成",msg);
			if(jQuery("#IsChecked").val()==1)Common.EditDialgAddButtonEvent("EmailSendUpdate",'',null);
			else Common.EditDialgAddButtonEvent("EmailSendUpdate",'确定',SaveSub);
		}
	});
	//将本行设置为选中颜色
	SetActive(id);
}


//var _TimeLength = 10;

//2秒以下不启动
var _isSend=0;
function AjaxUpdateSchedule()
{
	
	jQuery.ajax({
		type: "POST",
		url: "/admin/EmailSend/Update.aspx?IsAdd=10",
		data:{"idlist":_IdList,"IsSend":0,"TimeLength":_TimeLength},
		cache: false,
		dataType:"json",
		success: function(msg){//json
			JsonFill(msg)
			if(_TimeLength>2)
			setTimeout(function(){AjaxUpdateSchedule()},1000* _TimeLength);
		},
		error:function (XMLHttpRequest, textStatus, errorThrown) {
		}
	});	
}

function GetIdList(){
	var tr =jQuery("tr[id^='tr_']");
	var s="";
	for(var i=0;i<tr.length;i++){s += ((i>0)?",":"") +  tr[i].id.substr(3)+"";}
	return s;	
}


function JsonFill(jsonList){
	var json ;
	for(var i =0;i<jsonList.length;i++)	{
		json = jsonList[i];
		var item = jQuery("#tr_"+json.id +"").find("td");
//		if(item.length>2)jQuery( item[2]).html(json.SendCount);
//		if(item.length>3)jQuery( item[3]).html(json.SendSuccessCount);
//		if(item.length>4)jQuery( item[4]).html(json.SendFailCount);
//		if(item.length>5)jQuery( item[5]).html(json.SendBackCount);
//
		if(item.length>2)jQuery( item[2]).html(json.sendcount);
		if(item.length>3)jQuery( item[3]).html(json.sendsuccesscount);
		if(item.length>4)jQuery( item[4]).html(json.sendfailcount);
		if(item.length>5)jQuery( item[5]).html(json.sendbackcount);

		if(item.length>6){ 
			var s = json.state;
			if(s==-1)jQuery(item[6]).html("暂不启动");
			else if(s==0)jQuery(item[6]).html("立即启动");
			else if(s==1)jQuery(item[6]).html("已添加发送队列");
			else if(s==4)jQuery(item[6]).html("发送完毕");
		}
	}
}

function StartAjax()
{
	_IdList = GetIdList();
	_TimeLength = jQuery("#Timer").val();
	if(_TimeLength>2)	
	AjaxUpdateSchedule();
}


function SetActive(id){
jQuery("tr").removeClass("SelectTr");
jQuery("#tr_"+id).addClass("SelectTr");
}

jQuery(document).ready(function(){
//SetActive(1);
//JsonFill(_json );
});
</script>



<body >



<div class="PageWidth PageTitle">

...邮件发送进度...<hr size="1" style="color:#DDDDDD" />


刷新频率：
<select id="Timer">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
</select>秒
<input type="button" value="发信" onclick="StartAjax();" />


</div>

<div class="PageWidth">

<table class="Table">

<tr>
<th>期号</th>
<th>产品</th>
<th>总邮件量</th>
<th>已成功量</th>
<th>失败量</th>
<th>退信量</th>
<th style="display:none">类型</th>
<th style="width:160px;">编辑</th>
<th style="display:none">删除</th>
</tr>

<asp:Repeater ID="rpList" runat="server">

<ItemTemplate>

<tr id="tr_<%#Eval("id")%>" >
<td><%#Eval("VendueId")%></td>
<td><%#Eval("ProductName")%></td>
<td><%#Eval("SendCount")%></td>
<td style="color:green"><%#Eval("SendSuccessCount")%></td>
<td style="color:red"><%#Eval("SendFailCount")%></td>
<td style="color:red"><%#Eval("SendBackCount")%></td>
<td style="display:none"><%#GetState(Eval("State"))%></td>

<td>
<input type="button" id="btnEdit" onclick="AjaxUpdateUI(<%#Eval("id")%>,<%#Eval("VendueId")%>);" value="编辑" />

<input type="button" id="btnEdit" onclick="AjaxCreateSendQueryUI(<%#Eval("id")%>,<%#Eval("VendueId")%>);" value="生成发送序列" />
</td>
<td style="display:none">&nbsp;</td>
</tr>
</ItemTemplate>

</asp:Repeater>


</table>


</div>
<div class=" PageWidth ">
<%=strPageInfo%>

</div>


</body>

</html>
