【正文】
) Then MsgBox 請輸入歸還圖書編號 , 48, 警告 End If str7 = select * from borrow where readerid=39。 amp。and ISBN=39。 UserName amp。 str4, conn, adOpenKeyset With MSFlexGrid1 .Rows = 2 .CellAlignment = 4 .TextMatrix(1, 0) = 學(xué)號 .TextMatrix(1, 1) = 姓名 .TextMatrix(1, 2) = 圖書編號 .TextMatrix(1, 3) = 圖書名稱 .TextMatrix(1, 4) = 借閱日期 .TextMatrix(1, 5) = 最遲還書日期 Do While Not .Rows = .Rows + 1 .CellAlignment = 4 .TextMatrix(.Rows 1, 0) = UserName .TextMatrix(.Rows 1, 1) = (1) .TextMatrix(.Rows 1, 2) = (2) .TextMatrix(.Rows 1, 3) = (3) .TextMatrix(.Rows 1, 4) = Format((4), yyyymmdd) .TextMatrix(.Rows 1, 5) = Format((5), yyyymmdd) Loop End With End Sub 此處用到 flexgrid 來實現(xiàn)將查詢結(jié)果用一個表來顯示 用下面的兩句代碼來實現(xiàn)圖書的續(xù)借與歸還,由于對 borrow 表建立了觸發(fā)器 t1 與 t2,當(dāng)執(zhí)行到刪除語句時就會觸發(fā) t1 與 t2 對 reader 表中的結(jié)束數(shù)目和 book 表中的庫存自動改變 續(xù)借圖書代碼 Private Sub Command1_Click() If Trim( = ) Then MsgBox 請輸入圖書編號 , 48, 警告 End If str5 = select * from borrow where readerid=39。 UserName amp。Initial Catalog=books If = 1 Then MsgBox 數(shù)據(jù)庫連接成功! , 64, 提示 Else MsgBox 數(shù)據(jù)庫連接失敗! , 48, 警告 End If 20 str4 = select * from borrow where readerid=39。Integrated Security=SSPI。 UserName amp。 39。 amp。 39。 amp。Persist Security Info=False。 str1, conn, 1, 3 If Then MsgBox 該用戶不存在! , 48, 警告 Else If Trim((1)) = Trim() Then UserName = Trim() Unload Form2 Else MsgBox 密碼不正確!請重新輸入! , 48, 警告 End If End If End Sub 二、個人信息查詢功能主要代碼 Private Sub Form_Load() = Provider=。 amp。Initial Catalog=books If = 1 Then MsgBox 數(shù)據(jù)庫連接成功! , 64, 提示 Else MsgBox 數(shù)據(jù)庫連接失?。?, 48, 警告 End If End Sub ( 4)通過 select 語句查找用戶是否存在 str1 = select * from reader where readerid=39。Integrated Security=SSPI。通過登錄分別 進(jìn)入不同的界面運用代碼 Unload Form1 來實現(xiàn)不同界面之間的跳轉(zhuǎn)。 主窗體的設(shè)計 主窗體的界面如下所示 在主窗體中設(shè)計了一個下拉式菜單有讀者登錄、管理員登錄、系統(tǒng)管理員登錄。當(dāng)讀者借書數(shù)目超過 8 時即不能在借書。 create rule rule_num as num=8 建立了兩個規(guī)則,分別設(shè)置性別輸入男或女時才有效,數(shù)目小于等于八。 or sex=39。 create trigger t1 on borrow for insert, delete as begin if exists(select * from inserted)and not exists(select * from deleted) begin update book set bookcount=bookcount1 where ISBN in (select ISBN from inserted) end if not exists(select * from inserted)and exists(select * from deleted) begin update book set bookcount=bookcount+1 where ISBN in (select ISBN from deleted) end end create trigger t2 on borrow for insert, delete as begin if exists(select * from inserted)and not exists(select * from deleted) begin update reader set borrownum=borrownum+1 where readerid in (select readerid from inserted) end if not exists(select * from inserted)and exists(select * from deleted) begin update reader set borrownum=borrownum1 where readerid in (select readerid from deleted) end end 16 規(guī)則的建立 規(guī)則可以對表的屬性進(jìn)行限制 create rule rule_sex as sex=39。當(dāng)對表有insert、 delete、 update 操作是就發(fā)觸發(fā)觸發(fā)器。在前臺中用 execute 存儲工程名 (參數(shù))來調(diào)用存儲過程。 將上面的 ER 圖轉(zhuǎn)變成關(guān)系模式如下: ( 1)、 讀者 ( 讀者 證 號 , 密碼, 姓名 , 性別, 住址 , 聯(lián)系電話,借書數(shù)目) ( 2)、 書籍 ( ISBN, 圖書名稱 ,作者,出版社,出版日期, 圖書總量,庫存量) ( 3)、 管理員 ( 工作號 , 密碼, 姓名,性別 ,地址,聯(lián)系電話) ( 4)、 借閱 ( 讀者證號, ISBN,讀者姓名,圖書名稱,借書時間,還書時 間 ) 在實際建立時在 sqlserver2021 中建一個 books 庫其中表的信息如下 ( 1) reader(讀者表) readerid(讀者證號): char( 20) primarykey pwd(密碼): char( 20) notnull readername(讀者姓名) char( 40) notnull readersex(性別) char( 3) notnull address(住址) char( 40) notnull phone(聯(lián)系電話) char( 13) notnull borrownum(借書數(shù) 目) int notnull ( 2) book(圖書表) ISBN(圖書編號) char( 20) primarykey bookname(圖書名稱) char( 40) notnull writer(作者) char(40) notnull publish(出版社) char( 40) notnull publishtime(出版日期) datetime notnull total(總量) int notnull bookcount(庫存量) int notnull ( 3) borrow(借閱表) readerid(讀者證號) char( 20) primarykey readern