📄 frmcustomertypecard.frm
字号:
Dim edtErrReturn As ErrDealType
On Error GoTo ErrHandle
' SetHelpID hwnd, 30006
Utility.LoadFormResPicture Me
' SendKeys "%{C}"
' frmCustomerList.IsShowCard(1) = True
Exit Sub
ErrHandle:
edtErrReturn = Errors.ErrorsDeal
If edtErrReturn = edtResume Then
Resume
Else
On Error Resume Next
Unload Me
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim intMsgReturn As Integer, strMess As String
If UnloadMode <> vbFormControlMenu Then Exit Sub
If Trim(txtInput(0).Text & txtInput(1).Text) = "" Then Exit Sub
If mblnIsChanged Then
If mblnIsNew Then
strMess = "您要保存新增的单位类型"
If txtInput(0).Text <> "" Then
strMess = strMess & "“" & txtInput(0).Text & "”"
End If
If txtInput(1).Text <> "" Then
strMess = strMess & "“" & txtInput(1).Text & "”"
End If
strMess = strMess & "吗?"
Else
strMess = "“" & txtInput(0).Text & "”" & " " _
& "“" & txtInput(1).Text & "”单位类型已被修改,是否保存?"
End If
intMsgReturn = ShowMsg(hwnd, strMess, vbQuestion + vbYesNoCancel, Caption)
If intMsgReturn = vbYes Then
Cancel = Not SaveCard
ElseIf intMsgReturn = vbCancel Then
Cancel = True
End If
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
' frmCustomerList.IsShowCard(1) = False
Utility.UnLoadFormResPicture Me
mblnIsChanged = False
End Sub
Private Sub Form_Paint()
FrameBox Me.hwnd, 180, 170, 4385, 2150
End Sub
Private Sub cmdokcancel_Click(Index As Integer)
Dim strNextCode As String
Select Case Index
Case 0 '确定
If SaveCard Then Unload Me
Case 1 '取消
Unload Me
Case 2 '下一个
If SaveCard Then
strNextCode = GetNextCode(txtInput(0).Text)
' mlngCustomerTypeID = 0
InitCard
txtInput(0).Text = strNextCode
txtInput(0).SetFocus
txtInput(0).SelStart = 0
txtInput(0).SelLength = Len(txtInput(0).Text)
End If
End Select
End Sub
Private Function MergeCode() As Boolean
MergeCode = DisplaceActivity("Customer", "lngCustomerTypeID", mlngPCodeID, mlngCustomerTypeID)
End Function
Private Function SaveCard(Optional ByVal blnByAdd As Boolean = False) As Boolean
Dim blnMerge As Boolean 'NEW--转移业务 EDIT--合并代码
Dim intResult As Integer '编码检查结果:1--合法 -1--上级编码不存在 -2--编码已存在 -3--编码超长
Dim recCustomerType As rdoResultset, strSql As String
Dim intIsDetail As Integer, intIsInActive As Integer
On Error GoTo ErrHandle
SaveCard = False
gclsBase.BaseWorkSpace.BeginTrans
If Trim$(txtInput(0).Text) = "" Then
ShowMsg hwnd, "单位类型编码不能为空!", vbExclamation, Caption
txtInput(0).SetFocus
GoTo ErrHandle
End If
If InStr(1, txtInput(0).Text, mstrOldCode & "-") <> 0 And Not mblnIsNew Then
ShowMsg hwnd, "单位类型不能修改为自己的下级单位类型!", vbExclamation, Caption
txtInput(0).SetFocus
GoTo ErrHandle
End If
If InStr(1, mstrOldCode, txtInput(0).Text & "-") <> 0 And Not mblnIsNew Then
ShowMsg hwnd, "单位类型不能修改为自己的上级单位类型!", vbExclamation, Caption
txtInput(0).SetFocus
GoTo ErrHandle
End If
If Trim$(txtInput(1).Text) = "" Then
ShowMsg hwnd, "单位类型名称不能为空!", vbExclamation, Caption
txtInput(1).SetFocus
GoTo ErrHandle
End If
intResult = CodeCheck("CustomerType", "strCustomerTypeCode", "lngCustomerTypeID", _
mblnIsNew, txtInput(0).Text, txtInput(1).Text, mstrOldCode, _
mstrOldFullName, mstrFullName, mlngPCodeID, mblnPIsDetail, mblnPIsInActive, _
mblnIsDetail)
If intResult = -1 Then
If mblnIsNew Then
If Not blnByAdd Then
ShowMsg hwnd, "“" & Trim$(txtInput(0).Text) & "“的上级单位类型" _
& "不存在,请先增加上级单位类型”" & CodePrefix(txtInput(0).Text) & "“", _
vbExclamation, Caption
End If
Else
ShowMsg hwnd, "“" & Trim$(txtInput(0).Text) & "“的上级单位类型" _
& "不存在,请重新修改单位类型”" _
& Trim$(txtInput(0).Text) & "“", vbExclamation, Caption
End If
txtInput(0).SetFocus
GoTo ErrHandle
ElseIf intResult = -2 Then
If mblnIsNew Then
If Not blnByAdd Then
ShowMsg hwnd, "单位类型编码“" & Trim$(txtInput(0).Text) _
& "”已经存在,请重新录入单位类型编码", vbExclamation, Caption
txtInput(0).SetFocus
End If
GoTo ErrHandle
Else
If Not mblnPIsDetail Or (mblnIsInActive <> mblnPIsInActive) Or Not mblnIsDetail Then
ShowMsg hwnd, "单位类型“" & mstrOldCode & "”与单位类型“" _
& Trim$(txtInput(0).Text) & "”不能合并,请重新修改单位类型编码“" _
& Trim$(txtInput(0).Text) & "“", vbExclamation, Caption
mlngPCodeID = 0
txtInput(0).SetFocus
GoTo ErrHandle
Else
If ShowMsg(hwnd, "是否将单位类型“" & mstrOldCode & "”与“" _
& Trim$(txtInput(0).Text) & "”进行合并?", vbQuestion + _
vbYesNo, Caption) = vbNo Then
txtInput(0).SetFocus
GoTo ErrHandle
Else
blnMerge = True
End If
End If
End If
ElseIf intResult = -3 Then
If Not blnByAdd Then
ShowMsg hwnd, "单位类型编码太长,请重新修改编码!", vbExclamation, Caption
txtInput(0).SetFocus
End If
GoTo ErrHandle
Else
If mblnIsNew And mblnPIsDetail Then
If CodeUsed(mlngPCodeID) Then
If Not blnByAdd Then
If ShowMsg(hwnd, "单位类型“" & CodePrefix(txtInput(0).Text) & "”是一个已经发生业务的末级单位类型," _
& "是否在该单位类型下新增明细单位类型“" & Trim$(txtInput(0).Text) & "”," _
& "并将发生的所有业务转到新增的明细单位类型?", vbQuestion + vbYesNo, _
Caption) = vbNo Then
txtInput(0).SetFocus
GoTo ErrHandle
Else
blnMerge = True
End If
Else
blnMerge = True
End If
End If
End If
End If
' If CheckSameName("CustomerType", "strCustomerTypeCode", txtInput(0).Text, _
' "strCustomerTypeName", txtInput(1).Text, "lngCustomerTypeID", _
' IIf(mblnIsNew, 0, mlngCustomerTypeID)) Then
' If Not blnByAdd Then
' ShowMsg hWnd, "已有同级单位类型使用了" & "“" & txtInput(1).Text & "“" & _
' ",请重新录入单位类型名称!", vbExclamation, Caption
' txtInput(1).SetFocus
' End If
' recCustomerType.Close
' GoTo ErrHandle
' End If
mstrCode = Trim(txtInput(0).Text)
mstrName = Trim(txtInput(1).Text)
mblnIsInActive = (chkPause.Value = vbChecked)
mblnIsDetail = True
mstrStartDate = Format(gclsBase.BaseDate, "YYYY-MM-DD")
mintLevel = stringCount(Trim(txtInput(0).Text), "-") + 1
If mblnIsNew Then
If mblnPIsDetail Then
If blnMerge Then '上级编码是已使用的末级编码,合并业务
If Not TransActivity(mlngPCodeID) Then GoTo ErrHandle
Else
strSql = "UPDATE CustomerType SET blnIsDetail=0 WHERE " _
& "lngCustomerTypeID=" & mlngPCodeID
If Not gclsBase.ExecSQL(strSql) Then GoTo ErrHandle
End If
End If
If Not mblnIsInActive And mblnPIsInActive And mlngPCodeID <> 0 Then
If Not blnByAdd Then
If ShowMsg(hwnd, "上级单位类型已经被停用,是否启用上级单位类型?", _
vbQuestion + vbYesNo, Caption) = vbNo Then
mblnIsInActive = True
strSql = "UPDATE CustomerType SET blnIsInActive=True WHERE " _
& "lngCustomerTypeID=" & mlngPCodeID
If Not gclsBase.ExecSQL(strSql) Then GoTo ErrHandle
Else
mblnIsInActive = False
End If
Else
mblnIsInActive = False
End If
End If
intIsDetail = IIf(mblnIsDetail, 1, 0)
intIsInActive = IIf(mblnIsInActive, 1, 0)
mlngCustomerTypeID = GetNewID("CustomerType")
strSql = "INSERT INTO CustomerType(lngCustomerTypeID,strCustomerTypeCode,strCustomerTypeName," _
& "strFullName,blnIsInActive,intLevel,blnIsDetail," _
& "strStartDate) VALUES(" & mlngCustomerTypeID & ",'" & mstrCode & "','" & mstrName _
& "','" & mstrFullName & "'," & intIsInActive & "," _
& mintLevel & "," & intIsDetail & ",'" & mstrStartDate & "')" '插入数据库
gclsBase.BaseDB.Execute strSql
If blnMerge Then mlngCustomerTypeID = mlngPCodeID
' If Not mblnIsInActive Then
' strSql = "SELECT * FROM CustomerType WHERE strCustomerTypeCode='" & Trim(txtInput(0).Text) & "'"
' Set recCustomerType = gclsBase.BaseDB.OpenResultset(strSql, rdOpenStatic)
' mlngCustomerTypeID = recCustomerType!lngCustomerTypeID
' recCustomerType.Close
' End If
Else
'进行编码合并
If blnMerge Then
If Not MergeCode Then GoTo ErrHandle
strSql = "DELETE FROM CustomerType WHERE lngCustomerTypeID=" & mlngCustomerTypeID
If Not gclsBase.ExecSQL(strSql) Then GoTo ErrHandle
Else
intIsInActive = IIf(mblnIsInActive, 1, 0)
strSql = "UPDATE CustomerType SET strCustomerTypeCode='" & mstrCode _
& "',strCustomerTypeName='" & mstrName & "',strFullName='" & mstrFullName _
& "',blnIsInActive=" & intIsInActive & ",intLevel =" & mintLevel _
& " WHERE lngCustomerTypeID=" & mlngCustomerTypeID
gclsBase.BaseDB.Execute strSql
If Not ChangeLowerCardCodeAndFullName("CustomerType", "strCustomerTypeCode", _
"strFullName", "lngCustomerTypeID", mstrOldCode, mstrOldFullName, mstrCode, _
mstrFullName, mintOldLevel, mintLevel) Then GoTo ErrHandle
If mblnIsInActive Then '本级停用时改变下级的停用属性
If Not ChangeLowerActive("CustomerType", "strCustomerTypeCode", mstrCode) _
Then GoTo ErrHandle
End If
If mblnPIsDetail Then
strSql = "UPDATE CustomerType SET blnIsDetail=0 WHERE lngCustomerTypeID=" _
& mlngPCodeID
If Not gclsBase.ExecSQL(strSql) Then GoTo ErrHandle
End If
End If
If Not ChangeHigherCardDetail("CustomerType", "strCustomerTypeCode", mstrOldCode) Then GoTo ErrHandle
End If
If Not mblnIsInActive And mblnPIsInActive Then '本级是活动时改变上级的停用属性
If Not ChangeHigherActive("CustomerType", "strCustomerTypeCode", mstrCode) _
Then GoTo ErrHandle
End If
gclsBase.BaseWorkSpace.CommitTrans
SaveCard = True
mblnIsChanged = False
gclsSys.SendMessage Me.hwnd, Message.msgCustomerType
Exit Function
ErrHandle:
gclsBase.BaseWorkSpace.RollBacktrans
If InStr(Err.Description, "违反唯一约束条件") > 0 Then
If Not blnByAdd Then
ShowMsg hwnd, "已有同级单位类型使用了" & "“" & txtInput(1).Text & "“" & _
",请重新录入单位类型名称!", vbExclamation, Caption
txtInput(1).SetFocus
End If
End If
End Function
Private Function TransActivity(ByVal lngPID As Long) As Boolean
Dim intLevel As Integer
Dim recCustomerType As rdoResultset
Dim strSql As String, strFullName As String
strSql = "SELECT * FROM CustomerType WHERE lngCustomerTypeID=" & lngPID
Set recCustomerType = gclsBase.BaseDB.OpenResultset(strSql, rdOpenStatic)
With recCustomerType
mblnIsDetail = False
' mblnIsInActive = !blnIsInActive
mintLevel = !intLevel
mstrStartDate = !strStartDate
mstrCode = !strCustomerTypeCode
mstrName = !strCustomerTypeName
strFullName = !strFullName
End With
recCustomerType.Close
intLevel = stringCount(Trim(txtInput(0).Text), "-") + 1
strSql = "UPDATE CustomerType SET strCustomerTypeCode='" & Trim(txtInput(0).Text) _
& "',strCustomerTypeName='" & Trim(txtInput(1).Text) & "',strFullName='" & mstrFullName _
& "',blnIsInActive=" & chkPause.Value & ",intLevel =" & intLevel _
& ",strStartDate='" & Format(Date, "YYYY-MM-DD") _
& "' WHERE lngCustomerTypeID=" & lngPID
TransActivity = gclsBase.ExecSQL(strSql)
If TransActivity Then mstrFullName = strFullName
End Function
Private Sub txtInput_Change(Index As Integer)
Dim strErr As String
If Index = 0 Then
strErr = "'""|?`~!^*"
Else
strErr = "'""|?`~-!^*"
End If
If ContainErrorChar(txtInput(Index).Text, strErr) Then
BKKEY txtInput(Index).hwnd
End If
If Not mblnIsInit Then mblnIsChanged = True
End Sub
Private Sub txtInput_KeyPress(Index As Integer, KeyAscii As Integer)
If Index = 0 Then
If InStr("'""|?`~!^*", Chr(KeyAscii)) > 0 Then KeyAscii = 0
Else
If InStr("'""|?`~-!^*", Chr(KeyAscii)) > 0 Then KeyAscii = 0
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -