一个精巧的asp小程序
2004-11-14 08:57
309 查看
第一:数据库设计:(数据库为Access)
会员信息表user_info<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
二:代码实现:
<%
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
%>
不是很完善,请大家指点.
会员信息表user_info<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
字段 | 说明 | 类型(长度) | 备注 |
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
%>
不是很完善,请大家指点.
相关文章推荐
- 非常可耻地发布一个原创asp小程序
- 使用Asp.net mvc + Linq + mvc_scaffold_gen_setup.exe 生成一个完整的家庭帐册大管家程序 之二
- 折腾:一个小破ASP程序也能浪费不少时间
- 做完一个小网站的一点经验总结(2):asp.netaccess程序运行环境的配置
- ASP.NET一个简易的WebServer,用控制台程序模拟IIS 托起web服务
- 用ASP.Net写一个发送ICQ信息的程序
- 实现一个可host asp.net程序的小型IIS(Cassinidev介绍)
- 做完一个小网站的一点经验总结(2): asp.net+access程序运行环境的配置
- ASP网站数据采集程序制作:一个采集入库生成本地文件的几个FUCTION(可用来生成HTML静态网页)
- ASP.NET一个简易的WebServer,用控制台程序模拟IIS 托起web服务
- 用ASP.Net写一个发送ICQ信息的程序
- ASP程序中同一个用户不允许同时登陆两次
- 避免asp.net程序session过期的一个另类方法
- [ASP]一个非常简洁的验证码程序
- 一个asp+ACCESS省市二级联动菜单程序
- [导入]开源一个的Asp.net公共上传文件程序
- 用ASP.Net写一个发送ICQ信息的程序
- 把一个 ASP.NET 程序转换为了 Web Services
- 一个小Forum Web程序示例,ASP.NET MVC Framework,TDD简介(Part 2)
- 怎么判断一个ASP.NET的程序是否三层架构