前端界面的代码如下:
Dim e As RequestEventArgs = args(0)
Dim wb As New weui
wb.title="IT硬件故障报修申请"
wb.AppendHTML("<script src='http://res.wx.qq.com/open/js/jweixin-1.2.0.js'></script>",True) '引入JS-SDK库
wb.AppendHTML("<script src='../ajax/libs/jssdk.js'></script>") '引入脚本文件 这个js文件是微信扫码功能自动调用的 '假定这个扫码的网页会被放在 xdf/service/ 文件夹下面被调用时的路径
If e.PostValues.Count = 0 Then '生成网页 供填写报障信息
'在页面注入权限验证配置
Dim st As New Date(1970,1,1,8,0,0)
Dim appid As String = "wx7536******" '开发者ID
Dim timestamp As Integer = CInt((Date.Now - st).TotalSeconds()) '时间戳
Dim noncestr As String = Rand.NextString(16) '随机字符
Dim url As String = e.Request.URL.ToString '当前页面地址
Dim signature As String = Functions.Execute("GetJsSignature", noncestr, timestamp, url) '生成权限验证签名
Dim cfg As String = "wx.config({appId:'{0}',timestamp:{1},nonceStr:'{2}',signature:'{3}',jsApiList:['scanQRCode']});"
wb.AppendHTML("<script>" & CExp(cfg,appid,timestamp,noncestr,signature) & "</script>",True)
'开始正常生成网页内容
wb.AddForm("","form1","ITFailure.htm").Attribute="" 'ITFailure.htm 是接收本表单数据的网页(需要在else里先验证数据是否有缺失), DeviceInfoQueryFunction 函数是用来弹出对话框提示提交是否成功
With wb.AddInputGroup("form1","ipg1","请扫描IT设备上的二维码")
' .AddInput("product","所在楼","text") '显示
' .AddInput("product","所在科室","text") '显示
' .AddInput("product","所在房间","text") '显示
With .AddInputCell("ic1")
.AddLabel("lnumber","sn",0) '第2个sn 是显示在界面上的内容 第1个lsn是label控件的ID
.AddInput("number","text",1)
.AddVcodeButton("scan","扫码输入",2) '增加二维码扫描按钮,2表示显示在右边
End With
With .AddInputCell("ic2")
.AddLabel("lsblx","设备类型",0) '第2个sn 是显示在界面上的内容 第1个lsn是label控件的ID
.AddInput("sblx","text",1)
End With
With .AddInputCell("ic3")
.AddLabel("lszl","所在楼",0)
.AddInput("szl","text",1)
End With
With .AddInputCell("ic4")
.AddLabel("lszks","所在科室",0)
.AddInput("szks","text",1)
End With
With .AddInputCell("ic5")
.AddLabel("lszfj","所在房间",0) '第2个sn 是显示在界面上的内容 第1个lsn是label控件的ID
.AddInput("szfj","text",1)
End With
With .AddInputCell("ic6")
.AddLabel("lxm","姓名",0) '第2个sn 是显示在界面上的内容 第1个lsn是label控件的ID
.AddInput("xm","text",1)
End With
With .AddInputCell("ic7")
.AddLabel("ldh","电话",0) '第2个sn 是显示在界面上的内容 第1个lsn是label控件的ID
.AddInput("dh","text",1)
End With
With .AddInputCell("ic8")
.AddLabel("lks","科室",0) '第2个sn 是显示在界面上的内容 第1个lsn是label控件的ID
.AddInput("ks","text",1)
End With
With .AddInputCell("ic9")
.AddLabel("ljlsj","记录时间",0) '第2个sn 是显示在界面上的内容 第1个lsn是label控件的ID
.AddInput("jlsj","datetime-loca",1)
End With
With .AddInputCell("ic10")
.AddLabel("lgzms","故障描述",0) '第2个sn 是显示在界面上的内容 第1个lsn是label控件的ID
.AddInput("gzms","text",1)
End With
With wb.AddDialog("","dlg3", "","") '增加订单成功提示框,这里一定要有,不然javascript就调不出来 dlg4要与javascript中对应,后面两个"" ""内容 实际是javascript中决定的 weui框架弹出的
' .AddButton("btnYes","是").Attribute = ""
.AddButton("btnNo","确定","./DeviceResult.htm").Kind = 1 '提交成功跳转到的界面
End With
'提交失败被javascript调用的提示框
With wb.AddDialog("","dlg4", "","") '弹出增加订单失败提示框,这里一定要有,不然javascript就调不出来 dlg4要与javascript中对应,后面两个"" ""内容 实际是javascript中决定的 weui框架弹出的
.AddButton("btnOK","确定") '.Attribute = ""
End With
End With
With wb.AddButtonGroup("form1","btg1",True)
.Add("btn1", "提交", "submit")
End With
Else '显示提交成功或失败的网页
'msgbox(e.PlainText) 用来测试一下PlainText 里面是不是仅仅是条码号,用来和下面else的内容进行区分.
'提交之前的表单校验
Dim nms() As String = {"SN","设备类型","所在楼","所在科室","所在房间","姓名","电话","科室","记录时间","故障描述"}
For Each nm As String In nms
If e.PostValues(nm)="" Then '生成错误提示页
e.WriteString("请输入" & nm & "!")
Return "wrong" '必须返回
End If
Next
'校验通过则存到数据库中
nms= new String(){"SN","设备类型","所在楼","所在科室","所在房间","姓名","电话","科室","记录时间","故障描述"}
Dim dr As DataRow = DataTables("硬件报障记录表").AddNew()
For Each nm As String In nms
dr(nm) = e.PostValues(nm)
Next
dr.Save()
' e.WriteString("ok")
' With wb.AddMsgPage("","msgpage","增加成功", "您的意见我们已经收到,感谢你的反馈!") '增加订单成功提示信息 '有javascript就不用这里跳转了,它只能在不校验的时候跳转到成功页面
' .AddButton("btn1","继续增加","SoftRequire.htm")
' ' .AddButton("btn1","返回列表","list.htm")
' End With
End If
wb.AppendHTML("<div id='p1' style='margin:0.5em'></div>") '插入一个div,用于显示服务器返回的数据
wb.AppendHTML("<script src='../ajax/libs/DeviceInfoQuery.js'></script>") '引入脚本文件 '如果什么都和这个函数一样,仍然弹不出来框,说明微信调用 htm网页的路径不对. 看看httprequest 前面有没有xdf/service文件夹.这个决定了能不能调用到javascript
e.WriteString(wb.Build)