'DATABASE OPERATOR CLASS
option explicit
'option strict
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.web
'Imports System.Xml
namespace CJJERGUESTBOOK
Public Class conn
Private connstr as String
Private conn as oledbconnection
Public Sub new()
connstr = System.Configuration.ConfigurationSettings.Appsettings("acconnectionstring").tostring.Trim
'connstr= configurationSettings.appsettings("acconnectionstring")
connstr = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & connstr
conn = new oledbconnection(connstr)
End Sub
'获取数据源
'writeonly
Public property constr() as String
Set
connstr = value
End Set
Get
return connstr
End Get
End property
'显示打开connection对象
Public Sub open()
try
conn.open()
catch objerror as Exception
'HttpContext.Current.Response.Write("<font color =red>Conn类异常:</font>" & objerror.Message & ":" & objerror.source)
Exit sub
End try
End Sub
'显示关闭connection链接
Public Sub close()
conn.close()
End Sub
'返回一个datareader对象,输入的是sql语句
Public Function GetDataReader (strsql as String ) as oledbdatareader
Dim objdatareader as oledbdatareader
Dim objcommand as new oledbcommand(strsql,conn)
try
open()
objdatareader = objcommand.executereader()
catch
close()
Exit Function
finally
End try
return objdatareader
' objcommand.executereader(CommandBehavior.CloseConnection)
' close()
End Function
'返回 OledbCommand 对象
public function OledbCommand(str as string) as OledbCommand
Dim objcmd as new OleDbCommand(str,conn)
open()
return objcmd
End function
'返回 OledbCommand->ExecuteNonquery
Public Function ExecuteNonquery(objcmd as OledbCommand) as Integer
Dim xint as integer
try
open()
xint = objcmd.ExecuteNonquery()
catch objerror as Exception
HttpContext.Current.Response.Write("<font color =red>Conn类异常:</font>" & objerror.Message & ":" & objerror.source)
close()
finally
close()
End try
Return xint
End Function
'返回 OledbCommand->ExecuteNonquery
Public Function ExecuteNonquery(str as string) as Integer
Dim xint as integer = 2
try
Dim objcmd as new OleDbCommand(str,conn)
open()
xint = objcmd.ExecuteNonquery()
catch objerror as Exception
HttpContext.Current.Response.Write("<font color =red>Conn类异常:</font>" & objerror.Message & ":" & objerror.source & "<hr/>" & str)
exit Function
close()
finally
close()
End try
Return xint
End Function
'返回一个聚集的值
Public Function ExecuteScalar(str as string) as Integer
Dim xint as integer = 2
try
Dim objcmd as new OleDbCommand(str,conn)
open()
xint = ctype(objcmd.ExecuteScalar(),integer)
catch
close()
finally
close()
End try
Return xint
End Function
'返回dataset对象
Public Function GetDataSet(str as String ,optional refstr as string = "data" ) as DataSet
Dim objDataSet as new DataSet()
try
open()
Dim objdataadapter as new oledbdataadapter(str,conn)
objdataadapter.fill(objDataSet,refstr)
catch
HttpContext.Current.Response.Write("SQL 语句 出错")
finally
close()
End try
return objDataSet
End Function
'这个函数用于检测第一条数据中的第一个值
'
Function GetFirstInRow( sql as string) as string
Dim objdatareader as OleDbDataReader
Dim objcommand as new oledbcommand(sql,conn)
try
open()
objdatareader = objcommand.executereader()
catch objerror as Exception
HttpContext.Current.Response.Write("<font color =red>Conn类异常:</font>" & objerror.Message & ":" & objerror.source)
close()
HttpContext.Current.Response.End()
exit Function
finally
End try
Dim x as string
if objdatareader.Read()
' x = objdatareader.GetString(0) 'for option strict
x = objdatareader(0)
End if
objdatareader.Close()
close()
return x
End Function
'
'
'
'析构函数
Sub Destruct()
try
close()
catch
' close()
finally
End try
End Sub
End Class
End namespace
'IMAGE验证码
CjjerBase: Img
Imports System
Imports system.drawing
Imports system.drawing.imaging
Imports system.drawing.drawing2D
imports Microsoft.VisualBasic
Imports System.Web
namespace CjjerBase
Public Class Img
public shared Sub CheckImg (optional imgcheckid as string = "imgcheck", _
optional imgwidth as integer = 65,optional imgheight as integer = 25 , _
optional strsize as integer = 4 ,optional fonttype as string = "arial" , _
optional Fontdaxiao as integer =16,optional rgb1 as integer = 187 , _
optional rgb2 as integer = 251,optional rgb3 as integer = 255)
dim objbitmap as bitmap
Dim objgraphics as graphics
objbitmap = new Bitmap(imgwidth,imgheight)
objgraphics = graphics.fromimage( objbitmap )
dim str as string = getrandom(strsize)
dim objfont as new font(fonttype ,Fontdaxiao)
HttpContext.Current.session(imgcheckid) = str
Dim redShade As Color = Color.FromArgb( rgb1, rgb2, rgb3) 'first parements is argb
objgraphics.clear(redShade) 'Color.Azure
'添加杂点开始
dim intcounter as integer
dim objrandom as random
objrandom = new random
for intcounter = 1 to imgwidth * imgheight / 6
objbitmap.setpixel( objrandom.next(imgwidth),objrandom.next(imgheight),color.blue)
next
'杂点结束
dim objbrushed as brush = brushes.Blue 'DarkMagenta ,Chocolate,Blue ,red,DarkRed ,Gray,Maroon,Plum,Chocolate
objgraphics.drawstring (str,objfont,objbrushed,0,0)
objbitmap.save( HttpContext.Current.Response.outputstream,System.Drawing.Imaging.ImageFormat.Jpeg)
end sub
protected shared function getrandom(optional nsize as integer = 1 ) as string
if nsize <1 then nsize = 1
dim objrandom as random
dim intcounter as integer
dim tempstr as string
objrandom = new random
for intcounter = 1 to nsize
select case objrandom.next(0,4)
case 1:tempstr &= chr( objrandom.next(65,90) )
case 2:tempstr &= chr( objrandom.next(97,122) )
case 3:tempstr &= chr(objrandom.next(48,57))
case else: tempstr &= chr( objrandom.next(65,90) )
end select
next
return tempstr
end function
End Class
End Namespace
'UBB CLASS
Imports System
Imports System.Text.RegularExpressions
Imports System.Collections
Imports Microsoft.VisualBasic
namespace CjjerBase
Public Class bbCode
shared public Function GetBbcode(byref str as string ) as string
Dim objregex as Regex
' Dim expressdata as string ()
' Dim replacedata as string ()
'
' expressdata = new string () { "(/[b/])(.*?)(/[//b/])" ,"(/[i/])(.*?)(/[//i/])","(/[code/])(.*)(/[/code/])","(/[color=(.[^/[]*)/])(.[^/[]*)(/[//color/])"}
' replacedata = new string () { "<strong>$2</strong>", "<i>$2</i>" ,"<div class=""code"">$2</div>","<font color=$2>$3</font>"}
Dim expressdata , replacedata as ArrayList
expressdata = new ArrayList(4)'这个必添,节省资源
with expressdata
.add ("(/[b/])(.*?)(/[//b/])")'0
.add ("(/[i/])(.*?)(/[//i/])")
.add ("(/[code/])(.*)(/[/code/])")
.add ("(/[color=(.[^/[]*)/])(.[^/[]*)(/[//color/])")'3
End with
replacedata = new ArrayList(4)'这个必添,节省资源
with replacedata
.add ("<strong>$2</strong>")'0
.add ("<i>$2</i>")
.add ("<div class=""code"">$2</div>")
.add ("<font color=$2>$3</font>")'3
End with
Dim e_ex as IEnumerator = expressdata.GetEnumerator
Dim e_re as IEnumerator = replacedata.GetEnumerator
Dim new_str as string = GetHtmlcode( str )
do while e_ex.movenext() and e_re.movenext()
objregex = new Regex( e_ex.Current,RegexOptions.IgnoreCase )
new_str = objregex.replace(new_str,e_re.Current )
loop
return new_str
End Function
shared public Function GetHtmlcode (byref str as string) as string
Dim new_str as string = str
' new_str = Server.HtmlEncode(str)
new_str = new_str.Replace( CHR(60), "<")'左边的<
new_str = new_str.Replace(CHR(62), ">")'右边的>
new_str = new_str.Replace( CHR(10), "<br/>")
new_str = new_str.Replace(CHR(32), " ")
new_str = new_str.Replace(CHR(9), " ")
new_str = new_str.Replace(CHR(34), """)
new_str = new_str.Replace(CHR(39), "'")
return new_str
End Function
End Class
End namespace
option explicit
'option strict
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
imports Microsoft.VisualBasic
'Imports AdminBase
Imports CJJERGUESTBOOK
namespace BookAdminSpace
Public Class AdminUserLogin
Inherits Control
Implements INamingContainer
const session_user as string = "5do8"
Sub CheckPassword( s As Object, e As EventArgs )
Dim strUsername, strPassword,strck As string
Dim lblLabel As Label
strUsername = CTYPE( Controls( 1 ), TextBox ).Text
strPassword = CTYPE( Controls( 4 ), TextBox ).Text
strck = CTYPE( Controls( 7 ), TextBox ).Text
lblLabel = CTYPE( Controls( 10 ), Label )
Dim imgckstr as string = "imgcheck"
if len(strck) <> 4 or HttpContext.Current.session(imgckstr) <> strck then
lblLabel.Text = " 验证码不正确 "
exit Sub
End if
if len(strUsername) < 2 or len(strPassword) < 2 then
lblLabel.Text = " 用户名或者密码太短或太长,或不合规则 "
else
Dim code_password as string = Fundmental.CodeString( strPassword )
Dim sql as string = " select [user_level] from [szd_user] where [user_name] = '" & strUsername & "' and " & _
" [user_password] = '" & code_password & "' "
Dim conn as new CJJERGUESTBOOK.conn()
Dim connstr as string = conn.GetFirstInRow(sql)
Dim user_level as integer = CType (connstr,integer)
If user_level > 0 Then
Fundmental.CreateUser(strUsername,session_user)
if user_level >=3
' System.Web.HttpServerUtility.Transfer("index.aspx")
HttpContext.Current.server.Transfer("index.aspx")
End if
lblLabel.Text = "登陆成功,级别是 :" & user_level & sql
Else
lblLabel.Text = " 用户名或者密码不正确 "
End if
End if
End Sub
Protected Overrides Sub CreateChildControls() 'Protected
'' Me.Controls.Add( New LiteralControl( "<div class=""code"">" ) )
' Me.Controls.Add( New LiteralControl( "<form runat=""server"">" ) )
' Add Username
Me.Controls.Add( New LiteralControl( "<b>用户:</b> " ) )
Me.Controls.Add( New TextBox )
Me.Controls.Add( New LiteralControl( "<br/>" ) )
' Add Password
Dim txtPass As New TextBox
Me.Controls.Add( New LiteralControl( "<b>密码:</b> " ) )
txtPass.TextMode = TextBoxMode.Password
Me.Controls.Add( txtPass )
Me.Controls.Add( New LiteralControl( "<br/>" ) )
'Add image check
Dim txtchk As New TextBox
Me.Controls.Add( New LiteralControl( "<b>验证:</b> " ) )
' txtchk.TextMode = TextBoxMode.Password
Me.Controls.Add( txtchk )
Me.Controls.Add( New LiteralControl( "<img src= '../inc/imgcheck.aspx' alt='验证' /><br/>" ) )
' Add Submit Button
Dim btnButton As New Button
btnButton.Text = " 登陆 "
AddHandler btnButton.Click, AddressOf checkPassword
Me.Controls.Add( btnButton )
' Me.Controls.Add( New LiteralControl( "</div>" ) )
' Me.Controls.Add( New LiteralControl( "</form>" ) )
' Add Label Control
Dim lblLabel As New Label
lblLabel.EnableViewState = False
Me.Controls.Add( lblLabel )
'完毕
End Sub
End Class
End Namespace