2017年9月29日 星期五

[GrapeCity][Spread Windows Forms] 錯誤 Task could not find "LC.exe" using the SdkToolsPath ""






錯誤訊息(Error):
Task could not find "LC.exe" using the SdkToolsPath "" or the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\NETFXSDK\4.6.1\WinSDK-NetFx40Tools-x86". Make sure the SdkToolsPath is set and the tool exists in the correct processor specific location under the SdkToolsPath and that the Microsoft Windows SDK is installed xxx

解決方法:
這個狀況其實就是預設Spread一開所放置的是免費試用的版本
開新的專案(Project)要先手動直接刪除,再重新編譯就會再次自動產生有付費後的版本






[OFFICE2010][PowerPoint] 將PPT轉為網頁

PPT轉網頁方法
1.      請一個網頁一個PPT檔案
2.      PPT 中按下Alt+F11
接著在View選擇Immediate Window
3.      Immediate Window 輸入下面這串文字後直接Enter
※紅字為指定存檔位置,檔名切記不使用中文且不要有空白
ActivePresentation.SaveAs "D:\temp\Default.htm", ppSaveAsHTML, msoFalse
4.      轉出後會產生一個htm網頁檔與相同檔名資料夾,將這兩個檔案直接放置
Website資料夾中即可
5.      常見問題

þ有連結的請固定在前方加上紅字http://xxx.xxx.xxx/*****.htm

2017年8月25日 星期五

[Windows Forms] [VB.NET] 實現利用AD帳號登入Windows Form


我過去的設計都是走獨立SQL帳號密碼管理
但這次的需求是要利用走現有的AD認證,方便使用者不需要記多組帳號密碼





以下直接列出我的實作方式

1.先加入參考


2.直接開一個檔案為LdapAuthentication.vb
完整程式碼如下:

Imports System
Imports System.Text
Imports System.Collections
Imports System.DirectoryServices


Namespace FormsAuth
    Public Class LdapAuthentication

        Dim _path As String
        Dim _filterAttribute As String

        Public Sub New(ByVal path As String)
            _path = path
        End Sub

        Public Function IsAuthenticated(ByVal domain As String, ByVal username As String, ByVal pwd As String) As Boolean

            Dim domainAndUsername As String = domain & "\" & username
            Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, pwd)

            Try
                'Bind to the native AdsObject to force authentication.
                Dim obj As Object = entry.NativeObject
                Dim search As DirectorySearcher = New DirectorySearcher(entry)

                search.Filter = "(SAMAccountName=" & username & ")"
                search.PropertiesToLoad.Add("cn")
                Dim result As SearchResult = search.FindOne()

                If (result Is Nothing) Then
                    Return False
                End If

                'Update the new path to the user in the directory.
                _path = result.Path
                _filterAttribute = CType(result.Properties("cn")(0), String)

            Catch ex As Exception
                Throw New Exception("Error authenticating user. " & ex.Message)
            End Try

            Return True
        End Function

        Public Function GetGroups() As String
            Dim search As DirectorySearcher = New DirectorySearcher(_path)
            search.Filter = "(cn=" & _filterAttribute & ")"
            search.PropertiesToLoad.Add("memberOf")
            Dim groupNames As StringBuilder = New StringBuilder()

            Try
                Dim result As SearchResult = search.FindOne()
                Dim propertyCount As Integer = result.Properties("memberOf").Count

                Dim dn As String
                Dim equalsIndex, commaIndex

                Dim propertyCounter As Integer

                For propertyCounter = 0 To propertyCount - 1
                    dn = CType(result.Properties("memberOf")(propertyCounter), String)

                    equalsIndex = dn.IndexOf("=", 1)
                    commaIndex = dn.IndexOf(",", 1)
                    If (equalsIndex = -1) Then
                        Return Nothing
                    End If

                    groupNames.Append(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1))
                    groupNames.Append("|")
                Next

            Catch ex As Exception
                Throw New Exception("Error obtaining group names. " & ex.Message)
            End Try

            Return groupNames.ToString()
        End Function
    End Class
End Namespace


3.Login按鈕

