Foxtable(狐表)用户栏目专家坐堂 → 求网页用户注册时用户名不能重复的代码


  共有2620人关注过本帖树形打印复制链接

主题:求网页用户注册时用户名不能重复的代码

帅哥哟,离线,有人找我吗?
cxzhl
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:36 积分:459 威望:0 精华:0 注册:2020/3/23 23:20:00
求网页用户注册时用户名不能重复的代码  发帖心情 Post By:2020/9/7 23:38:00 [只看该作者]

Dim e As RequestEventArgs = args(0)                             '注册第1页,注册
Dim wb As New weui
Select Case e.Path
    Case "register.htm"
        If e.PostValues.Count = 0 Then
            wb.AddTopTips("","toptip1","") '用于显示动态错误提示
            wb.AddPageTitle("","pageheader","《众和出行》","比自驾更省钱的出行方式")
            wb.AddForm("","form1","register.htm").Attribute=""
            With wb.AddInputGroup("form1","ipg1","快速注册")
                With .AddInputCell("ic1")  '通过InputCell增加输入框(1表示突出显示,2表示红色警示图标)
                    .AddLabel("手机号1","手机号",0)  '增加标签(0显示在左边)
                    .AddInput("手机号","text",1).PlaceHolder= "请输入手机号"  '增加输入框(0靠左显示,1居中显示,2靠右显示)
            DataTables("用户").DataCols("手机号").Unique = False '禁止手机号重复
                End With
                .AddInput("openid","微信:","Text")
                With .AddInputCell("ic2")
                    .AddLabel("lyz","验证",0)
                    .AddInput("iyz","text",1).PlaceHolder= "请输入验证码"
                    .AddVcodeButton("vyz","获取验证码",2)  '0靠左显示,1居中显示,2靠右显示
                End With
                With .AddInputCell("ic3")
                    .AddLabel("密码1","密码",0)
                    .AddInput("密码","text",1).PlaceHolder= "请输入密码"
                End With
                .AddInput("上级推广码","上级推广码","Text").Placeholder = "为空表示由总平台推荐"
                .AddInput("注册日期","注册日期","date").Value = Date.Today()
                With .AddInput("推广码","我的推广码","text")
                    .Value = Functions.Execute("tgmscID")   '利用自定义函数生成推广码.
                    .Readonly = True
                End With
                ' .AddSelect("sxb","性别","|男|女")
                .AddSwitch("fuwuxieyi","同意协议")
                With wb.AddButtonGroup("form1","btg1",True)
                    .Add("btn1", "注册", "submit")
                    .Add("btn1", "查看服务协议", "","/zcxy.htm").Kind = 1
                End With
            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 = ""
                    End With
                    e.WriteString(wb.Build)
                   Return "" '必须返回
                End If
            Next
 nms = New String() {"手机号","openid","密码","上级推广码","注册日期","推广码"}   '重新定义了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.save()
            With wb.AddMsgPage("","msgpage","注册成功","欢迎来到《众和出行》") '生成成功提示页
                .AddButton("btn1","登陆","logon.htm")
            End With
            e.WriteString(wb.Build)
        End If
End Select

 

用了以上代码,但没解决问题 ,请老师指导哈!

 


 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111410 积分:567120 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/9/8 9:23:00 [只看该作者]

使用find查询判断

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 "" '必须返回
                End If
            Next
dim drr as datarow = DataTables("用户").find("手机号='" & e.PostValues("手机号")  & "'")
if drr isnot nothing then
                    With wb.AddMsgPage("","msgpage","增加失败", "手机号已经注册!") 
                        .icon = "Warn" '改变图标
                        .AddButton("btn1","返回").Attribute = ""
                    End With
                    e.WriteString(wb.Build)
                   Return "" '必须返回
end if

 回到顶部