Imports Telerik.WinForms.Documents.FormatProviders.OpenXml.Docx Imports Telerik.WinForms.Documents.Model Imports Telerik.WinForms.Documents Imports Telerik.WinControls.UI Imports System.IO Public Class 合約文本_Word Dim 放大, 存檔判斷 As Boolean Dim 選取位置, 選取位置1, 暫存數量 As Integer Dim 下載檔案位置, 文件資料庫指定, 已存檔文件所在, HH As String Dim RI As Integer = -1 Dim SK As String = "要查找的 KEY" Dim Str As String = Application.StartupPath Dim 對話框(21), 暫存檔(999) As String Private Sub Set_合約清單() Dim ds6 As New DataSet 合約_dgv.DataSource = Nothing : ds6.Clear() 合約_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 合約_dgv.ColumnHeadersHeight = 25 : 合約_dgv.AllowUserToAddRows = False PA46 = 合約編號1_cb.Text SQL_合約清單_文本() da.Fill(ds6) : 合約_dgv.DataSource = ds6.Tables(0) : conn.Close() 合約_dgv.Columns(0).FillWeight = 100 : 合約_dgv.Columns(3).FillWeight = 250 : 合約_dgv.Columns(2).FillWeight = 250 : 合約_dgv.Columns(7).FillWeight = 20 合約_dgv.Columns(0).ReadOnly = True : 合約_dgv.Columns(2).ReadOnly = True : 合約_dgv.Columns(3).ReadOnly = True 合約_dgv.Columns(1).Visible = False : 合約_dgv.Columns(4).Visible = False : 合約_dgv.Columns(5).Visible = False 合約_dgv.Columns(6).Visible = False : 合約_dgv.Columns(8).Visible = False For i As Integer = 0 To 合約_dgv.Rows.Count - 1 If 合約_dgv("合約存放", i).Value.ToString = "" Then : 合約_dgv("C", i).Value = False : Else : 合約_dgv("C", i).Value = True : End If Next If 放大 = True Then If 系統語言 = "繁體中文" Then : 合約_dgv.Columns("工程名稱_中").Visible = True : Else : 合約_dgv.Columns("工程名稱_英").Visible = True : End If Else 合約_dgv.Columns("工程名稱_中").Visible = False : 合約_dgv.Columns("工程名稱_英").Visible = False End If End Sub Private Sub Set_範本清單() Dim ds6 As New DataSet 範本清單_dgv.DataSource = Nothing : ds6.Clear() 範本清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 範本清單_dgv.ColumnHeadersHeight = 25 : 範本清單_dgv.AllowUserToAddRows = False 圖片庫 = "HX-PGS-FILE1-SYS" : SQL_連線字串_圖片資料庫() : SQL_合約範本清單() da.Fill(ds6) : 範本清單_dgv.DataSource = ds6.Tables(0) : conn.Close() 範本清單_dgv.Columns(0).FillWeight = 100 : 範本清單_dgv.Columns(1).FillWeight = 100 End Sub Private Sub 甲方條件下拉清單讀取() SQL合約條件讀取() : 合約編號1_cb.Items.Clear() : 合約編號1_cb.Items.Add("") : While (dr.Read()) : 合約編號1_cb.Items.Add(dr("約號甲方")) : End While : conn.Close() End Sub Private Sub Set_語言() 語言_dgv.DataSource = Nothing 語言_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing 語言_dgv.ColumnHeadersHeight = 25 : 語言_dgv.AllowUserToAddRows = False For i As Integer = 0 To 語言_dgv.Rows.Count - 1 : 語言_dgv.Rows.RemoveAt(0) : Next If File.Exists(Str + "\LANGUAGE_FILE.csv") Then Dim filereader = My.Computer.FileSystem.OpenTextFileReader(Str + "\LANGUAGE_FILE.csv", System.Text.Encoding.Default) Dim line As String = filereader.ReadLine() While Not (line Is Nothing) line = filereader.ReadLine() If line <> Nothing Then line = line.Replace("""", "") If Strings.Left(line, 4) = "G000" Or Strings.Left(line, 8) = "H001-128" Or Strings.Left(line, 4) = 介面 Then If 系統語言 = "繁體中文" Then If Strings.Mid(line, 10, 2) = "CH" Then : 語言_dgv.Rows.Insert(0) 語言_dgv.Rows(0).Cells(0).Value = Strings.Left(line, 11) If Strings.Mid(line, 13, 300).EndsWith(",") Then 語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300).Substring(0, Strings.Mid(line, 13, 300).Length - 1) Else : 語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300) : End If End If ElseIf 系統語言 = "English" Then If Strings.Mid(line, 10, 2) = "EN" Then : 語言_dgv.Rows.Insert(0) 語言_dgv.Rows(0).Cells(0).Value = Strings.Left(line, 11) If Strings.Mid(line, 13, 300).EndsWith(",") Then 語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300).Substring(0, Strings.Mid(line, 13, 300).Length - 1) Else : 語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300) : End If End If ElseIf 系統語言 = "Indonesian" Then If Strings.Mid(line, 10, 2) = "IN" Then : 語言_dgv.Rows.Insert(0) 語言_dgv.Rows(0).Cells(0).Value = Strings.Left(line, 11) If Strings.Mid(line, 13, 300).EndsWith(",") Then 語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300).Substring(0, Strings.Mid(line, 13, 300).Length - 1) Else : 語言_dgv.Rows(0).Cells(1).Value = Strings.Mid(line, 13, 300) : End If End If End If End If End If End While filereader.Close() End If End Sub Private Sub Set_語言查詢() RI = -1 : For Each row As DataGridViewRow In 語言_dgv.Rows If Strings.Left(row.Cells(0).Value.ToString(), 8) = SK Then RI = row.Index : Exit For End If Next End Sub Private Sub 語言轉換讀取() Set_語言() SK = "H001-128" : Set_語言查詢() : Me.Text = 語言_dgv(1, RI).Value.ToString : SK = "G000-108" : Set_語言查詢() : ToolTip1.ToolTipTitle = 語言_dgv(1, RI).Value.ToString SK = "H116-100" : Set_語言查詢() : 對話框(0) = 語言_dgv(1, RI).Value.ToString : SK = "H116-101" : Set_語言查詢() : 對話框(1) = 語言_dgv(1, RI).Value.ToString SK = "H116-102" : Set_語言查詢() : 對話框(2) = 語言_dgv(1, RI).Value.ToString : SK = "H116-103" : Set_語言查詢() : 對話框(3) = 語言_dgv(1, RI).Value.ToString SK = "H116-104" : Set_語言查詢() : 對話框(4) = 語言_dgv(1, RI).Value.ToString : SK = "G000-151" : Set_語言查詢() : 對話框(5) = 語言_dgv(1, RI).Value.ToString SK = "H116-105" : Set_語言查詢() : 高級編輯_lb.Text = 語言_dgv(1, RI).Value.ToString : SK = "H116-106" : Set_語言查詢() : 對話框(6) = 語言_dgv(1, RI).Value.ToString SK = "H116-108" : Set_語言查詢() : 範本_ch.Text = 語言_dgv(1, RI).Value.ToString : SK = "H116-110" : Set_語言查詢() : 對話框(7) = 語言_dgv(1, RI).Value.ToString SK = "H116-109" : Set_語言查詢() : 舊合約_ch.Text = 語言_dgv(1, RI).Value.ToString : SK = "H116-111" : Set_語言查詢() : 表頭(1) = 語言_dgv(1, RI).Value.ToString SK = "G000-119" : Set_語言查詢() : 對話框(8) = 語言_dgv(1, RI).Value.ToString : SK = "H116-112" : Set_語言查詢() : 對話框(9) = 語言_dgv(1, RI).Value.ToString SK = "G000-112" : Set_語言查詢() : 對話框(10) = 語言_dgv(1, RI).Value.ToString : SK = "G000-124" : Set_語言查詢() : 對話框(11) = 語言_dgv(1, RI).Value.ToString SK = "G000-152" : Set_語言查詢() : 對話框(12) = 語言_dgv(1, RI).Value.ToString : SK = "G000-120" : Set_語言查詢() : 對話框(13) = 語言_dgv(1, RI).Value.ToString SK = "G000-153" : Set_語言查詢() : 對話框(14) = 語言_dgv(1, RI).Value.ToString : SK = "G000-154" : Set_語言查詢() : 對話框(15) = 語言_dgv(1, RI).Value.ToString SK = "H116-113" : Set_語言查詢() : 對話框(16) = 語言_dgv(1, RI).Value.ToString : SK = "G000-110" : Set_語言查詢() : 對話框(17) = 語言_dgv(1, RI).Value.ToString SK = "H116-114" : Set_語言查詢() : 對話框(18) = 語言_dgv(1, RI).Value.ToString : SK = "H116-115" : Set_語言查詢() : 對話框(19) = 語言_dgv(1, RI).Value.ToString SK = "H116-116" : Set_語言查詢() : 自動存檔_ch.Text = 語言_dgv(1, RI).Value.ToString : SK = "G000-101" : Set_語言查詢() : 對話框(20) = 語言_dgv(1, RI).Value.ToString SK = "H116-117" : Set_語言查詢() : 對話框(21) = 語言_dgv(1, RI).Value.ToString SK = "H116-107" : Set_語言查詢() : 範本名稱_lb.Text = 語言_dgv(1, RI).Value.ToString : 表頭(0) = 語言_dgv(1, RI).Value.ToString End Sub Private Sub 取消_bt_MouseEnter(sender As Object, e As EventArgs) Handles 取消_bt.MouseEnter ToolTip1.SetToolTip(Me.取消_bt, 對話框(20)) End Sub Private Sub 更新合約_bt_MouseEnter(sender As Object, e As EventArgs) Handles 更新合約_bt.MouseEnter ToolTip1.SetToolTip(Me.更新合約_bt, 對話框(21)) End Sub Private Sub 刪除範本_bt_MouseEnter(sender As Object, e As EventArgs) Handles 刪除範本_bt.MouseEnter ToolTip1.SetToolTip(Me.刪除範本_bt, 對話框(10)) End Sub Private Sub 導入word_bt_MouseEnter(sender As Object, e As EventArgs) Handles 導入word_bt.MouseEnter ToolTip1.SetToolTip(Me.導入word_bt, 對話框(1)) End Sub Private Sub 輸出word_bt_MouseEnter(sender As Object, e As EventArgs) Handles 輸出word_bt.MouseEnter ToolTip1.SetToolTip(Me.輸出word_bt, 對話框(2)) End Sub Private Sub 編輯_bt_MouseEnter(sender As Object, e As EventArgs) Handles 編輯_bt.MouseEnter ToolTip1.SetToolTip(Me.編輯_bt, 對話框(3)) End Sub Private Sub 讀取範本_bt_MouseEnter(sender As Object, e As EventArgs) Handles 讀取範本_bt.MouseEnter ToolTip1.SetToolTip(Me.讀取範本_bt, 對話框(4)) End Sub Private Sub 縮放2_bt_MouseEnter(sender As Object, e As EventArgs) Handles 縮放2_bt.MouseEnter ToolTip1.SetToolTip(Me.縮放2_bt, 對話框(5)) End Sub Private Sub 範本存檔_bt_MouseEnter(sender As Object, e As EventArgs) Handles 範本存檔_bt.MouseEnter ToolTip1.SetToolTip(Me.範本存檔_bt, 對話框(6)) End Sub Private Sub 存檔_bt_MouseEnter(sender As Object, e As EventArgs) Handles 存檔_bt.MouseEnter ToolTip1.SetToolTip(Me.存檔_bt, 對話框(17)) End Sub Private Sub 合約文本_Word_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.MdiParent = HX_PGS_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True H(116) = True : 介面 = "H116" : 語言轉換讀取() : 顯示說明(999, False) 舊合約_ch.Checked = True : 合約狀態_tb.Text = "合約" : 圖片庫 = "" : 視窗2_pl.Visible = False : 放大 = False : Panel1.SendToBack() Word控制項.Enabled = False : Word文本框.Enabled = False : 語轉扭_bt.Enabled = True If CC(101) = True Then : 編輯_bt.Enabled = True : 自動存檔_ch.Enabled = True : Else : 編輯_bt.Enabled = False : 自動存檔_ch.Enabled = False : End If If CC(102) = True Then : 存檔_bt.Enabled = True : Else : 存檔_bt.Enabled = False : End If End Sub Private Sub 合約文本_Word_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown SQL_文件資料庫查詢() If dr.Read() Then : 文件資料庫指定 = dr("工程文件資料庫") : Else : MGB(對話框(15), 1) : Me.Close() : End If 計算分流.Enabled = True End Sub Private Sub 計算分流_Tick(sender As Object, e As EventArgs) Handles 計算分流.Tick 計算分流.Enabled = False Telerik.WinControls.ThemeResolutionService.LoadPackageFile(".\Theme\TelerikMetro_Chinese.tssp") Word控制項.CommandTabs.Item(0).PerformClick() Word控制項.ThemeName = "TelerikMetro_Chinese" Word文本框.ThemeName = "TelerikMetro_Chinese" '--------------移除多餘控件------------------------------- Word控制項.BackstageControl.BackstageElement.Items(0).Visibility = Telerik.WinControls.ElementVisibility.Collapsed Word控制項.BackstageControl.BackstageElement.Items(1).Visibility = Telerik.WinControls.ElementVisibility.Collapsed Word控制項.BackstageControl.BackstageElement.Items(4).Visibility = Telerik.WinControls.ElementVisibility.Collapsed Word控制項.QuickAccessToolBar.Items(0).Visibility = Telerik.WinControls.ElementVisibility.Collapsed Dim saveAsItem As BackstageTabItem = Word控制項.BackstageControl.Items("backstageTabItemSaveAs") Dim page As BackstageViewPage = saveAsItem.Page page.Controls(0).Controls(0).Visible = False : page.Controls(0).Controls(1).Visible = False page.Controls(0).Controls(2).Visible = False : page.Controls(0).Controls(3).Visible = False page.Controls(0).Controls(4).Visible = False : page.Controls(0).Controls(5).Visible = False '--------------------------------------------------------- 甲方條件下拉清單讀取() : Set_合約清單() : Set_範本清單() : 首次開啟 = False End Sub Private Sub 合約文本_Word_Closed(sender As Object, e As EventArgs) Handles MyBase.Closing If 存檔判斷 = True Then If CC(102) = True Then If 下載檔案位置 <> "" Then If 已存檔文件所在 <> "" Then MGB(對話框(19), 2) If 訊息回應 = "YES" Then : 存檔() : MGB(對話框(8), 1) Else : End If Else : 存檔() : End If End If End If End If For I As Integer = 0 To 暫存數量 If 暫存檔(I) <> "" Then : If File.Exists(暫存檔(I)) Then : File.Delete(暫存檔(I)) : End If : End If : 暫存檔(I) = "" Next MyMod.虛擬桌面開啟() End Sub Private Sub 範本清單_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 範本清單_dgv.CellClick If e.RowIndex = -1 Then : Else If 下載檔案位置 <> "" Then : If File.Exists(下載檔案位置) Then : File.Delete(下載檔案位置) : End If : End If : 下載檔案位置 = "" 合約名稱_tb.Text = 範本清單_dgv(0, e.RowIndex).Value.ToString 圖片庫 = "HX-PGS-FILE1-SYS" : SQL_連線字串_圖片資料庫() 範本_ch.Checked = True : 舊合約_ch.Checked = False : 合約狀態_tb.Text = "範本" Dim Str As String = Application.StartupPath : Dim ds1 As New DataSet PA1 = 合約名稱_tb.Text : PA2 = 合約狀態_tb.Text : ds1.Clear() : SQL_合約本文下載() : da.Fill(ds1) 下載檔案位置 = Str + "\" & PA1 & ".docx" : 暫存檔(暫存數量) = 下載檔案位置 : 暫存數量 += 1 If 下載檔案位置 <> "" Then : If File.Exists(下載檔案位置) Then : File.Delete(下載檔案位置) : End If : End If If ds1.Tables(0).Rows.Count > 0 Then Dim imgData() As Byte : imgData = ds1.Tables(0).Rows(0).Item("文檔") Dim fs As FileStream : fs = File.Create(Str + "\" & PA1 & ".docx", imgData.Length - 1) fs.Write(imgData, 0, imgData.Length - 1) : fs.Close() End If : conn.Close() 下載檔案位置 = Str + "\" & PA1 & ".docx" : 暫存檔(暫存數量) = 下載檔案位置 : 暫存數量 += 1 If 下載檔案位置 = "" Then : Else Word控制項.Enabled = True : Word文本框.Enabled = True Dim provider As DocxFormatProvider = New DocxFormatProvider() Dim input As Byte() = File.ReadAllBytes(下載檔案位置) Word文本框.Document = provider.Import(input) End If End If End Sub Private Sub 合約計算() Dim 確認 As Boolean = False If 合約_dgv("工程總價", 選取位置).Value.ToString = "" Then GA10.Text = InputBox("請輸入稅金比 例如 : 10 、11") If IsNumeric(GA10.Text) = True Then : 確認 = True : Else : MsgBox("請輸入數字") : 確認 = False : End If ElseIf 合約_dgv("內容", 選取位置).Value.ToString = "稅金 5% Tax" Then : GA10.Text = "5" : 確認 = True ElseIf 合約_dgv("內容", 選取位置).Value.ToString = "稅金 10% Tax" Then : GA10.Text = "10" : 確認 = True ElseIf 合約_dgv("內容", 選取位置).Value.ToString = "稅金 11% Tax" Then : GA10.Text = "11" : 確認 = True End If If 確認 = True Then GA8.Text = (CLng(合約_dgv("工程總價", 選取位置).Value.ToString) / (CLng(GA10.Text) + 100)) * CLng(GA10.Text) : GA7.Text = CLng(GA9.Text) - CLng(GA8.Text) GA11.Text = CLng(GA9.Text) / 100 * 40 : GA12.Text = CLng(GA9.Text) / 100 * 35 : GA13.Text = CLng(GA9.Text) / 100 * 30 : GA14.Text = CLng(GA9.Text) / 100 * 25 GA15.Text = CLng(GA9.Text) / 100 * 20 : GA16.Text = CLng(GA9.Text) / 100 * 15 : GA17.Text = CLng(GA9.Text) / 100 * 10 : GA18.Text = CLng(GA9.Text) / 100 * 5 GA19.Text = CLng(GA7.Text) / 100 * 40 : GA20.Text = CLng(GA7.Text) / 100 * 35 : GA21.Text = CLng(GA7.Text) / 100 * 30 : GA22.Text = CLng(GA7.Text) / 100 * 25 GA23.Text = CLng(GA7.Text) / 100 * 20 : GA24.Text = CLng(GA7.Text) / 100 * 15 : GA25.Text = CLng(GA7.Text) / 100 * 10 : GA26.Text = CLng(GA7.Text) / 100 * 5 Dim SSA As Integer GA7.Text = Strings.Format(CLng(GA7.Text), "###0") : SSA = Len(GA7.Text) If SSA < 4 Then : GA7.Text = GA7.Text & "," ElseIf SSA < 7 Then : GA7.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA7.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA7.Text), 3)) & "," ElseIf SSA < 10 Then : GA7.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA7.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA7.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA7.Text), 3)) & "," ElseIf SSA < 13 Then : GA7.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA7.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA7.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA7.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA7.Text), 3)) & "," End If GA8.Text = Strings.Format(CLng(GA8.Text), "###0") : SSA = Len(GA8.Text) If SSA < 4 Then : GA8.Text = GA8.Text & "," ElseIf SSA < 7 Then : GA8.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA8.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA8.Text), 3)) & "," ElseIf SSA < 10 Then : GA8.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA8.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA8.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA8.Text), 3)) & "," ElseIf SSA < 13 Then : GA8.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA8.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA8.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA8.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA8.Text), 3)) & "," End If GA9.Text = Strings.Format(CLng(GA9.Text), "###0") : SSA = Len(GA9.Text) If SSA < 4 Then : GA9.Text = GA9.Text & "," ElseIf SSA < 7 Then : GA9.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA9.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA9.Text), 3)) & "," ElseIf SSA < 10 Then : GA9.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA9.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA9.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA9.Text), 3)) & "," ElseIf SSA < 13 Then : GA9.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA9.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA9.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA9.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA9.Text), 3)) & "," End If GA11.Text = Strings.Format(CLng(GA11.Text), "###0") : SSA = Len(GA11.Text) If SSA < 4 Then : GA11.Text = GA11.Text & "," ElseIf SSA < 7 Then : GA11.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA11.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA11.Text), 3)) & "," ElseIf SSA < 10 Then : GA11.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA11.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA11.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA11.Text), 3)) & "," ElseIf SSA < 13 Then : GA11.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA11.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA11.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA11.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA11.Text), 3)) & "," End If GA12.Text = Strings.Format(CLng(GA12.Text), "###0") : SSA = Len(GA12.Text) If SSA < 4 Then : GA12.Text = GA12.Text & "," ElseIf SSA < 7 Then : GA12.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA12.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA12.Text), 3)) & "," ElseIf SSA < 10 Then : GA12.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA12.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA12.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA12.Text), 3)) & "," ElseIf SSA < 13 Then : GA12.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA12.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA12.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA12.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA12.Text), 3)) & "," End If GA13.Text = Strings.Format(CLng(GA13.Text), "###0") : SSA = Len(GA13.Text) If SSA < 4 Then : GA13.Text = GA13.Text & "," ElseIf SSA < 7 Then : GA13.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA13.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA13.Text), 3)) & "," ElseIf SSA < 10 Then : GA13.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA13.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA13.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA13.Text), 3)) & "," ElseIf SSA < 13 Then : GA13.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA13.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA13.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA13.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA13.Text), 3)) & "," End If GA14.Text = Strings.Format(CLng(GA14.Text), "###0") : SSA = Len(GA14.Text) If SSA < 4 Then : GA14.Text = GA14.Text & "," ElseIf SSA < 7 Then : GA14.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA14.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA14.Text), 3)) & "," ElseIf SSA < 10 Then : GA14.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA14.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA14.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA14.Text), 3)) & "," ElseIf SSA < 13 Then : GA14.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA14.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA14.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA14.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA14.Text), 3)) & "," End If GA15.Text = Strings.Format(CLng(GA15.Text), "###0") : SSA = Len(GA15.Text) If SSA < 4 Then : GA15.Text = GA15.Text & "," ElseIf SSA < 7 Then : GA15.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA15.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA15.Text), 3)) & "," ElseIf SSA < 10 Then : GA15.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA15.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA15.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA15.Text), 3)) & "," ElseIf SSA < 13 Then : GA15.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA15.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA15.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA15.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA15.Text), 3)) & "," End If GA16.Text = Strings.Format(CLng(GA16.Text), "###0") : SSA = Len(GA16.Text) If SSA < 4 Then : GA16.Text = GA16.Text & "," ElseIf SSA < 7 Then : GA16.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA16.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA16.Text), 3)) & "," ElseIf SSA < 10 Then : GA16.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA16.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA16.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA16.Text), 3)) & "," ElseIf SSA < 13 Then : GA16.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA16.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA16.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA16.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA16.Text), 3)) & "," End If GA17.Text = Strings.Format(CLng(GA17.Text), "###0") : SSA = Len(GA17.Text) If SSA < 4 Then : GA17.Text = GA17.Text & "," ElseIf SSA < 7 Then : GA17.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA17.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA17.Text), 3)) & "," ElseIf SSA < 10 Then : GA17.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA17.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA17.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA17.Text), 3)) & "," ElseIf SSA < 13 Then : GA17.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA17.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA17.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA17.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA17.Text), 3)) & "," End If GA18.Text = Strings.Format(CLng(GA18.Text), "###0") : SSA = Len(GA18.Text) If SSA < 4 Then : GA18.Text = GA18.Text & "," ElseIf SSA < 7 Then : GA18.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA18.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA18.Text), 3)) & "," ElseIf SSA < 10 Then : GA18.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA18.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA18.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA18.Text), 3)) & "," ElseIf SSA < 13 Then : GA18.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA18.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA18.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA18.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA18.Text), 3)) & "," End If GA19.Text = Strings.Format(CLng(GA19.Text), "###0") : SSA = Len(GA19.Text) If SSA < 4 Then : GA19.Text = GA19.Text & "," ElseIf SSA < 7 Then : GA19.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA19.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA19.Text), 3)) & "," ElseIf SSA < 10 Then : GA19.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA19.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA19.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA19.Text), 3)) & "," ElseIf SSA < 13 Then : GA19.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA19.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA19.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA19.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA19.Text), 3)) & "," End If GA20.Text = Strings.Format(CLng(GA20.Text), "###0") : SSA = Len(GA20.Text) If SSA < 4 Then : GA20.Text = GA20.Text & "," ElseIf SSA < 7 Then : GA20.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA20.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA20.Text), 3)) & "," ElseIf SSA < 10 Then : GA20.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA20.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA20.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA20.Text), 3)) & "," ElseIf SSA < 13 Then : GA20.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA20.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA20.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA20.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA20.Text), 3)) & "," End If GA21.Text = Strings.Format(CLng(GA21.Text), "###0") : SSA = Len(GA21.Text) If SSA < 4 Then : GA21.Text = GA21.Text & "," ElseIf SSA < 7 Then : GA21.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA21.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA21.Text), 3)) & "," ElseIf SSA < 10 Then : GA21.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA21.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA21.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA21.Text), 3)) & "," ElseIf SSA < 13 Then : GA21.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA21.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA21.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA21.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA21.Text), 3)) & "," End If GA22.Text = Strings.Format(CLng(GA22.Text), "###0") : SSA = Len(GA22.Text) If SSA < 4 Then : GA22.Text = GA22.Text & "," ElseIf SSA < 7 Then : GA22.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA22.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA22.Text), 3)) & "," ElseIf SSA < 10 Then : GA22.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA22.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA22.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA22.Text), 3)) & "," ElseIf SSA < 13 Then : GA22.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA22.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA22.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA22.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA22.Text), 3)) & "," End If GA23.Text = Strings.Format(CLng(GA23.Text), "###0") : SSA = Len(GA23.Text) If SSA < 4 Then : GA23.Text = GA23.Text & "," ElseIf SSA < 7 Then : GA23.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA23.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA23.Text), 3)) & "," ElseIf SSA < 10 Then : GA23.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA23.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA23.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA23.Text), 3)) & "," ElseIf SSA < 13 Then : GA23.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA23.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA23.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA23.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA23.Text), 3)) & "," End If GA24.Text = Strings.Format(CLng(GA24.Text), "###0") : SSA = Len(GA24.Text) If SSA < 4 Then : GA24.Text = GA24.Text & "," ElseIf SSA < 7 Then : GA24.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA24.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA24.Text), 3)) & "," ElseIf SSA < 10 Then : GA24.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA24.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA24.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA24.Text), 3)) & "," ElseIf SSA < 13 Then : GA24.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA24.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA24.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA24.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA24.Text), 3)) & "," End If GA25.Text = Strings.Format(CLng(GA25.Text), "###0") : SSA = Len(GA25.Text) If SSA < 4 Then : GA25.Text = GA25.Text & "," ElseIf SSA < 7 Then : GA25.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA25.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA25.Text), 3)) & "," ElseIf SSA < 10 Then : GA25.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA25.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA25.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA25.Text), 3)) & "," ElseIf SSA < 13 Then : GA25.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA25.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA25.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA25.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA25.Text), 3)) & "," End If GA26.Text = Strings.Format(CLng(GA26.Text), "###0") : SSA = Len(GA26.Text) If SSA < 4 Then : GA26.Text = GA26.Text & "," ElseIf SSA < 7 Then : GA26.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA26.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA26.Text), 3)) & "," ElseIf SSA < 10 Then : GA26.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA26.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA26.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA26.Text), 3)) & "," ElseIf SSA < 13 Then : GA26.Text = Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA26.Text), 10, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA26.Text), 7, 3)) & "." & Strings.StrReverse(Strings.Mid(Strings.StrReverse(GA26.Text), 4, 3)) & "." & Strings.StrReverse(Strings.Left(Strings.StrReverse(GA26.Text), 3)) & "," End If End If End Sub Private Sub 合約_dgv_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles 合約_dgv.CellClick If e.RowIndex = -1 Then : Else : 選取位置 = e.RowIndex : 選取位置1 = e.RowIndex GA1.Text = 合約_dgv("工程名稱_中", e.RowIndex).Value.ToString : GA2.Text = 合約_dgv("工程名稱_英", e.RowIndex).Value.ToString GA3.Text = 合約_dgv("合約編號", e.RowIndex).Value.ToString : GA9.Text = 合約_dgv("工程總價", e.RowIndex).Value.ToString GA4.Text = Strings.Left(合約_dgv("立約日期", e.RowIndex).Value.ToString, 4) : GA6.Text = Strings.Right(合約_dgv("立約日期", e.RowIndex).Value.ToString, 2) GA5.Text = Strings.Mid(合約_dgv("立約日期", e.RowIndex).Value.ToString, 6, 2) If GA5.Text = "01" Then : GA5.Text = "January" : ElseIf GA5.Text = "02" Then : GA5.Text = "February" : ElseIf GA5.Text = "03" Then : GA5.Text = "March" ElseIf GA5.Text = "04" Then : GA5.Text = "April" : ElseIf GA5.Text = "05" Then : GA5.Text = "May" : ElseIf GA5.Text = "06" Then : GA5.Text = "June" ElseIf GA5.Text = "07" Then : GA5.Text = "July" : ElseIf GA5.Text = "08" Then : GA5.Text = "August" : ElseIf GA5.Text = "09" Then : GA5.Text = "September" ElseIf GA5.Text = "10" Then : GA5.Text = "October" : ElseIf GA5.Text = "11" Then : GA5.Text = "November" : ElseIf GA5.Text = "12" Then : GA5.Text = "December" : End If If 合約編號_tb.Text <> 合約_dgv(0, e.RowIndex).Value.ToString Then If 存檔判斷 = True Then If CC(102) = True Then If 下載檔案位置 <> "" Then If 已存檔文件所在 <> "" Then MGB(對話框(18), 2) If 訊息回應 = "YES" Then : 存檔() : Set_合約清單() : MGB(對話框(8), 1) Else : End If Else : 存檔() : Set_合約清單() : End If End If End If End If 合約編號_tb.Text = 合約_dgv(0, e.RowIndex).Value.ToString If 下載檔案位置 <> "" Then : If File.Exists(下載檔案位置) Then : File.Delete(下載檔案位置) : End If : End If : 下載檔案位置 = "" If 視窗2_pl.Visible = True Then 合約計算() Else If 合約_dgv("合約存放", e.RowIndex).Value.ToString = "" Then MGB(對話框(0), 2) If 訊息回應 = "YES" Then If 範本清單_dgv.Rows.Count > 2999 Then : MGB(對話框(14), 1) : Else For I As Integer = 0 To 3000 : PPBB(I) = "" : Next For I As Integer = 0 To 範本清單_dgv.Rows.Count - 1 : PPBB(I) = 範本清單_dgv(0, I).Value.ToString : NN1 = I : Next 下拉清單_1.ShowDialog() For I As Integer = 0 To 範本清單_dgv.Rows.Count - 1 : If PPAA = 範本清單_dgv(0, I).Value.ToString Then : 選取位置 = I : Exit For : End If : Next : 範本讀取() 選取位置 = e.RowIndex : 合約計算() : 更新光標_bt.PerformClick() End If End If Else If 下載檔案位置 <> "" Then : If File.Exists(下載檔案位置) Then : File.Delete(下載檔案位置) : End If : End If : 下載檔案位置 = "" 合約名稱_tb.Text = 合約_dgv(0, e.RowIndex).Value.ToString 已存檔文件所在 = 合約_dgv("合約存放", e.RowIndex).Value.ToString 圖片庫 = 已存檔文件所在 : SQL_連線字串_圖片資料庫() 範本_ch.Checked = False : 舊合約_ch.Checked = True : 合約狀態_tb.Text = "合約" Dim Str As String = Application.StartupPath : Dim ds1 As New DataSet PA1 = 合約名稱_tb.Text : PA2 = 合約狀態_tb.Text : ds1.Clear() : SQL_合約本文下載() : da.Fill(ds1) 下載檔案位置 = Str + "\" & PA1 & ".docx" : 暫存檔(暫存數量) = 下載檔案位置 : 暫存數量 += 1 If 下載檔案位置 <> "" Then : If File.Exists(下載檔案位置) Then : File.Delete(下載檔案位置) : End If : End If If ds1.Tables(0).Rows.Count > 0 Then Dim imgData() As Byte : imgData = ds1.Tables(0).Rows(0).Item("文檔") Dim fs As FileStream : fs = File.Create(Str + "\" & PA1 & ".docx", imgData.Length - 1) fs.Write(imgData, 0, imgData.Length - 1) : fs.Close() End If : conn.Close() 下載檔案位置 = Str + "\" & PA1 & ".docx" : 暫存檔(暫存數量) = 下載檔案位置 : 暫存數量 += 1 If 下載檔案位置 = "" Then : Else Word控制項.Enabled = True : Word文本框.Enabled = True Dim provider As DocxFormatProvider = New DocxFormatProvider() Dim input As Byte() = File.ReadAllBytes(下載檔案位置) Word文本框.Document = provider.Import(input) End If 存檔判斷 = True End If End If End If End If : If 放大 = True Then : 縮放2_bt.PerformClick() : Else : End If End Sub Private Sub 範本讀取() If 下載檔案位置 <> "" Then : If File.Exists(下載檔案位置) Then : File.Delete(下載檔案位置) : End If : End If : 下載檔案位置 = "" 已存檔文件所在 = "" 合約名稱_tb.Text = 範本清單_dgv(0, 選取位置).Value.ToString 圖片庫 = "HX-PGS-FILE1-SYS" : SQL_連線字串_圖片資料庫() 範本_ch.Checked = True : 舊合約_ch.Checked = False : 合約狀態_tb.Text = "範本" Dim Str As String = Application.StartupPath : Dim ds1 As New DataSet PA1 = 合約名稱_tb.Text : PA2 = 合約狀態_tb.Text : ds1.Clear() : SQL_合約本文下載() : da.Fill(ds1) 下載檔案位置 = Str + "\" & PA1 & ".docx" : 暫存檔(暫存數量) = 下載檔案位置 : 暫存數量 += 1 If 下載檔案位置 <> "" Then : If File.Exists(下載檔案位置) Then : File.Delete(下載檔案位置) : End If : End If If ds1.Tables(0).Rows.Count > 0 Then Dim imgData() As Byte : imgData = ds1.Tables(0).Rows(0).Item("文檔") Dim fs As FileStream : fs = File.Create(Str + "\" & PA1 & ".docx", imgData.Length - 1) fs.Write(imgData, 0, imgData.Length - 1) : fs.Close() End If : conn.Close() 下載檔案位置 = Str + "\" & PA1 & ".docx" : 暫存檔(暫存數量) = 下載檔案位置 : 暫存數量 += 1 If 下載檔案位置 = "" Then : Else Word控制項.Enabled = True : Word文本框.Enabled = True Dim provider As DocxFormatProvider = New DocxFormatProvider() Dim input As Byte() = File.ReadAllBytes(下載檔案位置) Word文本框.Document = provider.Import(input) End If : 合約_dgv.Enabled = False End Sub Private Sub 合約編號1_cb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 合約編號1_cb.SelectedIndexChanged Set_合約清單() End Sub Private Sub 導入word_bt_Click(sender As Object, e As EventArgs) Handles 導入word_bt.Click 檔案路徑_tb.Text = "" OpenFileDialog1.Filter = "Word 文件 (*.docx)|*.docx" If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then If 下載檔案位置 <> "" Then If File.Exists(下載檔案位置) Then : File.Delete(下載檔案位置) : End If End If : 下載檔案位置 = "" 檔案路徑_tb.Text = OpenFileDialog1.FileName Dim fileNameWithoutExt As String = Path.GetFileNameWithoutExtension(檔案路徑_tb.Text) 合約名稱_tb.Text = fileNameWithoutExt End If If 檔案路徑_tb.Text = "" Then : Else Word控制項.Enabled = True : Word文本框.Enabled = True Dim provider As DocxFormatProvider = New DocxFormatProvider() Dim input As Byte() = File.ReadAllBytes(檔案路徑_tb.Text) Word文本框.Document = provider.Import(input) End If End Sub Private Sub 輸出word_bt_Click(sender As Object, e As EventArgs) Handles 輸出word_bt.Click Dim provider As DocxFormatProvider = New DocxFormatProvider() Using output As FileStream = File.OpenWrite(合約名稱_tb.Text & ".docx") Dim document As Telerik.WinForms.Documents.Model.RadDocument = Me.Word文本框.Document : provider.Export(document, output) End Using End Sub Private Sub 存檔() Dim provider As DocxFormatProvider = New DocxFormatProvider() Using output As FileStream = File.OpenWrite(合約編號_tb.Text & ".docx") Dim document As Telerik.WinForms.Documents.Model.RadDocument = Me.Word文本框.Document : provider.Export(document, output) End Using If 已存檔文件所在 = "" Then : 圖片庫 = 文件資料庫指定 : Else : 圖片庫 = 已存檔文件所在 : End If : SQL_連線字串_圖片資料庫() PA1 = 合約編號_tb.Text : PA2 = "合約" : PA3 = Strings.Format(存檔日期_dtp.Value, "yyyy/MM/dd") PA49 = Str + "\" & 合約編號_tb.Text & ".docx" : 暫存檔(暫存數量) = PA49 : 暫存數量 += 1 PA1 = 合約編號_tb.Text : PA2 = "合約" : SQL_合約本文查詢() If dr.Read Then : SQL_合約本文導入_修改() : Else : SQL_合約本文導入_新增() : End If SQL_合約存放修改() End Sub Private Sub 自動存檔_Tick(sender As Object, e As EventArgs) Handles 自動存檔.Tick 存檔() End Sub Private Sub 自動存檔_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 自動存檔_ch.Click If 自動存檔_ch.Checked = False Then : 自動存檔.Enabled = False : Else : If 合約編號_tb.Text <> "" Then : 自動存檔.Enabled = True : Else : 自動存檔_ch.Checked = False : End If : End If End Sub Private Sub 存檔_bt_Click(sender As Object, e As EventArgs) Handles 存檔_bt.Click If 下載檔案位置 = "" Then : Else 存檔日期_dtp.Value = Today If 已存檔文件所在 <> "" Then MGB(對話框(16), 2) If 訊息回應 = "YES" Then 存檔() : Set_合約清單() : MGB(對話框(8), 1) End If Else 存檔() : Set_合約清單() : MGB(對話框(8), 1) End If : 合約_dgv.Enabled = True : 存檔判斷 = False End If End Sub Private Sub 縮放2_bt_Click(sender As Object, e As EventArgs) Handles 縮放2_bt.Click Dim NX, NY As Integer : NX = 合約_dgv.Size.Width : NY = 合約_dgv.Size.Height If 放大 = True Then 合約_dgv.Size = New System.Drawing.Point(NX - 600, NY) : 放大 = False 合約_dgv.Columns("工程名稱_中").Visible = False : 合約_dgv.Columns("工程名稱_英").Visible = False Else 合約_dgv.Size = New System.Drawing.Point(NX + 600, NY) : 放大 = True If 系統語言 = "繁體中文" Then : 合約_dgv.Columns("工程名稱_中").Visible = True : Else : 合約_dgv.Columns("工程名稱_英").Visible = True : End If End If End Sub Private Sub CanceL2_bt_Click(sender As Object, e As EventArgs) Handles CanceL2_bt.Click If 視窗2_pl.Visible = False Then : 視窗2_pl.Visible = True : 視窗2_pl.BringToFront() : Else 視窗2_pl.Visible = False : End If End Sub Private Sub 編輯_bt_Click(sender As Object, e As EventArgs) Handles 編輯_bt.Click Dim XD As Integer = Me.Size.Width : XD = (XD - 851) / 2 If 視窗2_pl.Visible = False Then : 視窗2_pl.Location = New System.Drawing.Point(XD, 100) : 視窗2_pl.Visible = True : Else : 視窗2_pl.Visible = False : End If End Sub Private Sub 範本存檔_bt_Click(sender As Object, e As EventArgs) Handles 範本存檔_bt.Click 輸出word_bt.PerformClick() If File.Exists(Str + "\" & 合約名稱_tb.Text & ".docx") Then : 檔案路徑_tb.Text = Str + "\" & 合約名稱_tb.Text & ".docx" : End If If 檔案路徑_tb.Text = "" Then : MGB(對話框(7), 1) : Else 存檔日期_dtp.Value = Today If 範本_ch.Checked = True Then Dim 重複 As Boolean = False For Each row As DataGridViewRow In 範本清單_dgv.Rows If row.Cells(0).Value.ToString() = 合約名稱_tb.Text Then 重複 = True : Exit For End If Next If 重複 = True Then MGB(對話框(9), 2) If 訊息回應 = "YES" Then Dim provider As DocxFormatProvider = New DocxFormatProvider() Using output As FileStream = File.OpenWrite(合約名稱_tb.Text & ".docx") Dim document As Telerik.WinForms.Documents.Model.RadDocument = Me.Word文本框.Document : provider.Export(document, output) End Using 圖片庫 = "HX-PGS-FILE1-SYS" : SQL_連線字串_圖片資料庫() PA1 = 合約名稱_tb.Text : PA2 = 合約狀態_tb.Text : PA3 = 存檔日期_dtp.Value : PA49 = 檔案路徑_tb.Text : SQL_合約本文導入_修改() : Set_範本清單() MGB(對話框(8), 1) Else : End If Else Dim provider As DocxFormatProvider = New DocxFormatProvider() Using output As FileStream = File.OpenWrite(合約名稱_tb.Text & ".docx") Dim document As Telerik.WinForms.Documents.Model.RadDocument = Me.Word文本框.Document : provider.Export(document, output) End Using 圖片庫 = "HX-PGS-FILE1-SYS" : SQL_連線字串_圖片資料庫() PA1 = 合約名稱_tb.Text : PA2 = 合約狀態_tb.Text : PA3 = 存檔日期_dtp.Value : PA49 = 檔案路徑_tb.Text : SQL_合約本文導入_新增() : Set_範本清單() MGB(對話框(8), 1) End If Else End If End If End Sub Private Sub 刪除範本_bt_Click(sender As Object, e As EventArgs) Handles 刪除範本_bt.Click If 合約名稱_tb.Text = "" Then : MGB(對話框(12), 1) : Else MGB(對話框(11), 2) If 訊息回應 = "YES" Then 圖片庫 = "HX-PGS-FILE1-SYS" : SQL_連線字串_圖片資料庫() PA1 = 合約名稱_tb.Text : PA2 = 合約狀態_tb.Text : PA3 = 存檔日期_dtp.Value : PA49 = 檔案路徑_tb.Text : SQL_合約本文導入_刪除() : Set_範本清單() MGB(對話框(13), 1) End If End If End Sub Private Sub 範本_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 範本_ch.Click 範本_ch.Checked = True : 舊合約_ch.Checked = False : 合約狀態_tb.Text = "範本" End Sub Private Sub 舊合約_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 舊合約_ch.Click 範本_ch.Checked = False : 舊合約_ch.Checked = True : 合約狀態_tb.Text = "合約" : 圖片庫 = "" End Sub Private Sub 語轉扭_bt_Click(sender As Object, e As EventArgs) Handles 語轉扭_bt.Click 介面 = "H116" : 語言轉換讀取() : 計算分流.Enabled = True End Sub Private Sub 更新光標1_bt_Click(sender As Object, e As EventArgs) Handles 更新光標1_bt.Click 更新光標_bt.PerformClick() End Sub Private Sub 更新光標_bt_Click(sender As Object, e As EventArgs) Handles 更新光標_bt.Click For i As Integer = 1 To 26 Dim sa As Integer sa = i Dim position As New DocumentPosition(Me.Word文本框.Document) Do Dim word As String = position.GetCurrentWord If word.Contains("GA" & i.ToString().PadLeft(5, "0")) Then Dim Font_size As String = word.Substring(8, 2) Dim Font_Body As String = word.Substring(11, 3) Dim Font_Color As String = word.Substring(15) Dim style As FontStyle If Font_Body = "001" Then : style = FontStyle.Underline ElseIf Font_Body = "010" Then : style = FontStyle.Italic ElseIf Font_Body = "011" Then : style = FontStyle.Italic Or FontStyle.Underline ElseIf Font_Body = "100" Then : style = FontStyle.Bold ElseIf Font_Body = "101" Then : style = FontStyle.Bold Or FontStyle.Underline ElseIf Font_Body = "110" Then : style = FontStyle.Bold Or FontStyle.Italic ElseIf Font_Body = "111" Then : style = FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline Else : style = FontStyle.Regular : End If Dim wordEndPosition As New DocumentPosition(position) wordEndPosition.MoveToCurrentWordEnd() Word文本框.Document.Selection.AddSelectionStart(position) Word文本框.Document.Selection.AddSelectionEnd(wordEndPosition) Dim editor As New RadDocumentEditor(Word文本框.Document) editor.ChangeFontSize(CDbl(Font_size)) editor.ChangeForeColor(Color.FromName(Font_Color)) editor.ChangeFontStyle(style) Dim 選擇 As TextBox = CType(Me.Controls.Find("GA" + i.ToString(), True)(0), TextBox) editor.Insert(選擇.Text) End If If position Is Nothing Then : Exit Do : End If ' 如果 position 是 Nothing,跳出迴圈 ' 在這裡使用 position 的方法和屬性 Loop While position.MoveToNextWordStart() 'Loop While position.MoveToNextWordStart() Next MsgBox("完成") End Sub Private Sub 取消_bt_Click(sender As Object, e As EventArgs) Handles 取消_bt.Click 合約_dgv.Enabled = True Dim provider As DocxFormatProvider = New DocxFormatProvider() Dim input As Byte() = File.ReadAllBytes("HX01.docx") Word文本框.Document = provider.Import(input) End Sub Private Sub 更新合約_bt_Click(sender As Object, e As EventArgs) Handles 更新合約_bt.Click If 範本清單_dgv.Rows.Count > 2999 Then : MGB(對話框(14), 1) : Else For I As Integer = 0 To 3000 : PPBB(I) = "" : Next For I As Integer = 0 To 範本清單_dgv.Rows.Count - 1 : PPBB(I) = 範本清單_dgv(0, I).Value.ToString : NN1 = I : Next 下拉清單_1.ShowDialog() For I As Integer = 0 To 範本清單_dgv.Rows.Count - 1 : If PPAA = 範本清單_dgv(0, I).Value.ToString Then : 選取位置 = I : Exit For : End If : Next : 範本讀取() 選取位置 = 選取位置1 : 合約計算() : 更新光標_bt.PerformClick() : 存檔() End If End Sub Private Sub Word控制項_Click(sender As Object, e As EventArgs) Handles Word控制項.SizeChanged If 首次開啟 = False Then Dim XX1, YY1, YY2, YY3, YY4 As Integer YY1 = Word控制項.Size.Height XX1 = Word控制項.Size.Width YY2 = RadRichTextEditorRuler1.Location.Y YY4 = Me.Size.Height If YY1 = 167 Then RadRichTextEditorRuler1.Location = New System.Drawing.Point(190, 167) If YY1 = YY2 Then : Else RadRichTextEditorRuler1.Size = New System.Drawing.Point(XX1, YY4 - YY1 - 40) End If ElseIf YY1 > YY2 Then YY3 = YY1 RadRichTextEditorRuler1.Location = New System.Drawing.Point(190, YY3) If YY1 = YY2 Then : Else RadRichTextEditorRuler1.Size = New System.Drawing.Point(XX1, YY4 - YY1 - 40) End If ElseIf YY1 < YY2 Then YY3 = YY2 - (167 - YY1) RadRichTextEditorRuler1.Location = New System.Drawing.Point(190, YY3) If YY1 = YY2 Then : Else RadRichTextEditorRuler1.Size = New System.Drawing.Point(XX1, YY4 - YY1 - 40) End If End If End If End Sub Private Sub 讀取範本_bt_Click(sender As Object, e As EventArgs) Handles 讀取範本_bt.Click If 範本清單_dgv.Rows.Count > 2999 Then : MGB(對話框(14), 1) : Else For I As Integer = 0 To 3000 : PPBB(I) = "" : Next For I As Integer = 0 To 範本清單_dgv.Rows.Count - 1 : PPBB(I) = 範本清單_dgv(0, I).Value.ToString : NN1 = I : Next 下拉清單_1.ShowDialog() For I As Integer = 0 To 範本清單_dgv.Rows.Count - 1 : If PPAA = 範本清單_dgv(0, I).Value.ToString Then : 選取位置 = I : Exit For : End If : Next : 範本讀取1() Word預覽.Show() End If End Sub Private Sub 範本讀取1() PA48 = 範本清單_dgv(0, 選取位置).Value.ToString If PA48 <> "" Then : If File.Exists(PA48) Then : File.Delete(PA48) : End If : End If 圖片庫 = "HX-PGS-FILE1-SYS" : SQL_連線字串_圖片資料庫() : 合約狀態_tb.Text = "範本" Dim Str As String = Application.StartupPath : Dim ds1 As New DataSet PA1 = PA48 : PA2 = "範本" : ds1.Clear() : SQL_合約本文下載() : da.Fill(ds1) PA48 = Str + "\" & PA1 & ".docx" : 暫存檔(暫存數量) = PA48 : 暫存數量 += 1 If PA48 <> "" Then : If File.Exists(PA48) Then : File.Delete(PA48) : End If : End If If ds1.Tables(0).Rows.Count > 0 Then Dim imgData() As Byte : imgData = ds1.Tables(0).Rows(0).Item("文檔") Dim fs As FileStream : fs = File.Create(Str + "\" & PA1 & ".docx", imgData.Length - 1) fs.Write(imgData, 0, imgData.Length - 1) : fs.Close() End If : conn.Close() End Sub Dim OldX, OldY As Long Dim drag As Boolean Private Sub 視窗2_pl_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗2_pl.MouseDown If e.Button = MouseButtons.Left Then : OldX = e.X : OldY = e.Y : drag = True : End If End Sub Private Sub 視窗2_pl_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗2_pl.MouseMove If drag Then : 視窗2_pl.Left = 視窗2_pl.Left + e.X - OldX : 視窗2_pl.Top = 視窗2_pl.Top + e.Y - OldY : End If End Sub Private Sub 視窗2_pl_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles 視窗2_pl.MouseUp drag = False End Sub End Class