📄 frmdevice.frm
字号:
VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomct2.ocx"
Begin VB.Form frmDevice
BorderStyle = 3 'Fixed Dialog
Caption = "设备管理"
ClientHeight = 3945
ClientLeft = 3285
ClientTop = 2325
ClientWidth = 6990
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3945
ScaleWidth = 6990
ShowInTaskbar = 0 'False
Begin VB.CommandButton cmdCancel
Caption = "放弃并退出[&C]"
Height = 615
Left = 5040
TabIndex = 21
Top = 3120
Width = 1695
End
Begin VB.CommandButton cmdDelete
Caption = "删除并退出[&D]"
Height = 615
Left = 2760
TabIndex = 20
Top = 3120
Width = 1815
End
Begin VB.CommandButton cmdSave
Caption = "保存并退出[&S]"
Height = 615
Left = 360
TabIndex = 19
Top = 3120
Width = 1935
End
Begin VB.Frame Frame3
Height = 2850
Left = 360
TabIndex = 0
Top = 0
Width = 6360
Begin VB.TextBox txtDeviceNo
Height = 276
Left = 1152
TabIndex = 8
Top = 252
Width = 1788
End
Begin VB.TextBox txtDeviceName
Height = 264
Left = 1152
TabIndex = 7
Top = 662
Width = 4704
End
Begin VB.ComboBox cboTypeNO
Height = 276
Left = 1152
Style = 2 'Dropdown List
TabIndex = 6
Top = 1060
Width = 1524
End
Begin VB.ComboBox cboDepartment
Height = 315
Left = 4116
Style = 2 'Dropdown List
TabIndex = 5
Top = 1116
Width = 1776
End
Begin VB.TextBox txtPrice
Height = 288
Left = 1152
TabIndex = 4
Top = 1470
Width = 1536
End
Begin VB.TextBox txtCost
Height = 264
Left = 4116
TabIndex = 3
Top = 1512
Width = 1776
End
Begin VB.TextBox txtDeviceModel
Height = 264
Left = 4116
TabIndex = 1
Top = 204
Width = 1752
End
Begin MSComCtl2.DTPicker dtPurchaseDate
Height = 276
Left = 1152
TabIndex = 2
Top = 1892
Width = 1500
_ExtentX = 2646
_ExtentY = 476
_Version = 393216
Format = 25493505
CurrentDate = 38459
End
Begin VB.Label lblStatus
Height = 195
Left = 4080
TabIndex = 9
Top = 1935
Width = 945
End
Begin VB.Label Label3
Caption = "所属部门:"
Height = 312
Left = 3240
TabIndex = 18
Top = 1128
Width = 1200
End
Begin VB.Label Label1
Caption = "设备型号:"
Height = 312
Left = 3216
TabIndex = 17
Top = 240
Width = 1200
End
Begin VB.Label Label7
Caption = "折旧价:"
Height = 312
Left = 3240
TabIndex = 16
Top = 1548
Width = 1200
End
Begin VB.Label Label9
Caption = "状态:"
Height = 312
Left = 3240
TabIndex = 15
Top = 1992
Width = 1200
End
Begin VB.Label Label5
Caption = "设备名称:"
Height = 312
Left = 252
TabIndex = 14
Top = 684
Width = 1200
End
Begin VB.Label Label4
Caption = "购买价格:"
Height = 312
Left = 252
TabIndex = 13
Top = 1512
Width = 1200
End
Begin VB.Label Label2
Caption = "所属类型:"
Height = 312
Left = 252
TabIndex = 12
Top = 1104
Width = 1200
End
Begin VB.Label lblNo
Caption = "设备编号:"
Height = 312
Left = 252
TabIndex = 11
Top = 264
Width = 1200
End
Begin VB.Label Label8
Caption = "购买日期:"
Height = 312
Left = 252
TabIndex = 10
Top = 1932
Width = 1200
End
End
End
Attribute VB_Name = "frmDevice"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private theDevice As New classDevice
Public isUpdate As Boolean
Private Sub cmdCancel_Click()
With theDevice
If .isDirty Then
If MsgBox("你已经更改数据,是否做保存数据后再退出?", vbYesNo) = vbYes Then
If saveData() = False Then
Exit Sub
End If
End If
End If
End With
Me.Hide
End Sub
Private Sub cmdDelete_Click()
theDevice.deleteData (theDevice.iid)
isUpdate = True
Me.Hide
End Sub
Private Sub cmdSave_Click()
If saveData() = True Then
isUpdate = True
Me.Hide
End If
End Sub
Private Sub Form_Load()
Dim rs As ADODB.Recordset
Dim strSQL As String
strSQL = "SELECT * FROM tblTypeInfo ORDER BY TypeNO"
Set rs = gConn.Execute(strSQL)
With rs
Do Until .EOF
cboTypeNO.AddItem .Fields("TypeNO").value & "-" & .Fields("TypeName").value
.MoveNext
Loop
End With
strSQL = "SELECT * FROM tblDepartment ORDER BY DeptNO"
Set rs = gConn.Execute(strSQL)
With rs
Do Until .EOF
cboDepartment.AddItem .Fields("DeptNO").value & "-" & .Fields("Department").value
.MoveNext
Loop
End With
rs.Close
Set rs = Nothing
isUpdate = False
End Sub
Public Sub loadDevice(iid As String)
'显示用户数据
With theDevice
.loadDataByID iid
txtDeviceNo.Text = .DeviceNo
txtDeviceModel.Text = .DeviceModel
txtDeviceName.Text = .DeviceName
setTypeIndex .TypeNo
setDeptIndex .DeptNo
txtPrice.Text = .ProductPrice
txtCost.Text = .ProductCost
dtPurchaseDate = .PurchaseDate
If .Status = 0 Then
lblStatus.Caption = "在库"
Else
lblStatus.Caption = "借出"
End If
If Len(.RejectDate) = 0 Then
dtReject.Visible = False
Else
dtReject.value = .RejectDate
End If
If Len(.DisCardDate) = 0 Then
dtDisCard.Visible = False
Else
dtDisCard.value = .DisCardDate
End If
End With
End Sub
Private Sub setTypeIndex(TypeNo As String)
Dim pos As Integer
TypeNo = TypeNo & "-"
With cboTypeNO
For pos = 0 To .ListCount - 1
If Left(.List(pos), Len(TypeNo)) = TypeNo Then
.ListIndex = pos
Exit For
End If
Next
End With
End Sub
Private Sub setDeptIndex(DeptNo As String)
Dim pos As Integer
DeptNo = DeptNo & "-"
With cboDepartment
For pos = 0 To .ListCount - 1
If Left(.List(pos), Len(DeptNo)) = DeptNo Then
.ListIndex = pos
Exit For
End If
Next
End With
End Sub
Private Function getTypeNO() As String
Dim str As String
Dim pos As Integer
With cboTypeNO
str = .List(.ListIndex)
End With
pos = InStr(str, "-")
getTypeNO = Left(str, pos - 1)
End Function
Private Function getDeptNo() As String
Dim str As String
Dim pos As Integer
With cboDepartment
str = .List(.ListIndex)
End With
pos = InStr(str, "-")
getDeptNo = Left(str, pos - 1)
End Function
Public Sub setStatus()
If theDevice.iid = 0 Then
cmdDelete.Enabled = False
' dtReject.Visible = False
'dtDisCard.Visible = False
End If
End Sub
Private Function saveData() As Boolean
Dim DeviceNo As String
Dim DeviceModel As String
Dim DeviceName As String
Dim TypeNo As String
Dim DeptNo As String
Dim Price As String
Dim Cost As String
Dim PurchaseDate As String
saveData = False
DeviceNo = Trim(txtDeviceNo.Text)
DeviceModel = Trim(txtDeviceModel.Text)
DeviceName = Trim(txtDeviceName.Text)
Price = Trim(txtPrice.Text)
Cost = Trim(txtCost.Text)
PurchaseDate = FormatDateTime(dtPurchaseDate.value, vbShortDate)
If Len(DeviceNo) = 0 Then
MsgBox "请输入设备编号"
Exit Function
End If
If cboTypeNO.ListIndex < 0 Then
MsgBox "请选择设备类型!"
Exit Function
End If
If cboDepartment.ListIndex < 0 Then
MsgBox "请选择设备所属部门!"
Exit Function
End If
If IsNumeric(Price) = False Then
MsgBox "请输入正确的价格!"
Exit Function
End If
If IsNumeric(Cost) = False Then
MsgBox "请输入正确的折旧价!"
Exit Function
End If
If IsDate(PurchaseDate) = False Then
MsgBox "请输入正确的购买日期!"
Exit Function
End If
With theDevice
.DeviceNo = DeviceNo
.DeviceModel = DeviceModel
.DeviceName = DeviceName
.TypeNo = getTypeNO()
.DeptNo = getDeptNo()
.ProductPrice = Price
.ProductCost = Cost
.PurchaseDate = PurchaseDate
If .iid = 0 Then
saveData = .addData
Else
saveData = .saveData
End If
If saveData = False Then MsgBox "保存不成功!请检查设备编号的唯一性!"
End With
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -