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

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

Protected WithEvents txtcomppath As System.Web.UI.HtmlControls.HtmlInputFile

Protected WithEvents Image1 As System.Web.UI.WebControls.Image

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

Protected WithEvents ddlcompfunc As System.Web.UI.WebControls.DropDownList

Protected WithEvents txtcodefp As System.Web.UI.HtmlControls.HtmlInputFile

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

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

Private Sub InitializeComponent()

End Sub

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

If Not(Page.IsPostBack)Then

Dim conn As SqlConnection

Dim cmd As SqlCommand

Dim rd As SqlDataReader

Dim sql As String

Dim now As DateTime

conn=New SqlConnection(”server=(local);database=Componentsystem;Trusted_Connection=yes”)

conn.Open()

sql=”Select count(componentID)from tb_componentbasicinformation”

cmd=New SqlCommand(sql,conn)

If(CType(cmd.ExecuteScalar(),Integer)=0)Then

lblcompid.Text=”CO100001”

Else

sql=”SELECT MAX(RIGHT(componentID,6))FROM tb_componentbasicinformation”

Dim myCommand As SqlCommand=New SqlCommand(sql,conn)

Dim id As Integer

id=CType(myCommand.ExecuteScalar(),Integer)

id=id+1

lblcompid.Text=”CO”+CType(id,String)

End If

now=DateTime.Now

txtcompvers.Text=now.ToString()

txtcretime.Text=now.ToString()

sql=”Select componentfunctionname From tb_componentfunction”

cmd=New SqlCommand(sql,conn)

rd=cmd.ExecuteReader

ddlcompfunc.Items.Clear()

Do While rd.Read

ddlcompfunc.Items.Add(rd(”componentfunctionname”))

Loop

rd.Close()

sql=”Select categoryname From tb_componentcategory”

cmd=New SqlCommand(sql,conn)

rd=cmd.ExecuteReader

ddlcompcate.Items.Clear()

Do While rd.Read

ddlcompcate.Items.Add(rd(”categoryname”))

Loop

rd.Close()

sql=”Select operationsystemname From tb_operationsystem”

cmd=New SqlCommand(sql,conn)

rd=cmd.ExecuteReader

ddlos.Items.Clear()

Do While rd.Read

ddlos.Items.Add(rd(”operationsystemname”))

Loop

rd.Close()

sql=”Select toolname From tb_tool”

cmd=New SqlCommand(sql,conn)

rd=cmd.ExecuteReader

ddltool.Items.Clear()

Do While rd.Read

ddltool.Items.Add(rd(”toolname”))

Loop

rd.Close()

sql=”Select producttypename From tb_producttype”

cmd=New SqlCommand(sql,conn)

rd=cmd.ExecuteReader

ddlprodtype.Items.Clear()

Do While rd.Read

ddlprodtype.Items.Add(rd(”producttypename”))

Loop

rd.Close()

sql=”Select authorname From tb_author”

cmd=New SqlCommand(sql,conn)

rd=cmd.ExecuteReader

ddlcompauth.Items.Clear()

Do While rd.Read

ddlcompauth.Items.Add(rd(”authorname”))

Loop

rd.Close()

conn.Close()

End If

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

End Sub

Private Sub btnfinish_Click ( ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnfinish.Click

Dim mysql As String

Dim mycomd As SqlCommand

Dim myconn As SqlConnection

Dim myrd As SqlDataReader

Dim category As String

Dim tool As String

Dim product As String

Dim funct As String

Dim os As String

Dim update As String

Dim version As String

Dim versionid As String

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

myconn.Open()

mysql=”select componentname from tb_componentbasicinformation where

(componentname=’”+txtcompname.Text+”’)”

mycomd=New SqlCommand(mysql,myconn)

myrd=mycomd.ExecuteReader

If myrd.Read()Then

lblmessage.Text=”该构件名已存在”

myrd.Close()

Exit Sub

Else

myrd.Close()

mysql=”select componentcategoryid from tb_componentcategory where(categoryname=’”+ddlcompcate.SelectedItem.Text+”’)”

mycomd=New SqlCommand(mysql,myconn)

myrd=mycomd.ExecuteReader

myrd.Read()

category=myrd.Item(”componentcategoryid”)

myrd.Close()

mysql=”select toolid from tb_tool where(toolname=’”+ddltool.SelectedItem.Text+”’)”

mycomd=New SqlCommand(mysql,myconn)

myrd=mycomd.ExecuteReader

myrd.Read()

tool=myrd.Item(”toolid”)

myrd.Close()

mysql=”select producttypeid from tb_producttype where(producttypename=’”+ddlprodtype.SelectedItem.Text+”’)”

mycomd=New SqlCommand(mysql,myconn)

myrd=mycomd.ExecuteReader

myrd.Read()

product=myrd.Item(”producttypeid”)

myrd.Close()

mysql=”select componentfunctionid from tb_componentfunction where(componentfunctionname=’”+ddlcompfunc.SelectedItem.Text+”’)”

mycomd=New SqlCommand(mysql,myconn)

myrd=mycomd.ExecuteReader

myrd.Read()

funct=myrd.Item(”componentfunctionid”)

myrd.Close()

mysql=”select operationsystemid from tb_operationsystem where(operationsystemname=’”+ddlos.SelectedItem.Text+”’)”

mycomd=New SqlCommand(mysql,myconn)

myrd=mycomd.ExecuteReader

myrd.Read()

os=myrd.Item(”operationsystemid”)

myrd.Close()

update=”none”

version=”1.0”

mysql=”insert into tb_componentbasicinformation(componentid,componentname,componentintroduction,initialversiontime,componentcategoryid,toolid,producttypeid,componentfunctionid,functionintroduction)VALUES(’”+lblcompid.Text+”’,’”+txtcompname.Text+”’,’”+txtcompintro.Text+”’,’”+txtcompvers.Text+”’,’”+category+”’,’”+tool+”’,’”+product+”’,’”+funct+”’,’”+txtfuncintro.Text+”’)”

mycomd=New SqlCommand(mysql,myconn)

mycomd.ExecuteNonQuery()