Stack Trace:
******************************
[InvalidOperationException: The connection was not closed. The connection's current state is connecting.]
System.Data.ProviderBase.DbConnectionBusy.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +16
System.Data.SqlClient.SqlConnection.Open() +111
_Default.GridDisegni_Click(Object sender, GridViewCommandEventArgs e) in D:\WebFolder\PianoCamp\htdocs\Default.aspx.vb:127
System.Web.UI.WebControls.GridView.OnRowCommand(GridViewCommandEventArgs e) +105
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +199
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
DEFAULT.ASPX.VB:
************************************
Imports myFunz
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Cache.SetCacheability(HttpCacheability.NoCache)
If Not Page.IsPostBack Then
lblErr.Text = ""
lblErr2.Text = ""
If Not Request.Cookies("myUser")("id") Is Nothing Then
lblUserId.Text = Request.Cookies("myUser")("id")
End If
Bind_myPage()
End If
lblMyConn.Text = myConn.State.ToString
End Sub
Sub Bind_myPage()
Dim myCmd As SqlCommand
Try
myConn.Open()
myCmd = New SqlCommand()
myCmd.Connection = myConn
myCmd.CommandType = Data.CommandType.Text
'valorizzo lblMod
myCmd.CommandText = "SELECT Modello, Revisione FROM Settaggi"
dr = myCmd.ExecuteReader
If dr.Read Then
lblMod.Text = "Mod." & dr("Modello").ToString & " rev." & dr("Revisione").ToString
End If
dr.Close()
'carico la ddlPosiz
myCmd.CommandText = "SELECT * FROM CtrlDimPosiz ORDER BY Id"
ddlPosiz.DataValueField = "Id"
ddlPosiz.DataTextField = "Descrizione"
dr = myCmd.ExecuteReader()
ddlPosiz.DataSource = dr
ddlPosiz.DataBind()
dr.Close()
ddlPosiz.Items.Insert(0, "pos")
ddlPosiz.Items(0).Value = "0"
'carico la ddlStrum
myCmd.CommandText = "SELECT * FROM CtrlDimStrum ORDER BY Descrizione"
ddlStrum.DataValueField = "Id"
ddlStrum.DataTextField = "Descrizione"
dr = myCmd.ExecuteReader()
ddlStrum.DataSource = dr
ddlStrum.DataBind()
dr.Close()
ddlStrum.Items.Insert(0, "strumento")
ddlStrum.Items(0).Value = "0"
'carico la ddlFunzionali
myCmd.CommandText = "SELECT * FROM CtrlFunzTipi ORDER BY Descrizione"
ddlFunzionali.DataValueField = "Id"
ddlFunzionali.DataTextField = "Descrizione"
dr = myCmd.ExecuteReader()
ddlFunzionali.DataSource = dr
ddlFunzionali.DataBind()
dr.Close()
ddlFunzionali.Items.Insert(0, "controllo")
ddlFunzionali.Items(0).Value = "0"
'carico la ddlVisivi
myCmd.CommandText = "SELECT * FROM CtrlVisiviTipi ORDER BY Descrizione"
ddlVisivi.DataValueField = "Id"
ddlVisivi.DataTextField = "Descrizione"
dr = myCmd.ExecuteReader()
ddlVisivi.DataSource = dr
ddlVisivi.DataBind()
dr.Close()
ddlVisivi.Items.Insert(0, "controllo")
ddlVisivi.Items(0).Value = "0"
'valorizzo la gridview
Bind_myGrid(GridDisegni, "SELECT * FROM VIEW_Disegni ORDER BY Codice")
'chiudo la conn
myConn.Close()
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
End Sub
Sub Bind_myGrid(ByVal myGrid As GridView, ByVal myQuery As String)
lblErr.Text = ""
lblErr2.Text = ""
Try
Dim myCmd As New SqlCommand(myQuery, myConn)
dr = myCmd.ExecuteReader
myGrid.DataSource = dr
myGrid.DataBind()
dr.Close()
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
dr.Close()
End Try
End Sub
Sub Bind_myRpt(ByVal myRpt As Repeater, ByVal myQuery As String)
Try
Dim myCmd As New SqlCommand(myQuery, myConn)
dr = myCmd.ExecuteReader
myRpt.DataSource = dr
myRpt.DataBind()
dr.Close()
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
dr.Close()
End Try
End Sub
Sub GridDisegni_Click(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridDisegni.RowCommand
lblErr.Text = ""
lblErr2.Text = ""
GridDisegni.SelectedIndex = e.CommandArgument
lblId.Text = GridDisegni.SelectedValue.ToString
myId = CInt(lblId.Text)
Try
myConn.Open()
lblCod.Text = getValue("SELECT Codice FROM Disegni WHERE Id = " & myId & "")
Select Case e.CommandName
Case Is = "NewCtrl"
divElenco.Visible = False
divNewCod.Visible = False
divNewCtrl.Visible = True
divDetCod.Visible = False
divDelCod.Visible = False
lnkHome.Visible = True
lblCod.Text = "<h1>INSERIMENTO CONTROLLI - COD.N°: " & lblCod.Text & "</h1>"
Bind_myRpt(rptDimensionali, "SELECT * FROM VIEW_CtrlDimensionali WHERE IdDisegno = " & myId & " ORDER BY IdPos")
Bind_myRpt(rptFunzionali, "SELECT * FROM VIEW_CtrlFunzionali WHERE IdDisegno = " & myId & "")
Bind_myRpt(rptVisivi, "SELECT * FROM VIEW_CtrlVisivi WHERE IdDisegno = " & myId & "")
myConn.Close()
Case Is = "ViewCod"
divElenco.Visible = False
divNewCod.Visible = False
divNewCtrl.Visible = False
divDetCod.Visible = True
divDelCod.Visible = False
lnkHome.Visible = True
lblCod.Text = "<h1>Scheda disegno COD.N° [ " & lblCod.Text & " ]</h1> - (" & lblMod.Text & ")"
Case Is = "DelCod"
divElenco.Visible = False
divNewCod.Visible = False
divNewCtrl.Visible = False
divDetCod.Visible = False
divDelCod.Visible = True
lnkHome.Visible = True
lblCod.Text = "<h1>Il disegno COD.N° [ " & lblCod.Text & " ] verrà ELIMINATO</h1>"
btnDelCod.Enabled = True
Case Else
Response.Write(e.CommandName)
lnkHome.Visible = False
End Select
myConn.Close()
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
GridDisegni.SelectedIndex = -1
End Sub
Sub lnkNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkNew.Click
lblErr.Text = ""
lblErr2.Text = ""
divElenco.Visible = False
divNewCod.Visible = True
divNewCtrl.Visible = False
divDetCod.Visible = False
divDelCod.Visible = False
lnkHome.Visible = True
btnConferma.Enabled = True
myFunz.ClearForm(divNewCod)
lblCod.Text = "<h1>INSERIMENTO NUOVO CODICE</h1>"
Try
myConn.Open()
Dim myCmd As New SqlCommand
myCmd.CommandType = Data.CommandType.Text
myCmd.Connection = myConn
'carico la ddlMetodo
myCmd.CommandText = "SELECT * FROM Metodi ORDER BY Descrizione"
ddlMetodo.DataValueField = "Id"
ddlMetodo.DataTextField = "Descrizione"
dr = myCmd.ExecuteReader()
ddlMetodo.DataSource = dr
ddlMetodo.DataBind()
dr.Close()
ddlMetodo.Items.Insert(0, "Selezionare un metodo")
ddlMetodo.Items(0).Value = "0"
'carico le ddlCtrl
adp = New SqlDataAdapter("SELECT * FROM Tipi ORDER BY Descrizione", myConn)
ds = New DataSet
adp.Fill(ds)
ddlCtrl1.DataValueField = "Id"
ddlCtrl1.DataTextField = "Descrizione"
ddlCtrl2.DataValueField = "Id"
ddlCtrl2.DataTextField = "Descrizione"
ddlCtrl3.DataValueField = "Id"
ddlCtrl3.DataTextField = "Descrizione"
ddlCtrl1.DataSource = ds
ddlCtrl2.DataSource = ds
ddlCtrl3.DataSource = ds
ddlCtrl1.DataBind()
ddlCtrl1.SelectedValue = 1
ddlCtrl2.DataBind()
ddlCtrl2.SelectedIndex = 0
ddlCtrl3.DataBind()
ddlCtrl3.SelectedIndex = 0
ds.Dispose()
myConn.Close()
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
dr.Close()
myConn.Close()
End Try
End Sub
Sub btnConferma_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConferma.Click
lblErr.Text = ""
lblErr2.Text = ""
If (Codice.Text <> "" And ddlMetodo.SelectedValue <> 0) Then
Dim Funz As New myFunz
strOggi = Replace(DateTime.Now(), ".", ":")
strSql = "INSERT INTO Disegni(Codice, Serializzazione, IdMetodo, IdTipo_1, IdTipo_2, IdTipo_3, Note, DataIns, IdUser)" & _
" VALUES(@Codice, " & Funz.FormatBool(chkSer.Checked) & ", " & ddlMetodo.SelectedValue & _
", " & ddlCtrl1.SelectedValue & ", " & ddlCtrl2.SelectedValue & ", " & ddlCtrl3.SelectedValue & _
", @Note, '" & strOggi & "', " & lblUserId.Text & ")"
Try
myConn.Open()
Using myCmd = New SqlCommand(strSql, myConn)
myCmd.Parameters.AddWithValue("@Codice", Codice.Text)
myCmd.Parameters.AddWithValue("@Note", Note.Text)
myCmd.ExecuteNonQuery()
End Using
myConn.Close()
divNewCod.Visible = False
btnConferma.Enabled = False
lblErr2.Text = "Disegno COD.N° " & Codice.Text & " inserito con successo!"
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
Else
lblErr.Text = "Operazione non consentita"
lblErr2.Text = "Tutti i campi DEVONO essere compilati!"
End If
End Sub
Sub addNewDim_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles addNewDim.Click
lblErr.Text = ""
lblErr2.Text = ""
If (Quota.Text <> "" And ddlPosiz.SelectedValue <> 0 And ddlStrum.SelectedValue <> 0) Then
Dim Funz As New myFunz
myId = CInt(lblId.Text)
strOggi = Replace(DateTime.Now(), ".", ":")
strSql = "INSERT INTO CtrlDimensionali(IdDisegno, Quota, IdCtrlDimPosiz, IdCtrlDimStrum, Data)" & _
" VALUES(" & myId & ", @Quota, " & ddlPosiz.SelectedValue & ", " & ddlStrum.SelectedValue & ", '" & strOggi & "')"
Try
myConn.Open()
Using myCmd = New SqlCommand(strSql, myConn)
myCmd.Parameters.AddWithValue("@Quota", Quota.Text)
myCmd.ExecuteNonQuery()
End Using
Bind_myRpt(rptDimensionali, "SELECT * FROM VIEW_CtrlDimensionali WHERE IdDisegno = " & myId & " ORDER BY IdPos")
myConn.Close()
Quota.Text = ""
ddlPosiz.SelectedValue = 0
ddlStrum.SelectedValue = 0
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
Else
lblErr.Text = "Operazione non consentita"
lblErr2.Text = "Tutti i campi DEVONO essere compilati!"
End If
End Sub
Sub delCtrlDim(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs) Handles rptDimensionali.ItemCommand
lblErr.Text = ""
lblErr2.Text = ""
i = e.CommandArgument
strSql = "DELETE FROM CtrlDimensionali WHERE Id = " & i
myId = CInt(lblId.Text)
Dim Funz As New myFunz
Try
myConn.Open()
Using myCmd = New SqlCommand(strSql, myConn)
myCmd.ExecuteNonQuery()
End Using
Bind_myRpt(rptDimensionali, "SELECT * FROM VIEW_CtrlDimensionali WHERE IdDisegno = " & myId & " ORDER BY IdPos")
myConn.Close()
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
End Sub
Sub addNewVis_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles addNewVis.Click
lblErr.Text = ""
lblErr2.Text = ""
If ddlVisivi.SelectedValue <> 0 Then
Dim Funz As New myFunz
myId = CInt(lblId.Text)
strOggi = Replace(DateTime.Now(), ".", ":")
strSql = "INSERT INTO CtrlVisivi(IdDisegno, IdCtrlVisiviTipi, Data)" & _
" VALUES(" & myId & ", " & ddlVisivi.SelectedValue & ", '" & strOggi & "')"
Try
myConn.Open()
Using myCmd = New SqlCommand(strSql, myConn)
myCmd.ExecuteNonQuery()
End Using
Bind_myRpt(rptVisivi, "SELECT * FROM VIEW_CtrlVisivi WHERE IdDisegno = " & myId & "")
myConn.Close()
ddlVisivi.SelectedValue = 0
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
Else
lblErr.Text = "Operazione non consentita"
lblErr2.Text = "Tutti i campi DEVONO essere compilati!"
End If
End Sub
Sub delCtrlVis(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs) Handles rptVisivi.ItemCommand
lblErr.Text = ""
lblErr2.Text = ""
i = e.CommandArgument
strSql = "DELETE FROM CtrlVisivi WHERE Id = " & i
myId = CInt(lblId.Text)
Dim Funz As New myFunz
Try
myConn.Open()
Using myCmd = New SqlCommand(strSql, myConn)
myCmd.ExecuteNonQuery()
End Using
Bind_myRpt(rptVisivi, "SELECT * FROM VIEW_CtrlVisivi WHERE IdDisegno = " & myId & "")
myConn.Close()
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
End Sub
Sub addNewFunz_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles addNewFunz.Click
lblErr.Text = ""
lblErr2.Text = ""
If ddlFunzionali.SelectedValue <> 0 Then
Dim Funz As New myFunz
myId = CInt(lblId.Text)
strOggi = Replace(DateTime.Now(), ".", ":")
strSql = "INSERT INTO CtrlFunzionali(IdDisegno, IdCtrlFunzTipi, Data)" & _
" VALUES(" & myId & ", " & ddlFunzionali.SelectedValue & ", '" & strOggi & "')"
Try
myConn.Open()
Using myCmd = New SqlCommand(strSql, myConn)
myCmd.ExecuteNonQuery()
End Using
Bind_myRpt(rptFunzionali, "SELECT * FROM VIEW_CtrlFunzionali WHERE IdDisegno = " & myId & "")
myConn.Close()
ddlFunzionali.SelectedValue = 0
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
Else
lblErr.Text = "Operazione non consentita"
lblErr2.Text = "Tutti i campi DEVONO essere compilati!"
End If
End Sub
Sub delCtrlFunz(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs) Handles rptFunzionali.ItemCommand
lblErr.Text = ""
lblErr2.Text = ""
i = e.CommandArgument
strSql = "DELETE FROM CtrlFunzionali WHERE Id = " & i
myId = CInt(lblId.Text)
Dim Funz As New myFunz
Try
myConn.Open()
Using myCmd = New SqlCommand(strSql, myConn)
myCmd.ExecuteNonQuery()
End Using
Bind_myRpt(rptFunzionali, "SELECT * FROM VIEW_CtrlFunzionali WHERE IdDisegno = " & myId & "")
myConn.Close()
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
End Sub
Sub btnDelCod_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelCod.Click
lblErr.Text = ""
lblErr2.Text = ""
myId = CInt(lblId.Text)
Dim myTrans As SqlTransaction
Dim myCmd As New SqlCommand
Try
myConn.Open()
myTrans = myConn.BeginTransaction
myCmd = myConn.CreateCommand
myCmd.Connection = myConn
myCmd.Transaction = myTrans
myCmd.CommandText = "DELETE FROM Disegni WHERE Id = " & myId
myCmd.ExecuteNonQuery()
myCmd.CommandText = "DELETE FROM CtrlDimensionali WHERE IdDisegno = " & myId
myCmd.ExecuteNonQuery()
myCmd.CommandText = "DELETE FROM CtrlFunzionali WHERE IdDisegno = " & myId
myCmd.ExecuteNonQuery()
myCmd.CommandText = "DELETE FROM CtrlVisivi WHERE IdDisegno = " & myId
myCmd.ExecuteNonQuery()
myTrans.Commit()
myConn.Close()
lblErr2.Text = "Operazione riuscita con successo!"
btnDelCod.Enabled = False
Catch ex As SqlException
Try
myTrans.Rollback()
Catch ex2 As SqlException
If Not myTrans.Connection Is Nothing Then
lblErr.Text = ex2.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = "An exception of type " & ex2.GetType().ToString() & " was encountered while attempting to roll back the transaction."
End If
End Try
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
End Sub
Sub lnkHome_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHome.Click
lblCod.Text = ""
lblId.Text = ""
lnkHome.Visible = False
divDelCod.Visible = False
divDetCod.Visible = False
divNewCtrl.Visible = False
divNewCod.Visible = False
divElenco.Visible = True
myConn.Open()
Bind_myGrid(GridDisegni, "SELECT * FROM VIEW_Disegni ORDER BY Codice")
myConn.Close()
End Sub
Function getValue(ByVal myQuery As String)
Using myCmd As New SqlCommand(myQuery, myConn)
getValue = myCmd.ExecuteScalar()
Return getValue
End Using
End Function
End Class
***********************************
APP_CODE\MYFUNZ.VB
**********************************
Imports System
Imports System.Configuration
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Web.Mail
Imports System.Web.Security
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text.RegularExpressions
Imports Microsoft.VisualBasic
Public Class myFunz
Public Shared WithEvents lblErr As Label
Public Shared WithEvents lblErr2 As Label
' Dichiaro la connessione usando i dati su web.config
Public Shared myConn As New SqlConnection(ConfigurationManager.AppSettings("SqlConn"))
Public Shared dr As SqlDataReader
Public Shared ds As DataSet
Public Shared adp As SqlDataAdapter
Public Shared strSql, strSql2, strSql3, strSql4, strErrJava As String
Public Shared myId, i As Integer
Public Shared myRegExp, strErrore, strOggi, strUserID, strAziendaID, strMailBody, strMailSubject, strMailTo As String
Public Shared myUsername, myPassword As String
Public Shared myBool As Boolean
Public Function FixString(ByVal strToFix As String) As String
FixString = Replace(strToFix, "'", "''")
End Function
Public Function CheckString(ByVal strToCheck, ByVal strRegExp)
Dim re As New Regex(strRegExp)
CheckString = re.IsMatch(strToCheck)
End Function
Public Function CheckForm(ByVal divForm As HtmlGenericControl)
For i = 0 To divForm.Controls.Count - 1
If divForm.Controls(i).GetType Is GetType(TextBox) Then
If Left(CType(divForm.Controls(i), TextBox).ID, 1) = "o" And CType(divForm.Controls(i), TextBox).Text = "" Then
Return False
Else
Return True
End If '<>""
End If 'getType(textBox)
Next i
End Function
Public Shared Sub ClearForm(ByVal divItem As HtmlGenericControl)
'Pulisco le textBox del controllo DIV incriminato
For i = 0 To divItem.Controls.Count - 1
Dim strControl As String = divItem.Controls(i).ID
If divItem.Controls(i).GetType Is GetType(TextBox) Then
Dim myControl As TextBox = DirectCast(divItem.Controls(i), TextBox)
myControl.Text = ""
ElseIf divItem.Controls(i).GetType Is GetType(HtmlInputCheckBox) Then
Dim myControl As HtmlInputCheckBox = DirectCast(divItem.Controls(i), HtmlInputCheckBox)
myControl.Checked = False
ElseIf divItem.Controls(i).GetType Is GetType(Label) Then
Dim myControl As Label = DirectCast(divItem.Controls(i), Label)
myControl.Text = ""
End If
Next i
End Sub
Public Sub DisableForm(ByVal divItem As HtmlGenericControl)
'Pulisco le textBox del controllo DIV incriminato
For i = 0 To divItem.Controls.Count - 1
Dim strControl As String = divItem.Controls(i).ID
If divItem.Controls(i).GetType Is GetType(TextBox) Then
Dim myControl As TextBox = DirectCast(divItem.Controls(i), TextBox)
myControl.Enabled = False
ElseIf divItem.Controls(i).GetType Is GetType(HtmlInputCheckBox) Then
Dim myControl As HtmlInputCheckBox = DirectCast(divItem.Controls(i), HtmlInputCheckBox)
myControl.Disabled = True
ElseIf divItem.Controls(i).GetType Is GetType(CheckBox) Then
Dim myControl As CheckBox = DirectCast(divItem.Controls(i), CheckBox)
myControl.Enabled = False
ElseIf divItem.Controls(i).GetType Is GetType(DropDownList) Then
Dim myControl As DropDownList = DirectCast(divItem.Controls(i), DropDownList)
myControl.Enabled = False
End If
Next i
End Sub
Public Sub BindForm(ByVal strSql As String, ByVal divEditItem As HtmlGenericControl)
Dim myCmd As New SqlCommand(strSql, myConn)
Try
If myConn.State.ToString <> "Open" Then myConn.Open()
dr = myCmd.ExecuteReader()
If dr.Read Then
'Valorizzo i controlli di DIV incriminato
For i = 0 To divEditItem.Controls.Count - 1
Dim strControl As String = divEditItem.Controls(i).ID
If divEditItem.Controls(i).GetType Is GetType(TextBox) Then
Dim myControl As TextBox = DirectCast(divEditItem.Controls(i), TextBox)
If Not IsDBNull(dr(strControl).ToString) Then
myControl.Text = dr(strControl).ToString
End If
ElseIf divEditItem.Controls(i).GetType Is GetType(HtmlInputCheckBox) Then
Dim myControl As HtmlInputCheckBox = DirectCast(divEditItem.Controls(i), HtmlInputCheckBox)
myControl.Checked = dr(strControl)
ElseIf divEditItem.Controls(i).GetType Is GetType(DropDownList) Then
Dim myControl As DropDownList = DirectCast(divEditItem.Controls(i), DropDownList)
myControl.SelectedValue = dr(strControl)
ElseIf divEditItem.Controls(i).GetType Is GetType(Label) Then
Dim myControl As Label = DirectCast(divEditItem.Controls(i), Label)
If Not IsDBNull(dr(strControl).ToString) Then
myControl.Text = dr(strControl).ToString
End If
End If
Next i
End If 'dr.read
dr.Close()
Catch ex As SqlException
lblErr.Text = ex.Number & " - Errore durante l'accesso ai dati!"
lblErr2.Text = ex.Message
Finally
myConn.Close()
End Try
End Sub
Public Function FormattaEuro(ByVal Prezzo)
If Not IsDBNull(Prezzo) Then
Return CDec(Prezzo).ToString("#,##0.00 ¤")
Else
Return "0,00 ¤"
End If
End Function
Shared Function FormattaChk(ByVal stato As Boolean)
If stato Then
Return "a_vis.gif"
Else
Return "a_hid.gif"
End If
End Function
Public Function FormatBool(ByVal myStr As String)
If myStr <> "True" Then
Return 0
Else
Return 1
End If
End Function
Public Function TrimTesto(ByVal Testo As String)
If Testo <> "" Then
Dim LenMax As Integer = 40 'lunghezza massima consentita
Dim LenFrase As Integer = Len(Testo) 'lunghezza totale della frase
If LenFrase > LenMax Then
Dim TempFrase As String = ""
Dim LastChar As String = "a"
Dim i As Integer = LenMax
While LastChar <> " "
TempFrase = Left(Testo, i)
LastChar = Right(TempFrase, 1)
i = i - 1
If i = 0 Then
LastChar = " "
End If
End While
If i <> 0 Then
TempFrase = Left(Testo, i) & " ..."
Else
TempFrase = Left(Testo, LenMax)
End If
Return TempFrase
Else
Return Testo
End If
Else 'testo = ""
Return "n/a"
End If
End Function
Public Function chkLink(ByVal myHref, ByVal myString) As String
If Not IsDBNull(myHref) Then
Return "<a href='http://" & myHref & "' target='_blank' class='link11'>" & myString & "</a>"
Else
Return myString
End If
End Function
End Class
************************************