用vb.net做的校友錄……(附所有源代碼)
我們擁有10余年網(wǎng)頁(yè)設(shè)計(jì)和網(wǎng)站建設(shè)經(jīng)驗(yàn),從網(wǎng)站策劃到網(wǎng)站制作,我們的網(wǎng)頁(yè)設(shè)計(jì)師為您提供的解決方案。為企業(yè)提供成都網(wǎng)站建設(shè)、成都做網(wǎng)站、微信開(kāi)發(fā)、微信小程序開(kāi)發(fā)、手機(jī)網(wǎng)站制作設(shè)計(jì)、H5網(wǎng)站設(shè)計(jì)、等業(yè)務(wù)。無(wú)論您有什么樣的網(wǎng)站設(shè)計(jì)或者設(shè)計(jì)方案要求,我們都將富于創(chuàng)造性的提供專業(yè)設(shè)計(jì)服務(wù)并滿足您的需求。
來(lái)源:不詳 作者 佚名 點(diǎn)擊數(shù):31 錄入時(shí)間:07-12-17 15:21:39
想必大家都上過(guò)校友錄吧,里面的功能雖然不是很強(qiáng)大,但是為我們這些畢業(yè)之后各奔西東的學(xué)子來(lái)說(shuō),到真是提供了一個(gè)好的聚集點(diǎn),下面是我用vb.net做的校友錄,當(dāng)然也不能說(shuō)是校友錄了,只能說(shuō)是我們班的學(xué)友錄了:)不過(guò)只要你掌握了這種編程思想,校友錄就不在話下了。這里我將重點(diǎn)談一下關(guān)于管理員權(quán)限賦予。
以前有這個(gè)想法的時(shí)候,難就難在管理員身份的賦予上,開(kāi)始想如果一般用戶在被提升為管理員之后,我可以把他的信息轉(zhuǎn)到另外一個(gè)表中,以后登陸的時(shí)候先檢查manage表中是否有他就行了,這種辦法我已經(jīng)實(shí)現(xiàn)了,是不是有些笨……可是正在我要正式開(kāi)工的時(shí)候,一個(gè)想法突然冒了出來(lái),是什么呢?呵呵,就是在數(shù)據(jù)庫(kù)中再增加一個(gè)字段了如果是第一次注冊(cè)就讓這個(gè)字段item(int)的值為0,要是被提升之后就update為1,班級(jí)創(chuàng)始人呢?當(dāng)然了,在他申請(qǐng)時(shí)付給他一個(gè)班級(jí)id,然后先判斷班級(jí)id為這個(gè)已經(jīng)注冊(cè)的人信息條數(shù)是否為0,如果是,那么就付給他item=2好了。下面的代碼中,我沒(méi)有實(shí)現(xiàn)這個(gè)功能,因?yàn)槲易龅氖前嘤唁浀模?dāng)然了,我就是管理員嘍:)
在這里,我使用的是checkboxlist(兩個(gè)),一個(gè)用來(lái)轉(zhuǎn)換數(shù)據(jù)(visibe=fause),一個(gè)用來(lái)顯示數(shù)據(jù),還有一個(gè)checkbox用來(lái)寫(xiě)全部選中的事件。當(dāng)然了還有兩個(gè)按鈕事件,一個(gè)是用來(lái)提升為管理員的,一個(gè)是用來(lái)降級(jí)為一般用戶的,這兩個(gè)按鈕在判斷為一般用戶時(shí)
enable都是為fause的,只有當(dāng)判斷登錄為管理員時(shí)才為true。當(dāng)然了,如果你是班級(jí)創(chuàng)始人,是不可能被降級(jí)的:)
這里用來(lái)顯示信息的我用的是一個(gè)datagrid,當(dāng)判斷為非管理員時(shí),刪除欄的visible將為fause,為管理員的時(shí)候,才為true,也就是說(shuō)只有管理員才可以刪除信息。而不是注冊(cè)的用戶是不能發(fā)言的所有的按鈕控件的enable將都為fause。
代碼如下:board.aspx
%@ Page Language="vb" AutoEventWireup="false" Codebehind="boaman.aspx.vb" Inherits="_99re1.boaman"%
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
HTML
HEAD
title/title
meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR"
meta content="Visual Basic 7.0" name="CODE_LANGUAGE"
meta content="javascript" name="vs_defaultClientScript"
meta content="" name="vs_targetSchema"
/HEAD
body background="image/bg.gif" MS_POSITIONING="GridLayout"
form id="Form1" method="post" runat="server"
asp:checkbox id="yourcheck" style="Z-INDEX: 101; LEFT: 84px; POSITION: absolute; TOP: 71px" runat="server" Text="全部選中" AutoPostBack="True" ForeColor="SaddleBrown" Font-Bold="True"/asp:checkbox
asp:button id="Button1" style="Z-INDEX: 102; LEFT: 34px; POSITION: absolute; TOP: 43px" runat="server" Text="提升為管理員" Height="20px" Width="100px" BackColor="Gainsboro" BorderColor="Lavender" BorderWidth="2px" BorderStyle="Outset"/asp:button
asp:button id="Button2" style="Z-INDEX: 103; LEFT: 142px; POSITION: absolute; TOP: 43px" runat="server" Text="降級(jí)為一般用戶" Height="20px" Width="100px" BackColor="Gainsboro" BorderColor="Lavender" BorderWidth="2px" BorderStyle="Outset"/asp:button
asp:checkboxlist id="CheckBoxList1" style="Z-INDEX: 104; LEFT: 14px; POSITION: absolute; TOP: 10px" runat="server" Visible="False"/asp:checkboxlist
asp:checkboxlist id="mycheck" style="Z-INDEX: 105; LEFT: 98px; POSITION: absolute; TOP: 99px" runat="server" ForeColor="Navy" Font-Size="X-Small"/asp:checkboxlist
asp:label id="Label1" style="Z-INDEX: 106; LEFT: 82px; POSITION: absolute; TOP: 14px" runat="server" ForeColor="Red" Font-Names="方正姚體"(已注冊(cè)用戶)/asp:label
asp:image id="Image1" style="Z-INDEX: 107; LEFT: 260px; POSITION: absolute; TOP: 180px" runat="server" Height="124px" Width="221px" ImageUrl="image/99re1-1.gif"/asp:image
asp:datagrid id="DataGrid1" style="Z-INDEX: 108; LEFT: 250px; POSITION: absolute; TOP: 83px" runat="server" Height="113px" Width="461px" BorderColor="#ffcc66" AutoGenerateColumns="False" HeaderStyle-Font-Size="9" HeaderStyle-HorizontalAlign="Center" HeaderStyle-ForeColor="red" HeaderStyle-Font-Bold="True"
Columns
asp:HyperLinkColumn ItemStyle-ForeColor="navy" ItemStyle-HorizontalAlign="Center" ItemStyle-Height="24" ItemStyle-Font-Size="9" DataNavigateUrlField="stu_id" DataNavigateUrlFormatString="querry.aspx?stu_id={0}" DataTextField="stu_id" HeaderText="學(xué)號(hào)"/asp:HyperLinkColumn
asp:BoundColumn ItemStyle-ForeColor="navy" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100" ItemStyle-Font-Size="9" DataField="tel" HeaderText="電話"/asp:BoundColumn
asp:BoundColumn ItemStyle-ForeColor="navy" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="80" ItemStyle-Font-Size="9" DataField="oicq" HeaderText="OICQ"/asp:BoundColumn
asp:BoundColumn ItemStyle-ForeColor="navy" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="140" ItemStyle-Font-Size="9" DataField="email" HeaderText="E-mail"/asp:BoundColumn
asp:BoundColumn ItemStyle-ForeColor="navy" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="60" ItemStyle-Font-Size="9" DataField="point" HeaderText="登錄次數(shù)"/asp:BoundColumn
/Columns
/asp:datagrid
/form
/body
/HTML
下面是codebehind中的內(nèi)容:boaman.asp.vb
Imports System.Data
Imports System.Data.SqlClient
Public Class boaman
Inherits System.Web.UI.Page
Protected WithEvents yourcheck As System.Web.UI.WebControls.CheckBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents CheckBoxList1 As System.Web.UI.WebControls.CheckBoxList
Protected WithEvents mycheck As System.Web.UI.WebControls.CheckBoxList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim conn As SqlConnection = New SqlConnection("server=lixinri;uid=sa;pwd=;database=99re1")
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'////////////////////判斷是否為過(guò)客
If Session("stu_id") = "" Then
Button1.Enabled = False : Button2.Enabled = False
'////////////////////調(diào)用check()事件
check()
Else
If Not IsPostBack Then
Dim sql As String = "select * from pwd where stu_id=@stu_id"
Dim comm As SqlCommand = New SqlCommand(sql, conn)
comm.Parameters.Add(New SqlParameter("@stu_id", SqlDbType.Int, 4))
comm.Parameters("@stu_id").Value = Session("stu_id")
Dim dr As SqlDataReader
conn.Open()
dr = comm.ExecuteReader
While dr.Read
If dr.Item("term") = "0" Then
'///////////////////判斷是否為一般用戶
dr.Close()
Button1.Enabled = False : Button2.Enabled = False
Dim sql_1 As String = "select a.stu_id as stu_id,a.term,b.name as name,b.tel as tel,b.call as oicq,b.point as point,b.email from pwd a,stu_base b where a.stu_id=b.stu_id"
Dim cmd As New SqlCommand(sql_1, conn)
dr = cmd.ExecuteReader
While dr.Read
If dr.Item("term") = "1" Then
mycheck.Items.Add("u" dr.Item("name") "/u" "font color=darkorange(管理員)/font")
ElseIf dr.Item("term") = "2" Then
mycheck.Items.Add("u" dr.Item("name") "/u" "font color=red(班級(jí)創(chuàng)始人)font")
Else
mycheck.Items.Add("u" dr.Item("name") "/u")
End If
CheckBoxList1.Items.Add(dr.Item("stu_id"))
End While
Else
'////////////////////判斷是否為管理員
dr.Close()
Button1.Enabled = True : Button2.Enabled = True
Dim sql_1 As String = "select a.stu_id as stu_id,a.term,b.name as name,b.tel as tel,b.call as oicq,b.point as point,b.email from pwd a,stu_base b where a.stu_id=b.stu_id"
Dim cmd As New SqlCommand(sql_1, conn)
dr = cmd.ExecuteReader
While dr.Read
If dr.Item("term") = "1" Then
mycheck.Items.Add("u" dr.Item("name") "/u" "font color=darkorange(管理員)/font")
ElseIf dr.Item("term") = "2" Then
mycheck.Items.Add("u" dr.Item("name") "/u" "font color=red(班級(jí)創(chuàng)始人)font")
Else
mycheck.Items.Add("u" dr.Item("name") "/u")
End If
CheckBoxList1.Items.Add(dr.Item("stu_id"))
End While
End If
End While
dr.Close()
'////////////////////////取出數(shù)據(jù),填充dataset
Dim mysql As String = "select a.stu_id as stu_id,a.term,b.name as name,b.tel as tel,b.call as oicq,b.point as point,b.email from pwd a,stu_base b where a.stu_id=b.stu_id"
comm = New SqlCommand(mysql, conn)
Dim mycomm As SqlDataAdapter = New SqlDataAdapter(mysql, conn)
Dim ds As DataSet = New DataSet()
mycomm.Fill(ds, "base")
DataGrid1.DataSource = ds.Tables("base").DefaultView
DataGrid1.DataBind()
End If
End If
End Sub
'///////////////////////書(shū)寫(xiě)check()事件
Sub check()
If Not IsPostBack Then
Dim mysql As String = "select a.stu_id as stu_id,a.term,b.name as name,b.tel as tel,b.call as oicq,b.point as point,b.email from pwd a,stu_base b where a.stu_id=b.stu_id"
Dim comm As New SqlCommand(mysql, conn)
Dim dr As SqlDataReader
conn.Open()
dr = comm.ExecuteReader
While dr.Read
If dr.Item("term") = "1" Then
mycheck.Items.Add("u" dr.Item("name") "/u" "font color=darkorange(管理員)/font")
ElseIf dr.Item("term") = "2" Then
mycheck.Items.Add("u" dr.Item("name") "/u" "font color=red(班級(jí)創(chuàng)始人)font")
Else
mycheck.Items.Add("u" dr.Item("name") "/u")
End If
CheckBoxList1.Items.Add(dr.Item("stu_id"))
End While
dr.Close()
Dim mycomm As SqlDataAdapter = New SqlDataAdapter(mysql, conn)
Dim ds As DataSet = New DataSet()
mycomm.Fill(ds, "base")
DataGrid1.DataSource = ds.Tables("base").DefaultView
DataGrid1.DataBind()
End If
End Sub
'/////////////////////填充yourcheck
Private Sub yourcheck_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yourcheck.CheckedChanged
Dim i As Integer
For i = 0 To mycheck.Items.Count - 1
If yourcheck.Checked Then
mycheck.Items(i).Selected = True
Else
mycheck.Items(i).Selected = False
End If
Next
End Sub
'///////////////////////提升一般用戶為管理員
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conn.Open()
Dim i As Integer
For i = 0 To mycheck.Items.Count - 1
If mycheck.Items(i).Selected Then
Dim sql_1 As String = "update pwd set term=1 where stu_id=@stu_id and term=0"
Dim comm As SqlCommand = New SqlCommand(sql_1, conn)
comm.Parameters.Add(New SqlParameter("@stu_id", SqlDbType.Int, 4))
comm.Parameters("@stu_id").Value = CheckBoxList1.Items(i).Text
comm.ExecuteNonQuery()
End If
Next
Response.Redirect("boaman.aspx")
End Sub
'///////////////////////降級(jí)管理員為一般用戶
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
conn.Open()
Dim i As Integer
For i = 0 To mycheck.Items.Count - 1
If mycheck.Items(i).Selected Then
Dim sql_1 As String = "update pwd set term=0 where stu_id=@stu_id and term=1"
Dim comm As SqlCommand = New SqlCommand(sql_1, conn)
comm.Parameters.Add(New SqlParameter("@stu_id", SqlDbType.Int, 4))
comm.Parameters("@stu_id").Value = CheckBoxList1.Items(i).Text
comm.ExecuteNonQuery()
End If
Next
Response.Redirect("boaman.aspx")
End Sub
End Class
當(dāng)然了,這里面還有好多不足的地方,懇求高手批評(píng)指正。
校友錄還有一些其它的功能就很簡(jiǎn)單了,這里就不再探討了。
很簡(jiǎn)單,點(diǎn)擊菜單“項(xiàng)目”--“WindowsApplication1屬性”
在屬性面板里點(diǎn)“資源”,這里可添加字符串資源、圖片資源、多媒體資源等等。
使用資源很簡(jiǎn)單,舉例如下:
? Label1.Text = My.Resources.String1
? PictureBox1.Image = My.Resources.小貓
打開(kāi)VS?,?選擇VisualBasic?--?Web?--?ASP.NET?Web?應(yīng)用程序
如下圖:
VB.NET是一種.NET編程語(yǔ)言,與之平行的是C#
VC++.NET
等.
net語(yǔ)言
ASP.NET
是一種使嵌入網(wǎng)頁(yè)中的腳本可由因特網(wǎng)服務(wù)器執(zhí)行的
服務(wù)器端
腳本技術(shù)。
簡(jiǎn)單地說(shuō)就是編寫(xiě)網(wǎng)站的技術(shù)
,與之平行的是PHP,ASP等.
ASP.NET后臺(tái)代碼可用VB.NET
C#編寫(xiě).
你說(shuō)的操作是像人一樣用鼠標(biāo)點(diǎn)擊網(wǎng)頁(yè)?
直接應(yīng)該是不行的,可以考慮先抓包分析數(shù)據(jù)包,在模擬瀏覽器發(fā)送請(qǐng)求獲取數(shù)據(jù),然后進(jìn)行相應(yīng)處理
這個(gè)是超鏈接的target 屬性,具體寫(xiě)法為: XXX 使用 Target 屬性,你可以定義被鏈接的文檔在何處顯示,如果把鏈接的 target 屬性設(shè)置為 "_blank"