Public Class CBOM
    Dim m_SQL As New CSQLInterface

    Const cst_TABLE_NAME As String = "BOM"
    Dim m_COLS_NAME() As String = {
        "序号",
        "BOM阶层",
        "料号PN",
        "单位",
        "用量",
        "使用位置",
        "使用备注"
        }

    Private Enum COLS
        序号
        BOM阶层
        料号PN
        单位
        用量
        使用位置
        使用备注
    End Enum

    '权限
    Public Shared AccessRight As Integer = RIGHTS.NONE


    Public Sub New()
    End Sub

    Public Function CreateNew(ByVal BOM_ID As String) As ERROR_CODE
        If CBool(AccessRight And RIGHTS.WRITE) = False Then
            Return ERROR_CODE.NORIGHT
        End If

        '"DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci " &
        Dim strSql As String = "CREATE TABLE " & "BOM_" & BOM_ID & " " &
            "(" &
            "序号 int(11) NOT NULL UNIQUE PRIMARY KEY AUTO_INCREMENT," &
            "BOM阶层 int(11) NOT NULL," &
            "料号PN varchar(16) NOT NULL," &
            "单位 varchar(20)," &
            "用量 double NOT NULL DEFAULT 0," &
            "使用位置 text," &
            "使用备注 text" &
            ") " &
            "DEFAULT CHARACTER SET gbk;"

        If SQL_ExeCommand(COL_RIGHTS.BOM管理, strSql) = True Then
            Return ERROR_CODE.SUCCESS
        End If

        Return ERROR_CODE.ACCESS
    End Function

    ''查询指定列的总条数
    'Public Function QueryColumeItemCount(ByVal BOM_ID As String, ByRef rCount As Long) As Boolean
    '    rCount = 0

    '    Dim strSql As String = "SELECT COUNT(" & m_COLS_NAME(0) & ") FROM '" & cst_TABLE_NAME & "-" & BOM_ID & "'"
    '    Dim rTable As New System.Data.DataTable
    '    If SQL_Query(strSql, rTable) = True Then
    '        rCount = rTable.Rows(0).Item(1)
    '        Return ERROR_CODE.SUCCESS
    '    End If

    '    Return ERROR_CODE.ACCESS
    'End Function

    'Public Function AddItem(ByVal BOM阶层 As String, _
    '                        ByVal 料号PN As String, _
    '                        ByVal 单位 As String, _
    '                        ByVal 用量 As Integer, _
    '                        ByVal 使用位置 As String, _
    '                        ByVal 使用备注 As String) As ERROR_CODE
    '    If CBool(m_AccessRight And RIGHTS.WRITE) = False Then
    '        Return ERROR_CODE.NORIGHT
    '    End If
    '    '"INSERT INTO [dbo].[TABLE1] ([11],[22],[33],[44],[55]) VALUES ('11','2','3','4','5')"
    '    Dim strSql As String = "INSERT INTO " & cst_TABLE_NAME & "("
    '    '加入列名
    '    For i As Integer = 0 To m_COLS_NAME.Length - 1
    '        If i > 0 Then
    '            strSql &= ","
    '        End If
    '        strSql &= "[" & m_COLS_NAME(i) & "]"
    '    Next
    '    strSql &= ") VALUES ("
    '    strSql &= "'" & 入库单PN & "'"
    '    strSql &= "'" & BOM阶层 & "'"
    '    strSql &= "'" & 料号PN & "'"
    '    strSql &= "'" & 单位 & "'"
    '    strSql &= "'" & 用量 & "'"
    '    strSql &= "'" & 使用位置 & "'"
    '    strSql &= "'" & 使用备注 & "'"
    '    strSql &= ")"

    '    If SQL_ExeCommand(strSql) = True Then
    '        Return ERROR_CODE.SUCCESS
    '    End If

    '    Return ERROR_CODE.ACCESS
    'End Function

    'Public Function UpdateItem(ByVal 入库单PN As String, _
    '                        ByVal 入库日期 As String, _
    '                        ByVal 入库时间 As String, _
    '                        ByVal 入库数量 As Integer, _
    '                        ByVal 单价 As String, _
    '                        ByVal 总金额 As String, _
    '                        ByVal 操作员ID As String, _
    '                        ByVal 料号PN As String, _
    '                        ByVal 供应商ID As String) As ERROR_CODE
    '    If CBool(m_AccessRight And RIGHTS.WRITE) = False Then
    '        Return ERROR_CODE.NORIGHT
    '    End If

    '    Dim strSql As String = "UPDATE " & cst_TABLE_NAME & " SET"
    '    strSql &= ", " & m_COLS_NAME(COLS.入库日期) & "=" & 入库日期
    '    strSql &= ", " & m_COLS_NAME(COLS.入库时间) & "=" & 入库时间
    '    strSql &= " " & m_COLS_NAME(COLS.入库数量) & "=" & 入库数量
    '    strSql &= ", " & m_COLS_NAME(COLS.单价) & "=" & 单价
    '    strSql &= ", " & m_COLS_NAME(COLS.总金额) & "=" & 总金额
    '    strSql &= ", " & m_COLS_NAME(COLS.操作员ID) & "=" & 操作员ID
    '    strSql &= ", " & m_COLS_NAME(COLS.料号PN) & "=" & 料号PN
    '    strSql &= ", " & m_COLS_NAME(COLS.供应商ID) & "=" & 供应商ID
    '    strSql &= " WHERE "
    '    strSql &= m_COLS_NAME(COLS.入库单PN) & "=" & 入库单PN

    '    If SQL_ExeCommand(strSql) = True Then
    '        Return ERROR_CODE.SUCCESS
    '    End If

    '    Return ERROR_CODE.ACCESS
    'End Function

    'Public Function DeleteItem(ByVal 入库单PN As String) As ERROR_CODE
    '    If CBool(m_AccessRight And RIGHTS.WRITE) = False Then
    '        Return ERROR_CODE.NORIGHT
    '    End If

    '    Dim strSql As String = "DELETE FROM " & cst_TABLE_NAME & " WHERE "
    '    strSql &= m_COLS_NAME(COLS.入库单PN) & "=" & 入库单PN

    '    If SQL_ExeCommand(strSql) = True Then
    '        Return ERROR_CODE.SUCCESS
    '    End If

    '    Return ERROR_CODE.ACCESS
    'End Function

    'Public Function QueryItem(ByVal 入库单PN As String, _
    '                        ByRef 入库日期 As String, _
    '                        ByRef 入库时间 As String, _
    '                        ByRef 入库数量 As Integer, _
    '                        ByRef 单价 As String, _
    '                        ByRef 总金额 As String, _
    '                        ByRef 操作员ID As String, _
    '                        ByRef 料号PN As String, _
    '                        ByRef 供应商ID As String) As ERROR_CODE
    '    If CBool(m_AccessRight And RIGHTS.READ) = False Then
    '        Return ERROR_CODE.NORIGHT
    '    End If

    '    Dim strSql As String = "SELECT * FROM " & cst_TABLE_NAME & " WHERE "
    '    strSql &= m_COLS_NAME(COLS.料号PN) & "=" & 料号PN

    '    Dim rTable As New System.Data.DataTable
    '    If SQL_Query(strSql, rTable) = True Then
    '        入库日期 = rTable.Rows(0).Item(1)
    '        入库时间 = rTable.Rows(0).Item(2)
    '        入库数量 = rTable.Rows(0).Item(3)
    '        单价 = rTable.Rows(0).Item(4)
    '        总金额 = rTable.Rows(0).Item(5)
    '        操作员ID = rTable.Rows(0).Item(6)
    '        料号PN = rTable.Rows(0).Item(7)
    '        供应商ID = rTable.Rows(0).Item(8)
    '        Return ERROR_CODE.SUCCESS
    '    End If

    '    Return ERROR_CODE.ACCESS
    'End Function
End Class
