📄 frmdept.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form frmDept
BorderStyle = 1 'Fixed Single
Caption = "部门代号维护"
ClientHeight = 4185
ClientLeft = 45
ClientTop = 330
ClientWidth = 6105
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4185
ScaleWidth = 6105
StartUpPosition = 2 '屏幕中心
Begin MSComctlLib.ImageList ImageList1
Left = 2400
Top = 2640
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 50
ImageHeight = 32
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 1
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmDept.frx":0000
Key = ""
EndProperty
EndProperty
End
Begin MSComctlLib.ListView LViewDept
Height = 2775
Left = 120
TabIndex = 6
Top = 1320
Width = 5895
_ExtentX = 10398
_ExtentY = 4895
View = 3
LabelWrap = -1 'True
HideSelection = -1 'True
FullRowSelect = -1 'True
GridLines = -1 'True
_Version = 393217
Icons = "ImageList1"
SmallIcons = "ImageList1"
ColHdrIcons = "ImageList1"
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
Begin VB.CommandButton cmdDelete
Caption = "删除"
Height = 375
Left = 4320
TabIndex = 5
Top = 120
Width = 975
End
Begin VB.CommandButton cmdSave
Caption = "保存"
Height = 375
Left = 2880
TabIndex = 4
Top = 120
Width = 855
End
Begin VB.TextBox txtItem
Height = 375
Index = 1
Left = 1200
MaxLength = 20
TabIndex = 3
Top = 720
Width = 4095
End
Begin VB.TextBox txtItem
Height = 375
Index = 0
Left = 1200
MaxLength = 3
TabIndex = 2
Top = 120
Width = 1095
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "部门名称"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 210
Left = 120
TabIndex = 1
Top = 840
Width = 900
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "部门代号"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 210
Left = 120
TabIndex = 0
Top = 240
Width = 900
End
End
Attribute VB_Name = "frmDept"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public mrc As ADODB.Recordset
Dim txtSql As String
Private Sub cmdDelete_Click()
'检查数据
If Not check_data Then
Exit Sub
End If
'删除语句
txtSql = "delete from dept where Code ='" & txtItem(0).Text & "'"
Set mrc = Nothing
Set mrc = ExecuteSQL(txtSql)
ShowList ' 刷新数据
Cleartxt '清除文本中的数据
End Sub
Private Sub cmdSave_Click()
'检查数据
If Not check_data Then
Exit Sub
End If
'判断是否新增的SQL语句
txtSql = "select * from dept where Code='" & txtItem(0).Text & "'"
Set mrc = Nothing
Set mrc = ExecuteSQL(txtSql)
If mrc.EOF = False Then '修改
' txtSql = "select * from feria where DealDate='" & DTPDealDate.Value & "'"
' Set mrc = ExecuteSQL(txtSql)
mrc.Fields(1) = txtItem(1).Text
mrc.Update
Else '新增
txtSql = "select * from dept"
Set mrc = Nothing
Set mrc = ExecuteSQL(txtSql)
mrc.AddNew
mrc.Fields(0) = txtItem(0).Text
mrc.Fields(1) = txtItem(1).Text
mrc.Update
End If
Set mrc = Nothing
ShowList ' 刷新数据
Cleartxt '清除文本中的数据
End Sub
Private Sub Form_Load()
Dim FlagEnabled As Boolean
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
FlagEnabled = CheckProgramLimit("hrd103")
cmdSave.Enabled = FlagEnabled
cmdDelete.Enabled = FlagEnabled
Call Init '初始化
Call ShowList
End Sub
Private Sub Init()
Dim TvHead As ColumnHeader
Set TvHead = LViewDept.ColumnHeaders.Add(, "h01", "序号", 0)
Set TvHead = LViewDept.ColumnHeaders.Add(, "h02", "部门代号", 2000)
Set TvHead = LViewDept.ColumnHeaders.Add(, "h03", "部门名称", 30000)
End Sub
Private Sub ShowList()
Dim i As Integer
Dim LvDate As ListItem
LViewDept.ListItems.Clear
txtSql = "select * from dept"
Set mrc = Nothing
Set mrc = ExecuteSQL(txtSql)
i = 1
Do While Not mrc.EOF
Set LvData = LViewDept.ListItems.Add(, "d" & i, i, 1, 1)
LvData.SubItems(1) = mrc.Fields(0).Value
LvData.SubItems(2) = mrc.Fields(1).Value
i = i + 1
mrc.MoveNext
Loop
mrc.Close
End Sub
Private Sub LViewDept_BeforeLabelEdit(Cancel As Integer)
Cancel = 1
End Sub
Private Sub LViewDept_ItemClick(ByVal Item As MSComctlLib.ListItem)
txtItem(0).Text = Item.SubItems(1)
txtItem(1).Text = Item.SubItems(2)
End Sub
Private Function check_data() As Boolean
Dim i As Integer
check_data = True
For i = 0 To 1
If txtItem(i).Text = "" Then
MsgBox "输入的数据不能为空", vbCritical + vbOKOnly, "错误提示:"
check_data = False
txtItem(i).SetFocus
Exit Function
End If
Next i
End Function
Private Sub Cleartxt()
Dim i As Integer
For i = 0 To txtItem.Count - 1
txtItem(i).Text = ""
Next i
txtItem(0).SetFocus
End Sub
Private Sub txtItem_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
If Index < 1 Then
txtItem(i + 1).SetFocus
Else
txtItem(0).SetFocus
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -