Foxtable(狐表)用户栏目专家坐堂 → 登陆窗口中的复选框选中时让表中的复选框也选中


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

主题:登陆窗口中的复选框选中时让表中的复选框也选中

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


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
登陆窗口中的复选框选中时让表中的复选框也选中  发帖心情 Post By:2012/8/28 22:38:00 [显示全部帖子]

各位老师,

 如下图,我在用户登陆窗口中勾选了“记住密码”复选框,确定时要实现用户表中对应列的复选框也选中,如下图

 


此主题相关图片如下:未命名.jpg
按此在新窗口浏览图片

 

我用了以下代码,但提示出错

Dim UserName As String = e.Form.Controls("UserName").Value
Dim chk As WinForm.CheckBox = e.Form.Controls("CheckBox1")
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim dr As DataRow
cmd.C
If UserName = ""  Then
    Messagebox.show("请选择用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
cmd.CommandText = "Select * From {用户} Where [Name] = '" & UserName & "'"
dt = cmd.ExecuteReader
dr = dt.DataRows(0)
If e.Form.Controls("PassWord").Value = dr("Password") Then
    _UserName = UserName
    _UserGroup = dr("Group")
    _UserRole = dr("Role")


dr("记住密码").checked = chk.checked

 

其余代码略。。。

请问最后一句代码要怎么写?

 

谢谢!


 

 


 


 回到顶部
帅哥哟,离线,有人找我吗?
zpx_2012
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2012/8/28 23:04:00 [显示全部帖子]

谢谢两位老师,现在不提示出错了,但是勾选后不起作用啊,问题会出在哪里呢?以下是确定按钮的全部代码,

 

Dim UserName As String = e.Form.Controls("UserName").Value
Dim chk As WinForm.CheckBox = e.Form.Controls("CheckBox1")
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim dr As DataRow
cmd.C
If UserName = ""  Then
    Messagebox.show("请选择用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
cmd.CommandText = "Select * From {用户} Where [Name] = '" & UserName & "'"
dt = cmd.ExecuteReader
dr = dt.DataRows(0)
If e.Form.Controls("PassWord").Value = dr("Password") Then
    _UserName = UserName
    _UserGroup = dr("Group")
    _UserRole = dr("Role")
'dr("记住密码") = True

dr("记住密码") = chk.checked
    If _UserName <> "开发者" Then
        TableCaptionVisible = False
        Dim drs As List(Of DataRow)
        drs = DataTables("授权表").Select("部门 = '" & _UserGroup & "' And 角色 In ('" & _UserRole & "')")
        If drs.count < 1 Then
            MessageBox.Show("你还没有被授权,不能查看及编辑任何数据,请联系管理员制授权!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            e.Form.Close()
            Syscmd.Project.Exit()
           
           
        Else
            e.Form.Close
           
            For Each dr1 As DataRow In drs
               
                '        For Each dr1 As DataRow In DataTables("授权表").Select("部门 = '" & _UserGroup & "' And 角色 In ('" & _UserRole & "')")
                If dr1.IsNull("可查看列") Then
                    Tables(dr1("表名")).Visible = False
                    Tables(dr1("表名")).AllowEdit = False
                ElseIf dr1.IsNull("可编辑列") Then
                    Tables(dr1("表名")).AllowEdit = False
                Else
                    For Each tb As Table In Tables
                        If tb.name = dr1("表名") Then
                            For Each c As Col In tb.Cols
                                Dim a As String = c.name
                                If dr1("可查看列").contains(a) Then
                                    c.Visible = True
                                Else
                                    c.Visible = False
                                End If
                                If dr1("可编辑列").contains(a) Then
                                    c.AllowEdit = True
                                Else
                                    c.AllowEdit = False
                                End If
                            Next
                        End If
                    Next
                End If
            Next
            '设置导航
            Forms("导航").Open()
            '设置权限
           
        End If
    End If
    '设置分页加载所有表
    '    For Each dt1 As DataTable In DataTables
    '       dt1.LoadFilter = "" '清除加载条件
    '       dt1.LoadTop = 20
    '      dt1.LoadPage = 0
    '      dt1.Load()
    'Next
   
Else
    Messagebox.show("密码错误!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

谢谢两位老师



 回到顶部
帅哥哟,离线,有人找我吗?
zpx_2012
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2012/8/28 23:30:00 [显示全部帖子]

谢谢CZY老师,但反得修改还是不行,老提示出错,请问

SQL Server数据源还要将逻辑值转换成0和1要怎么写,是下面这样吗,我不会。

 

 Dim cmd1 As New SQLCommand
    If  chk.checked = True Then
        chk.checked =1
    Else
        chk.checked =0
    End If
   
    cmd1.CommandText = "UPDATE {用户} SET 记住密码 = " & chk.checked & "  Where [Name] = '" & UserName & "'"
    cmd1.ExecuteNonQuery()

 

谢谢!

如果不用SQL语句,直接用一般的方式用如下代码就很容易实现这个要求,如下:

 

Dim UserName As String = e.Form.Controls("UserName").Value
Dim chk As WinForm.CheckBox = e.Form.Controls("CheckBox1")
Dim dr As DataRow
If UserName = ""  Then
    Messagebox.show("请选择用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
dr = DataTables("用户").Find("[Name] = '" & UserName & "'")
If chk.checked = True Then
    dr("记住密码") = True
Else
    dr("记住密码") = False
End If


 

我还想问的是:是不是SQL语句执行速度更快?两者比较有什么不同?请老师明天抽空看一下

谢谢!

[此贴子已经被作者于2012-8-29 0:05:12编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
zpx_2012
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2012/8/29 12:10:00 [显示全部帖子]

谢谢狐爸,但运行了提示出错,是不是哪里不对?

 

 


此主题相关图片如下:qq截图20120829120700.jpg
按此在新窗口浏览图片

 

如果不用SQL语句,直接用一般的方式用如下代码就很容易实现这个要求,如下:

 

Dim UserName As String = e.Form.Controls("UserName").Value
Dim chk As WinForm.CheckBox = e.Form.Controls("CheckBox1")
Dim dr As DataRow
If UserName = ""  Then
    Messagebox.show("请选择用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
dr = DataTables("用户").Find("[Name] = '" & UserName & "'")
If chk.checked = True Then
    dr("记住密码") = True
Else
    dr("记住密码") = False
End If


 

我还想问的是:是不是SQL语句执行速度更快?两者比较有什么不同?

 

谢谢!


 回到顶部
帅哥哟,离线,有人找我吗?
zpx_2012
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2012/8/29 15:58:00 [显示全部帖子]

谢谢狐神的回复,但外部数据源是有定义的,现在精简代码如下:

 

Dim UserName As String = e.Form.Controls("UserName").Value
Dim chk As WinForm.CheckBox = e.Form.Controls("CheckBox1")
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim dr As DataRow
cmd.C
If UserName = ""  Then
    Messagebox.show("请选择用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
cmd.CommandText = "Select * From {用户} Where [Name] = '" & UserName & "'"
dt = cmd.ExecuteReader
dr = dt.DataRows(0)
If e.Form.Controls("PassWord").Value = dr("Password") Then
    _UserName = UserName
    _UserGroup = dr("Group")
    _UserRole = dr("Role")

 Dim cmd1 As New SQLCommand
    If  chk.checked = True Then
        chk.checked =1
    Else
        chk.checked =0
    End If
    cmd1.CommandText = "UPDATE {用户} SET 记住密码 = " & chk.checked & "  Where [Name] = '" & UserName  & "'"
    cmd1.ExecuteNonQuery()

Else
    Messagebox.show("密码错误!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

那行红色的,

本来是 cmd.C

不知什么原因复制到论坛上就只有前面部份了。 

但运行后还是会出现那个错误的提示框。现在只好不用SQL语句了。

[此贴子已经被作者于2012-8-29 16:00:29编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
zpx_2012
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2012/8/29 16:04:00 [显示全部帖子]

奇怪,本来是

 

 


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20120829160242.jpg
图片点击可在新窗口打开查看

不知什么原因复制到论坛上就只有前面部份了。 

 

 cmd.C


 回到顶部
帅哥哟,离线,有人找我吗?
zpx_2012
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2012/8/29 20:43:00 [显示全部帖子]

谢谢CZY版主,已经加了9楼的那段代码了,但会出现10楼截图的那个错误,代码如下:

Dim UserName As String = e.Form.Controls("UserName").Value
Dim chk As WinForm.CheckBox = e.Form.Controls("CheckBox1")
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim dr As DataRow
cmd.C
If UserName = ""  Then
    Messagebox.show("请选择用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
cmd.CommandText = "Select * From {用户} Where [Name] = '" & UserName & "'"
dt = cmd.ExecuteReader
dr = dt.DataRows(0)
If e.Form.Controls("PassWord").Value = dr("Password") Then
    _UserName = UserName
    _UserGroup = dr("Group")
    _UserRole = dr("Role")
    Dim cmd1 As New SQLCommand
    Dim v As Integer
    If chk.checked = True Then
        v = 1
    Else
        v  =0
    End If
    cmd1.CommandText = "UPDATE {用户} SET 记住密码 = " & v & "  Where [Name] = '" & UserName & "'"
    cmd1.ExecuteNonQuery()

 

 

外部SQL数据源及用户表都是定义好的,不会有错。



 回到顶部
帅哥哟,离线,有人找我吗?
zpx_2012
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:976 积分:8527 威望:0 精华:0 注册:2012/2/9 16:35:00
  发帖心情 Post By:2012/8/29 21:14:00 [显示全部帖子]

谢谢CZY版主,可以了,原来是每一个定义一个不同的SQLCommand命令都要重新设定一下外部数据源。

初学真的很多东西没有领悟啊。再次感谢!


 回到顶部