users.aspx.vb
来自「这是用ASP.NET和SQLserver编写的购物网站的程序」· VB 代码 · 共 191 行
VB
191 行
Imports System.Data.SqlClient
Public Class users
Inherits System.Web.UI.Page
Dim cm As SqlCommand
Dim Cstring As String = "data source=(local);initial catalog=library;user id=sa;pwd=200343129"
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Button6 As System.Web.UI.WebControls.Button
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton
Protected WithEvents ImageButton2 As System.Web.UI.WebControls.ImageButton
Protected WithEvents ImageButton3 As System.Web.UI.WebControls.ImageButton
Dim nwindConn As SqlConnection = New SqlConnection(Cstring)
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button3 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Button4 As System.Web.UI.WebControls.Button
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
If (Session("userpower") <> 0) Then
Response.End()
End If
Catch ex As Exception
Response.Write("您不是合法的用户,请登录后再操作,<a href='default.aspx'>返回</a>")
Response.End()
End Try
Label1.Text = "欢迎读者" & Session("userid")
Label2.Visible = False
Label3.Visible = False
DataGrid1.Visible = False
Label4.Visible = False
End Sub
Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Unload
End Sub
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label4.Visible = False
DataGrid1.Visible = False
nwindConn.Open()
Dim cmd As New SqlCommand
cmd.CommandText = "select * from reader where rno='" & Session("userid") & "'"
cmd.Connection = nwindConn
Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()
If (myReader("type") = 0) Then
Label3.Text = "你已有超期的书,请将超期书还了,否则你无法借书,您可以通过点击'罚款情况'的按钮查看具体情况"
Label3.Visible = True
End If
Label2.Text = "姓名: " & myReader("rno") & " 性别: " & myReader("sex") & " 共可借书: " & myReader("lendnumber") & " 已借书 " & myReader("lendednumber")
Label2.Visible = True
nwindConn.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Label4.Visible = False
nwindConn.Open()
Dim cmd As New SqlCommand
cmd.CommandText = "select book.bno 书号,bname 书名,lenddate 借书日期,returndate 应还日期,renew 已经续借 from lend,book where rno='" & Session("userid") & "' and book.bno=lend.bno"
cmd.Connection = nwindConn
Dim myReader As SqlDataReader = cmd.ExecuteReader()
DataGrid1.DataSource = myReader
DataGrid1.DataBind()
DataGrid1.Visible = True
Label3.Visible = False
Label2.Visible = False
nwindConn.Close()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Response.Redirect("default.aspx")
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Label4.Visible = False
nwindConn.Open()
Dim cmd As New SqlCommand
cmd.CommandText = "select bno 书号,lenddate 应还日期,cost 应付罚款 from fakuan where rno='" & Session("userid") & "'"
cmd.Connection = nwindConn
Dim myReader As SqlDataReader = cmd.ExecuteReader()
DataGrid1.DataSource = myReader
DataGrid1.DataBind()
DataGrid1.Visible = True
Label3.Visible = False
Label2.Visible = False
nwindConn.Close()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Response.Redirect("userpassword.aspx")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Response.Redirect("search.aspx")
End Sub
Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
End Sub
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
Label4.Visible = False
DataGrid1.DataKeyField = "书号"
nwindConn.Open()
Dim cmd As New SqlCommand
Dim id As String = DataGrid1.DataKeys(e.Item.ItemIndex)
cmd.CommandText = "select * from fakuan where bno='" & id & "' and rno='" & Session("userid") & "'"
cmd.Connection = nwindConn
Dim reader As SqlDataReader = cmd.ExecuteReader()
Dim b As Boolean = reader.Read()
reader.Close()
cmd.CommandText = "select renew from lend where bno='" & id & "' and rno='" & Session("userid") & "'"
cmd.Connection = nwindConn
Dim a As Boolean = cmd.ExecuteScalar()
If (b = False) Then
If (a = False) Then
Dim d As DateTime = CDate(Year(Now) & "-" & Month(Now) + 1 & "-" & Day(Now))
cmd.CommandText = "update lend set renew=1 ,returndate='" & d & "' from lend where bno='" & id & "' and rno='" & Session("userid") & "'"
cmd.Connection = nwindConn
cmd.ExecuteNonQuery()
cmd.CommandText = "select book.bno 书号,bname 书名,lenddate 借书日期,returndate 应还日期,renew 已经续借 from lend,book where rno='" & Session("userid") & "' and book.bno=lend.bno"
cmd.Connection = nwindConn
Dim myReader As SqlDataReader = cmd.ExecuteReader()
DataGrid1.DataSource = myReader
DataGrid1.DataBind()
Label4.Visible = True
Label4.Text = "续借成功"
Else
Label4.Visible = True
Label4.Text = "你已经续借过了,只能续借一次,不能再续借"
End If
Else
Label4.Visible = True
Label4.Text = "此书已超期,不能续借"
End If
nwindConn.Close()
End Sub
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim delbutton As LinkButton
delbutton = e.Item.Cells(0).Controls(0)
delbutton.Attributes.Add("onclick", "JavaScript :return confirm('您真的要续借" & e.Item.DataItem("书名") & "吗?');")
End If
End Sub
Private Sub ImageButton2_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
Response.Redirect("default.aspx")
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?