8/08/2014

ใน Visual Studio ตั้งแต่ 2010  เป็นต้นไป  จะไม่มี Crystal Report ให้   ถ้าใครเปิดโปรแกรมมาแล้วหาไม่เจอไม่ต้องตกใจค่ะ  จะต้องติดตั้งเพิ่มเข้าไปถึงจะงานได้ค่ะ

สามารถ Download  Crystal Report ได้ที่นี่ค่ะ  http://scn.sap.com/docs/DOC-7824
โดย Download >> Support Pack 10 (v.13.0.10.1385)


จะได้ตัว CRForVS_13_0_10.exe

ขั้นตอนติดตั้ง Crystal Report 










เมื่อติดตั้งเรียบร้อยแล้ว  Visual Studio 2010 จะมี Toolbox ของ  Crystal Report  สามารถใช้งานได้ปกติค่ะ

Posted on Friday, August 08, 2014 by nuyingnaja

Public Class ThaiBath
    Private suffix() As String = {"", "", "สิบ", "ร้อย", "พัน", "หมื่น", "แสน", "ล้าน"}
    Private numSpeak() As String = {"", "หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก", "เจ็ด", "แปด", "เก้า"}

    Public Function ThaiBahtText(ByVal m As Double) As String
        Dim s1 As String = ""   ' ---- ส่วนที่เกินหลักล้านขึ้นไป  (ล้าน)
        Dim s2 As String = ""   ' ---- ส่วนจำนวนเต็ม                 (บาท)
        Dim s3 As String = ""   ' ---- ส่วนสตางค์                       (สตางค์)
        Dim result As New System.Text.StringBuilder

        If (m = 0) Then Return ("ศูนย์บาท") ' ---- ศูนย์บาทถ้วน ???

        splitCurr(m, s1, s2, s3)                        ' now 'm' split to 3 parts in 's1' & 's2' & 's3'

        If (s1.Length > 0) Then result.Append(Speak(s1) & "ล้าน")
        If (s2.Length > 0) Then result.Append(Speak(s2) & "บาท")
        If (s3.Length > 0) Then
            result.Append(speakStang(s3) & "สตางค์")
        Else
            result.Append("ถ้วน")
        End If

        Return (result.ToString)
    End Function

    Private Function Speak(ByVal s As String) As String
        Dim c As Integer
        Dim result As New System.Text.StringBuilder
        Dim L As Integer

        If (s.Length = 0) Then Return ("")
        L = s.Length

        For i As Integer = 1 To L
            If (s.Chars(i - 1) = "-") Then
                result.Append("ติดลบ")
            Else
                c = Val(s.Chars(i - 1))
                If ((i = L) And (c = 1)) Then
                    If (L = 1) Then
                        Return ("หนึ่ง")
                    End If
                    If (L > 1) And (s.Chars(L - 2) = "0") Then
                        result.Append("หนึ่ง")
                    Else
                        result.Append("เอ็ด")
                    End If
                ElseIf ((i = L - 1) And (c = 2)) Then
                    result.Append("ยี่สิบ")
                ElseIf ((i = L - 1) And (c = 1)) Then
                    result.Append("สิบ")
                Else
                    If (c <> 0) Then
                        result.Append(numSpeak(c) & suffix(L - i + 1))
                    End If
                End If
            End If
        Next

        Return (result.ToString())
    End Function

    Private Function speakStang(ByVal s As String) As String
        Dim i, L As Integer
        Dim c As Integer
        Dim result As New System.Text.StringBuilder

        L = s.Length
        If (L = 0) Then Return ("")
        If (L = 1) Then s = s & "0" : L = 2
        If (L > 2) Then s = s.Substring(0, 2) : L = 2

        For i = 1 To 2
            c = Val(s.Chars(i - 1)) ' --- CInt(Mid$(s, i, 1))

            If ((i = L) And (c = 1)) Then
                If (CInt(Mid$(s, 1, 1)) = 0) Then
                    result.Append("หนึ่ง")
                Else
                    result.Append("เอ็ด")
                End If
            ElseIf ((i = L - 1) And (c = 2)) Then
                result.Append("ยี่สิบ")
            ElseIf ((i = L - 1) And (c = 1)) Then
                result.Append("สิบ")
            Else
                If (c <> 0) Then
                    result.Append(numSpeak(c) & suffix(2 - i + 1))
                End If
            End If
        Next

        Return (result.ToString())
    End Function

    Private Sub splitCurr(ByVal m As Double, _
                    ByRef s1 As String, _
                    ByRef s2 As String, _
                    ByRef s3 As String)
        Dim s As String
        Dim L, position As Integer

        s = CStr(m)
        position = s.IndexOf(".") + 1 ' --- InStr( 1, s, ".")
        If (position <> 0) Then
            'this currency have a point
            s1 = s.Substring(0, position - 1) '  Mid$(s, 1, position - 1)
            s3 = s.Substring(position) '  Mid$(s, position + 1, 2)
            If s3 = "00" Then s3 = ""
        Else
            s1 = s
            s3 = ""
        End If

        L = s1.Length
        If (L > 6) Then
            s2 = s1.Substring(L - 5 - 1) ' --- Mid$(s1, L - 5, 99)
            s1 = s1.Substring(0, L - 6) '  Mid$(s1, 1, L - 6)
        Else
            s2 = s1
            s1 = ""
        End If

        If (Not IsNumeric(s1)) Then s1 = ""
        If (Not IsNumeric(s2)) Then s2 = ""
        If (Val(s1) = 0) Then s1 = ""
        If (Val(s2) = 0) Then s2 = ""
    End Sub

