Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.IO

Module SQL_Module
    '---------------資料庫權限語法--------------------------------------------------------------------------------------------------------------------------------------------------------
    Public 權限數量 As Integer = 128
    Public 系統權限 As String = "CC01, CC02, CC03, CC04, CC05, CC06, CC07, CC08, CC09, CC10, CC11, CC12, CC13, CC14, CC15, CC16, CC17, 
                                 CC18, CC19, CC20, CC21, CC22, CC23, CC24, CC25, CC26, CC27, CC28, CC29, CC30, CC31, CC32, CC33, CC34, CC35, CC36, CC37, CC38, CC39, CC40, CC41, CC42, CC43, 
                                 CC44, CC45, CC46, CC47, CC48, CC49, CC50, CC51, CC52, CC53, CC54, CC55, CC56, CC57, CC58, CC59, CC60, CC61, CC62, CC63, CC64, CC65, CC66, CC67, CC68, CC69, 
                                 CC70, CC71, CC72, CC73, CC74, CC75, CC76, CC77, CC78, CC79, CC80, CC81, CC82, CC83, CC84, CC85, CC86, CC87, CC88, CC89, CC90, CC91, CC92, CC93, CC94, CC95, 
                                 CC96, CC97, CC98, CC99, CC100, CC101, CC102, CC103, CC104, CC105, CC106, CC107, CC108, CC109, CC110, CC111, CC112, CC113, CC114, CC115, CC116, CC117, CC118, 
                                 CC119, CC120, CC121, CC122, CC123, CC124, CC125, CC126, CC127, CC128"
    Public LINE_權限數量 As Integer = 61
    Public LINE_系統權限 As String = "CC200,CC201,CC202,CC203,CC204,CC205,CC206,CC207,CC208,CC209,CC210,CC211,CC212,CC213,CC214,CC215,CC216,CC217,
                                            CC218,CC219,CC220,CC221,CC222,CC223,CC224,CC225,CC226,CC227,CC228,CC229,CC230,CC231,CC232,CC233,CC234,CC235,CC236,CC237,
                                            CC238,CC239,CC240,CC241,CC242,CC243,CC244,CC245,CC246,CC247,CC248,CC249,CC250,CC251,CC252,CC253,CC254,CC255,CC256,CC257,
                                            CC258,CC259,CC260"
    Public 登入權限 As String = "姓名, 帳號, 密碼, 部門, 課別, 組別, 職稱, 密碼日期, " & 系統權限
    Public 登入權限1 As String = "姓名, 帳號, 密碼, 部門, 處別, 課別, 組別, 職稱, 密碼日期, 級別, NAS帳號, NAS密碼, " & 系統權限
    Public LINE_登入權限 As String = "姓名, 帳號,token,通知語言,電話號碼1,電話號碼2,電話號碼3,Line,WhatsApp,Message," & LINE_系統權限
    Public LINE_登入權限2 As String = "使用者權限管理表_1.姓名, 使用者權限管理表_1.帳號, 使用者權限管理表.token, 使用者權限管理表.通知語言, 使用者權限管理表.電話號碼1, 
                                       使用者權限管理表.電話號碼2, 使用者權限管理表.電話號碼3, 使用者權限管理表.Line, 使用者權限管理表.WhatsApp, 使用者權限管理表.Message," & LINE_系統權限
    '---------------資料庫連線字串宣告--------------------------------------------------------------------------------------------------------------------------------------------------------
    Public Access1 As New OleDbConnection : Public AccesCmd As OleDbCommand
    Public Acdr As OleDbDataReader
    Public ConString, ConString1, ConString2, ConString3, ConString4 As String : Public AccessConString As String : Public SQL1, SQL2, SQL3, SQL4, SQL5, SQL6, SQL7, SQL8, SQL9, SQL10 As String
    Public conn As New SqlConnection : Public cmd As New SqlCommand
    Public dr As SqlDataReader : Public da As New SqlDataAdapter
    Friend Sub ConnOpen()
        conn.Close() : If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
    End Sub
    Friend Sub ConnOpen_圖庫SQL()
        conn.Close() : If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString2 : conn.Open() : End If
    End Sub
    Friend Sub ConnOpenFTP()
        conn.Close() : If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString4 : conn.Open() : End If
    End Sub
    Friend Sub CmdSet_For_DGV()
        cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd
    End Sub
    Friend Sub CmdSet_For_dr()
        cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader
    End Sub
    Friend Sub CmdSet_For_dr_pic()
        Dim fs As FileStream : fs = File.OpenRead(PA49) : Dim picb(fs.Length) As Byte : fs.Read(picb, 0, fs.Length) : fs.Close() : cmd.Parameters.Clear()
        cmd.CommandText = SQL1 : cmd.Parameters.Add("@binary_file", SqlDbType.VarBinary).Value = picb : cmd.Connection = conn : dr = cmd.ExecuteReader
    End Sub
    '---------------系統應用模組--------------------------------------------------------------------------------------------------------------------------------------------------------
    Public 平均數 As Integer : Public 最終數 As Integer = 0 : Public 資料數 As Integer = 0
    Public Class MyMod
        Friend Shared Sub 進度條()
            平均數 = 10000 / 資料數
            最終數 += 平均數
            If 最終數 > 10000 Then : 最終數 = 10000 : End If
            YS_ERP_SYS.ToolStripProgressBar1.Value = 最終數
        End Sub
        'Friend Shared Sub 進度條1()
        '    If 資料數 = 0 Then : 平均數 = 0 : Else : 平均數 = 10000 / 資料數 : End If
        '    最終數 += 平均數
        '    If 最終數 > 10000 Then : 最終數 = 10000 : End If
        '    進度條視窗.ProgressBar1.Value = 最終數
        'End Sub
        'Friend Shared Sub 計算顯示2()
        '    計算累加 += 1
        '    If 系統語言 = "繁體中文" Then
        '        進度條視窗.Text = "請勿操作電腦 -- [" & Strings.Format((計算累加 + 1), "#,##0") & "] 筆數據計算中 !! -- "
        '    Else
        '        進度條視窗.Text = "Jangan Mengoperasikan Komputer -- [" & Strings.Format((計算累加 + 1), "#,##0") & "] Data Are Being Calculated !! -- "
        '    End If
        'End Sub
        'Friend Shared Sub 計算顯示3()
        '    進度條視窗.Text = "Progress Bar Window" : 進度條視窗.Close() : 進度條視窗.ProgressBar1.Value = 0 : 最終數 = 0 : 計算累加 = 0
        'End Sub
        'Friend Shared Sub 清單字體大小調整()
        '    If HX_PGS_ERP_SYS.Size.Width >= 1440 And HX_PGS_ERP_SYS.Size.Height >= 900 Then
        '        7.6 = 9
        '    ElseIf HX_PGS_ERP_SYS.Size.Width <= 1440 And HX_PGS_ERP_SYS.Size.Height <= 900 Then
        '        7.6 = 7.6
        '    End If
        'End Sub
        'Friend Shared Sub 間距設定存檔_1()
        '    BBL1 = 1 : BBL2 = 0 : BBL3 = 0 : SQL_清單欄位查詢()
        '    If Acdr.Read() Then : Access1.Close() : SQL_清單欄位修改1_2_3() : Else : BBL4 = 0 : BBL5 = 0 : BBL6 = 0 : Access1.Close() : SQL_清單欄位建檔() : End If : Access1.Close()
        'End Sub
        'Friend Shared Sub 間距設定存檔_2()
        '    BBL1 = 0 : BBL2 = 1 : BBL3 = 0 : SQL_清單欄位查詢()
        '    If Acdr.Read() Then : Access1.Close() : SQL_清單欄位修改1_2_3() : Else : BBL4 = 0 : BBL5 = 0 : BBL6 = 0 : Access1.Close() : SQL_清單欄位建檔() : End If : Access1.Close()
        'End Sub
        'Friend Shared Sub 間距設定存檔_3()
        '    BBL1 = 0 : BBL2 = 0 : BBL3 = 1 : SQL_清單欄位查詢()
        '    If Acdr.Read() Then : Access1.Close() : SQL_清單欄位修改1_2_3() : Else : BBL4 = 0 : BBL5 = 0 : BBL6 = 0 : Access1.Close() : SQL_清單欄位建檔() : End If : Access1.Close()
        'End Sub
        'Friend Shared Sub 間距設定存檔_4()
        '    BBL4 = 1 : BBL5 = 0 : BBL6 = 0 : SQL_清單欄位查詢()
        '    If Acdr.Read() Then : Access1.Close() : SQL_清單欄位修改4_5_6() : Else : BBL1 = 0 : BBL2 = 0 : BBL3 = 0 : Access1.Close() : SQL_清單欄位建檔() : End If : Access1.Close()
        'End Sub
        'Friend Shared Sub 間距設定存檔_5()
        '    BBL4 = 0 : BBL5 = 1 : BBL6 = 0 : SQL_清單欄位查詢()
        '    If Acdr.Read() Then : Access1.Close() : SQL_清單欄位修改4_5_6() : Else : BBL1 = 0 : BBL2 = 0 : BBL3 = 0 : Access1.Close() : SQL_清單欄位建檔() : End If : Access1.Close()
        'End Sub
        'Friend Shared Sub 間距設定存檔_6()
        '    BBL4 = 0 : BBL5 = 6 : BBL6 = 0 : SQL_清單欄位查詢()
        '    If Acdr.Read() Then : Access1.Close() : SQL_清單欄位修改4_5_6() : Else : BBL1 = 0 : BBL2 = 0 : BBL3 = 0 : Access1.Close() : SQL_清單欄位建檔() : End If : Access1.Close()
        'End Sub
        'Friend Shared Sub 虛擬桌面開啟()
        '    HX_PGS_ERP_SYS.大框_sc.Visible = True : HX_PGS_ERP_SYS.計算分流1.Enabled = True : HX_PGS_ERP_SYS.視窗1_pl.SendToBack()
        '    If 總務 = False And 業務 = False And 採購 = False And 工程 = False And 倉儲 = False And 財務 = False And 人事 = False Then : HX_PGS_ERP_SYS.虛擬桌_pl.BringToFront()
        '    ElseIf 總務 = True And 業務 = False And 採購 = False And 工程 = False And 倉儲 = False And 財務 = False And 人事 = False Then : HX_PGS_ERP_SYS.虛擬桌_總務_pl.BringToFront()
        '    ElseIf 總務 = False And 業務 = True And 採購 = False And 工程 = False And 倉儲 = False And 財務 = False And 人事 = False Then : HX_PGS_ERP_SYS.虛擬桌_業務_pl.BringToFront()
        '    ElseIf 總務 = False And 業務 = False And 採購 = True And 工程 = False And 倉儲 = False And 財務 = False And 人事 = False Then : HX_PGS_ERP_SYS.虛擬桌_採購_pl.BringToFront()
        '    ElseIf 總務 = False And 業務 = False And 採購 = False And 工程 = True And 倉儲 = False And 財務 = False And 人事 = False Then : HX_PGS_ERP_SYS.虛擬桌_工程_pl.BringToFront()
        '    ElseIf 總務 = False And 業務 = False And 採購 = False And 工程 = False And 倉儲 = True And 財務 = False And 人事 = False Then : HX_PGS_ERP_SYS.虛擬桌_倉儲_pl.BringToFront()
        '    ElseIf 總務 = False And 業務 = False And 採購 = False And 工程 = False And 倉儲 = False And 財務 = True And 人事 = False Then : HX_PGS_ERP_SYS.虛擬桌_財務_pl.BringToFront()
        '    ElseIf 總務 = False And 業務 = False And 採購 = False And 工程 = False And 倉儲 = False And 財務 = False And 人事 = True Then : HX_PGS_ERP_SYS.虛擬桌_人事_pl.BringToFront()
        '    End If : HX_PGS_ERP_SYS.重讀_bt.PerformClick()
        'End Sub
    End Class
End Module
