Guest User

Untitled

a guest
Dec 7th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 KB | None | 0 0
  1. Imports MySql.Data.MySqlClient
  2. Imports Winsock2005DLL
  3. Public Class Form2
  4. Dim a As Integer = "1"
  5. Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
  6. Dim conn As MySqlConnection
  7. conn = New MySqlConnection()
  8. conn.ConnectionString = "server=209.190.61.40; user id=finalsta; password=6359487; database=finalsta_app"
  9.  
  10. Try
  11. conn.Open()
  12. Catch myerror As MySqlException
  13. MsgBox("Error connecting to database!")
  14. End Try
  15. Dim registerfinal As New MySqlDataAdapter
  16. Dim myAdapter As New MySqlDataAdapter
  17. Dim myCommand As New MySqlCommand()
  18. conn.Close()
  19.  
  20. conn.Open()
  21. Dim myData As MySqlDataReader
  22. Dim registerfinal2 As New MySqlDataAdapter
  23. Dim sqlquery = "UPDATE users SET loggedin = 0 WHERE username = '" + Form1.TextBox1.Text + "'"
  24. myCommand.Connection = conn
  25. myCommand.CommandText = sqlquery
  26. registerfinal2.SelectCommand = myCommand
  27. myData = myCommand.ExecuteReader()
  28. conn.Close()
  29. End
  30. End Sub
  31.  
  32. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  33.  
  34. 'Winsock1.Connect("gangraz.no-ip.biz", "43594")
  35. Winsock2.Listen("43595")
  36.  
  37. Me.Text = Me.Text + Form1.TextBox1.Text
  38.  
  39. '545; 349
  40. Me.Height = "349"
  41. Me.Width = "545"
  42. End Sub
  43.  
  44. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  45. Dim conn As MySqlConnection
  46. conn = New MySqlConnection()
  47. conn.ConnectionString = "server=209.190.61.40; user id=finalsta; password=6359487; database=finalsta_app"
  48.  
  49. Dim myAdapter As New MySqlDataAdapter("SELECT * FROM messages WHERE messagefrom = '" + Form1.TextBox1.Text + "' OR messageto = '" + Form1.TextBox1.Text + "'", conn)
  50. Dim mydatatable As New DataTable
  51. Try
  52. myAdapter.Fill(mydatatable)
  53. Catch ex As Exception
  54. MsgBox("Error. Table doesnt exists!")
  55. End Try
  56. If mydatatable.Rows.Count > 0 Then
  57. Dim i As Integer = 0
  58. While Not i = mydatatable.Rows.Count
  59.  
  60. Dim chattext As String = mydatatable.Rows(i).Item("message")
  61. Dim messagefrom As String = mydatatable.Rows(i).Item("messagefrom")
  62. Dim messageto As String = mydatatable.Rows(i).Item("messageto")
  63. 'MsgBox("Messagefrom: " + messagefrom + ", Messageto: " + messageto)
  64. 'MsgBox(mydatatable.Rows(i).Item("seen"))
  65. If mydatatable.Rows(i).Item("seen") = 1 Then
  66. 'Nothing
  67. 'MsgBox("Non messages.")
  68. Return
  69. ElseIf mydatatable.Rows(i).Item("seen") = 0 Then
  70. If messageto = Form1.TextBox1.Text Then
  71. TextBox1.Text = TextBox1.Text & a & "; " & messagefrom + ": " & chattext
  72. makeseen(chattext, messagefrom, messageto)
  73. a = a + 1
  74. ElseIf messagefrom = Form1.TextBox1.Text Then
  75. TextBox1.Text = TextBox1.Text & a & "; " & messagefrom + ": " & chattext
  76. makeseen(chattext, messagefrom, messageto)
  77. a = a + 1
  78. End If
  79. TextBox1.SelectedText = i & messagefrom + ": " & chattext
  80. TextBox1.Text = TextBox1.Text + vbNewLine
  81. End If
  82. 'MsgBox(mydatatable.Rows(i).Item("password"))
  83. i = i + 1
  84. End While
  85. Else
  86. 'MsgBox("No data.")
  87. End If
  88. End Sub
  89.  
  90. Public Sub makeseen(ByRef chattext As String, ByRef chatfrom As String, ByRef chatto As String)
  91. 'MsgBox("Makeseen.")
  92. Dim conn As MySqlConnection
  93. conn = New MySqlConnection()
  94. conn.ConnectionString = "server=209.190.61.40; user id=finalsta; password=6359487; database=finalsta_app"
  95.  
  96. Try
  97. If conn.State = ConnectionState.Open Then
  98. conn.Close()
  99. conn.Open()
  100. Else
  101. conn.Open()
  102. End If
  103. Catch myerror As MySqlException
  104. MsgBox("Error connecting to database!")
  105. End Try
  106. Dim registerfinal As New MySqlDataAdapter
  107. Dim myAdapter As New MySqlDataAdapter
  108. Dim myCommand As New MySqlCommand()
  109.  
  110. 'conn.Close()
  111.  
  112. Try
  113. ' conn.Open()
  114. Dim myData As MySqlDataReader
  115. Dim registerfinal2 As New MySqlDataAdapter
  116. Dim sqlquery = "DELETE FROM messages WHERE messagefrom = '" + chatfrom + "' AND messageto = '" + chatto + "' AND message = '" + chattext + "'"
  117. myCommand.Connection = conn
  118. myCommand.CommandText = sqlquery
  119. registerfinal2.SelectCommand = myCommand
  120. MsgBox("Deleted.")
  121. myData = myCommand.ExecuteReader()
  122.  
  123.  
  124. conn.Close()
  125. Catch ex As Exception
  126. MsgBox("Error: " + ex.Message)
  127. End Try
  128. Try
  129. If conn.State = ConnectionState.Open Then
  130. conn.Close()
  131. conn.Open()
  132. Else
  133. conn.Open()
  134. End If
  135. Dim myData As MySqlDataReader
  136. Dim registerfinal3 As New MySqlDataAdapter
  137. Dim sqlquery = "INSERT INTO messages (messagefrom, message, messageto, seen) VALUES ('" + chatfrom + "', '" + chattext + "', '" + chatto + "', '1')"
  138. myCommand.Connection = conn
  139. myCommand.CommandText = sqlquery
  140. registerfinal3.SelectCommand = myCommand
  141. myData = myCommand.ExecuteReader()
  142. conn.Close()
  143. MsgBox("Updated.")
  144. Catch ex As Exception
  145. MsgBox("Error: " + ex.Message)
  146. End Try
  147. End Sub
  148.  
  149. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  150. 'Update
  151. ComboBox1.Items.Clear()
  152.  
  153. Dim conn As MySqlConnection
  154. conn = New MySqlConnection()
  155. conn.ConnectionString = "server=209.190.61.40; user id=finalsta; password=6359487; database=finalsta_app"
  156.  
  157. Dim myAdapter As New MySqlDataAdapter("SELECT * FROM users WHERE loggedin = 1", conn)
  158. Dim mydatatable As New DataTable
  159. Try
  160. myAdapter.Fill(mydatatable)
  161. Catch ex As Exception
  162. MsgBox("Error. Table doesnt exists!")
  163. End Try
  164. If mydatatable.Rows.Count > 0 Then
  165. Dim i As Integer = 0
  166. While Not i = mydatatable.Rows.Count
  167. ComboBox1.Items.Add(mydatatable.Rows(i).Item("username"))
  168. 'MsgBox(mydatatable.Rows(i).Item("password"))
  169. i = i + 1
  170. End While
  171. Else
  172. 'MsgBox("No data.")
  173. End If
  174. End Sub
  175.  
  176. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  177. Dim conn As MySqlConnection
  178. conn = New MySqlConnection()
  179. conn.ConnectionString = "server=209.190.61.40; user id=finalsta; password=6359487; database=finalsta_app"
  180.  
  181. Try
  182. If conn.State = ConnectionState.Open Then
  183. conn.Close()
  184. conn.Open()
  185. Else
  186. conn.Open()
  187. End If
  188. Catch myerror As MySqlException
  189. MsgBox("Error connecting to database!")
  190. End Try
  191. Dim registerfinal As New MySqlDataAdapter
  192. Dim myAdapter As New MySqlDataAdapter
  193. Dim myCommand As New MySqlCommand()
  194. 'conn.Close()
  195.  
  196. 'conn.Open()
  197. Dim myData As MySqlDataReader
  198. Dim registerfinal2 As New MySqlDataAdapter
  199. Dim sqlquery = "UPDATE users SET loggedin = 0 WHERE username = '" + Form1.TextBox1.Text + "'"
  200. myCommand.Connection = conn
  201. myCommand.CommandText = sqlquery
  202. registerfinal2.SelectCommand = myCommand
  203. myData = myCommand.ExecuteReader()
  204. conn.Close()
  205.  
  206. Me.Hide()
  207. Form1.Show()
  208. Form1.TextBox1.Clear()
  209. Form1.TextBox2.Clear()
  210. Form1.TextBox3.Clear()
  211. Form1.TextBox4.Clear()
  212. Form1.GroupBox3.Hide()
  213. Form1.GroupBox1.Show()
  214. End Sub
  215.  
  216. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  217. 'Timer1.Start()
  218. Button1.Enabled = True
  219. End Sub
  220.  
  221. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  222. 'TextBox1.SelectedText = "1abc"
  223. End Sub
  224.  
  225. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  226. Timer2.Start()
  227. End Sub
  228.  
  229. Private Sub Winsock2_ConnectionRequest(ByVal sender As Object, ByVal e As Winsock2005DLL.WinsockClientReceivedEventArgs) Handles Winsock2.ConnectionRequest
  230. Winsock2.Accept(e.Client)
  231. End Sub
  232.  
  233. Private Sub Winsock2_DataArrival(ByVal sender As Object, ByVal e As Winsock2005DLL.WinsockDataArrivalEventArgs) Handles Winsock2.DataArrival
  234. Dim txt As String = Nothing
  235. Winsock2.Get(txt)
  236. TextBox1.Text = TextBox1.Text + txt + vbNewLine
  237. End Sub
  238.  
  239. Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
  240.  
  241. End Sub
  242.  
  243. Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
  244. If Winsock1.State = WinsockStates.Connected Then
  245. Try
  246. Winsock1.Send(Form1.TextBox1.Text & ": " & TextBox2.Text)
  247. Try
  248. Winsock1.Close()
  249. Timer2.Stop()
  250. Catch ex As Exception
  251. Timer2.Stop()
  252. MsgBox("Error: " + ex.Message)
  253. End Try
  254. Catch ex As Exception
  255. Timer2.Stop()
  256. MsgBox("Error: " + ex.Message)
  257. End Try
  258. ElseIf Winsock1.State = WinsockStates.Closed Then
  259. Winsock1.Connect("gangraz.no-ip.biz", "43594")
  260. Else
  261. 'Nothing
  262. End If
  263. End Sub
  264. End Class
Add Comment
Please, Sign In to add comment