Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2004
    Messaggi
    2

    conversione da ASP

    Salve amici programmatori e non ,
    sono un neofita; avrei bisogno di realizzare in vb.net queste funzioni; un mio collega mi ha lasciato queste stesse realizzate in ASPe vb script; quete comprendono il classico login con username e password , modifica dati utente, inserimento nuovo utente, cancellazione, etc
    vi porto il codice, anche se č lungo. Non vi chiedo di farmi ola traduzione riga pr riga, per caritā sarebbe troppo ma di fornirmi delle linee guida affinche lo possa fare da solo ,premesso che di asp so poco e nulla e che mi sono da poco avvicinato a VB.NET

    codice:
    . Login.asp
    
    <% 
    dim user, password, oUtente
    user = request.Form("user")
    password=request.Form("password")
    set oUtente = New Utente
    if oUtente.Login (user,password) then
    		set oUtente = nothing
    		response.Redirect("../ep.asp")
    	else
    		response.Redirect("../index.asp?messaggio=Login Errato")
    end if 
    'response.Write(user & password)
    
    'response.write request.Cookies("Tipo")
    %>
    
    	3.2. Utente.asp
    
    
    <script language="vbscript">
    
    	Class Utente
    		public function controllo (byVal User)
    			Application.Lock()
    			if (Application(User) = "") then
    				Application (User) = User 
    				controllo = true
    			else
    				controllo = false
    			end if
    			Application.UnLock()
    		end function
    		
    		public function Login (byVal UserName, byval Password )
    			if controllo (UserName) = true then
    				dim oRS
    				set oRS = server.CreateObject("ADODB.Recordset")
    				oRS.ActiveConnection = connectstring
    				oRS.CursorType = adOpenDynamic
    				oRS.Source = "select * from UtentiEp where UserName = '" + UserName + "' and Password ='" + Password + "' ;"
    				oRS.open 
    				if not oRS.EOF then
    					session.Contents("UserName") = oRS("UserName")
    					session.Contents("Tipo") = oRS("Tipo")
    					
    					' Inserisci nome, cognome '
    					
    					session.timeout = 10
    					login = true
    					else
    					login = false
    					Application(UserName) = ""
    				end if 
    				oRS.close 
    				set oRS = nothing
    				
    			else 'UTENTE CONNESSO
    				login = false
    			end if
    		end function
    		
    		public sub logout ()
    			Application(Session.Contents("UserName")) = ""
    			Session.Contents("UserName") = ""
    			'Nome = null
    			'Cognome = null
    			session.Contents("Tipo") = ""
    			session.Abandon()
    		end sub
    		
    		public function Inserisci_Nuovo(byval Nome, byVal Cognome, ByVal UserName, ByVal Password, ByVal Tipo)
    			dim oRS
    			set oRS = server.CreateObject("ADODB.Recordset")
    			oRS.ActiveConnection = connectstring
    			oRS.CursorType = adOpenDynamic
    			oRS.Source = "select * from UtentiEp where UserName = '" + UserName + "' ;"
    			oRS.open 
    			if oRS.EOF then
    				oRS.addnew
    					oRS ("UserName") = UserName
    					oRS ("Password") = Password
    					oRS ("Tipo") = Tipo
    				oRS.update
    				Inserisci_Nuovo = true
    			else
    				Inserisci_Nuovo = false
    			end if
    			oRS.close
    		end function
    		
    		public function Elimina (byVal UserName)
    			dim oRS
    			set oRS = server.CreateObject("ADODB.Recordset")
    			oRS.ActiveConnection = connectstring
    			oRS.CursorType = adOpenDynamic
    			oRS.Source = "select * from UtentiEp where UserName = '" + UserName + "' ;"
    			oRS.open 
    			if (not oRS.EOF) then
    				oRS.delete
    				Elimina = true
    				else
    				Elimina = false
    
    			end if
    			oRS.close
    		end function
    		
    		public function Modifica (byval Nome, byVal Cognome, ByVal UserName, ByVal Password, ByVal Tipo)
    			dim oRS
    			set oRS = server.CreateObject("ADODB.Recordset")
    			oRS.ActiveConnection = connectstring
    			oRS.CursorType = adOpenDynamic
    			oRS.Source = "select * from UtentiEp where UserName = '" + UserName + "' ;"
    			oRS.open 
    			if not oRS.EOF then
    				oRS("Password") = Password
    				oRS("Tipo") = Tipo
    				oRS.update
    				Modifica=true
    			else
    				Modifica=false
    			end if
    			oRS.close
    		end function
    		
    	End Class
    </script>
    
    	3.3. Logout.asp
    <script language="vbscript" runat="server">
    	session.Abandon()
    	response.Redirect(../index.htm)
    </script>
    <html>
    <head>
    <title>Documento senza titolo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    </body>
    </html>
    
    3.4. connection.asp
    
    <%
    	connectstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= c:\inetpub\wwwroot\mioep\_mdb\mydata.mdb; Persist Security Info=False "
    %>
    
    3.4. VisBacheca.asp
    
    
    <html>
    <head><title>Visualizza bacheca</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    .Stile1 {color: #CCCCCC}
    body {
    	background-color: #003063;
    }
    -->
    </style>
    </head>
    <body>
    <div align="center">
      <table width="80%" height="50%" border="1" align="center" bordercolor="#000000" bgcolor="#CCCCCC">
        <tr>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1">
            <div align="center">ID</div>
          </div></td>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1">Testo</div></td>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1">Data</div></td>
        </tr>
        <% 
    'qui inizia lo script lato sever
    Set cn = Server.CreateObject("ADODB.Connection")
    Set rs = Server.CreateObject("ADODB.RecordSet")
    cn.Open connectstring
    
    'Ora, componiamo la stringa SQL di interrogazione. Potete
    'estendere una stringa su pių di una linea utilizzando
    'il carattere "_"
    
    sql="SELECT Bacheca.ID, Bacheca.Testo, Bacheca.Data FROM Bacheca ORDER BY Bacheca.Data DESC;"
    
    'Ora č il momento di eseguire la nostra interrogazione.
    rs.Open sql, cn
    
    'itera attraverso il recordset finchč
    'non viene raggiunta la fine del file (EOF) 
    do while not rs.EOF
    %>
        <tr>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1"><%Response.Write rs("ID")%>
          </div></td>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1"><%Response.Write rs("Testo")%>
          </div></td>
    	  <td valign="top" bgcolor="#003366"><div align="center" class="Stile1"><%Response.Write rs("Data")%>
          </div></td>
    	 <!-- <td valign="top"><div align="center">
    	    <input type="radio" checked>
    	  </div></td> -->
        </tr>
        <%
      ' spostati sul prossimo record
      rs.MoveNext 
    loop
    
    ' chiudi gli oggetti recordset e connection
    rs.Close    
    cn.Close
    
    ' libera le risorse
    Set rs = nothing 
    Set cn = nothing
    %>
      </table>
    </div>
    </body>
    
    3.5	scrivi.asp
    
    
    <%
    	if request.Form("Testo") <> "" then
    		dim Testo
    		Testo = request.Form ("Testo")
    		set Bac = new Bacheca
    		if Bac.InsNewMes(Testo) then 
    			response.redirect ("../Bacheca/VisualizzaBac.asp")
    		end if
    		set Bac = nothing
    	else
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Documento senza titolo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    body {
    background-color: #003366;
    }
    -->
    </style></head>
    
    <body>
    <form name="form1" method="post" action="./scrivi.asp">
    <table  align="center" border="0">
    <tr>
    <td valign="top"><div align="center">
    <textarea name="Testo" cols="40" rows="10"></textarea>
    </div></td>
    </tr>
    <tr>
    <td valign="top" align="right"><input type="submit" name="Scrivi" value="Scrivi" v></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    
    <%
    end if
    %>
    
    cancella.asp
    
    
    <html>
    <head>
    <body>
    
    <style type="text/css">
    <!--
    body {
    	background-color: #003063;
    }
    -->
    </style>
    <form action="../Bacheca/cancBac.asp" method="post" name="form1">
      <table border="1" align="center" bordercolor="#000000" bgcolor="#CCCCCC">
        <tr>
          <td valign="top" bgcolor="#003366"></td>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1">
              <div align="center">ID</div>
          </div></td>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1">Testo</div></td>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1">Data</div></td>
        </tr>
        <% 
    'qui inizia lo script lato sever
    Set cn = Server.CreateObject("ADODB.Connection")
    Set rs = Server.CreateObject("ADODB.RecordSet")
    cn.Open connectstring
    
    'Ora, componiamo la stringa SQL di interrogazione. Potete
    'estendere una stringa su pi&ugrave; di una linea utilizzando
    'il carattere "_"
    
    sql="SELECT Bacheca.ID, Bacheca.Testo, Bacheca.Data FROM Bacheca ORDER BY Bacheca.Data DESC;"
    
    'Ora &egrave; il momento di eseguire la nostra interrogazione.
    rs.Open sql, cn
    
    'itera attraverso il recordset finch&egrave;
    'non viene raggiunta la fine del file (EOF) 
    do while not rs.EOF
    %>
        <tr>
          <td valign="top" bgcolor="#003366"><input name="<%="chk" & rs("ID")%>" onClick="myclick('<%=rs("ID")%>')" type="checkbox"></td>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1">
              <%Response.Write rs("ID")%>
          </div></td>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1">
              <%Response.Write rs("Testo")%>
          </div></td>
          <td valign="top" bgcolor="#003366"><div align="center" class="Stile1">
              <%Response.Write rs("Data")%>
          </div></td>
        </tr>
    <%
      ' spostati sul prossimo record
      rs.MoveNext 
      I=I+1
    loop
    
    ' chiudi gli oggetti recordset e connection
    rs.Close    
    cn.Close
    
    ' libera le risorse
    Set rs = nothing 
    Set cn = nothing
    %>
        <tr>
          <td colspan="4" align="right" valign="top" bgcolor="#003366"><input name="cancella" type="submit" value="cancella"></td>
    	</tr>
      </table>
    </form>
    </body>
    </head>
    </html>
    spero do non aver chiesto troppo

  2. #2
    Utente di HTML.it L'avatar di MMarzia
    Registrato dal
    Mar 2001
    Messaggi
    1,781
    linguaggio e versione anche nel titolo
    io sono festosamente cicciottello :: e. cartman

    t'amo senza sapere come, nč quando nč da dove,
    t'amo direttamente senza problemi nč orgoglio:
    cosė ti amo perchč non so amare altrimenti

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.