Sub Login_Click(sender as object,e as EventArgs) Handles btnLogin.Click

  Dim adPath as String = "LDAP://DC=..,DC=.." 'Path to your LDAP directory server

 'LDAP 輸入方式再請另外自己GOOGLE填寫方式

  Dim adAuth as LdapAuthentication = new LdapAuthentication(adPath)
  try
    if(true = adAuth.IsAuthenticated(txtDomain.Text, txtUsername.Text, txtPassword.Text)) then
      Dim groups as string = adAuth.GetGroups()

      'Create the ticket, and add the groups.
      Dim isCookiePersistent as boolean = chkPersist.Checked
      Dim authTicket as FormsAuthenticationTicket = new FormsAuthenticationTicket(1, _
           txtUsername.Text,DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups)

      'Encrypt the ticket.
      Dim encryptedTicket as String = FormsAuthentication.Encrypt(authTicket)

      'Create a cookie, and then add the encrypted ticket to the cookie as data.
      Dim authCookie as HttpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)

      if(isCookiePersistent = true) then
authCookie.Expires = authTicket.Expiration
      end if
      'Add the cookie to the outgoing cookies collection.
      Response.Cookies.Add(authCookie)

      'You can redirect now.
      Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, false))
    
    else
      errorLabel.Text = "Authentication did not succeed. Check user name and password."
    end if

  catch ex as Exception
    errorLabel.Text = "Error authenticating. " & ex.Message
  end try
End sub




文章參考
 vb.net開發的login程式(win form),帳號要如何與AD帳號整合?
https://social.msdn.microsoft.com/Forums/zh-TW/5fe87afe-340a-41eb-bab4-a8707400a9a3/vbnetloginwin-formad?forum=232


如何使用表單驗證及 Visual Basic .NET 通過 Active Directory 驗證
https://support.microsoft.com/zh-tw/help/326340/how-to-authenticate-against-the-active-directory-by-using-forms-authen

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 10] [English Version]將預設輸入法切換改為 Ctrl + Shift


從控制台進入到語言設定
> Control Panel\Clock, Language, and Region\Language



從左側選擇進階選項
找到更換語言快速鍵




把切換輸入法改為Ctrl+Shift




OK囉!!

[設計好物]CANVA


推薦網站:https://www.canva.com/



這是線上免費設計卡片或者是一些平面小宣傳廣告用的(例如:Facebook)

裡面有些基本設計或者是收費的設計

最好用的地方是你可以自由設計後轉成圖片檔或者是PDF

轉出後的PDF還可以直接使用Illustrator去修改成自己需要的尺寸

而且在Illustrator中使用,每個頁面都是獨立的物件還可以做更廣泛的應用

真的是無敵好用!!!強力推薦 👍

[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

2017年6月5日 星期一

[Windows Forms] [VB.NET] 取得日期 資料處理

'Get the first day of the month
'取得當月的第一天 Public Function FirstDayOfMonth(ByVal sourceDate As DateTime) As DateTime
  Return New DateTime(sourceDate.Year, sourceDate.Month, 1)
End Function


'Get the last day of the month
'取得當月的最後一天 Public Function LastDayOfMonth(ByVal sourceDate As DateTime) As DateTime
  Dim lastDay As DateTime = New DateTime(sourceDate.Year, sourceDate.Month, 1)
  Return lastDay.AddMonths(1).AddDays(-1)
End Function


'根據日期取得上個月的最後一天
Public Shared Function LastDayOfLastMonth(ByVal sourceDate As DateTime) As DateTime
        Dim lastDay As DateTime = New DateTime(sourceDate.Year, sourceDate.Month, 1)
        Return lastDay.AddMonths(0).AddDays(-1)
End Function


'根據日期取得下個月的第一天
Public Shared Function FirstDayOfNextMonth(ByVal sourceDate As DateTime) As DateTime
        Dim NextDay As DateTime = New DateTime(sourceDate.Year, sourceDate.Month, 1)
        Return NextDay.AddMonths(1).AddDays(0)

End Function

2017年5月23日 星期二

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

  Private Sub txtbox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtbox1.KeyPress
        '只能輸入字母
        If Char.IsLetter(e.KeyChar) = True Or Char.IsControl(e.KeyChar) = True Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

2017年1月23日 星期一

[ADOBE] [PDF] 文件轉向


如果你收到一個PDF 文件需要轉向,你又只有安裝Adobe Reader的話
可以試試看你的印表機如果有PDF Writer
就可以在Reader中再次列印,選到PDF Writer
另存檔案
就可以得到轉好的檔案唷!


如果你沒有PDF Writer
可以試著安裝 CutePDF Writer

[OFFICE 2010] [OUTLOOK] Outlook 中開啟或儲存電子郵件附件時出現錯誤訊息:「無法建立檔案」

Can not create file:XXXX. Right-click the folder you want to create the file in, and the click Properties on the shortcut menu to check your permissions for the folder.



1.[開始],再按一下 [執行],輸入 regedit

2.找出下列登錄機碼並按一下: 

HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Security\
但這邊有個祕訣,你用肉眼找可能找不到Security這資料夾,一定要利用Edit →Find
用搜尋的方式才會找到在這各OUTLOOK底下有一個Security
接著可以看到右側的OutlookSecureTempFolder ,右鍵點選修改
COPY整段路徑到檔案總管中(此路徑是隨機的,你一定要透過regedit才能找到這各路徑)



接著手動清除此資料夾中的所有檔案,OUTLOOK也可以立即開啟檔案了!
另外~不用重開機啦!!

參考:
當您嘗試在 Outlook 中開啟或儲存電子郵件附件時出現錯誤訊息:「無法建立檔案」

2017年1月20日 星期五

[OFFICE 2010] [OUTLOOK] 用顏色辨識來信的人

[OFFICE 2010] [OUTLOOK] 用顏色辨識來信的人

1.  在OUTLOOK中先選擇收件匣(或是你想要的資料夾也可以)


2.    選擇Conditional Formatting 


3.    點選新增然後建立一個新的命名,接著你可以選擇FONT 來指定顏色


4.    選好顏色後按OK.


5.    點選Condition→點選From,利用Address Book找到你要指定的人(建議先將你要的人存在Address Book),這樣設定效果才會成功出來!
 



6.   確定後就可以囉!

[OFFICE 2010 ] [OUTLOOK] PST檔案太大,如何快速重新建立一個

先開一個新的PST 檔案NewItemsMoreItemsOutlookDataFile,檔案命名隨你~,存到你想要的地方

產生完後如果你的收件夾有些資料夾要跟著帶過去,但所有的信件不想全帶過去的話
你接著可以作下一步匯入的動作



選擇原本的PST 並將今天收到的信也一併帶過去

指定到新的PST


打開Account Setting


Change FolderYes 指定到新的PST


將新的PST指定為預設存放位置



※完成後重新開啟OUTLOOK





[OFFICE 2010] [ EXCEL] [WINOWS 10] 網站網頁下載下來的EXCEL 打不開檔案 打不開xls 開啟是空白的?

EXCEL 開啟後空白 請進入EXCEL 設定
FileOptions

Trust CenterTrust Center SettingProtected View
全部取消打勾→OK



[OFFICE 2010] [OUTLOOK] 開啟 關閉 迷你即時翻譯小工具

OUTLOOK 的即時翻譯工具

不過要呼叫啟用的話要先開啟一封email
 Tab上面選到Mesage
找到翻譯這各選項後 點選Mini Translator就可以出現即時翻譯唷!




2017年1月13日 星期五

[SQL Server 2008][SQL Server Management Studio] 縮小 壓縮 清除 交易紀錄檔 _Log.LDF 無效的時候怎麼處理

👷狀況發生~偶而會遇到DB 復原模式設定為簡單SIMPLE模式,但LOG 還是不斷成長
有時候直接使用下面這段語法可以立即壓縮到1MB,但有時候就是無效。

ALTER DATABASE DBNAME SET RECOVERY SIMPLE
DBCC SHRINKFILE(DBNAME _Log, 1)

上面這段語法法也可以用操作介面來處理
先在DB上按右鍵選擇屬性

將復原模式先切換為FULL,等縮小後記得改為SIMPLE→OK

確認後再重新開一次屬性,並切換到FILE
直接手動將LOG的檔案大小設定為1→OK


*****************************************
如果遇到以上兩種做法都不能的時候呢!我們就來重新產生新的一個交易檔最快!
但這各作法要先暫時將DB卸離,接著將原先過大的_Log.LDF 更改名稱

重新掛上DB,手動將LOG Remove→OK


最後我們新產生出來的交易記錄檔只有504KB!
真是太好了!!!

參考有用文章

縮小 壓縮 交易記錄檔 (Shrink Transaction Log);以使用 SQL Server 2008/2005 SSMS 管理工具 為例