顯示具有 常用程式 標籤的文章。 顯示所有文章
顯示具有 常用程式 標籤的文章。 顯示所有文章

2022年1月11日 星期二

[Vb.NET] 搜尋指定文字資料夾 & 尋找資料夾中的副檔名 或 特定文字

         Dim sSourcePath As String = txtDirection.Text.Trim

        Dim sDestPath As String = ""

        Dim sTextToFind As String = "搜尋指定文字資料夾"

        Dim FolderName As String = ""

        Dim PrinterFolderPath As String = sSourcePath


        For Each sDir In Directory.GetDirectories(sSourcePath, "*" & sTextToFind & "*")

            FolderName = Path.GetFileName(sDir)

            PrinterFolderPath = sSourcePath & "\" & FolderName

            Dim di As New DirectoryInfo(PrinterFolderPath)



            '抓取資料夾中檔名,並只取PDF

            For Each fi As FileInfo In di.GetFiles()

                If fi.Extension.ToLower = ".pdf" Then

                   '資料夾中檔案副檔名是PDF的

                End If

           

                If fi.Name.ToLower.Contains("TEST") Then

                   '找出資料夾中的檔案名稱有包含TEST的

                End If


            Next

        Next

2020年6月18日 星期四

[VB.NET][Windows Form] 錯誤訊息System.Exception: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.


錯誤訊息

************** Exception Text **************
System.Exception: Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.




原本使用的SQL連線方式如下
 Dim Ds As New DataSet
Conn = New SqlConnection(connStr)
Dim records As New List(Of GUIDO)
Dim SqlTxt As String = ""
SqlTxt += " SELECT * "
SqlTxt += " FROM TESTTABLE "
Dim Cmmd As New SqlCommand(SqlTxt, Conn)
Conn.Open()
Dim Da As New SqlDataAdapter(Cmmd)
Da.Fill(Ds)

後來發現Timeout 的原因為預設30秒,剛好這一段SQL 真的屬於比較複雜,所以我就針對這一段SQL加長timeout的預設值到120
就快速解決問題了

 Dim Ds As New DataSet
Conn = New SqlConnection(connStr)
Dim records As New List(Of GUIDO)
Dim SqlTxt As String = ""
SqlTxt += " SELECT * "
SqlTxt += " FROM TESTTABLE "
Dim Cmmd As New SqlCommand(SqlTxt, Conn)
Conn.Open()
Dim Da As New SqlDataAdapter(Cmmd)
Da.SelectCommand.CommandTimeout = 120
 Da.Fill(Ds)

-後續追蹤-
發現DB 因為最近都沒有執行rebulid index ,所以開始造成查詢緩慢的現象
緊急先將幾個重要的table 執行rebulid後
隔天狀況有改善了,不過最好還是在每天備份的時候順便排程執行rebulid index 會比較好
後續再來分享立即rebulid 的方式 跟 排程rebulid

2020年1月9日 星期四

[SQL] 列出DB裡面所有的 TABLE 與 Column

列出DB裡面所有的 TABLE 與 Column


'List All DB Table name
SELECT * 
FROM INFORMATION_SCHEMA.TABLES
where table_type='base Table'
order by TABLE_NAME




'列出Table_Name,Column順序,Column欄位型態,Column,Column長度,ColumnIs_Identity 

select 
    tab.name as Table_Name, 
    col.Column_id,
    col.name as Column_Name, 
    t.name as Data_type,    
    col.Max_Length,
COL.Is_Identity 
from sys.tables as tab
    inner join sys.columns as col
        on tab.object_id = col.object_id
    left join sys.types as t
    on col.user_type_id = t.user_type_id
order by 
    table_name,   col.column_id

2019年4月18日 星期四

[VB.NET] FormatCurrency 格式化金額的顯示方法

在TEXTBOX 上顯示金額

'將金額格式化

Dim Amount as integer = 88971
TextBox1.Text = FormatCurrency(Amount, 0, TriState.True, TriState.False, TriState.True)

結果顯示   NT$88,971


'將金額格式化且不顯示貨幣符號

Dim Amount as integer = 88971
TextBox1.Text = FormatCurrency(Amount, 0, TriState.True, TriState.False, TriState.True).Replace("NT$", "")

結果顯示   88,971


參考連結:
Strings.FormatCurrency(Object, Int32, TriState, TriState, TriState) Method

2019年4月15日 星期一

[VB.NET] [SQL] 判斷字元是英文或是數字

[VB.NET]

If TextBox1.Text <> "" Then
Dim str As String = ""
str = TextBox1.Text
Dim str1 As String = str.Substring(0, 1)
Dim str2 As String = str.Substring(4, 1)

 

If IsNumeric(str1) = True And Char.IsLetter(str2) = True Then
MsgBox("第一個字是數字:" & str1 & " 第五字是英文:" & str2)
Else
MsgBox("OK 第一個字是數字:" & str1 & " 第五字是英文:" & str2)
End If

End If



[SQL]

' [0-9]% 找出開頭為數字的資料
' %[A-Z] 找出結尾為英文字母的資料

SELECT *
FROM TESTTABLE
WHERE (Column1 LIKE '[0-9]%') AND (Column1 LIKE '%[A-Z]')



參考:判斷身分證字號及統一編號是否正確

2017年7月27日 星期四

[VB.Net] 程式自動建立捷徑到桌面上


If (Not File.Exists(String.Format("{0}\程式.lnk", My.Computer.FileSystem.SpecialDirectories.Desktop))) Then '檢查桌面
CreateShortCut("檔案位置", "程式.exe", "描述") '產生捷徑
End If



Sub CreateShortCut(ByRef strFolder As String, ByRef strExe As String, ByRef strName As String)
Dim sc, objWS As Object
objWS = CreateObject("WScript.Shell")
With objWS
sc = .CreateShortCut(.SpecialFolders("Desktop") & "\" & Replace(strExe, ".EXE", ".LNK", 1, , 1))
End With
With sc
.TargetPath = objWS.ExpandEnvironmentStrings(strFolder & "\" & strExe)
.WorkingDirectory = strFolder
.Description = strName
.WindowStyle = 4
.IconLocation = objWS.ExpandEnvironmentStrings(strFolder & "\" & strExe & ",0")
.Save()
End With
End Sub

2017年7月6日 星期四

[Windows Forms] [VB.NET] TEXTBOX 輸入限制 -只能輸入數字

'只能輸入數字
 If e.KeyChar = Chr(48) Or e.KeyChar = Chr(49) Or e.KeyChar = Chr(50) Or e.KeyChar = Chr(51) Or e.KeyChar = Chr(52) Or e.KeyChar = Chr(53) Or e.KeyChar = Chr(54) Or e.KeyChar = Chr(55) Or e.KeyChar = Chr(56) Or e.KeyChar = Chr(57) Or e.KeyChar = Chr(13) Or e.KeyChar = Chr(8) Then
 e.Handled = False
  Else
e.Handled = True
 End If

2016年10月20日 星期四

[ASP.NET] [VB]字串處理: 西元轉民國 民國轉西元


民國轉西元

EX: Label1.text="105/10/12" 要轉成 TextBox1.Text="2016/10/12"

Dim strDate As String = Label1.text
Dim DateArr As Array = Split(strDate, "/")
TextBox1.Text = CInt(DateArr(0)) + 1911 & Mid(strDate, Len(DateArr(0)) + 1)




西元轉民國

Dim dtNow As Date = CDate(TextBox1.Text.Trim)
Dim twC = New System.Globalization.TaiwanCalendar()
Dim date1 As String
date1 = twC.GetYear(dtNow).ToString + dtNow.ToString("/MM/dd")