📄 frmhwbm.frm
字号:
VERSION 5.00
Begin VB.Form frmHwbm
Caption = "货物资料维护"
ClientHeight = 2355
ClientLeft = 4245
ClientTop = 3150
ClientWidth = 6030
LinkTopic = "Form2"
LockControls = -1 'True
ScaleHeight = 2355
ScaleWidth = 6030
Begin VB.CommandButton Command
Caption = "保存(&S)"
Height = 345
Index = 2
Left = 4830
TabIndex = 9
Top = 540
Width = 1125
End
Begin VB.Frame Frame
Height = 2145
Left = 30
TabIndex = 2
Top = 90
Width = 4695
Begin VB.TextBox Text
Height = 330
Index = 2
Left = 1110
TabIndex = 10
Top = 1620
Width = 2025
End
Begin VB.TextBox Text
Height = 330
Index = 0
Left = 1110
TabIndex = 5
Top = 720
Width = 2025
End
Begin VB.TextBox Text
Height = 330
Index = 1
Left = 1110
TabIndex = 4
Top = 1170
Width = 3315
End
Begin VB.ComboBox Combo
Height = 300
Index = 0
Left = 1110
Style = 2 'Dropdown List
TabIndex = 3
Top = 300
Width = 2025
End
Begin VB.Label Label
Caption = "货物单价:"
Height = 195
Index = 3
Left = 210
TabIndex = 11
Top = 1680
Width = 825
End
Begin VB.Label Label
Caption = "货物编码:"
Height = 195
Index = 0
Left = 180
TabIndex = 8
Top = 780
Width = 825
End
Begin VB.Label Label
Caption = "货物名称:"
Height = 195
Index = 1
Left = 180
TabIndex = 7
Top = 1230
Width = 825
End
Begin VB.Label Label
Caption = "货物分类:"
Height = 195
Index = 2
Left = 180
TabIndex = 6
Top = 330
Width = 825
End
End
Begin VB.CommandButton Command
Caption = "新增(&A)"
Height = 345
Index = 0
Left = 4830
TabIndex = 1
Top = 120
Width = 1125
End
Begin VB.CommandButton Command
Caption = "退出(&X)"
Height = 345
Index = 1
Left = 4830
TabIndex = 0
Top = 960
Width = 1125
End
End
Attribute VB_Name = "frmHwbm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Conn As ADODB.Connection
Dim AddChgFlg As Integer '0表示新增,1-表示修改
Dim OldHwbmCode As String
Const CbxHwBmFlCode = 0
Const TxtHwBmCode = 0
Const TxtHwBmMc = 1
Const TxtHwBmPrice = 2
Const CmdAdd = 0
Const CmdSave = 2
Const CmdExit = 1
Public Sub LetHwbm(vHwbmFlCode As String, vHwbmCode As String, vHwBmMc As String, vHwbmPrice As Double)
Dim I As Integer
On Error GoTo Errorhandle
AddChgFlg = 1
For I = 1 To Combo(CbxHwBmFlCode).ListCount
If vHwbmFlCode = Trim(Left(Combo(CbxHwBmFlCode).List(I), InStr(1, Combo(CbxHwBmFlCode).List(I), vbTab) - 1)) Then
Combo(CbxHwBmFlCode).ListIndex = I
Exit For
End If
Next
OldHwbmCode = vHwbmCode
Text(TxtHwBmCode).Text = vHwbmCode
Text(TxtHwBmMc).Text = vHwBmMc
Text(TxtHwBmPrice).Text = vHwbmPrice
Exit Sub
Errorhandle:
Err.Raise vbObjectError + 1, , Err.Description
End Sub
Private Sub Command_Click(Index As Integer)
On Error GoTo Errorhandle
Select Case Index
Case CmdAdd
AddRecord
Case CmdSave
SaveRecord
Case CmdExit
Unload Me
End Select
Exit Sub
Errorhandle:
MsgBox Err.Description
End Sub
Private Sub AddRecord()
On Error GoTo Errorhandle
AddChgFlg = 0
Combo(CbxHwBmFlCode).ListIndex = 0
Text(TxtHwBmCode).Text = ""
Text(TxtHwBmMc).Text = ""
Text(TxtHwBmPrice).Text = ""
Exit Sub
Errorhandle:
Err.Raise vbObjectError + 1, , Err.Description
End Sub
Private Sub SaveRecord()
Dim SqlStr As String
On Error GoTo Errorhandle
Conn.BeginTrans
Select Case AddChgFlg
Case 0
Conn.Execute "INSERT HWBMREC(HWBMFLCODE,HWBMCODE,HWBMMC,HWBMPRICE,HWBMDAT) VALUES('" & Trim(Left(Combo(CbxHwBmFlCode).Text, InStr(1, Combo(CbxHwBmFlCode).Text, vbTab) - 1)) & "','" & Trim(Text(TxtHwBmCode).Text) & "','" & Trim(Text(TxtHwBmMc).Text) & "'," & CStr(Val(Text(TxtHwBmPrice).Text)) & ",GETDATE())"
Case 1
SqlStr = "UPDATE HWBMREC SET HWBMFLCODE='" & Trim(Left(Combo(CbxHwBmFlCode).Text, InStr(1, Combo(CbxHwBmFlCode).Text, vbTab) - 1)) & "',"
SqlStr = SqlStr & "HWBMCODE='" & Trim(Text(TxtHwBmCode).Text) & "',HWBMMC='" & Trim(Text(TxtHwBmMc).Text) & "',"
SqlStr = SqlStr & "HWBMPRICE=" & CStr(Val(Text(TxtHwBmPrice).Text)) & ",HWBMDAT=GETDATE() "
SqlStr = SqlStr & " WHERE HWBMCODE='" & OldHwbmCode & "'"
Conn.Execute SqlStr
End Select
Conn.CommitTrans
OldHwbmCode = Trim(Text(TxtHwBmCode).Text)
Exit Sub
Errorhandle:
Conn.RollbackTrans
Err.Raise vbObjectError + 1, , Err.Description
End Sub
Private Sub Form_Load()
On Error GoTo Errorhandle
Connection
LoadHwFl
Exit Sub
Errorhandle:
MsgBox Err.Description
End Sub
Private Sub Connection()
Dim ConnStr As String
On Error GoTo Errorhandle
ConnStr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=fiterp;Data Source=ERP002"
Set Conn = New ADODB.Connection
Conn.ConnectionString = ConnStr
Conn.Open
Conn.CursorLocation = adUseClient
Exit Sub
Errorhandle:
Set Conn = Nothing
Err.Raise vbObjectError + 1, , Err.Description
End Sub
Private Sub LoadHwFl()
Dim Rs As ADODB.Recordset
On Error GoTo Errorhandle
Combo(CbxHwBmFlCode).Clear
Combo(CbxHwBmFlCode).AddItem ""
Set Rs = New ADODB.Recordset
Set Rs.ActiveConnection = Conn
Rs.Open "SELECT HWFLCODE,HWFLMC FROM HWFLREC ORDER BY HWFLCODE"
Do While Not Rs.EOF
Combo(CbxHwBmFlCode).AddItem Rs("HWFLCODE") & vbTab & Rs("HWFLMC")
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Exit Sub
Errorhandle:
Set Rs = Nothing
Err.Raise vbObjectError + 1, , Err.Description
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Errorhandle
Conn.Close
Set Conn = Nothing
Exit Sub
Errorhandle:
MsgBox Err.Description
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -