📄 frmsplog.frm
字号:
Call CmdClear_Click
End If
n = n - 1
Else
txtID.Text = "g" & Val(Right(Trim(rct.Fields.Item(0).Value), 4)) + 1 '表格为空时,厂商编号返回到最小可用编号
MsgBox "无记录!", vbInformation + vbOKOnly, "删除提示!"
End If
End Sub
Private Sub CmdExit_Click()
Unload Me
End Sub
Private Sub CmdInput_Click()
Dim intindex As Integer
Dim temp As String
'判断个文本框的输入是否为空
If txtName = "" Then
MsgBox "厂商名称输入不能为空,请重输!", vbInformation + vbOKOnly, "输入提示!"
txtName.Text = ""
txtName.SetFocus
Exit Sub
End If
If txtAddress.Text = "" Then
MsgBox "地址输入不能为空,请重输!", vbInformation + vbOKOnly, "输入提示!"
txtAddress.Text = ""
txtAddress.SetFocus
Exit Sub
End If
If txtCity.Text = "" Then
MsgBox "城市输入不能为空,请重输!", vbInformation + vbOKOnly, "输入提示!"
txtName.Text = ""
txtName.SetFocus
Exit Sub
End If
If TxtState.Text = "" Then
MsgBox "省份输入能为空,请重新输入!", vbInformation + vbOKOnly, "输入提示!"
TxtState.Text = ""
TxtState.SetFocus
Exit Sub
End If
If TxtPhone.Text = "" Then
MsgBox "电话号码输入能为空,请重新输入!", vbInformation + vbOKOnly, "输入提示!"
TxtPhone.Text = ""
TxtPhone.SetFocus
Exit Sub
End If
If TxtBA.Text = "" Then
MsgBox "银行帐号输入能为空,请重新输入!", vbInformation + vbOKOnly, "输入提示!"
TxtBA.Text = ""
TxtBA.SetFocus
Exit Sub
End If
rct.MoveFirst
If txtName.Text <> "" Then
Do While Not rct.EOF
'不能输入数据库中已有的厂商名称
If txtID.Text = Trim(rct.Fields.Item(0).Value) Or txtName.Text = rct.Fields.Item(1).Value Then
MsgBox "厂商记录已存在,无法添加!", vbInformation + vbOKOnly, "输入提示!"
txtName.Text = ""
txtAddress.Text = ""
txtCity.Text = ""
TxtState.Text = ""
TxtPhone.Text = ""
TxtBA.Text = ""
txtName.SetFocus
Exit Sub
Else
rct.MoveNext
End If
Loop
If MSFlexGrid1.Rows > 2 Then
'表格中不允许输入重复的厂商编号和名称
For intindex = 1 To MSFlexGrid1.Rows - 2
If txtID.Text = MSFlexGrid1.TextMatrix(intindex, 1) Or txtName.Text = MSFlexGrid1.TextMatrix(intindex, 2) Then
MsgBox "输入记录有重复,请重输!", vbInformation + vbOKOnly, "输入提示!"
txtName.Text = ""
txtAddress.Text = ""
txtCity.Text = ""
TxtState.Text = ""
TxtPhone.Text = ""
TxtBA.Text = ""
txtName.SetFocus
Exit Sub
End If
Next intindex
End If
n = n + 1
MSFlexGrid1.Row = MSFlexGrid1.Rows - 1
For intindex = 0 To 7
MSFlexGrid1.Col = intindex
MSFlexGrid1.CellAlignment = 4
Next intindex
MSFlexGrid1.Col = 0
MSFlexGrid1.Text = n
MSFlexGrid1.Col = 1
MSFlexGrid1.Text = txtID.Text
MSFlexGrid1.Col = 2
MSFlexGrid1.Text = txtName.Text
MSFlexGrid1.Col = 3
MSFlexGrid1.Text = txtAddress.Text
MSFlexGrid1.Col = 4
MSFlexGrid1.Text = txtCity.Text
MSFlexGrid1.Col = 5
MSFlexGrid1.Text = TxtState.Text
MSFlexGrid1.Col = 6
MSFlexGrid1.Text = TxtPhone.Text
MSFlexGrid1.Col = 7
MSFlexGrid1.Text = TxtBA.Text
MSFlexGrid1.AddItem (Empty)
CmdClear.Enabled = True
CmdSave.Enabled = True
temp = txtID.Text
txtID.Text = "g" & Val(Right((temp), 4)) + 1 '输入完毕后,厂商编号加1,以便进行下次输入
txtName.Text = ""
txtAddress.Text = ""
txtCity.Text = ""
TxtState.Text = ""
TxtPhone.Text = ""
TxtBA.Text = ""
txtName.SetFocus
Else
MsgBox "厂商名称不能为空!", vbInformation + vbOKOnly, "输入提示!"
txtName.Text = ""
txtAddress.Text = ""
txtCity.Text = ""
TxtState.Text = ""
TxtPhone.Text = ""
TxtBA.Text = ""
txtName.SetFocus
End If
End Sub
Private Sub CmdSave_Click()
On Error GoTo error
Dim intindex As Integer
If MSFlexGrid1.TextMatrix(1, 0) <> "" Then
For intindex = 1 To MSFlexGrid1.Rows - 2
rct.AddNew
rct.Fields.Item(0).Value = MSFlexGrid1.TextMatrix(intindex, 1)
rct.Fields.Item(1).Value = MSFlexGrid1.TextMatrix(intindex, 2)
rct.Fields.Item(2).Value = MSFlexGrid1.TextMatrix(intindex, 3)
rct.Fields.Item(3).Value = MSFlexGrid1.TextMatrix(intindex, 4)
rct.Fields.Item(4).Value = MSFlexGrid1.TextMatrix(intindex, 5)
rct.Fields.Item(5).Value = MSFlexGrid1.TextMatrix(intindex, 6)
rct.Fields.Item(6).Value = MSFlexGrid1.TextMatrix(intindex, 7)
rct.UpdateBatch
MsgBox "成功保存到数据库!", vbInformation + vbOKOnly, "保存成功!"
Next intindex
Else
MsgBox "无记录可保存!", vbInformation + vbOKOnly, "错误提示!"
End If
Call CmdClear_Click
CmdSave.Enabled = False
Exit Sub
error:
MsgBox "错误代码:" & Err.Number & vbCrLf & _
"错误描述:" & Err.Description, vbCritical + vbOKOnly, "错误!"
End Sub
Private Sub Form_Load()
Call flexView
Dim str As String
str = "select * from suppliers "
Set rct = QueryXFInfo(str)
n = 0
rct.MoveFirst
If rct.Fields.Item(0).Value = "" Then '如果厂商表没有记录,则厂商编号以“g0001”开始,否则从最小可用编号开始,依次加一。
txtID.Text = "g1001"
Else
rct.MoveLast
txtID.Text = "g" & Val(Right(Trim(rct.Fields.Item(0).Value), 4)) + 1
End If
CmdSave.Enabled = False
CmdClear.Enabled = False
End Sub
'判断各文本框输入的合法性
Private Sub TxtAddress_LostFocus()
If txtAddress.Text <> "" Then
If IsChar(txtAddress.Text) = False Then
MsgBox "厂商名称输入不合法,请重新输入!", vbInformation + vbOKOnly, "输入提示!"
txtAddress.Text = ""
txtAddress.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub TxtBA_LostFocus()
If TxtBA.Text <> "" Then
If IsNumber(TxtBA.Text) = False Then
MsgBox "银行帐号输入不合法,请重新输入!", vbInformation + vbOKOnly, "输入提示!"
TxtBA.Text = ""
TxtBA.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub txtID_LostFocus()
If txtID.Text <> "" Then
If IsChar(txtID) = False Then
MsgBox "厂商编号输入不合法,请重新输入!", vbInformation + vbOKOnly, "输入提示!"
txtID.Text = ""
txtName.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub TxtName_LostFocus()
If txtName.Text <> "" Then
If IsChar(txtName.Text) = False Then
MsgBox "厂商名称输入不合法,请重新输入!", vbInformation + vbOKOnly, "输入提示!"
txtName.Text = ""
txtName.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub TxtCity_LostFocus()
If txtCity.Text <> "" Then
If IsChar(txtCity.Text) = False Then
MsgBox "城市输入不合法,请重新输入!", vbInformation + vbOKOnly, "输入提示!"
txtCity.Text = ""
txtCity.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub TxtState_LostFocus()
If TxtState.Text <> "" Then
If IsChar(TxtState.Text) = False Then
MsgBox "省份输入不合法,请重新输入!", vbInformation + vbOKOnly, "输入提示!"
TxtState.Text = ""
TxtState.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub TxtPhone_LostFocus()
Dim str As String
str = TxtPhone.Text
Dim i As Integer
Dim intindex As Integer
intindex = 0
Dim length As Integer
length = Len(str)
For i = 1 To length
If Left(str, 1) >= "0" And Left(str, 1) <= "9" Or Left(str, 1) = "-" Then
If Left(str, 1) = "-" Then
intindex = intindex + 1
End If
Else
MsgBox "电话号码输入不合法,请重新输入", vbInformation + vbOKOnly, "输入提示!"
TxtPhone.Text = ""
TxtPhone.SetFocus
Exit Sub
End If
str = Right(str, Len(str) - 1) '此处的str动态变化!!
Next i
If intindex > 1 Then
MsgBox "电话号码输入不合法,请重新输入", vbInformation + vbOKOnly, "输入提示!"
TxtPhone.Text = ""
TxtPhone.SetFocus
Exit Sub
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -