【正文】
看 2 當(dāng)點(diǎn)擊 DataGridView 組建中的任意一客戶資料時(shí)在組件左邊的PictureBox 中將顯示客戶照片 Private Sub DataGridView1_CellClick ByVal sender As Object ByVal e As SysDataGridViewCellEventArgs Handles DataGridView1CellClick If row eRowIndex And eRowIndex 0 Then row eRowIndex Label1Text MeDataGridView1Item 0 row V If Label1Text Then CmdStr select photo from customer where name Label1Text DisplayImg CmdStr Else PictureBox1Image Nothing End If End If End Sub 其中 If row eRowIndex And eRowIndex 0 中 eRowIndex 指的是點(diǎn)擊的行數(shù)第一行為 0Label1Text MeDataGridView1Item 0 row V 是為了取所選行數(shù)的第一列值即客戶姓名 If Label1Text Then 是指如果 label1 不為空 CmdStr select photo from customer where name Label1Text 是 SQL 語(yǔ)句查詢圖片數(shù)據(jù) DisplayImg CmdStr 是在 DisplayImg 方法中執(zhí)行 SQL語(yǔ)句 Else PictureBox1Image Nothing 指不滿足條件時(shí)清空?qǐng)D像 3DisplayImg 方法 Private Sub DisplayImg ByVal str As String sqlobjectSQL_Ada str If sqlobjectSQL_Ada str Rows 0 Item 0 Is DBNullValue Then PictureBox1Image Nothing Else Dim imgbyte As Byte sqlobjectSQL_Ada str Rows 0 Item 0 Dim imgmemory As New MemoryStream imgbyte PictureBox1Image ImageFromStream imgmemory End If End Sub DisplayImg 方法的作用是讀出數(shù)據(jù)庫(kù)中保存的二進(jìn)制圖像 菜單信息查詢模塊與本模塊的原理類(lèi)似以下不在闡述 44 添加預(yù)定信息 圖 45 添加預(yù)定信息 系統(tǒng)在窗口載入時(shí)先查詢了客戶和菜單兩張表將數(shù)據(jù)顯示在窗體左邊供用戶選擇時(shí)使用其代碼和客戶查詢類(lèi)似這里不再敘述本節(jié)介紹其他功能的實(shí)現(xiàn) 日期時(shí)間桌號(hào)的核對(duì) 為了防止客戶預(yù)定的餐桌出現(xiàn)重合的情況添加預(yù)定的餐桌時(shí)系統(tǒng)執(zhí)行以下代碼 Private Sub DateTimePicker1_ValueChanged ByVal sender As SystemObject ByVal e As SystemEventArgs Handles DateTimePicker1ValueChanged sqlobject New SQL_Conn CmdStr select tableid from YuDing where tableid ComboBox1Text and date DateTimePicring and time ComboBox2Text If sqlobjectIs_SQL_Cmd CmdStr Then MsgBox 在此時(shí)刻此桌已有預(yù)定 End If End Sub 當(dāng)桌號(hào)時(shí)間或者日期中任何一條改動(dòng)時(shí)程序都會(huì)使用方法 Is_SQL_Cmd 執(zhí)行查找一次數(shù)據(jù)庫(kù)看在此時(shí)刻此桌是否已有預(yù)定信息的記錄如果已有相同記錄系統(tǒng)就會(huì)提示在此時(shí)刻此桌已有預(yù)定 打折信息處理 當(dāng)用戶向系統(tǒng)添加預(yù)定的菜品時(shí)系統(tǒng)會(huì)執(zhí)行以下代碼 If Label6Text Then 選擇客戶 MsgBox 請(qǐng)選擇客戶 ElseIf Label12Text Then 選擇菜單 MsgBox 請(qǐng)選擇菜單 Else Label14Text Label14Text Label10Text 所點(diǎn)菜單 price Label12Text totle price 總消費(fèi)金額 Label16Text totle Label18Text totle CmdStr select usedmoney from discount 查詢?cè)O(shè)定的消費(fèi)金額 Cmd select discount from discount 查詢?cè)O(shè)定的打折程度 Cm SELECT usedmoney FROM [customer] where id Label6Text 客戶已消費(fèi)金額 f sqlobjectSQL_Ada Cm Rows 0 Item 0 f 為客戶已消費(fèi)金額 Try For i 0 To sqlobjectSQL_Ada CmdStr RowsCount – 1 打折表行數(shù) j sqlobjectSQL_Ada CmdStr Rows i Item 0 打折表行消費(fèi)金額 d sqlobjectSQL_Ada Cmd Rows i Item 0 打折表行折扣率 If f j Then Label18Text totle d 10 End If Next i Catch ex As Exception eErr ex End Try End If End Sub 首先選擇客戶和預(yù)定的餐點(diǎn)客戶信息用于判斷打折程度餐點(diǎn)用于結(jié)算消費(fèi)金額用累加的方法計(jì)算出總消費(fèi)金 額系統(tǒng)先在數(shù)據(jù)表中查詢客戶信息中的客戶已消費(fèi)金額再用查出的金額與數(shù)據(jù)庫(kù)對(duì)比判斷打折程度具體方法是系統(tǒng)先查看折扣數(shù)據(jù)表中共有的數(shù)據(jù)行數(shù)然后從第 0 行開(kāi)始依次向下掃描由于添加打折信息時(shí)是按照消費(fèi)額度遞增方式添加的所以系統(tǒng)查到的數(shù)據(jù)會(huì)越來(lái)越大越來(lái)越接近客戶已消費(fèi)金額當(dāng)已消費(fèi)金額剛好超過(guò)設(shè)定的金額時(shí)系統(tǒng)停止繼續(xù)向下查找新的設(shè)定金額同時(shí)查找設(shè)定金額對(duì)應(yīng)的打折程度再用此打折程度計(jì)算打折后的實(shí)付金額 取消預(yù)定信息 系統(tǒng)根據(jù)用戶選擇的預(yù)定信息執(zhí)行刪除命令其關(guān)鍵代碼如下 CmdStr delete from YuDing where name Label25Text and date Label27Text and time Label28Text and tableid Label30Text Try sqlobjectExecCmd CmdStr 預(yù)定信息查詢 圖 46 預(yù)定查詢 當(dāng)預(yù)定查詢模塊載入時(shí)系統(tǒng)執(zhí)行以下語(yǔ)句 Private Sub Form1_Load ByVal sender As SystemObject ByVal e As SystemEventArgs Handles MyBaseLoad sqlobject New SQL_Conn CmdStr SELECT name as 客戶姓名 customerid as 身份證 date as 預(yù)定日期 time as 預(yù)定時(shí)間 tableid as 餐桌號(hào) money as 結(jié)算價(jià)格 food as 預(yù)定菜單 userid as 服務(wù)員編號(hào) FROM YuDing Try MeDataGridView1DataSource sqlobjectSQL_Ada CmdStr Catch ex As Exception eErr ex End Try MeDataGridView1AutoSizeColumnsMode DataGridViewAutoSizeColumnsModeDisplayedCells End Sub 當(dāng)預(yù)定查詢模塊載入時(shí)讀取數(shù)據(jù)庫(kù)中的預(yù)定信息并且顯示在 DataGridView組件中顯示給用戶 查看餐廳的廚房就是使用這一模塊來(lái)獲取需要準(zhǔn)備的餐點(diǎn) 當(dāng)用戶知道想要查找的預(yù)定信息中的某些確切內(nèi)容時(shí)可以將知道的內(nèi)容輸入空格中系統(tǒng)將會(huì)自動(dòng)在數(shù)據(jù)庫(kù)中查找這些內(nèi)容關(guān)鍵代碼如下 Private Sub TextBox1_TextChanged ByVal sender As SystemObject ByVal e As SystemEventArgs Handles TextBox1TextChanged TextBox2Text TextBox3Text sqlobject New SQL_Conn CmdStr SELECT name as 客戶姓名 customerid as 身份證 date as 預(yù)定日期 time as 預(yù)定時(shí)間 tableid as 餐桌號(hào) money as 結(jié)算價(jià)格 food as 預(yù)定菜單 userid as 服務(wù)員編號(hào) FROM YuDing where name TextBox1Text Try MeDataGridView1DataSource sqlobjectSQL_Ada CmdStr Catch ex As Exception eErr ex End Try MeDataGridView1AutoSizeColumnsMode DataGridViewAutoSizeColumnsModeDisplayedCells End Sub 當(dāng)根據(jù)姓名查找根據(jù)日期查找和根據(jù)餐桌號(hào)查找的文本框中的數(shù)據(jù)被改動(dòng)時(shí)系統(tǒng)根據(jù)改動(dòng)后的數(shù)據(jù)使用 CmdStr 所代表的 SQL 語(yǔ)句查找數(shù)據(jù)庫(kù)中的信息并將新的信息顯示在 DataGridView 組件中45 充值與結(jié)算 客戶充值 圖 47 客戶充值 用戶充值會(huì)模塊會(huì)調(diào)取數(shù)據(jù)庫(kù)中的 customer 表里的 money 數(shù)據(jù)當(dāng)用戶選擇要充值的客戶后系統(tǒng)會(huì)提取對(duì)應(yīng)客戶的客戶余額當(dāng)用戶確定添加后系統(tǒng)會(huì)用客戶余額加上客戶充值的金額然后把得到的結(jié)果更新到數(shù)據(jù)庫(kù)中客戶的賬戶余額中同時(shí)系統(tǒng)也會(huì)以同樣的方法更新數(shù)據(jù)庫(kù) user表中的收款金額 money數(shù)據(jù) 然后再刷新 DataGridView 組件中的數(shù)據(jù)信息當(dāng)用戶點(diǎn)擊充值按鈕時(shí)系統(tǒng)執(zhí)行以下代碼 If Label6Text Then a Label6Text If TextBox1Text Then b TextBox1Text money a b CmdStr update customer set money moneyToString where name Label4Text Try sqlobjectExecCmd CmdStr 更新充值后的客戶數(shù)據(jù)庫(kù) Cmd SELECT money FROM [user] where user_id userid