home *** CD-ROM | disk | FTP | other *** search
- Imports System.Data.SqlClient
- Public Class Documento
- Public Key As String
- Public ondb As Boolean
- Private mIdDocumento As Integer
- Private mIntestatario As Integer
- Private mData As Date
- Private mTipo As String
- Private mTotaleDocumento As Decimal
- Private mColRigaDocumento As ColRigaDocumento
- Private mDescrizioneIntestatario As String
-
- Public Property DescrizioneIntestatario() As String
- Get
- DescrizioneIntestatario = mDescrizioneIntestatario
- End Get
- Set(ByVal Value As String)
- mDescrizioneIntestatario = Value
- End Set
- End Property
-
- Public Property ColRigaDocumento() As ColRigaDocumento
- Get
- If mColRigaDocumento Is Nothing Then
- mColRigaDocumento = New ColRigaDocumento()
- End If
- ColRigaDocumento = mColRigaDocumento
- End Get
- Set(ByVal Value As ColRigaDocumento)
- mColRigaDocumento = Value
- End Set
- End Property
- Public Sub RetrivelistRigaDocumento()
- Dim objRigaDocumento As RigaDocumento
- Dim QuerySql As String
- QuerySql = "select * from RigaDocumento where IdDocumento=" & IdDocumento
- Dim ObjCommand As New SqlCommand(QuerySql, ObjConnection)
- Dim ObjReader As SqlDataReader = ObjCommand.ExecuteReader()
- mColRigaDocumento = New ColRigaDocumento()
- Try
- While ObjReader.Read()
- objRigaDocumento = New RigaDocumento()
- With objRigaDocumento
- .IdRiga = ObjReader.GetInt32(0)
- .Key = .IdRiga
- .IdDocumento = ObjReader.GetInt32(1)
- .IdArticolo = ObjReader.GetInt32(2)
- .Quantita = ObjReader.GetValue(3)
- .PrezzoCosto = ObjReader.GetDecimal(4)
- .Iva = ObjReader.GetValue(5)
- .ondb = True
- End With
- mColRigaDocumento.Add(objRigaDocumento)
- End While
- Finally
- ObjReader.Close()
- End Try
- End Sub
-
-
- Public Property IdDocumento() As Integer
- Get
- IdDocumento = mIdDocumento
- End Get
- Set(ByVal Value As Integer)
- mIdDocumento = Value
- End Set
- End Property
- Public Property Intestatario() As Integer
- Get
- Intestatario = mIntestatario
- End Get
- Set(ByVal Value As Integer)
- mIntestatario = Value
- End Set
- End Property
- Public Property Data() As Date
- Get
- Data = mData
- End Get
- Set(ByVal Value As Date)
- mData = Value
- End Set
- End Property
- Public Property Tipo() As String
- Get
- Tipo = mTipo
- End Get
- Set(ByVal Value As String)
- mTipo = Value
- End Set
- End Property
- Public Property TotaleDocumento() As Decimal
- Get
- TotaleDocumento = mTotaleDocumento
- End Get
- Set(ByVal Value As Decimal)
- mTotaleDocumento = Value
- End Set
- End Property
- Public Sub Salva()
- Dim sp As SqlCommand
- Dim spPar As SqlParameter
- Dim ObjReader As SqlDataReader
- Dim strSql As String
- If ondb = True Then
- strSql = "up_update_Documento"
- Else
- strSql = "up_insert_Documento"
- End If
- sp = New SqlCommand(strSql, ObjConnection)
- sp.CommandType = CommandType.StoredProcedure
- spPar = sp.Parameters.Add("@IdDocumento", SqlDbType.Int, 4)
- spPar.Value() = IdDocumento
- If ondb = False Then spPar.Direction = ParameterDirection.InputOutput
- spPar = sp.Parameters.Add("@Intestatario", SqlDbType.Int, 4)
- spPar.Value() = Intestatario
- spPar = sp.Parameters.Add("@Data", SqlDbType.DateTime, 16)
- spPar.Value() = Data
- spPar = sp.Parameters.Add("@Tipo", SqlDbType.Char, 1)
- spPar.Value() = Tipo
- spPar = sp.Parameters.Add("@TotaleDocumento", SqlDbType.Money, 8)
- spPar.Value() = TotaleDocumento
- Try
- ObjReader = sp.ExecuteReader()
- Catch e As Exception
- MsgBox(e.Message)
- Finally
- ObjReader.Close()
- End Try
- If ondb = False Then IdDocumento = sp.Parameters.Item("@IdDocumento").Value
- CancellaRighe()
- Dim tmpriga As RigaDocumento
- For Each tmpriga In ColRigaDocumento.Elements
- tmpriga.IdDocumento = Me.IdDocumento
- tmpriga.Salva()
- Next
-
- ondb = True
- End Sub
- Private Sub CancellaRighe()
- Dim tmpriga As New RigaDocumento()
- tmpriga.IdDocumento = Me.IdDocumento
- tmpriga.Cancella()
- tmpriga = Nothing
- End Sub
- Public Sub Cancella()
- If ondb = False Then Exit Sub
- Dim sp As SqlCommand
- Dim spPar As SqlParameter
- Dim ObjReader As SqlDataReader
- Dim strSql As String
- strSql = "up_delete_Documento"
- sp = New SqlCommand(strSql, ObjConnection)
- sp.CommandType = CommandType.StoredProcedure
- spPar = sp.Parameters.Add("@IdDocumento", SqlDbType.Int, 4)
- spPar.Value() = IdDocumento
- ' spPar = sp.Parameters.Add("@Tipo", SqlDbType.Char, 1)
- ' spPar.Value() = Tipo
- Try
- ObjReader = sp.ExecuteReader()
- Catch e As Exception
- MsgBox(e.Message)
- Finally
- ObjReader.Close()
- End Try
- End Sub
- Public Sub Ricerca(ByVal StringaRicerca As String)
- Dim QuerySql As String
- QuerySql = "select * from Documento"
- If StringaRicerca <> "" Then
- StringaRicerca = " where " + Right(StringaRicerca, Len(StringaRicerca) - 4)
- End If
- QuerySql = QuerySql + StringaRicerca
- Dim ObjCommand As New SqlCommand(QuerySql, ObjConnection)
- Dim ObjReader As SqlDataReader = ObjCommand.ExecuteReader()
- Try
- While ObjReader.Read()
- IdDocumento = ObjReader.GetInt32(0)
- Intestatario = ObjReader.GetInt32(1)
- Data = ObjReader.GetDateTime(2)
- Tipo = ObjReader.GetString(3)
- TotaleDocumento = ObjReader.GetDecimal(4)
- ondb = True
- End While
- Finally
- ObjReader.Close()
- End Try
- End Sub
-
-
- End Class
-