<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../Task/TaskConfig.asp"-->
<!--#include file="../HSK_Cls/HSK.CommonCls.asp"-->
<!--#include file="../HSK_Cls/HSK.AdministratorCls.asp"-->
<!--#include file="../HSK_Cls/HSK.Label.CommonCls.asp"-->
<!--#include file="Include/Session.asp"-->
<%
Dim HSKCls
Set HSKCls = New Admin_ExpressManage_Num
HSKCls.Run()
Set HSKCls = Nothing

Class Admin_ExpressManage_Num
        Private KS,KSCls
		Private totalPut,rs, Page, MaxPerPage,DomainStr,SearchType,SQLParam
		Private Sub Class_Initialize()
		  Set KS=New PublicCls
		  Set KSCls=New ManageCls
		End Sub
        Private Sub Class_Terminate()
		 Call CloseConn()
		 Set KS=Nothing
		 Set KSCls=Nothing
		End Sub
	
	Sub DoDel()		'删除任务
	Dim RSObj, ID ,Total_Point
	ID = KS.G("ID")
	IF KS.CheckOuterUrl()=False Then
		If ID <> "" Then
			Conn.Execute("Delete From Express_Num Where ID IN("& ID & ")")
			KS.AlertHintScript("删除成功！")
		Else
			KS.AlertHintScript("提交参数有误！")
		End If
	End If
	End Sub
	
	Sub DoAdd()
	%>
    <html>
<head><title>添加空包快递单</title>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<link href="include/Admin_Style.css" type=text/css rel=stylesheet>
<script src="../HSK_Js/jquery.js" type="text/javascript"></script>
<script src="../HSK_Js/common.js" language="JavaScript"></script>
<script language="javascript" src="../HSK_Js/popcalendar.js"></script>
</head>
<Script Language='javascript'>
function CheckForm(){
	var form=document.myform; 
	if (form.Express_Com.value==''){
		alert('请输入快递公司!');
		form.Express_Com.focus(); 
		return false;    }
	if (form.Express_Num.value==''){
		alert('请输入快递单号!');
		form.Express_Num.focus(); 
		return false;    }

	   form.submit();
	   return true;
}</Script>
<body leftMargin=2 topMargin=0 marginheight="0" marginwidth="0">
<%
Dim ID: ID = KS.S("ID")
If KS.S("Optype") = "Edit" Then
	 Set RS = Server.CreateObject("ADODB.RECORDSET")
	 Dim Sql: Sql = "Select * From Express_Num Where ID='" & ID & "'"
	 RS.Open Sql, conn, 1, 1
	If Not RS.EOF Then
		Dim Express_Com: Express_Com = Trim(RS("Express_Com"))
		Dim Express_Num: Express_Num = Trim(RS("Express_Num"))
		Dim ScanDate: ScanDate = Trim(RS("ScanDate"))
		Dim IsBuy: IsBuy = KS.ChkClng(RS("IsBuy"))
	End If
	RS.Close
	Set RS=Nothing
End If
%>
<table width='100%' border='0' align='center' cellpadding='1' cellspacing='1' class='ctable' style='margin-top:5px;border-collapse: collapse'>
<form action='?ID=<%=ID%>&page=<%=KS.S("p")%>' method='post' name='myform' onsubmit='return(CheckForm())'>
<input type='hidden' value='AddSave' name='action'>
<tr class='tdbg'>
	<td width='180' height='30' align='right' class='clefttitle'><strong>快递公司：</strong></td>
	<td><input name='Express_Com' value='<%=Express_Com%>' type='text' id='Express_Com' class='textbox'> <select name="expressid" id="expressid" onChange="myform.Express_Com.value=this.options[this.selectedIndex].value">
        <option selected="selected" value="">点这选择快递公司</option>
        <option value="顺丰快递">顺丰快递</option>
        <option value="韵达快递">韵达快递</option>
        <option value="圆通快递">圆通快递</option>
        <option value="EMS快递">EMS快递</option>
        <option value="中通快递">中通快递</option>
        <option value="天天快递">天天快递</option>
        <option value="汇通快递">汇通快递</option>
        <option value="申通快递">申通快递</option>
        <option value="宅急送快递">宅急送快递</option>
        </select></td>
