본문 바로가기
VB.net

실시간 알람 공지

by 호야호잇 2018. 3. 19.

실시간 알람공지


팝업하는 객체클래스 C#코딩한거



PopupMsgbox.zip





먼저 버튼34, Label78.text 한개, 

해당 파일을 참조 추가해야 한다 



실행할 버튼

Private Sub Button34_Click(sender As System.Object, e As System.EventArgs) Handles Button34.Click

        Label78.Text = "" ' 비교할 데이터

        '실시간 알람호출

        Dim DBConn As SqlConnection

        DBConn = New SqlConnection(dbstring)

        DBConn.Open()

        Dim mySqlCommAND As SqlCommand

        Dim QueryString As String

        QueryString = "SELECT TOP 1 공지제목, 내용1, 내용2, 파일명, No FROM TB_TopkisNews order by No Desc"

        mySqlCommAND = New SqlCommand(QueryString, DBConn)

        Dim DBread As SqlDataReader = mySqlCommAND.ExecuteReader()


        If DBread.Read() Then

            RichTextBox1.Rtf = DBread.GetValue(1)

            Dim strPath As String = Application.StartupPath & "\TopMsgbox.log"

            Dim strBuff As String = ""

            If Dir(strPath) <> "" Then  '읽을파일이 존재 한다면

                Dim sr As StreamReader = File.OpenText(strPath) '읽어들일 파일을 열어준다.

                Label78.Text = sr.ReadToEnd() '전체 텍스트 읽어오기

                sr.Close()

            End If


            If DBread.GetValue(0) <> Label78.Text Then

                PMSG.showPopupMsg(DBread.GetValue(0), "공지사항", 50000, 0) ' pop-up뛰우기


                '저장하기

                Dim objWriter As StreamWriter = _

                    New StreamWriter(Application.StartupPath & "\TopMsgbox.log") '파일이름 및 위치

                Dim strTxt As String = ""

                strTxt = DBread.GetValue(0)

                objWriter.Write(strTxt)

                objWriter.Close()


                With TOP_CARE_Popup

                    .Label1.Text = DBread.GetValue(4) '번호

                    .Label3.Text = DBread.GetValue(0) '번호

                    .RichTextBox1.Rtf = DBread.GetValue(1)

                    If DBread.GetValue(3) <> "" Then

                        .Label2.Text = DBread.GetValue(3)

                        .Button1.Visible = True

                    Else

                        .Button1.Visible = False

                    End If

                End With


            Else

            End If

        End If

        DBread.Close()

        mySqlCommAND.Dispose()

        DBConn.Close()


    End Sub


팝업 눌렀을때의 이벤트

    Private Sub PMSG_OnMessageClick(ByVal sender As Object, ByVal sIDX As Object)

        '팝업창을 클릭 했을때 이벤트.

        TOP_CARE_Popup.Show()

        TOP_CARE_Popup.Text = sIDX


        'MsgBox("팝업을 눌렀음:" & sIDX)

    End Sub



시작 Form로드에 반드시 추가

        PMSG = New PopupMsgbox.Main(Me.Top, Me.Left)

        AddHandler PMSG.OnMessageClick, AddressOf PMSG_OnMessageClick


최상단 

 Public PMSG As PopupMsgbox.Main



마지막으로 타임걸어서 확인하면됨



출처: http://byhwan.tistory.com/entry/실시간-공지알람MSN형태?category=535198# [By Hwan]