书城计算机网络综合应用软件设计
8724600000055

第55章 软件工程实例——构件库管理系统(19)

Protected WithEvents btnupdate As System.Web.UI.WebControls.Button

Protected WithEvents lblmessage As System.Web.UI.WebControls.Label

Protected WithEvents txtID As System.Web.UI.WebControls.TextBox

Protected WithEvents lblerror As System.Web.UI.WebControls.Label

Protected WithEvents btnsubmit As System.Web.UI.WebControls.Button

#Region”Web窗体设计器生成的代码”

’该调用是Web窗体设计器所必需的。

Private Sub InitializeComponent()

End Sub

Private Sub Page_(ByVal sender As System.Object,ByVal e As System.EventArgs)

Handles MyBase.Init

’CODEGEN:此方法调用是Web窗体设计器所必需的

’不要使用代码编辑器修改它。

InitializeComponent()

End Sub

#End Region

Private startIndex As Integer

Sub Binding()

Dim MyConnection As SqlConnection

MyConnection=New SqlConnection(”server=(local);database=componentsystem;Trusted_Connection=yes”)

MyConnection.Open()

Dim mySQL As String=”SELECT ArticleID,Title,Writer,WriteTime,Counter FROM tb_componentintroduction ORDER BY WriteTime DESC”

Dim myDataSet As DataSet=New DataSet()

Dim myCommand As SqlDataAdapter=New SqlDataAdapter(mySQL,MyConnection)

myCommand.Fill(myDataSet,”introduce”)

MyConnection.Close()

MyDataGrid.DataSource=myDataSet.Tables(”introduce”).DefaultView

MyDataGrid.DataBind()

End Sub

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load

If Not IsPostBack Then

startIndex=0

End If

Binding()

’在此处放置初始化页的用户代码

End Sub

Private Sub MyDataGrid_PageIndexChanged(ByVal source As Object,ByVal e AsSystem.Web.UI.WebControls.DataGridPageChangedEventArgs)Handles MyData—Grid.PageIndexChanged

startIndex=e.NewPageIndex*MyDataGrid.PageSize

MyDataGrid.CurrentPageIndex=e.NewPageIndex

Binding()

End Sub

Private Sub btnadd_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnadd.Click

Response.Redirect(”aboutcompadd.aspx”)

End Sub

Private Sub btndel_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btndel.Click

lblmessage.Text=”输入所要删除的文章ID”

txtID.Visible=True

btnsubmit.Visible=True

End Sub

Private Sub btnupdate_Click(ByVal sender As System.Object,ByVal e AsSystem.EventArgs)Handles btnupdate.Click

lblmessage.Text=”输入所要修改的文章ID”

txtID.Visible=True

btnsubmit.Visible=True

End Sub

Private Sub btnsubmit_Click(ByVal sender As System.Object,ByVal e AsSystem.EventArgs)Handles btnsubmit.Click

Dim MyConnection As SqlConnection

Dim MyCommand As SqlCommand

Dim ConnStr As String

MyConnection=New SqlConnection(”server=(local);database=componentsystem;Trusted_Connection=yes”)

MyConnection.Open()

If lblmessage.Text=”输入所要删除的文章ID”Then

If txtID.Text=””Then

lblerror.Text=”文章ID不能为空!”

Else

ConnStr=”SELECT ArticleID FROM tb_componentintroduction WHERE ArticleID=’”+txtID.Text+”’”

MyCommand=New SqlCommand(ConnStr,MyConnection)

Dim reader As SqlDataReader

reader=MyCommand.ExecuteReader()

If Not reader.Read()Then

lblerror.Text=”无此文章ID!”

reader.Close()

Else

reader.Close()

ConnStr=”DELETE FROM tb_componentintroduction WHERE ArticleID=’”+txtID.Text+”’”

MyCommand=New SqlCommand(ConnStr,MyConnection)

MyCommand.ExecuteNonQuery()

Binding()

lblmessage.Text=”文章删除成功!”

txtID.Visible=False

btnsubmit.Visible=False

End If

End If

End IfIf lblmessage.Text=”输入所要修改的文章ID”Then

If txtID.Text=””Then

lblerror.Text=”文章ID不能为空!”

Else

ConnStr=”SELECT ArticleID FROM tb_componentintroduction WHERE ArticleID=’”+txtID.Text+”’”

MyCommand=New SqlCommand(ConnStr,MyConnection)

Dim reader As SqlDataReader

reader=MyCommand.ExecuteReader()

If Not reader.Read()Then

lblerror.Text=”无此文章ID!”

reader.Close()

Else

reader.Close()

Session(”ArticleID”)=txtID.Text

Response.Redirect(”aboutcompupdate.aspx”)

End If

End If

End If

End Sub

End Class

思考题

1.假设您是一位团队领导者,请您对一个感兴趣的应用项目进行项目规划和管理。

2.请对该项目进行项目分析设计,包括详细数据库设计、UML设计等。

3.请对项目的数据库设计、UML设计进行优化。

4.请找出项目中的技术难点,并写出解决方案。

5.请选一种您熟悉的开发环境对项目进行具体实现。

6.请对自己的项目分析、设计、实现过程进行总结,写出体会。