</tr>
<tr class='tdbg'>
	<td width='180' height='30' align='right' class='clefttitle'><strong>快递单号：</strong><br>
	<font color="#FF0000">(可批量添加)</font></td>
	<td><textarea name="Express_Num" cols="50" rows="20" class="textarea" id="Express_Num" style="width:300px" title="一行一个单号，注意快递公司名别选错了呀！"><%=Express_Num%></textarea></td>
</tr>
<tr class='tdbg'>
	<td width='180' height='30' align='right' class='clefttitle'><strong>预计扫描时间：</strong></td>
	<td><input name='ScanDate' type='text' onClick="popUpCalendar(this, this, dateFormat,-1,-1)" id='ScanDate' value='<%
	If ScanDate<>"" Then
		KS.Echo ScanDate
	Else
		KS.Echo DateAdd("h", 6, Now())
	End If%>' class='textbox'> <a href='#' onClick="popUpCalendar(this, $('input[name=InputDate]').get(0), dateFormat,-1,-1)"><img src='Images/date.gif'  border='0' align='absmiddle' title='选择日期'></a>日期格式：年-月-日 时：分：秒</td>
</tr>
<tr class='tdbg'>
	<td width='180' height='30' align='right' class='clefttitle'><strong>初始状态设置：</strong></td>
	<td><select name="IsBuy">
	  <option value="0"<%If KS.ChkClng(IsBuy)=0 Then KS.Echo " selected"%>>未使用</option>
	  <option value="1"<%If KS.ChkClng(IsBuy)=1 Then KS.Echo " selected"%>>已使用</option>
	</select></td>
</tr>
</form>
</table>
<br>
<div id='save'>
<li class='parent' onClick="return(CheckForm())">
	<span class=child onMouseOver="this.parentNode.className='parent_border'" onMouseOut="this.parentNode.className='parent'"><img src='images/ico/save.gif' border='0' align='absmiddle'>确定保存</span>
</li>
<li class='parent' onClick="parent.closeWindow()">
    <span class=child onMouseOver="this.parentNode.className='parent_border'" onMouseOut="this.parentNode.className='parent'"><img src='images/ico/back.gif' border='0' align='absmiddle'>关闭取消</span>
</li>
</div>

  </body>
  </html>
	<%
	End Sub

'添加/编辑保存单号
Sub AddSave()
	If KS.CheckOuterUrl()=False Then
		Dim RS,Sql,i
		Dim ID: ID = KS.S("ID")
		Dim Express_Com: Express_Com = Trim(KS.S("Express_Com"))
		Dim Express_Num: Express_Num = Trim(KS.S("Express_Num"))
		Dim ScanDate: ScanDate = Trim(KS.S("ScanDate"))
		Dim IsBuy: IsBuy = KS.ChkClng(KS.S("IsBuy"))

		 If Express_Com = "" Or Express_Num = "" Then Call KS.AlertHistory("快递公司或单号不能为空，请返回审查!", -1): Exit Sub
		 If Not IsDate(ScanDate) Then Call KS.AlertHistory("预计扫描时间格式不对!", -1): Exit Sub
		 Express_Num = Split(Express_Num, vbCrlf)
		 Set RS = Server.CreateObject("ADODB.RECORDSET")
		 For i = 0 To Ubound(Express_Num)
		 If Not KS.IsNul(Express_Num(i)) Then
			 If ID = "" Then
				 Sql = "Select Top 1 * From Express_Num Where Express_Num='" & Express_Num(i) & "'"
				 RS.Open Sql, conn, 1, 3
				 If Not RS.Eof Then
					RS.Close
					Set RS = Nothing
					Call KS.AlertHistory("抱歉！第" & i + 1 & "条单号：" & Express_Num(i) & " 已存在，不可重复添加!", -1)
					Exit Sub
				 End If
				 RS.AddNew
			 Else
				 Sql = "Select Top 1 * From Express_Num Where ID=" & ID
				 RS.Open Sql, conn, 1, 3
				 If RS.EOF Then
					RS.Close
					Set RS = Nothing
					Call KS.AlertHistory("数据库中不存在该单号，请检查是否已被删除!", -1)
					Exit Sub
				 End If
			 End If
			  RS("Express_Com") = Express_Com
			  RS("Express_Num") = Express_Num(i)
			  RS("ScanDate") = ScanDate
			  RS("IsBuy") = IsBuy
			  RS("AddDate") = Now()
			  RS("AddIP") = KS.GetIP()
			  RS.Update
			  RS.Close
		  End If
		  Next
		  Set RS = Nothing
		  If ID = "" Then
			  KS.Echo ("<Script> if (confirm('单号添加成功,还继续添加吗?')) { location.href='?Action=Add';} else{top.frames[""MainFrame""].location.reload();}</script>")
		  Else
			  KS.Echo ("<Script> alert('单号修改成功！'); top.frames[""MainFrame""].location.reload();</script>")
		  End If
	End If
