private void tsmMenuAdd_Click(object sender, EventArgs e) { cDining_Table table = lsvBill.Tag as cDining_Table; if (table == null) { MessageBox.Show("Hãy chọn bàn !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } fInput f = new fInput(); f.ShowDialog(); if (f.amount == 0) { return; } string id = string.Empty; if (DataProvider.ExecuteQuery("SELECT dbo.Products.id FROM dbo.Products WHERE dbo.Products.ProductName = N'" + lsvMenu.SelectedItems[0].Text + "'") != null) { foreach (DataRow dr in DataProvider.ExecuteQuery("SELECT dbo.Products.id FROM dbo.Products WHERE dbo.Products.ProductName = N'" + lsvMenu.SelectedItems[0].Text + "'").Rows) { id = dr["id"].ToString(); } } int idBill = cBill.GetUncheckBillIDByTableID(table.ID); int productID = int.Parse(id); int amount = f.amount; if (idBill == -1) { cBill.InsertBill(table.ID); cBillInfo.InsertBillInfo(cBill.GetMaxIDBill(), productID, amount); } else { cBillInfo.InsertBillInfo(idBill, productID, amount); } ShowBill(table.ID); loadFpnl(cDining_Table.LoadAllTableList()); btnPayment.Enabled = true; }
private void tsmBillDelete_Click(object sender, EventArgs e) { string a = string.Empty; string b = string.Empty; string c = string.Empty; if (DataProvider.ExecuteQuery("SELECT dbo.Products.id AS idProduct, Bill.id AS idBill, dbo.BillInfo.Amount AS Amount FROM dbo.Products, dbo.Bill, dbo.BillInfo WHERE dbo.Products.ProductName = N'" + lsvBill.SelectedItems[0].Text + "' AND dbo.Bill.id = dbo.BillInfo.idBill AND dbo.BillInfo.idProduct = dbo.Products.id AND dbo.Bill.BillStatus = N'Chưa thanh toán' AND dbo.Bill.idDiningTable = " + tableID) != null) { foreach (DataRow dr in DataProvider.ExecuteQuery("SELECT dbo.Products.id AS idProduct, Bill.id AS idBill, dbo.BillInfo.Amount AS Amount FROM dbo.Products, dbo.Bill, dbo.BillInfo WHERE dbo.Products.ProductName = N'" + lsvBill.SelectedItems[0].Text + "' AND dbo.Bill.id = dbo.BillInfo.idBill AND dbo.BillInfo.idProduct = dbo.Products.id AND dbo.Bill.BillStatus = N'Chưa thanh toán' AND dbo.Bill.idDiningTable = " + tableID).Rows) { a = dr["idProduct"].ToString(); b = dr["idBill"].ToString(); c = dr["Amount"].ToString(); } } int idProduct = int.Parse(a); int idBill = int.Parse(b); int Amount = int.Parse(c); fInput f = new fInput(); f.ShowDialog(); if (f.amount > Amount) { MessageBox.Show("Số lượng không phù hợp !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (f.amount == Amount) { DataProvider.ExecuteQuery("DELETE FROM dbo.BillInfo WHERE idFood = " + idProduct + " AND idBill = " + idBill + " AND Amount = " + Amount); } else { DataProvider.ExecuteQuery("UPDATE dbo.BillInfo SET Amount = " + (Amount - f.amount) + " WHERE idProduct = " + idProduct + " AND idBill = " + idBill); } lsvBill.Items.RemoveAt(lsvBill.FocusedItem.Index); ShowBill(tableID); }