home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / Member.cls < prev    next >
Text File  |  1997-11-01  |  17KB  |  502 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Member"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Option Explicit
  11.  
  12. Function AddNew(ByVal strFileDSN As String, ByVal strFirstName As String, ByVal strLastName As String, ByVal strMiddleName As String, ByVal strKnownAs As String, _
  13.      ByVal strGender As String, ByVal strAddress1 As String, ByVal strAddress2 As String, ByVal strCity As String, ByVal strState As String, ByVal strPostCode As String, _
  14.      ByVal strCountry As String, ByVal strHomePhone As String, ByVal strBusinessPhone As String, ByVal strFax As String, ByVal strEmail As String, _
  15.      ByVal strWebSite As String, ByVal strMeal As String, ByVal strSeating As String, _
  16.      ByVal strExitRow As String, ByVal lngMileage As Long)
  17.  
  18.     Dim objContext As ObjectContext
  19.     Set objContext = GetObjectContext
  20.     
  21.     On Error GoTo ErrorHandler
  22.     
  23.     Dim strSQL As String
  24.     Dim lngAccountID As Long
  25.     Dim cnn As New ADODB.Connection
  26.     Dim arrReturn(2)
  27.     Dim strPassword As String
  28.     
  29.     arrReturn(0) = 0
  30.     strPassword = InventPassword()
  31.     
  32.     'TakeANumber generates a unique account number and insures that no one will
  33.     'concurrently choose the same number
  34.     
  35.     ' This method is in another class, so have to "objContext.CreateInstance"
  36.     '   Note that should not CreateObject in this circumstance, because if
  37.     '   CreateObject, will get a NEW transaction that cannot see the work
  38.     '   done in this (calling) transaction
  39.     Dim TakeANum As Object
  40.     Set TakeANum = objContext.CreateInstance("MTS_TakeANumber.TakeANumber")
  41.     lngAccountID = TakeANum.GetANumber(strFileDSN, "AccountID")
  42.         
  43.     strSQL = "INSERT INTO Member " & _
  44.                           "(Password, " & _
  45.                           "AccountID, " & _
  46.                           "FirstName, " & _
  47.                           "LastName, " & _
  48.                           "MiddleName, " & _
  49.                           "KnownAs, " & _
  50.                           "Gender, " & _
  51.                           "Address1, " & _
  52.                           "Address2, " & _
  53.                           "City, " & _
  54.                           "State, " & _
  55.                           "PostCode, " & _
  56.                           "Country, " & _
  57.                           "HomePhone, " & _
  58.                           "BusinessPhone, " & _
  59.                           "Fax, " & _
  60.                           "Email, " & _
  61.                           "Mileage, " & _
  62.                           "WebSite, " & _
  63.                           "Meal, " & _
  64.                           "Seating, " & _
  65.                           "ExitRow)"
  66.         
  67.     strSQL = strSQL & _
  68.                         "VALUES ('" & _
  69.                                 SQLEncode(strPassword) & "', " & _
  70.                                 lngAccountID & ", '" & _
  71.                                 SQLEncode(strFirstName) & "', '" & _
  72.                                 SQLEncode(strLastName) & "', '" & _
  73.                                 SQLEncode(strMiddleName) & "', '" & _
  74.                                 SQLEncode(strKnownAs) & "', '" & _
  75.                                 SQLEncode(strGender) & "', '" & _
  76.                                 SQLEncode(strAddress1) & "', '" & _
  77.                                 SQLEncode(strAddress2) & "', '" & _
  78.                                 SQLEncode(strCity) & "', '" & _
  79.                                 SQLEncode(strState) & "', '" & _
  80.                                 SQLEncode(strPostCode) & "', '" & _
  81.                                 SQLEncode(strCountry) & "', '" & _
  82.                                 SQLEncode(strHomePhone) & "', '" & _
  83.                                 SQLEncode(strBusinessPhone) & "', '" & _
  84.                                 SQLEncode(strFax) & "', '" & _
  85.                                 SQLEncode(strEmail) & "', " & _
  86.                                 lngMileage & ", '" & _
  87.                                 SQLEncode(strWebSite) & "', '" & _
  88.                                 SQLEncode(strMeal) & "', '" & _
  89.                                 SQLEncode(strSeating) & "', '" & _
  90.                                 SQLEncode(strExitRow) & "')"
  91.                                 
  92.     cnn.Open "FileDSN=" & strFileDSN
  93.     cnn.Execute (strSQL)
  94.     
  95.     objContext.SetComplete
  96.     AddNew = lngAccountID
  97.     Exit Function
  98.     
  99. ErrorHandler:
  100.     If Not cnn Is Nothing Then Set cnn = Nothing
  101.  
  102.     objContext.SetAbort
  103.     Err.Raise Err.Number, "Member.AddNew()", Err.Description
  104.  
  105. End Function
  106.  
  107. Function Update(ByVal strFileDSN As String, ByVal lngAccountID As Long, ByVal strFirstName As String, ByVal strLastName As String, ByVal strMiddleName As String, ByVal strKnownAs As String, _
  108.      ByVal strGender As String, ByVal strAddress1 As String, ByVal strAddress2 As String, ByVal strCity As String, ByVal strState As String, ByVal strPostCode As String, _
  109.      ByVal strCountry As String, ByVal strHomePhone As String, ByVal strBusinessPhone As String, ByVal strFax As String, ByVal strEmail As String, _
  110.      ByVal strWebSite As String, ByVal strMeal As String, ByVal strSeating As String, _
  111.      ByVal strExitRow As String)
  112.  
  113.     Dim objContext As ObjectContext
  114.     Set objContext = GetObjectContext
  115.     
  116.     On Error GoTo ErrorHandler
  117.     
  118.     Dim strSQL As String
  119.     Dim cnn As New ADODB.Connection
  120.     strSQL = "UPDATE Member " & _
  121.         "SET FirstName = '" & SQLEncode(strFirstName) & "'," & _
  122.             "LastName = '" & SQLEncode(strLastName) & "'," & _
  123.             "MiddleName = '" & SQLEncode(strMiddleName) & "'," & _
  124.             "KnownAs = '" & SQLEncode(strKnownAs) & "'," & _
  125.             "Gender = '" & SQLEncode(strGender) & "'," & _
  126.             "Address1 = '" & SQLEncode(strAddress1) & "'," & _
  127.             "Address2 = '" & SQLEncode(strAddress2) & "'," & _
  128.             "City = '" & SQLEncode(strCity) & "'," & _
  129.             "State = '" & SQLEncode(strState) & "'," & _
  130.             "PostCode = '" & SQLEncode(strPostCode) & "'," & _
  131.             "Country = '" & SQLEncode(strCountry) & "'," & _
  132.             "HomePhone = '" & SQLEncode(strHomePhone) & "'," & _
  133.             "BusinessPhone = '" & SQLEncode(strBusinessPhone) & "'," & _
  134.             "Fax = '" & SQLEncode(strFax) & "'," & _
  135.             "Email = '" & SQLEncode(strEmail) & "'," & _
  136.             "WebSite = '" & SQLEncode(strWebSite) & "'," & _
  137.             "Meal = '" & SQLEncode(strMeal) & "'," & _
  138.             "Seating = '" & SQLEncode(strSeating) & "'," & _
  139.             "ExitRow = '" & SQLEncode(strExitRow) & "'" & _
  140.         "WHERE AccountID = " & lngAccountID
  141.         
  142.     cnn.Open "FILEDSN=" & strFileDSN
  143.     cnn.Execute strSQL
  144.     
  145.     objContext.SetComplete
  146.     
  147.     Exit Function
  148.  
  149. ErrorHandler:
  150.     If Not cnn Is Nothing Then Set cnn = Nothing
  151.  
  152.     objContext.SetAbort
  153.     Err.Raise Err.Number, "Member.Update()", Err.Description
  154.     
  155. End Function
  156.  
  157. Function ChangePassword(ByVal strFileDSN As String, ByVal lngAccountID As Long, _
  158.      ByVal strPassword As String)
  159.  
  160.     Dim objContext As ObjectContext
  161.     Set objContext = GetObjectContext
  162.     
  163.     On Error GoTo ErrorHandler
  164.     
  165.     Dim strSQL As String
  166.     Dim cnn As New ADODB.Connection
  167.     strSQL = "UPDATE Member " & _
  168.         "SET Password = '" & SQLEncode(strPassword) & "' " & _
  169.         "WHERE AccountID = " & lngAccountID
  170.         
  171.     cnn.Open "FILEDSN=" & strFileDSN
  172.     cnn.Execute strSQL
  173.     
  174.     objContext.SetComplete
  175.     
  176.     Exit Function
  177.  
  178. ErrorHandler:
  179.     If Not cnn Is Nothing Then Set cnn = Nothing
  180.  
  181.     objContext.SetAbort
  182.     Err.Raise Err.Number, "Member.ChangePassword()", Err.Description
  183.     
  184. End Function
  185.  
  186. Function Remove(ByVal strFileDSN As String, ByVal lngAccountID As Long)
  187.     
  188.     Dim objContext As ObjectContext
  189.     Set objContext = GetObjectContext
  190.     
  191.     On Error GoTo ErrorHandler
  192.     
  193.     Dim strSQL As String
  194.     Dim cnn As New ADODB.Connection
  195.     
  196.     strSQL = "DELETE FROM Member WHERE AccountID = " & lngAccountID
  197.     cnn.Open "FILEDSN=" & strFileDSN
  198.     cnn.Execute strSQL
  199.     
  200.     objContext.SetComplete
  201.     
  202.     Exit Function
  203.  
  204. ErrorHandler:
  205.     If Not cnn Is Nothing Then Set cnn = Nothing
  206.  
  207.     objContext.SetAbort
  208.     Err.Raise Err.Number, "Member.Remove()", Err.Description
  209.  
  210. End Function
  211.  
  212. Function UpdateInterests(ByVal strFileDSN As String, ByVal lngAccountID As Long, Interests)
  213.     
  214.     Dim objContext As ObjectContext
  215.     Set objContext = GetObjectContext
  216.     
  217.     On Error GoTo ErrorHandler
  218.     
  219.     Dim strSQL As String
  220.     Dim cnn As New ADODB.Connection, varItem As Variant
  221.  
  222.     strSQL = "DELETE FROM MembersInterests WHERE AccountID = " & lngAccountID
  223.     
  224.     cnn.Open "FILEDSN=" & strFileDSN
  225.     cnn.Execute strSQL
  226.     For Each varItem In Interests
  227.         strSQL = "INSERT INTO MembersInterests (AccountID, InterestID) " & _
  228.                 "VALUES (" & lngAccountID & "," & varItem & ")"
  229.         cnn.Execute strSQL
  230.     Next
  231.     
  232.     objContext.SetComplete
  233.     UpdateInterests = 0
  234.            
  235.     Exit Function
  236.     
  237. ErrorHandler:
  238.     If Not cnn Is Nothing Then Set cnn = Nothing
  239.  
  240.     objContext.SetAbort
  241.     Err.Raise Err.Number, "Member.UpdateInterests()", Err.Description
  242.     
  243. End Function
  244.  
  245. Private Function SQLEncode(str As String) As String
  246.     
  247.     Dim vntPosition As Variant
  248.     
  249.     If IsNull(str) Or str = "" Then
  250.  
  251.     Else
  252.         vntPosition = InStr(str, "'")
  253.         Do While vntPosition <> 0
  254.             str = Mid(str, 1, vntPosition - 1) & "`'`" & Mid(str, vntPosition + 1)
  255.             vntPosition = InStr(vntPosition + 2, str, "'")
  256.         Loop
  257.     End If
  258.     SQLEncode = str
  259.     
  260. End Function
  261.  
  262. Private Function InventPassword() As String
  263.     
  264.     Dim strPass As String, x
  265.     Randomize
  266.     
  267.     For x = 1 To 5
  268.         strPass = strPass & Chr(Int((25 * Rnd) + 65))
  269.     Next
  270.         
  271.     InventPassword = strPass
  272.     
  273. End Function
  274.  
  275. Function GetForID(ByVal strFileDSN As String, ByVal lngAccountID As Long) As Variant
  276.     
  277.     Dim objContext As ObjectContext
  278.     Set objContext = GetObjectContext
  279.     
  280.     On Error GoTo ErrorHandler
  281.     
  282.     Dim strSQL As String
  283.     Dim rst As New ADODB.Recordset
  284.     
  285.     strSQL = "SELECT FirstName," & _
  286.                 "LastName," & _
  287.                 "MiddleName," & _
  288.                 "KnownAs," & _
  289.                 "Password," & _
  290.                 "Gender," & _
  291.                 "Address1," & _
  292.                 "Address2," & _
  293.                 "City," & _
  294.                 "State," & _
  295.                 "PostCode," & _
  296.                 "Country," & _
  297.                 "HomePhone," & _
  298.                 "BusinessPhone," & _
  299.                 "Fax," & _
  300.                 "Email," & _
  301.                 "WebSite," & _
  302.                 "Mileage," & _
  303.                 "Seating," & _
  304.                 "Smoking," & _
  305.                 "Bulkhead," & _
  306.                 "ExitRow," & _
  307.                 "Meal," & _
  308.                 "Comment " & _
  309.             "FROM Member WHERE AccountID = " & lngAccountID
  310.     
  311.     rst.CursorLocation = adUseServer
  312.     rst.Open strSQL, "FILEDSN=" & strFileDSN, adOpenStatic, adLockReadOnly, adCmdText
  313.     
  314.     objContext.SetComplete
  315.     Set GetForID = rst
  316.     Exit Function
  317.     
  318. ErrorHandler:
  319.     If Not rst Is Nothing Then Set rst = Nothing
  320.  
  321.     objContext.SetAbort
  322.     Err.Raise Err.Number, "Member.GetForID()", Err.Description
  323.     
  324. End Function
  325.  
  326. Function ListForName(ByVal strFileDSN As String, ByVal strLastName As String)
  327.     
  328.     Dim objContext As ObjectContext
  329.     Set objContext = GetObjectContext
  330.     
  331.     On Error GoTo ErrorHandler
  332.     
  333.     Dim strSQL As String
  334.     Dim rst As New ADODB.Recordset
  335.     
  336.     strSQL = "SELECT FirstName," & _
  337.                 "LastName," & _
  338.                 "MiddleName," & _
  339.                 "KnownAs," & _
  340.                 "Gender," & _
  341.                 "Address1," & _
  342.                 "Address2," & _
  343.                 "City," & _
  344.                 "State," & _
  345.                 "PostCode," & _
  346.                 "Country," & _
  347.                 "HomePhone," & _
  348.                 "BusinessPhone," & _
  349.                 "Fax," & _
  350.                 "Email," & _
  351.                 "WebSite," & _
  352.                 "Mileage," & _
  353.                 "Comment " & _
  354.             "FROM Member WHERE LastName = '" & strLastName & "'"
  355.     
  356.     rst.CursorLocation = adUseServer
  357.     rst.Open strSQL, "FILEDSN=" & strFileDSN, adOpenStatic, adLockReadOnly, adCmdText
  358.     
  359.     objContext.SetComplete
  360.     Set ListForName = rst
  361.     
  362.     Exit Function
  363.     
  364. ErrorHandler:
  365.     If Not rst Is Nothing Then Set rst = Nothing
  366.     
  367.     objContext.SetAbort
  368.     Err.Raise Err.Number, "Member.ListForName()", Err.Description
  369.     
  370. End Function
  371.  
  372. Function CheckPassword(ByVal strFileDSN As String, ByVal lngAccountID As Long, ByVal strPassword As String)
  373.  
  374.     Dim objContext As ObjectContext
  375.     Set objContext = GetObjectContext
  376.     
  377.     On Error GoTo ErrorHandler
  378.     
  379.     Dim strSQL As String
  380.     Dim rst As New ADODB.Recordset
  381.    
  382.     strSQL = "SELECT Password FROM Member WHERE AccountID = " & lngAccountID
  383.     
  384.     rst.CursorLocation = adUseServer
  385.     rst.Open strSQL, "FILEDSN=" & strFileDSN, adOpenForwardOnly, adLockReadOnly
  386.     
  387.     'check to see if an account exists for that ID, if so then check password
  388.     If rst.EOF Then
  389.         CheckPassword = 0
  390.     ElseIf rst("Password") = strPassword Then
  391.         CheckPassword = 1
  392.     Else
  393.         CheckPassword = 0
  394.     End If
  395.      
  396.     objContext.SetComplete
  397.      
  398.     Exit Function
  399.     
  400. ErrorHandler:
  401.     If Not rst Is Nothing Then Set rst = Nothing
  402.     
  403.     objContext.SetAbort
  404.     Err.Raise Err.Number, "Member.CheckPassword()", Err.Description
  405.     
  406. End Function
  407.  
  408.  
  409. Function ListInterests(ByVal strFileDSN As String, ByVal lngAccountID As Long)
  410.     
  411.     Dim objContext As ObjectContext
  412.     Set objContext = GetObjectContext
  413.     
  414.     On Error GoTo ErrorHandler
  415.     
  416.     Dim strSQL As String
  417.     Dim rst As New ADODB.Recordset
  418.     
  419.     strSQL = "SELECT Interests.InterestID, " & _
  420.                     "Interests.InterestDescription, " & _
  421.                     "MembersInterests.AccountID, " & _
  422.                     "InterestCategories.Description " & _
  423.              "FROM (Interests INNER JOIN InterestCategories " & _
  424.                         "ON Interests.CategoryID = InterestCategories.CategoryID) " & _
  425.                     "LEFT JOIN MembersInterests " & _
  426.                         "ON Interests.InterestID = MembersInterests.InterestID " & _
  427.                         "AND MembersInterests.AccountID =  " & lngAccountID & _
  428.              "ORDER BY InterestCategories.SortOrder,  " & _
  429.                        "Interests.InterestDescription"
  430.                 
  431.     rst.CursorLocation = adUseServer
  432.     rst.Open strSQL, "FILEDSN=" & strFileDSN, adOpenStatic, adLockReadOnly, adCmdText
  433.     
  434.     objContext.SetComplete
  435.     Set ListInterests = rst
  436.     
  437.     Exit Function
  438.     
  439. ErrorHandler:
  440.     If Not rst Is Nothing Then Set rst = Nothing
  441.     
  442.     objContext.SetAbort
  443.     Err.Raise Err.Number, "Member.ListInterests()", Err.Description
  444.  
  445. End Function
  446.     
  447. Function GetMileage(ByVal strFileDSN As String, ByVal lngAccountID As Long)
  448.     
  449.     Dim objContext As ObjectContext
  450.     Set objContext = GetObjectContext
  451.     
  452.     On Error GoTo ErrorHandler
  453.     
  454.     Dim strSQL As String
  455.     Dim rst As New ADODB.Recordset
  456.     
  457.     strSQL = "SELECT Mileage FROM Member WHERE AccountID = " & lngAccountID
  458.     
  459.     rst.CursorLocation = adUseServer
  460.     rst.Open strSQL, "FILEDSN=" & strFileDSN, adOpenStatic, adLockReadOnly, adCmdText
  461.     
  462.     objContext.SetComplete
  463.     GetMileage = rst("Mileage")
  464.     
  465.     Exit Function
  466.     
  467. ErrorHandler:
  468.     If Not rst Is Nothing Then Set rst = Nothing
  469.     
  470.     objContext.SetAbort
  471.     Err.Raise Err.Number, "Member.GetMileage()", Err.Description
  472.     
  473. End Function
  474.  
  475. Function GetPassword(ByVal strFileDSN As String, ByVal lngAccountID As Long)
  476.     
  477.     Dim objContext As ObjectContext
  478.     Set objContext = GetObjectContext
  479.     
  480.     On Error GoTo ErrorHandler
  481.     
  482.     Dim strSQL As String
  483.     Dim rst As New ADODB.Recordset
  484.     
  485.     strSQL = "SELECT Password FROM Member WHERE AccountID = " & lngAccountID
  486.     
  487.     rst.CursorLocation = adUseServer
  488.     rst.Open strSQL, "FILEDSN=" & strFileDSN, adOpenStatic, adLockReadOnly, adCmdText
  489.     
  490.     objContext.SetComplete
  491.     GetPassword = rst("Password")
  492.     
  493.     Exit Function
  494.     
  495. ErrorHandler:
  496.     If Not rst Is Nothing Then Set rst = Nothing
  497.     
  498.     objContext.SetAbort
  499.     Err.Raise Err.Number, "Member.GetPassword()", Err.Description
  500.     
  501. End Function
  502.