一個小型管理系統的pb實現

 

一、用戶需求分析

 

該實習完成的是一個簡單的學生學籍管理系統,功能比較簡單,要在實際中應用還需進一步的改進和功能的進一步的擴充,它實現的功能如下

 

1、完成數據的錄入和修改,並提交數據庫保存。其中的主要數據包括學生的基本信息以及操作員管理等。

 

2、實現學生信息的簡單查詢、高級查詢及人數的統計。

 

3、信息具有一定的安全性。對操作員要有口令管理

 

使用的開發工具:PowerBuilder9.0

 

二、設計數據庫

 

在下面的表的結構的描述中 ,遵循以下規則:

表的中文含義(表名),如 “學生檔案表(student)”。

列的中文含義:列名(數據類型及寬度)[能否爲空] [pk]

如“學號:student_id(C12) [n][pk]”表示該列的中文含義是“學號,列名是 “student_id” 數據類型是“char”,寬度是12,不能爲空,[pk]說明該列作爲主鍵。各個表的結構如下

1、學生檔案表(student

   學號:student_id(C12) [n] [pk]

   姓名:student_name(C12) [y]

   性別:sex(C2) [y]

   生日:birthdaydate[y]

   民族:nationC10[y]

   政治面貌:background C10[y]

   學院:department_name C40[y]

   專業:major_name (C40) [y]

   班級:class C4[y]

   籍貫:hometown  (C20) [y]

   聯繫地址:address (C30) [y]

   電話:telephone (C20) [y]

   備註:remark(C30) [y]

2、操作員表(operator

   編號:operator_id C20[n] [pk]

   姓名:operator_name  (C20) [y]

   密碼:password  (C10) [y]

 

然後在PowerBuilder9.0中創建ASA本地數據庫,操作步驟如下

1、 從“Tools”菜單中選擇“Database Profile…”菜單項,系統顯示“Database Profiles”對話框,單擊“ODBC”項目中“Utilities”圖標左邊的“+”。

2、 雙擊“Utilities”項目下的“Create ASA Database”項 ,系統顯示“Create ASA Database”對話框。

3、配置數據庫的屬性。用戶名和密碼都取默認值,數據庫名爲student

4、配置好其他屬性後單擊OK按鈕。

這樣就完成了ASA本地數據庫的創建。然後在student數據庫重創建上面的表。完成了數據庫及表的創建,然後連接到數據庫,這樣子數據庫的連接參數都保存在註冊表中。以後就可以使用了。

 

三、系統設計

 

1、創建應用庫和應用對象

   工作區名爲student.dbw

   應用庫名爲student.dbl

   應用對象名爲 student,註釋名爲學生學籍管理系統

   對應用對象的open事件進行編程,包括:打開應用程序的封面窗口,設置數據庫的連接參數並連接數據庫,然後打開登陸窗口。我只使用了一個數據庫,用的數據庫事務對象是默認的SQLCA

   Open事件中的程序代碼:

 

open(m_welcome)//打開應用程序啓動封面窗口

// Profile student

SQLCA.DBMS = "ODBC"

SQLCA.AutoCommit = False

SQLCA.DBParm = "ConnectString='DSN=student;UID=;PWD='"

connect ;

if sqlca.sqlcode<>0 then

messagebox("提示","數據庫連接錯誤,請檢查後重試!",stopsign!)

close(m_welcome)

else

messagebox("提示","數據庫已經連接上,點擊確定進入",information!)

close(m_welcome)

open(w_login)

end if

 

2、創建全局變量

string  gs_password//操作員的口令

string  gs_operator_id//操作員的編號

3、創建菜單

  

菜單名稱爲m_menu ,各菜單項及相應的Clicked事件中的代碼如下:

   學生檔案管理 (m_file

       更新(m_input):open(w_input)

       學號查詢(m_query):    open(w_query)

w_query.sle_query_id.setfocus()

       高級查詢(m_querymore):open(w_querymore)

   系統設置(m_system

       口令更改(m_chagepassword):open(w_changepassword)

       重新登陸(m_relogin):      w_main.visible=false

open(w_login)

       關於(m_about

退出(m_quit):disconnect;halt

4、創建數據窗口

   1d_student:學生檔案數據窗口。

      創建選項:Grid

顯示風格;Quick Select

數據源 student表,選擇所有列;

student_id排序;

       2d_studentshort:學生學號顯示窗口。

      創建選項:Grid

顯示風格;Quick Select

數據源 student表,選擇學號屬性列;

student_id排序;

  

5、創建窗口並在窗口中放置所需的控件

   1w_welcome:封面窗口。

      創建選項    Title=“歡迎(歡迎使用學生學籍管理系統測試版)”

                  WindowType=popup

                  st_welcome.Text=“歡迎使用學生檔案管理系統”

st_connect.Text=“正在連接數據庫...

       2w_login  :登陸窗口。

         創建選項   Title=“登錄”

WindowType=response!”

                Icon= Window!

  st_remind.Text =“請在下面填入您的用戶名和口令”

st_id.Text =“用戶名”

sle_id.Text =“”

st_password.Text =“口令”

sle_password.Text =“”

sle_password.Password =TRUE

p_login= D:/學生學籍管理系統/login.GIF

cb_ok.Text =“確定”

cb_cancel.Text =“取消”

 

“確定”按鈕的Clicked 事件的代碼爲

 

string ls_operator_id

string ls_getpassword,ls_password

ls_operator_id=sle_id.Text

ls_operator_id=trim(ls_operator_id)

ls_getpassword=sle_password.Text

select operator.password

into :ls_password

from operator

where operator.operator_id=:ls_operator_id ;

if sqlca.sqlcode <> 0 then

  messagebox("提示","該用戶不存在")

  sle_id.Text="" 

  sle_password.Text=""   

 sle_id.setfocus()

return

end if

if ls_password <> ls_getpassword then

  messagebox("提示","口令不正確")

  sle_password.Text=""

  sle_password.setfocus()

  return

end if

gs_operator_id = ls_operator_id

gs_password = ls_password

close(w_login)

open(w_main)

w_main.visible=true

“退出”按鈕的Clicked事件的代碼爲:

disconnect;

halt

  3、w_main:主窗口。

   創建選項:

          Title=“學生檔案管理系統”

WindowType=main!

MenuName=m_menu

st_name.Text =“數據庫系統概論實習”

st_vertion.Text =“學生學籍管理系統測試版”

st_me.Text =“歡迎您的測試”

p_main= D:/學生學籍管理系統/main.jpg

   4w_changepassword: 更改口令窗口。

創建選項:

Title=“更改口令”

WindowType=response!”

p_changepassword= D:/學生學籍管理系統/login.GIF

 st_oldpassword.Text =“原口令”

sle_oldpassword.Text =“”

 st_newpassword.Text =“新口令”

sle_newpassword.Text =“”

st_newpassword_sure.Text =“確認”

sle_newpassword_sure.Text =“”

cb_ok.Text =“更改”

cb_cancel.Text =“取消”

“更改”按鈕的Clicked 事件的代碼爲

string ls_oldpassword

string ls_newpassword

ls_oldpassword=sle_oldpassword.Text

if ls_oldpassword <> gs_password then

   messagebox("提示","口令不正確!")

    return

end if

if sle_newpassword.Text <> sle_newpassword_sure.Text then

   messagebox("提示","兩次輸入口令不一致!")

return

end if

ls_newpassword = sle_newpassword.Text

update operator

set password = :ls_newpassword

where operator_id = :gs_operator_id ;

messagebox("提示","修改成功!")

close(w_changepassword)

“取消”按鈕的Clicked 事件的代碼爲

close(w_changepassword)

5w_input:更新窗口。

 

創建選項:

Title=“學生基本資料”

WindowType=response!

dw_student.DataObject=d_student

cb_add.Text =“增加”

cb_delete.Text =“刪除”

 cb_save.Text =“保存”

cb_cancel.Text =“退出”

st_hello.Text = *修改資料後要記得保存哦…”

Open事件中的程序代碼:

 

dw_student.setTransObject(SQLCA)

dw_student.Retrieve()

“增加” 按鈕的Clicked事件的代碼爲:

open(w_add)

“刪除” 按鈕的Clicked事件的代碼爲:

 

int li_ret

li_ret=MessageBox("提示","確實要刪除嗎?如果確定刪除後請保存結果",exclamation!,yesno!)

if(li_ret = 1) then

  dw_student.DeleteRow(0)

end if

“保存” 按鈕的Clicked事件的代碼爲:

if dw_student.update()=1 then

commit;

   messagebox("提示","保存成功!")

else

rollback;

messagebox("提示","保存失敗!")

end if

“退出” 按鈕的Clicked事件的代碼爲:

close(w_input)

 

6m_add: 添加一個學生記錄窗口。

   創建選項:

Title=“添加一個學生記錄”

   WindowType=response!

   st_input.Text =“請輸入學生信息”

st_add_id.Text =“學號”

sle_add_id.Text=“”

st_add_name.Text =“姓名”

sle_add_name.Text=“”

st_add_sex.Text =“性別”

ddlb_add_sex.text=“”,Items爲“男”“女”

st_ad_birthday.Text =“出生日期”

sle_add_birthday.Text=“”

st_add_nation.Text =“民族”

sle_add_nation.Text=“”

st_add_background.Text =“政治面貌”

sle_add_background.Text=“”

st_add_departmen.Text =“學院”

sle_add_department.Text=“”

st_add_major.Text =“專業”

sle_add_major.Text=“”

st_add_class.Text =“班級”

sle_add_class.Text=“”

st_add_hometown.Text =“籍貫”

sle_add_hometown.Text=“”

st_add_address=.Text “聯繫地址”

sle_add_address.Text=“”

st_add_telephone.Text =“電話”

sle_add_telephone.Text=“”

st_add_remark.Text =“備註”

sle_add_remark.Text=“”

cb_add_ok.Text =“保存”

cb_add_cancel.Text =“退出”

Open事件中的程序代碼:

w_input.visible=false

“保存” 按鈕的Clicked事件的代碼爲:

long l

string ls_student_id

string ls_student_name

string ls_sex

date ls_birthday

string ls_nation

string ls_background

string ls_department_name

string ls_major_name

string ls_class

string ls_hometown

string ls_address

string ls_telephone

string ls_remark

ls_student_id=sle_add_id.Text

ls_student_name=sle_add_name.Text

ls_sex=ddlb_add_sex.text

ls_birthday=date(sle_add_birthday.Text)

 

ls_nation=sle_add_nation.Text

ls_background=sle_add_background.Text

ls_department_name=sle_add_department.Text

ls_major_name=sle_add_major.Text

ls_class=sle_add_class.Text

ls_hometown=sle_add_hometown.Text

ls_address=sle_add_address.Text

ls_telephone=sle_add_telephone.Text

ls_remark=sle_add_remark.Text

if ls_student_id = "" then

messagebox("提示","學號不能爲空!",stopsign!)

   return

end if

w_input.dw_student.setfilter("student_id='"+ls_student_id+"'")

w_input.dw_student.filter()

l=w_input.dw_student.retrieve()

if l <> 0 then

  messagebox("提示","該學號已經存在!",stopsign!)

  return

end if

insert into student

values( :ls_student_id,

        :ls_student_name,

        :ls_sex,

        :ls_birthday,

        :ls_nation,

        :ls_background,

        :ls_department_name,

        :ls_major_name,

        :ls_class,

        :ls_hometown,

        :ls_address,

        :ls_telephone,

        :ls_remark) ;

if sqlca.sqlcode <> 0 then

rollback;

messagebox("提示","保存失敗!",stopsign!)

   return

end if

commit;

messagebox("提示","保存成功!")

w_input.dw_student.setfilter("")

w_input.dw_student.filter()

w_input.dw_student.retrieve()

 

//清空各個控件

sle_add_id.Text=""

sle_add_name.Text=""

ddlb_add_sex.text=""

sle_add_birthday.Text=""

sle_add_nation.Text=""

sle_add_background.Text=""

sle_add_department.Text=""

sle_add_major.Text=""

sle_add_class.Text=""

sle_add_hometown.Text=""

sle_add_address.Text=""

sle_add_telephone.Text=""

sle_add_remark.Text=""

sle_add_id.setfocus()

“退出” 按鈕的Clicked事件的代碼爲:

close(w_add)

w_input.visible=true

7w_query: 按學號查詢的窗口。

 

   創建選項:

Title=“查詢”

   WindowType=response!

st_student_id.Text =“學號”

sle_student_id.Text=“”

st_student_name.Text =“姓名”

sle_student_name.Text=“”

st_sex.Text =“性別”

sle_sex.text=“”

st__birthday.Text =“出生日期”

sle_birthday.Text=“”

st_nation.Text =“民族”

sle_nation.Text=“”

st_background.Text =“政治面貌”

sle_background.Text=“”

st_departmen.Text =“學院”

sle_department.Text=“”

st_major.Text =“專業”

sle_major.Text=“”

st_class.Text =“班級”

sle_class.Text=“”

st_hometown.Text =“籍貫”

sle_hometown.Text=“”

st_address.Text =“聯繫地址”

sle_address.Text=“”

st_telephone.Text =“電話”

sle_telephone.Text=“”

st_remark.Text =“備註”

sle_remark.Text=“”

   dw_student_short.DataObject= d_student_short

   st_suery_id.Text =“請輸入學號”

sle_query_id.Text =“”

 cb_query.Text =“查詢”

cb_reset.Text =“清空”

cb_cancel.Text =“退出”

Open事件中的程序代碼:

dw_student_short.setTransObject(SQLCA)

dw_student_short.Retrieve()

“查詢” 按鈕的Clicked事件的代碼爲:

string ls_query_id

string ls_student_name

string ls_sex

string ls_birthday

string ls_nation

string ls_background

string ls_department_name

string ls_major_name

string ls_class

string ls_hometown

string ls_address

string ls_telephone

string ls_remark

ls_query_id=sle_query_id.Text

 

select student_name,

       sex,

      birthday,

      nation,

      background,

      department_name,

      major_name,

      class,

      hometown,

      address,

      telephone,

      remark

into  :ls_student_name,

      :ls_sex,

      :ls_birthday,

      :ls_nation,

      :ls_background,

      :ls_department_name,

      :ls_major_name,

      :ls_class,

      :ls_hometown,

      :ls_address,

      :ls_telephone,

      :ls_remark

from   student

where  student_id = :ls_query_id ;

if SQLCA.sqlcode <> 0 then

messagebox("提示","沒有找到,請覈查學號後重新輸入!",stopsign!)

sle_query_id.Text=""

return

end if

sle_student_id.Text=ls_query_id

sle_student_name.Text=ls_student_name

sle_sex.Text=ls_sex

sle_birthday.Text=ls_birthday

sle_nation.Text=ls_nation

sle_background.Text=ls_background

sle_department_name.Text=ls_department_name

sle_major.Text=ls_major_name

sle_class.Text=ls_class

sle_hometown.Text=ls_hometown

sle_address.Text=ls_address

sle_telephone.Text=ls_telephone

sle_remark.Text=ls_remark

messagebox("提示","查詢完畢",information!)

sle_query_id.Text=""

“清空” 按鈕的Clicked事件的代碼爲:

sle_student_id.Text=""

sle_student_name.Text=""

sle_sex.Text=""

sle_birthday.Text=""

sle_nation.Text=""

sle_background.Text=""

sle_department_name.Text=""

sle_major.Text=""

sle_class.Text=""

sle_hometown.Text=""

sle_address.Text=""

sle_telephone.Text=""

sle_remark.Text=""

sle_query_id.Text=""

“退出” 按鈕的Clicked事件的代碼爲:

close(parent)

 8w_querymore:高級查詢的窗口。

 

   創建選項:

Title=“分類查詢”

WindowType=response!

dw_querymore .DataObject=d_student

st_name.Text =“姓名”

sle_name.Text =“”

st_sex.Text =“性別”

ddlb_sex.Text =“” Items爲“男”“女”

st_department_query.Text =“學院”Items爲“計算機學院”“電信學院”“文學院 ”等等

ddlb_department.Text =“”

cb_query.Text =“開始查詢”

cb_quit.Text =“退出查詢”

st_num.Text =“”

Open事件中的程序代碼:

dw_querymore.setTransObject(SQLCA)

dw_querymore.Retrieve()

“開始查詢” 按鈕的Clicked事件的代碼爲

string ls_department

string ls_name

string ls_sex

//查詢條件

string ls_condition1

string ls_condition2

string ls_condition3

int num

//第一個條件 查詢的學院

ls_department=trim(ddlb_department.Text)

ls_condition1="department_name='"+ls_department+"'"

if ls_department = "" then

  ls_condition1=""

end if

//第二個條件 查詢的姓名

ls_name=trim(sle_name.Text)

ls_condition2="student_name like '%"+ls_name+"%'"

if ls_name ="" then

  ls_condition2=""

end if

//第三個條件 查詢的性別

ls_sex=trim(ddlb_sex.Text)

ls_condition3="sex='"+ls_sex+"'"

if ls_sex = "" then

  ls_condition3=""

end if

// 三個條件都有的情況

if ls_condition1 <> "" and ls_condition2 <> "" and ls_condition3 <> "" then

  ls_condition1=ls_condition1+" and "

   ls_condition3=" and "+ls_condition3

end if

//兩個條件的情況

if ls_condition1 = "" and ls_condition2 <> "" and ls_condition3 <> "" then

   ls_condition2=ls_condition2+" and "

end if

if ls_condition1 <> "" and ls_condition2 = "" and ls_condition3 <> "" then

  ls_condition1=ls_condition1+" and "

end if

if ls_condition1 <> "" and ls_condition2 <> "" and ls_condition3 = "" then

  ls_condition1=ls_condition1+" and "

end if

//過濾查詢

dw_querymore.setfilter(ls_condition1+ls_condition2+ls_condition3)

dw_querymore.filter()

num=dw_querymore.retrieve()

//統計滿足條件的人數

st_num.Text="查詢完畢,滿足條件的學生共有"+string(num)+""

“退出查詢” 按鈕的Clicked事件的代碼爲

close(parent)

 

四、小結

       通過這個小應用系統的學習,掌握數據庫系統的基本原理,初步嘗試用PowerBuilder開發數據庫的技術。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

                                                     

  

 

 

 

 

 

 

數據庫系統概論實習報告

—學生學籍管理系統

      

 

 

                                       

 

 

 

 

學院 計算機學院

學號 200232530020

姓名 成肖

                                  

 

 

 

發佈了33 篇原創文章 · 獲贊 3 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章