Imports MySql.Data.MySqlClient
Public Class form_UserManage
    Dim m_Table As New System.Data.DataTable

    Private Sub form_UserManage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If CBool(Current_Rights(COL_RIGHTS.用户管理) And RIGHTS.WRITE) = False Then
            btSave.Enabled = False
        End If

        SetDataBinding()
    End Sub

    Private Sub GetDataSet()
        If Not m_Table Is Nothing Then
            m_Table.Dispose()
        End If
        m_Table = New DataTable

        'SQL_Query("SELECT * FROM `AccountManageTable`", m_Table)
        SQL_Query(COL_RIGHTS.用户管理, "SELECT * FROM `帐号表`", m_Table)
    End Sub

    Private Sub SetDataBinding()
        GetDataSet()

        Grid1.AllowUserSort = True
        Grid1.DisplayFocusRect = False
        Grid1.ExtendLastCol = True
        Grid1.DisplayRowArrow = True
        Grid1.BoldFixedCell = False
        Grid1.SortIndicatorStyle = FlexCell.SortIndicatorStyleEnum.Light3D

        '绑定到数据源时可以指定固定行数，但绑定后不能改变Grid.FixedRows属性的值
        'Grid1.SetDataBinding(m_Table, "products", True, 2)
        Grid1.SetDataBinding(m_Table, "", True, 2)

        Grid1.Cell(0, 0).Text = ""
        Grid1.Cell(1, 0).Text = ""
        Dim src_col As Integer = 0
        Dim col As Integer = 1
        For src_col = 0 To m_Table.Columns.Count - 1
            Grid1.Cell(1, col).Text = m_Table.Columns.Item(src_col).ColumnName
            col += 1
        Next
        Grid1.Range(0, 0, 1, 0).Merge()
        Grid1.Range(0, 1, 1, 1).Merge()
        Grid1.Range(0, 2, 1, 2).Merge()
        Grid1.Range(0, 3, 1, 3).Merge()
        Grid1.Range(0, 4, 1, 4).Merge()
        Grid1.Range(0, 5, 0, 17).Merge()

        Grid1.Cell(0, 5).Text = "权限"

        Dim rights_table() As String
        '权限列设定

        '登录权限
        rights_table = {"禁止", "开启"}
        col = CAccountManage.COLS.登录 + 1
        Grid1.Column(col).CellType = FlexCell.CellTypeEnum.ComboBox
        Grid1.Column(col).Mask = FlexCell.MaskEnum.DefaultMask

        With Grid1.ComboBox(col)
            .DataSource = rights_table
            .Locked = True
            .AutoComplete = True
        End With

        '系统记录
        rights_table = {"禁止", "只读"}
        col = CAccountManage.COLS.系统记录 + 1
        Grid1.Column(col).CellType = FlexCell.CellTypeEnum.ComboBox
        Grid1.Column(col).Mask = FlexCell.MaskEnum.DefaultMask

        With Grid1.ComboBox(col)
            .DataSource = rights_table
            .Locked = True
            .AutoComplete = True
        End With

        '其它权限
        rights_table = {"禁止", "只读", "读写", "管理"}
        For col = CAccountManage.COLS.用户管理 + 1 To Grid1.Cols - 1
            Grid1.Column(col).CellType = FlexCell.CellTypeEnum.ComboBox
            Grid1.Column(col).Mask = FlexCell.MaskEnum.DefaultMask

            With Grid1.ComboBox(col)
                .DataSource = rights_table
                .Locked = True
                .AutoComplete = True
            End With
        Next

        'Grid1.Locked = True
    End Sub

    Private Sub Grid1_BeforeUserDeleteRow(ByVal Sender As System.Object, ByVal e As FlexCell.Grid.BeforeUserDeleteRowEventArgs) Handles Grid1.BeforeUserDeleteRow
        If MsgBox("确定要删除该行数据？", MsgBoxStyle.OkCancel Or MsgBoxStyle.DefaultButton2, "删除确认") <> MsgBoxResult.Ok Then
            e.Cancel = True
        End If
    End Sub

    Private Sub btSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSave.Click
        Grid1.EndCurrentEdit()
        SQL_Update(COL_RIGHTS.用户管理, m_Table)
        SetDataBinding()
    End Sub


End Class