Torna al Thread

Imports System.Data Imports System.Data.SqlClient Imports System.IO Public Class Profilo Inherits System.Web.UI.Page Dim conn As New SqlConnection("Data Source=xx.xxx.xxx.xx;Initial Catalog=xxxxxxx;Persist Security Info=True;User ID=xxxxxxx;Password=xxxxxxxxxxxxxxx") Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Page.IsPostBack Then Exit Sub End If FileUpload1.Enabled = False Button15.Enabled = False Label28.Enabled = False Label1.Text = HttpContext.Current.User.Identity.Name Dim query As String = "select * from utenti WHere username = '" + HttpContext.Current.User.Identity.Name + "'" Dim cmd As New SqlCommand(query, conn) Dim tbutenti As New DataTable Try conn.Open() tbutenti.Load(cmd.ExecuteReader) Catch ex As Exception MsgBox(ex.Message) Finally conn.Close() End Try If tbutenti.Rows.Count > 0 Then Label23.Text = tbutenti.Rows(0).Item(2).ToString Label24.Text = tbutenti.Rows(0).Item(3).ToString Label25.Text = tbutenti.Rows(0).Item(5).ToString Label26.Text = FormatDateTime(tbutenti.Rows(0).Item(4).ToString, DateFormat.ShortDate) Label27.Text = tbutenti.Rows(0).Item(7).ToString End If If Not tbutenti.Rows(0).Item(6).ToString = "" Then Dim dire As String = ("~/Utenti/" + tbutenti.Rows(0).Item(1) + "/" + tbutenti.Rows(0).Item(6)) Image1.ImageUrl = dire Else Image1.ImageUrl = "~/Template/Immagini/no_avatar.jpg" End If TextBox23.Visible = False TextBox24.Visible = False TextBox25.Visible = False TextBox26.Visible = False TextBox27.Visible = False Label23.Visible = True Label24.Visible = True Label25.Visible = True Label26.Visible = True Label27.Visible = True Button11.Visible = True Button12.Visible = False Button13.Visible = False Directory.SetCurrentDirectory(Server.MapPath("~/Utenti/" + tbutenti.Rows(0).Item(1))) End Sub Protected Sub Button11_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button11.Click TextBox23.Text = Label23.Text TextBox24.Text = Label24.Text TextBox25.Text = Label25.Text TextBox26.Text = Label26.Text TextBox27.Text = Label27.Text TextBox23.Visible = True TextBox24.Visible = True TextBox25.Visible = True TextBox26.Visible = True TextBox27.Visible = True Label23.Visible = False Label24.Visible = False Label25.Visible = False Label26.Visible = False Label27.Visible = False Button12.Visible = True Button13.Visible = True Button11.Visible = False End Sub Protected Sub Button13_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button13.Click Button12.Visible = False Button13.Visible = False Button11.Visible = True TextBox23.Visible = False TextBox24.Visible = False TextBox25.Visible = False TextBox26.Visible = False TextBox27.Visible = False Label23.Visible = True Label24.Visible = True Label25.Visible = True Label26.Visible = True Label27.Visible = True End Sub Protected Sub Button12_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button12.Click Dim query As String = "update utenti SET nome = @nome, cognome = @cognome, dnascita = @dnascita, email = @email, citta = @citta WHERE username = '" + HttpContext.Current.User.Identity.Name + "'" Dim cmd As New SqlCommand(query, conn) cmd.Parameters.Add("@nome", SqlDbType.VarChar) cmd.Parameters.Add("@cognome", SqlDbType.VarChar) cmd.Parameters.Add("@dnascita", SqlDbType.DateTime) cmd.Parameters.Add("@email", SqlDbType.VarChar) cmd.Parameters.Add("@citta", SqlDbType.VarChar) cmd.Parameters("@nome").Value = TextBox23.Text cmd.Parameters("@cognome").Value = TextBox24.Text If TextBox26.Text = "" Or TextBox26.Text Is Nothing Then cmd.Parameters("@dnascita").Value = FormatDateTime("01/01/1990", DateFormat.ShortDate) Else cmd.Parameters("@dnascita").Value = FormatDateTime(TextBox26.Text, DateFormat.ShortDate) End If cmd.Parameters("@email").Value = TextBox25.Text cmd.Parameters("@citta").Value = TextBox27.Text Try conn.Open() cmd.ExecuteNonQuery() Catch ex As Exception MsgBox(ex.Message) Finally conn.Close() End Try query = "select * from utenti WHere username = '" + HttpContext.Current.User.Identity.Name + "'" cmd = New SqlCommand(query, conn) Dim tbutenti As New DataTable Try conn.Open() tbutenti.Load(cmd.ExecuteReader) Catch ex As Exception MsgBox(ex.Message) Finally conn.Close() End Try If tbutenti.Rows.Count > 0 Then Label23.Text = tbutenti.Rows(0).Item(2).ToString Label24.Text = tbutenti.Rows(0).Item(3).ToString Label25.Text = tbutenti.Rows(0).Item(5).ToString Label26.Text = FormatDateTime(tbutenti.Rows(0).Item(4).ToString, DateFormat.ShortDate) Label27.Text = tbutenti.Rows(0).Item(7).ToString End If If Not tbutenti.Rows(0).Item(6).ToString = "" Then Dim dire As String = ("~/Utenti/" + tbutenti.Rows(0).Item(1) + "/" + tbutenti.Rows(0).Item(6)) Image1.ImageUrl = dire Else Image1.ImageUrl = "~/Template/Immagini/no_avatar.jpg" End If Button12.Visible = False Button13.Visible = False Button11.Visible = True TextBox23.Visible = False TextBox24.Visible = False TextBox25.Visible = False TextBox26.Visible = False TextBox27.Visible = False Label23.Visible = True Label24.Visible = True Label25.Visible = True Label26.Visible = True Label27.Visible = True End Sub Protected Sub Button14_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button14.Click FileUpload1.Enabled = True Button15.Enabled = True Label28.Enabled = True FileUpload1.Focus() End Sub Protected Sub Button15_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button15.Click If FileUpload1.HasFile Then Dim percorso As String = CurDir() + "\" + FileUpload1.FileName Try FileUpload1.SaveAs(percorso) Catch ex As Exception MsgBox(ex.Message) End Try Else FileUpload1.Enabled = True Button15.Enabled = True Label28.Enabled = True Exit Sub End If Dim query As String = "update utenti set avatar='" + FileUpload1.FileName + "' WHERE username = '" + HttpContext.Current.User.Identity.Name + "'" Dim command As New SqlCommand(query, conn) Try conn.Open() command.ExecuteNonQuery() Catch ex As Exception MsgBox(ex.Message) Finally conn.Close() End Try query = "select * from utenti WHere username = '" + HttpContext.Current.User.Identity.Name + "'" command = New SqlCommand(query, conn) Dim tbutenti As New DataTable Try conn.Open() tbutenti.Load(command.ExecuteReader) Catch ex As Exception MsgBox(ex.Message) Finally conn.Close() End Try If Not tbutenti.Rows(0).Item(6).ToString = "" Then Dim dire As String = ("~/Utenti/" + tbutenti.Rows(0).Item(1) + "/" + tbutenti.Rows(0).Item(6)) Image1.ImageUrl = dire Else Image1.ImageUrl = "~/Template/Immagini/no_avatar.jpg" End If FileUpload1.Enabled = True Button15.Enabled = True Label28.Enabled = True End Sub End Class
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5