Option Strict Off
Public Class 倉儲分區控制表
    ReadOnly ds12 As New DataSet
    Dim 對話框(5) As String
    Private Sub Set_清單1()
        Dim ds As New DataSet : 倉儲區域_dgv.DataSource = Nothing : ds.Clear()
        倉儲區域_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        倉儲區域_dgv.ColumnHeadersHeight = 25 : 倉儲區域_dgv.AllowUserToAddRows = False : 倉儲區域_dgv.RowTemplate.Height = 25

        SQL_倉儲分區控制表_清單() : 列印用SQL = SQL1
        da.Fill(ds) : 倉儲區域_dgv.DataSource = ds.Tables(0) : conn.Close()
        倉儲區域_dgv.Columns(0).ReadOnly = True : 倉儲區域_dgv.Columns(1).ReadOnly = True : 倉儲區域_dgv.Columns(2).ReadOnly = True : 倉儲區域_dgv.Columns(3).ReadOnly = True
        倉儲區域_dgv.Columns(0).FillWeight = 90 : 倉儲區域_dgv.Columns(1).FillWeight = 90 : 倉儲區域_dgv.Columns(2).FillWeight = 350 : 倉儲區域_dgv.Columns(3).FillWeight = 60
        倉儲區域_dgv.Columns(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
    End Sub
    Private Sub Set_清單2()
        Dim ds2 As New DataSet : 入庫無指定_dgv.DataSource = Nothing : ds2.Clear()
        入庫無指定_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        入庫無指定_dgv.ColumnHeadersHeight = 25 : 入庫無指定_dgv.AllowUserToAddRows = False : 入庫無指定_dgv.RowTemplate.Height = 25

        SQL_入庫申請無指定()
        da.Fill(ds2) : 入庫無指定_dgv.DataSource = ds2.Tables(0) : conn.Close()
        入庫無指定_dgv.Columns(1).Visible = False : 入庫無指定_dgv.Columns(3).Visible = False
        入庫無指定_dgv.Columns(0).FillWeight = 300
    End Sub
    Private Sub 編號推進()
        SQL_倉儲分區控制表_最後一筆()
        If dr.Read() Then : 倉名編號_tb.Text = dr("倉名編號")
            If Val(Strings.Right(倉名編號_tb.Text, 2)) < 10 Then
                倉名編號_tb.Text = "N0" & Val(Strings.Right(倉名編號_tb.Text, 2)) + 1 : Else : 倉名編號_tb.Text = "N" & Val(Strings.Right(倉名編號_tb.Text, 2)) + 1
            End If
        Else : 倉名編號_tb.Text = "N01" : End If : conn.Close()
    End Sub
    Private Sub 倉儲分區控制表_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = FH_ERP_SYS
        Set_清單1() : Set_清單2() : ToolTip1.ToolTipTitle = "系統說明" : 倉名編號_tb.Enabled = False
        If Val(登入人級別) <= 1 Then : 修改_bt.Enabled = True : 刪除_bt.Enabled = True : Else : 修改_bt.Enabled = True : 刪除_bt.Enabled = False : End If
        編號推進()
        倉儲區域_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", FH_ERP_SYS.字體_NUD.Value)
        入庫無指定_dgv.RowsDefaultCellStyle.Font = New System.Drawing.Font("微軟正黑體", FH_ERP_SYS.字體_NUD.Value)
    End Sub
    Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
        timeNow = 0 : FH_ERP_SYS.Timer1.Enabled = False : FH_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
        timeNow = 0 : FH_ERP_SYS.Timer1.Enabled = False : FH_ERP_SYS.Timer1.Enabled = True
    End Sub
    Private Sub 入庫無指定_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 入庫無指定_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            單號_bt.Text = 入庫無指定_dgv.Rows(e.RowIndex).Cells(0).Value : 倉級1_tb.Text = 入庫無指定_dgv.Rows(e.RowIndex).Cells(2).Value
            倉編_tb.Text = 入庫無指定_dgv.Rows(e.RowIndex).Cells(4).Value
        End If
    End Sub
    Private Sub 倉儲區域_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 倉儲區域_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            倉級_tb.Text = 倉儲區域_dgv(0, e.RowIndex).Value.ToString : 倉名編號_tb.Text = 倉儲區域_dgv(1, e.RowIndex).Value.ToString
            倉級1_tb.Text = 倉儲區域_dgv.Rows(e.RowIndex).Cells(0).Value : 倉編_tb.Text = 倉儲區域_dgv.Rows(e.RowIndex).Cells(1).Value
            倉名_tb.Text = 倉儲區域_dgv(2, e.RowIndex).Value.ToString : CXL_ch.Checked = 倉儲區域_dgv.Rows(e.RowIndex).Cells(3).Value
        End If
    End Sub
    Private Sub 修正_tb_Click(sender As Object, e As EventArgs) Handles 修正_tb.Click
        If 單號_bt.Text = "" Or 倉級1_tb.Text = "" Or 倉編_tb.Text = "" Then : MsgBox("修正資料不可空白!!")
        Else : PA1 = 單號_bt.Text : PA2 = 倉級1_tb.Text : PA3 = 倉編_tb.Text : SQL_倉儲明細表修正入庫資料() : Set_清單2() : Set_清單1() : End If
    End Sub
    Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        If 倉級_tb.Text = "" Or 倉名_tb.Text = "" Then : MsgBox("沒有倉名或倉級!!") : Else
            編號推進() : SQL_倉儲分區控制表_倉名查詢()
            If dr.Read() Then : conn.Close() : MsgBox("倉庫資料重複無法新增!!") : Else
                SQL_倉儲分區控制表_不重複查詢()
                If dr.Read() Then : conn.Close() : MsgBox("倉庫資料重複無法新增!!") : Else
                    SQL_倉儲分區控制表_新增() : conn.Close() : MsgBox("倉庫資料新增完成!!") : 編號推進() : 倉名_tb.Text = "" : Set_清單1()
                End If
            End If
        End If
    End Sub
    Private Sub 修改_bt_Click(sender As Object, e As EventArgs) Handles 修改_bt.Click
        If 倉級_tb.Text = "" Or 倉名_tb.Text = "" Then : MsgBox("沒有倉名或倉級!!") : Else
            SQL_倉儲分區控制表_倉名查詢()
            If dr.Read() Then : conn.Close() : MsgBox("倉庫資料重複無法新增!!") : Else
                SQL_倉儲分區控制表_不重複查詢()
                If dr.Read() Then : conn.Close() : MsgBox("倉庫資料重複無法新增!!") : Else
                    SQL_倉儲分區控制表_修改() : conn.Close()
                    MsgBox("倉庫資料修改完成!!") : Set_清單1()
                End If
            End If
        End If
    End Sub
    Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        Dim result As DialogResult = MessageBox.Show("確定要刪除該筆資料?", "請選擇", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = DialogResult.Yes Then
            SQL_倉儲分區控制表_刪除() : conn.Close()
            MsgBox("倉庫資料刪除完成!!") : 編號推進() : 倉名_tb.Text = "" : Set_清單1()
        End If
    End Sub
    Private Sub 倉級_tb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 倉級_tb.SelectedIndexChanged
        If 系統分區控制 = True And 倉級_tb.Text = "3" Then
            If Val(登入人級別) <= 1 Then
                新增_bt.Enabled = True : 修改_bt.Enabled = True : 刪除_bt.Enabled = True
            Else
                新增_bt.Enabled = True : 修改_bt.Enabled = True : 刪除_bt.Enabled = False
            End If
        ElseIf 系統分區控制 = True And 倉級_tb.Text <> "3" Then
            新增_bt.Enabled = False : 修改_bt.Enabled = False : 刪除_bt.Enabled = False
        Else
            If Val(登入人級別) <= 1 Then
                新增_bt.Enabled = True : 修改_bt.Enabled = True : 刪除_bt.Enabled = True
            Else
                新增_bt.Enabled = True : 修改_bt.Enabled = True : 刪除_bt.Enabled = False
            End If
        End If
    End Sub
    Private Sub 新增資料_rbt_MouseEnter(sender As Object, e As EventArgs) Handles 新增_bt.MouseEnter
        ToolTip1.SetToolTip(Me.新增_bt, "新增")
    End Sub
    Private Sub 存檔_rbt_MouseEnter(sender As Object, e As EventArgs) Handles 修改_bt.MouseEnter
        ToolTip1.SetToolTip(Me.修改_bt, "修改")
    End Sub
    Private Sub 刪除_rbt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除_bt.MouseEnter
        ToolTip1.SetToolTip(Me.刪除_bt, "刪除")
    End Sub
End Class