Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. Module GcmProc
  2. Private Function IsOperatorOrSpace(c As Char) As Boolean
  3. Return "+-*/()^".Contains(c)
  4. End Function
  5. ' 添加单元格引用到公式,如果需要则添加乘法运算符
  6. Public Function 檢查前一運算子是否可運算(算式物件 As String, 位置格 As String) As String
  7. BL10 = False
  8. If String.IsNullOrEmpty(算式物件) OrElse
  9. IsOperatorOrSpace(算式物件.Last()) Then
  10. Return 算式物件 & 位置格
  11. Else
  12. BL10 = True
  13. Return 算式物件
  14. End If
  15. End Function
  16. Public Sub DGV編輯模式滑鼠點擊不要將文字全選使用(dgv As DataGridView, rowIndex As Integer, columnIndex As Integer)
  17. If rowIndex >= 0 AndAlso columnIndex >= 0 AndAlso rowIndex < dgv.RowCount AndAlso columnIndex < dgv.ColumnCount Then
  18. Dim cell As DataGridViewCell = dgv.Rows(rowIndex).Cells(columnIndex)
  19. If TypeOf cell Is DataGridViewTextBoxCell AndAlso Not cell.ReadOnly Then
  20. dgv.CurrentCell = cell
  21. dgv.BeginEdit(True)
  22. Dim editingControl As System.Windows.Forms.TextBox = TryCast(dgv.EditingControl, System.Windows.Forms.TextBox)
  23. If editingControl IsNot Nothing Then
  24. editingControl.SelectionStart = editingControl.Text.Length
  25. editingControl.SelectionLength = 0
  26. End If
  27. End If
  28. End If
  29. End Sub
  30. ''' <summary>
  31. ''' MGB 通知視窗 strA 要顯示的文字
  32. ''' strB:訊息類型 [1] 只有確定 ; [2] 有確定跟取消, 使用 [訊息回應] 字串回傳 [YES] OR [NO]
  33. ''' </summary>
  34. Public Sub MGB(ByVal strA As String, ByVal strB As String)
  35. 通知訊息 = strA : 訊息類型 = strB : 通知視窗.ShowDialog()
  36. End Sub
  37. ''' <summary>
  38. ''' INB 輸入視窗 strC 要顯示的文字 strD 要輸入的文字
  39. ''' 輸入視窗會將訊息回傳到 [訊息回應] 上,在將 [訊息回應] 帶入要傳送的條件中。
  40. ''' 如果要在輸入視窗的輸入控件上先帶入文字即可設定第二個變數,沒有設定就是空白。
  41. ''' </summary>
  42. Public Sub INB(ByVal strC As String, Optional ByVal strD As String = "")
  43. 通知訊息 = strC : 輸入視窗.輸入_rtb.Text = strD : 輸入視窗.ShowDialog()
  44. End Sub
  45. ''' <summary>
  46. ''' 顯示說明 之前必須要宣告 [介面]
  47. ''' 開公告 輸入的是要顯示公告的次數。
  48. ''' 如果要在輸入視窗的輸入控件上先帶入文字即可設定第二個變數,沒有設定就是空白。
  49. ''' </summary>
  50. Public Sub 顯示說明(ByVal 開公告 As Integer, ByVal 公告顯示 As Boolean)
  51. Dim 開啟, 公告 As Integer : Dim 是否新增 As Boolean = False : Dim inputDate As Date : Dim yearValue As Integer
  52. Dim monthValue As Integer : Dim formattedMonth As String
  53. inputDate = Date.Now ' 假設您有一個日期,這裡我們使用當前日期作為示例
  54. yearValue = Year(inputDate) ' 從日期中提取年份和月份
  55. monthValue = Month(inputDate) ' 從日期中提取年份和月份
  56. If monthValue < 10 Then : formattedMonth = "0" & monthValue.ToString() : Else : formattedMonth = monthValue.ToString() : End If ' 格式化月份以確保兩位數
  57. PA45 = yearValue.ToString() : PA46 = formattedMonth ' 將年份和月份數值存入變數X和Y中
  58. SQL_說明顯示查詢()
  59. If dr.Read Then : 開啟 = dr("開啟次數") : 公告 = dr("公告次數") : Else : 開啟 = 0 : 公告 = 0 : 是否新增 = True : End If
  60. If 公告顯示 = True Then
  61. If 開公告 > 公告 Then : WEB說明頁面.Show() : PA48 = 公告 + 1 : ElseIf 登入人級別 = "00" Then : WEB說明頁面.Show() : PA48 = 公告 + 1 : End If
  62. End If
  63. PA47 = 開啟 + 1
  64. If 是否新增 = True Then : SQL_說明顯示新增() : Else : SQL_說明顯示修改() : End If
  65. End Sub
  66. ''' <summary>
  67. ''' 使用代號之前,請先到LINE使用者管理去進行設定
  68. ''' 對象 請在LINE使用者管理中去複製字串出來。
  69. ''' </summary>
  70. Public Sub LIN訊息通知(ByVal 代號 As String, ByVal 對象 As String, Optional ByVal 變數X As String = "", Optional ByVal 變數Y As String = "")
  71. LINE_權限代號 = 代號 : 發送對象 = 對象 : 通知變數X = 變數X : 通知變數Y = 變數Y : LINE_通知模塊()
  72. End Sub
  73. ''' <summary>
  74. ''' 輸入cb 用來載入Combox的清單
  75. ''' 原來值 用來把原本的控件上的已選擇的值帶入變數,在沒有選擇任何資料時帶回原來的值。
  76. ''' </summary>
  77. Public Sub CB選擇清單(ByVal 輸入cb As ComboBox, Optional ByVal 原來值 As String = "")
  78. Dim 原來的 As String = 原來值
  79. For I As Integer = 0 To 3000 : PPBB(I) = "" : Next
  80. For I As Integer = 0 To 輸入cb.Items.Count - 1 : PPBB(I) = 輸入cb.Items(I).ToString : NN1 = I : Next
  81. If 輸入cb.Items.Count < 23 Then : 下拉清單_2.ShowDialog() : Else : 下拉清單_1.ShowDialog() : End If
  82. If PPAA = "" Then : 輸入cb.Text = 原來的
  83. Else : 輸入cb.Text = PPAA : End If
  84. End Sub
  85. Public Sub CB選擇清單_可選空白(ByVal 輸入cb As ComboBox)
  86. For I As Integer = 0 To 3000 : PPBB(I) = "" : Next
  87. For I As Integer = 0 To 輸入cb.Items.Count - 1 : PPBB(I) = 輸入cb.Items(I).ToString : NN1 = I : Next
  88. If 輸入cb.Items.Count < 23 Then : 下拉清單_2.ShowDialog() : Else : 下拉清單_1.ShowDialog() : End If
  89. 輸入cb.Text = PPAA
  90. End Sub
  91. Public Sub 查詢DGV中的關鍵字_手動(ByVal dgv As DataGridView, ByVal txtKeyword As TextBox)
  92. Dim keyword As String = txtKeyword.Text
  93. Dim found As Boolean = False
  94. dgv.ClearSelection() ' 清除先前的选择
  95. Dim numColumns As Integer = dgv.Columns.Count ' 获取 DataGridView 的列数
  96. Dim startRowIndex As Integer = If(lastFoundRowIndex = -1, 0, lastFoundRowIndex + 1)
  97. For colIndex As Integer = If(lastFoundRowIndex = -1, 0, lastFoundColIndex) To numColumns - 1
  98. For rowIndex As Integer = startRowIndex To dgv.Rows.Count - 1
  99. Dim cellValue As String = dgv.Rows(rowIndex).Cells(colIndex).Value.ToString()
  100. If cellValue.Contains(keyword) Then
  101. dgv.Rows(rowIndex).Selected = True : dgv.FirstDisplayedScrollingRowIndex = rowIndex : found = True
  102. lastFoundRowIndex = rowIndex : lastFoundColIndex = colIndex : Exit For
  103. End If
  104. Next : If found Then : Exit For : End If
  105. Next
  106. If Not found Then
  107. lastFoundRowIndex = -1 : lastFoundColIndex = -1 : dgv.FirstDisplayedScrollingRowIndex = 0 : MGB(系統語言字典("H527-215-" & 語言), 1) : 重新計算 = True : dgv.ClearSelection()
  108. Else : 重新計算 = False
  109. End If
  110. End Sub
  111. Public Sub 查詢DGV中的關鍵字_自動(ByVal dgv As DataGridView, ByVal txtKeyword As TextBox)
  112. Dim keyword As String = txtKeyword.Text
  113. Dim found As Boolean = False
  114. dgv.ClearSelection() ' 清除先前的选择
  115. Dim numColumns As Integer = dgv.Columns.Count ' 获取 DataGridView 的列数
  116. Dim startRowIndex As Integer = If(lastFoundRowIndex = -1, 0, lastFoundRowIndex + 1)
  117. For colIndex As Integer = If(lastFoundRowIndex = -1, 0, lastFoundColIndex) To numColumns - 1
  118. For rowIndex As Integer = startRowIndex To dgv.Rows.Count - 1
  119. Dim cellValue As String = dgv.Rows(rowIndex).Cells(colIndex).Value.ToString()
  120. If cellValue.Contains(keyword) Then
  121. dgv.Rows(rowIndex).Selected = True : dgv.FirstDisplayedScrollingRowIndex = rowIndex : found = True
  122. lastFoundRowIndex = rowIndex : lastFoundColIndex = colIndex : Exit For
  123. End If
  124. Next : If found Then : Exit For : End If
  125. Next
  126. If Not found Then
  127. lastFoundRowIndex = -1 : lastFoundColIndex = -1 : dgv.FirstDisplayedScrollingRowIndex = 0 : 重新計算 = True : dgv.ClearSelection()
  128. Else : 重新計算 = False
  129. End If
  130. End Sub
  131. End Module
  132. Module 單位去除模組
  133. ' 處理單位轉換的函數
  134. Public Function 轉換為雙精確度(ByVal input As String) As Double
  135. Dim result As Double = 0
  136. ' 移除空白
  137. input = input.Trim()
  138. Try
  139. ' 處理英制格式,例如 "1 1/2", "3/4", "1/5"
  140. If input.EndsWith("""") Then
  141. ' 移除英吋符號
  142. input = input.Replace("""", "").Trim()
  143. ' 處理帶分數和整數的格式
  144. If input.Contains(" ") Then
  145. ' 帶分數處理,如 "1 1/2"
  146. Dim parts() As String = input.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
  147. result = Convert.ToDouble(parts(0)) + FractionToDouble(parts(1))
  148. ElseIf input.Contains("/") Then
  149. ' 單純分數,如 "3/4"
  150. result = FractionToDouble(input)
  151. Else
  152. ' 單純整數,如 "1", "2", "3"
  153. result = Convert.ToDouble(input)
  154. End If
  155. ' 處理純數值,如 "12mm", "45 M"
  156. ElseIf input.ToLower().EndsWith("mm") Or input.ToLower().EndsWith("m") Then
  157. result = CDbl(input.Replace("mm", "").Replace("M", "").Trim())
  158. ' 處理英吋格式 "30in"
  159. ElseIf input.ToLower().EndsWith("in") Then
  160. result = CDbl(input.Replace("in", "").Trim())
  161. ' 處理其他純數字格式
  162. Else
  163. result = CDbl(input)
  164. End If
  165. Catch ex As Exception
  166. ' 如果轉換失敗,可以回傳預設值,或丟出例外
  167. Throw New FormatException("無法轉換單位: " & input, ex)
  168. End Try
  169. Return result
  170. End Function
  171. ' 將分數轉換成小數的輔助函數
  172. Private Function FractionToDouble(ByVal fraction As String) As Double
  173. Dim parts() As String = fraction.Split("/"c)
  174. If parts.Length = 2 Then
  175. Return CDbl(parts(0)) / CDbl(parts(1))
  176. Else
  177. Throw New FormatException("無法解析分數格式: " & fraction)
  178. End If
  179. End Function
  180. End Module