<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../HSK_Cls/HSK.CommonCls.asp"-->
<!--#include file="../HSK_Cls/HSK.Label.BaseFunCls.asp"-->
<!--#include file="../HSK_Cls/HSK.AdministratorCls.asp"-->
<!--#include file="../HSK_Cls/HSK.UpFileCls.asp"-->
<!--#include file="Include/Session.asp"-->
<%

Dim KSCls
Set KSCls = New Admin_EnterPrise
KSCls.HSK_Run()
Set KSCls = Nothing

Class Admin_EnterPrise
        Private KS,Param,KSCls
		Private Action,i,strClass,RS,SQL,maxperpage,CurrentPage,totalPut,TotalPageNum
        Private Sub Class_Initialize()
		  Set KS=New PublicCls
		  Set KSCls=New ManageCls
		  maxperpage = 30 '###每页显示数
		End Sub
        Private Sub Class_Terminate()
		 Call CloseConn()
		 Set KS=Nothing
		End Sub

		Public Sub HSK_Run()
			
		 If KS.G("action")="SearchUser" Then
		  SearchUser
		  Exit Sub
		 End If

		
		 With Response
			  If Not KS.ReturnPowerResult(0, "M520001") Then          '检查是权限
					 Call KS.ReturnErr(1, "")
					 .End
			  End If
			  .Write "<html>"
			  .Write"<head>"
			  .Write"<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">"
			  .Write"<link href=""Include/Admin_Style.CSS"" rel=""stylesheet"" type=""text/css"">"
			  .Write "<script src=""../HSK_JS/common.js"" language=""JavaScript""></script>"
			  .Write "<script language='JavaScript' src='../HSK_JS/Jquery.js'></script>" & vbCrLf
			  .Write"</head>"
			  .Write"<body leftmargin=""0"" topmargin=""0"" marginwidth=""0"" marginheight=""0"">"
			  .Write "<ul id='menu_top'>"
			  .Write "<li class='parent' onclick=""window.$(parent.document).find('#BottomFrame')[0].src='Split.asp?OpStr='+escape('商城系统 >> <font color=red>添加联盟店</font>')+'&ButtonSymbol=GOSave';location.href='?action=Add';""><span class=child onmouseover=""this.parentNode.className='parent_border'"" onMouseOut=""this.parentNode.className='parent'""><img src='images/ico/a.gif' border='0' align='absmiddle'>添加联盟店</span></li>"
			 

			  .Write "</ul>"
		End With
		
		If Not IsNumeric(Request("page")) And Len(Request("page")) <> 0 Then
			Response.Write ("错误的系统参数!请输入整数")
			Response.End
		End If
		If Not IsEmpty(Request("page")) And Len(Request("page")) <> 0 Then
			CurrentPage = CInt(Request("page"))
		Else
			CurrentPage = 1
		End If
        If CInt(CurrentPage) = 0 Then CurrentPage = 1
		Select Case KS.G("action")
		 Case "Add","Edit" Call CouponManage()
		 Case "EditSave" Call DoSave()
		 Case "Del"  Call CouponDel()
		 Case Else
		  Call showmain
		End Select
		
		
End Sub

Private Sub showmain()
        Param=" where 1=1"
		If KS.G("KeyWord")<>"" Then
		   Param= Param & " and title like '%" & KS.G("KeyWord") & "%'"
		End If

		totalPut = Conn.Execute("Select Count(id) From KS_ShopUnion " & Param)(0)
		TotalPageNum = CInt(totalPut / maxperpage)  '得到总页数
		If TotalPageNum < totalPut / maxperpage Then TotalPageNum = TotalPageNum + 1
		If CurrentPage < 1 Then CurrentPage = 1
		If CurrentPage > TotalPageNum Then CurrentPage = TotalPageNum
%>
<table width="100%" border="0" align="center" cellspacing="0" cellpadding="0">
<tr height="25" align="center" class='sort'>
	<td width='5%'>选择</td>
	<td>店名</td>
	<td>详细地址</td>
	<td>公交路线</td>
	<td>管理操作</td>
</tr>
<%
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "select * from KS_ShopUnion " & Param & " order by id desc"
	If DataBaseType = 1 Then
		If CurrentPage > 100 Then
			Rs.Open SQL, Conn, 1, 1
		Else
			Set Rs = Conn.Execute(SQL)
		End If
	Else
		Rs.Open SQL, Conn, 1, 1
	End If
	If Rs.bof And Rs.EOF Then
		Response.Write "<tr><td height=""25"" align=center bgcolor=""#ffffff"" colspan=7>到不起,找不到符合条件的加盟店！</td></tr>"
	Else
		If TotalPageNum > 1 then Rs.Move (CurrentPage - 1) * maxperpage
		i = 0
%>
<form name=selform method=post action=?action=Del>
<%
	Do While Not Rs.EOF And i < CInt(maxperpage)
		If Not Response.IsClientConnected Then Response.End
		
%>
<tr height="25" class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'">
	<td align="center" class="splittd"><input type=checkbox name=ID value='<%=rs("id")%>'></td>
	<td  class="splittd"><%=Rs("Title")%>
	</td>
	<td align="center" class="splittd"><%=Rs("Address")%></td>
	<td align="center" class="splittd"><%=KS.Gottopic(Rs("CarRoute"),50)%></td>
	
	<td align="center" class="splittd">
	
	<a href="?action=Edit&ID=<%=RS("ID")%>"  onclick="window.$(parent.document).find('#BottomFrame')[0].src='Split.asp?OpStr='+escape('商城系统 >> <font color=red>修改加盟店信息</font>')+'&ButtonSymbol=GOSave';">修改</a> <a href="?Action=Del&ID=<%=rs("id")%>" onclick="return(confirm('确定删除该加盟店吗？'));">删除</a> 
		
	

	</td>
</tr>
<%
		Rs.movenext
			i = i + 1
			If i >= maxperpage Then Exit Do
		Loop
	End If
	Rs.Close:Set Rs = Nothing
%>
<tr>
	<td class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'" height='25' colspan=7>
	&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=7 align=right>
	<%
	 Call KSCLS.ShowPage(totalPut, MaxPerPage, "ShopUnion.asp", True, "家", CurrentPage, KS.QueryParam("page"))
	%></td>
</tr>
</table>
<div>
<form action="ShopUnion.asp" name="myform" method="get">
   <div style="border:1px dashed #cccccc;margin:3px;padding:4px">
      &nbsp;<strong>快速搜索=></strong>
	 &nbsp;关键字:<input type="text" class='textbox' name="keyword">&nbsp;<input type="submit" value="开始搜索" class="button" name="s1">
    </div>
</form>
</div>

   <div style="border:1px dashed #cccccc;margin:3px;padding:9px">
    <b>调用代码：</b>请在商品内容页模板放上<font color=red>&lt;script src=&quot;/shop/UnionShop.asp?ProID={$InfoID}&quot;&gt;&lt;/script&gt;</font>进行调用。
   </div>
   <%
End Sub

Sub CouponManage()
Dim Title,ActiveDate,Address,CarRoute,Map
Dim ID:ID=KS.ChkClng(KS.G("ID"))
Dim RS:Set RS=server.createobject("adodb.recordset")
If KS.G("Action")="Edit" Then
	RS.Open "Select * From KS_ShopUnion Where ID=" & ID,conn,1,1
	 If RS.Eof And RS.Bof Then
	  RS.Close:Set RS=Nothing
	  Response.Write "<script>alert('参数传递出错！');history.back();</script>"
	  Response.End
	 Else
	   Title=RS("Title")
	   Address=RS("Address")
	   CarRoute=RS("CarRoute")
	   Map=RS("Map")
	 End If
Else
  Map="../images/nophoto.gif"
 End If
%>
<script>
function CheckForm()
{
	if ($('input[name=Title]').val()=='')
	{
	 alert('请输入店名称!');
	 $("input[name=Title]").focus();
	 return false;
	}
	if ($('input[name=Address]').val()=='')
	{
	 alert('请输入详细地址!');
	 $("input[name=Address]").focus();
	 return false;
	}
	$("form[name=myform]").submit();
}
</script>
<br>
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" class="ctable">
  <form name="myform" action="?action=EditSave" method="post"  enctype="multipart/form-data">
    <input type="hidden" value="<%=ID%>" name="id" />
    <input type="hidden" value="<%=request.servervariables("http_referer")%>" name="comeurl" />
    <tr class="tdbg" onmouseover="this.className='tdbgmouseover'" onmouseout="this.className='tdbg'">
      <td  width='225' height='35' align='right' class='clefttitle'><strong>店名：</strong></td>
      <td width="743" height='30'>&nbsp;
          <input type='text' name='Title' value='<%=Title%>' size="40" />
          <font color=red>*</font></td>
    </tr>
    <tr class="tdbg" onmouseover="this.className='tdbgmouseover'" onmouseout="this.className='tdbg'">
      <td  width='225' height='35' align='right' class='clefttitle'><strong>详细地址：</strong></td>
      <td height='30'>&nbsp;
      <input type='text' name='Address' value='<%=Address%>' size="40" /></td>
    </tr>
    <tr class="tdbg" onmouseover="this.className='tdbgmouseover'" onmouseout="this.className='tdbg'">
      <td  width='225' height='35' align='right' class='clefttitle'><strong>公交路线：</strong></td>
      <td height='30'>&nbsp;
           <textarea name='CarRoute' style="width:300px;height:60px"><%=CarRoute%></textarea></td>
    </tr>
    <tr class="tdbg" onmouseover="this.className='tdbgmouseover'" onmouseout="this.className='tdbg'">
      <td  width='225' height='35' align='right' class='clefttitle'><strong>地图：</strong></td>
      <td height='30'>&nbsp;
        <input class="textbox" type="file" name="photo" size="40" onchange='document.getElementById(&quot;pic&quot;).innerHTML=&quot;&quot;;document.getElementById(&quot;pic&quot;).filters.item(&quot;DXImageTransform.Microsoft.AlphaImageLoader&quot;).src=this.value;' />
        <font color="red">*</font> <br />
