วันอาทิตย์ที่ 23 สิงหาคม พ.ศ. 2558

ทำกล่องข้อความแจ้งเตือนแบบ Growl ด้วย Bootstrap




















<button type="button" class="btn btn-sm btn-success btn-growl" data-growl="success"><i class="fa fa-check fa-fw"></i> Success</button>
<button type="button" class="btn btn-sm btn-info btn-growl" data-growl="info"><i class="fa fa-info fa-fw"></i> Info</button>
<button type="button" class="btn btn-sm btn-warning btn-growl" data-growl="warning"><i class="fa fa-exclamation-triangle fa-fw"></i> Warning</button>
<button type="button" class="btn btn-sm btn-danger btn-growl" data-growl="danger"><i class="fa fa-times fa-fw"></i> Danger</button>
     
        <script>
            /* Grawl Notifications with Bootstrap-growl plugin, check out more examples at http://ifightcrime.github.io/bootstrap-growl/ */
            $('.btn-growl').on('click', function () {
                var growlType = $(this).data('growl');

                $.bootstrapGrowl('<h4>Hi there!</h4> <p>This is another notification!</p>', {
                    type: growlType,
                    delay: 2500,
                    allow_dismiss: true
                });

                $(this).prop('disabled', true);
            });

        </script>

ลากไฟล์เพื่ออัพโหลด โดยใช้ Dropzone js + Asp.net























<!--  File Name : drop.html -->
<meta charset="utf-8">

<title>Dropzone simple example</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">


<div id="dZUpload" class="dropzone">
         <div class="dz-default dz-message">Upload File</div>
</div>


<hr />

 <script type="text/javascript">

     $(document).ready(function () {

         Dropzone.autoDiscover = false;

         //Simple Dropzonejs
         $("#dZUpload").dropzone({
             url: "/file-upload/hn_SimpeFileUploader.ashx",
             addRemoveLinks: true,
             success: function (file, response) {
                 var imgName = response;
                 file.previewElement.classList.add("dz-success");
                 console.log("Successfully uploaded :" + imgName);
             },
             error: function (file, response) {
                 file.previewElement.classList.add("dz-error");
             },maxFiles:1,
         init: function() {
             this.on("maxfilesexceeded", function(file) {
                 this.removeAllFiles();
                 this.addFile(file);
             });
         }
         });
     });

</script>

************************* hn_SimpeFileUploader.ashx ******************************
Imports System.Web
Imports System.Web.Services

Public Class hn_SimpeFileUploader
    Implements System.Web.IHttpHandler



    Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
        context.Response.ContentType = "text/plain"

        Dim dirFullPath As String = HttpContext.Current.Server.MapPath("~/file-upload/upload-target/")
        Dim files As String()
        Dim numFiles As Integer
        files = System.IO.Directory.GetFiles(dirFullPath)
        numFiles = files.Length
        numFiles = numFiles + 1

        Dim str_image As String = ""
        Dim i As Integer
        For Each s As String In context.Request.Files
            i += 1
            Dim file As HttpPostedFile = context.Request.Files(s)
            '  int fileSizeInBytes = file.ContentLength;
            Dim fileName As String = file.FileName
            Dim fileExtension As String = file.ContentType

            If Not String.IsNullOrEmpty(fileName) Then
                'fileExtension = IO.Path.GetExtension(fileName)
                'str_image = "MyPHOTO_" & i & fileExtension
                Dim pathToSave_100 As String = HttpContext.Current.Server.MapPath("~/file-upload/upload-target/") & fileName 'str_image
                file.SaveAs(pathToSave_100)
            End If
        Next
        context.Response.Write(str_image)
    End Sub

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class

วันพุธที่ 13 พฤษภาคม พ.ศ. 2558

ฟังก์ชั่นเพื่อแก้ปัญหาปี พ.ศ. ไม่ตรงในฐานข้อมูล MS Access

    Public Function DBToDate(ByVal prmdate As Date) As Date
        Dim d As String = DateAndTime.Day(prmdate).ToString("##00")
        Dim m As String = DateAndTime.Month(prmdate).ToString("##00")
        Dim y As String = DateAndTime.Year(prmdate).ToString("##00")
        If y < 2500 Then
            y = y + 543
        End If
        Return DateValue(d & "/" & m & "/" & y)

    End Function

วันเสาร์ที่ 25 เมษายน พ.ศ. 2558

แปลงตัวเลขเป็นตัวหนังสือ คำอ่านสำหรับจำนวนเงิน