End Class

Posted on Friday, August 08, 2014 by nuyingnaja

7/29/2014

SqlConnection connection = new SqlConnection(Program.C);
connection.Open();
string cmdText = "Update table1 set rate=@rate,qty=@qty,total=@total where id=@id";
SqlCommand command = new SqlCommand(cmdText, connection);
command.Parameters.AddWithValue("rate", rate);
command.Parameters.AddWithValue("qty", qty);
command.Parameters.AddWithValue("total", total);
command.Parameters.AddWithValue("id", id);
command.ExecuteNonQuery();
connection.Close();

Posted on Tuesday, July 29, 2014 by nuyingnaja

7/07/2014

Imports MySql.Data.MySqlClient

Public Class clsConnecetion
    Public ConMy As MySqlConnection = New MySqlConnection

    'Dim Hostname As String = "172.00.00.000"
    'Dim DBName As String = "XXX"
    'Dim SID As String = "admin"
    'Dim Password As String = "1234567890"

    Public Sub ConnectOpen()
        ConMy.Close()
        Try
            With ConMy
                If .State = ConnectionState.Open Then .Close()
                .ConnectionString = "Data Source=" & Hostname & ";Database=" & DBName & ";User ID=" & SID & ";Password=" & Password & ";CharSet=tis620"
                .Open()
            End With
        Catch ex As Exception
        End Try
    End Sub

    Public Sub ConnectClose()
        Try
            ConMy.Close()
        Catch ex As Exception
        End Try
    End Sub

End Class

Posted on Monday, July 07, 2014 by nuyingnaja

6/10/2014

จัด format ตัวเลข
Dim num As Integer = 10
Dim id As String =  num.ToString.PadLeft(5, "0")
'  id = 00010


Dim num As Integer = 10
Dim id As String =  Microsoft.VisualBasic.Right("00001", 5)
'  id = 00010

Posted on Tuesday, June 10, 2014 by nuyingnaja

6/09/2014


สร้าง Text Editor เอง ด้วย VB.Net

หน้าจอหลักๆ ของ Text Editor



ค้นหาคำ

แสดงโค้ด HTML

Download Semple Coding in vb.net Project


ภาษา C#
Credit by : www.codeproject.com

ภาษา VB converse จาก C#
Credit by : NuyingNaja

Posted on Monday, June 09, 2014 by nuyingnaja

6/03/2014

ตัวอย่างคำสั่ง SQL ที่ใช้ง่ายบ่อยๆ

ตัวอย่าง database ดังนี้
Book_id
Book_name
Book_price
1
Vb.net 2008
50
2
Vb.net 2010
100
3
Vb.net 2011
200
4
Vb.net 2012
500
5
Vb.net 2013
500

1. คำสั่ง SQL นี้  ค้นหาข้อมูลง่ายๆ ที่ book_id  = 1
" SELECT * FROM  tbl_book  WHERE  book_id  = 1 "
Book_id
Book_name
Book_price
1
Vb.net 2008
50

2. คำสั่ง SQL นี้  ค้นหาข้อมูล เรียงลำดับข้อมูล น้อยไปมาก
" SELECT * FROM  tbl_book  ORDER BY  book_id "

Book_id
Book_name
Book_price
1
Vb.net 2008
50
2
Vb.net 2010
100
3
Vb.net 2011
200
4
Vb.net 2012
500
5
Vb.net 2013
500

3. คำสั่ง SQL นี้  ค้นหาข้อมูล เรียงลำดับข้อมูล มากไปน้อย
" SELECT * FROM  tbl_book  ORDER BY  book_id  DESC "
Book_id
Book_name
Book_price
5
Vb.net 2013
500
4
Vb.net 2012
500
3
Vb.net 2011
200
2
Vb.net 2010
100
1
Vb.net 2008
50

4. คำสั่ง SQL นี้  ค้นหาข้อมูล จัดกลุ่มข้อมูล
" SELECT  book_price  FROM  tbl_book  GROUP BY  book_price "
book_price 
50
100
200
500

5. คำสั่ง SQL นี้ เพิ่มข้อมูล อีก 1 row
" INSERT INTO  tbl_book  (book_id , book_name, book_price) VALUES (6, 'AAA',20) "
Book_id
Book_name
Book_price
1
Vb.net 2008
50
2
Vb.net 2010
100
3
Vb.net 2011
200
4
Vb.net 2012
500
5
Vb.net 2013
500
6
AAA
20

6. คำสั่ง SQL  แก้ไขข้อมูล
" UPDATE  tbl_book  SET
book_name = 'Vb.net' ,
book_price = 111
WHERE book_id = 1 "
Book_id
Book_name
Book_price
1
Vb.net
111

7. คำสั่ง SQL  ลบข้อมูล
" DELETE FROM  tbl_book  WHERE  book_id = 5 "
Book_num
Book_name
Book_price
1
Vb.net 2008
50
2
Vb.net 2010
100
3
Vb.net 2011
200
4
Vb.net 2012
500
6
AAA
20

8. คำสั่ง SQL นี้ สามารถหาผลรวมที่ต้องการได้
" SELECT * FROM  tbl_book WHERE (book_id & 7) =  book_id "
Book_num
Book_name
Book_price
1
Vb.net 2008
50
2
Vb.net 2010
100
4
Vb.net 2012
300

9. คำสั่ง SQL นี้  count นับจำนวน row
" SELECT  count(*) as count_book FROM  tbl_book "
count_book 
5

10. คำสั่ง SQL นี้ MAX 
" SELECT  max(book_price) as book_price FROM  tbl_book "
count_book 
500

11. คำสั่ง SQL นี้ Update data and Select Data  ถ้าจะใช้กับ Insert data and Select Data ก็ได้
" UPDATE  tbl_book  SET
book_name = 'Vb.net' ,
book_price = (SELECT  max(book_price) as book_price FROM  tbl_book)
WHERE book_id = 1 "

12. คำสั่ง SQL  insert date time database
 "INSERT INTO tbl_book
(book_date)
 VALUES
(
 CURRENT_TIMESTAMP
 )"

12. คำสั่ง SQL  insert date time database for vb.net
 Dim date_now As Date = "#01/12/2014 11:11:11#"
 "INSERT INTO tbl_book
(book_date)
 VALUES
(
  IIf( date_now = Date.MinValue, "Null", "STR_TO_DATE('" & Format(date_now , "M/d/y h:m:s") & "', '%m/%d/%Y %h:%i:%s')")
 )"

13. ตัดตัวอักษร SQL Oracle
SELECT MAX(substr(book_id,2)) AS ID
FROM tbl_book ;

14. ตัดตัวอักษร SQL server
SELECT  MAX(RIGHT(book_id,2)) AS ID
FROM tbl_book
GROUP BY RIGHT(book_id,2);



Posted on Tuesday, June 03, 2014 by nuyingnaja

4/03/2014

กำหนดให้ TextBox รับค่าจาก Keyboard เป็นตัวเลขเท่านั้น
 
Private Sub txt_price_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt_price.KeyPress
        Select Case Asc(e.KeyChar)
            Case 48 To 57
                e.Handled = False
            Case 8, 3, 22   ' Backspace = 8, Enter = 13, Delete = 46 ,Ctrl+C=3,Ctrl+V=22
                e.Handled = False
            Case 13
                e.Handled = True 'SendKeys.Send("{TAB}")
            Case 46         'Delete = 46 ,.
                If txt_price.Text.IndexOf(".") <> -1 Then
                    e.Handled = True
                Else
                    e.Handled = False
                End If
            Case Else
                e.Handled = True
        End Select 
End Sub

Private Sub txt_price_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_price.Leave
        If txt_price.Text <> "" Then
            txt_price.Text = Convert.ToDouble(txt_price.Text).ToString("#,###.#0")
        End If
End Sub

Posted on Thursday, April 03, 2014 by nuyingnaja

