Public Class CStoreLocation
    Dim m_SQL As New CSQLInterface
    Public TABLE_NAME As String = ""

    Public Shared m_COLS_NAME() As String = {
        "序号",
        "库位"
    }

    Public Enum COLS
        序号
        库位
        max
    End Enum


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

    Public Function AddItem(ByVal 库位 As String
                            ) As ERROR_CODE
        If TABLE_NAME.Length = 0 Then Return ERROR_CODE.NONE

        If CBool(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 `" & TABLE_NAME & "` ("
        '加入列名
        Dim isFirst As Boolean = True
        For i As Integer = COLS.库位 To COLS.max - 1
            If isFirst = True Then
                isFirst = False
            Else
                strSql &= ","
            End If
            strSql &= "`" & m_COLS_NAME(i) & "`"
        Next
        strSql &= ") VALUES ("
        strSql &= "'" & 库位 & "'"
        strSql &= ")"

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

        Return ERROR_CODE.ACCESS
    End Function

    Public Function QueryAll(ByRef rTable As Data.DataTable) As ERROR_CODE
        If TABLE_NAME.Length = 0 Then Return ERROR_CODE.NONE

        If CBool(AccessRight And RIGHTS.READ) = False Then
            Return ERROR_CODE.NORIGHT
        End If

        Dim strSQL As String = "SELECT * FROM " & TABLE_NAME

        If SQL_Query(COL_RIGHTS.库位管理, strSQL, rTable) = True Then
            Return ERROR_CODE.SUCCESS
        End If

        Return ERROR_CODE.ACCESS
    End Function
End Class
