Imports System.Data.SqlClient Imports ThoughtWorks.QRCode.Codec Module Module1 '------------------連線用全域變數-------------------------------------------------------------------------------------------------------------------------------------------- Public dr As SqlDataReader : Public cmd As New SqlCommand : Public conn, conn1 As SqlConnection : Public da As New SqlDataAdapter Public gUserName, connstring, connstring1, my_ip, SQL1, Target As String '----系統版本---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Public 版本 As String = "2025032201" : Public 資料庫版本 As String Public g_conn_type As String = "" : Public my_month As String = "" : Public my_year As String = "" : Public my_month1 As String = "" : Public my_year1 As String = "" Public my_month2 As String = "" : Public my_year2 As String = "" : Public rcp As String = "" Public gLastMonth As Boolean = False Public Frm_bg_io As New Frm_BG_IO Public Frmbg As New FrmBG Public Frm_bg_chem As New Frm_BG_CHEM Public Frm_bg_main As New Frm_BG_main Public Frm_bg_SUM As New Frm_BG_sum Public Frm_BG_FM_MEASURE As New Frm_BG_FM_MEASURE Public FrmInProcess As New FrmInProcess Declare Function SetProcessDPIAware Lib "user32.dll" () As Boolean Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Integer, ByRef lpdwProcessId As Integer) As Integer Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) ' Public gMsg As MsgBoxResult Public my_chem, my_comment, xno, Staff_ID As String Public my_percent As Double Public my_time, lastFoundRowIndex, lastFoundColIndex As Integer Public cc(99), LoginSucceeded, 重新計算 As Boolean Friend Sub ConnOpen() If conn IsNot Nothing Then conn.Close() : If conn.State = ConnectionState.Closed Then : conn.ConnectionString = connstring : conn.Open() : End If Else conn = New SqlConnection(connstring) : conn.ConnectionString = connstring : 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 Public Function MakeQrCode(ByVal StrContentChar As String) As Image Dim qrCodeEncoder As New QRCodeEncoder qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE '二微码尺寸 qrCodeEncoder.QRCodeScale = 5 '二微码版本 qrCodeEncoder.QRCodeVersion = 10 qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M Dim image As Image = qrCodeEncoder.Encode(StrContentChar) Return image End Function Public Sub 查詢DGV中的關鍵字_自動(ByVal dgv As DataGridView, ByVal txtKeyword As TextBox) Dim keyword As String = txtKeyword.Text Dim found As Boolean = False dgv.ClearSelection() ' 清除先前的选择 Dim numColumns As Integer = dgv.Columns.Count ' 获取 DataGridView 的列数 Dim startRowIndex As Integer = If(lastFoundRowIndex = -1, 0, lastFoundRowIndex + 1) For colIndex As Integer = If(lastFoundRowIndex = -1, 0, lastFoundColIndex) To numColumns - 1 For rowIndex As Integer = startRowIndex To dgv.Rows.Count - 1 Dim cellValue As String = dgv.Rows(rowIndex).Cells(colIndex).Value.ToString() If cellValue.Contains(keyword) Then dgv.Rows(rowIndex).Selected = True : dgv.FirstDisplayedScrollingRowIndex = rowIndex : found = True lastFoundRowIndex = rowIndex : lastFoundColIndex = colIndex : Exit For End If Next : If found Then : Exit For : End If Next If Not found Then lastFoundRowIndex = -1 : lastFoundColIndex = -1 : dgv.FirstDisplayedScrollingRowIndex = 0 : 重新計算 = True : dgv.ClearSelection() Else : 重新計算 = False End If End Sub End Module