&nbsp;&nbsp;<font color="blue">请上传少于200K的图片,支持jpg,gif,png格式</font></td>
    </tr>
   
</table>
<br />
<div style="padding-left:150px">
<span id="pic" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);height:200px;width:255px;border:1px solid #777777"><img src="<%=Map%>" style="height:200px;width:255px;" /></span>
</div>
  </form>
<%
End Sub

Sub DoSave()
		  	Dim Fobj:Set FObj = New UpFileClass
			on error resume next
			FObj.GetData
			if err.number<>0 then
			 call ks.alerthistory("出错了,文件超出大小",-1)
			 response.End()
			end if

		   Dim ID:ID=KS.ChkClng(Fobj.Form("id"))
		   Dim Title:Title=KS.LoseHtml(Fobj.Form("Title"))
           Dim Address:Address=Fobj.Form("Address")
		   Dim CarRoute:CarRoute=Fobj.Form("CarRoute")
			
			Dim MaxFileSize:MaxFileSize = 200   '设定文件上传最大字节数
			Dim AllowFileExtStr:AllowFileExtStr = "gif|jpg|png"
			Dim FormPath:FormPath = KS.GetUpFilesDir() & "/"
			Call KS.CreateListFolder(FormPath) 
			Dim ReturnValue:ReturnValue = FObj.UpSave(FormPath,MaxFileSize,AllowFileExtStr,"u" & right(Year(Now),2) & right("0" & Month(Now),2) & right("0" & Day(Now),2) & right("0"&Hour(Now),2) & right("0"&Minute(Now),2) & right("0"&Second(Now),2))
			Select Case ReturnValue
			  Case "errext" Call KS.AlertHistory("文件上传失败,文件类型不允许\n允许的类型有" + AllowFileExtStr + "\n",-1):exit sub
	          Case "errsize"  Call KS.AlertHistory("文件上传失败,文件超过允许上传的大小\n允许上传 " & MaxFileSize & " KB的文件\n",-1):exit sub
			End Select

	   Dim Map:Map=ReturnValue


	   Dim ComeUrl:ComeUrl=Fobj.Form("ComeUrl")
	   Set Fobj=Nothing
	   
		
	   If Title="" Then Response.Write "<script>alert('联盟店名称必须输入');history.back();</script>":response.end

            Dim RS: Set RS=Server.CreateObject("Adodb.RecordSet")
			  RS.Open "Select * From KS_ShopUnion Where ID=" & ID,Conn,1,3
			  If RS.Eof And RS.Bof Then
			     RS.AddNEW
				 RS("AddDate")=Now
			  End If
			     RS("Title")=Title
				 RS("Address")=Address
				 IF Map<>"" Then RS("Map")=Map
				 RS("CarRoute")=CarRoute
		 		 RS.Update
				 RS.MoveLast
				 
				 If Map<>"" Then
					 If ID=0 Then
						Call KS.FileAssociation(1002,RS("ID"),Map,0)
					 Else
						Call KS.FileAssociation(1002,ID,Map,1)
					 End If
				 End If
				 
			     RS.Close
				 Set RS=Nothing
				 If ID=0 Then
				  Response.Write "<script>if (confirm('加盟店添加成功!')){location.href='?action=Add';}else{$(parent.document).find('#BottomFrame')[0].src='Split.asp?ButtonSymbol=Disabled&OpStr=" & Server.URLEncode("商城系统 >> <font color=red>加盟店管理</font>") & "';location.href='ShopUnion.asp';}</script>"
				 Else
				  Response.Write "<script>alert('加盟店修改成功！');$(parent.document).find('#BottomFrame')[0].src='Split.asp?ButtonSymbol=Disabled&OpStr=" & Server.URLEncode("商城系统 >> <font color=red>加盟店管理</font>") & "';location.href='"& ComeUrl & "';</script>"
				 End If

EnD Sub

'删除
Sub CouponDel()
 Dim ID:ID=KS.G("ID")
 If ID="" Then Response.Write "<script>alert('对不起，您没有选择!');history.back();</script>":response.end
 Conn.execute("Delete From KS_ShopUnion Where id In("& id & ")")
 Conn.Execute("Delete From KS_UploadFiles Where ChannelID=1002 and infoid in(" & ID & ")")
 Response.Write "<script>alert('删除成功！');location.href='" & Request.servervariables("http_referer") & "';</script>"
End Sub


End Class
%> 
