Option Strict Off
Imports System.IO
Public Class 供應商管理
    Dim RI As Integer = -1
    Dim SK As String = "要查找的 KEY"
    Dim Str As String = Application.StartupPath
    Dim 對話框(12), 銀行資料(3) As String
    Private Sub 讀取供應商料表()
        Dim ds As New DataSet : 廠商清單_dgv.DataSource = Nothing : ds.Clear()
        廠商清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
        廠商清單_dgv.ColumnHeadersHeight = 25 : 廠商清單_dgv.AllowUserToAddRows = False : 廠商清單_dgv.RowTemplate.Height = 35

        SQL_建築物料供應商資料管理_清單()
        列印用SQL = SQL1 : da.Fill(ds) : 廠商清單_dgv.DataSource = ds.Tables(0)

        廠商清單_dgv.Columns(0).FillWeight = 80 : 廠商清單_dgv.Columns(1).FillWeight = 150 : 廠商清單_dgv.Columns(2).FillWeight = 200
        廠商清單_dgv.Columns(3).FillWeight = 400 : 廠商清單_dgv.Columns(4).FillWeight = 120 : 廠商清單_dgv.Columns(5).Visible = False
        廠商清單_dgv.Columns(6).Visible = False : 廠商清單_dgv.Columns(7).FillWeight = 120 : 廠商清單_dgv.Columns(8).Visible = False
        廠商清單_dgv.Columns(9).Visible = False : 廠商清單_dgv.Columns(10).FillWeight = 120 : 廠商清單_dgv.Columns(11).FillWeight = 120
        廠商清單_dgv.Columns(12).Visible = False
        廠商清單_dgv.Columns(13).Visible = False : 廠商清單_dgv.Columns(14).Visible = False : 廠商清單_dgv.Columns(15).Visible = False
        廠商清單_dgv.Columns(16).Visible = False : 廠商清單_dgv.Columns(17).Visible = False : 廠商清單_dgv.Columns(18).Visible = False
        廠商清單_dgv.Columns(19).Visible = False : 廠商清單_dgv.Columns(20).Visible = False : 廠商清單_dgv.Columns(21).Visible = False
        廠商清單_dgv.Columns(22).Visible = False : 廠商清單_dgv.Columns(23).Visible = False : 廠商清單_dgv.Columns(24).Visible = False
        廠商清單_dgv.Columns(25).Visible = False : 廠商清單_dgv.Columns(26).Visible = False : 廠商清單_dgv.Columns(27).Visible = False

        For I As Integer = 0 To 廠商清單_dgv.Columns.Count - 1 : 廠商清單_dgv.Columns(I).ReadOnly = True : Next
    End Sub
    Private Sub 格式設定1()
        供應商編號_tb.Enabled = False : 確認新增_bt.Enabled = False : 新增_bt.Enabled = True
        簡稱_lb.ForeColor = Color.Black : 公司名_ib.ForeColor = Color.Black : 公司地址_lb.ForeColor = Color.Black : 公司電話1_lb.ForeColor = Color.Black : 傳真1_lb.ForeColor = Color.Black
    End Sub
    Private Sub 格式設定2()
        簡稱_lb.ForeColor = Color.Red : 公司名_ib.ForeColor = Color.Red : 公司地址_lb.ForeColor = Color.Red : 公司電話1_lb.ForeColor = Color.Red : 傳真1_lb.ForeColor = Color.Red
    End Sub
    Private Sub 類別管理_bt_MouseEnter(sender As Object, e As EventArgs) Handles 類別管理_bt.MouseEnter
        ToolTip1.SetToolTip(Me.類別管理_bt, "類別管理")
    End Sub
    Private Sub 查詢_bt_MouseEnter(sender As Object, e As EventArgs) Handles 查詢_bt.MouseEnter
        ToolTip1.SetToolTip(Me.查詢_bt, "查詢")
    End Sub
    Private Sub 新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 新增_bt.MouseEnter
        ToolTip1.SetToolTip(Me.新增_bt, "新增")
    End Sub
    Private Sub 確認新增_bt_MouseEnter(sender As Object, e As EventArgs) Handles 確認新增_bt.MouseEnter
        ToolTip1.SetToolTip(Me.確認新增_bt, "確認新增")
    End Sub
    Private Sub 修改_bt_MouseEnter(sender As Object, e As EventArgs) Handles 修改_bt.MouseEnter
        ToolTip1.SetToolTip(Me.修改_bt, "修改")
    End Sub
    Private Sub 刪除_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除_bt.MouseEnter
        ToolTip1.SetToolTip(Me.刪除_bt, "刪除")
    End Sub
    Private Sub 類別管理_cb_下拉表單資料載入()
        SQL_供應商類別_下拉清單() : 類別管理_cb.Items.Clear()
        While (dr.Read()) : 類別管理_cb.Items.Add(dr("類別")) : End While : conn.Close()
    End Sub
    Private Sub 供應商管理_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MdiParent = FH_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
        If CC(12) = False Then : 新增_bt.Enabled = False : 修改_bt.Enabled = False : End If
        If CC(13) = False Then : 刪除_bt.Enabled = False : End If : PA = "" : Panel1.SendToBack() : ToolTip1.ToolTipTitle = "系統說明"
        清單字體大小調整()
    End Sub
    Private Sub 供應商管理_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        格式設定1() : 讀取供應商料表() : 類別管理_cb_下拉表單資料載入()
    End Sub
    Private Sub 供應商管理_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        清單字體大小調整()
    End Sub
    Private Sub 清單字體大小調整()
        廠商清單_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 System.Windows.Forms.DataGridViewCellEventArgs) Handles 廠商清單_dgv.CellClick
        If e.RowIndex = -1 Then : Else
            供應商編號_tb.Text = 廠商清單_dgv(0, e.RowIndex).Value.ToString : 供應商簡稱_tb.Text = 廠商清單_dgv(22, e.RowIndex).Value.ToString
            公司名_tb.Text = 廠商清單_dgv(2, e.RowIndex).Value.ToString : 地址_tb.Text = 廠商清單_dgv(3, e.RowIndex).Value.ToString
            電話1_tb.Text = 廠商清單_dgv(4, e.RowIndex).Value.ToString : 電話2_tb.Text = 廠商清單_dgv(5, e.RowIndex).Value.ToString
            電話3_tb.Text = 廠商清單_dgv(6, e.RowIndex).Value.ToString : 傳真1_tb.Text = 廠商清單_dgv(7, e.RowIndex).Value.ToString
            傳真2_tb.Text = 廠商清單_dgv(8, e.RowIndex).Value.ToString : 傳真3_tb.Text = 廠商清單_dgv(9, e.RowIndex).Value.ToString
            聯繫人1_tb.Text = 廠商清單_dgv(10, e.RowIndex).Value.ToString : 聯繫人2_tb.Text = 廠商清單_dgv(11, e.RowIndex).Value.ToString
            聯繫人3_tb.Text = 廠商清單_dgv(12, e.RowIndex).Value.ToString : 職稱1_tb.Text = 廠商清單_dgv(13, e.RowIndex).Value.ToString
            職稱2_tb.Text = 廠商清單_dgv(14, e.RowIndex).Value.ToString : 職稱3_tb.Text = 廠商清單_dgv(15, e.RowIndex).Value.ToString
            聯繫電話1_tb.Text = 廠商清單_dgv(16, e.RowIndex).Value.ToString : 聯繫電話2_tb.Text = 廠商清單_dgv(17, e.RowIndex).Value.ToString
            聯繫電話3_tb.Text = 廠商清單_dgv(18, e.RowIndex).Value.ToString : 信箱1_tb.Text = 廠商清單_dgv(19, e.RowIndex).Value.ToString
            信箱2_tb.Text = 廠商清單_dgv(20, e.RowIndex).Value.ToString : 信箱3_tb.Text = 廠商清單_dgv(21, e.RowIndex).Value.ToString
            支付對象_tb.Text = 廠商清單_dgv(23, e.RowIndex).Value.ToString : 銀行名稱_tb.Text = 廠商清單_dgv(24, e.RowIndex).Value.ToString
            銀行帳號_tb.Text = 廠商清單_dgv(25, e.RowIndex).Value.ToString : 銀行支行_tb.Text = 廠商清單_dgv(26, e.RowIndex).Value.ToString

            付款條件_tb.Text = 廠商清單_dgv(27, e.RowIndex).Value.ToString
            If 廠商清單_dgv(1, e.RowIndex).Value.ToString = "" Then : 類別管理_cb_下拉表單資料載入() : Else : 類別管理_cb.Text = 廠商清單_dgv(1, e.RowIndex).Value.ToString : End If
        End If
    End Sub
    Private Sub 新增_bt_Click(sender As Object, e As EventArgs) Handles 新增_bt.Click
        供應商簡稱_tb.Text = "" : 公司名_tb.Text = "" : 地址_tb.Text = "" : 電話1_tb.Text = "" : 電話2_tb.Text = "" : 電話3_tb.Text = "" : 傳真1_tb.Text = ""
        傳真2_tb.Text = "" : 傳真3_tb.Text = "" : 聯繫人1_tb.Text = "" : 聯繫人2_tb.Text = "" : 聯繫人3_tb.Text = "" : 職稱1_tb.Text = "" : 職稱2_tb.Text = ""
        職稱3_tb.Text = "" : 聯繫電話1_tb.Text = "" : 聯繫電話2_tb.Text = "" : 聯繫電話3_tb.Text = "" : 信箱1_tb.Text = "" : 信箱2_tb.Text = "" : 信箱3_tb.Text = ""

        SQL_建築物料供應商資料管理_最後一筆資料()
        If dr.Read() Then : 供應商編號_tb.Text = dr("供應商編碼").ToString : Else : 供應商編號_tb.Text = "DS000" : End If : conn.Close()
        Dim NUM1 As Integer = Double.Parse(Strings.Right(供應商編號_tb.Text, 3)) + 1
        If NUM1 < 10 Then : 供應商編號_tb.Text = "DS" & "00" & NUM1
        ElseIf NUM1 > 9 And NUM1 < 100 Then : 供應商編號_tb.Text = "DS" & "0" & NUM1
        ElseIf NUM1 > 99 Then : 供應商編號_tb.Text = "DS" & NUM1 : End If : 格式設定2() : 確認新增_bt.Enabled = True : 新增_bt.Enabled = False : 廠商清單_dgv.Enabled = False
    End Sub
    Private Sub 確認新增_bt_Click(sender As Object, e As EventArgs) Handles 確認新增_bt.Click
        If 供應商簡稱_tb.Text = "" Or 公司名_tb.Text = "" Or 地址_tb.Text = "" Or 電話1_tb.Text = "" Or 傳真1_tb.Text = "" Then : MsgBox("紅色字體處為必填項，不可空白!!")
        Else : SQL_供應商資料表_新增() : conn.Close() : MsgBox("新增完成!!") : 格式設定1() : 讀取供應商料表() : 廠商清單_dgv.Enabled = True : End If
    End Sub
    Private Sub 修改_bt_Click(sender As Object, e As EventArgs) Handles 修改_bt.Click
        For i As Integer = 0 To 廠商清單_dgv.Rows.Count - 1
            If 供應商編號_tb.Text = 廠商清單_dgv.Rows(i).Cells(0).Value.ToString Then
                If 廠商清單_dgv.Rows(i).Cells(23).Value.ToString = "" Or 廠商清單_dgv.Rows(i).Cells(24).Value.ToString = "" Or 廠商清單_dgv.Rows(i).Cells(25).Value.ToString = "" Or
                    廠商清單_dgv.Rows(i).Cells(26).Value.ToString = "" Then
                    SQL_供應商資料表_修改() : conn.Close() : MsgBox("修改完成!!") : 讀取供應商料表()
                Else
                    If 支付對象_tb.Text = 廠商清單_dgv(23, i).Value.ToString And 銀行名稱_tb.Text = 廠商清單_dgv(24, i).Value.ToString And
                        銀行帳號_tb.Text = 廠商清單_dgv(25, i).Value.ToString And 銀行支行_tb.Text = 廠商清單_dgv(26, i).Value.ToString Then
                        SQL_供應商資料表_修改() : conn.Close() : MsgBox("修改完成!!") : 讀取供應商料表()
                    Else
                        SQL_供應商資料表_修改_改() : conn.Close() : MsgBox("修改的銀行資料，主管審核後才會生效!!") : 讀取供應商料表()
                        LIN訊息通知("CC211", "FH-系統通知(主管)")
                    End If
                End If : Exit For
            End If
        Next
    End Sub
    Private Sub 刪除_bt_Click(sender As Object, e As EventArgs) Handles 刪除_bt.Click
        訊息回應 = InputBox("確定要刪除該筆資料? 請輸入大寫 [YES] 來繼續執行後續動作!!")
        If 訊息回應 = "YES" Then : SQL_供應商資料表_刪除() : conn.Close() : MsgBox("新增完成!!") : 讀取供應商料表() : End If
    End Sub
    Private Sub 查詢_bt_Click(sender As Object, e As EventArgs) Handles 查詢_bt.Click
        PA = InputBox("請輸入要查詢的供應商資料。") : 讀取供應商料表() : PA = ""
    End Sub
    Private Sub 類別管理_bt_Click_1(sender As Object, e As EventArgs) Handles 類別管理_bt.Click
        供應商類別管理.ShowDialog() : 供應商類別管理.BringToFront() : 類別管理_cb_下拉表單資料載入()
    End Sub
    Private Sub 類別管理_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 類別管理_cb.SelectedIndexChanged
        PA20 = 類別管理_cb.Text : SQL_供應商類別管理_查詢() : If dr.Read() Then : 供應商簡稱_tb.Text = dr("編碼").ToString : Else : 供應商簡稱_tb.Text = "" : End If
    End Sub
End Class