📄 frmperiod.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form frmPeriod
BorderStyle = 1 'Fixed Single
Caption = "上班时段设定"
ClientHeight = 3495
ClientLeft = 45
ClientTop = 330
ClientWidth = 6375
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
Palette = "frmPeriod.frx":0000
Picture = "frmPeriod.frx":E9EE
ScaleHeight = 3495
ScaleWidth = 6375
StartUpPosition = 2 '屏幕中心
Begin MSComctlLib.ImageList ImageList1
Left = 1560
Top = 2040
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 38
ImageHeight = 38
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 1
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "frmPeriod.frx":66870
Key = ""
EndProperty
EndProperty
End
Begin VB.TextBox txtItem
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 375
Index = 1
Left = 2640
MaxLength = 2
TabIndex = 12
Top = 120
Width = 450
End
Begin VB.TextBox txtItem
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 375
Index = 3
Left = 2640
MaxLength = 2
TabIndex = 10
Top = 600
Width = 450
End
Begin MSComctlLib.ListView LViewPeriod
Height = 2175
Left = 120
TabIndex = 6
Top = 1200
Width = 6135
_ExtentX = 10821
_ExtentY = 3836
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 = 400
Left = 4200
TabIndex = 5
Top = 600
Width = 1000
End
Begin VB.CommandButton cmdSave
Caption = "保存"
Height = 400
Left = 4200
TabIndex = 4
Top = 120
Width = 1000
End
Begin VB.TextBox txtItem
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 375
Index = 0
Left = 1680
MaxLength = 2
TabIndex = 0
Top = 120
Width = 450
End
Begin VB.TextBox txtItem
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 375
Index = 2
Left = 1680
MaxLength = 2
TabIndex = 3
Top = 600
Width = 450
End
Begin VB.Label Label6
Caption = "分"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 3200
TabIndex = 11
Top = 720
Width = 255
End
Begin VB.Label Label5
Caption = "点"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 2250
TabIndex = 9
Top = 720
Width = 255
End
Begin VB.Label Label4
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 = 3200
TabIndex = 8
Top = 240
Width = 225
End
Begin VB.Label Label3
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 = 2250
TabIndex = 7
Top = 240
Width = 225
End
Begin VB.Label Label2
Caption = "上班终止时间:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 2
Top = 720
Width = 1575
End
Begin VB.Label Label1
Caption = "上班开始时间:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 1
Top = 240
Width = 1695
End
End
Attribute VB_Name = "frmPeriod"
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
Dim MsgText As String
Private Sub cmdDelete_Click()
Dim begintxt As String
If Not check_data Then
Exit Sub
End If
begintxt = Trim(txtItem(0).Text) & ":" & Trim(txtItem(1).Text)
txtSql = "delete from period where BeginTime='" & begintxt & "'"
Set mrc = Nothing
Set mrc = ExecuteSQL(txtSql)
Set mrc = Nothing
ShowMsgListData
Cleartxt '清除文本中的数据
End Sub
Private Sub cmdSave_Click()
Dim nNumber As Double
Dim begintxt, endtxt As String
If Not check_data Then '检查数据
Exit Sub
End If
begintxt = Trim(txtItem(0).Text) & ":" & Trim(txtItem(1).Text) '开始上班时间
endtxt = Trim(txtItem(2).Text) & ":" & Trim(txtItem(3).Text) '终止上班时间
'判断是否新增的SQL语句
txtSql = "select * from period where BeginTime='" & begintxt & "'"
'上班时间
nNumber = (Val(txtItem(2).Text) * 60 + Val(txtItem(3).Text)) - (Val(txtItem(0).Text) * 60 + Val(txtItem(1).Text))
nNumber = nNumber / 60
Set mrc = Nothing
Set mrc = ExecuteSQL(txtSql)
If mrc.EOF = False Then '修改
txtSql = "select * from period where BeginTime='" & begintxt & "'"
Set mrc = ExecuteSQL(txtSql)
'mrc.Fields(0) = BeginTxt
mrc.Fields(1) = endtxt
mrc.Fields(2) = nNumber
mrc.Update
'txtSql = "update Period set EndTime='" & txtItem(1).Text & "',Number=" & nNumber & " where BeginTime='" & txtItem(0).Text & "'"
Else '新增
txtSql = "select * from period"
Set mrc = ExecuteSQL(txtSql)
mrc.AddNew
mrc.Fields(0) = begintxt
mrc.Fields(1) = endtxt
mrc.Fields(2) = nNumber
mrc.Update
'txtSql = "insert into period (BeginTime,EndTime,Number) values('" & txtItem(0).Text & "','" & txtItem(1).Text & "'," & nNumber & ")"
End If
Set mrc = Nothing
'MsgBox MsgText, vbCritical + vbOKOnly, "系统提示:"
ShowMsgListData
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
Call showMsgListTitle
ShowMsgListData
FlagEnabled = CheckProgramLimit("hrd101")
cmdSave.Enabled = FlagEnabled
cmdDelete.Enabled = FlagEnabled
End Sub
Private Sub showMsgListTitle()
Dim TvHead As ColumnHeader
Set TvHead = LViewPeriod.ColumnHeaders.Add(, "h01", "序号", 0)
Set TvHead = LViewPeriod.ColumnHeaders.Add(, "h02", "上班时间", 1800)
Set TvHead = LViewPeriod.ColumnHeaders.Add(, "h03", "下班时间", 1800)
Set TvHead = LViewPeriod.ColumnHeaders.Add(, "h04", "上班时数", 1000)
End Sub
'显示Grid的内容
Public Sub ShowMsgListData()
Dim i As Integer
Dim LvDate As ListItem
LViewPeriod.ListItems.Clear
txtSql = "select * from period"
Set mrc = Nothing
Set mrc = ExecuteSQL(txtSql)
i = 1
Do While Not mrc.EOF
Set LvData = LViewPeriod.ListItems.Add(, "d" & i, i, 1, 1)
LvData.SubItems(1) = mrc.Fields(0).Value
LvData.SubItems(2) = mrc.Fields(1).Value
LvData.SubItems(3) = mrc.Fields(2).Value
i = i + 1
mrc.MoveNext
Loop
mrc.Close
End Sub
Private Sub msgList_Click()
'txtItem(0).Text = Str(msgList.RowPos)
Cancel = 1
End Sub
Private Sub msgList_ItemClick()
End Sub
Public Sub Cleartxt()
txtItem(0).Text = ""
txtItem(1).Text = ""
txtItem(2).Text = ""
txtItem(3).Text = ""
txtItem(0).SetFocus
End Sub
Private Sub LViewPeriod_BeforeLabelEdit(Cancel As Integer)
'Cancel = 1
End Sub
Private Sub LViewPeriod_ItemClick(ByVal Item As MSComctlLib.ListItem)
txtItem(0).Text = Left(Trim(Item.SubItems(1)), Len(Trim(Item.SubItems(1))) - 3)
txtItem(1).Text = Right(Trim(Item.SubItems(1)), 2)
txtItem(2).Text = Left(Trim(Item.SubItems(2)), Len(Trim(Item.SubItems(2))) - 3)
txtItem(3).Text = Right(Trim(Item.SubItems(2)), 2)
End Sub
Private Sub txtItem_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
If Index < 3 Then
txtItem(Index + 1).SetFocus
Else
txtItem(0).SetFocus
End If
End If
End Sub
Private Function check_data() As Boolean
Dim i As Integer
check_data = True
If Val(txtItem(0).Text) > 24 Then
MsgBox "输入的数据不能大于24", vbCritical + vbOKOnly, "错误提示: "
txtItem(0).SetFocus
check_data = False
Exit Function
Else
If Len(Trim(txtItem(0).Text)) < 2 Then
For i = Len(Trim(txtItem(0).Text)) To 1
txtItem(0).Text = "0" + Trim(txtItem(0).Text)
Next i
End If
End If
If Val(txtItem(1).Text) > 60 Then
MsgBox "输入的数据不能大于60", vbCritical + vbOKOnly, "错误提示: "
txtItem(1).SetFocus
check_data = False
Exit Function
Else
If Len(Trim(txtItem(1).Text)) < 2 Then
For i = Len(Trim(txtItem(1).Text)) To 1
txtItem(1).Text = "0" + Trim(txtItem(1).Text)
Next i
End If
End If
If Val(txtItem(2).Text) > 24 Then
MsgBox "输入的数据不能大于24", vbCritical + vbOKOnly, "错误提示: "
txtItem(2).SetFocus
check_data = False
Exit Function
Else
If Len(Trim(txtItem(2).Text)) < 2 Then
For i = Len(Trim(txtItem(2).Text)) To 1
txtItem(2).Text = "0" + Trim(txtItem(2).Text)
Next i
End If
End If
If Val(txtItem(3).Text) > 60 Then
MsgBox "输入的数据不能大于60", vbCritical + vbOKOnly, "错误提示: "
txtItem(3).SetFocus
check_data = False
Exit Function
Else
If Len(Trim(txtItem(3).Text)) < 2 Then
For i = Len(Trim(txtItem(3).Text)) To 1
txtItem(3).Text = "0" + Trim(txtItem(3).Text)
Next i
End If
End If
For i = 0 To 3
If Not IsNumeric(txtItem(i).Text) Then
MsgBox "输入的数据不正确", vbCritical + vbOKOnly, "错误提示: "
txtItem(i).SetFocus
check_data = False
Exit Function
End If
Next i
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -