?? clsaccgrpbi.cls
字號:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsAccGrpBI"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'--------------------------------
'時間:2001.11.12
'版權:北京用友軟件股份有限公司
'設計:章景峰
'編碼:章景峰
'說明:U8資金管理---業(yè)務對象
'--------------------------------
Option Explicit
Private Const m_conBIStyle As Long = 2
'得到賬戶余額
Public Function GetBalance(DataSourceName As String, ID As String, dEnd As Date) As Double
Dim rec As New ADODB.Recordset
OpenConnection con, DataSourceName
If Not OpenRecordset(con, rec, "Select * From fd_accdef Where accdef_id = '" & ID & "'") Then
'Err.Raise 該賬戶不存在
End If
GetBalance = IIf(IsNull(rec.Fields(0).Value), 0, rec.Fields(0).Value)
CloseRec rec
Set rec = Nothing
End Function
'得到賬戶積數(shù)
Public Function GetAccumulate(DataSourceName As String, ID As String, dEnd As Date) As Double
Dim rec As New ADODB.Recordset
OpenConnection con, DataSourceName
If Not OpenRecordset(con, rec, "Select * From fd_accdef Where accdef_id = '" & ID & "'") Then
'Err.Raise 該賬戶不存在
End If
GetAccumulate = IIf(IsNull(rec.Fields(0).Value), 0, rec.Fields(0).Value)
CloseRec rec
Set rec = Nothing
End Function
Public Function MoveTo(DataSourceName As String, MoveMode As MoveModeEnum, Optional ByVal BIStyle As Long = m_conBIStyle, Optional OID As U8FDEso.OIDObject, Optional ByVal ParentID As String) As U8FDEso.EntityObject
Dim objEO As U8FDEso.EntityObject
Dim objDataMgr As New U8FDmgr.DataManager
'----裝載此業(yè)務對象的元數(shù)據(jù)(EntityObject)
Set objEO = objDataMgr.LoadEOMetaData(DataSourceName, BIStyle)
'----賦oid值
If Not OID Is Nothing Then Set objEO.OID = OID
'----
If MoveTo_Grp(DataSourceName, objEO, MoveMode, ParentID) Then
Set MoveTo = objEO
Else
Set MoveTo = objEO 'Nothing
End If
Set objDataMgr = Nothing
Set objEO = Nothing
End Function
'刪除賬戶組時用到
Private Function MoveTo_Grp(DataSourceName As String, EO As U8FDEso.EntityObject, MoveMode As U8FDEso.MoveModeEnum, Optional ByVal ParentID As String) As Boolean
Dim sql As String
Dim rec As New ADODB.Recordset
Dim objFO As U8FDEso.FieldObject
'----建立數(shù)據(jù)庫連接,并拼寫SQL語句
If con.State = adStateClosed Then con.Open DataSourceName
Select Case MoveMode
Case esoCurrent
sql = "Select * From " & EO.SourceTable & " Where " & EO.SourceOIDField & " = '" & EO.OID & "'"
Case esoFirst
If IsNull(ParentID) Or ParentID = "" Then
sql = "Select Top 1 * From " & EO.SourceTable & " Where " & EO.SourceOIDField & " Like '" & Right("0" & EO.BIType, 2) & "%' Order By " & EO("parent_id").SourceField & "," & EO("accgrp_id").SourceField & " ASC"
Else
sql = "Select Top 1 * from " & EO.SourceTable & " where " & EO("parent_id").SourceField & "='" & ParentID & "' and " & EO.SourceOIDField & " Like '" & Right("0" & EO.BIType, 2) & "%' And " & EO.SourceOIDField & " > '" & EO.OID & "' order by " & EO("accgrp_id").SourceField & ""
End If
Case esoLast
sql = "Select Top 1 * From " & EO.SourceTable & " Where " & EO.SourceOIDField & " Like '" & Right("0" & EO.BIType, 2) & "%' Order By " & EO("parent_id").SourceField & "," & EO("accgrp_id").SourceField & " DESC"
Case esoNext
'sql = "Select Top 1 * From " & EO.SourceTable & " Where " & EO.SourceOIDField & " Like '" & Right("0" & EO.BIType, 2) & "%' And " & EO.SourceOIDField & " > '" & EO(EO.SourceOIDField) & "' Order By " & EO("parent_id").SourceField & "," & EO("accgrp_id").SourceField & " ASC"
If IsNull(ParentID) Or ParentID = "" Then
sql = "Select Top 1 * from " & EO.SourceTable & " where " & EO("parent_id").SourceField & " is Null and " & EO.SourceOIDField & " Like '" & Right("0" & EO.BIType, 2) & "%' And " & EO.SourceOIDField & " > '" & EO.OID & "' order by " & EO("accgrp_id").SourceField & ""
Else
sql = "Select Top 1 * from " & EO.SourceTable & " where " & EO("parent_id").SourceField & "='" & ParentID & "' and " & EO.SourceOIDField & " Like '" & Right("0" & EO.BIType, 2) & "%' And " & EO.SourceOIDField & " > '" & EO.OID & "' order by " & EO("accgrp_id").SourceField & ""
End If
Case esoPrevious
sql = "Select Top 1 * From " & EO.SourceTable & " Where " & EO.SourceOIDField & " Like '" & Right("0" & EO.BIType, 2) & "%' And " & EO.SourceOIDField & " < '" & EO.OID & "' Order By " & EO("parent_id").SourceField & "," & EO("accgrp_id").SourceField & " DESC"
End Select
'----打開結果集
rec.Open sql, con, adOpenStatic, adLockOptimistic
'----
If rec.EOF Then
Set rec = Nothing
'sql = "Select Top 1 * From " & EO.SourceTable & " Where " & EO.SourceOIDField & " Like '" & Right("0" & EO.BIType, 2) & "%' Order By " & EO("parent_id").SourceField & "," & EO.SourceOIDField
If IsNull(ParentID) Or ParentID = "" Then
sql = "Select Top 1 * from " & EO.SourceTable & " where " & EO("parent_id").SourceField & " is Null and " & EO.SourceOIDField & " Like '" & Right("0" & EO.BIType, 2) & "%' And " & EO.SourceOIDField & " < '" & EO.OID & "' order by " & EO.SourceOIDField & ""
Else
sql = "Select Top 1 * from " & EO.SourceTable & " where " & EO("parent_id").SourceField & "='" & ParentID & "' and " & EO.SourceOIDField & " Like '" & Right("0" & EO.BIType, 2) & "%' And " & EO.SourceOIDField & " < '" & EO.OID & "' order by " & EO.SourceOIDField & ""
End If
rec.Open sql, con, adOpenStatic, adLockOptimistic
End If
If Not rec.EOF Then
For Each objFO In EO.Fields
If objFO.Persistent And objFO.IsUsed Then
objFO.Value = rec.Fields(objFO.SourceField)
End If
Next
'----成功后,置State為esoInstance
EO.State = esoInstance
Else
If ParentID <> "" Then ' MoveTo_Grp DataSourceName, EO, MoveMode, ParentID
Set rec = Nothing
sql = "Select * from " & EO.SourceTable & " where " & EO.SourceOIDField & "='" & ParentID & "'"
rec.Open sql, con, adOpenStatic, adLockOptimistic
If Not rec.EOF Then
For Each objFO In EO.Fields
If objFO.Persistent And objFO.IsUsed Then
objFO.Value = rec.Fields(objFO.SourceField)
End If
Next
'----成功后,置State為esoInstance
EO.State = esoInstance
End If
Else
rec.Close
Set rec = Nothing
MoveTo_Grp = False
Exit Function
End If
End If
rec.Close
Set rec = Nothing
MoveTo_Grp = True
End Function
Public Function Init(DataSourceName As String, Optional ByVal BIStyle As Long = m_conBIStyle) As U8FDEso.EntityObject
Dim objEO As U8FDEso.EntityObject
Dim objDataMgr As New U8FDmgr.DataManager
Dim objOIDMgr As New U8FDmgr.OIDManager
'----裝載此業(yè)務對象的元數(shù)據(jù)(EntityObject)
Set objEO = objDataMgr.LoadEOMetaData(DataSourceName, BIStyle)
'----申請OID
Set objEO.OID = objOIDMgr.GetNewOID(DataSourceName, BIStyle)
Set Init = objEO
Set objOIDMgr = Nothing
Set objDataMgr = Nothing
Set objEO = Nothing
End Function
Public Function Save(DataSourceName As String, EO As U8FDEso.EntityObject, Optional ByVal BIStyle As Long = m_conBIStyle) As Boolean
Dim objDataMgr As New U8FDmgr.DataManager
Dim objOIDMgr As New U8FDmgr.OIDManager
'----驗證
If Not Validate(DataSourceName, EO) Then Exit Function
'----得到OID
If EO.State = esoAddNew Then
Set EO.OID = objOIDMgr.GetNewOID(DataSourceName, BIStyle, True)
End If
'----存盤
If con.State = adStateClosed Then con.Open DataSourceName
con.BeginTrans
If Not objDataMgr.Save(con, EO) Then Exit Function
con.CommitTrans
Save = True
Set objOIDMgr = Nothing
Set objDataMgr = Nothing
End Function
Private Function Validate(DataSourceName As String, EO As U8FDEso.EntityObject) As Boolean
Dim rec As New ADODB.Recordset
Dim sql As String
Select Case EO.State
Case esoDelete '----刪除前驗證
Case esoAddNew, esoEdit '----保存前驗證
If con.State = adStateClosed Then con.Open DataSourceName
sql = "Select count(*) from " & EO.SourceTable & " where " & EO("accgrp_id").SourceField & "<>'" & EO("accgrp_id") & "' and " & EO("accgrp_code").SourceField & "='" & EO("accgrp_code") & "'"
If Not IsNull(EO("parent_id").Value) Then
sql = sql & " and " & EO("parent_id").SourceField & "='" & EO("parent_id").Value & "'"
Else
sql = sql & " and " & EO("parent_id").SourceField & " is null"
End If
rec.Open sql, con, adOpenDynamic, adLockReadOnly
If rec.Fields(0) > 0 Then
MsgBox "同一類型下代碼不能重復!"
Validate = False
rec.Close
Exit Function
End If
rec.Close
End Select
Validate = True
End Function
Public Function Delete(DataSourceName As String, EO As U8FDEso.EntityObject, Optional ByVal BIStyle As Long = m_conBIStyle) As Boolean
Dim objDataMgr As New U8FDmgr.DataManager
Dim objEO As U8FDEso.EntityObject
Dim objOID As New U8FDEso.OIDObject
Dim i As Integer
Dim RecCount As Long
RecCount = RecordCount(DataSourceName, EO, EO(EO.SourceOIDField))
If RecCount > 0 Then '如果有子節(jié)點,先刪除
Set objEO = MoveTo(DataSourceName, esoFirst, , , EO(EO.SourceOIDField))
Delete DataSourceName, objEO
For i = 1 To RecCount
If i < RecCount Then
objOID = objEO(objEO.SourceOIDField)
Set objEO = MoveTo(DataSourceName, esoNext, , objOID, EO(EO.SourceOIDField))
Delete DataSourceName, objEO
End If
Next
End If
'If Not DeleteOID(DataSourceName, EO(EO.SourceOIDField), FirstChildNode) Then
' MsgBox "刪除不成功!"
' Exit Function
'End If
If con.State = adStateClosed Then con.Open DataSourceName
'----應該先加鎖,再刪除
objDataMgr.Delete con, EO
Dim sql As String
sql = "delete from fd_accgrplnk where " & EO.SourceOIDField & "='" & EO(EO.SourceOIDField) & "'"
con.Execute sql
'----解鎖
Delete = True
Set objDataMgr = Nothing
End Function
Public Function FindByCode(DataSourceName As String, Code As String, Optional ByVal BIStyle As Long = m_conBIStyle) As U8FDEso.EntityObject
Dim objEO As U8FDEso.EntityObject
Dim objDataMgr As New U8FDmgr.DataManager
Dim objOID As New U8FDEso.OIDObject
Dim rec As New ADODB.Recordset
'----裝載此業(yè)務對象的元數(shù)據(jù)(EntityObject)
Set objEO = objDataMgr.LoadEOMetaData(DataSourceName, BIStyle)
If con.State = adStateClosed Then con.Open DataSourceName
'----Get Oid from Code
rec.Open "Select " & objEO.SourceOIDField & " From " & objEO.SourceTable & " Where " & objEO("accgrp_code").SourceField & " = '" & Code & "'", con
If Not rec.EOF Then
'----賦oid值
objOID = rec.Fields(objEO.SourceOIDField)
Set objEO.OID = objOID
Else
Err.Raise vbObjectError + 3001, , "當前賬戶不存在!"
End If
rec.Close
Set rec = Nothing
'----
objDataMgr.MoveTo con, objEO, esoCurrent
Set FindByCode = objEO
Set objOID = Nothing
Set objDataMgr = Nothing
Set objEO = Nothing
End Function
Public Function RecordCount(ByVal DataSourceName As String, EO As U8FDEso.EntityObject, Optional ByVal ParentID As String)
Dim sql As String
Dim rec As New ADODB.Recordset
If con.State = adStateClosed Then con.Open DataSourceName
If IsNull(ParentID) Or ParentID = "" Then
sql = "Select count(*) From " & EO.SourceTable & " where " & EO("parent_id").SourceField & " is null"
Else
sql = "Select count(*) From " & EO.SourceTable & " where " & EO("parent_id").SourceField & "='" & ParentID & "'"
End If
rec.Open sql, con, adOpenStatic, adLockOptimistic
RecordCount = rec.Fields(0).Value
rec.Close
Set rec = Nothing
End Function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -