⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 department.cls

📁 这是一个企业版的人力资源管理源码,很适合初级开发人员
💻 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 = "Department"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Public Dep_Id As Long
Public Dep_name As String
Public Describe As String
Public UpperId As Long

Public Sub Init()
  Dep_Id = -1
  Dep_name = ""
  Describe = -1
  UpperId = -1
End Sub

'删除Department
Public Sub Delete(ByVal TmpId As Long)
  DB_Connect
  
  SqlStmt = "DELETE FROM Department WHERE Dep_Id=" + Trim(Str(TmpId))
  OdbcExt (SqlStmt)
  Rc = SQLFreeStmt(Hstmt, SQL_DROP)

  DB_Disconnect
End Sub

Public Sub GetInfo(TmpId As Long)
  Dep_Id = TmpId
  
  DB_Connect
  
  SqlStmt = "SELECT * FROM Department WHERE Dep_Id=" + Trim(Str(TmpId))
  OdbcExt (SqlStmt)
  If SQLFetch(Hstmt) <> SQL_NO_DATA_FOUND Then
    '读取部门名称
    ColVal = String(400, 0)
    Rc = SQLGetData(Hstmt, 2, 1, ColVal, Len(ColVal), pcblen)
    Dep_name = TrimStr(ColVal)
    '读取部门描述
    ColVal = String(400, 0)
    Rc = SQLGetData(Hstmt, 3, 1, ColVal, Len(ColVal), pcblen)
    Describe = TrimStr(ColVal)
    '读取上一级部门的编号
    ColVal = String(40, 0)
    Rc = SQLGetData(Hstmt, 4, 1, ColVal, Len(ColVal), pcblen)
    UpperId = Val(ColVal)
  Else
    Init
  End If
  Rc = SQLFreeStmt(Hstmt, SQL_DROP)
  
  DB_Disconnect
End Sub

Public Function GetName(ByVal TmpId As Long) As String
  DB_Connect
  
  SqlStmt = "SELECT Dep_Name FROM Department WHERE Dep_Id=" _
          + Trim(Str(TmpId))
  OdbcExt (SqlStmt)
  If SQLFetch(Hstmt) <> SQL_NO_DATA_FOUND Then
    ColVal = String(400, 0)
    Rc = SQLGetData(Hstmt, 1, 1, ColVal, Len(ColVal), pcblen)
    GetName = TrimStr(ColVal)
  Else
    GetName = ""
  End If
  Rc = SQLFreeStmt(Hstmt, SQL_DROP)
  
  DB_Disconnect
End Function

Public Function GetNewId() As Long
  Dim TmpId As Long
  
  DB_Connect
    
  SqlStmt = "SELECT Dep_Id FROM Department ORDER BY Dep_Id"
  OdbcExt (SqlStmt)
  i = 1
  Do While SQLFetch(Hstmt) <> SQL_NO_DATA_FOUND
    ColVal = String(40, 0)
    Rc = SQLGetData(Hstmt, 1, 1, ColVal, Len(ColVal), pcblen)
    TmpId = Val(ColVal)
    If TmpId = i Then
      i = i + 1
    Else
      GetNewId = i
      Rc = SQLFreeStmt(Hstmt, SQL_DROP)
      DB_Disconnect
      Exit Function
    End If
  Loop
  Rc = SQLFreeStmt(Hstmt, SQL_DROP)
  
  DB_Disconnect
  
  GetNewId = i
End Function

Public Function HaveEmp(ByVal TmpDepid As Long) As Boolean
  DB_Connect
  
  SqlStmt = "SELECT * FROM Employees WHERE Dep_id=" + Trim(Str(TmpDepid))
  OdbcExt (SqlStmt)
  If SQLFetch(Hstmt) = SQL_NO_DATA_FOUND Then
    HaveEmp = False
  Else
    HaveEmp = True
  End If
  Rc = SQLFreeStmt(Hstmt, SQL_DROP)
  
  DB_Disconnect
