up1\up2是附件,附件不是必传项目。保存按钮全部代码如下:
Dim e As object = args(0)
Dim wb As New weui
wb.InsertHTML("<style>.exui-navbar {height:40px;}</style>")
wb.AppendHTML("<link rel='stylesheet' href='./weui/exweui.css'/>",True)
If e.PostValues.Count = 0 Then
wb.AddForm("","form1","Yuwen_Clock_add.htm")
'设置导航条并添加标题栏名称
With ExWeUI.WebUI.AddNavBar("form1","navbar01")
.Attribute = "style='background-color: #FBF9FC;color:#000000'" '设置导航条背景色和标题文字颜色
With .LeftGroup.AddItem("nvi01","") '左导航栏添加一个项目
.image = "./images/返回.png" '添加图标
'.Attribute = """ '浏览器后退功能
.Attribute = "" '回退到首页指定页面
End With
With .RightGroup.AddItem("nvi02","") '右导航栏添加一个空项目
End With
.CenterGroup.Text = "语文打卡登记信息" '标题栏名称
wb.InsertHTML("form1",.BuildHtml) '添加到TabBar的page1中
End With
'添加学生信息分组
With wb.AddInputGroup("form1","id1","学生信息") 'ParentID 父容器的ID,如果是顶层对象,设置为""即可. ID 分组ID. Text 可选参数,用于指定分组标题.
With .AddInput("班级","班  级","text")
.Value = _UserGroup
.Readonly= True
End With
With .AddInput("姓名","姓  名","text")
.Value = _UserXingMing
.Readonly= True
End With
With .AddInput("打卡日期","打卡日期","data")
.Value = Date.Today
.Readonly= True
End With
End With
'添加打卡项目
With wb.AddInputGroup("form1","打卡项目","打卡项目")
With .AddInputCell("ic1") '通过InputCell增加输入框
.AddLabel("ls1","课内阅读",0) '增加标签,0显示在左边
.AddInput("课内阅读","number",1).Placeholder ="课内阅读时间" '增加输入框,1表示显示在中间
.AddLabel("ls2","(分钟)",2) '增加标签,2表示显示在右边
End With
With .AddUploader("up1","",True)
.Accept = "image/*"
.Capture = "camera" '拍照上传
.AllowDelete = True '允许删除
.Incremental = True '允许重复选择文件或连续拍照
.ScaleWidth = 400 '自动压缩图片宽度为400个像素,高度等比例压缩
End With
With .AddInputCell("ic1") '通过InputCell增加输入框
.AddLabel("ls1","课外阅读",0) '增加标签,0显示在左边
.AddInput("课外阅读","number",1).Placeholder ="课外阅读时间" '增加输入框,1表示显示在中间
.AddLabel("ls2","(分钟)",2) '增加标签,2表示显示在右边
End With
With .AddUploader("up2","",True)
.Accept = "image/*"
.Capture = "camera" '拍照上传
.AllowDelete = True '允许删除
.Incremental = True '允许重复选择文件或连续拍照
.ScaleWidth = 400 '自动压缩图片宽度为400个像素,高度等比例压缩
End With
End With
With wb.AddPreview("","pv1","","")
.AddButton("保  存","", 1,"submit")
End With
wb.InsertHTML("<style>.weui-form-preview {margin-top:5px;}</style>") '设置AddPreview1与上边间距
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 = ""
End With
e.WriteString(wb.Build)
Return Nothing '必须返回
End If
Next
If e.Files.containskey("up1")Then
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
dr("打卡项目") = "课内阅读"
dr("登记状态") = True
dr("登记人") = _UserXingMing
dr("登记日期") = Date.Today
Dim lst As List(of String) = dr.Lines("附件")
For Each key As String In e.Files.Keys
If key = "up1" Then
For Each fln As String In e.Files(key)
e.SaveFile(key,fln, ProjectPath & "web\images\语文打卡记录\" & fln) '保存接收到的文件
lst.add("/images/语文打卡记录/" & "/" & fln)
Next
dr.Lines("附件") = lst
End If
Next
dr.Save
End If
If e.Files.containskey("up2")Then
nms = New String() {"班级","姓名","打卡日期","打卡用时"} '重新定义了nms数组,增加了两列.
Dim ds As DataRow = DataTables("语文打卡记录").AddNew()
For Each nm As String In nms
If e.PostValues.ContainsKey(nm) Then
ds(nm) = e.PostValues(nm)
End If
Next
ds("打卡项目") = "课外阅读"
ds("登记状态") = True
ds("登记人") = _UserXingMing
ds("登记日期") = Date.Today
Dim lst As List(of String) = ds.Lines("附件")
For Each key As String In e.Files.Keys
If key = "up2" Then
For Each fln As String In e.Files(key)
e.SaveFile(key,fln, ProjectPath & "web\images\语文打卡记录\" & fln) '保存接收到的文件
lst.add("/images/语文打卡记录/" & "/" & fln)
Next
ds.Lines("附件") = lst
End If
Next
ds.Save
End If
'保存并生成增加成功提示页面
With wb.AddMsgPage("","msgpage","打卡成功", "好好学习,天天向上!") '生成成功提示页
.AddButton("btn1","返回").Attribute = ""
End With
e.WriteString(wb.Build)
End If
e.WriteString(wb.Build)