• 沒有找到結果。

5 系統實作與呈現

5.2 程式碼簡述及選取

實作的程式原始碼來源如下表 5.2,有三種不同程式語言類型(asp、aspx 及 vb),共 10 個資料庫應用程式,總共 446 個原始碼檔案。

資料庫應用程式名稱 程式語言類型 原始碼檔案數

儲存媒體管理系統 vb 69

生產紀錄管理資訊系統 vb 147

問卷調查 asp 27

線上報名 asp 42

討論區 asp 39

意見箱 aspx 15

留言板 aspx 25

行事曆 aspx 25

公佈欄 aspx 26

工作管理 aspx 31

表 5.2:實作的程式原始碼列表

以下為此三種不同類型的原始碼格式,以下節錄此三種類型原始碼與存取資料庫 相關的部份,分別如下:

5.2.1 asp 檔案格式

<%

Set RSreg = Server.CreateObject("ADODB.RecordSet") subject = replace(trim(request("subject")), "'", "''") subjectid = request("subjectid")

if subjectid <> "" then sql = "" & _

" delete from m011 where m011_subjectid = " & subjectid & "; " & _

" delete from m012 where m012_subjectid = " & subjectid & "; " & _

" delete from m013 where m013_subjectid = " & subjectid & "; " & _

" delete from m014 where m014_subjectid = " & subjectid & "; " & _

" delete from m015 where m015_subjectid = " & subjectid & "; " & _

" delete from m016 where m016_subjectid = " & subjectid conn.execute(sql)

response.end

end if

notetype_str = trim(request("notetype")) notetype = ""

if ( subjectid <> "" then sql = "" & _

" update m011 set " & _

" m011_subject = '" & subject & "', " & _

" m011_questno = " & request("questno") & ", " & _

" m011_bdate = '" & bdate & "', " & _

" m011_edate = '" & edate & "', " & _

" m011_online = '" & request("online") & "', " & _

" m011_notetype = '" & notetype & "', " & _

" m011_questionnote= '" & replace(trim(request("questionnote")), "'", "''") & "', " & _

" m011_haveprize = '" & request("haveprize") & "', " & _

" m011_jumpquestion = '" & request("jumpquestion") & "', " & _

" m011_onlyonce = '" & request("onlyonce") & "', " & _

" m011_modifyuser = '" & session("NetUser") & "', " & _

" m011_updatetime = getdate() " & _

" where " & _

" m011_subjectid = " & subjectid conn.execute(sql)

response.end

end if

set rs = conn.execute("select IsNull(Max(m011_subjectid), 0) from m011") subjectid = rs(0) + 1

sql = "" & _

" insert into m011 ( " & _

" m011_subjectid, " & _

" m011_subject, " & _

" m011_questno, " & _ " m011_bdate, " & _ " m011_edate, " & _

" m011_online, " & _

" m011_notetype, " & _

" m011_questionnote, " & _

" m011_haveprize, " & _

" m011_jumpquestion, " & _

" m011_onlyonce, " & _

" m011_createuser, " & _

" m011_createtime, " & _

" m011_modifyuser, " & _

" m011_updatetime " & _

" ) values ( " & _

subjectid & ", " & _

" '" & subject & "', " & _ request("questno") & ", " & _

" '" & bdate & "', " & _

" '" & edate & "', " & _

" '" & request("online") & "', " & _

" '" & notetype & "', " & _

" '" & Replace(trim(request("questionnote")), "'", "''") & "', " & _

" '" & request("haveprize") & "', " & _

" '" & request("jumpquestion") & "', " & _

" '" & request("onlyonce") & "', " & _

" '" & session("NetUser") & "', " & _

" getdate(), " & _

" '" & session("NetUser") & "', "& _

" getdate() " & _

Sub Page_Load(sender As Object, e As EventArgs) Dim sql="select max(p_number) from patent"

dim ds as new dataset() select Case request("db")

case "mssql"

Dim cn As New

SqlConnection(ConfigurationSettings.AppSettings("ConnString_mssql")) dim da as sqlDataAdapter =new sqlDataAdapter(sql,cn) da.fill(ds,"patent")

case "access"

Dim cn As New

OleDbConnection(ConfigurationSettings.AppSettings("ConnString_access"))

dim da as OleDbDataAdapter =new OleDbDataAdapter(sql,cn)

da.fill(ds,"patent") 'cn.close

case "excel"

if isdbnull(ds.tables("patent").rows(0).item(0)) then

p_number.text=(Year(Today)-1911)*10000 + 1

Else

p_number.text=ds.tables("patent").rows(0).item(0) + 1

End if

End Sub

Sub btnOk_Click(sender As Object, e As EventArgs) Dim sql as String

sql="insert into patent values ('" & p_number.text & "','" & p_title.text & "','" &

p_inventor.text & "','" & p_claim.text & "','" & p_abstract.text & "')"

select Case request("db")

end select

response.redirect("mssql_list.aspx?db=" & request("db"))

End Sub

</Script>

<title>mssql_new</title>

<LINK href="css.css" type="text/css" rel="stylesheet">

<form id="Form1" method="post" runat="server" >

<div align="right"><a href="#" onClick="history.go(-1);">回上一頁</a></div>

<table width="90%" border="1" align="center">

<caption><font color="blue">「<%=request("db")%>」新增資料

</font></caption>

<tr>

<td width="15%">專利號碼:</td>

<td><asp:label id="p_number" runat="server" Width="100px"

></asp:label></td>

</tr>

<tr>

<td>發明人:</td>

<td><asp:textbox id="p_inventor" runat="server"

Width="300px"></asp:textbox></td>

</tr>

<tr>

<td>發明名稱:</td>

<td><asp:textbox id="p_title" runat="server" Width="600px"

></asp:textbox></td>

</tr>

<tr>

<td>專利權人:</td>

<td><asp:textbox id="p_claim" runat="server" Width="600px"

></asp:textbox></td>

</tr>

<tr>

<td>摘要:</td>

<td><asp:textbox id="p_abstract" runat="server" Width="600px"

Height="200px" TextMode="MultiLine"></asp:textbox></td>

</tr>

</table>

<br/>

<div align="center"><asp:button id="btnOk" runat="server" Width="40px"

Text="確定" CssClass="sbttn" onClick="btnOk_Click"></asp:button><input type="reset"

id="btn_reset" name="btn_reset" class="sbttn" value="重設" /></div>

</form>

ButtonRefresh.Enabled = False ButtonPrint.Enabled = False End If

End Sub

Private Sub ButtonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAdd.Click

TextBoxName.Text & "','" & TextBoxKeyman.Text & "','" & TextBoxTel.Text & "','" &

TextBoxFax.Text & "','" & TextBoxAddress.Text & "', '" & TextBoxEmail.Text & "')"

Dim cmd As SqlCommand = New SqlCommand(ic, cn)

Private Sub ButtonModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonModify.Click

= '" & TextBoxKeyman.Text & "', s_email='" & TextBoxEmail.Text & "',s_tel = '" & TextBoxTel.Text

& "', s_fax = '" & TextBoxFax.Text & "', s_address= '" & TextBoxAddress.Text & "' where s_code='" & TextBoxCode.Text & "'"

Dim cmd As SqlCommand = New SqlCommand(uc, cn) cmd.ExecuteNonQuery()

ds.AcceptChanges()

Private Sub ButtonDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDel.Click

Private Function getRptNum(ByVal csName As String) As Integer Dim sc As String

sc = "select count(*) as 'RptNum' from rptnum_mag where rptnum_cserial='" & csName & "' and rptnum_date = '" & Today & "'"

Dim cmd As SqlCommand = New SqlCommand(sc, cn)

dr.Close() End Function

Private Sub insertRptTable(ByVal ReportCode As String) Dim nInOut As Integer

nInOut = getRptNum(ReportCode) + 1 Dim ic As String

ic = "insert into rptnum_mag values ('" & ReportCode & "','" & Today & "', '" &

String.Format("{0:000}", nInOut) & "')"

Dim icmd2 As SqlCommand = New SqlCommand(ic, cn) icmd2.ExecuteNonQuery()

ReportNo = ReportCode & Year(Today) & String.Format("{0:00}", Month(Today)) &

String.Format("{0:00}", Microsoft.VisualBasic.DateAndTime.Day(Today)) &

String.Format("{0:000}", nInOut) End Sub

相關文件