home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / corsovb / utente.cls < prev   
Encoding:
Visual Basic class definition  |  1997-11-03  |  3.6 KB  |  131 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CContatto"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. Rem Lista errori restituiti
  13.  
  14. Rem 0   Nessun Errore
  15. Rem 1   Errore generico
  16. Rem 2   Errore relativo alla data di nascita
  17.  
  18. Private PNome As String
  19. Private PCognome As String
  20. Private PIndirizzo As String
  21. Private PData As Date
  22. Private PTelCasa As String
  23. Private PTelUfficio As String
  24. Private PTelFax As String
  25. Private PTelCellulare As String
  26. Private PEMail As String
  27. Private PNote As String
  28. Private PError As Integer
  29. Private PErrDescription As String
  30. Private Tabella As Recordset
  31. Private SQLStatement As String
  32.  
  33. Public Event OnError()
  34.  
  35. Public Property Get Nome() As String
  36.     Nome = PNome
  37.     ReturnError (0)
  38. End Property
  39.  
  40. Public Property Let Nome(TNome As String)
  41.     If Len(TNome) > 30 Then
  42.         If MsgBox("Attenzione! Il nome inserito contiene pi∙ di 30 caratteri. Si desidera troncare il nome a lunghezza 30?", vbYesNo, "Contact Manager v1.0") = vbNo Then Exit Property
  43.     End If
  44.     PNome = Left$(TNome, 30)
  45.     ReturnError (0)
  46. End Property
  47.  
  48. Private Sub ReturnError(ErrorCode As Integer)
  49.     If ErrorCode = 0 Then
  50.         PError = 0
  51.         PErrDescription = ""
  52.         Exit Sub
  53.     End If
  54.     If ErrorCode = 1 Then
  55.         PError = 1
  56.         PErrDescription = "Errore generico"
  57.         Exit Sub
  58.     End If
  59.     If ErrorCode = 2 Then
  60.         PError = 2
  61.         PErrDescription = "Errore relativo alla data di nascita"
  62.         Exit Sub
  63.     End If
  64. End Sub
  65.  
  66. Public Property Get Cognome() As String
  67.     Cognome = PCognome
  68.     ReturnError (0)
  69. End Property
  70.  
  71. Public Property Let Cognome(TCognome As String)
  72.     If Len(TCognome) > 30 Then
  73.         If MsgBox("Attenzione! Il cognome inserito contiene pi∙ di 30 caratteri. Si desidera troncarlo a lunghezza 30?", vbYesNo, "Contact Manager v1.0") = vbNo Then Exit Property
  74.     End If
  75.     PCognome = Left$(TCognome, 30)
  76.     ReturnError (0)
  77. End Property
  78.  
  79. Public Property Get Indirizzo() As String
  80.     Indirizzo = PIndirizzo
  81.     ReturnError (0)
  82. End Property
  83.  
  84. Public Property Let Indirizzo(TIndirizzo As String)
  85.     If Len(TIndirizzo) > 100 Then
  86.         If MsgBox("Attenzione! L'indirizzo inserito contiene pi∙ di 100 caratteri. Si desidera troncarlo a lunghezza 100?", vbYesNo, "Contact Manager v1.0") = vbNo Then Exit Property
  87.     End If
  88.     PIndirizzo = Left$(TIndirizzo, 100)
  89.     ReturnError (0)
  90. End Property
  91.  
  92. Public Property Get Data() As Date
  93.     Data = PData
  94.     ReturnError (0)
  95. End Property
  96.  
  97. Public Property Let Data(TData As Date)
  98.     If DateDiff("d", Now, TData) < 3650 Then
  99.         Rem MsgBox "La data inserita Φ troppo vicina a quella odierna. E' necessario cambiarla!", vbExclamation, "Contacts Manager v1.0"
  100.         ReturnError (2)
  101.         RaiseEvent OnError
  102.         Exit Property
  103.     End If
  104.     PData = TData
  105.     ReturnError (0)
  106. End Property
  107.  
  108. Public Property Get Error() As Integer
  109.     Error = PError
  110. End Property
  111.  
  112. Public Property Get ErrDescription() As String
  113.     ErrDescription = PErrDescription
  114. End Property
  115.  
  116. Public Function Exist(Source As Database) As Boolean
  117.        
  118.     SQLStatement = "SELECT * FROM CONTATTI WHERE NOME='" + PNome + "' AND COGNOME='" + PCognome + "'"
  119.     Set Tabella = Source.OpenRecordset(SQLStatement)
  120.     If Tabella.RecordCount Then
  121.         Tabella.Close
  122.         Set Tabella = Nothing
  123.         Exist = True
  124.     Else
  125.         Tabella.Close
  126.         Set Tabella = Nothing
  127.         Exist = False
  128.     End If
  129.     
  130. End Function
  131.