【正文】
看 2 當(dāng)點擊 DataGridView 組建中的任意一客戶資料時在組件左邊的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 指的是點擊的行數(shù)第一行為 0Label1Text MeDataGridView1Item 0 row V 是為了取所選行數(shù)的第一列值即客戶姓名 If Label1Text Then 是指如果 label1 不為空 CmdStr select photo from customer where name Label1Text 是 SQL 語句查詢圖片數(shù)據(jù) DisplayImg CmdStr 是在 DisplayImg 方法中執(zhí)行 SQL語句 Else PictureBox1Image Nothing 指不滿足條件時清空圖像 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ù)庫中保存的二進制圖像 菜單信息查詢模塊與本模塊的原理類似以下不在闡述 44 添加預(yù)定信息 圖 45 添加預(yù)定信息 系統(tǒng)在窗口載入時先查詢了客戶和菜單兩張表將數(shù)據(jù)顯示在窗體左邊供用戶選擇時使用其代碼和客戶查詢類似這里不再敘述本節(jié)介紹其他功能的實現(xiàn) 日期時間桌號的核對 為了防止客戶預(yù)定的餐桌出現(xiàn)重合的情況添加預(yù)定的餐桌時系統(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 在此時刻此桌已有預(yù)定 End If End Sub 當(dāng)桌號時間或者日期中任何一條改動時程序都會使用方法 Is_SQL_Cmd 執(zhí)行查找一次數(shù)據(jù)庫看在此時刻此桌是否已有預(yù)定信息的記錄如果已有相同記錄系統(tǒng)就會提示在此時刻此桌已有預(yù)定 打折信息處理 當(dāng)用戶向系統(tǒng)添加預(yù)定的菜品時系統(tǒng)會執(zhí)行以下代碼 If Label6Text Then 選擇客戶 MsgBox 請選擇客戶 ElseIf Label12Text Then 選擇菜單 MsgBox 請選擇菜單 Else Label14Text Label14Text Label10Text 所點菜單 price Label12Text totle price 總消費金額 Label16Text totle Label18Text totle CmdStr select usedmoney from discount 查詢設(shè)定的消費金額 Cmd select discount from discount 查詢設(shè)定的打折程度 Cm SELECT usedmoney FROM [customer] where id Label6Text 客戶已消費金額 f sqlobjectSQL_Ada Cm Rows 0 Item 0 f 為客戶已消費金額 Try For i 0 To sqlobjectSQL_Ada CmdStr RowsCount – 1 打折表行數(shù) j sqlobjectSQL_Ada CmdStr Rows i Item 0 打折表行消費金額 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ù)定的餐點客戶信息用于判斷打折程度餐點用于結(jié)算消費金額用累加的方法計算出總消費金 額系統(tǒng)先在數(shù)據(jù)表中查詢客戶信息中的客戶已消費金額再用查出的金額與數(shù)據(jù)庫對比判斷打折程度具體方法是系統(tǒng)先查看折扣數(shù)據(jù)表中共有的數(shù)據(jù)行數(shù)然后從第 0 行開始依次向下掃描由于添加打折信息時是按照消費額度遞增方式添加的所以系統(tǒng)查到的數(shù)據(jù)會越來越大越來越接近客戶已消費金額當(dāng)已消費金額剛好超過設(shè)定的金額時系統(tǒng)停止繼續(xù)向下查找新的設(shè)定金額同時查找設(shè)定金額對應(yīng)的打折程度再用此打折程度計算打折后的實付金額 取消預(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ù)定查詢模塊載入時系統(tǒng)執(zhí)行以下語句 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ù)定時間 tableid as 餐桌號 money as 結(jié)算價格 food as 預(yù)定菜單 userid as 服務(wù)員編號 FROM YuDing Try MeDataGridView1DataSource sqlobjectSQL_Ada CmdStr Catch ex As Exception eErr ex End Try MeDataGridView1AutoSizeColumnsMode DataGridViewAutoSizeColumnsModeDisplayedCells End Sub 當(dāng)預(yù)定查詢模塊載入時讀取數(shù)據(jù)庫中的預(yù)定信息并且顯示在 DataGridView組件中顯示給用戶 查看餐廳的廚房就是使用這一模塊來獲取需要準(zhǔn)備的餐點 當(dāng)用戶知道想要查找的預(yù)定信息中的某些確切內(nèi)容時可以將知道的內(nèi)容輸入空格中系統(tǒng)將會自動在數(shù)據(jù)庫中查找這些內(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ù)定時間 tableid as 餐桌號 money as 結(jié)算價格 food as 預(yù)定菜單 userid as 服務(wù)員編號 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ù)餐桌號查找的文本框中的數(shù)據(jù)被改動時系統(tǒng)根據(jù)改動后的數(shù)據(jù)使用 CmdStr 所代表的 SQL 語句查找數(shù)據(jù)庫中的信息并將新的信息顯示在 DataGridView 組件中45 充值與結(jié)算 客戶充值 圖 47 客戶充值 用戶充值會模塊會調(diào)取數(shù)據(jù)庫中的 customer 表里的 money 數(shù)據(jù)當(dāng)用戶選擇要充值的客戶后系統(tǒng)會提取對應(yīng)客戶的客戶余額當(dāng)用戶確定添加后系統(tǒng)會用客戶余額加上客戶充值的金額然后把得到的結(jié)果更新到數(shù)據(jù)庫中客戶的賬戶余額中同時系統(tǒng)也會以同樣的方法更新數(shù)據(jù)庫 user表中的收款金額 money數(shù)據(jù) 然后再刷新 DataGridView 組件中的數(shù)據(jù)信息當(dāng)用戶點擊充值按鈕時系統(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ù)庫 Cmd SELECT money FROM [user] where user_id userid