会员管理系统中会员类的实现

类别:Asp 点击:0 评论:0 推荐:
第一:数据库设计:(数据库为Access)

会员信息表user_info

字段

说明

类型(长度)

备注

Id

会员标识

自动编号

自增长

User_Name

用户名

文本

 

User_Password

密码

文本

 

Question

密码提示问题

文本

 

Answer

答案

文本

 

Name

称呼

文本

 

Sex

性别

文本

 

Birthday

出生年月

日期型

 

Region

地区

文本

 

City

城市

文本

 

Address

地址

文本

 

Phone

电话

文本

 

Email

e-mail

文本

 

Ciertified

是否认证

文本

CType

会员类型

文本

 

User_Grade

会员等级   

文本

 

二:代码实现:
<%
dim Conn,connstring,dbfile
dbfile=server.MapPath("/Database/db.mdb")
set Conn = server.createobject("ADODB.Connection")
'connstring = "Provider=Microsoft.Jet.OLEDB.4.01;Data Source=" & dbfile
connstring = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & dbfile
Conn.open connstring


'定义用户类
Class User_Info
 dim ID,User_Name,User_Password,Question,Answer,Name,Sex,Birthday,Region,City,Address
 dim Phone,Email,Ciertified,CType,User_Grade
 
 '类初始化
 Private Sub Class_Initialize
  ID = 0
  User_Name = ""
  User_password = ""
  Question = ""
  Answer = ""
  Name = ""
  Sex = ""
  Birthday = "1910-01-01"
  Region = ""
  City = ""
  Address = ""
  Phone = ""
  Email = ""
  Ciertified = "否"
  CType = "普通会员"
  User_Grade = "铜牌"
 End Sub
 
 '加载用户信息
 Public Sub Load(ByVal UserName)
  dim rs,sql
  sql = "select * from User_Info Where User_Name='" & UserName & "'"
  set rs =Conn.execute(sql)
  if not (rs.bof and rs.eof) then
   ID = rs("ID")
   User_Name = rs("User_Name")
   User_Password = rs("User_Password")
   Question = rs("Question")
   Answer = rs("Answer")
   Name = rs("Name")
   Sex = rs("Sex")
   Birthday = rs("birthday")
   Region = rs("Region")
   City = rs("City")
   Address = rs("Address")
   Phone = rs("Phone")
   Email = rs("Email")
   Ciertified = rs("Ciertified")
   CType = rs("CType")
   User_Grade = rs("User_Grade")
  end if
  rs.close
  set rs = Nothing 
 End Sub
 
 '检测用户是否存在数据库中
 '返回值:True存在,False不存在;
 Public Function IsExist()
  dim rs,sql,flag
  sql = "SELECT * FROM User_Info Where User_Name='" & User_Name & "'"
  Set rs = Conn.execute(sql)
  if not (rs.bof and rs.eof ) then
   flag = True
  else
   flag = False
  end if
  rs.close
  set rs = Nothing
  IsExist = flag  
 End Function
 
 '登录时判断用户密码是否正确
 '返回值:True正确,False返回
 Public Function IsPassed()
  dim rs,sql,Flag
  if User_Name<>"" and User_Password<>"" then
  sql = "select * from User_Info where User_Name='" & User_Name & "' and User_Password='" & Password & "'"
  set rs = Conn.execute(sql)
  if not (rs.bof and rs.eof ) then
   Flag = True
  else
   Flag = False
  end if
  rs.close
  set rs = Nothing
  else
   Flag = False
  end if
  IsPassed = Flag
 End Function
 
 '添加新用户
 Public Function Add()
  dim strSQL
  if IsExist() = True then
   Add = False
   exit function
  end if
  if User_Name="" or User_Password="" or Question = "" or Answer = "" then
   Add =False
   exit function
  end if
  strSQL = "Insert into User_Info(User_Name,User_Password,Question,Answer,Name,Sex,Birthday,Region,City,Address,Phone,Email,Ciertified,CType,User_Grade)"
  strSQL = strSQL & " Values('" & User_Name & "','"
  strSQL = strSQL & User_Password & "',"
  strSQL = strSQL & "'" & Question & "',"
  strSQL = strSQL & "'" & Answer & "',"
  strSQL = strSQL & "'" & Name & "',"
  strSQL = strSQL & "'" & Sex & "',"
  strSQL = strSQL & "#" & Birthday & "#,"
  strSQL = strSQL & "'" & Region & "',"
  strSQL = strSQL & "'" & City & "',"
  strSQL = strSQL & "'" & Address & "',"
  strSQL = strSQL & "'" & Phone & "',"
  strSQL = strSQL & "'" & Email & "',"
  strSQL = strSQL & "'" & Ciertified & "',"
  strSQL = strSQL & "'" & CType & "',"
  strSQL = strSQL & "'" & User_Grade & "')"
  'response.write strSQL
  Conn.Execute (strSQL)
  Add = True
 End Function
 
 '用户修改资料
 Public Sub Update()
  dim strSQL
  If ID = 0 then
   exit sub
  end if
  strSQL = "Update User_Info set User_Password='" & User_Password & "'"
  strSQL = strSQL & ",Question='" & Question & "'"
  strSQL = strSQL & ",Answer='" & Answer & "'"
  strSQL = strSQL & ",Birthday=#" & birthday & "#"
  strSQL = strSQL & ",Sex='" & Sex & "'"
  strSQL = strSQL & ",Region='" & Region & "'"
  strSQL = strSQL & ",City='" & City & "'"
  strSQL = strSQL & ",Address='" & Address & "'"
  strSQL = strSQL & ",Phone='" & Phone & "'"
  strSQL = strSQL & ",Email='" & Email & "'"
  strSQL = strSQL & ",Ciertified='" & Ciertified & "'"
  strSQL = strSQL & ",CType='" & CType & "'"
  strSQL = strSQL & ",User_Grade='" & User_Grade & "'"
  strSQL = strSQL & " where ID =" & ID
  Conn.Execute(strSQL)
 End Sub
 '删除用户
 Public Sub Delete()
  dim strSQL
  if IsExist = True then
   strSQL = "Delete from User_Info where User_Name='" & User_Name & "'"
   Conn.execute(strSQL)
   ID = 0
  end if
 End Sub
 '类终结
 Private Sub Class_Terminate
  
 End Sub
End Class
%>
不是很完善,请大家指点.

本文地址:http://com.8s8s.com/it/it8096.htm