<%
Response.Buffer = EW_RESPONSE_BUFFER
%>
<!--#include file="ewcfg7.asp"-->
<!--#include file="bhlminfo.asp"-->
<!--#include file="zlogininfo.asp"-->
<!--#include file="aspfn7.asp"-->
<!--#include file="userfn7.asp"-->
<% Session.Timeout = 900 %>
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
%>
<%

' Define page object
Dim bhlm_delete
Set bhlm_delete = New cbhlm_delete
Set Page = bhlm_delete

' Page init processing
Call bhlm_delete.Page_Init()

' Page main processing
Call bhlm_delete.Page_Main()
%>
<!--#include file="header.asp"-->
<script type="text/javascript">
<!--
// Create page object
var bhlm_delete = new ew_Page("bhlm_delete");
// page properties
bhlm_delete.PageID = "delete"; // page ID
var EW_PAGE_ID = bhlm_delete.PageID; // for backward compatibility
// extend page with Form_CustomValidate function
bhlm_delete.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!
 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
bhlm_delete.SelectAllKey = function(elem) {
	ew_SelectAll(elem);
}
<% If EW_CLIENT_VALIDATE Then %>
bhlm_delete.ValidateRequired = true; // uses JavaScript validation
<% Else %>
bhlm_delete.ValidateRequired = false; // no JavaScript validation
<% End If %>
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->
</script>
<%

' Load records for display
Set Rs = bhlm_delete.LoadRecordset()
bhlm_delete.lTotalRecs = Rs.RecordCount ' Get record count
If bhlm_delete.lTotalRecs <= 0 Then ' No record found, exit
	Rs.Close
	Set Rs = Nothing
	Call bhlm_delete.Page_Terminate("bhlmlist.asp") ' Return to list
End If
%>
<p><span class="aspmaker">删除自 表: 信息栏目<br><br>
<a href="<%= bhlm.ReturnUrl %>">返回</a></span></p>
<% bhlm_delete.ShowMessage %>
<form action="<%= ew_CurrentPage %>" method="post">
<p>
<input type="hidden" name="t" id="t" value="bhlm">
<input type="hidden" name="a_delete" id="a_delete" value="D">
<% For i = 0 to UBound(bhlm_delete.arRecKeys) %>
<input type="hidden" name="key_m" id="key_m" value="<%= Server.HtmlEncode(bhlm_delete.arRecKeys(i)) %>">
<% Next %>
<table class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable ewTableSeparate">
<%= bhlm.TableCustomInnerHTML %>
	<thead>
	<tr class="ewTableHeader">
		<td valign="top">编号</td>
		<td valign="top">编号名称</td>
		<td valign="top">排序</td>
		<td valign="top">展示类别</td>
	</tr>
	</thead>
	<tbody>
<%
bhlm_delete.lRecCnt = 0
i = 0
Do While (Not Rs.Eof)
	bhlm_delete.lRecCnt = bhlm_delete.lRecCnt + 1

	' Set row properties
	bhlm.CssClass = ""
	bhlm.CssStyle = ""
	bhlm.RowType = EW_ROWTYPE_VIEW ' view

	' Get the field contents
	Call bhlm_delete.LoadRowValues(Rs)

	' Render row
	Call bhlm_delete.RenderRow()
%>
	<tr<%= bhlm.RowAttributes %>>
		<td<%= bhlm.bh.CellAttributes %>>
<div<%= bhlm.bh.ViewAttributes %>><%= bhlm.bh.ListViewValue %></div>
</td>
		<td<%= bhlm.bhmc.CellAttributes %>>
<div<%= bhlm.bhmc.ViewAttributes %>><%= bhlm.bhmc.ListViewValue %></div>
</td>
		<td<%= bhlm.px.CellAttributes %>>
<div<%= bhlm.px.ViewAttributes %>><%= bhlm.px.ListViewValue %></div>
</td>
		<td<%= bhlm.urllb.CellAttributes %>>
<div<%= bhlm.urllb.ViewAttributes %>><%= bhlm.urllb.ListViewValue %></div>
</td>
	</tr>
<%
	Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
%>
	</tbody>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="Action" id="Action" value="   删除确认   ">
</form>
<script language="JavaScript" type="text/javascript">
<!--
// Write your table-specific startup script here
// document.write("page loaded");
//-->
</script>
<!--#include file="footer.asp"-->
<%

' Drop page object
Set bhlm_delete = Nothing
%>
<%

' -----------------------------------------------------------------
' Page Class
'
Class cbhlm_delete

	' Page ID
	Public Property Get PageID()
		PageID = "delete"
	End Property

	' Table Name
	Public Property Get TableName()
		TableName = "bhlm"
	End Property

	' Page Object Name
	Public Property Get PageObjName()
		PageObjName = "bhlm_delete"
	End Property

	' Page Name
	Public Property Get PageName()
		PageName = ew_CurrentPage()
	End Property

	' Page Url
	Public Property Get PageUrl()
		PageUrl = ew_CurrentPage() & "?"
		If bhlm.UseTokenInUrl Then PageUrl = PageUrl & "t=" & bhlm.TableVar & "&" ' add page token
	End Property

	' Message
	Public Property Get Message()
		Message = Session(EW_SESSION_MESSAGE)
	End Property

	Public Property Let Message(v)
		If Session(EW_SESSION_MESSAGE) <> "" Then ' Append
			Session(EW_SESSION_MESSAGE) = Session(EW_SESSION_MESSAGE) & "<br>" & v
		Else
			Session(EW_SESSION_MESSAGE) = v
		End If
	End Property

	' Show Message
	Public Sub ShowMessage()
		If Message <> "" Then ' Message in Session, display
			Response.Write "<p><span class=""ewMessage"">" & Message & "</span></p>"
			Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session
		End If
	End Sub

	' -----------------------
	'  Validate Page request
	'
	Public Function IsPageRequest()
		If bhlm.UseTokenInUrl Then
			IsPageRequest = False
			If Not (ObjForm Is Nothing) Then
				IsPageRequest = (bhlm.TableVar = ObjForm.GetValue("t"))
			End If
			If Request.QueryString("t").Count > 0 Then
				IsPageRequest = (bhlm.TableVar = Request.QueryString("t"))
			End If
		Else
			IsPageRequest = True
		End If
	End Function

	' -----------------------------------------------------------------
	'  Class initialize
	'  - init objects
	'  - open ADO connection
	'
	Private Sub Class_Initialize()

		' Initialize table object
		Set bhlm = New cbhlm

		' Initialize other table object
		Set zlogin = New czlogin

		' Initialize form object
		Set ObjForm = Nothing

		' Intialize page id (for backward compatibility)
		EW_PAGE_ID = "delete"

		' Initialize table name (for backward compatibility)
		EW_TABLE_NAME = "bhlm"

		' Open connection to the database
		Set Conn = Server.CreateObject("ADODB.Connection")
		Conn.Open EW_DB_CONNECTION_STRING
	End Sub

	' -----------------------------------------------------------------
	'  Subroutine Page_Init
	'  - called before page main
	'  - check Security
	'  - set up response header
	'  - call page load events
	'
	Sub Page_Init()
		Set Security = New cAdvancedSecurity
		If Not Security.IsLoggedIn() Then Call Security.AutoLogin()
		If Not Security.IsLoggedIn() Then
			Call Security.SaveLastUrl()
			Call Page_Terminate("login.asp")
		End If

		' Table Permission loading event
		Call Security.TablePermission_Loading()
		Call Security.LoadCurrentUserLevel(TableName)

		' Table Permission loaded event
		Call Security.TablePermission_Loaded()
		If Not Security.CanDelete Then
			Call Security.SaveLastUrl()
			Call Page_Terminate("bhlmlist.asp")
		End If

		' Global page loading event (in userfn7.asp)
		Call Page_Loading()

		' Page load event, used in current page
		Call Page_Load()
	End Sub

	' -----------------------------------------------------------------
	'  Class terminate
	'  - clean up page object
	'
	Private Sub Class_Terminate()
		Call Page_Terminate("")
	End Sub

	' -----------------------------------------------------------------
	'  Subroutine Page_Terminate
	'  - called when exit page
	'  - clean up ADO connection and objects
	'  - if url specified, redirect to url
	'
	Sub Page_Terminate(url)

		' Page unload event, used in current page
		Call Page_Unload()

		' Global page unloaded event (in userfn60.asp)
		Call Page_Unloaded()
		If Not (Conn Is Nothing) Then Conn.Close ' Close Connection
		Set Conn = Nothing
		Set Security = Nothing
		Set bhlm = Nothing

		' Go to url if specified
		If url <> "" Then
			Response.Clear
			Response.Redirect url
		End If
	End Sub

	'
	'  Subroutine Page_Terminate (End)
	' ----------------------------------------

	Dim lTotalRecs
	Dim lRecCnt
	Dim arRecKeys

	' Page main processing
	Sub Page_Main()
		Dim sKey, bSingleDelete
		Dim nKeySelected
		Dim sKeyFld, arKeyFlds
		Dim i
		Dim sFilter

		' Load Key Parameters
		sKey = ""
		bSingleDelete = True ' Initialize as single delete
		nKeySelected = 0 ' Initialize selected key count
		If Request.QueryString("bh").Count > 0 Then
			bhlm.bh.QueryStringValue = Request.QueryString("bh")
			If Not IsNumeric(bhlm.bh.QueryStringValue) Then
				Call Page_Terminate("bhlmlist.asp") ' Prevent sql injection, return to list
			End If
			sKey = sKey & bhlm.bh.QueryStringValue
		Else
			bSingleDelete = False
		End If
		If bSingleDelete Then
			nKeySelected = 1 ' Set up key selected count
			Redim arRecKeys(0) ' Set up key
			arRecKeys(0) = sKey
		Else
			If Request.Form("key_m").Count > 0 Then ' Key in form
				nKeySelected = Request.Form("key_m").Count ' Set up key selected count
				Redim arRecKeys(nKeySelected-1)
				For i = 1 to nKeySelected ' Set up keys
					arRecKeys(i-1) = Request.Form("key_m")(i)
				Next
			End If
		End If
		If nKeySelected <= 0 Then Call Page_Terminate("bhlmlist.asp") ' No key specified, return to list

		' Build filter
		For i = 0 to UBound(arRecKeys)
			sKey = Trim(arRecKeys(i))
			sFilter = sFilter & "("

			' Set up key field
			sKeyFld = sKey
			If Not IsNumeric(sKeyFld) Then Call Page_Terminate("bhlmlist.asp") ' Prevent sql injection, return to list
			sFilter = sFilter & "[bh]=" & ew_AdjustSql(sKeyFld) & " AND "
			If Right(sFilter, 5) = " AND " Then sFilter = Left(sFilter, Len(sFilter)-5) & ") OR "
		Next
		If Right(sFilter, 4) = " OR " Then sFilter = Left(sFilter, Len(sFilter)-4)

		' Set up filter (Sql Where Clause) and get Return Sql
		' Sql constructor in bhlm class, bhlminfo.asp

		bhlm.CurrentFilter = sFilter

		' Get action
		If Request.Form("a_delete").Count > 0 Then
			bhlm.CurrentAction = Request.Form("a_delete")
		Else
			bhlm.CurrentAction = "I"	' Display record
		End If
		Select Case bhlm.CurrentAction
			Case "D" ' Delete
				bhlm.SendEmail = True ' Send email on delete success
				If DeleteRows() Then ' delete rows
					Message = "删除成功" ' Set up success message
					Call Page_Terminate(bhlm.ReturnUrl) ' Return to caller
				End If
		End Select
	End Sub

	' ------------------------------------------------
	'  Function DeleteRows
	'  - Delete Records based on current filter
	'
	Function DeleteRows()
		If Not EW_DEBUG_ENABLED Then On Error Resume Next
		Dim sKey, sThisKey, sKeyFld, arKeyFlds
		Dim RsDelete, sSql, sWrkFilter
		Dim RsOld
		DeleteRows = True
		sWrkFilter = bhlm.CurrentFilter

		' Set up filter (Sql Where Clause) and get Return Sql
		' Sql constructor in bhlm class, bhlminfo.asp

		bhlm.CurrentFilter = sWrkFilter
		sSql = bhlm.SQL
		Set RsDelete = Server.CreateObject("ADODB.Recordset")
		RsDelete.CursorLocation = EW_CURSORLOCATION
		RsDelete.Open sSql, Conn, 1, 2
		If Err.Number <> 0 Then
			Message = Err.Description
			RsDelete.Close
			Set RsDelete = Nothing
			DeleteRows = False
			Exit Function
		ElseIf RsDelete.Eof Then
			Message = "没有找到记录" ' No record found
			RsDelete.Close
			Set RsDelete = Nothing
			DeleteRows = False
			Exit Function
		End If
		Conn.BeginTrans

		' Clone old recordset object
		Set RsOld = ew_CloneRs(RsDelete)

		' Call recordset deleting event
		If DeleteRows Then DeleteRows = bhlm.Recordset_Deleting(RsDelete)
		If DeleteRows Then
			sKey = ""
			If Not RsDelete.Eof Then RsDelete.MoveFirst
			Do While Not RsDelete.Eof
				sThisKey = ""
				If sThisKey <> "" Then sThisKey = sThisKey & EW_COMPOSITE_KEY_SEPARATOR
				sThisKey = sThisKey & RsDelete("bh")
				RsDelete.Delete
				If Err.Number <> 0 Then
					Message = Err.Description ' Set up error message
					DeleteRows = False
					Exit Do
				End If
				If sKey <> "" Then sKey = sKey & ", "
				sKey = sKey & sThisKey
				RsDelete.MoveNext
			Loop
		Else

			' Set up error message
			If bhlm.CancelMessage <> "" Then
				Message = bhlm.CancelMessage
				bhlm.CancelMessage = ""
			Else
				Message = "取消删除"
			End If
		End If
		If DeleteRows Then
			Conn.CommitTrans ' Commit the changes
			If Err.Number <> 0 Then
				Message = Err.Description
				DeleteRows = False ' Delete failed
			Else
			End If
		Else
			Conn.RollbackTrans ' Rollback changes
		End If
		RsDelete.Close
		Set RsDelete = Nothing

		' Call recordset deleted event
		If DeleteRows Then Call bhlm.Recordset_Deleted(RsOld)
		RsOld.Close
		Set RsOld = Nothing
	End Function

	' -----------------------------------------------------------------
	' Load recordset
	'
	Function LoadRecordset()

		' Call Recordset Selecting event
		Call bhlm.Recordset_Selecting(bhlm.CurrentFilter)

		' Load list page sql
		Dim sSql
		sSql = bhlm.ListSQL
		If EW_DEBUG_ENABLED Then Response.Write sSql ' Show SQL for debugging

		' Load recordset
		Dim RsRecordset
		Set RsRecordset = Server.CreateObject("ADODB.Recordset")
		RsRecordset.CursorLocation = EW_CURSORLOCATION
		RsRecordset.Open sSql, Conn, 1, 2

		' Call Recordset Selected event
		Call bhlm.Recordset_Selected(RsRecordset)
		Set LoadRecordset = RsRecordset
	End Function

	' -----------------------------------------------------------------
	' Load row based on key values
	'
	Function LoadRow()
		Dim RsRow, sSql, sFilter
		sFilter = bhlm.KeyFilter

		' Call Row Selecting event
		Call bhlm.Row_Selecting(sFilter)

		' Load sql based on filter
		bhlm.CurrentFilter = sFilter
		sSql = bhlm.SQL
		If EW_DEBUG_ENABLED Then Response.Write sSql ' Show SQL for debugging
		Set RsRow = Server.CreateObject("ADODB.Recordset")
		RsRow.Open sSql, Conn
		If RsRow.Eof Then
			LoadRow = False
		Else
			LoadRow = True
			RsRow.MoveFirst
			Call LoadRowValues(RsRow) ' Load row values

			' Call Row Selected event
			Call bhlm.Row_Selected(RsRow)
		End If
		RsRow.Close
		Set RsRow = Nothing
	End Function

	' -----------------------------------------------------------------
	' Load row values from recordset
	'
	Sub LoadRowValues(RsRow)
		bhlm.bh.DbValue = RsRow("bh")
		bhlm.bhmc.DbValue = RsRow("bhmc")
		bhlm.px.DbValue = RsRow("px")
		bhlm.urllb.DbValue = RsRow("urllb")
	End Sub

	' -----------------------------------------------------------------
	' Render row values based on field settings
	'
	Sub RenderRow()

		' Call Row Rendering event
		Call bhlm.Row_Rendering()

		' ---------------------------------------
		'  Common render codes for all row types
		' ---------------------------------------
		' bh

		bhlm.bh.CellCssStyle = ""
		bhlm.bh.CellCssClass = ""

		' bhmc
		bhlm.bhmc.CellCssStyle = ""
		bhlm.bhmc.CellCssClass = ""

		' px
		bhlm.px.CellCssStyle = ""
		bhlm.px.CellCssClass = ""

		' urllb
		bhlm.urllb.CellCssStyle = ""
		bhlm.urllb.CellCssClass = ""

		' -----------
		'  View  Row
		' -----------

		If bhlm.RowType = EW_ROWTYPE_VIEW Then ' View row

			' bh
			bhlm.bh.ViewValue = bhlm.bh.CurrentValue
			bhlm.bh.CssStyle = ""
			bhlm.bh.CssClass = ""
			bhlm.bh.ViewCustomAttributes = ""

			' bhmc
			bhlm.bhmc.ViewValue = bhlm.bhmc.CurrentValue
			bhlm.bhmc.CssStyle = ""
			bhlm.bhmc.CssClass = ""
			bhlm.bhmc.ViewCustomAttributes = ""

			' px
			bhlm.px.ViewValue = bhlm.px.CurrentValue
			bhlm.px.CssStyle = ""
			bhlm.px.CssClass = ""
			bhlm.px.ViewCustomAttributes = ""

			' urllb
			If Not IsNull(bhlm.urllb.CurrentValue) Then
				Select Case bhlm.urllb.CurrentValue
					Case "0"
						bhlm.urllb.ViewValue = "列表"
					Case "1"
						bhlm.urllb.ViewValue = "单页"
					Case "2"
						bhlm.urllb.ViewValue = "图片列表"
					Case Else
						bhlm.urllb.ViewValue = bhlm.urllb.CurrentValue
				End Select
			Else
				bhlm.urllb.ViewValue = Null
			End If
			bhlm.urllb.CssStyle = ""
			bhlm.urllb.CssClass = ""
			bhlm.urllb.ViewCustomAttributes = ""

			' View refer script
			' bh

			bhlm.bh.HrefValue = ""

			' bhmc
			bhlm.bhmc.HrefValue = ""

			' px
			bhlm.px.HrefValue = ""

			' urllb
			bhlm.urllb.HrefValue = ""
		End If

		' Call Row Rendered event
		Call bhlm.Row_Rendered()
	End Sub

	' Page Load event
	Sub Page_Load()

		'Response.Write "Page Load"
	End Sub

	' Page Unload event
	Sub Page_Unload()

		'Response.Write "Page Unload"
	End Sub
End Class
%>
