2019年11月22日 星期五

SQL ORDER BY 指定排序

想要在結果傳回指定的排序














SELECT         Autoid,  ITEMName,  TypeCode
FROM            TypeData
WHERE        1=1
ORDER BY
 (  CASE
    WHEN  TypeCode= 'CRN'  THEN '01'
    WHEN  TypeCode= 'OTH' THEN '02'
    WHEN  TypeCode= 'PON' THEN '03'
    WHEN  TypeCode= 'CIN'  THEN '04'
    WHEN  TypeCode= 'CLT'  THEN '05'
    WHEN  TypeCode= 'INC'  THEN '06'
    ELSE  TypeCode
  END)



















2019年11月6日 星期三

[CMD應用] robocopy 三個資料夾同步備份

Robocopy 一用就愛上它,以下是同步備份的應用

我需要做到三個資料夾同步備份
下圖A 為原始資料夾,假設今日為11/3,這份檔案是會一直附加上去的
B為中繼資料夾,目的在於收到檔案後可以上傳至C
C為終點資料夾,希望只收到有新增的檔案,過去已經收過11/1 之前的則就不要再重複收到了




語法
robocopy <Source> <Destination> [<File>[ ...]] [<Options>]

參數
<Source >           指定來原始目錄的路徑。
<Destination >   指定目的地目錄的路徑。
<File >                 指定要複製的檔案。 如有需要,您可以 * 使用萬用字元(或 ? )。 如果未指定File參數, *. \ * 當做預設值使用。
<Options >         指定要與robocopy命令搭配使用的選項。
此次所應用到的相關參數
/maxage: <N > 指定檔案最長存留期(排除N天或日期之前的檔案)。
/minage: <N > 指定檔案最短存留期(排除比N天或日期更新的檔案)。
/mov 移動檔案,並在複製後從來源刪除檔案。


搭配排程,執行兩次robocopy

第一次 - 先做資料夾同步
"A:\TXT" "B:\TXT"
第二次  將一天以前的都搬移至備份資料夾
"A:\TXT" "A:\TXTBackup" /MOV /MINAGE:1



參考資料

2019年5月24日 星期五

2019年5月23日 星期四

[SFTP] Windows Server SFTP 架站經驗談

你可以直接參考下面這篇更有用

[SFTP 架站 ]SERVER FREE SFTP SITE 免費快速架站免安裝 適用多站台


之前就已經有架站SFTP SERVER的實作經驗
當時是使用Rebex,不過近期開始有需要一台Server 架多組帳號,且又不能隨意開一個Port來使用,所以分享一下試用心得

  首先我的架站環境是Windows Server 2016

小而美SFTP SERVER 架站工具

Rebex Tiny SFTP Server
Free SFTP server from the authors of this site.
-使用心得-
優點:免費、快速架站、簡單、可多組帳號(需另外指定Port)
缺點:無法使用同一支程式來執行多組服務、沒有中文介面(其實簡單到不行,覺得沒有必要有中文介面)


完整功能SFTP SERVER 架站工具

Lightweight SFTP, SCP, SSH server for Windows from authors of this site.
-使用心得-
它的官網上是這麼列的...實際測試程式無法啟動在我的環境中
Buru Server runs on
Windows 7 SP1
Windows 8.1
Windows 10
Windows Server 2008 R2 SP1 or later
結論: 畫面跑不出來~可以刪了

OpenSSH
The most widely used SFTP/SSH server on the planet. Perfect for Linux or *BSD, not so great on Windows. Open source.
-使用心得-
說是free 的,但看到不建議在WINDOWS上使用就沒興趣了
結論: 非必要不用考慮了,不想測試


Bitvise SSH Server
SFTP/SSH server for Windows.-使用心得-
介面上有些陽春,設定解釋也有些不容易理解,不過實際測試後覺得也還OK,功能算是完整
缺點:沒有中文介面喔,設定上可能會有些搞不懂是做什麼用的,然後官網說名字有些小
結論: 還能用,但要購買

Tectia SSH Server
Enterprise SFTP/SSH server from the creators of the SSH protocol.
-使用心得-
網站做得漂亮,不過無法直接看到系統畫面,想要下載試用還要留下基本資料,就連輸入Gmail帳號還會說你的email是不是公司,覺得有點囉嗦,到底是要不要讓人試用?
結論: 不想測試

CrushFTP
File transfer server with support for SFTP, SCP, FTPS and HTTPS.
-使用心得-
缺點: 安裝檔案好大 要125MB,網頁設計讓人覺得像詐騙網站,令人卻步
結論: 非必要不用考慮了,不想測試


VanDyke VShell Server
SSH2/SFTP/FTPS file transfer server for Windows, Linux & Mac with fine-grain access control and configuration.
-使用心得-
缺點: 一樣,想要下載試用還要留下基本資料
結論: 非必要不用考慮了,不想測試



GlobalScape EFT Server
-使用心得-
我以為跑錯網站.....
結論:  非必要不用考慮了,不想測試



Titan FTP Server
SFTP, FTP/SSL and FTP server for Windows
-使用心得-
看影片介紹似乎還蠻符合需要的,但無法下載試用檔
結論:無法測試

CORE FTP



參考STP.NET
https://sftp.net/servers

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]')



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

2019年4月10日 星期三

[GrapeCity][Spread Windows Forms] combine sheet to one PDF 實作合併sheet 匯出一個PDF檔案




'單一FPSpread

    Public Sub CombinePDFFiles()
        Dim printset As FarPoint.Win.Spread.PrintInfo = New FarPoint.Win.Spread.PrintInfo()
        printset.PrintToPdf = True
        printset.PdfWriteMode = PdfWriteMode.Append
        printset.PdfFileName = "D:\TEST\testPDF_" & Format(Now, "yyyyMMddHHmmss") & ".pdf"

        FpSpread1.Sheets(0).PrintInfo = printset
        FpSpread1.Sheets(1).PrintInfo = printset
        FpSpread1.Sheets(2).PrintInfo = printset

        FpSpread1.PrintSheet(-1)
    End Sub


原本希望將多個FPSpread 直接合併匯出一個PDF檔案,實測後是不支援的
所以比較好的做法是直接將兩個檔案合併到同一個FPSpread中




'多個FPSpread

    Public Sub CombinePDFFiles()
        Dim Spread As FarPoint.Win.Spread.FpSpread = New FarPoint.Win.Spread.FpSpread()
        Spread.BringToFront()

        Spread.Size = New System.Drawing.Size(600, 300)
        Spread.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Dim coll As FarPoint.Win.Spread.SheetViewCollection
        coll = Spread.Sheets
        coll.Add(FpSpread1.Sheets(0))
        coll.Add(FpSpread2.Sheets(0))

        Dim printset As FarPoint.Win.Spread.PrintInfo = New FarPoint.Win.Spread.PrintInfo()
        printset.PrintToPdf = True
        printset.PdfWriteMode = PdfWriteMode.Append

        printset.PdfFileName = "D:\TEST\testPDF_" & Format(Now, "yyyyMMddHHmmss") & ".pdf"

        Me.Controls.Add(Spread)
        Spread.Sheets(0).PrintInfo = printset
        Spread.Sheets(1).PrintInfo = printset
        Spread.PrintSheet(-1)


    End Sub


這方法也是可行,但我覺得如果設計成自動產生會造成元件的負擔
應該蠻容易crash的


程式碼