---
# System prepended metadata

title: 資料庫串接
tags: [Code]

---

---
title: 參數編碼設定 :以帳款系統為例
tags: Code
description: Abs
---
# 參數編碼設定 :以帳款系統為例
----


## CodingPrincipleSetting.vb
### ComfirmBtn_Click
![image](https://hackmd.io/_uploads/r1BvdmLF0.png)
宣告要儲存編碼原則的字典 
Ex:
```vb
'Dim updateData As New Dictionary(Of String, Object)()
'Dim updateInventoryData As New Dictionary(Of String, Object)()
'Dim updateProductionManagment As New Dictionary(Of String, Object)()
'Dim updateFixedAsset As New Dictionary(Of String, Object)()
Dim updateBillingSystem As New Dictionary(Of String, Object)()
```
formType 增加帳款系統的CPID
![image](https://hackmd.io/_uploads/Bkx8ImELYR.png)
| Case                           | Field                                           | 
|--------------------------------|-------------------------------------------------|
| "應收請款核准單"               | accountsPayableVoucherApprovalFormCPID          | _resultCodePrincipleString   |
| "應收請款紀錄單"               | accountsReceivableBillingVoucherCPID            | _resultCodePrincipleString   |
| "付款憑單"                     | paymentVoucherCPID                              | _resultCodePrincipleString   |
| "收款憑單"                     | receiptVoucherCPID                              | _resultCodePrincipleString   |
| "佣金付款"                     | commissionPaymentVoucherCPID                    | _resultCodePrincipleString   |
```vb
'Select Case formType
        '    訂單   
        '    Case "報價"
        '        updateData("quoteCPID") = _resultCodePrincipleString
        '    ...... 
        '    Case "費用採購單"
        '        updateData("expensePurchaseOrderCPID") = _resultCodePrincipleString
        '    庫存
        '    Case "借出還回"
        '        updateInventoryData("borrowOutReturnCPID") = _resultCodePrincipleString
        '    .......
        '    Case "寄銷退貨"
        '        updateInventoryData("ConsignmentSalesReturnCPID") = _resultCodePrincipleString
        '     生管
        '    Case "廠內製令編碼"
        '        updateProductionManagment("insideFactoryProductionOrderCPID") = _resultCodePrincipleString
        '    Case "批次變更單"
        '        updateFixedAsset("batchLocationChangeCPID") = _resultCodePrincipleString
        Case "應收請款核准單"
        updateBillingSystem("accountsPayableVoucherApprovalFormCPID") = _resultCodePrincipleString
        Case "應收請款紀錄單"
        updateBillingSystem("accountsReceivableBillingVoucherCPID") = _resultCodePrincipleString
        Case "付款憑單"
        updateBillingSystem("paymentVoucherCPID") = _resultCodePrincipleString
        Case "收款憑單"
        updateBillingSystem("receiptVoucherCPID") = _resultCodePrincipleString
        Case "佣金付款"
        updateBillingSystem("commissionPaymentVoucherCPID") = _resultCodePrincipleString
        '    Case Else
        '        MessageBox.Show("此報價編碼未設定完全, 請通知工程師!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error)
        '        Return
        'End Select
```
更新到Firebase資料庫
系統:FixedAssetsSystemParameterSetting
前面宣告的字典:updateBillingSystem
```vb
        If 你要替換的系統.Count > 0 Then
            If _firebaseHelper.DocumentExists("你要替換的系統", "1") Then
                _firebaseHelper.UpdateDocument("你要替換的系統", "1", 系統字典)
            Else
                _firebaseHelper.CreateCollectionAndAddData("你要替換的系統", 系統字典, "1")
           End If
        End If

```
```vb
        '更新OrderParameterSetting裡的編碼
        'If updateData.Count > 0 Then
        '    If _firebaseHelper.DocumentExists("OrderParameterSetting", "1") Then
        '        _firebaseHelper.UpdateDocument("OrderParameterSetting", "1", updateData)
        '    Else
        '        _firebaseHelper.CreateCollectionAndAddData("OrderParameterSetting", updateData, "1")
        '    End If
        'End If

        'If updateInventoryData.Count > 0 Then
        '    If _firebaseHelper.DocumentExists("InventoryParameterSetting", "1") Then
        '        _firebaseHelper.UpdateDocument("InventoryParameterSetting", "1", updateInventoryData)
        '    Else
        '        _firebaseHelper.CreateCollectionAndAddData("InventoryParameterSetting", updateInventoryData, "1")
        '    End If

        'End If
        'If updateProductionManagment.Count > 0 Then
        '    If _firebaseHelper.DocumentExists("ProductionManagementSystemParameterSetting", "1") Then
        '        _firebaseHelper.UpdateDocument("ProductionManagementSystemParameterSetting", "1", updateProductionManagment)
        '    Else
        '        _firebaseHelper.CreateCollectionAndAddData("ProductionManagementSystemParameterSetting", updateProductionManagment, "1")
        '    End If
        'End If
        'If updateFixedAsset.Count > 0 Then
        '    If _firebaseHelper.DocumentExists("FixedAssetsSystemParameterSetting", "1") Then
        '        _firebaseHelper.UpdateDocument("FixedAssetsSystemParameterSetting", "1", updateFixedAsset)
        '    Else
        '        _firebaseHelper.CreateCollectionAndAddData("FixedAssetsSystemParameterSetting", updateFixedAsset, "1")
        '    End If
        'End If

        If updateBillingSystem.Count > 0 Then
            If _firebaseHelper.DocumentExists("BillingSystemParameterSetting", "1") Then
                _firebaseHelper.UpdateDocument("BillingSystemParameterSetting", "1", updateBillingSystem)
            Else
                _firebaseHelper.CreateCollectionAndAddData("BillingSystemParameterSetting", updateBillingSystem, "1")
           End If
        End If

```
### CodingPrincipleSetting_Load
宣告要載入介面的字典 orderParameterBillSystemData 
```vb
     If _firebaseHelper.DocumentExists("宣告的系統", "1") Then
            要讀取進來的字典 = _firebaseHelper.GetDocumentDataById("系統資料表", "1")
        End If
```
```vb
        'Dim formData = Nothing
        'Dim searchFields As New Dictionary(Of String, Object)()
        'Dim orderParameterSettingData As New Dictionary(Of String, Object)()
        'Dim orderParameterInventoryData As New Dictionary(Of String, Object)()
        'Dim orderParameterProductionData As New Dictionary(Of String, Object)()
        'Dim orderParameterFixedData As New Dictionary(Of String, Object)()
        Dim orderParameterBillSystemData As New Dictionary(Of String, Object)()
        'isCodePrincipleReset = True
        'searchFields("principleType") = formType

        'If (_firebaseHelper.DocumentExists("OrderParameterSetting", "1")) Then
        '    orderParameterSettingData = _firebaseHelper.GetDocumentDataById("OrderParameterSetting", "1")
        'End If

        'If (_firebaseHelper.DocumentExists("InventoryParameterSetting", "1")) Then
        '    orderParameterInventoryData = _firebaseHelper.GetDocumentDataById("InventoryParameterSetting", "1")
        'End If
        'If (_firebaseHelper.DocumentExists("ProductionManagementSystemParameterSetting", "1")) Then
        '    orderParameterProductionData = _firebaseHelper.GetDocumentDataById("ProductionManagementSystemParameterSetting", "1")
        'End If
        'If _firebaseHelper.DocumentExists("FixedAssetsSystemParameterSetting", "1") Then
        '    orderParameterFixedData = _firebaseHelper.GetDocumentDataById("FixedAssetsSystemParameterSetting", "1")
        'End If
        If _firebaseHelper.DocumentExists("orderParameterBillSystemData", "1") Then
            orderParameterBillSystemData = _firebaseHelper.GetDocumentDataById("orderParameterBillSystemData", "1")
        End If

```
讀取各項CPID

```vb
        'If orderParameterInventoryData.Count > 0 Then
        '    Select Case formType
        '        Case "進項"
        '            If                      (orderParameterInventoryData.ContainsKey("purchaseInvoiceCPID")) Then
        '                searchFields("codingPrinciple") = orderParameterInventoryData("purchaseInvoiceCPID")
        '            End If

        '        ......
        '        ......
        '        ......略
        '        Case "批次變更單"
        '           If orderParameterFixedData.ContainsKey("batchLocationChangeCPID") Then
        '                searchFields("codingPrinciple") = orderParameterFixedData("batchLocationChangeCPID")
        '            End If

        '            ' 如果還有其他情況，可以在這裡添加更多 Case 分支

        '    End Select
        'End If

      If orderParameterBillSystemData.Count > 0 Then
            Select Case formType
                Case "應收請款核准單"
                    If orderParameterFixedData.ContainsKey("accountsPayableVoucherApprovalFormCPID") Then
                        searchFields("codingPrinciple") = orderParameterFixedData("accountsPayableVoucherApprovalFormCPID")
                    End If
                Case "應收請款紀錄單"
                    If orderParameterFixedData.ContainsKey("accountsReceivableBillingVoucherCPID") Then
                        searchFields("codingPrinciple") = orderParameterFixedData("accountsReceivableBillingVoucherCPID")
                    End If
                Case "付款憑單"
                    If orderParameterFixedData.ContainsKey("paymentVoucherCPID") Then
                        searchFields("codingPrinciple") = orderParameterFixedData("paymentVoucherCPID")
                    End If
                Case "收款憑單"
                    If orderParameterFixedData.ContainsKey("receiptVoucherCPID") Then
                        searchFields("codingPrinciple") = orderParameterFixedData("receiptVoucherCPID")
                    End If
                Case "佣金付款"
                    If orderParameterFixedData.ContainsKey("commissionPaymentVoucherCPID") Then
                        searchFields("codingPrinciple") = orderParameterFixedData("commissionPaymentVoucherCPID")
                    End If
            End Select
            ' 如果還有其他情況，可以在這裡添加更多 Case 分支
        End If
```
## 參數系統UI
![image](https://hackmd.io/_uploads/S17ysmUt0.png)
### 參數系統程式碼
編碼系統 所需要宣告的物件 fieldDictionary 用來儲存置資料庫
```vb
    Private ReadOnly _firebaseHelper As FirebaseHelper = FirebaseHelper.Instance
    Dim fieldDictionary As New Dictionary(Of String, Object)
```
#### 抓取CPID SpecialValue
CPID中文名稱 必須對應CodingPrincipleSetting 所設置的值
此Function 是根據CPID透過CodingPrincipleSetting來查詢，最後會得到SpecialValue (參數編碼不會紀錄SpecialValue 是透過查詢顯示)
| Case                           | Field                                           | 
|--------------------------------|-------------------------------------------------|
| "應收請款核准單"               | accountsPayableVoucherApprovalFormCPID          | _resultCodePrincipleString   |
| "應收請款紀錄單"               | accountsReceivableBillingVoucherCPID            | _resultCodePrincipleString   |
| "付款憑單"                     | paymentVoucherCPID                              | _resultCodePrincipleString   |
| "收款憑單"                     | receiptVoucherCPID                              | _resultCodePrincipleString   |
| "佣金付款"                     | commissionPaymentVoucherCPID                    | _resultCodePrincipleString   |
```vb
     Private Sub UpdateCodePrincipleUI(principleType As String, fieldDictionary As Dictionary(Of String, Object))
        Dim searchFields As New Dictionary(Of String, Object)()
        If (principleType = "應收請款核准單" And fieldDictionary.ContainsKey("accountsPayableVoucherApprovalFormCPID")) Then searchFields("codingPrinciple") = fieldDictionary("accountsPayableVoucherApprovalFormCPID")
        If (principleType = "應收請款紀錄單" And fieldDictionary.ContainsKey("accountsReceivableBillingVoucherCPID")) Then searchFields("codingPrinciple") = fieldDictionary("accountsReceivableBillingVoucherCPID")
        If (principleType = "付款憑單" And fieldDictionary.ContainsKey("paymentVoucherCPID")) Then searchFields("codingPrinciple") = fieldDictionary("paymentVoucherCPID")
        If (principleType = "收款憑單" And fieldDictionary.ContainsKey("receiptVoucherCPID")) Then searchFields("codingPrinciple") = fieldDictionary("outsourcedMaterialDeliveryCPID")
        If (principleType = "佣金付款" And fieldDictionary.ContainsKey("commissionPaymentVoucherCPID")) Then searchFields("codingPrinciple") = fieldDictionary("commissionPaymentVoucherCPID")


        searchFields("principleType") = principleType
        ' 調用函數查找文檔的 ID
        Dim documentId As String = _firebaseHelper.FindDocumentIdByFields("CodingPrincipleSetting", searchFields)
        Dim codingPrincipleSettingData
        If documentId.Length > 0 Then
            codingPrincipleSettingData = _firebaseHelper.GetDocumentDataById("CodingPrincipleSetting", documentId)
            '將介面的物件賦值
            Select Case principleType
                Case "應收請款核准單"
                    accountsPayableVoucherApprovalFormCPID.Text = fieldDictionary("accountsPayableVoucherApprovalFormCPID")
                    accountsPayableVoucherApprovalFormCPID_SpecialValue.Text = codingPrincipleSettingData("specialValue")
                Case "應收請款紀錄單"
                    accountsReceivableBillingVoucherCPID.Text = fieldDictionary("accountsReceivableBillingVoucherCPID")
                    accountsReceivableBillingVoucherCPID_SpecialValue.Text = codingPrincipleSettingData("specialValue")
                Case "付款憑單"
                    paymentVoucherCPID.Text = fieldDictionary("paymentVoucherCPID")
                    paymentVoucherCPID_SpecialValue.Text = codingPrincipleSettingData("specialValue")
                Case "收款憑單"
                    receiptVoucherCPID.Text = fieldDictionary("receiptVoucherCPID")
                    receiptVoucherCPID_SpecialValue.Text = codingPrincipleSettingData("specialValue")
                Case "佣金付款"
                    commissionPaymentVoucherCPID.Text = fieldDictionary("commissionPaymentVoucherCPID")
                    commissionPaymentVoucherCPID_SpecialValue.Text = codingPrincipleSettingData("specialValue")
            End Select
        End If
    End Sub
```
#### 各項Btn.Click
![image](https://hackmd.io/_uploads/BJX754IFA.png)
根據已命名的編碼，這邊可透過格式化的方式用GenAI幫我們生成 不多闡述

```vb
 Private Sub accountsPayableVoucherApprovalFormCPIDSettingBtn_Click(sender As Object, e As EventArgs) Handles accountsPayableVoucherApprovalFormCPIDSettingBtn.Click
        Dim codingPrincipleSetting As New CodingPrincipleSetting("應收請款核准單")
        Dim result As DialogResult = codingPrincipleSetting.ShowDialog()

        ' 根據結果處理相應邏輯
        If result = DialogResult.OK Then
            accountsPayableVoucherApprovalFormCPID.Text = codingPrincipleSetting.ResultString
            accountsPayableVoucherApprovalFormCPID_SpecialValue.Text = codingPrincipleSetting.ResultSpecialValue
        End If
    End Sub

    Private Sub accountsReceivableBillingVoucherCPIDSettingBtn_Click(sender As Object, e As EventArgs) Handles accountsReceivableBillingVoucherCPIDSettingBtn.Click
        Dim codingPrincipleSetting As New CodingPrincipleSetting("應收請款紀錄單")
        Dim result As DialogResult = codingPrincipleSetting.ShowDialog()

        ' 根據結果處理相應邏輯
        If result = DialogResult.OK Then
            accountsReceivableBillingVoucherCPID.Text = codingPrincipleSetting.ResultString
            accountsReceivableBillingVoucherCPID_SpecialValue.Text = codingPrincipleSetting.ResultSpecialValue
        End If
    End Sub

    Private Sub paymentVoucherCPIDSettingBtn_Click(sender As Object, e As EventArgs) Handles paymentVoucherCPIDSettingBtn.Click
        Dim codingPrincipleSetting As New CodingPrincipleSetting("付款憑單")
        Dim result As DialogResult = codingPrincipleSetting.ShowDialog()

        ' 根據結果處理相應邏輯
        If result = DialogResult.OK Then
            paymentVoucherCPID.Text = codingPrincipleSetting.ResultString
            paymentVoucherCPID_SpecialValue.Text = codingPrincipleSetting.ResultSpecialValue
        End If
    End Sub

    Private Sub outsourcedMaterialDeliveryCPIDSettingBtn_Click(sender As Object, e As EventArgs) Handles outsourcedMaterialDeliveryCPIDSettingBtn.Click
        Dim codingPrincipleSetting As New CodingPrincipleSetting("佣金付款")
        Dim result As DialogResult = codingPrincipleSetting.ShowDialog()

        ' 根據結果處理相應邏輯
        If result = DialogResult.OK Then
            commissionPaymentVoucherCPID.Text = codingPrincipleSetting.ResultString
            commissionPaymentVoucherCPID_SpecialValue.Text = codingPrincipleSetting.ResultSpecialValue
        End If
    End Sub
```
#### 儲存到資料庫
注意這邊要使用 UpdateDocument 因為表單唯一，文件ID賦予"1"
```vb
      fieldDictionary("accountsPayableVoucherApprovalFormCPID") = accountsPayableVoucherApprovalFormCPID.Text
        fieldDictionary("accountsReceivableBillingVoucherCPID") = accountsReceivableBillingVoucherCPID.Text
        fieldDictionary("paymentVoucherCPID") = paymentVoucherCPID.Text
        fieldDictionary("receiptVoucherCPID") = receiptVoucherCPID.Text
        fieldDictionary("commissionPaymentVoucherCPID") = commissionPaymentVoucherCPID.Text
        _firebaseHelper.UpdateDocument("BillingSystemParameterSetting", "1", fieldDictionary)
        MessageBox.Show("修改成功！", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
```
#### 讀取載入參數表單
_firebaseHelper.DocumentExists("BillingSystemParameterSetting", "1") 先判斷表單是否存在才進行讀取，否則會報錯
```vb
    Private Sub BillingSystemParameterSetting_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If (_firebaseHelper.DocumentExists("BillingSystemParameterSetting", "1")) Then
            LoadUIData()
        End If
    End Sub
```
 LoadUIData() 呼叫UpdateCodePrincipleUI 來顯示SpecialValue
```vb
    Private Sub LoadUIData()
        Try
            fieldDictionary = _firebaseHelper.GetDocumentDataById("BillingSystemParameterSetting", "1")
            accountsPayableVoucherApprovalFormCPID.Text = fieldDictionary("accountsPayableVoucherApprovalFormCPID")
            accountsReceivableBillingVoucherCPID.Text = fieldDictionary("accountsReceivableBillingVoucherCPID")
            paymentVoucherCPID.Text = fieldDictionary("paymentVoucherCPID")
            receiptVoucherCPID.Text = fieldDictionary("receiptVoucherCPID")
            commissionPaymentVoucherCPID.Text = fieldDictionary("commissionPaymentVoucherCPID")
            UpdateCodePrincipleUI("應收請款核准單", fieldDictionary)
            UpdateCodePrincipleUI("應收請款紀錄單", fieldDictionary)
            UpdateCodePrincipleUI("付款憑單", fieldDictionary)
            UpdateCodePrincipleUI("收款憑單", fieldDictionary)
            UpdateCodePrincipleUI("佣金付款", fieldDictionary)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

```
# 點選會計科目
---
![image](https://hackmd.io/_uploads/rkuhjfIK0.png)


```vb
    Private Sub 你的科目Code_KeyDown(sender As Object, e As KeyEventArgs) Handles 你的科目Code.KeyDown
        If e.KeyCode = Keys.Enter Then
            Dim thisTextBox = DirectCast(sender, TextBox)
            Dim content = $"{thisTextBox.Name}Name".Replace("Code", "")
            Dim thisTextBoxContent = DirectCast(Me.Controls.Find(content, True).FirstOrDefault(), TextBox)
            Dim getDictionary = AccountingLedgerSingleItemLookup.Search(thisTextBox.Text)

            If getDictionary("accountingCode") = "" Then
                MessageBox.Show("查無會計科目編號，請重新輸入！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
            LoadAccountingSingleItem(getDictionary, thisTextBox, thisTextBoxContent)
        End If
    End Sub

```
雙擊速查會計科目
---
```vb
  Private Sub 你的科目Code_DoubleClick(sender As Object, e As EventArgs) Handles 你的科目Code.DoubleClick, 
        Dim result As DialogResult = AccountingLedgerSingleItemLookup.ShowDialog()
        Try
            If result = DialogResult.OK Then
                Dim thisTextBox = DirectCast(sender, TextBox)
                Dim content = $"{thisTextBox.Name}Name".Replace("Code", "")
                Dim thisTextBoxContent = DirectCast(Me.Controls.Find(content, True).FirstOrDefault(), TextBox)
                Dim getDictionary = AccountingLedgerSingleItemLookup.GetResultOfSingleItemLookup()
                LoadAccountingSingleItem(getDictionary, thisTextBox, thisTextBoxContent)
            End If
        Catch ex As Exception

        End Try
    End Sub
```

載入科目函式
---
```vb
   Private Sub LoadAccountingSingleItem(getDictionary As Dictionary(Of String, String), NowTextBox As TextBox, Content As TextBox)
        Dim getColumnNameMapping() As String = {"accountingCode", "accountingName"}

        Dim showDataOfTextBox() As TextBox = {NowTextBox, Content}
        For index As Integer = 0 To getColumnNameMapping.Count() - 1
            showDataOfTextBox(index).Text = getDictionary(getColumnNameMapping(index))
        Next
    End Sub
```
檢視模式時載入科目
---
在載入畫面時呼叫LoadAccountingName()，textBoxes()為你的科目Code
```vb!
 Private Sub LoadAccountingName()
    Dim textBoxes() As TextBox = {你的TextBoxes....}
        For Each thisTextBox As TextBox In textBoxes
            Dim content = $"{thisTextBox.Name}Name".Replace("Code", "")
            Dim thisTextBoxContent = DirectCast(Me.Controls.Find(content, True).FirstOrDefault(), TextBox)
            Dim getDictionary = New AccountingLedgerSingleItemLookup().Search(thisTextBox.Text)
            If getDictionary("accountingCode") = "" Then
                Return
            End If
            LoadAccountingSingleItem(getDictionary, thisTextBox, thisTextBoxContent)
        Next
    End Sub
```
# 數值格式設定
處理小數後幾位和千位逗號
```vb
 ' 處理 quantityFormatCheckbox 的選項變更事件
Private Sub quantityFormatCheckbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles quantityFormatCheckbox.SelectedIndexChanged
    ' 移除 quantityFormat.Text 中小數點後的部分
    quantityFormat.Text = RemoveAfterDot(quantityFormat.Text)
    ' 如果選中的索引大於 0，則在文本中添加小數點後的數字
    If quantityFormatCheckbox.SelectedIndex > 0 Then
        quantityFormat.Text &= "." & GenerateString(quantityFormatCheckbox.SelectedIndex)
    End If
End Sub

' 處理 unitPriceFormatCheckbox 的選項變更事件
Private Sub unitPriceFormatCheckbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles unitPriceFormatCheckbox.SelectedIndexChanged
    ' 移除 unitPriceFormat.Text 中小數點後的部分
    unitPriceFormat.Text = RemoveAfterDot(unitPriceFormat.Text)
    ' 如果選中的索引大於 0，則在文本中添加小數點後的數字
    If unitPriceFormatCheckbox.SelectedIndex > 0 Then
        unitPriceFormat.Text &= "." & GenerateString(unitPriceFormatCheckbox.SelectedIndex)
    End If
End Sub

' 處理 priceFormatCheckbox 的選項變更事件
Private Sub priceFormatCheckbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles priceFormatCheckbox.SelectedIndexChanged
    ' 移除 priceFormat.Text 中小數點後的部分
    priceFormat.Text = RemoveAfterDot(priceFormat.Text)
    ' 如果選中的索引大於 0，則在文本中添加小數點後的數字
    If priceFormatCheckbox.SelectedIndex > 0 Then
        priceFormat.Text &= "." & GenerateString(priceFormatCheckbox.SelectedIndex)
    End If
End Sub

' 處理 isQuantityFormatUseComma 的勾選變更事件
Private Sub isQuantityFormatUseComma_CheckedChanged(sender As Object, e As EventArgs) Handles isQuantityFormatUseComma.CheckedChanged
    ' 如果使用公司參數設定，則轉換為帶逗號格式，否則移除逗號
    If isUseCompanyParameterSettings.Checked Then
        quantityFormat.Text = DoubleToComma(quantityFormat.Text)
    Else
        quantityFormat.Text = quantityFormat.Text.Replace(",", "")
    End If
End Sub

' 處理 isUnitPriceFormatUseComma 的勾選變更事件
Private Sub isUnitPriceFormatUseComma_CheckedChanged(sender As Object, e As EventArgs) Handles isUnitPriceFormatUseComma.CheckedChanged
    ' 如果勾選，則轉換為帶逗號格式，否則移除逗號
    If isUnitPriceFormatUseComma.Checked Then
        unitPriceFormat.Text = DoubleToComma(unitPriceFormat.Text)
    Else
        unitPriceFormat.Text = unitPriceFormat.Text.Replace(",", "")
    End If
End Sub

' 處理 isPriceFormatUseComma 的勾選變更事件
Private Sub isPriceFormatUseComma_CheckedChanged(sender As Object, e As EventArgs) Handles isPriceFormatUseComma.CheckedChanged
    ' 如果勾選，則轉換為帶逗號格式，否則移除逗號
    If isPriceFormatUseComma.Checked Then
        priceFormat.Text = DoubleToComma(priceFormat.Text)
    Else
        priceFormat.Text = priceFormat.Text.Replace(",", "")
    End If
End Sub

' 處理 isExchangeRateFormatUseComma 的勾選變更事件
Private Sub isExchangeRateFormatUseComma_CheckedChanged(sender As Object, e As EventArgs)
    ' 如果勾選，則轉換為帶逗號格式，否則移除逗號
    If isUnitFormatUseComma.Checked Then
        unitFormat.Text = DoubleToComma(unitFormat.Text)
    Else
        unitFormat.Text = unitFormat.Text.Replace(",", "")
    End If
End Sub

' 將數字字符串轉換為帶逗號格式的字符串
Private Function DoubleToComma(inputString As String) As String
    ' 將輸入字符串轉換為 Double 類型
    Dim convertString As Double = Double.Parse(inputString)
    ' 返回帶有千位逗號的格式字符串
    Return $"{convertString:#,#0.##############}"
End Function

' 移除字符串中的小數點及其後的部分
Private Function RemoveAfterDot(inputString As String) As String
    ' 獲取小數點的索引
    Dim indexOfDot As Integer = inputString.IndexOf("."c)
    ' 如果存在小數點，則返回小數點前的部分，否則返回原字符串
    If indexOfDot >= 0 Then
        Return inputString.Substring(0, indexOfDot)
    Else
        Return inputString
    End If
End Function

' 生成指定長度的數字字符串
Private Function GenerateString(number As Integer) As String
    ' 生成從 1 到 number 的數字字符串
    Return String.Concat(Enumerable.Range(1, number).Select(Function(i) i.ToString()))
End Function


```