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

📄 classdevice.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 = "classDevice"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'设备管理类


Option Explicit

Private m_IID As Integer
Private m_DeviceNO As String
Private m_DeviceName As String
Private m_DeviceModel As String
Private m_TypeNO As String
Private m_TypeName As String
Private m_DeptNO As String
Private m_Department As String
Private m_ProductPrice As Double
Private m_ProductCost As Double
Private m_PurchaseDate As String
Private m_Status As Integer
Private m_RejectDate As String
Private m_DisCardDate As String

Private m_isDirty As Boolean


Private Sub Class_Initialize()

    m_isDirty = False
    
End Sub

Public Property Get isDirty() As Boolean

    isDirty = m_isDirty
    
End Property

Public Property Get iid() As Integer

    iid = m_IID
    
End Property

Public Property Get DeviceNo() As String

    DeviceNo = m_DeviceNO
    
End Property

Public Property Let DeviceNo(value As String)

    m_DeviceNO = value
    
    m_isDirty = True
    
End Property

Public Property Get DeviceName() As String

    DeviceName = m_DeviceName
    
End Property

Public Property Let DeviceName(value As String)

    m_DeviceName = value
    
    m_isDirty = True
    
End Property

Public Property Get DeviceModel() As String

    DeviceModel = m_DeviceModel
    
End Property

Public Property Let DeviceModel(value As String)

    m_DeviceModel = value
    
    m_isDirty = True
    
End Property

Public Property Get TypeNo() As String

    TypeNo = m_TypeNO
    
End Property

Public Property Let TypeNo(value As String)

    m_TypeNO = value
    
    m_isDirty = True
    
End Property

Public Property Get TypeName() As String

    TypeName = m_TypeName
    
End Property

Public Property Get DeptNo() As String

    DeptNo = m_DeptNO
    
End Property

Public Property Let DeptNo(value As String)

    m_DeptNO = value
    
    m_isDirty = True
    
End Property

Public Property Get Department() As String

    Department = m_Department
    
End Property


Public Property Get ProductPrice() As Double

    ProductPrice = m_ProductPrice
    
End Property

Public Property Let ProductPrice(value As Double)

    m_ProductPrice = value
    
    m_isDirty = True
    
End Property

Public Property Get ProductCost() As Double

    ProductCost = m_ProductCost
    
End Property

Public Property Let ProductCost(value As Double)

    m_ProductCost = value
    
    m_isDirty = True
    
End Property

Public Property Get PurchaseDate() As String

    PurchaseDate = m_PurchaseDate
    
End Property

Public Property Let PurchaseDate(value As String)

    m_PurchaseDate = value
    
    m_isDirty = True
    
End Property

Public Property Get Status() As Integer

    Status = m_Status
    
End Property

Public Property Let Status(value As Integer)

    m_Status = value
    
    m_isDirty = True
    
End Property

Public Property Get RejectDate() As String

    RejectDate = m_RejectDate
    
End Property

Public Property Let RejectDate(value As String)

    m_RejectDate = value
    
    m_isDirty = True
    
End Property

Public Property Get DisCardDate() As String

    DisCardDate = m_DisCardDate
    
End Property

Public Property Let DisCardDate(value As String)

    m_DisCardDate = value
    
    m_isDirty = True
    
End Property

'根据设备名称取记录
Public Function loadDataByDeviceNo(DeviceNo As String) As Boolean

    Dim strSQL As String
    
    strSQL = "SELECT a.*,b.department,c.Typename FROM ( tblDevice AS A INNER JOIN tblDepartment AS B ON a.deptNO=b.deptNO ) INNER JOIN tblTypeInfo AS C ON a.TypeNO=c.TypeNO WHERE a.DeviceNo='" & DeviceNo & "'"

    loadDataByDeviceNo = loadData(strSQL)
    
End Function

'根据设备ID取记录
Public Function loadDataByID(iid As String) As Boolean

    Dim strSQL As String
    
    strSQL = "SELECT a.*,b.department,c.Typename FROM ( tblDevice AS A INNER JOIN tblDepartment AS B ON a.deptNO=b.deptNO ) INNER JOIN tblTypeInfo AS C ON a.TypeNO=c.TypeNO WHERE a.IID=" & iid
    
    loadDataByID = loadData(strSQL)

End Function

