以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  关于信息文字加图片上传的问题,求指教!  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=144045)

--  作者:狐来江湖
--  发布时间:2019/12/9 15:32:00
--  关于信息文字加图片上传的问题,求指教!
 我根据帮助的例子做了一个页面,要求能将图片和文字等一起上传,现在虽然做好了,也能正常上传,但是总是提示“上传失败”,不知道代码问题出在哪里?请老师指教!

代码:
Dim e As RequestEventArgs = args(0)
Dim wb As new weui
If e.postvalues.count = 0 Then
    wb.addform("","form1","xxsc.htm")
    With wb.AddRadioGroup("form1","xxgxfl","供需分类")
        .Add("供给","供给")  \',True)
        .Add("需求","需求")
    End With
    With wb.AddCheckGroup("form1","xxnrfl","内容分类")
        .Add("劳务供需","劳务供需") \', True) \'默认勾选
        .Add("不动产供需","不动产供需")
        .Add("二手供需","二手供需")
        .Add("社区公益","社区公益")  \'.Enabled = False \'此项不可选
        .add("生活消费品供需","生活消费品供需")
        .add("商家促销活动","商家促销活动")
        .add("其他","其他")
    End With
    With wb.AddInputGroup("form1","ipg1","你的新信息")
        .AddTextArea("xxinfo",10).Placeholder = "请输入200字以内的文字信息"
        .AddInput("xxtimeout","有效时限截止:","date")
        With .AddUploader("up2","添加图片",True) \'True表示允许一次上传多个文件
            .TextPosition = 0 \'标题靠左
            .Accept = "image/*"   \'允许使用相册和相机
            .AllowDelete = True \'允许用户删除图片
            .Incremental = True \'允许重复选择文件或连续拍照
        End With
    End With
    With wb.AddButtonGroup("form1","btg1",False)
        .Add("btn1", "确定", "button").Attribute= "" \'调用js函数上传
    End With
    wb.AddToast("","tst1", "正在上传",1)
    wb.AddToast("","tst2", "上传成功,待审核",0)
    wb.AddToast("","tst3", "上传失败",0).Icon= "warn"
    wb.AppendHTML("<script src=\'./lib/ajaxform.js\'></script>") \'引入脚本文件
    e.WriteString(wb.Build)
Else
    Dim nms() As String = {"xxgxfl","xxinfo","xxtimeout"} \'不能为空的列名数组
    For Each nm As String In nms
        If e.PostValues.ContainsKey(nm) = False Then \'生成错误提示页
            With wb.AddMsgPage("","msgpage","您的信息上传未成功", "信息有关项不能为空!")
                .icon = "Warn" \'改变图标
                .AddButton("btn1","返回").Attribute = ""
            End With
            e.WriteString(wb.Build)
            Return "" \'必须返回
        End If
    Next
    nms = New String() {"xxgxfl","xxinfo","xxtimeout"}
    Dim dr As DataRow = DataTables("gxxxtbl").AddNew()
    \'以下代码上传保存图片
    For Each key As String In e.Files.Keys
        Dim pctn As String
        If key = "up2" Then
            For Each fln As String In e.Files(key)
                e.SaveFile(key, fln, ProjectPath & "web\\pict\\" & fln)
            Next
            dr.lines("xxinfopct") = e.files(key)
        End If
    Next
    dr("cxinfodate") = Date.Today \'给信息表新增行的"发布日期"单元格赋值
    dr("xxfbz") = e.Cookies("userid") \'给信息表新增行的"发布者"单元格赋值
    For Each nm As String In nms
        If e.PostValues.ContainsKey(nm) Then
            dr(nm) = e.PostValues(nm)
        End If
    Next
    \'编码生成信息id
    Dim d As Date = Date.Now
    Dim bms As String = cstr(d)
    bms = bms.Replace("-","")
    bms = bms.Replace(" ","")
    bms = bms.Replace(":","")
    dr("cxinfoid") = bms & "d" & e.Cookies("userid") \'自动生成信息id,赋值给信息表新增行的"信息编码"单元格
    \'以下代码处理信息内容分类复选列表项
    Dim nrfl As String
    Dim nrs As List (of String)
    nrs =  DataTables("xxnrtbl").GetValues("xxnrfl")
    For Each nr As String In nrs
        If e.PostValues.ContainsKey(nr) AndAlso e.PostValues(nr).Trim() = "on" Then \'不能省略Trim
            nrfl = nrfl & nr  & ","
        End If
    Next
    If nrfl > "" Then
        dr("xxnrfl") = nrfl.Trim(",") \'赋值给信息表的新增行的"内容分类"单元格
    End If
    \'保存并生成增加成功提示页面
    dr.save()
    With wb.AddMsgPage("","msgpage","上传成功,等待审核!", "") \'生成成功提示页
        .AddButton("btn1","返回","yh.htm")
    End With
    e.WriteString(wb.Build)
End If
[此贴子已经被作者于2019/12/9 15:56:40编辑过]

--  作者:有点蓝
--  发布时间:2019/12/9 15:55:00
--  
AddCheckGroup需要单独判断:http://www.foxtable.com/mobilehelp/topics/0055.htm

Dim nms5 = New String() {"劳务供需","不动产供需","二手供需",..........}
Dim hasxxgxfl As Boolean
For Each nm As String In nms5
    If e.PostValues.ContainsKey(nm) Then \'生成错误提示页
        hasxxgxfl = True
        Exit For
    End If
Next
If hasxxgxfl  = False
    With wb.AddMsgPage("","msgpage","您的信息上传未成功", "内容分类不能为空!")
        .icon = "Warn" \'改变图标
        \' .AddButton("btn1","返回","reset").Attribute = ""
        .AddButton("btn1","返回").Attribute = ""
    End With
    e.WriteString(wb.Build)
    Return "" \'必须返回
End If

--  作者:狐来江湖
--  发布时间:2019/12/13 11:00:00
--  
 Dim e As RequestEventArgs = args(0)
Dim wb As new weui
If e.postvalues.count = 0 Then
    wb.addform("","form1","xxsc.htm")
    With wb.AddRadioGroup("form1","xxgxfl","供需分类")
        .Add("供给","供给")  \',True)
        .Add("需求","需求")
    End With
    With wb.AddCheckGroup("form1","xxnrfl","内容分类")
        .Add("劳务供需","劳务供需") \', True) \'默认勾选
        .Add("不动产供需","不动产供需")
        .Add("二手供需","二手供需")
        .Add("社区公益","社区公益")  \'.Enabled = False \'此项不可选
        .add("生活消费品供需","生活消费品供需")
        .add("商家促销活动","商家促销活动")
        .add("其他","其他")
    End With
    With wb.AddInputGroup("form1","ipg1","你的新信息")
        .AddTextArea("xxinfo",10).Placeholder = "请输入200字以内的文字信息"
        .AddInput("xxtimeout","有效时限截止:","date")
        With .AddUploader("up2","添加图片",True) \'True表示允许一次上传多个文件
            .TextPosition = 0 \'标题靠左
            .Accept = "image/*"   \'允许使用相册和相机
            .AllowDelete = True \'允许用户删除图片
            .Incremental = True \'允许重复选择文件或连续拍照
        End With
    End With
    With wb.AddButtonGroup("form1","btg1",False)
        .Add("btn1", "确定", "button").Attribute= "" \'调用js函数上传
        \' .add ("btn1", "确定", "submit")
    End With
    wb.AddToast("","tst1", "正在上传",1)
    wb.AddToast("","tst2", "上传成功,待审核",0)
    wb.AddToast("","tst3", "上传失败",0).Icon= "warn"
    wb.AppendHTML("<script src=\'./lib/ajaxform.js\'></script>") \'引入脚本文件
    e.WriteString(wb.Build)
Else
    Dim nms() As String = {"xxgxfl","xxinfo","xxtimeout"} \'不能为空的列名数组
    For Each nm As String In nms
        If e.PostValues.ContainsKey(nm) = False Then \'生成错误提示页
            With wb.AddMsgPage("","msgpage","您的信息上传未成功", "供需分类|信息内容|有效时限均不能为空!")
                .icon = "Warn" \'改变图标
                \' .AddButton("btn1","返回","reset").Attribute = ""
                .AddButton("btn1","返回").Attribute = ""
            End With
            e.WriteString(wb.Build)
            Return "" \'必须返回
        End If
    Next
    Dim nms5 = New String() {"劳务供需","不动产供需","二手供需","社区公益","生活消费品供需","商家促销活动","其他"}
    Dim hasxxnrfl As Boolean
    For Each nm As String In nms5
        If e.PostValues.ContainsKey(nm) Then \'生成错误提示页
            hasxxnrfl = True
            Exit For
        End If
    Next
    If hasxxnrfl  = False
        With wb.AddMsgPage("","msgpage","您的信息上传未成功", "内容分类不能为空!")
            .icon = "Warn" \'改变图标
            .AddButton("btn1","返回").Attribute = ""
        End With
        e.WriteString(wb.Build)
        Return "" \'必须返回
    End If

    nms = New String() {"xxgxfl","xxinfo","xxtimeout"}
    Dim dr As DataRow = DataTables("gxxxtbl").AddNew()
    \'以下代码上传保存图片
    For Each key As String In e.Files.Keys
        Dim pctn As String
        If key = "up2" Then
            For Each fln As String In e.Files(key)
                e.SaveFile(key, fln, ProjectPath & "web\\pict\\" & fln)
                \'                        pctn = pctn & fln &","
            Next
            \'                    If pctn > "" Then
            dr.lines("xxinfopct") = e.files(key)
            \'                    End If
        End If
    Next
    dr("cxinfodate") = Date.Today \'给信息表新增行的"发布日期"单元格赋值
    dr("xxfbz") = e.Cookies("userid") \'给信息表新增行的"发布者"单元格赋值
    For Each nm As String In nms
        If e.PostValues.ContainsKey(nm) Then
            dr(nm) = e.PostValues(nm)
        End If
    Next
    \'编码生成信息id
    Dim d As Date = Date.Now
    Dim bms As String = cstr(d)
    bms = bms.Replace("-","")
    bms = bms.Replace(" ","")
    bms = bms.Replace(":","")
    dr("cxinfoid") = bms & "d" & e.Cookies("userid") \'自动生成信息id,赋值给信息表新增行的"信息编码"单元格
    \'以下代码处理信息内容分类复选列表项
    Dim nrfl As String
    Dim nrs As List (of String)
    nrs =  DataTables("xxnrtbl").GetValues("xxnrfl")
    For Each nr As String In nrs
        If e.PostValues.ContainsKey(nr) AndAlso e.PostValues(nr).Trim() = "on" Then \'不能省略Trim
            nrfl = nrfl & nr  & ","
        End If
    Next
    If nrfl > "" Then
        dr("xxnrfl") = nrfl.Trim(",") \'赋值给信息表的新增行的"内容分类"单元格
    End If
    \'保存并生成增加成功提示页面
    dr.save()
    With wb.AddMsgPage("","msgpage","上传成功,等待审核!", "") \'生成成功提示页
        .AddButton("btn1","返回","yh.htm")
    End With
    e.WriteString(wb.Build)
End If
--  作者:狐来江湖
--  发布时间:2019/12/13 11:16:00
--  
 蓝老师,之前的checkgroup已经按照您的要求做了判断,但是代码中黄标的部分,即使出现了对应的情况,依然没有相应提示,
最后即使上传成功,也如之前一样,显示“上传失败”。
我的代码的逻辑有没有什么纰漏的地方?或者不合理的地方?
请指教!

--  作者:有点蓝
--  发布时间:2019/12/13 11:38:00
--  
With wb.AddRadioGroup("form1","xxgxfl","供需分类")
        .Add("供给","供给")  \',True)
        .Add("需求","需求")
    End With

这里也要改为同样的方式判断

另外多选框,单选框的取值赋值也要另外处理
For Each nm As String In nms
        If e.PostValues.ContainsKey(nm) Then
            dr(nm) = e.PostValues(nm)
        End If
    Next