Advertisement
Guest User

Untitled

a guest
May 4th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. Imports System.Data.SqlClient
  2. Imports System.Data.SqlClient.SqlDataAdapter
  3. Partial Class _Default
  4. Inherits System.Web.UI.Page
  5. 'Dim nFicheiro As String
  6. Dim CONNSTR As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\GSIb04.mdf;Integrated Security=True;User Instance=True"
  7.  
  8. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  9.  
  10. End Sub
  11.  
  12. Protected Sub envregalu_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles envregalu.Click
  13.  
  14.  
  15. If aluregcod.Text <> "" And aluregnome.Text <> "" And aluregpass.Text <> "" And alureguser.Text <> "" And aluregcontacto.Text <> "" Then
  16.  
  17. Dim conn As New SqlConnection(CONNSTR)
  18. Dim query As String = "SELECT A_COD, A_USERNAME FROM ALUNO WHERE A_USERNAME = '" & alureguser.Text & "'"
  19. Dim commd As New SqlCommand(query, conn)
  20. Dim dr As SqlDataReader
  21.  
  22. conn.Open()
  23. dr = commd.ExecuteReader()
  24.  
  25.  
  26. If dr.HasRows = True Then
  27. Label1.Text = "Username j� existente! Escolha outro Username por favor. Obrigado!"
  28.  
  29. Else
  30.  
  31. Dim conn1 As New SqlConnection(CONNSTR)
  32. Dim sp As New SqlCommand("ADICIONAR_ALUNO", conn1)
  33. sp.CommandType = Data.CommandType.StoredProcedure
  34.  
  35. Dim A_COD As New SqlParameter("@A_COD", Data.SqlDbType.Int)
  36. A_COD.Value = aluregcod.Text
  37. sp.Parameters.Add(A_COD)
  38.  
  39. Dim A_NOME As New SqlParameter("@A_NOME", Data.SqlDbType.NChar)
  40. A_NOME.Value = aluregnome.Text
  41. sp.Parameters.Add(A_NOME)
  42.  
  43. Dim A_CONTACTO As New SqlParameter("@A_TLF", Data.SqlDbType.NChar)
  44. A_CONTACTO.Value = aluregcontacto.Text
  45. sp.Parameters.Add(A_CONTACTO)
  46.  
  47. Dim A_AREA_COD As New SqlParameter("@A_AREA_COD", Data.SqlDbType.Int)
  48. A_AREA_COD.Value = areainteressedrop.Text
  49. sp.Parameters.Add(A_AREA_COD)
  50.  
  51. Dim A_CUR_COD As New SqlParameter("@A_CUR_COD", Data.SqlDbType.Int)
  52. A_CUR_COD.Value = dropdowncurso.Text
  53. sp.Parameters.Add(A_CUR_COD)
  54.  
  55. Dim A_MORADA As New SqlParameter("@A_MORADA", Data.SqlDbType.NChar)
  56. A_MORADA.Value = aluregmorada.Text
  57. sp.Parameters.Add(A_MORADA)
  58.  
  59.  
  60. Dim A_EMAIL As New SqlParameter("@A_EMAIL", Data.SqlDbType.NChar)
  61. A_EMAIL.Value = aluregmail.Text
  62. sp.Parameters.Add(A_EMAIL)
  63.  
  64. Dim A_USERNAME As New SqlParameter("@A_USERNAME", Data.SqlDbType.NChar)
  65. A_USERNAME.Value = alureguser.Text
  66. sp.Parameters.Add(A_USERNAME)
  67.  
  68. Dim A_PASSWORD As New SqlParameter("@A_PASSWORD", Data.SqlDbType.NChar)
  69. A_PASSWORD.Value = aluregpass.Text
  70. sp.Parameters.Add(A_PASSWORD)
  71.  
  72. Dim password As String = aluregpass.Text
  73. Dim password2 As String = aluregpass2.Text
  74.  
  75. If aluregpass.Text.Length < 6 Then
  76. Label1.Text = "Password tem de ter no minimo 6 caracteres"
  77. Else
  78. If Not password = password2 Then
  79. Label1.Text = "Passwords n�o coincidem"
  80. Else
  81.  
  82. If (Not aluregcv.PostedFile Is Nothing And aluregcv.PostedFile.FileName <> "") Then
  83. Dim nFicheiro As String = System.IO.Path.GetFileName(aluregcv.PostedFile.FileName)
  84.  
  85.  
  86. If nFicheiro.Substring(nFicheiro.IndexOf(".")).Equals(".pdf") Then
  87. nFicheiro = NomeFicheiro()
  88.  
  89.  
  90. Dim aluregcv As New SqlParameter("@A_CV", System.Data.SqlDbType.NVarChar)
  91. aluregcv.Value = nFicheiro
  92. sp.Parameters.Add(aluregcv)
  93.  
  94.  
  95. conn1.Open()
  96. sp.ExecuteNonQuery()
  97. conn1.Close()
  98. Response.Redirect("RegistoSucesso.aspx")
  99. Else
  100. MsgBox("S� � permitido ficheiros pdf")
  101. Return
  102. End If
  103. End If
  104. End If
  105. End If
  106. conn.Close()
  107. dr.Close()
  108. End If
  109. Else
  110. Label1.Text = ("Preencha os dados obrigat�rios")
  111. End If
  112.  
  113.  
  114.  
  115. End Sub
  116.  
  117. Public ReadOnly Property NomeFicheiro()
  118. Get
  119.  
  120.  
  121. Dim nFicheiro As String
  122. Dim dirficheiro As String = Server.MapPath("~\curriculos\")
  123.  
  124. If (Not aluregcv.PostedFile Is Nothing) Then
  125.  
  126. nFicheiro = System.IO.Path.GetFileName(aluregcv.PostedFile.FileName)
  127. If nFicheiro.Substring(nFicheiro.IndexOf(".")).Equals(".pdf") Then
  128. Dim aux As Integer = nFicheiro.IndexOf(".")
  129. Dim primNome As String = nFicheiro.Substring(0, aux)
  130. Dim tipoFich As String = nFicheiro.Substring(aux)
  131. Dim novoFic As String = primNome & "_" & aluregnome.Text & tipoFich
  132. aluregcv.PostedFile.SaveAs(dirficheiro + novoFic)
  133. Return novoFic
  134. End If
  135.  
  136. End If
  137.  
  138.  
  139. End Get
  140. End Property
  141.  
  142. Protected Sub aluregnumero_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles aluregcod.TextChanged
  143.  
  144. End Sub
  145.  
  146. Protected Sub aluregmorada_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles aluregmorada.TextChanged
  147.  
  148. End Sub
  149.  
  150. Protected Sub areainteressedrop_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles areainteressedrop.SelectedIndexChanged
  151.  
  152. End Sub
  153. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement