Imports DevExpress.Utils
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraEditors.Controls

Public Class clsWMDocGrid
    '  Private Shared _Helper As ClassHelper
    Public Shared SELECTED_DOC_PATH As String
    'Public Shared RESULT_OBJECTTYPE As String
    Public Shared SELECTED_INWORK As Boolean
    Public Shared SELECTED_DOC_ID As Integer
    Public Shared SELECTED_DOC_RIGHT As Integer
    'Public Shared RESULT_DISPLAYNAME As String
    Public Shared RESULT_CONFIG_IDS As Hashtable
    Private Shared DATE_COLUMNS As New List(Of String)
    Private Shared DATE_COLUMNS_CONFIG As New List(Of String)
    Public Shared ActiveDocGrid As GridView

    Public Shared DTDocuments As DataTable
    Private Shared DT_DROPDOWN_ITEMS As DataTable

    Private Shared _dropdownValueChangedHandler As EventHandler
    Private Shared _datepickerValueChangedHandler As EventHandler
    Private Shared _textValueChangedHandler As EventHandler
    Private Shared _checkValueChangedHandler As EventHandler

    Private Shared Function Init_Table()
        Try
            Dim oNewDataTable As New DataTable
            oNewDataTable.TableName = "TBSELECTED_FILES"
            ' Create two columns, ID and Name.
            oNewDataTable.Columns.Add("DocID", GetType(Integer))
            oNewDataTable.Columns.Add("DOC_PATH", GetType(System.String))
            oNewDataTable.Columns.Add("OBJECTTYPE", GetType(System.String))
            oNewDataTable.Columns.Add("INWORK", GetType(System.Boolean))
            oNewDataTable.Columns.Add("DISPLAYNAME", GetType(System.String))
            oNewDataTable.Columns.Add("ACCESS_RIGHT", GetType(Integer))
            DTDocuments = oNewDataTable
            Return True
        Catch ex As Exception
            LOGGER.Error(ex)
            DTDocuments = Nothing
            Return False
        End Try

    End Function
    Public Shared Sub GetDocItems()

        '_Helper = New ClassHelper
        SELECTED_DOC_ID = 0
        If Init_Table() = True Then
            LOGGER.Debug("gridView.SelectedRowsCount: " & ActiveDocGrid.SelectedRowsCount.ToString)
            If ActiveDocGrid.SelectedRowsCount >= 1 Then
                DTDocuments.Clear()
                For Each row In ActiveDocGrid.GetSelectedRows
                    Dim newRow As DataRow = DTDocuments.NewRow()
                    Try
                        Dim DocID = ActiveDocGrid.GetRowCellValue(row, "DocID")
                        SELECTED_DOC_ID = DocID
                        newRow("DocID") = ActiveDocGrid.GetRowCellValue(row, "DocID")
                    Catch ex As Exception
                        newRow("DocID") = 0
                        SELECTED_DOC_ID = 0
                    End Try
                    Try
                        SELECTED_DOC_RIGHT = ActiveDocGrid.GetRowCellValue(row, "ACCESS_RIGHT")
                        newRow("ACCESS_RIGHT") = ActiveDocGrid.GetRowCellValue(row, SELECTED_DOC_RIGHT)
                    Catch ex As Exception
                        newRow("ACCESS_RIGHT") = 1
                    End Try
                    Try
                        SELECTED_DOC_PATH = ActiveDocGrid.GetRowCellValue(row, "FULL_FILENAME")
                        newRow("DOC_PATH") = ActiveDocGrid.GetRowCellValue(row, "FULL_FILENAME")
                    Catch ex As Exception
                        newRow("DOC_PATH") = ""
                    End Try
                    Try
                        newRow("OBJECTTYPE") = ActiveDocGrid.GetRowCellValue(row, "OBJECTTYPE")
                    Catch ex As Exception
                        newRow("OBJECTTYPE") = ""
                    End Try
                    Try
                        newRow("INWORK") = ActiveDocGrid.GetRowCellValue(row, "in work?")
                        SELECTED_INWORK = ActiveDocGrid.GetRowCellValue(row, "in work?")
                    Catch ex As Exception
                        newRow("INWORK") = False
                        SELECTED_INWORK = False
                    End Try
                    Try
                        Dim dpn = ActiveDocGrid.GetRowCellValue(row, "Displayname")
                        If IsDBNull(dpn) Or IsNothing(dpn) Then
                            dpn = ""
                        End If
                        newRow("DISPLAYNAME") = dpn
                    Catch ex As Exception
                        newRow("DISPLAYNAME") = ""
                    End Try
                    DTDocuments.Rows.Add(newRow)
                    DTDocuments.AcceptChanges()
                Next
            Else
                Dim newRow As DataRow = DTDocuments.NewRow()
                Try
                    Dim DocID = ActiveDocGrid.GetFocusedRowCellValue(ActiveDocGrid.Columns("DocID"))
                    SELECTED_DOC_ID = DocID
                    newRow("DocID") = ActiveDocGrid.GetFocusedRowCellValue(ActiveDocGrid.Columns("DocID"))
                Catch ex As Exception
                    newRow("DocID") = 0
                    SELECTED_DOC_ID = 0
                End Try
                Try
                    SELECTED_DOC_PATH = ActiveDocGrid.GetFocusedRowCellValue(ActiveDocGrid.Columns("FULL_FILENAME"))
                    newRow("DOC_PATH") = ActiveDocGrid.GetFocusedRowCellValue(ActiveDocGrid.Columns("FULL_FILENAME"))
                Catch ex As Exception
                    newRow("DOC_PATH") = ""
                End Try
                Try
                    newRow("OBJECTTYPE") = ActiveDocGrid.GetFocusedRowCellValue(ActiveDocGrid.Columns("OBJECTTYPE"))
                Catch ex As Exception
                    newRow("OBJECTTYPE") = ""
                End Try
                Try
                    newRow("INWORK") = ActiveDocGrid.GetFocusedRowCellValue(ActiveDocGrid.Columns("in work?"))
                    SELECTED_INWORK = ActiveDocGrid.GetFocusedRowCellValue(ActiveDocGrid.Columns("in work?"))
                Catch ex As Exception
                    newRow("INWORK") = False
                    SELECTED_INWORK = False
                End Try
                Try
                    Dim dpn = ActiveDocGrid.GetFocusedRowCellValue(ActiveDocGrid.Columns("Displayname"))
                    If IsDBNull(dpn) Or IsNothing(dpn) Then
                        dpn = ""
                    End If
                    newRow("DISPLAYNAME") = dpn
                Catch ex As Exception
                    newRow("DISPLAYNAME") = ""
                End Try
                DTDocuments.Rows.Add(newRow)
                DTDocuments.AcceptChanges()
            End If
        End If
    End Sub



    Public Class WindreamDocGridComboboxItem
        Implements IConvertible

        Public ConfigID As Integer
        Public Value As String

        Public Overrides Function ToString() As String
            Return Me.Value
        End Function

        Public Function ToString1(provider As IFormatProvider) As String Implements IConvertible.ToString
            Return Me.Value
        End Function

        Public Function GetTypeCode() As TypeCode Implements IConvertible.GetTypeCode
            Throw New NotImplementedException
        End Function

        Public Function ToBoolean(provider As IFormatProvider) As Boolean Implements IConvertible.ToBoolean
            Throw New NotImplementedException
        End Function

        Public Function ToByte(provider As IFormatProvider) As Byte Implements IConvertible.ToByte
            Throw New NotImplementedException
        End Function

        Public Function ToChar(provider As IFormatProvider) As Char Implements IConvertible.ToChar
            Throw New NotImplementedException
        End Function

        Public Function ToDateTime(provider As IFormatProvider) As Date Implements IConvertible.ToDateTime
            Throw New NotImplementedException
        End Function

        Public Function ToDecimal(provider As IFormatProvider) As Decimal Implements IConvertible.ToDecimal
            Throw New NotImplementedException
        End Function

        Public Function ToDouble(provider As IFormatProvider) As Double Implements IConvertible.ToDouble
            Throw New NotImplementedException
        End Function

        Public Function ToInt16(provider As IFormatProvider) As Short Implements IConvertible.ToInt16
            Throw New NotImplementedException
        End Function

        Public Function ToInt32(provider As IFormatProvider) As Integer Implements IConvertible.ToInt32
            Throw New NotImplementedException
        End Function

        Public Function ToInt64(provider As IFormatProvider) As Long Implements IConvertible.ToInt64
            Throw New NotImplementedException
        End Function

        Public Function ToSByte(provider As IFormatProvider) As SByte Implements IConvertible.ToSByte
            Throw New NotImplementedException
        End Function

        Public Function ToSingle(provider As IFormatProvider) As Single Implements IConvertible.ToSingle
            Throw New NotImplementedException
        End Function

        Public Function ToType(conversionType As Type, provider As IFormatProvider) As Object Implements IConvertible.ToType
            Throw New NotImplementedException
        End Function

        Public Function ToUInt16(provider As IFormatProvider) As UShort Implements IConvertible.ToUInt16
            Throw New NotImplementedException
        End Function

        Public Function ToUInt32(provider As IFormatProvider) As UInteger Implements IConvertible.ToUInt32
            Throw New NotImplementedException
        End Function

        Public Function ToUInt64(provider As IFormatProvider) As ULong Implements IConvertible.ToUInt64
            Throw New NotImplementedException
        End Function
    End Class

End Class