'根据SQL语句取设备记录
Private Function loadData(strSQL As String) As Boolean
      
    Dim rs As ADODB.Recordset

    On Error GoTo err_handle
    
    Set rs = gConn.Execute(strSQL)
    
    If rs.EOF Then
        loadData = False
        rs.Close
        Set rs = Nothing
    End If
    
    m_IID = rs("IID").value
    m_DeviceNO = rs("DeviceNO").value
    m_DeviceModel = rs("DeviceModel").value
    m_DeviceName = rs("DeviceName").value
    m_TypeNO = rs("TypeNO").value
    m_TypeName = rs("TypeName").value
    m_DeptNO = rs("DeptNO").value
    m_Department = rs("Department").value
    m_ProductPrice = rs("Productprice").value
    m_ProductCost = rs("ProductCost").value
    m_PurchaseDate = FormatDateTime(rs("PurchaseDate").value, vbShortDate)
    m_Status = rs("Status").value
    
    If Not IsNull(rs("RejectDate").value) Then
        m_RejectDate = FormatDateTime(rs("RejectDate").value, vbShortDate)
    End If
    If Not IsNull(rs("DiscardDate").value) Then
        m_DisCardDate = FormatDateTime(rs("DiscardDate").value, vbShortDate)
    End If
    
    m_isDirty = False
    
    rs.Close
    Set rs = Nothing
    
    loadData = True
    
    Exit Function
    
err_handle:
    Set rs = Nothing
    loadData = False

End Function

'保存当前记录
Public Function saveData() As Boolean

    Dim strSQL As String
    
    If m_isDirty = False Then
        saveData = True
        Exit Function
    End If
    
    strSQL = "UPDATE tblDevice SET"
    strSQL = strSQL & " DeviceNo='" & Replace(m_DeviceNO, "'", "''") & "',"
    strSQL = strSQL & "DeviceModel='" & Replace(m_DeviceModel, "'", "''") & "',"
    strSQL = strSQL & "DeviceName='" & Replace(m_DeviceName, "'", "''") & "',"
    strSQL = strSQL & "TypeNo='" & m_TypeNO & "',"
    strSQL = strSQL & "DeptNO='" & m_DeptNO & "',"
    strSQL = strSQL & "Productprice=" & m_ProductPrice & ","
    strSQL = strSQL & "ProductCost=" & m_ProductCost & ","
    strSQL = strSQL & "PurchaseDate=#" & m_PurchaseDate & "# WHERE IID=" & m_IID
    
    On Error GoTo err_handle
    
    gConn.Execute strSQL
    
    saveData = True
    
    m_isDirty = False
    
    Exit Function
    
err_handle:
    saveData = False

End Function

'执行数据增加操作
Public Function addData() As Boolean
    
    Dim strSQL As String
    
    strSQL = "INSERT INTO tblDevice (DeviceNO,DeviceModel,DeviceName,TypeNO,DeptNO,ProductPrice,ProductCost,PurchaseDate) VALUES ("
    strSQL = strSQL & "'" & Replace(m_DeviceNO, "'", "''") & "',"
    strSQL = strSQL & "'" & Replace(m_DeviceModel, "'", "''") & "',"
    strSQL = strSQL & "'" & Replace(m_DeviceName, "'", "''") & "',"
    strSQL = strSQL & "'" & m_TypeNO & "',"
    strSQL = strSQL & "'" & m_DeptNO & "',"
    strSQL = strSQL & m_ProductPrice & ","
    strSQL = strSQL & m_ProductCost & ","
    strSQL = strSQL & "#" & m_PurchaseDate & "#)"
    
    On Error GoTo err_handle
    
    gConn.Execute strSQL
    
    m_isDirty = False
    
    addData = loadDataByDeviceNo(m_DeviceNO)
    
    Exit Function
    
err_handle:
    addData = False

End Function

'执行数据删除操作
Public Function deleteData(iid As String) As Boolean

    Dim strSQL As String
    
    strSQL = "DELETE FROM tbldevice WHERE IID=" & iid
    
    On Error GoTo err_handle
    
    gConn.Execute strSQL
    
    deleteData = True
    
    Exit Function
    
err_handle:
    deleteData = False

End Function


'执行设备注销操作
Public Function Reject(iid As String, Optional strDate As String) As Boolean

    Dim strSQL As String
    
    If Len(strDate) = 0 Then
        strDate = FormatDateTime(Date, vbShortDate)
    End If
    
    strSQL = "UPDATE tbldevice SET RejectDate=#" & strDate & "# WHERE IID=" & iid
    
    On Error GoTo err_handle
    
    gConn.Execute strSQL
    
    Reject = True
    
    Exit Function
    
err_handle:
    Reject = False

End Function


'执行设备报废操作
Public Function DisCard(iid As String, Optional strDate As String) As Boolean

    Dim strSQL As String
    
    If Len(strDate) = 0 Then
        strDate = FormatDateTime(Date, vbShortDate)
    End If
    
    strSQL = "UPDATE tbldevice SET DiscardDate=#" & strDate & "# WHERE IID=" & iid
    
    On Error GoTo err_handle
    
    gConn.Execute strSQL
    
    DisCard = True
    
    Exit Function
    
err_handle:
    DisCard = False

End Function

⌨️ 快捷键说明

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