End Sub

Sub DoMod()
	Dim ID: ID=KS.ChkClng(KS.G("ID"))
	IF KS.CheckOuterUrl()=False Then
		Dim StatusID : StatusID = KS.ChkClng(KS.S("Status"))
		If ID <> 0 Then
			Conn.Execute("Update Express_Num Set IsBuy = " & StatusID & " Where ID=" & ID)
			KS.AlertHintScript("设置成功！")
		End If
	End If
End Sub
	
	
		Public Sub Run()
	    If Not (KS.ReturnPowerResult(0, "KMUA10007") or KS.ReturnPowerResult(5,"M510014"))Then
			  Call KS.ReturnErr(1, "")
		End If
		SearchType=KS.ChkClng(KS.G("SearchType"))
		Dim begindate:begindate=request("begindate")
		Dim enddate:enddate=request("enddate")

		Dim ID,Action : Action=KS.S("Action")
		IF Action="Add" Then
			Call DoAdd()
			Exit Sub
		ElseIf Action="AddSave" Then
			Call AddSave()
			Exit Sub
		ElseIf Action="Mod" Then
			Call DoMod()
			Exit Sub
		ElseIF Action="Del" And KS.G("ID") <>"" then
			Call DoDel()
			Exit Sub
		ElseIF Action="del" then	'暂时没用到
			Dim Param
			Select Case KS.ChkClng(KS.G("DelType"))
				Case 1 Param="datediff(" & DataPart_D & ",adddate," & SqlNowString & ")>3"
				Case 2 Param="datediff(" & DataPart_D & ",adddate," & SqlNowString & ")>5"
				Case 3 Param="datediff(" & DataPart_D & ",adddate," & SqlNowString & ")>10"
				Case 4 Param="datediff(" & DataPart_D & ",adddate," & SqlNowString & ")>30"
			End Select
			If Param<>"" Then
				Conn.Execute("Delete From Express_Num Where 1=1 and " & Param)
				KS.AlertHintScript "已按所选的条件，删除了相关记录！"
			End IF
			Exit Sub
		End If
		%>
<html>
<head><title>空包快递单管理</title>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<link href="include/Admin_Style.css" type=text/css rel=stylesheet>
<script src="../HSK_Js/jquery.js" type="text/javascript"></script>
<script src="../HSK_Js/common.js" language="JavaScript"></script>
<script language="JavaScript" src="../HSK_Js/HSK.Box.js"></script>
</head>
<body leftMargin=2 topMargin=0 marginheight="0" marginwidth="0">
  <div class="topdashed" style="padding:4px;">
  <table cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td>&nbsp; <a href="javascript:;" onClick="new KesionPopup().PopupCenterIframe('添加快递单','?Action=Add',620,500,'no')"><strong style="color:red">【添加空包快递单】</strong></a></td>
<FORM name="form2" action="?" method="post">
      <td style="border:1px #cccccc dashed">高级查询： 
<Select id=Field name=Field class='textbox'> 
  <Option value=1<%=KS.IIF(KS.ChkClng(KS.G("Field"))=1," selected","")%>>快递单号</Option> 
  <Option value=2<%=KS.IIF(KS.ChkClng(KS.G("Field"))=2," selected","")%>>订购人用户名</Option>
  <Option value=3<%=KS.IIF(KS.ChkClng(KS.G("Field"))=3," selected","")%>>快递公司名</Option>
</Select> 关键字：
  <Input id=Keyword class='textbox' maxLength=30 name=Keyword value="<%=KS.G("KeyWord")%>"> 
  <Input class='button' type=submit value=" 查 询 " name=Submit2> 
        <Input id=SearchType type=hidden value=5 name=SearchType> </td></FORM>
    </tr>
  </table>
  </div>

  <div style="border:1px #cccccc dashed;overflow:hidden"></div>
  
   <table width="100%" border="0">
<form action="?action=search&SearchType=100&Field=2" method=post name="myform">
   
   <tr>
     <td width="12%"><strong>按时间段查询</strong></td>
     <td width="48%">
       
       <table width="100%"  align="center" border=0 cellPadding=0 cellSpacing=0>
         <tr>
           <td nowrap="nowrap" class=form-left>起始日期：
             <%if isdate(begindate) then%>
             <input type="text" name="begindate" value="<%=begindate%>" size="12" class="form-input">
             <%else%>
             <input type="text" name="begindate" value="<%=year(now)&"-"&month(now)&"-1"%>" size="12" class="form-input">
             <%end if%>
            </td>    
		    <td  class=form-left>终止日期：  
		      <%if isdate(enddate) then%>            
		      <input type="text" name="enddate" value="<%=enddate%>" size="12" class="form-input">
		      <%else%>
		      <input type="text" name="enddate" value="<%=formatdatetime(now,2)%>" size="12" class="form-input">
		      <%end if%>
		      </td>    
			</tr>
        </table>	 </td>
     <td width="40%">订购人用户名：
      <input type="text" class='textbox' name="keyword" size="10" value="<%If KS.ChkClng(KS.G("Field"))=2 Then KS.Echo Request("keyword")%>" /> &nbsp;
      <input name="submit2" type="submit" value="按日期查找" class='button' />
      </td>
    </tr>
</form>
 </table>
<table width="100%">
    <tr>
      <td align=left>
	  <%
	  if begindate<>"" and enddate<>"" then
	   response.write "<br><div align=center style='font-size:14px'>"
	 response.write "查询时间段 <font color=red>" & begindate & "</font> 至 <font color=red>" & enddate & "</font><br></div>"
	  end if
	  %></td>
    </tr>
  </table>
  
  
  
  <table width="100%">
    <tr>
      <td align=left>您现在的位置：空包快递单管理&nbsp;&gt;&gt;&nbsp;
	  <%Dim SearchTypeStr,SQLStr,TotalPages
	    Dim KeyWord:KeyWord=Trim(KS.G("KeyWord"))
	  Select Case SearchType
		 Case 5 
		    Select Case KS.ChkClng(KS.G("Field"))
			  Case 1:SearchTypeStr="快递单号含有<font color=red>""" & KeyWord & """</font>"
			  Case 2:SearchTypeStr="订购人用户名含有<font color=red>""" & KeyWord & """</font>"
			  Case 2:SearchTypeStr="快递公司名含有<font color=red>""" & KeyWord & """</font>"
			End Select
		Case 100:SearchTypeStr="时间段查询结果"
	  End Select
	  Response.Write SearchTypeStr%></td>
    </tr>
  </table>
    <div style="border:1px #cccccc dashed;overflow:hidden"></div>

  <table cellSpacing=0 cellPadding=0 width="100%" border=0>
  <form name="selform" method="post" action="?action=Del">
    <tr class=sort align=middle>
	  <td width="4%" nowrap>选择</td>
      <td width="7%" height="25">ID号</td>
      <td width="10%">快递公司</td>
      <td width="14%">快递单号</td>
      <td width="15%">预计扫描日期</td>
      <td width="8%">是否使用</td>
      <td width="15%">订购人用户名</td>
      <td width="15%">订购时间</td>
      <td width="">操作</td>
    </tr>
	<%
			MaxPerPage=20
			Page = KS.ChkClng(KS.G("page"))
			If Page<=0 Then  Page = 1
			SqlParam="1=1"
            If SearchType<>"0" Then
			  Select Case SearchType

			  Case 5
			      Select Case KS.ChkClng(KS.G("Field"))
				   Case 1
				   	 If KS.IsNul(Keyword) Then Keyword = 0
				     SqlParam=SqlParam &" And Express_Num Like '%" & Keyword & "%'"
				   Case 2
				     SqlParam=SqlParam &" And BuyUserName Like '%" & Keyword & "%'"
				   Case 3
				     SqlParam=SqlParam &" And Express_Com Like '%" & Keyword & "%'"
				  End Select
			  Case 100
			  		If Keyword <> "" Then
				  		SqlParam=SqlParam &" And BuyUserName Like '%" & Keyword & "%'"
					End If
			  End Select
			End If
			If CInt(DataBaseType) = 1 Then         'Sql
				if isdate(begindate) then SqlParam=SqlParam & " and AddDate>='" & begindate & "'"
				if isdate(enddate) then enddate=DateAdd("d", 1,EndDate):SqlParam=SqlParam & " and AddDate<='" & enddate & "'"
			else
				if isdate(begindate) then SqlParam=SqlParam & " and AddDate>=#" & begindate & "#"
				if isdate(enddate) then enddate=DateAdd("d", 1,EndDate):SqlParam=SqlParam & " and AddDate<=#" & enddate & "#"
			end if


    If DataBaseType=1 Then
					Dim Cmd : Set Cmd = Server.CreateObject("ADODB.Command")
					Set Cmd.ActiveConnection=conn
					Cmd.CommandText="KS_GetPageRecords"
					Cmd.CommandType=4	
					CMD.Prepared = true 
					Cmd.Parameters.Append cmd.CreateParameter("@tblName",202,1,200)
					Cmd.Parameters.Append cmd.CreateParameter("@fldName",202,1,200)
					Cmd.Parameters.Append cmd.CreateParameter("@pagesize",3)
					Cmd.Parameters.Append cmd.CreateParameter("@pageindex",3)
					Cmd.Parameters.Append cmd.CreateParameter("@ordertype",3)
					Cmd.Parameters.Append cmd.CreateParameter("@strWhere",202,1,1000)
					Cmd.Parameters.Append cmd.CreateParameter("@fieldIds",202,1,1000)
					Cmd("@tblName")="Express_Num"
					Cmd("@fldName")= "ID"
					Cmd("@pagesize")=MaxPerPage
					Cmd("@pageindex")=page
					Cmd("@ordertype")=1
					Cmd("@strWhere")=SqlParam
					Cmd("@fieldIds")="*"
					Set Rs=Cmd.Execute
					Set Cmd = Nothing
	 Else
			SQLStr=KS.GetPageSQL("Express_Num","ID",MaxPerPage,Page,1,SqlParam,"*")
			Set RS = Server.CreateObject("AdoDb.RecordSet")
			RS.Open SQLStr, conn, 1, 1
	 End If
	If RS.Eof AND RS.Bof Then
	 Response.WRITE "<tr class=list onmouseover=""this.className='listmouseover'"" onmouseout=""this.className='list'""><td colspan=9 align=center height='25'>当前没记录或找不到" & SearchTypeStr & "!</td></tr></table></form>"
	Else
		totalPut = Conn.Execute("Select Count(0) From Express_Num Where " & SqlParam)(0)
		Call showContent()
	End If
	RS.Close:Set RS=Nothing
   %>
<br/>
	<br/>
<div class="attention">
<strong>特别建议：</strong>
过期三天以上的单号，建议停用或删除，以释放资源。
<br />

<iframe src='about:blank' style='display:none' name='_hiddenframe' id='_hiddenframe'></iframe>
<form action="?action=del" target="_hiddenframe" method=post onSubmit="return confirm('确实要删除有关记录吗？请慎重!')">
删除范围：<input name="deltype" type="radio" value=1>
3天前 
    <input name="deltype" type="radio" value="2" checked="checked" />
    5天前
    <input name="deltype" type="radio" value="3" />
    10天前
    <input name="deltype" type="radio" value="4" />
    1个月前
    <input type="submit" value="执行删除" class="button">
	</form>

	<br/>
</body>
</html>
   <%
   End Sub
  
  Sub ShowContent()
     on error resume next
     Dim I
     Do While Not rs.eof 
	%>
    <tr class=list onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'" onClick="$('#C<%=rs("id")%>').toggle()">
	  <td align="center" class="splittd"><input type="checkbox" name="ID" value="<%=rs("id")%>"></td>
      <td  class="splittd" align=middle><a href="javascript:;" onClick="new KesionPopup().PopupCenterIframe('编辑快递单','?Action=Add&Optype=Edit&ID=<%=rs("ID")%>',620,500,'no')"><%=rs("ID")%></a></td>
      <td  class="splittd" align=middle><a href="?SearchType=5&Field=3&KeyWord=<%=rs("Express_Com")%>"><%=rs("Express_Com")%></a></td>
      <td  class="splittd" align=middle><%=rs("Express_Num")%></td>
      <td  class="splittd" align=middle><%=rs("ScanDate")%></td>
      <td  class="splittd" align=middle><%
			  Select Case KS.ChkClng(rs("IsBuy"))
					Case 0
						KS.Echo "<span style=""color:blue"">未使用</span>"
					Case 1
						KS.Echo "<span style=""color:green"">已使用</span>"
			  End Select
		  %></td>
      <td  class="splittd" align=middle><a href="?SearchType=5&Field=2&KeyWord=<%=Rs("BuyUserName")%>"><%=rs("BuyUserName")%></a>&nbsp;</td>
      <td  class="splittd" align=middle><%=rs("BuyDate")%>&nbsp;</td>
      <td  class="splittd" align=center><a href="javascript:;" onClick="new KesionPopup().PopupCenterIframe('编辑快递单','?Action=Add&Optype=Edit&ID=<%=rs("ID")%>',620,500,'no')" title="请谨慎修改！">修改</a> | <a href="?Action=Del&ID=<%=rs("ID")%>" onClick="return confirm('您确定要删除吗？')" title="删除单号">删除</a></td>
    </tr>
    <tr id="C<%=rs("id")%>" bgcolor="#EEEEEE" style="display:none;">
      <td class="splittd" align=center colSpan=9>购买人IP：<%=rs("BuyIP")%> &nbsp; 单号添加日期：<%=rs("AddDate")%></td>
    </tr>
	<%
	I = I + 1
	RS.MoveNext
	If I >= MaxPerPage Then Exit Do
	loop
	%>
<tr>
	<td class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'" height='25' colspan=9>
	&nbsp;&nbsp;<input id="chkAll" onClick="CheckAll(this.form)" type="checkbox" value="checkbox"  name="chkAll">全选
    <input class="button" type="submit" name="Submit2" value=" 删除选中的任务 " onClick="{if(confirm('确定要删除选中的记录吗?')){this.document.selform.submit();return true;}return false;}"></td>
</tr>
</form>
<tr>
	<td colspan=11 align=right>
	<%
	 Call KSCLS.ShowPage(totalPut, MaxPerPage, "", True, "条", Page, KS.QueryParam("page"))
	%></td>
</tr>
</table>
		<%
		End Sub
		
End Class
%> 
