Imports System.IO
Imports System.Text
Public Class FH_ERP_SYS
    Dim Str As String = Application.StartupPath
    Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewWindowToolStripMenuItem.Click
        Dim ChildForm As New System.Windows.Forms.Form
        ChildForm.MdiParent = Me
        m_ChildFormNumber += 1
        ChildForm.Text = "視窗 " & m_ChildFormNumber
        ChildForm.Show()
    End Sub
    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub
    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CascadeToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub
    Private Sub TileVerticalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub
    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileHorizontalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub
    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ArrangeIconsToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub
    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub
    Private Sub 重置()
        工人 = False : 重新計算 = True : 首次開啟 = True ': 不變形 = True
        BL = False : BL1 = False ': BL2 = False : BL3 = False : BL4 = False : BL5 = False : BL6 = False : BL7 = False : BL8 = False
        NU1 = 0 : NU2 = 0 : NU3 = 0 : NU4 = 0 : NU5 = 0
        BBL1 = "" : BBL2 = "" : BBL3 = "" : BBL4 = "" : BBL5 = "" : BBL6 = "" : PA = "" : PA1 = "" : PA2 = "" : PA3 = "" : PA4 = "" : PA5 = "" : PA6 = "" : PA7 = "" : PA8 = "" : PA9 = ""
        PA10 = "" : PA11 = "" : PA12 = "" : PA13 = "" : PA14 = "" : PA15 = "" : PA16 = "" : PA17 = "" : PA18 = "" : PA19 = "" : PA20 = "" : PA21 = "" : PA22 = "" : PA23 = "" : PA24 = ""
        PA25 = "" : PA26 = "" : PA27 = "" : PA28 = "" : PA29 = "" : PA30 = "" : PA31 = "" : PA32 = "" : PA33 = "" : PA34 = "" : PA35 = "" : PA36 = "" : PA37 = "" : PA38 = "" : PA39 = ""
        PA40 = "" : PA41 = "" : PA42 = "" : PA43 = "" : PA44 = "" : PA45 = "" : PA46 = "" : PA47 = "" : PA48 = "" : PA49 = "" : PA50 = "" : PA51 = ""
        PPAA = "" : DTP = "" : DTP1 = "" : DTP2 = "" : DTP3 = "" ': 列印用SQL = "" : 列印用SQL2 = ""

        物料主項(0) = "FH、組合件" : 物料主項(1) = "A、加工件" : 物料主項(2) = "B、西工件" : 物料主項(3) = "C、鈑金件" : 物料主項(4) = "D、市購件" : 物料主項(5) = "E、其他"
        物料主項(6) = "NA" : 物料主項(7) = "NA" : 物料主項(8) = "NA" : 物料主項(9) = "NA"
        物料資料庫.主項目_cb.Items.Clear() : 物料資料庫.主項目_cb.Items.Add("")
        For i As Integer = 0 To 5 : 物料資料庫.主項目_cb.Items.Add(物料主項(i)) : Next : 物料資料庫.主項目_cb.Text = ""
        物料資料庫.主項目1_cb.Items.Clear() : 物料資料庫.主項目1_cb.Items.Add("")
        For i As Integer = 0 To 5 : 物料資料庫.主項目1_cb.Items.Add(物料主項(i)) : Next : 物料資料庫.主項目1_cb.Text = ""
        物料資料庫.主項目2_cb.Items.Clear() : 物料資料庫.主項目2_cb.Items.Add("")
        For i As Integer = 0 To 5 : 物料資料庫.主項目2_cb.Items.Add(物料主項(i)) : Next : 物料資料庫.主項目2_cb.Text = ""
        物料資料庫.主項目3_cb.Items.Clear() : 物料資料庫.主項目3_cb.Items.Add("")
        For i As Integer = 0 To 5 : 物料資料庫.主項目3_cb.Items.Add(物料主項(i)) : Next : 物料資料庫.主項目3_cb.Text = ""
        物料資料庫.主項目4_cb.Items.Clear() : 物料資料庫.主項目4_cb.Items.Add("")
        For i As Integer = 0 To 5 : 物料資料庫.主項目4_cb.Items.Add(物料主項(i)) : Next : 物料資料庫.主項目4_cb.Text = ""
        物料資料庫.主項目5_cb.Items.Clear() : 物料資料庫.主項目5_cb.Items.Add("")
        For i As Integer = 0 To 5 : 物料資料庫.主項目5_cb.Items.Add(物料主項(i)) : Next : 物料資料庫.主項目5_cb.Text = ""
        專案項目BOM表.主項目_cb.Items.Clear() : 專案項目BOM表.主項目_cb.Items.Add("")
        For i As Integer = 0 To 5 : 專案項目BOM表.主項目_cb.Items.Add(物料主項(i)) : Next : 專案項目BOM表.主項目_cb.Text = ""
        請購單申請.主項目_cb.Items.Clear() : 請購單申請.主項目_cb.Items.Add("")
        For i As Integer = 0 To 5 : 請購單申請.主項目_cb.Items.Add(物料主項(i)) : Next : 請購單申請.主項目_cb.Text = ""
    End Sub
    Private m_ChildFormNumber As Integer
    Private Sub FH_ERP_SYS_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If 登入人級別 = "00" Then : Me.Text = Me.Text & "  --  " & g_conn_type & "  --  " & gUserName & "  --  系統版本  :" & 版本 & " -- IP : " & 登入人IP
        Else : Me.Text = Me.Text & "  --  " & g_conn_type & "  --  " & gUserName & "  --  系統版本  :" & 版本 : End If : 主頁開啟 = True
        If File.Exists(Str + "\LOGG.jpg") Then : Else : MsgBox("缺少預設圖形，請洽系統管理員!!") : Me.Close() : End If
    End Sub
    Private Sub YS_ERP_SYS_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        ''-----業務管理---------------------------------------------------------------------------------------------------------------------------------------------------------------------
        '業務管理系統_tsm.Visible = CC(5) : 客戶資料表_tsm.Visible = CC(19) : 洽談日報表_tsm.Visible = CC(42)
        ''-----採購管理---------------------------------------------------------------------------------------------------------------------------------------------------------------------
        採購系統管理_tsm.Visible = CC(5) : 請購單申請_tsm.Visible = CC(33) : 請購單核準_tsm.Visible = CC(34) : 採購單詢價_tsm.Visible = CC(20) : 採購單編輯_tsm.Visible = CC(36)
        供應商管理_tsm.Visible = CC(19) : 銀行資料修改審核_tsm.Visible = CC(14) : 採購單一級核准_tsm.Visible = CC(73) : 採購單二級核准_tsm.Visible = CC(37)
        採購單一覽表_tsm.Visible = CC(38) : 入庫驗收單_tsm.Visible = CC(39) : 採購單初級核准_tsm.Visible = CC(83) : 物料採購統計表_tsm.Visible = CC(21)
        請購一覽表_tsm.Visible = False : 供應商商品單價設定_tsm.Visible = False
        ''-----倉儲管理---------------------------------------------------------------------------------------------------------------------------------------------------------------------
        倉儲管理系統_tsm.Visible = CC(9) : 物料資料庫_tsm.Visible = CC(70) : 專案項目BOM表_tsm.Visible = CC(52) : 倉儲分區控制表_tsm.Visible = CC(114)
        '-----人事管理---------------------------------------------------------------------------------------------------------------------------------------------------------------------
        人事管理系統_tsm.Visible = CC(22) : 人員ID卡系統配置設定_tsm.Visible = CC(23)
        '-----系統管理---------------------------------------------------------------------------------------------------------------------------------------------------------------------
        資料庫系統管理_tsm.Visible = CC(1) : 系統使用者管理_tsm.Visible = CC(2) : 系統權限預設表_tsm.Visible = CC(84) : 系統組織架構設定_tsm.Visible = CC(41)
        部門權限設定_tsm.Visible = CC(87) : 系統組織結構與權限設定_tsm.Visible = CC(89) : 系統通用變數管理_tsm.Visible = CC(43) : 系統編碼規則_tsm.Visible = CC(10)
        系統對應電腦註冊_tsm.Visible = CC(44) : 系統執行檔版本管理_tsm.Visible = CC(4)

        If File.Exists(Str + "\Font_NUD.txt") Then
            Dim filereader = My.Computer.FileSystem.OpenTextFileReader(Str + "\Font_NUD.txt", System.Text.Encoding.Default)
            Dim Text As String = "" : Dim line As String = filereader.ReadLine()
            While Not (line Is Nothing) : Text = line : line = filereader.ReadLine() : End While : filereader.Close()
            If IsNothing(Text) Then : 字體_NUD.Value = 7.6 : Else : 字體_NUD.Value = CDbl(Text) : End If
        Else : 字體_NUD.Value = 7.6 : End If

        SQL_系統閒置時間設定讀取() : If dr.Read() Then : timeExit = dr("timeExit") : timeExit2 = dr("timeExit2") : End If : conn.Close() : 重登計時()
        If gUser帳號 = LoginForm1.密碼驗證_tb.Text Then : 個人帳號管理.ShowDialog() : End If
        首次開啟 = False
    End Sub
    Private Sub GRAMS_SYS_SIZE(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        Me.BackgroundImage = My.Resources._123123 : Me.BackgroundImageLayout = 3
    End Sub
    Private Sub FH_ERP_SYS_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed
        LoginForm1.Close()
    End Sub
    Private Sub 重登計時()
        timeNow = 0 : timeNow2 = 0 : Timer1.Enabled = False : Timer2.Enabled = False : Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        timeNow += 1
        If (timeNow >= timeExit) Then
            Timer1.Enabled = False : Timer2.Enabled = True : 系統登出.ShowDialog()
            If 重登確認 = True And 主頁開啟 = True Then
                Timer1.Enabled = False : Timer2.Enabled = False
                判斷重登 = True : 重登確認 = False : 主頁開啟 = False : LoginForm1.Close() : Me.Close() : Exit Sub
            ElseIf 重登確認 = True And 主頁開啟 = False Then
                Timer1.Enabled = False : Timer2.Enabled = False
                判斷重登 = True : 重登確認 = False : 主頁開啟 = False : LoginForm1.Close() : Me.Close() : Exit Sub
            ElseIf 重登確認 = False And 主頁開啟 = True Then
                timeNow = 0 : Timer1.Enabled = True : Timer2.Enabled = False : timeNow2 = 0
            ElseIf 重登確認 = False And 主頁開啟 = False Then
                timeNow = 0 : Timer1.Enabled = True : Timer2.Enabled = False : timeNow2 = 0
            End If
        End If
    End Sub
    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        Timer1.Enabled = False
        timeNow2 += 1
        If (timeNow2 >= timeExit2) Then
            Timer1.Enabled = False : Timer2.Enabled = False
            判斷重登 = True : 重登確認 = False : 主頁開啟 = False : LoginForm1.Close() : 系統登出.Close() : Me.Close() : Exit Sub
        End If
    End Sub
    Private Sub 字體_NUD_ValueChanged(sender As Object, e As EventArgs) Handles 字體_NUD.ValueChanged
        If 首次開啟 = True Then : Else
            Dim strDirName As String : Dim Strs As String = Application.StartupPath
            If File.Exists(Strs & "\Font_NUD.txt") Then : File.Delete(Strs & "\Font_NUD.txt") : End If
            strDirName = Strs & "\Font_NUD.txt"
            Try
                Using fs As IO.FileStream = New IO.FileStream(strDirName, FileMode.Append)
                    Using sw As StreamWriter = New StreamWriter(fs, Encoding.Default)
                        Dim str1 As String = 字體_NUD.Value
                        sw.WriteLine(str1)   '插入一整行
                        sw.Flush()
                    End Using
                End Using
            Catch ex As Exception
            End Try
        End If
    End Sub
    Private Sub 個人帳號管理_tsm_Click(sender As Object, e As EventArgs) Handles 個人帳號管理_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 個人帳號管理.ShowDialog() : 個人帳號管理.BringToFront()
    End Sub
    Private Sub 系統使用者管理_tsm_Click(sender As Object, e As EventArgs) Handles 系統使用者管理_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : BL = False : 系統使用者管理.Show() : 系統使用者管理.BringToFront()
    End Sub
    Private Sub 系統執行檔版本管理_tsm_Click(sender As Object, e As EventArgs) Handles 系統執行檔版本管理_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 系統執行檔版本管理.ShowDialog()
    End Sub
    Private Sub 系統組織架構設定_tsm_Click(sender As Object, e As EventArgs) Handles 系統組織架構設定_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 系統組織架構設定.Show() : 系統組織架構設定.BringToFront()
    End Sub
    Private Sub 系統權限預設表_tsm_Click(sender As Object, e As EventArgs) Handles 系統權限預設表_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 系統權限預設表.Show() : 系統權限預設表.BringToFront()
    End Sub
    Private Sub 系統對應電腦註冊_tsm_Click(sender As Object, e As EventArgs) Handles 系統對應電腦註冊_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 系統綁定電腦資訊.ShowDialog() : 系統綁定電腦資訊.BringToFront()
    End Sub
    Private Sub 公司組織結構_tsm_Click(sender As Object, e As EventArgs) Handles 公司組織結構_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 公司組織結構.Show() : 公司組織結構.BringToFront()
    End Sub
    Private Sub 系統組織結構與權限設定_tsm_Click(sender As Object, e As EventArgs) Handles 系統組織結構與權限設定_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 系統組織結構與權限設定.Show() : 系統組織結構與權限設定.BringToFront()
    End Sub
    Private Sub 部門權限設定_tsm_Click(sender As Object, e As EventArgs) Handles 部門權限設定_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 部門權限設定.Show() : 部門權限設定.BringToFront()
    End Sub
    Private Sub 人員ID卡系統配置設定_tsm_Click(sender As Object, e As EventArgs) Handles 人員ID卡系統配置設定_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 人員ID卡系統配置設定.Show() : 人員ID卡系統配置設定.BringToFront()
    End Sub
    Private Sub 系統通用變數管理_tsm_Click(sender As Object, e As EventArgs) Handles 系統通用變數管理_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 系統通用變數管理.Show() : 系統通用變數管理.BringToFront()
    End Sub
    Private Sub 物料資料庫_tsm_Click(sender As Object, e As EventArgs) Handles 物料資料庫_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 舊群組開啟位置 = "物料資料庫" : 物料資料庫.Show() : 物料資料庫.BringToFront()
    End Sub
    Private Sub 專案項目BOM表_tsm_Click(sender As Object, e As EventArgs) Handles 專案項目BOM表_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 舊群組開啟位置 = "專案項目BOM表" : 專案項目BOM表.Show() : 專案項目BOM表.BringToFront()
    End Sub
    Private Sub 請購單申請_tsm_Click(sender As Object, e As EventArgs) Handles 請購單申請_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 舊群組開啟位置 = "請購單申請" : 請購單申請.Show() : 請購單申請.BringToFront()
    End Sub
    Private Sub 倉儲分區控制表_tsm_Click(sender As Object, e As EventArgs) Handles 倉儲分區控制表_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 倉儲分區控制表.Show() : 倉儲分區控制表.BringToFront()
    End Sub
    Private Sub 請購單核準_tsm_Click(sender As Object, e As EventArgs) Handles 請購單核準_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 請購單核准.Show() : 請購單核准.BringToFront()
    End Sub
    Private Sub 採購單詢價_tsm_Click(sender As Object, e As EventArgs) Handles 採購單詢價_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 採購單詢價.Show() : 採購單詢價.BringToFront()
    End Sub
    Private Sub 採購單編輯_tsm_Click(sender As Object, e As EventArgs) Handles 採購單編輯_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 採購單編輯.Show() : 採購單編輯.BringToFront()
    End Sub
    Private Sub 供應商管理_tsm_Click(sender As Object, e As EventArgs) Handles 供應商管理_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 供應商管理.Show() : 供應商管理.BringToFront()
    End Sub
    Private Sub 銀行資料修改審核_tsm_Click(sender As Object, e As EventArgs) Handles 銀行資料修改審核_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 供應商管理銀行修改審核.Show() : 供應商管理銀行修改審核.BringToFront()
    End Sub
    Private Sub 採購單一級核准_tsm_Click(sender As Object, e As EventArgs) Handles 採購單一級核准_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 採購單一級核准.Show() : 採購單一級核准.BringToFront()
    End Sub
    Private Sub 採購單二級核准_tsm_Click(sender As Object, e As EventArgs) Handles 採購單二級核准_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 採購單二級核准.Show() : 採購單二級核准.BringToFront()
    End Sub
    Private Sub 簽名檔管理_tsm_Click(sender As Object, e As EventArgs) Handles 簽名檔管理_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 簽名檔管理.Show() : 簽名檔管理.BringToFront()
    End Sub
    Private Sub 採購單一覽表_tsm_Click(sender As Object, e As EventArgs) Handles 採購單一覽表_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 採購單歷史檔案.Show() : 採購單歷史檔案.BringToFront()
    End Sub
    Private Sub 入庫驗收單_tsm_Click(sender As Object, e As EventArgs) Handles 入庫驗收單_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 採購單驗收.Show() : 採購單驗收.BringToFront()
    End Sub
    Private Sub 採購單初級核准_tsm_Click(sender As Object, e As EventArgs) Handles 採購單初級核准_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 採購單初級審核.Show() : 採購單初級審核.BringToFront()
    End Sub
    Private Sub 物料採購統計表_tsm_Click(sender As Object, e As EventArgs) Handles 物料採購統計表_tsm.Click
        For Each ChildForm As Form In Me.MdiChildren : ChildForm.Close() : Next
        重置() : 舊群組開啟位置 = "物料採購統計表" : 物料採購統計表.Show() : 物料採購統計表.BringToFront()
    End Sub
End Class
