解析基于Access數據庫的抽獎系統設計(3)_Access數據庫教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:揭秘如何在Access數據庫中使用SQL一般在Oracle中使用Sql,在Access中使用很少,不過與Oracle的Sql還是有很多相似之處的。 以下SQL語句在ACCESS XP的查詢中測試通過 建表: Create Table Tab1 ( ID Counter primary key, Name string(20), Age integer, [Date] DateTime); 技巧: 自動增加字段
……
N = 0
cnt = Me!電科.Value + Me!電氣.Value + Me!自動化.Value + Me!通信.Value + Me!院辦.Value + Me!退休.Value
Do While Me!抽獎數量.Value > N And Not qrs.EOF And cnt < Me!總數量.Value
'電科抽獎
’四舍五入確定電科中獎數
If Me!電科.Value < (Int(((unit1.姓名之Count / cnt1) * Me!總數量.Value + 0.5))) And N < Me!抽獎數量.Value And cnt < Me!總數量.Value Then
If qrs.單位 = "電科" And qrs!批次.Value = 0 Then
Me!電科.Value = Me!電科.Value + 1
qrs.Edit
qrs!獎勵等級.Value = Me!獎勵等級.Value
qrs!批次.Value = Me!批次.Value
qrs.Update
N = N + 1
End If
Else
End If
……
'退休抽獎
cnt = Me!電科.Value + Me!電氣.Value + Me!自動化.Value + Me!通信.Value + Me!院辦.Value + Me!退休.Value
cnt2= Me!電科.Value + Me!電氣.Value + Me!自動化.Value + Me!通信.Value + Me!院辦.Value
'剩余數量分配給退休
If Me!退休.Value < Int((Me!總數量.Value – cnt2) And N < Me!抽獎數量.Value And cnt < Me!總數量.Value Then
If qrs22.單位 = "退休" And qrs!批次.Value = 0 Then
Me!退休.Value = Me!退休.Value + 1
qrs.Edit
qrs22!獎勵等級.Value = Me!獎勵等級.Value
qrs22!批次.Value = Me!批次.Value
qrs22.Update
N = N + 1
End If
Else
End If
……
’判斷是否完成抽獎
cnt = Me!電科.Value + Me!電氣.Value + Me!自動化.Value + Me!通信.Value + Me!院辦.Value + Me!退休.Value
If cnt = Me!總數量.Value Then
MsgBox ("抽獎總數已到。")
Me.可抽獎.Value = 0
Else
MsgBox ("抽獎限制。")
End If
……
N = 0
cnt = Me!電科.Value + Me!電氣.Value + Me!自動化.Value + Me!通信.Value + Me!院辦.Value + Me!退休.Value
Do While Me!抽獎數量.Value > N And Not qrs.EOF And cnt < Me!總數量.Value
'電科抽獎
’四舍五入確定電科中獎數
If Me!電科.Value < (Int(((unit1.姓名之Count / cnt1) * Me!總數量.Value + 0.5))) And N < Me!抽獎數量.Value And cnt < Me!總數量.Value Then
If qrs.單位 = "電科" And qrs!批次.Value = 0 Then
Me!電科.Value = Me!電科.Value + 1
qrs.Edit
qrs!獎勵等級.Value = Me!獎勵等級.Value
qrs!批次.Value = Me!批次.Value
qrs.Update
N = N + 1
End If
Else
End If
……
'退休抽獎
cnt = Me!電科.Value + Me!電氣.Value + Me!自動化.Value + Me!通信.Value + Me!院辦.Value + Me!退休.Value
cnt2= Me!電科.Value + Me!電氣.Value + Me!自動化.Value + Me!通信.Value + Me!院辦.Value
'剩余數量分配給退休
If Me!退休.Value < Int((Me!總數量.Value – cnt2) And N < Me!抽獎數量.Value And cnt < Me!總數量.Value Then
If qrs22.單位 = "退休" And qrs!批次.Value = 0 Then
Me!退休.Value = Me!退休.Value + 1
qrs.Edit
qrs22!獎勵等級.Value = Me!獎勵等級.Value
qrs22!批次.Value = Me!批次.Value
qrs22.Update
N = N + 1
End If
Else
End If
……
’判斷是否完成抽獎
cnt = Me!電科.Value + Me!電氣.Value + Me!自動化.Value + Me!通信.Value + Me!院辦.Value + Me!退休.Value
If cnt = Me!總數量.Value Then
MsgBox ("抽獎總數已到。")
Me.可抽獎.Value = 0
Else
MsgBox ("抽獎限制。")
End If
……
結論
本系統利用Access數據庫,結合其內置VBA語言,探討了系統初始化、抽獎的隨機性和相對均衡性等關鍵問題,滿足了抽獎的要求。進行適當調整,該系統可以應用于多種抽獎場合。
分享:詳解如何遠程調用Access數據庫使用了TCP/IP,ADO及XML(需要安裝Microsoft XML 4.0。)。分服務器和客戶端兩部分,服務器可以多用戶同時連接。遠程連接Access數據庫有很多方法,我以前已經比較詳細的回答過(見下面所列的5種方法),我現在這個例子屬于其中的第3種方法(不需要使用RDS或W
相關Access數據庫教程:
- Access數據庫安全策略之ASP式
- 第N次被ACCESS的關鍵字涮
- Access中用Jet SQL語句刪除表關系
- Access報表打印如何自動分頁
- Access完成累計余額的計算
- 搭建Access為主的Mdb數據庫
- 一句sql更新兩個表并可更新對應的字段值具體實現
- MySQL查詢優(yōu)化:連接查詢排序limit(join、order by、limit語句)介紹
- 內網ssh/mysql登錄緩慢的解決方法
- 使用準則進行條件查詢--1.4.從窗體中選擇查詢的條件
- 中文Access2000速成教程--1.1 使用“向導”設計數據庫
- 中文Access2000速成教程--1.3 在“設計”視圖中設計表
- 相關鏈接:
- 教程說明:
Access數據庫教程-解析基于Access數據庫的抽獎系統設計(3)
。