#Region "--แสดงตัวเลขเป็นตัวหนังสือ--"

    Public Function NumberToThaiWord(ByVal InputNumber As Double) As String
        If InputNumber = 0 Then
            NumberToThaiWord = "ศูนย์บาทถ้วน"
            Return NumberToThaiWord
        End If

        Dim NewInputNumber As String
        NewInputNumber = InputNumber.ToString("###0.00")

        If CDbl(NewInputNumber) >= 10000000000000 Then
            NumberToThaiWord = ""
            Return NumberToThaiWord
        End If

        Dim tmpNumber(2) As String
        Dim FirstNumber As String
        Dim LastNumber As String

        tmpNumber = NewInputNumber.Split(CChar("."))
        FirstNumber = tmpNumber(0)
        LastNumber = tmpNumber(1)

        Dim nLength As Integer = 0
        nLength = CInt(FirstNumber.Length)

        Dim i As Integer
        Dim CNumber As Integer = 0
        Dim CNumberBak As Integer = 0
        Dim strNumber As String = ""
        Dim strPosition As String = ""
        Dim FinalWord As String = ""
        Dim CountPos As Integer = 0

        For i = nLength To 1 Step -1
            CNumberBak = CNumber
            CNumber = CInt(FirstNumber.Substring(CountPos, 1))

            If CNumber = 0 AndAlso i = 7 Then
                strPosition = "ล้าน"
            ElseIf CNumber = 0 Then
                strPosition = ""
            Else
                strPosition = PositionToText(i)
            End If

            If CNumber = 2 AndAlso strPosition = "สิบ" Then
                strNumber = "ยี่"
            ElseIf CNumber = 1 AndAlso strPosition = "สิบ" Then
                strNumber = ""
            ElseIf CNumber = 1 AndAlso strPosition = "ล้าน" AndAlso nLength >= 8 Then
                If CNumberBak = 0 Then
                    strNumber = "หนึ่ง"
                Else
                    strNumber = "เอ็ด"
                End If
            ElseIf CNumber = 1 AndAlso strPosition = "" AndAlso nLength > 1 Then
                strNumber = "เอ็ด"
            Else
                strNumber = NumberToText(CNumber)
            End If

            CountPos = CountPos + 1

            FinalWord = FinalWord & strNumber & strPosition
        Next

        CountPos = 0
        CNumberBak = 0
        nLength = CInt(LastNumber.Length)

        Dim Stang As String = ""
        Dim FinalStang As String = ""

        If CDbl(LastNumber) > 0.0 Then
            For i = nLength To 1 Step -1
                CNumberBak = CNumber
                CNumber = CInt(LastNumber.Substring(CountPos, 1))

                If CNumber = 1 AndAlso i = 2 Then
                    strPosition = "สิบ"
                ElseIf CNumber = 0 Then
                    strPosition = ""
                Else
                    strPosition = PositionToText(i)
                End If

                If CNumber = 2 AndAlso strPosition = "สิบ" Then
                    Stang = "ยี่"
                ElseIf CNumber = 1 AndAlso i = 2 Then
                    Stang = ""
                ElseIf CNumber = 1 AndAlso strPosition = "" AndAlso nLength > 1 Then
                    If CNumberBak = 0 Then
                        Stang = "หนึ่ง"
                    Else
                        Stang = "เอ็ด"
                    End If
                Else
                    Stang = NumberToText(CNumber)
                End If

                CountPos = CountPos + 1

                FinalStang = FinalStang & Stang & strPosition
            Next

            FinalStang = FinalStang & "สตางค์"
        Else
            FinalStang = ""
        End If

        Dim SubUnit As String
        If FinalStang = "" Then
            SubUnit = "บาทถ้วน"
        Else
            If CDbl(FirstNumber) <> 0 Then
                SubUnit = "บาท"
            Else
                SubUnit = ""
            End If
        End If

        NumberToThaiWord = FinalWord & SubUnit & FinalStang
    End Function

    Private Function NumberToText(ByVal CurrentNum As Integer) As String
        Dim _nText As String = ""

        Select Case CurrentNum
            Case 0
                _nText = ""
            Case 1
                _nText = "หนึ่ง"
            Case 2
                _nText = "สอง"
            Case 3
                _nText = "สาม"
            Case 4
                _nText = "สี่"
            Case 5
                _nText = "ห้า"
            Case 6
                _nText = "หก"
            Case 7
                _nText = "เจ็ด"
            Case 8
                _nText = "แปด"
            Case 9
                _nText = "เก้า"
        End Select

        NumberToText = _nText
    End Function

    Private Function PositionToText(ByVal CurrentPos As Integer) As String
        Dim _nPos As String = ""

        Select Case CurrentPos
            Case 0
                _nPos = ""
            Case 1
                _nPos = ""
            Case 2
                _nPos = "สิบ"
            Case 3
                _nPos = "ร้อย"
            Case 4
                _nPos = "พัน"
            Case 5
                _nPos = "หมื่น"
            Case 6
                _nPos = "แสน"
            Case 7
                _nPos = "ล้าน"
            Case 8
                _nPos = "สิบ"
            Case 9
                _nPos = "ร้อย"
            Case 10
                _nPos = "พัน"
            Case 11
                _nPos = "หมื่น"
            Case 12
                _nPos = "แสน"
            Case 13
                _nPos = "ล้าน"
        End Select

        PositionToText = _nPos
    End Function


#End Region

การใช้ WebClient สำหรับเรียก URL

Dim _url As String = " https :// www . MyDomain . com /?q=ทดสอบ " Dim wc As New System . Net . WebClient () wc . Encodin...