📄 frmreturndisk.frm
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "Msflxgrd.ocx"
Begin VB.Form frmReturnDisk
Caption = "影碟归还"
ClientHeight = 4575
ClientLeft = 60
ClientTop = 345
ClientWidth = 6150
LinkTopic = "Form1"
ScaleHeight = 4575
ScaleWidth = 6150
StartUpPosition = 3 'Windows Default
Begin VB.Frame Frame1
Caption = "输入会员号"
Height = 1095
Left = 120
TabIndex = 5
Top = 120
Width = 5895
Begin VB.CommandButton cmdOk
Caption = "确认(&Y)"
Height = 375
Left = 3240
TabIndex = 8
Top = 480
Width = 1095
End
Begin VB.TextBox txtMemberNo
Height = 405
Left = 1200
TabIndex = 7
Top = 450
Width = 1695
End
Begin VB.CommandButton Command1
Caption = "返回(&C)"
Height = 375
Left = 4560
TabIndex = 6
Top = 480
Width = 1095
End
Begin VB.Label Label1
Caption = "会员编号:"
Height = 255
Left = 240
TabIndex = 9
Top = 480
Width = 1095
End
End
Begin VB.Frame Frame2
Caption = "选择影碟"
Height = 975
Left = 120
TabIndex = 1
Top = 1320
Width = 5895
Begin VB.CommandButton Command2
Caption = "结帐(&P)"
Height = 375
Left = 4560
TabIndex = 13
Top = 360
Width = 1095
End
Begin VB.TextBox txtDiskNo
Height = 405
Left = 1200
TabIndex = 3
Top = 360
Width = 1695
End
Begin VB.CommandButton cmdReturn
Caption = "归还(&R)"
Height = 375
Left = 3240
TabIndex = 2
Top = 360
Width = 1095
End
Begin VB.Label Label4
Caption = "影碟编号:"
Height = 375
Left = 240
TabIndex = 4
Top = 360
Width = 1095
End
End
Begin MSFlexGridLib.MSFlexGrid fgRent
Height = 1695
Left = 120
TabIndex = 0
Top = 2760
Width = 5895
_ExtentX = 10398
_ExtentY = 2990
_Version = 393216
End
Begin VB.Label Label2
Caption = "已还影碟:"
Height = 255
Left = 120
TabIndex = 12
Top = 2400
Width = 975
End
Begin VB.Label Label3
Caption = "张"
Height = 255
Left = 1320
TabIndex = 11
Top = 2400
Width = 255
End
Begin VB.Label lblTotal
Caption = "0"
ForeColor = &H000000FF&
Height = 255
Left = 1080
TabIndex = 10
Top = 2400
Width = 135
End
End
Attribute VB_Name = "frmReturnDisk"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public sqlStr As String
Public msgText As String
Public userNo As String
Public total As Double
Private Sub cmdOk_Click()
If verifyUser(txtMemberNo.Text) = True Then
cmdOk.Enabled = False
txtMemberNo.Enabled = False
userNo = txtMemberNo.Text
cmdReturn.Enabled = True
End If
End Sub
Private Sub cmdReturn_Click()
returnDisk
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Command2_Click()
MsgBox "一共归还" & lblTotal.Caption & "张碟,租金共计" & total & "元。"
Unload Me
End Sub
Private Sub Form_Load()
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
initTable
cmdReturn.Enabled = False
total = 0
End Sub
Sub initTable()
Dim i As Integer
fgRent.Rows = 1
fgRent.Cols = 6
'设定行高
For i = 0 To fgRent.Rows - 1
fgRent.RowHeight(i) = 280
Next i
'设定列的属性
fgRent.Row = 0
For i = 0 To fgRent.Cols - 1
fgRent.Col = i '指定当前列为第i列
fgRent.FixedAlignment(i) = 4 '每列内容居中显示
Select Case i
Case 0
fgRent.ColWidth(i) = 600 '设定列宽
fgRent.Text = "序号"
Case 1
fgRent.ColWidth(i) = 1200 '设定列宽
fgRent.Text = "影碟编号"
Case 2
fgRent.ColWidth(i) = 2200 '设定列宽
fgRent.Text = "影碟名称"
Case 3
fgRent.ColWidth(i) = 1000 '设定列宽
fgRent.Text = "会员编号"
Case 4
fgRent.ColWidth(i) = 800 '设定列宽
fgRent.Text = "数量"
Case 5
fgRent.ColWidth(i) = 600 '设定列宽
fgRent.Text = "租金"
End Select
Next i
End Sub
Sub returnDisk()
Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim sqlstr2 As String
Dim i As Integer
Dim j As Integer
'定义变量来计算借出的天数和费用
Dim dateLend As Date
Dim dateReturn As Date
Dim days As Integer
Dim rentPay As Double
Dim totalPay As Double
sqlstr2 = "select * from lendInfo where diskNo=" & txtDiskNo.Text _
& " AND memberNo=" & txtMemberNo.Text & " AND hasReturned='否'"
Set rs2 = ExecuteSQL(sqlstr2, msgText)
If rs2.RecordCount = 0 Then
MsgBox "租借信息中没有查找满足条件的数据!", vbExclamation, "提示"
Exit Sub
Else
If txtDiskNo.Text = "" Then
MsgBox "请填写影碟编号!", vbExclamation, "提示"
Exit Sub
End If
sqlStr = "select * from disks where [no]=" & txtDiskNo.Text
Set rs = ExecuteSQL(sqlStr, msgText)
If rs.RecordCount = 0 Then
MsgBox "没有查找满足条件的数据!", vbExclamation, "提示"
Exit Sub
Else
lblTotal.Caption = Val(lblTotal.Caption) + 1
fgRent.Rows = fgRent.Rows + 1
fgRent.RowHeight(fgRent.Rows - 1) = 280
'设定列的属性
fgRent.Row = fgRent.Rows - 1
For j = 0 To fgRent.Cols - 2
fgRent.Col = j '设置当前为列为第j列
fgRent.CellAlignment = 4 '每列内容居中显示
Select Case j
Case 0
fgRent.Text = fgRent.Rows - 1
Case 1
fgRent.Text = rs.Fields("no")
Case 2
fgRent.Text = rs.Fields("diskName")
Case 3
fgRent.Text = txtMemberNo.Text
Case 4
fgRent.Text = "1"
End Select
Next j
End If
rs.Fields("stock") = rs.Fields("stock") + 1
'获取该影碟的每日租金
rentPay = Val(rs.Fields("payForRent"))
rs.Update
rs.Close
'计算借出的天数
dateLend = CDate(rs2.Fields("lendDate"))
dateReturn = Date
days = DateDiff("d", dateLend, dateReturn)
If days = 0 Then
days = 1
End If
'计算该碟的总租金
totalPay = rentPay * days
'修改租借信息表中相关字段的值
rs2.Fields("totalPay") = totalPay
rs2.Fields("returnDate") = Format(Date, "yyyy-mm-dd")
rs2.Fields("hasReturned") = "是"
rs2.Update
rs2.Close
fgRent.Col = fgRent.Cols - 1
fgRent.Text = totalPay
'计算并在变量中保存总租金
total = total + totalPay
End If
txtDiskNo.Text = ""
End Sub
Function verifyUser(userNo As String) As Boolean
Dim rs As ADODB.Recordset
Dim i As Integer
Dim j As Integer
sqlStr = "select * from members where [no]=" & userNo
Set rs = ExecuteSQL(sqlStr, msgText)
If rs.RecordCount = 0 Then
MsgBox "该会员不存在!", vbExclamation, "提示"
verifyUser = False
Else
verifyUser = True
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -