一个简单录入界面

假定有下图所示的一个表:

希望设计一个手机录入界面:

在输入数据,单击确定按钮,能提示下图所示的页面:

如果有些关键列内容没有输入,则提示下图所示页面:

下面是HttpRequest事件代码,这段代码完成了HTTP服务的建立,3个页面的生成,以及数据接收等任务:

Dim
wb As New weui
Select
Case e.Path
    Case "addnew.htm"
        If e.PostValues.Count = 0 Then
            wb.AddForm("","form1","addnew.htm")
            With wb.AddInputGroup("form1","ipg1",
"
客户资料")
                .AddInput(
"
姓名","姓名","Text") '前一个"姓名"ID,后一个"姓名"是标题
                .AddInput(
"
年龄","年龄","number")
                .AddInput(
"
日期","日期","date")
                .AddSelect(
"
级别","级别","普通会员|高级会员|VIP会员")
                .AddSwitch(
"
停权","停权").Value = "True"
            End With
            With wb.AddRadioGroup("form1",
"
学历","最高学历")
                .Add(
"
本科","本科")
                .Add(
"
硕士","硕士")
                .Add(
"
博士","博士")
            End With
            With wb.AddCheckGroup("form1",
"
偏好","品牌偏好")
               
.Add("苹果","苹果")
                .Add("华为","华为")
               
.Add("三星","三星")
            End With
            With wb.AddButtonGroup("form1","btg1",True)
                .Add("btn1",
"
确定", "submit")
            End With
            e.WriteString(wb.Build)
        Else
            Dim nms() As String =
{"
姓名","年龄","日期","级别"} '不能为空的列名数组
            For Each nm As String In nms

               
If e.PostValues.ContainsKey(nm) = False Then '生成错误提示页
                    With wb.AddMsgPage("","msgpage","增加失败", nm & "列不能为空!")
                        .icon = "Warn" '改变图标
                        .AddButton("btn1","返回").Attribute = "onclick='history.back()'"
                    End With
                    e.WriteString(wb.Build)
                    Return '必须返回
                End If
            Next
            nms = New String() {"姓名","年龄","日期","级别","停权","学历"} 
'重新定义了nms数组,增加了两列.
           
Dim dr As DataRow = DataTables("员工").AddNew()
            For Each nm As String In nms
                If e.
PostValues.ContainsKey(nm) Then
                    dr(nm) = e.
PostValues(nm)
                End If
            Next
            '以下代码处理品牌复选列表项
            Dim pp As String
            nms = New String() {"苹果","华为","三星"}
'将nms重新定义为品牌数组
           
For Each nm As String In nms
                If e.PostValues.ContainsKey(nm) AndAlso e.PostValues(nm).Trim() = "on" Then
'
不能省略Trim
                    pp = pp & nm  & ","
                End If
            Next
            If pp > "" Then
                dr(
"
偏好") = pp.Trim(",")
            End If
           
'
保存并生成增加成功提示页面
            dr.save()
            With wb.
AddMsgPage("","msgpage","增加成功", "好好学习,天天向上") '生成成功提示页
               
.AddButton("btn1","继续增加","addnew.htm")
            End With
            e.WriteString(wb.Build)
        End
If
End
Select

代码很好理解,以下几点注意一下:

1、输入组件的ID尽量用列名,方便简化编码。
2、对于开关组件,默认返回值是"on",可以将其Value属性设置为"True",方便统一编码。
3、开关组件和复选列表项的返回值可能有空格,例如"on  ",所以比较值的时候要用Trim方法去掉空格。


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