Dim FtpHostname As String = '192.XX.XX.XXX'
Dim FtpHostname As String = "172.16.80.185"
Dim FtpUserName As String = "username"   
Dim FtpPassWord As String = "password"   
Dim FtpPort As String = "21"

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
       Dim response As Boolean

       Dim folderServer As String = '/Newfolder/'
       Dim pathFullName As String = 'D:\1234.jpg'
       Dim filename As String = '1234.jpg'
       Dim filenameNew As String = 'pic.jpg'


        Try 
            ' ====== Upload =======
            response = cSftp.FTPuploadFile(folderServer , pathFullName , filename )

            ' ====== Delete =======
            response = cSftp.FTPDeleteFile(folderServer & filename)

            ' ====== Rename =======
            response = cSftp.FTPuploadFile(folderServer & filename,  filenameNew )
 






        Catch ex As Exception
        End Try

End Sub

Function FTPuploadFile(ByVal folderServer As String, ByVal pathFullName As String, ByVal filename As String) As Boolean
        ' folderServer = '/Newfolder/'
        ' pathFullName = 'D:\1234.jpg'
        ' filename = '1234.jpg'
        Try
            Dim ftp As String = "ftp://" & FtpHostname & folderServer
            Dim Request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(ftp & filename), System.Net.FtpWebRequest)

            Request.Credentials = New System.Net.NetworkCredential(FtpUserName, FtpPassWord)
            Request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

            'Read File
            Dim File() As Byte = System.IO.File.ReadAllBytes(pathFullName)

            'Upload
            Dim Strz As System.IO.Stream = Request.GetRequestStream()
            Strz.Write(File, 0, File.Length)
            Strz.Close()
            Strz.Dispose()
            Return True
        Catch ex As Exception
            'MessageBox.Show("เกิดความผิดพลาดของไฟล์: " & _pathName & vbNewLine & ex.Message, "Messsage")
            Return False
        End Try 
End Function
 
' Delete File in Server Past FTP
 Function FTPDeleteFile(ByVal folderServerFilename As String) As Boolean

        Try
            Dim filename As String = "ftp://" & FtpHostname & "/" & folderServerFilename
            Dim ftpReq As FtpWebRequest = WebRequest.Create(filename)
            ftpReq.Method = WebRequestMethods.Ftp.DeleteFile
            ftpReq.Credentials = New NetworkCredential(FtpUserName, FtpPassWord)

            Dim ftpResp As FtpWebResponse = ftpReq.GetResponse
            Return True
        Catch ex As Exception
            'MsgBox("Error " + ex.ToString)
            Return False
        End Try 
End Function

' Rename File in Server Past FTP
Private Sub RenameFileWord(ByVal NameOld As String, ByVal NameNew As String)
        Dim reqFTP As FtpWebRequest = Nothing
        Dim ftpStream As Stream = Nothing
        reqFTP = DirectCast(FtpWebRequest.Create(New Uri(FtpHostname & NameOld)), FtpWebRequest)
        reqFTP.Method = WebRequestMethods.Ftp.Rename
        reqFTP.RenameTo = NameNew
        reqFTP.UseBinary = True
        reqFTP.Credentials = New NetworkCredential(FtpUserName, FtpPassWord)
        Dim response As FtpWebResponse = DirectCast(reqFTP.GetResponse(), FtpWebResponse)
        ftpStream = response.GetResponseStream()
        ftpStream.Close()
        response.Close()
 End Sub

Posted on Thursday, April 03, 2014 by nuyingnaja

4/02/2014

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click   
        Dim sContents As String = GetFileContents("C:\note.txt")
        If sContents = "" Then
            Return
        Else
            Me.txtUserName.Text = Mid(sContents, 1, InStr(sContents, "|") - 1)
            Me.txtPassword.Text = Mid(sContents, InStr(sContents, "|") + 1, 900)
        End If
 End Sub


Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click   
        SaveTextToFile(txtUserName.Text & "|" & Me.txtPassword.Text, "C:\note.txt")
 End Sub

Public Sub GetFileContents(ByVal FullPath As String) As String

        Dim strContents As String = ""
        Dim objReader As StreamReader
        Try
            objReader = New StreamReader(FullPath)
            strContents = objReader.ReadToEnd()
            objReader.Close()
            Return strContents
        Catch Ex As Exception
        End Try
        Return strContentsEnd Sub

Public Function SaveTextToFile(ByVal strData As String, ByVal FullPath As String) As Boolean

        Dim Contents As String = ""
        Dim bAns As Boolean = False
        Dim objReader As StreamWriter
        Try
            objReader = New StreamWriter(FullPath)
            objReader.Write(strData)
            objReader.Close()
            bAns = True
        Catch Ex As Exception
        End Try
        Return bAns

    End Function

Posted on Wednesday, April 02, 2014 by nuyingnaja