123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- Module GcmProc
- Private Function IsOperatorOrSpace(c As Char) As Boolean
- Return "+-*/()^".Contains(c)
- End Function
- ' 添加单元格引用到公式,如果需要则添加乘法运算符
- Public Function 檢查前一運算子是否可運算(算式物件 As String, 位置格 As String) As String
- BL10 = False
- If String.IsNullOrEmpty(算式物件) OrElse
- IsOperatorOrSpace(算式物件.Last()) Then
- Return 算式物件 & 位置格
- Else
- BL10 = True
- Return 算式物件
- End If
- End Function
- Public Sub DGV編輯模式滑鼠點擊不要將文字全選使用(dgv As DataGridView, rowIndex As Integer, columnIndex As Integer)
- If rowIndex >= 0 AndAlso columnIndex >= 0 AndAlso rowIndex < dgv.RowCount AndAlso columnIndex < dgv.ColumnCount Then
- Dim cell As DataGridViewCell = dgv.Rows(rowIndex).Cells(columnIndex)
- If TypeOf cell Is DataGridViewTextBoxCell AndAlso Not cell.ReadOnly Then
- dgv.CurrentCell = cell
- dgv.BeginEdit(True)
- Dim editingControl As System.Windows.Forms.TextBox = TryCast(dgv.EditingControl, System.Windows.Forms.TextBox)
- If editingControl IsNot Nothing Then
- editingControl.SelectionStart = editingControl.Text.Length
- editingControl.SelectionLength = 0
- End If
- End If
- End If
- End Sub
- ''' <summary>
- ''' MGB 通知視窗 strA 要顯示的文字
- ''' strB:訊息類型 [1] 只有確定 ; [2] 有確定跟取消, 使用 [訊息回應] 字串回傳 [YES] OR [NO]
- ''' </summary>
- Public Sub MGB(ByVal strA As String, ByVal strB As String)
- 通知訊息 = strA : 訊息類型 = strB : 通知視窗.ShowDialog()
- End Sub
- ''' <summary>
- ''' INB 輸入視窗 strC 要顯示的文字 strD 要輸入的文字
- ''' 輸入視窗會將訊息回傳到 [訊息回應] 上,在將 [訊息回應] 帶入要傳送的條件中。
- ''' 如果要在輸入視窗的輸入控件上先帶入文字即可設定第二個變數,沒有設定就是空白。
- ''' </summary>
- Public Sub INB(ByVal strC As String, Optional ByVal strD As String = "")
- 通知訊息 = strC : 輸入視窗.輸入_rtb.Text = strD : 輸入視窗.ShowDialog()
- End Sub
- ''' <summary>
- ''' 顯示說明 之前必須要宣告 [介面]
- ''' 開公告 輸入的是要顯示公告的次數。
- ''' 如果要在輸入視窗的輸入控件上先帶入文字即可設定第二個變數,沒有設定就是空白。
- ''' </summary>
- Public Sub 顯示說明(ByVal 開公告 As Integer, ByVal 公告顯示 As Boolean)
- Dim 開啟, 公告 As Integer : Dim 是否新增 As Boolean = False : Dim inputDate As Date : Dim yearValue As Integer
- Dim monthValue As Integer : Dim formattedMonth As String
- inputDate = Date.Now ' 假設您有一個日期,這裡我們使用當前日期作為示例
- yearValue = Year(inputDate) ' 從日期中提取年份和月份
- monthValue = Month(inputDate) ' 從日期中提取年份和月份
- If monthValue < 10 Then : formattedMonth = "0" & monthValue.ToString() : Else : formattedMonth = monthValue.ToString() : End If ' 格式化月份以確保兩位數
- PA45 = yearValue.ToString() : PA46 = formattedMonth ' 將年份和月份數值存入變數X和Y中
- SQL_說明顯示查詢()
- If dr.Read Then : 開啟 = dr("開啟次數") : 公告 = dr("公告次數") : Else : 開啟 = 0 : 公告 = 0 : 是否新增 = True : End If
- If 公告顯示 = True Then
- If 開公告 > 公告 Then : WEB說明頁面.Show() : PA48 = 公告 + 1 : ElseIf 登入人級別 = "00" Then : WEB說明頁面.Show() : PA48 = 公告 + 1 : End If
- End If
- PA47 = 開啟 + 1
- If 是否新增 = True Then : SQL_說明顯示新增() : Else : SQL_說明顯示修改() : End If
- End Sub
- ''' <summary>
- ''' 使用代號之前,請先到LINE使用者管理去進行設定
- ''' 對象 請在LINE使用者管理中去複製字串出來。
- ''' </summary>
- Public Sub LIN訊息通知(ByVal 代號 As String, ByVal 對象 As String, Optional ByVal 變數X As String = "", Optional ByVal 變數Y As String = "")
- LINE_權限代號 = 代號 : 發送對象 = 對象 : 通知變數X = 變數X : 通知變數Y = 變數Y : LINE_通知模塊()
- End Sub
- ''' <summary>
- ''' 輸入cb 用來載入Combox的清單
- ''' 原來值 用來把原本的控件上的已選擇的值帶入變數,在沒有選擇任何資料時帶回原來的值。
- ''' </summary>
- Public Sub CB選擇清單(ByVal 輸入cb As ComboBox, Optional ByVal 原來值 As String = "")
- Dim 原來的 As String = 原來值
- For I As Integer = 0 To 3000 : PPBB(I) = "" : Next
- For I As Integer = 0 To 輸入cb.Items.Count - 1 : PPBB(I) = 輸入cb.Items(I).ToString : NN1 = I : Next
- If 輸入cb.Items.Count < 23 Then : 下拉清單_2.ShowDialog() : Else : 下拉清單_1.ShowDialog() : End If
- If PPAA = "" Then : 輸入cb.Text = 原來的
- Else : 輸入cb.Text = PPAA : End If
- End Sub
- Public Sub CB選擇清單_可選空白(ByVal 輸入cb As ComboBox)
- For I As Integer = 0 To 3000 : PPBB(I) = "" : Next
- For I As Integer = 0 To 輸入cb.Items.Count - 1 : PPBB(I) = 輸入cb.Items(I).ToString : NN1 = I : Next
- If 輸入cb.Items.Count < 23 Then : 下拉清單_2.ShowDialog() : Else : 下拉清單_1.ShowDialog() : End If
- 輸入cb.Text = PPAA
- End Sub
- 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 : MGB(系統語言字典("H527-215-" & 語言), 1) : 重新計算 = True : dgv.ClearSelection()
- Else : 重新計算 = False
- End If
- End Sub
- 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
- Module 單位去除模組
- ' 處理單位轉換的函數
- Public Function 轉換為雙精確度(ByVal input As String) As Double
- Dim result As Double = 0
- ' 移除空白
- input = input.Trim()
- Try
- ' 處理英制格式,例如 "1 1/2", "3/4", "1/5"
- If input.EndsWith("""") Then
- ' 移除英吋符號
- input = input.Replace("""", "").Trim()
- ' 處理帶分數和整數的格式
- If input.Contains(" ") Then
- ' 帶分數處理,如 "1 1/2"
- Dim parts() As String = input.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
- result = Convert.ToDouble(parts(0)) + FractionToDouble(parts(1))
- ElseIf input.Contains("/") Then
- ' 單純分數,如 "3/4"
- result = FractionToDouble(input)
- Else
- ' 單純整數,如 "1", "2", "3"
- result = Convert.ToDouble(input)
- End If
- ' 處理純數值,如 "12mm", "45 M"
- ElseIf input.ToLower().EndsWith("mm") Or input.ToLower().EndsWith("m") Then
- result = CDbl(input.Replace("mm", "").Replace("M", "").Trim())
- ' 處理英吋格式 "30in"
- ElseIf input.ToLower().EndsWith("in") Then
- result = CDbl(input.Replace("in", "").Trim())
- ' 處理其他純數字格式
- Else
- result = CDbl(input)
- End If
- Catch ex As Exception
- ' 如果轉換失敗,可以回傳預設值,或丟出例外
- Throw New FormatException("無法轉換單位: " & input, ex)
- End Try
- Return result
- End Function
- ' 將分數轉換成小數的輔助函數
- Private Function FractionToDouble(ByVal fraction As String) As Double
- Dim parts() As String = fraction.Split("/"c)
- If parts.Length = 2 Then
- Return CDbl(parts(0)) / CDbl(parts(1))
- Else
- Throw New FormatException("無法解析分數格式: " & fraction)
- End If
- End Function
- End Module
|