Public Class form_StoreLocManage
    Public Event StoreLocUpdated()

    Dim m_Table As New System.Data.DataTable
    Dim m_库位表名 As String = ""

    Public Sub New(ByVal 库位表名 As String)
        Me.InitializeComponent()
        m_库位表名 = 库位表名
    End Sub

    Private Sub form_StoreLocManage_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_库位表名 & "`", 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, 1)
        Grid1.Column(CStoreLocation.COLS.序号 + 1).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()

        RaiseEvent StoreLocUpdated()
    End Sub
End Class