End Function

Public Function HaveSon(ByVal TmpUpperId As Long) As Boolean
  DB_Connect
  
  SqlStmt = "SELECT Dep_Id FROM Department WHERE UpperId=" _
          + Trim(Str(TmpUpperId))
  OdbcExt (SqlStmt)
  If SQLFetch(Hstmt) = SQL_NO_DATA_FOUND Then
    HaveSon = False
  Else
    HaveSon = True
  End If
  Rc = SQLFreeStmt(Hstmt, SQL_DROP)
  
  DB_Disconnect
End Function

Public Function In_DB(ByVal DepName As String, _
                      ByVal DepUpper As Long) As Boolean
  DB_Connect
  
  SqlStmt = "SELECT Dep_Id FROM Department WHERE Dep_Name='" + Trim(DepName) _
             + "' and UpperId=" + Trim(Str(DepUpper))
  OdbcExt (SqlStmt)
  If SQLFetch(Hstmt) = SQL_NO_DATA_FOUND Then
    In_DB = False
  Else
    In_DB = True
  End If
  Rc = SQLFreeStmt(Hstmt, SQL_DROP)

  DB_Disconnect
End Function

Public Function Insert() As Long
  Dim Dep_Id As Long
  '生成新的编号
  Dep_Id = GetNewId
  
  DB_Connect
  SqlStmt = "INSERT INTO Department VALUES(" + Trim(Str(Dep_Id)) + ",'" _
            + Trim(Dep_name) + "','" + Trim(Describe) _
            + "'," + Trim(Str(UpperId)) + ")"
  OdbcExt (SqlStmt)
  Rc = SQLFreeStmt(Hstmt, SQL_DROP)
  DB_Disconnect
  Insert = Dep_Id
End Function

Public Sub Load_Department_ByUpper(UpperId As Long)
  Dim i As Integer
  '初始化部门数组
  Erase Arr_DepName
  Erase Arr_DepDescribe
  Erase Arr_DepId
  ReDim Arr_DepName(0)
  ReDim Arr_DepDescribe(0)
  ReDim Arr_DepId(0)
  
  DB_Connect
  SqlStmt = "SELECT Dep_Id,Dep_Name,Describe FROM Department WHERE UpperId=" _
          + Trim(Str(UpperId)) + " ORDER BY Dep_Id"
  OdbcExt (SqlStmt)
  i = 0
  Do Until SQLFetch(Hstmt) = 100
    '读取部门编号
    ColVal = String(40, 0)
    Rc = SQLGetData(Hstmt, 1, 1, ColVal, Len(ColVal), pcblen)
    ReDim Preserve Arr_DepId(i + 1)
    Arr_DepId(i) = Val(ColVal)
    '读取部门名称
    ColVal = String(400, 0)
    Rc = SQLGetData(Hstmt, 2, 1, ColVal, Len(ColVal), pcblen)
    ReDim Preserve Arr_DepName(i + 1)
    Arr_DepName(i) = TrimStr(ColVal)
    '读取部门描述
    ColVal = String(400, 0)
    Rc = SQLGetData(Hstmt, 3, 1, ColVal, Len(ColVal), pcblen)
    ReDim Preserve Arr_DepDescribe(i + 1)
    Arr_DepDescribe(i) = Val(ColVal)
    
    i = i + 1
  Loop
  Rc = SQLFreeStmt(Hstmt, SQL_DROP)
  
  DB_Disconnect
End Sub

'更新数据
Public Sub Update(ByVal TmpId As Long)
  DB_Connect
  
  SqlStmt = "UPDATE Department SET Dep_Name='" + Trim(Dep_name) _
          + "',Describe='" + Trim(Describe) _
          + "' WHERE Dep_Id=" + Trim(Str(TmpId))
  OdbcExt (SqlStmt)
  Rc = SQLFreeStmt(Hstmt, SQL_DROP)
  DB_Disconnect
End Sub






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -