frmUser.frm
上传用户:xianglong
上传日期:2022-06-19
资源大小:1105k
文件大小:10k
源码类别:

控制台编程

开发平台:

Visual Basic

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
  3. Begin VB.Form frmUser 
  4.    Caption         =   "用户管理"
  5.    ClientHeight    =   3945
  6.    ClientLeft      =   45
  7.    ClientTop       =   435
  8.    ClientWidth     =   5160
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   3945
  13.    ScaleWidth      =   5160
  14.    StartUpPosition =   2  '屏幕中心
  15.    Begin MSComctlLib.ImageList ImList 
  16.       Left            =   4200
  17.       Top             =   600
  18.       _ExtentX        =   1005
  19.       _ExtentY        =   1005
  20.       BackColor       =   -2147483643
  21.       ImageWidth      =   16
  22.       ImageHeight     =   16
  23.       MaskColor       =   12632256
  24.       _Version        =   393216
  25.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  26.          NumListImages   =   5
  27.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  28.             Picture         =   "frmUser.frx":0000
  29.             Key             =   ""
  30.          EndProperty
  31.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  32.             Picture         =   "frmUser.frx":08DA
  33.             Key             =   ""
  34.          EndProperty
  35.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  36.             Picture         =   "frmUser.frx":11B4
  37.             Key             =   ""
  38.          EndProperty
  39.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  40.             Picture         =   "frmUser.frx":1A8E
  41.             Key             =   ""
  42.          EndProperty
  43.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  44.             Picture         =   "frmUser.frx":2368
  45.             Key             =   ""
  46.          EndProperty
  47.       EndProperty
  48.    End
  49.    Begin VB.Frame Frame1 
  50.       Caption         =   "用户列表"
  51.       Height          =   2535
  52.       Left            =   120
  53.       TabIndex        =   7
  54.       Top             =   1080
  55.       Width           =   2295
  56.       Begin VB.ListBox lstname 
  57.          BackColor       =   &H00FFFFFF&
  58.          ForeColor       =   &H00FF0000&
  59.          Height          =   1860
  60.          Left            =   120
  61.          TabIndex        =   8
  62.          Top             =   360
  63.          Width           =   2055
  64.       End
  65.    End
  66.    Begin VB.Frame Frame2 
  67.       Caption         =   "添加新用户"
  68.       Height          =   2535
  69.       Left            =   2520
  70.       TabIndex        =   0
  71.       Top             =   1080
  72.       Width           =   2535
  73.       Begin VB.CommandButton CmdOK 
  74.          Caption         =   "确定"
  75.          Default         =   -1  'True
  76.          Height          =   375
  77.          Left            =   120
  78.          Picture         =   "frmUser.frx":2C42
  79.          Style           =   1  'Graphical
  80.          TabIndex        =   4
  81.          Top             =   2040
  82.          Width           =   735
  83.       End
  84.       Begin VB.CommandButton CmdNO 
  85.          Caption         =   "取消"
  86.          Height          =   375
  87.          Left            =   1680
  88.          Picture         =   "frmUser.frx":2F4C
  89.          Style           =   1  'Graphical
  90.          TabIndex        =   3
  91.          Top             =   2040
  92.          Width           =   735
  93.       End
  94.       Begin VB.TextBox txtUser 
  95.          Appearance      =   0  'Flat
  96.          ForeColor       =   &H00FF0000&
  97.          Height          =   375
  98.          Left            =   1080
  99.          TabIndex        =   2
  100.          Top             =   480
  101.          Width           =   1215
  102.       End
  103.       Begin VB.TextBox txtPassword 
  104.          Appearance      =   0  'Flat
  105.          ForeColor       =   &H00FF0000&
  106.          Height          =   375
  107.          IMEMode         =   3  'DISABLE
  108.          Left            =   1080
  109.          PasswordChar    =   "*"
  110.          TabIndex        =   1
  111.          Top             =   1200
  112.          Width           =   1215
  113.       End
  114.       Begin VB.Label lb1 
  115.          BackStyle       =   0  'Transparent
  116.          Caption         =   "用户名:"
  117.          ForeColor       =   &H00FF0000&
  118.          Height          =   255
  119.          Left            =   120
  120.          TabIndex        =   6
  121.          Top             =   480
  122.          Width           =   975
  123.       End
  124.       Begin VB.Label lb2 
  125.          BackStyle       =   0  'Transparent
  126.          Caption         =   "密  码:"
  127.          ForeColor       =   &H00FF0000&
  128.          Height          =   372
  129.          Left            =   120
  130.          TabIndex        =   5
  131.          Top             =   1200
  132.          Width           =   852
  133.       End
  134.    End
  135.    Begin MSComctlLib.Toolbar Tlbar 
  136.       Align           =   1  'Align Top
  137.       Height          =   570
  138.       Left            =   0
  139.       TabIndex        =   9
  140.       Top             =   0
  141.       Width           =   5160
  142.       _ExtentX        =   9102
  143.       _ExtentY        =   1005
  144.       ButtonWidth     =   820
  145.       ButtonHeight    =   953
  146.       Appearance      =   1
  147.       Style           =   1
  148.       ImageList       =   "ImList"
  149.       _Version        =   393216
  150.       BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
  151.          NumButtons      =   7
  152.          BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  153.             Caption         =   "添加"
  154.             Key             =   "Add"
  155.             ImageIndex      =   1
  156.          EndProperty
  157.          BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  158.             Caption         =   "删除"
  159.             Key             =   "Del"
  160.             ImageIndex      =   2
  161.          EndProperty
  162.          BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  163.             Style           =   3
  164.          EndProperty
  165.          BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  166.             Caption         =   "保存"
  167.             Key             =   "Save"
  168.             ImageIndex      =   3
  169.          EndProperty
  170.          BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  171.             Caption         =   "撤销"
  172.             Key             =   "Undo"
  173.             ImageIndex      =   4
  174.          EndProperty
  175.          BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  176.             Style           =   3
  177.          EndProperty
  178.          BeginProperty Button7 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  179.             Caption         =   "退出"
  180.             Key             =   "Exit"
  181.             ImageIndex      =   5
  182.          EndProperty
  183.       EndProperty
  184.    End
  185.    Begin VB.Label x 
  186.       BackStyle       =   0  'Transparent
  187.       Caption         =   "已启用"
  188.       ForeColor       =   &H000000FF&
  189.       Height          =   255
  190.       Left            =   120
  191.       TabIndex        =   10
  192.       Top             =   3720
  193.       Visible         =   0   'False
  194.       Width           =   1575
  195.    End
  196. End
  197. Attribute VB_Name = "frmUser"
  198. Attribute VB_GlobalNameSpace = False
  199. Attribute VB_Creatable = False
  200. Attribute VB_PredeclaredId = True
  201. Attribute VB_Exposed = False
  202. Public dbs As Database
  203. Public rec As Recordset
  204. Public rec1 As Recordset
  205. Sub save()
  206.   If txtUser.Text = "" Then
  207.   Exit Sub
  208.   End If
  209.   
  210.   filename = App.Path & "dbmaterialinfo2007.mdb"
  211.   Set dbs = OpenDatabase(filename)
  212.   Set rec = dbs.OpenRecordset("用户信息表")
  213.          rec.AddNew
  214.          rec.Fields(0) = txtUser.Text
  215.          rec.Fields(1) = txtPassword.Text
  216.          rec.Update
  217.                 
  218.   Set rec1 = dbs.OpenRecordset("用户角色表")
  219.          rec1.AddNew
  220.          rec1.Fields(5) = txtUser.Text
  221.          rec1.Fields(6) = txtPassword.Text
  222.          rec1.Update
  223.          
  224.          lstname.AddItem txtUser.Text
  225.          txtUser.Text = ""
  226.          txtPassword.Text = ""
  227.          txtUser.SetFocus
  228. End Sub
  229. Private Sub CmdNO_Click()
  230. Unload Me
  231. End Sub
  232. Private Sub CmdOK_Click()
  233. save
  234. End Sub
  235. Private Sub Form_Load()
  236. CmdOK.Enabled = False
  237. txtUser.Enabled = False
  238. txtPassword.Enabled = False
  239.   
  240.   filename = App.Path & "dbmaterialinfo2007.mdb"
  241.   Set dbs = OpenDatabase(filename)
  242.   Set rec = dbs.OpenRecordset("用户信息表")
  243.   Set rec1 = dbs.OpenRecordset("用户角色表")
  244.   
  245.   If rec.RecordCount = 0 Then
  246.   Exit Sub
  247.   End If
  248.   
  249.   If rec1.RecordCount = 0 Then
  250.   Exit Sub
  251.   End If
  252.   
  253.   
  254. Do While Not rec.EOF
  255.    lstname.AddItem rec.Fields(0)
  256.    rec.MoveNext
  257.    rec1.MoveNext
  258. Loop
  259.      Tlbar.Buttons(2).Enabled = False
  260.      Tlbar.Buttons(3).Enabled = False
  261.      Tlbar.Buttons(4).Enabled = False
  262. End Sub
  263. Private Sub Tlbar_ButtonClick(ByVal Button As MSComctlLib.Button)
  264.  Select Case Button.key
  265.      Case "Add"
  266.        Changed = False
  267.        Tlbar.Buttons(5).Enabled = False
  268.        txtUser.Enabled = True
  269.        txtPassword.Enabled = True
  270.        txtUser.Text = ""
  271.        txtPassword.Text = ""
  272.        txtUser.SetFocus
  273.        CmdOK.Enabled = False
  274.     Case "Undo"
  275.        txtUser.Text = ""
  276.        txtPassword.Text = ""
  277.        Tlbar.Buttons(2).Enabled = False
  278.        Tlbar.Buttons(3).Enabled = False
  279.        Tlbar.Buttons(5).Enabled = False
  280.     Case "Save"
  281.         Tlbar.Buttons(2).Enabled = False
  282.         save
  283.     Case "Del"
  284.         r = MsgBox("确定删除吗?(Y/N)", 1 + 64, "自动配料系统")
  285.       If r = 1 Then
  286.           dbs.Execute "DELETE * FROM " & "[用户信息表] WHERE name ='" & lstname.Text & "'"
  287.           
  288.           dbs.Execute "DELETE * FROM " & "[用户角色表] WHERE name ='" & lstname.Text & "'"
  289.           
  290.           txtUser.Text = ""
  291.           lstname.RemoveItem lstname.ListIndex
  292.           txtPassword.Text = ""
  293.       End If
  294.     Case "Exit"
  295.           Unload Me
  296.     End Select
  297. End Sub
  298. Private Sub txtPassword_Change()
  299.   CmdOK.Enabled = True
  300.   Tlbar.Buttons(4).Enabled = True
  301. End Sub
  302. Private Sub lstname_Click()
  303.     If lstname.Text = "SuperUser" Then
  304.        Tlbar.Buttons(2).Enabled = False
  305.     Else
  306.        Tlbar.Buttons(2).Enabled = True
  307.     End If
  308. End Sub