Imports System.Data.SqlClient

Public Class ChatNSBottom
        Inherits System.Web.UI.Page
        Protected WithEvents btFakeRecieve As System.Web.UI.WebControls.Button
        Protected WithEvents btSend As System.Web.UI.WebControls.Button
        Protected WithEvents txtSendMessage As System.Web.UI.WebControls.TextBox
        Protected WithEvents txtUserID As System.Web.UI.WebControls.TextBox
        Protected WithEvents txtChatID As System.Web.UI.WebControls.TextBox
        Protected WithEvents tblNewMessages As System.Web.UI.WebControls.Table

#Region "Developer Credits"
        '=======================================================================================
        'AUTHOR                  : David Silverlight
        '
        'CLAIM TO FAME      : Head Geek at XMLPitstop.com and CoFounder of NonProfitWays.com
        '
        'EMAIL                      : HeadGeek@XMLPitstop.com
        '
        'SHAMELESS PLUG  :Yes I am a consultant who is always looking for cool projects.
        '
        'PHONE                    : (561) 212-5707  Coconut Grove, Florida
        '
        'COPYWRIGHT		: This demo is not copywrighted so feel free to use it however may help you.  Credit is always appreciated,
        '                                  but not required.  I created it simply for the learning experience. If you have any suggestions on areas that 
        '                                  can be improved upon, please feel free to email me.  All credit for enhancements will be given to 
        '                                  those who suggest them.  Enjoy.
        '=======================================================================================
#End Region

#Region " Web Form Designer Generated Code "

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
                'CODEGEN: This method call is required by the Web Form Designer
                'Do not modify it using the code editor.
                InitializeComponent()
        End Sub

#End Region

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                'Put user code to initialize the page here
                txtUserID.Text = Session("UserID")
                txtChatID.Text = Session("ChatID")

        End Sub

        Private Sub btSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSend.Click

                Try
                        Dim strUserID As String = txtUserID.Text
                        Dim strChatID As String = txtChatID.Text
                        Dim strStatus = ""
                        If Trim(txtSendMessage.Text) <> "" Then
                                SendMessage(txtSendMessage.Text, strChatID, strUserID)
                        End If
                        txtSendMessage.Text = ""
                Catch ex As Exception
                        txtSendMessage.Text = ex.Message
                End Try
        End Sub
        Function SendMessage(ByVal strMessage As String, ByVal strChatID As String, ByVal strUserID As String)

                Try
                        strMessage = Replace(strMessage, "'", "`")

                        Dim strMessages As String
                        Dim cn As New SqlConnection(ConfigurationSettings.AppSettings().Item("cnChat"))
                        Dim cmd As New SqlCommand()
                        Dim strSQL As String = "exec sp_insChatMessage " & strChatID & ", " & strUserID & ", '" & strMessage & "'"
                        cn.Open()
                        cmd.Connection = cn
                        cmd.CommandText = strSQL
                        cmd.ExecuteNonQuery()

                        '      doSetFocus("")
                        Return ""
                Catch ex As Exception
                        Return "Error: " & ex.Message
                End Try

        End Function

End Class
