⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmuserupdate.frm

📁 适用一般于毕业设计! VB代码源加SQL 数据库 ··
💻 FRM
字号:
VERSION 5.00
Begin VB.Form FrmUserUpdate 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "编辑用户信息"
   ClientHeight    =   2910
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   4575
   Icon            =   "FrmUserUpdate.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2910
   ScaleWidth      =   4575
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton cmdOk 
      Caption         =   "确定"
      Default         =   -1  'True
      Height          =   400
      Left            =   720
      TabIndex        =   3
      Top             =   2280
      Width           =   1125
   End
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "取消"
      Height          =   400
      Left            =   2580
      TabIndex        =   4
      Top             =   2280
      Width           =   1125
   End
   Begin VB.Frame Frame1 
      Height          =   1935
      Left            =   180
      TabIndex        =   5
      Top             =   120
      Width           =   4215
      Begin VB.TextBox txtUserNo 
         Height          =   375
         IMEMode         =   3  'DISABLE
         Left            =   1560
         TabIndex        =   0
         Text            =   "UserNo"
         Top             =   360
         Width           =   1995
      End
      Begin VB.TextBox txtPwd 
         Height          =   375
         IMEMode         =   3  'DISABLE
         Left            =   1560
         PasswordChar    =   "*"
         TabIndex        =   2
         Text            =   "Pwd"
         Top             =   1320
         Width           =   1995
      End
      Begin VB.TextBox txtUserName 
         Height          =   375
         Left            =   1560
         TabIndex        =   1
         Text            =   "UserName"
         Top             =   840
         Width           =   1995
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "用户名称"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   9
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   180
         Left            =   600
         TabIndex        =   8
         Top             =   900
         Width           =   720
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "用户编号"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   9
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   180
         Left            =   600
         TabIndex        =   7
         Top             =   420
         Width           =   720
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "密    码"
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   9
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   180
         Left            =   600
         TabIndex        =   6
         Top             =   1380
         Width           =   720
      End
   End
End
Attribute VB_Name = "FrmUserUpdate"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Form_Load()
  If ModifyFlag = 0 Then      '添加记录,需要清空各控件中的内容
    txtUserNo.Text = ""
    txtUserName.Text = ""
    txtPwd.Text = ""
  Else                        '修改记录,在控件中填充内容
    With FrmUser
      txtUserNo.Text = IIf(IsNull(.rsUser!UserNo), "", .rsUser!UserNo)
      txtUserName.Text = IIf(IsNull(.rsUser!UserName), "", .rsUser!UserName)
      txtPwd.Text = IIf(IsNull(.rsUser!UserPwd), "", .rsUser!UserPwd)
    End With
  End If
  '不允许修改默认用户Admin的编号
  If UCase(txtUserNo.Text) = UCase("Admin") Then
    txtUserNo.Enabled = False
  End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Set FrmUserUpdate = Nothing
End Sub

Private Sub cmdOk_Click()
  On Error GoTo ErrorHandle
  Dim strSql As String
  Dim Rs As New ADODB.Recordset

  If Trim(txtUserNo.Text) = "" Then
    MsgBox "请输入用户编号", vbExclamation + vbOKOnly, "操作提示"
    txtUserNo.SetFocus
    Exit Sub
  End If
  If Trim(txtUserName.Text) = "" Then
    MsgBox "请输入用户名称", vbExclamation + vbOKOnly, "操作提示"
    txtUserName.SetFocus
    Exit Sub
  End If
  
  If ModifyFlag = 0 Then      '添加记录
    '判断用户编号是否重复,若重复,要求重新输入
    strSql = "select count(*) as s_count from users " & _
             "where UserNo='" & txtUserNo.Text & "'"
    Rs.Open strSql, Conn, adOpenStatic, adLockReadOnly
    If Rs!s_count > 0 Then
      MsgBox "用户编号 " & txtUserNo.Text & " 已经存在", _
                vbExclamation + vbOKOnly, "操作提示"
      txtUserNo.SetFocus
      Rs.Close
      Set Rs = Nothing
      Exit Sub
    End If
    Rs.Close
    Set Rs = Nothing
  
    '正式添加用户
    With FrmUser
      .rsUser.AddNew              '添加用户
      .rsUser!UserNo = txtUserNo.Text     '用户编号
      .rsUser!UserName = txtUserName.Text   '用户名称
      .rsUser!UserPwd = txtPwd.Text       '密码
      .rsUser.Update              '更新
    End With
  Else      '修改记录
    '如果用户编号修改了,需要判断用户编号是否重复,若重复,要求重新输入
    If UCase(txtUserNo.Text) <> UCase(FrmUser.rsUser!UserNo) Then
      strSql = "select count(*) as s_count from users " & _
               "where UserNo='" & txtUserNo.Text & "'"
      Rs.Open strSql, Conn, adOpenStatic, adLockReadOnly
      If Rs!s_count > 0 Then
        MsgBox "用户编号 " & txtUserNo.Text & " 已经存在", _
                  vbExclamation + vbOKOnly, "操作提示"
        txtUserNo.SetFocus
        Rs.Close
        Set Rs = Nothing
        Exit Sub
      End If
      Rs.Close
      Set Rs = Nothing
    End If
    
    '正式修改用户
    With FrmUser
      .rsUser!UserNo = txtUserNo.Text     '用户编号
      .rsUser!UserName = txtUserName.Text   '用户名称
      .rsUser!UserPwd = txtPwd.Text       '密码
      .rsUser.Update              '更新
    End With

    '如果修改的是默认用户Admin,需要修改状态条上用户名称显示
    If UCase(txtUserNo.Text) = UCase("Admin") Then
      CurLoginUserName = txtUserName.Text
      FrmMain.StatusBar1.Panels("user").Text = "登录用户:" & CurLoginUserName
    End If
  End If

  Unload Me
  
  On Error GoTo 0
  Exit Sub
  
ErrorHandle:
  MsgBox Error(Err.Number), vbExclamation + vbOKOnly, "操作提示"
End Sub

Private Sub cmdCancel_Click()
  Unload Me
End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -