改用按钮操作

本节任务和上一节相同,但全部改用按钮操作,并加上首页和末页按钮。

此外根据页面的位置,按钮颜色会改变,例如到了最后一页,下一页和末页按钮颜色变灰:

需要改动的地方有两处。

1、首先如果用户没有选择任何行,应该禁止编辑和删除订单,以免出错,所以将table.js的代码改为:

function edit(){
    if (table1.primarykey){
        location="edit.htm?page=" + table1.pagenumber + "&key=" + table1.primarykey;
    }
}
function del(){
    if(table1.primarykey){
        location="delete.htm?page=" + table1.pagenumber + "&key=" + table1.primarykey;
    }
}
function addnew(){
    location="addnew.htm?page=" + table1.pagenumber;
}

2、自定义函数list的代码改为:

Dim e As RequestEventArgs = args(0)
'
获取要显示的页
Dim
page As Integer = 0 '默认page0,显示第一页
Dim
pageRows As Integer = 10 '每页10
If
e.GetValues.ContainsKey("page") Then  '如果地址中有page参数
    Integer.TryParse(e.GetValues("page"), page) '
提取page参数
End
If
Dim
StartRow As Integer = page * pageRows + 1 '此页第一行
Dim
EndRow As Integer = (page + 1) * pageRows '此页最后一行
'
获取该页数据
Dim
cmd As New SQLCommand
cmd
.ConnectionName = "orders" '记得设置数据源名称
cmd
.CommandText = "Select Count(*) From {订单}"
Dim
Count As Integer = cmd.ExecuteScalar() '获取总的行数
Dim
Pages As Integer = Math.Ceiling(Count/PageRows) '计算出总页数
cmd
.CommandText = "Select * From (Select Row_Number() Over(Order by 日期 desc) As [NO.],[_Identify],产品,客户,数量,单价,日期 From 订单) As a "
cmd
.CommandText = cmd.CommandText & "  Where [NO.]>= " & StartRow & " And [NO.] <= " & EndRow
Dim
dt As DataTable = cmd.ExecuteReader
Dim
wb As New WeUI
'
根据此页数据生成网页
With
wb.AddTable("","Table1")
    .PageNumber = page '
设置页码
    .Primarykey = "_Identify" '
设置主键
    .CreateFromDataTable(dt)

End
With
With
wb.AddButtonGroup("","btg1", False) '生成换页按钮
    If page > 0 Then
        .Add("btnFirst", "
首页","","List.htm?page=0")
        .Add("btnPrev", "
上一页","","List.htm?page=" & page - 1)
    Else
        .Add("btnFirst", "
首页").Kind = 1
        .Add("btnPrev", "
上一页").Kind = 1
    End If
    If Endrow < count Then
        .Add("btnNext", "
下一页","","List.htm?page=" & page + 1)
        .Add("btnLast", "
末页","","List.htm?page=" & pages - 1)
    Else
       .Add("btnNext", "
下一页").Kind = 1
        .Add("btnNext", "
末页").Kind = 1
    End If

End
With
With
wb.AddButtonGroup("","btg2", False) '生成操作按钮
    .Add("btnAdd", "
增加订单").Attribute = "onclick='addnew()'"
    .Add("btnEdit", "
编辑订单").Attribute = "onclick='edit()'"
    .Add("btnDelete", "
删除订单").Attribute = "onclick='del()'"
End
With
wb
.AppendHTML("<script src='./lib/table.js'></script>") '引入脚本文件
e
.WriteString(wb.Build)


本页地址:http://www.foxtable.com/mobilehelp/topics/0121.htm