Thêm, Xóa, Sửa Thức ăn Trong Phần Mềm Quản Lý Quán Cafe Với C# ...
Có thể bạn quan tâm
Không có gì tuyệt vời hơn là luyện tập với ví dụ thực tế. Nào cùng nhau thử thách bản thân với phần mềm: Quản lý quán cafe
Bạn nên có kiến thức về:
- Lập trình Winform cơ bản
- Delegate – Event
- SQL server
- Xử lý ngày tháng năm
Code data.sql
CREATE DATABASE QuanLyQuanCafe GO USE QuanLyQuanCafe GO -- Food -- Table -- FoodCategory -- Account -- Bill -- BillInfo CREATE TABLE TableFood ( id INT IDENTITY PRIMARY KEY, name NVARCHAR(100) NOT NULL DEFAULT N'Bàn chưa có tên', status NVARCHAR(100) NOT NULL DEFAULT N'Trống' -- Trống || Có người ) GO CREATE TABLE Account ( UserName NVARCHAR(100) PRIMARY KEY, DisplayName NVARCHAR(100) NOT NULL DEFAULT N'Kter', PassWord NVARCHAR(1000) NOT NULL DEFAULT 0, Type INT NOT NULL DEFAULT 0 -- 1: admin && 0: staff ) GO CREATE TABLE FoodCategory ( id INT IDENTITY PRIMARY KEY, name NVARCHAR(100) NOT NULL DEFAULT N'Chưa đặt tên' ) GO CREATE TABLE Food ( id INT IDENTITY PRIMARY KEY, name NVARCHAR(100) NOT NULL DEFAULT N'Chưa đặt tên', idCategory INT NOT NULL, price FLOAT NOT NULL DEFAULT 0 FOREIGN KEY (idCategory) REFERENCES dbo.FoodCategory(id) ) GO CREATE TABLE Bill ( id INT IDENTITY PRIMARY KEY, DateCheckIn DATE NOT NULL DEFAULT GETDATE(), DateCheckOut DATE, idTable INT NOT NULL, status INT NOT NULL DEFAULT 0 -- 1: đã thanh toán && 0: chưa thanh toán FOREIGN KEY (idTable) REFERENCES dbo.TableFood(id) ) GO CREATE TABLE BillInfo ( id INT IDENTITY PRIMARY KEY, idBill INT NOT NULL, idFood INT NOT NULL, count INT NOT NULL DEFAULT 0 FOREIGN KEY (idBill) REFERENCES dbo.Bill(id), FOREIGN KEY (idFood) REFERENCES dbo.Food(id) ) GO INSERT INTO dbo.Account ( UserName , DisplayName , PassWord , Type ) VALUES ( N'K9' , -- UserName - nvarchar(100) N'RongK9' , -- DisplayName - nvarchar(100) N'1' , -- PassWord - nvarchar(1000) 1 -- Type - int ) INSERT INTO dbo.Account ( UserName , DisplayName , PassWord , Type ) VALUES ( N'staff' , -- UserName - nvarchar(100) N'staff' , -- DisplayName - nvarchar(100) N'1' , -- PassWord - nvarchar(1000) 0 -- Type - int ) GO CREATE PROC USP_GetAccountByUserName @userName nvarchar(100) AS BEGIN SELECT * FROM dbo.Account WHERE UserName = @userName END GO EXEC dbo.USP_GetAccountByUserName @userName = N'k9' -- nvarchar(100) GO CREATE PROC USP_Login @userName nvarchar(100), @passWord nvarchar(100) AS BEGIN SELECT * FROM dbo.Account WHERE UserName = @userName AND PassWord = @passWord END GO -- thêm bàn DECLARE @i INT = 0 WHILE @i <= 10 BEGIN INSERT dbo.TableFood ( name)VALUES ( N'Bàn ' + CAST(@i AS nvarchar(100))) SET @i = @i + 1 END GO CREATE PROC USP_GetTableList AS SELECT * FROM dbo.TableFood GO UPDATE dbo.TableFood SET STATUS = N'Có người' WHERE id = 9 EXEC dbo.USP_GetTableList GO -- thêm category INSERT dbo.FoodCategory ( name ) VALUES ( N'Hải sản' -- name - nvarchar(100) ) INSERT dbo.FoodCategory ( name ) VALUES ( N'Nông sản' ) INSERT dbo.FoodCategory ( name ) VALUES ( N'Lâm sản' ) INSERT dbo.FoodCategory ( name ) VALUES ( N'Sản sản' ) INSERT dbo.FoodCategory ( name ) VALUES ( N'Nước' ) -- thêm món ăn INSERT dbo.Food ( name, idCategory, price ) VALUES ( N'Mực một nắng nước sa tế', -- name - nvarchar(100) 1, -- idCategory - int 120000) INSERT dbo.Food ( name, idCategory, price ) VALUES ( N'Nghêu hấp xả', 1, 50000) INSERT dbo.Food ( name, idCategory, price ) VALUES ( N'Dú dê nướng sữa', 2, 60000) INSERT dbo.Food ( name, idCategory, price ) VALUES ( N'Heo rừng nướng muối ớt', 3, 75000) INSERT dbo.Food ( name, idCategory, price ) VALUES ( N'Cơm chiên mushi', 4, 999999) INSERT dbo.Food ( name, idCategory, price ) VALUES ( N'7Up', 5, 15000) INSERT dbo.Food ( name, idCategory, price ) VALUES ( N'Cafe', 5, 12000) -- thêm bill INSERT dbo.Bill ( DateCheckIn , DateCheckOut , idTable , status ) VALUES ( GETDATE() , -- DateCheckIn - date NULL , -- DateCheckOut - date 3 , -- idTable - int 0 -- status - int ) INSERT dbo.Bill ( DateCheckIn , DateCheckOut , idTable , status ) VALUES ( GETDATE() , -- DateCheckIn - date NULL , -- DateCheckOut - date 4, -- idTable - int 0 -- status - int ) INSERT dbo.Bill ( DateCheckIn , DateCheckOut , idTable , status ) VALUES ( GETDATE() , -- DateCheckIn - date GETDATE() , -- DateCheckOut - date 5 , -- idTable - int 1 -- status - int ) -- thêm bill info INSERT dbo.BillInfo ( idBill, idFood, count ) VALUES ( 5, -- idBill - int 1, -- idFood - int 2 -- count - int ) INSERT dbo.BillInfo ( idBill, idFood, count ) VALUES ( 5, -- idBill - int 3, -- idFood - int 4 -- count - int ) INSERT dbo.BillInfo ( idBill, idFood, count ) VALUES ( 5, -- idBill - int 5, -- idFood - int 1 -- count - int ) INSERT dbo.BillInfo ( idBill, idFood, count ) VALUES ( 6, -- idBill - int 1, -- idFood - int 2 -- count - int ) INSERT dbo.BillInfo ( idBill, idFood, count ) VALUES ( 6, -- idBill - int 6, -- idFood - int 2 -- count - int ) INSERT dbo.BillInfo ( idBill, idFood, count ) VALUES ( 7, -- idBill - int 5, -- idFood - int 2 -- count - int ) GO CREATE PROC USP_InsertBill @idTable INT AS BEGIN INSERT dbo.Bill ( DateCheckIn , DateCheckOut , idTable , status, discount ) VALUES ( GETDATE() , -- DateCheckIn - date NULL , -- DateCheckOut - date @idTable , -- idTable - int 0, -- status - int 0 ) END GO CREATE PROC USP_InsertBillInfo @idBill INT, @idFood INT, @count INT AS BEGIN DECLARE @isExitsBillInfo INT DECLARE @foodCount INT = 1 SELECT @isExitsBillInfo = id, @foodCount = b.count FROM dbo.BillInfo AS b WHERE idBill = @idBill AND idFood = @idFood IF (@isExitsBillInfo > 0) BEGIN DECLARE @newCount INT = @foodCount + @count IF (@newCount > 0) UPDATE dbo.BillInfo SET count = @foodCount + @count WHERE idFood = @idFood ELSE DELETE dbo.BillInfo WHERE idBill = @idBill AND idFood = @idFood END ELSE BEGIN INSERT dbo.BillInfo ( idBill, idFood, count ) VALUES ( @idBill, -- idBill - int @idFood, -- idFood - int @count -- count - int ) END END GO DELETE dbo.BillInfo DELETE dbo.Bill CREATE TRIGGER UTG_UpdateBillInfo ON dbo.BillInfo FOR INSERT, UPDATE AS BEGIN DECLARE @idBill INT SELECT @idBill = idBill FROM Inserted DECLARE @idTable INT SELECT @idTable = idTable FROM dbo.Bill WHERE id = @idBill AND status = 0 DECLARE @count INT SELECT @count = COUNT(*) FROM dbo.BillInfo WHERE idBill = @idBill IF (@count > 0) BEGIN PRINT @idTable PRINT @idBill PRINT @count UPDATE dbo.TableFood SET status = N'Có người' WHERE id = @idTable END ELSE BEGIN PRINT @idTable PRINT @idBill PRINT @count UPDATE dbo.TableFood SET status = N'Trống' WHERE id = @idTable end END GO CREATE TRIGGER UTG_UpdateBill ON dbo.Bill FOR UPDATE AS BEGIN DECLARE @idBill INT SELECT @idBill = id FROM Inserted DECLARE @idTable INT SELECT @idTable = idTable FROM dbo.Bill WHERE id = @idBill DECLARE @count int = 0 SELECT @count = COUNT(*) FROM dbo.Bill WHERE idTable = @idTable AND status = 0 IF (@count = 0) UPDATE dbo.TableFood SET status = N'Trống' WHERE id = @idTable END GO ALTER TABLE dbo.Bill ADD discount INT UPDATE dbo.Bill SET discount = 0 GO CREATE PROC USP_SwitchTabel @idTable1 INT, @idTable2 int AS BEGIN DECLARE @idFirstBill int DECLARE @idSeconrdBill INT DECLARE @isFirstTablEmty INT = 1 DECLARE @isSecondTablEmty INT = 1 SELECT @idSeconrdBill = id FROM dbo.Bill WHERE idTable = @idTable2 AND status = 0 SELECT @idFirstBill = id FROM dbo.Bill WHERE idTable = @idTable1 AND status = 0 PRINT @idFirstBill PRINT @idSeconrdBill PRINT '-----------' IF (@idFirstBill IS NULL) BEGIN PRINT '0000001' INSERT dbo.Bill ( DateCheckIn , DateCheckOut , idTable , status ) VALUES ( GETDATE() , -- DateCheckIn - date NULL , -- DateCheckOut - date @idTable1 , -- idTable - int 0 -- status - int ) SELECT @idFirstBill = MAX(id) FROM dbo.Bill WHERE idTable = @idTable1 AND status = 0 END SELECT @isFirstTablEmty = COUNT(*) FROM dbo.BillInfo WHERE idBill = @idFirstBill PRINT @idFirstBill PRINT @idSeconrdBill PRINT '-----------' IF (@idSeconrdBill IS NULL) BEGIN PRINT '0000002' INSERT dbo.Bill ( DateCheckIn , DateCheckOut , idTable , status ) VALUES ( GETDATE() , -- DateCheckIn - date NULL , -- DateCheckOut - date @idTable2 , -- idTable - int 0 -- status - int ) SELECT @idSeconrdBill = MAX(id) FROM dbo.Bill WHERE idTable = @idTable2 AND status = 0 END SELECT @isSecondTablEmty = COUNT(*) FROM dbo.BillInfo WHERE idBill = @idSeconrdBill PRINT @idFirstBill PRINT @idSeconrdBill PRINT '-----------' SELECT id INTO IDBillInfoTable FROM dbo.BillInfo WHERE idBill = @idSeconrdBill UPDATE dbo.BillInfo SET idBill = @idSeconrdBill WHERE idBill = @idFirstBill UPDATE dbo.BillInfo SET idBill = @idFirstBill WHERE id IN (SELECT * FROM IDBillInfoTable) DROP TABLE IDBillInfoTable IF (@isFirstTablEmty = 0) UPDATE dbo.TableFood SET status = N'Trống' WHERE id = @idTable2 IF (@isSecondTablEmty= 0) UPDATE dbo.TableFood SET status = N'Trống' WHERE id = @idTable1 END GO ALTER TABLE dbo.Bill ADD totalPrice FLOAT DELETE dbo.BillInfo DELETE dbo.Bill GO CREATE PROC USP_GetListBillByDate @checkIn date, @checkOut date AS BEGIN SELECT t.name AS [Tên bàn], b.totalPrice AS [Tổng tiền], DateCheckIn AS [Ngày vào], DateCheckOut AS [Ngày ra], discount AS [Giảm giá] FROM dbo.Bill AS b,dbo.TableFood AS t WHERE DateCheckIn >= @checkIn AND DateCheckOut <= @checkOut AND b.status = 1 AND t.id = b.idTable END GO CREATE PROC USP_UpdateAccount @userName NVARCHAR(100), @displayName NVARCHAR(100), @password NVARCHAR(100), @newPassword NVARCHAR(100) AS BEGIN DECLARE @isRightPass INT = 0 SELECT @isRightPass = COUNT(*) FROM dbo.Account WHERE USERName = @userName AND PassWord = @password IF (@isRightPass = 1) BEGIN IF (@newPassword = NULL OR @newPassword = '') BEGIN UPDATE dbo.Account SET DisplayName = @displayName WHERE UserName = @userName END ELSE UPDATE dbo.Account SET DisplayName = @displayName, PassWord = @newPassword WHERE UserName = @userName end END GO CREATE TRIGGER UTG_DeleteBillInfo ON dbo.BillInfo FOR DELETE AS BEGIN DECLARE @idBillInfo INT DECLARE @idBill INT SELECT @idBillInfo = id, @idBill = Deleted.idBill FROM Deleted DECLARE @idTable INT SELECT @idTable = idTable FROM dbo.Bill WHERE id = @idBill DECLARE @count INT = 0 SELECT @count = COUNT(*) FROM dbo.BillInfo AS bi, dbo.Bill AS b WHERE b.id = bi.idBill AND b.id = @idBill AND b.status = 0 IF (@count = 0) UPDATE dbo.TableFood SET status = N'Trống' WHERE id = @idTable END GOCode fTableManager.cs
using QuanLyQuanCafe.DAO; using QuanLyQuanCafe.DTO; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Globalization; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace QuanLyQuanCafe { public partial class fTableManager : Form { private Account loginAccount; public Account LoginAccount { get { return loginAccount; } set { loginAccount = value; ChangeAccount(loginAccount.Type); } } public fTableManager(Account acc) { InitializeComponent(); this.LoginAccount = acc; LoadTable(); LoadCategory(); LoadComboboxTable(cbSwitchTable); } #region Method void ChangeAccount(int type) { adminToolStripMenuItem.Enabled = type == 1; thôngTinTàiKhoảnToolStripMenuItem.Text += " (" + LoginAccount.DisplayName + ")"; } void LoadCategory() { List<Category> listCategory = CategoryDAO.Instance.GetListCategory(); cbCategory.DataSource = listCategory; cbCategory.DisplayMember = "Name"; } void LoadFoodListByCategoryID(int id) { List<Food> listFood = FoodDAO.Instance.GetFoodByCategoryID(id); cbFood.DataSource = listFood; cbFood.DisplayMember = "Name"; } void LoadTable() { flpTable.Controls.Clear(); List<Table> tableList = TableDAO.Instance.LoadTableList(); foreach (Table item in tableList) { Button btn = new Button() { Width = TableDAO.TableWidth, Height = TableDAO.TableHeight}; btn.Text = item.Name + Environment.NewLine + item.Status; btn.Click += btn_Click; btn.Tag = item; switch (item.Status) { case "Trống": btn.BackColor = Color.Aqua; break; default: btn.BackColor = Color.LightPink; break; } flpTable.Controls.Add(btn); } } void ShowBill(int id) { lsvBill.Items.Clear(); List<QuanLyQuanCafe.DTO.Menu> listBillInfo = MenuDAO.Instance.GetListMenuByTable(id); float totalPrice = 0; foreach (QuanLyQuanCafe.DTO.Menu item in listBillInfo) { ListViewItem lsvItem = new ListViewItem(item.FoodName.ToString()); lsvItem.SubItems.Add(item.Count.ToString()); lsvItem.SubItems.Add(item.Price.ToString()); lsvItem.SubItems.Add(item.TotalPrice.ToString()); totalPrice += item.TotalPrice; lsvBill.Items.Add(lsvItem); } CultureInfo culture = new CultureInfo("vi-VN"); //Thread.CurrentThread.CurrentCulture = culture; txbTotalPrice.Text = totalPrice.ToString("c", culture); } void LoadComboboxTable(ComboBox cb) { cb.DataSource = TableDAO.Instance.LoadTableList(); cb.DisplayMember = "Name"; } #endregion #region Events void btn_Click(object sender, EventArgs e) { int tableID = ((sender as Button).Tag as Table).ID; lsvBill.Tag = (sender as Button).Tag; ShowBill(tableID); } private void đăngXuấtToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } private void thôngTinCáNhânToolStripMenuItem_Click(object sender, EventArgs e) { fAccountProfile f = new fAccountProfile(LoginAccount); f.UpdateAccount += f_UpdateAccount; f.ShowDialog(); } void f_UpdateAccount(object sender, AccountEvent e) { thôngTinTàiKhoảnToolStripMenuItem.Text = "Thông tin tài khoản (" + e.Acc.DisplayName + ")"; } private void adminToolStripMenuItem_Click(object sender, EventArgs e) { fAdmin f = new fAdmin(); f.InsertFood += f_InsertFood; f.DeleteFood += f_DeleteFood; f.UpdateFood += f_UpdateFood; f.ShowDialog(); } void f_UpdateFood(object sender, EventArgs e) { LoadFoodListByCategoryID((cbCategory.SelectedItem as Category).ID); if (lsvBill.Tag != null) ShowBill((lsvBill.Tag as Table).ID); } void f_DeleteFood(object sender, EventArgs e) { LoadFoodListByCategoryID((cbCategory.SelectedItem as Category).ID); if (lsvBill.Tag != null) ShowBill((lsvBill.Tag as Table).ID); LoadTable(); } void f_InsertFood(object sender, EventArgs e) { LoadFoodListByCategoryID((cbCategory.SelectedItem as Category).ID); if (lsvBill.Tag != null) ShowBill((lsvBill.Tag as Table).ID); } private void cbCategory_SelectedIndexChanged(object sender, EventArgs e) { int id = 0; ComboBox cb = sender as ComboBox; if (cb.SelectedItem == null) return; Category selected = cb.SelectedItem as Category; id = selected.ID; LoadFoodListByCategoryID(id); } private void btnAddFood_Click(object sender, EventArgs e) { Table table = lsvBill.Tag as Table; if (table == null) { MessageBox.Show("Hãy chọn bàn"); return; } int idBill = BillDAO.Instance.GetUncheckBillIDByTableID(table.ID); int foodID = (cbFood.SelectedItem as Food).ID; int count = (int)nmFoodCount.Value; if (idBill == -1) { BillDAO.Instance.InsertBill(table.ID); BillInfoDAO.Instance.InsertBillInfo(BillDAO.Instance.GetMaxIDBill(), foodID , count); } else { BillInfoDAO.Instance.InsertBillInfo(idBill, foodID, count); } ShowBill(table.ID); LoadTable(); } private void btnCheckOut_Click(object sender, EventArgs e) { Table table = lsvBill.Tag as Table; int idBill = BillDAO.Instance.GetUncheckBillIDByTableID(table.ID); int discount = (int)nmDisCount.Value; double totalPrice = Convert.ToDouble(txbTotalPrice.Text.Split(',')[0]); double finalTotalPrice = totalPrice - (totalPrice/100)*discount; if (idBill != -1) { if (MessageBox.Show(string.Format("Bạn có chắc thanh toán hóa đơn cho bàn {0}\nTổng tiền - (Tổng tiền / 100) x Giảm giá\n=> {1} - ({1} / 100) x {2} = {3}",table.Name, totalPrice, discount, finalTotalPrice), "Thông báo", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) { BillDAO.Instance.CheckOut(idBill, discount, (float)finalTotalPrice); ShowBill(table.ID); LoadTable(); } } } private void btnSwitchTable_Click(object sender, EventArgs e) { int id1 = (lsvBill.Tag as Table).ID; int id2 = (cbSwitchTable.SelectedItem as Table).ID; if (MessageBox.Show(string.Format("Bạn có thật sự muốn chuyển bàn {0} qua bàn {1}", (lsvBill.Tag as Table).Name, (cbSwitchTable.SelectedItem as Table).Name), "Thông báo", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) { TableDAO.Instance.SwitchTable(id1, id2); LoadTable(); } } #endregion } }Code FoodDAO.cs
using QuanLyQuanCafe.DTO; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace QuanLyQuanCafe.DAO { public class FoodDAO { private static FoodDAO instance; public static FoodDAO Instance { get { if (instance == null)instance = new FoodDAO(); return FoodDAO.instance; } private set { FoodDAO.instance = value; } } private FoodDAO() { } public List<Food> GetFoodByCategoryID(int id) { List<Food> list = new List<Food>(); string query = "select * from Food where idCategory = " + id; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { Food food = new Food(item); list.Add(food); } return list; } public List<Food> GetListFood() { List<Food> list = new List<Food>(); string query = "select * from Food"; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { Food food = new Food(item); list.Add(food); } return list; } public bool InsertFood(string name, int id, float price) { string query = string.Format("INSERT dbo.Food ( name, idCategory, price )VALUES ( N'{0}', {1}, {2})", name, id, price); int result = DataProvider.Instance.ExecuteNonQuery(query); return result > 0; } public bool UpdateFood(int idFood, string name, int id, float price) { string query = string.Format("UPDATE dbo.Food SET name = N'{0}', idCategory = {1}, price = {2} WHERE id = {3}", name, id, price, idFood); int result = DataProvider.Instance.ExecuteNonQuery(query); return result > 0; } public bool DeleteFood(int idFood) { BillInfoDAO.Instance.DeleteBillInfoByFoodID(idFood); string query = string.Format("Delete Food where id = {0}",idFood); int result = DataProvider.Instance.ExecuteNonQuery(query); return result > 0; } } }Code BillDAO.cs
using QuanLyQuanCafe.DTO; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace QuanLyQuanCafe.DAO { public class BillDAO { private static BillDAO instance; public static BillDAO Instance { get { if (instance == null) instance = new BillDAO(); return BillDAO.instance; } private set { BillDAO.instance = value; } } private BillDAO() { } /// <summary> /// Thành công: bill ID /// thất bại: -1 /// </summary> /// <param name="id"></param> /// <returns></returns> public int GetUncheckBillIDByTableID(int id) { DataTable data = DataProvider.Instance.ExecuteQuery("SELECT * FROM dbo.Bill WHERE idTable = " + id +" AND status = 0"); if (data.Rows.Count > 0) { Bill bill = new Bill(data.Rows[0]); return bill.ID; } return -1; } public void CheckOut(int id, int discount, float totalPrice) { string query = "UPDATE dbo.Bill SET dateCheckOut = GETDATE(), status = 1, " + "discount = " + discount + ", totalPrice = " + totalPrice + " WHERE id = " + id; DataProvider.Instance.ExecuteNonQuery(query); } public void InsertBill(int id) { DataProvider.Instance.ExecuteNonQuery("exec USP_InsertBill @idTable", new object[]{id}); } public DataTable GetBillListByDate(DateTime checkIn, DateTime checkOut) { return DataProvider.Instance.ExecuteQuery("exec USP_GetListBillByDate @checkIn , @checkOut", new object[]{checkIn, checkOut}); } public int GetMaxIDBill() { try { return (int)DataProvider.Instance.ExecuteScalar("SELECT MAX(id) FROM dbo.Bill"); } catch { return 1; } } } }Code fLogin.cs
using QuanLyQuanCafe.DAO; using QuanLyQuanCafe.DTO; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace QuanLyQuanCafe { public partial class fLogin : Form { public fLogin() { InitializeComponent(); } private void btnLogin_Click(object sender, EventArgs e) { string userName = txbUserName.Text; string passWord = txbPassWord.Text; if (Login(userName, passWord)) { Account loginAccount = AccountDAO.Instance.GetAccountByUserName(userName); fTableManager f = new fTableManager(loginAccount); this.Hide(); f.ShowDialog(); this.Show(); } else { MessageBox.Show("Sai tên tài khoản hoặc mật khẩu!"); } } bool Login(string userName, string passWord) { return AccountDAO.Instance.Login(userName, passWord); } private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); } private void fLogin_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("Bạn có thật sự muốn thoát chương trình?", "Thông báo", MessageBoxButtons.OKCancel) != System.Windows.Forms.DialogResult.OK) { e.Cancel = true; } } } }Code fAdmin.Designer.cs
namespace QuanLyQuanCafe { partial class fAdmin { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.tcAdmin = new System.Windows.Forms.TabControl(); this.tpBill = new System.Windows.Forms.TabPage(); this.panel2 = new System.Windows.Forms.Panel(); this.btnViewBill = new System.Windows.Forms.Button(); this.dtpkToDate = new System.Windows.Forms.DateTimePicker(); this.dtpkFromDate = new System.Windows.Forms.DateTimePicker(); this.panel1 = new System.Windows.Forms.Panel(); this.dtgvBill = new System.Windows.Forms.DataGridView(); this.tpFood = new System.Windows.Forms.TabPage(); this.panel6 = new System.Windows.Forms.Panel(); this.txbSearchFoodName = new System.Windows.Forms.TextBox(); this.btnSearchFood = new System.Windows.Forms.Button(); this.panel5 = new System.Windows.Forms.Panel(); this.panel10 = new System.Windows.Forms.Panel(); this.nmFoodPrice = new System.Windows.Forms.NumericUpDown(); this.label4 = new System.Windows.Forms.Label(); this.panel9 = new System.Windows.Forms.Panel(); this.cbFoodCategory = new System.Windows.Forms.ComboBox(); this.label3 = new System.Windows.Forms.Label(); this.panel8 = new System.Windows.Forms.Panel(); this.txbFoodName = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.panel7 = new System.Windows.Forms.Panel(); this.txbFoodID = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.panel4 = new System.Windows.Forms.Panel(); this.btnShowFood = new System.Windows.Forms.Button(); this.btnEditFood = new System.Windows.Forms.Button(); this.btnDeleteFood = new System.Windows.Forms.Button(); this.btnAddFood = new System.Windows.Forms.Button(); this.panel3 = new System.Windows.Forms.Panel(); this.dtgvFood = new System.Windows.Forms.DataGridView(); this.tbFoodCategory = new System.Windows.Forms.TabPage(); this.panel12 = new System.Windows.Forms.Panel(); this.panel15 = new System.Windows.Forms.Panel(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.panel16 = new System.Windows.Forms.Panel(); this.txbCategoryID = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); this.panel17 = new System.Windows.Forms.Panel(); this.btnShowCategory = new System.Windows.Forms.Button(); this.btnEditCategory = new System.Windows.Forms.Button(); this.btnDeleteCategory = new System.Windows.Forms.Button(); this.btnAddCategory = new System.Windows.Forms.Button(); this.panel18 = new System.Windows.Forms.Panel(); this.dtgvCategory = new System.Windows.Forms.DataGridView(); this.tpTable = new System.Windows.Forms.TabPage(); this.panel11 = new System.Windows.Forms.Panel(); this.panel21 = new System.Windows.Forms.Panel(); this.cbTableStatus = new System.Windows.Forms.ComboBox(); this.label9 = new System.Windows.Forms.Label(); this.panel13 = new System.Windows.Forms.Panel(); this.txbTableName = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.panel14 = new System.Windows.Forms.Panel(); this.textBox3 = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); this.panel19 = new System.Windows.Forms.Panel(); this.btnShowTable = new System.Windows.Forms.Button(); this.btnEditTable = new System.Windows.Forms.Button(); this.btnDeleteTable = new System.Windows.Forms.Button(); this.btnAddTable = new System.Windows.Forms.Button(); this.panel20 = new System.Windows.Forms.Panel(); this.dtgvTable = new System.Windows.Forms.DataGridView(); this.tpAccount = new System.Windows.Forms.TabPage(); this.panel23 = new System.Windows.Forms.Panel(); this.btnResetPassword = new System.Windows.Forms.Button(); this.panel25 = new System.Windows.Forms.Panel(); this.cbAccountType = new System.Windows.Forms.ComboBox(); this.label11 = new System.Windows.Forms.Label(); this.panel26 = new System.Windows.Forms.Panel(); this.txbDisplayName = new System.Windows.Forms.TextBox(); this.label12 = new System.Windows.Forms.Label(); this.panel27 = new System.Windows.Forms.Panel(); this.txbUserName = new System.Windows.Forms.TextBox(); this.label13 = new System.Windows.Forms.Label(); this.panel28 = new System.Windows.Forms.Panel(); this.btnShowAccount = new System.Windows.Forms.Button(); this.btnEditAccount = new System.Windows.Forms.Button(); this.btnDeleteAccount = new System.Windows.Forms.Button(); this.btnAddAccount = new System.Windows.Forms.Button(); this.panel29 = new System.Windows.Forms.Panel(); this.dtgvAccount = new System.Windows.Forms.DataGridView(); this.tcAdmin.SuspendLayout(); this.tpBill.SuspendLayout(); this.panel2.SuspendLayout(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dtgvBill)).BeginInit(); this.tpFood.SuspendLayout(); this.panel6.SuspendLayout(); this.panel5.SuspendLayout(); this.panel10.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.nmFoodPrice)).BeginInit(); this.panel9.SuspendLayout(); this.panel8.SuspendLayout(); this.panel7.SuspendLayout(); this.panel4.SuspendLayout(); this.panel3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dtgvFood)).BeginInit(); this.tbFoodCategory.SuspendLayout(); this.panel12.SuspendLayout(); this.panel15.SuspendLayout(); this.panel16.SuspendLayout(); this.panel17.SuspendLayout(); this.panel18.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dtgvCategory)).BeginInit(); this.tpTable.SuspendLayout(); this.panel11.SuspendLayout(); this.panel21.SuspendLayout(); this.panel13.SuspendLayout(); this.panel14.SuspendLayout(); this.panel19.SuspendLayout(); this.panel20.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dtgvTable)).BeginInit(); this.tpAccount.SuspendLayout(); this.panel23.SuspendLayout(); this.panel25.SuspendLayout(); this.panel26.SuspendLayout(); this.panel27.SuspendLayout(); this.panel28.SuspendLayout(); this.panel29.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dtgvAccount)).BeginInit(); this.SuspendLayout(); // // tcAdmin // this.tcAdmin.Controls.Add(this.tpBill); this.tcAdmin.Controls.Add(this.tpFood); this.tcAdmin.Controls.Add(this.tbFoodCategory); this.tcAdmin.Controls.Add(this.tpTable); this.tcAdmin.Controls.Add(this.tpAccount); this.tcAdmin.Location = new System.Drawing.Point(12, 12); this.tcAdmin.Name = "tcAdmin"; this.tcAdmin.SelectedIndex = 0; this.tcAdmin.Size = new System.Drawing.Size(658, 439); this.tcAdmin.TabIndex = 0; // // tpBill // this.tpBill.Controls.Add(this.panel2); this.tpBill.Controls.Add(this.panel1); this.tpBill.Location = new System.Drawing.Point(4, 22); this.tpBill.Name = "tpBill"; this.tpBill.Padding = new System.Windows.Forms.Padding(3); this.tpBill.Size = new System.Drawing.Size(650, 413); this.tpBill.TabIndex = 0; this.tpBill.Text = "Doanh thu"; this.tpBill.UseVisualStyleBackColor = true; // // panel2 // this.panel2.Controls.Add(this.btnViewBill); this.panel2.Controls.Add(this.dtpkToDate); this.panel2.Controls.Add(this.dtpkFromDate); this.panel2.Location = new System.Drawing.Point(6, 6); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(638, 26); this.panel2.TabIndex = 1; // // btnViewBill // this.btnViewBill.Location = new System.Drawing.Point(282, 0); this.btnViewBill.Name = "btnViewBill"; this.btnViewBill.Size = new System.Drawing.Size(75, 23); this.btnViewBill.TabIndex = 2; this.btnViewBill.Text = "Thống kê"; this.btnViewBill.UseVisualStyleBackColor = true; this.btnViewBill.Click += new System.EventHandler(this.btnViewBill_Click); // // dtpkToDate // this.dtpkToDate.Location = new System.Drawing.Point(435, 3); this.dtpkToDate.Name = "dtpkToDate"; this.dtpkToDate.Size = new System.Drawing.Size(200, 20); this.dtpkToDate.TabIndex = 1; // // dtpkFromDate // this.dtpkFromDate.Location = new System.Drawing.Point(3, 3); this.dtpkFromDate.Name = "dtpkFromDate"; this.dtpkFromDate.Size = new System.Drawing.Size(200, 20); this.dtpkFromDate.TabIndex = 0; // // panel1 // this.panel1.Controls.Add(this.dtgvBill); this.panel1.Location = new System.Drawing.Point(6, 38); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(638, 369); this.panel1.TabIndex = 0; // // dtgvBill // this.dtgvBill.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dtgvBill.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dtgvBill.Location = new System.Drawing.Point(3, 3); this.dtgvBill.Name = "dtgvBill"; this.dtgvBill.Size = new System.Drawing.Size(632, 363); this.dtgvBill.TabIndex = 0; // // tpFood // this.tpFood.Controls.Add(this.panel6); this.tpFood.Controls.Add(this.panel5); this.tpFood.Controls.Add(this.panel4); this.tpFood.Controls.Add(this.panel3); this.tpFood.Location = new System.Drawing.Point(4, 22); this.tpFood.Name = "tpFood"; this.tpFood.Padding = new System.Windows.Forms.Padding(3); this.tpFood.Size = new System.Drawing.Size(650, 413); this.tpFood.TabIndex = 1; this.tpFood.Text = "Thức ăn"; this.tpFood.UseVisualStyleBackColor = true; // // panel6 // this.panel6.Controls.Add(this.txbSearchFoodName); this.panel6.Controls.Add(this.btnSearchFood); this.panel6.Location = new System.Drawing.Point(361, 3); this.panel6.Name = "panel6"; this.panel6.Size = new System.Drawing.Size(283, 52); this.panel6.TabIndex = 3; // // txbSearchFoodName // this.txbSearchFoodName.Location = new System.Drawing.Point(3, 17); this.txbSearchFoodName.Name = "txbSearchFoodName"; this.txbSearchFoodName.Size = new System.Drawing.Size(199, 20); this.txbSearchFoodName.TabIndex = 5; // // btnSearchFood // this.btnSearchFood.Location = new System.Drawing.Point(208, 3); this.btnSearchFood.Name = "btnSearchFood"; this.btnSearchFood.Size = new System.Drawing.Size(75, 46); this.btnSearchFood.TabIndex = 4; this.btnSearchFood.Text = "Tìm"; this.btnSearchFood.UseVisualStyleBackColor = true; // // panel5 // this.panel5.Controls.Add(this.panel10); this.panel5.Controls.Add(this.panel9); this.panel5.Controls.Add(this.panel8); this.panel5.Controls.Add(this.panel7); this.panel5.Location = new System.Drawing.Point(361, 61); this.panel5.Name = "panel5"; this.panel5.Size = new System.Drawing.Size(285, 346); this.panel5.TabIndex = 2; // // panel10 // this.panel10.Controls.Add(this.nmFoodPrice); this.panel10.Controls.Add(this.label4); this.panel10.Location = new System.Drawing.Point(3, 153); this.panel10.Name = "panel10"; this.panel10.Size = new System.Drawing.Size(279, 44); this.panel10.TabIndex = 4; // // nmFoodPrice // this.nmFoodPrice.Location = new System.Drawing.Point(91, 8); this.nmFoodPrice.Maximum = new decimal(new int[] { 100000000, 0, 0, 0}); this.nmFoodPrice.Name = "nmFoodPrice"; this.nmFoodPrice.Size = new System.Drawing.Size(185, 20); this.nmFoodPrice.TabIndex = 1; // // label4 // this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label4.Location = new System.Drawing.Point(3, 9); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(40, 19); this.label4.TabIndex = 0; this.label4.Text = "Giá:"; // // panel9 // this.panel9.Controls.Add(this.cbFoodCategory); this.panel9.Controls.Add(this.label3); this.panel9.Location = new System.Drawing.Point(3, 103); this.panel9.Name = "panel9"; this.panel9.Size = new System.Drawing.Size(279, 44); this.panel9.TabIndex = 3; // // cbFoodCategory // this.cbFoodCategory.FormattingEnabled = true; this.cbFoodCategory.Location = new System.Drawing.Point(91, 9); this.cbFoodCategory.Name = "cbFoodCategory"; this.cbFoodCategory.Size = new System.Drawing.Size(185, 21); this.cbFoodCategory.TabIndex = 1; // // label3 // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label3.Location = new System.Drawing.Point(3, 9); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(93, 19); this.label3.TabIndex = 0; this.label3.Text = "Danh mục:"; // // panel8 // this.panel8.Controls.Add(this.txbFoodName); this.panel8.Controls.Add(this.label2); this.panel8.Location = new System.Drawing.Point(3, 53); this.panel8.Name = "panel8"; this.panel8.Size = new System.Drawing.Size(279, 44); this.panel8.TabIndex = 2; // // txbFoodName // this.txbFoodName.Location = new System.Drawing.Point(91, 8); this.txbFoodName.Name = "txbFoodName"; this.txbFoodName.Size = new System.Drawing.Size(185, 20); this.txbFoodName.TabIndex = 1; // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label2.Location = new System.Drawing.Point(3, 9); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(82, 19); this.label2.TabIndex = 0; this.label2.Text = "Tên món:"; // // panel7 // this.panel7.Controls.Add(this.txbFoodID); this.panel7.Controls.Add(this.label1); this.panel7.Location = new System.Drawing.Point(3, 3); this.panel7.Name = "panel7"; this.panel7.Size = new System.Drawing.Size(279, 44); this.panel7.TabIndex = 1; // // txbFoodID // this.txbFoodID.Location = new System.Drawing.Point(91, 8); this.txbFoodID.Name = "txbFoodID"; this.txbFoodID.ReadOnly = true; this.txbFoodID.Size = new System.Drawing.Size(185, 20); this.txbFoodID.TabIndex = 1; this.txbFoodID.TextChanged += new System.EventHandler(this.txbFoodID_TextChanged); // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label1.Location = new System.Drawing.Point(3, 9); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(31, 19); this.label1.TabIndex = 0; this.label1.Text = "ID:"; // // panel4 // this.panel4.Controls.Add(this.btnShowFood); this.panel4.Controls.Add(this.btnEditFood); this.panel4.Controls.Add(this.btnDeleteFood); this.panel4.Controls.Add(this.btnAddFood); this.panel4.Location = new System.Drawing.Point(6, 3); this.panel4.Name = "panel4"; this.panel4.Size = new System.Drawing.Size(349, 52); this.panel4.TabIndex = 1; // // btnShowFood // this.btnShowFood.Location = new System.Drawing.Point(246, 3); this.btnShowFood.Name = "btnShowFood"; this.btnShowFood.Size = new System.Drawing.Size(75, 46); this.btnShowFood.TabIndex = 3; this.btnShowFood.Text = "Xem"; this.btnShowFood.UseVisualStyleBackColor = true; this.btnShowFood.Click += new System.EventHandler(this.btnShowFood_Click); // // btnEditFood // this.btnEditFood.Location = new System.Drawing.Point(165, 3); this.btnEditFood.Name = "btnEditFood"; this.btnEditFood.Size = new System.Drawing.Size(75, 46); this.btnEditFood.TabIndex = 2; this.btnEditFood.Text = "Sửa"; this.btnEditFood.UseVisualStyleBackColor = true; this.btnEditFood.Click += new System.EventHandler(this.btnEditFood_Click); // // btnDeleteFood // this.btnDeleteFood.Location = new System.Drawing.Point(84, 3); this.btnDeleteFood.Name = "btnDeleteFood"; this.btnDeleteFood.Size = new System.Drawing.Size(75, 46); this.btnDeleteFood.TabIndex = 1; this.btnDeleteFood.Text = "Xóa"; this.btnDeleteFood.UseVisualStyleBackColor = true; this.btnDeleteFood.Click += new System.EventHandler(this.btnDeleteFood_Click); // // btnAddFood // this.btnAddFood.Location = new System.Drawing.Point(3, 3); this.btnAddFood.Name = "btnAddFood"; this.btnAddFood.Size = new System.Drawing.Size(75, 46); this.btnAddFood.TabIndex = 0; this.btnAddFood.Text = "Thêm"; this.btnAddFood.UseVisualStyleBackColor = true; this.btnAddFood.Click += new System.EventHandler(this.btnAddFood_Click); // // panel3 // this.panel3.Controls.Add(this.dtgvFood); this.panel3.Location = new System.Drawing.Point(6, 61); this.panel3.Name = "panel3"; this.panel3.Size = new System.Drawing.Size(349, 346); this.panel3.TabIndex = 0; // // dtgvFood // this.dtgvFood.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dtgvFood.Location = new System.Drawing.Point(3, 3); this.dtgvFood.Name = "dtgvFood"; this.dtgvFood.Size = new System.Drawing.Size(343, 340); this.dtgvFood.TabIndex = 0; // // tbFoodCategory // this.tbFoodCategory.Controls.Add(this.panel12); this.tbFoodCategory.Controls.Add(this.panel17); this.tbFoodCategory.Controls.Add(this.panel18); this.tbFoodCategory.Location = new System.Drawing.Point(4, 22); this.tbFoodCategory.Name = "tbFoodCategory"; this.tbFoodCategory.Padding = new System.Windows.Forms.Padding(3); this.tbFoodCategory.Size = new System.Drawing.Size(650, 413); this.tbFoodCategory.TabIndex = 2; this.tbFoodCategory.Text = "Danh mục"; this.tbFoodCategory.UseVisualStyleBackColor = true; // // panel12 // this.panel12.Controls.Add(this.panel15); this.panel12.Controls.Add(this.panel16); this.panel12.Location = new System.Drawing.Point(360, 62); this.panel12.Name = "panel12"; this.panel12.Size = new System.Drawing.Size(285, 346); this.panel12.TabIndex = 6; // // panel15 // this.panel15.Controls.Add(this.textBox2); this.panel15.Controls.Add(this.label7); this.panel15.Location = new System.Drawing.Point(3, 53); this.panel15.Name = "panel15"; this.panel15.Size = new System.Drawing.Size(279, 44); this.panel15.TabIndex = 2; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(125, 8); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(151, 20); this.textBox2.TabIndex = 1; // // label7 // this.label7.AutoSize = true; this.label7.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label7.Location = new System.Drawing.Point(3, 9); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(124, 19); this.label7.TabIndex = 0; this.label7.Text = "Tên danh mục:"; // // panel16 // this.panel16.Controls.Add(this.txbCategoryID); this.panel16.Controls.Add(this.label8); this.panel16.Location = new System.Drawing.Point(3, 3); this.panel16.Name = "panel16"; this.panel16.Size = new System.Drawing.Size(279, 44); this.panel16.TabIndex = 1; // // txbCategoryID // this.txbCategoryID.Location = new System.Drawing.Point(125, 8); this.txbCategoryID.Name = "txbCategoryID"; this.txbCategoryID.ReadOnly = true; this.txbCategoryID.Size = new System.Drawing.Size(151, 20); this.txbCategoryID.TabIndex = 1; // // label8 // this.label8.AutoSize = true; this.label8.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label8.Location = new System.Drawing.Point(3, 9); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(31, 19); this.label8.TabIndex = 0; this.label8.Text = "ID:"; // // panel17 // this.panel17.Controls.Add(this.btnShowCategory); this.panel17.Controls.Add(this.btnEditCategory); this.panel17.Controls.Add(this.btnDeleteCategory); this.panel17.Controls.Add(this.btnAddCategory); this.panel17.Location = new System.Drawing.Point(5, 4); this.panel17.Name = "panel17"; this.panel17.Size = new System.Drawing.Size(349, 52); this.panel17.TabIndex = 5; // // btnShowCategory // this.btnShowCategory.Location = new System.Drawing.Point(246, 3); this.btnShowCategory.Name = "btnShowCategory"; this.btnShowCategory.Size = new System.Drawing.Size(75, 46); this.btnShowCategory.TabIndex = 3; this.btnShowCategory.Text = "Xem"; this.btnShowCategory.UseVisualStyleBackColor = true; // // btnEditCategory // this.btnEditCategory.Location = new System.Drawing.Point(165, 3); this.btnEditCategory.Name = "btnEditCategory"; this.btnEditCategory.Size = new System.Drawing.Size(75, 46); this.btnEditCategory.TabIndex = 2; this.btnEditCategory.Text = "Sửa"; this.btnEditCategory.UseVisualStyleBackColor = true; // // btnDeleteCategory // this.btnDeleteCategory.Location = new System.Drawing.Point(84, 3); this.btnDeleteCategory.Name = "btnDeleteCategory"; this.btnDeleteCategory.Size = new System.Drawing.Size(75, 46); this.btnDeleteCategory.TabIndex = 1; this.btnDeleteCategory.Text = "Xóa"; this.btnDeleteCategory.UseVisualStyleBackColor = true; // // btnAddCategory // this.btnAddCategory.Location = new System.Drawing.Point(3, 3); this.btnAddCategory.Name = "btnAddCategory"; this.btnAddCategory.Size = new System.Drawing.Size(75, 46); this.btnAddCategory.TabIndex = 0; this.btnAddCategory.Text = "Thêm"; this.btnAddCategory.UseVisualStyleBackColor = true; // // panel18 // this.panel18.Controls.Add(this.dtgvCategory); this.panel18.Location = new System.Drawing.Point(5, 62); this.panel18.Name = "panel18"; this.panel18.Size = new System.Drawing.Size(349, 346); this.panel18.TabIndex = 4; // // dtgvCategory // this.dtgvCategory.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dtgvCategory.Location = new System.Drawing.Point(3, 3); this.dtgvCategory.Name = "dtgvCategory"; this.dtgvCategory.Size = new System.Drawing.Size(343, 340); this.dtgvCategory.TabIndex = 0; // // tpTable // this.tpTable.Controls.Add(this.panel11); this.tpTable.Controls.Add(this.panel19); this.tpTable.Controls.Add(this.panel20); this.tpTable.Location = new System.Drawing.Point(4, 22); this.tpTable.Name = "tpTable"; this.tpTable.Padding = new System.Windows.Forms.Padding(3); this.tpTable.Size = new System.Drawing.Size(650, 413); this.tpTable.TabIndex = 3; this.tpTable.Text = "Bàn ăn"; this.tpTable.UseVisualStyleBackColor = true; // // panel11 // this.panel11.Controls.Add(this.panel21); this.panel11.Controls.Add(this.panel13); this.panel11.Controls.Add(this.panel14); this.panel11.Location = new System.Drawing.Point(360, 62); this.panel11.Name = "panel11"; this.panel11.Size = new System.Drawing.Size(285, 346); this.panel11.TabIndex = 9; // // panel21 // this.panel21.Controls.Add(this.cbTableStatus); this.panel21.Controls.Add(this.label9); this.panel21.Location = new System.Drawing.Point(3, 103); this.panel21.Name = "panel21"; this.panel21.Size = new System.Drawing.Size(279, 44); this.panel21.TabIndex = 3; // // cbTableStatus // this.cbTableStatus.FormattingEnabled = true; this.cbTableStatus.Location = new System.Drawing.Point(125, 9); this.cbTableStatus.Name = "cbTableStatus"; this.cbTableStatus.Size = new System.Drawing.Size(151, 21); this.cbTableStatus.TabIndex = 1; // // label9 // this.label9.AutoSize = true; this.label9.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label9.Location = new System.Drawing.Point(3, 9); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(91, 19); this.label9.TabIndex = 0; this.label9.Text = "Trạng thái:"; // // panel13 // this.panel13.Controls.Add(this.txbTableName); this.panel13.Controls.Add(this.label5); this.panel13.Location = new System.Drawing.Point(3, 53); this.panel13.Name = "panel13"; this.panel13.Size = new System.Drawing.Size(279, 44); this.panel13.TabIndex = 2; // // txbTableName // this.txbTableName.Location = new System.Drawing.Point(125, 8); this.txbTableName.Name = "txbTableName"; this.txbTableName.Size = new System.Drawing.Size(151, 20); this.txbTableName.TabIndex = 1; // // label5 // this.label5.AutoSize = true; this.label5.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label5.Location = new System.Drawing.Point(3, 9); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(77, 19); this.label5.TabIndex = 0; this.label5.Text = "Tên bàn:"; // // panel14 // this.panel14.Controls.Add(this.textBox3); this.panel14.Controls.Add(this.label6); this.panel14.Location = new System.Drawing.Point(3, 3); this.panel14.Name = "panel14"; this.panel14.Size = new System.Drawing.Size(279, 44); this.panel14.TabIndex = 1; // // textBox3 // this.textBox3.Location = new System.Drawing.Point(125, 8); this.textBox3.Name = "textBox3"; this.textBox3.ReadOnly = true; this.textBox3.Size = new System.Drawing.Size(151, 20); this.textBox3.TabIndex = 1; // // label6 // this.label6.AutoSize = true; this.label6.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label6.Location = new System.Drawing.Point(3, 9); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(31, 19); this.label6.TabIndex = 0; this.label6.Text = "ID:"; // // panel19 // this.panel19.Controls.Add(this.btnShowTable); this.panel19.Controls.Add(this.btnEditTable); this.panel19.Controls.Add(this.btnDeleteTable); this.panel19.Controls.Add(this.btnAddTable); this.panel19.Location = new System.Drawing.Point(5, 4); this.panel19.Name = "panel19"; this.panel19.Size = new System.Drawing.Size(349, 52); this.panel19.TabIndex = 8; // // btnShowTable // this.btnShowTable.Location = new System.Drawing.Point(246, 3); this.btnShowTable.Name = "btnShowTable"; this.btnShowTable.Size = new System.Drawing.Size(75, 46); this.btnShowTable.TabIndex = 3; this.btnShowTable.Text = "Xem"; this.btnShowTable.UseVisualStyleBackColor = true; // // btnEditTable // this.btnEditTable.Location = new System.Drawing.Point(165, 3); this.btnEditTable.Name = "btnEditTable"; this.btnEditTable.Size = new System.Drawing.Size(75, 46); this.btnEditTable.TabIndex = 2; this.btnEditTable.Text = "Sửa"; this.btnEditTable.UseVisualStyleBackColor = true; // // btnDeleteTable // this.btnDeleteTable.Location = new System.Drawing.Point(84, 3); this.btnDeleteTable.Name = "btnDeleteTable"; this.btnDeleteTable.Size = new System.Drawing.Size(75, 46); this.btnDeleteTable.TabIndex = 1; this.btnDeleteTable.Text = "Xóa"; this.btnDeleteTable.UseVisualStyleBackColor = true; // // btnAddTable // this.btnAddTable.Location = new System.Drawing.Point(3, 3); this.btnAddTable.Name = "btnAddTable"; this.btnAddTable.Size = new System.Drawing.Size(75, 46); this.btnAddTable.TabIndex = 0; this.btnAddTable.Text = "Thêm"; this.btnAddTable.UseVisualStyleBackColor = true; // // panel20 // this.panel20.Controls.Add(this.dtgvTable); this.panel20.Location = new System.Drawing.Point(5, 62); this.panel20.Name = "panel20"; this.panel20.Size = new System.Drawing.Size(349, 346); this.panel20.TabIndex = 7; // // dtgvTable // this.dtgvTable.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dtgvTable.Location = new System.Drawing.Point(3, 3); this.dtgvTable.Name = "dtgvTable"; this.dtgvTable.Size = new System.Drawing.Size(343, 340); this.dtgvTable.TabIndex = 0; // // tpAccount // this.tpAccount.Controls.Add(this.panel23); this.tpAccount.Controls.Add(this.panel28); this.tpAccount.Controls.Add(this.panel29); this.tpAccount.Location = new System.Drawing.Point(4, 22); this.tpAccount.Name = "tpAccount"; this.tpAccount.Padding = new System.Windows.Forms.Padding(3); this.tpAccount.Size = new System.Drawing.Size(650, 413); this.tpAccount.TabIndex = 4; this.tpAccount.Text = "Tài khoản"; this.tpAccount.UseVisualStyleBackColor = true; // // panel23 // this.panel23.Controls.Add(this.btnResetPassword); this.panel23.Controls.Add(this.panel25); this.panel23.Controls.Add(this.panel26); this.panel23.Controls.Add(this.panel27); this.panel23.Location = new System.Drawing.Point(360, 62); this.panel23.Name = "panel23"; this.panel23.Size = new System.Drawing.Size(285, 346); this.panel23.TabIndex = 6; // // btnResetPassword // this.btnResetPassword.Location = new System.Drawing.Point(204, 153); this.btnResetPassword.Name = "btnResetPassword"; this.btnResetPassword.Size = new System.Drawing.Size(75, 46); this.btnResetPassword.TabIndex = 4; this.btnResetPassword.Text = "Đặt lại mật khẩu"; this.btnResetPassword.UseVisualStyleBackColor = true; // // panel25 // this.panel25.Controls.Add(this.cbAccountType); this.panel25.Controls.Add(this.label11); this.panel25.Location = new System.Drawing.Point(3, 103); this.panel25.Name = "panel25"; this.panel25.Size = new System.Drawing.Size(279, 44); this.panel25.TabIndex = 3; // // cbAccountType // this.cbAccountType.FormattingEnabled = true; this.cbAccountType.Location = new System.Drawing.Point(127, 9); this.cbAccountType.Name = "cbAccountType"; this.cbAccountType.Size = new System.Drawing.Size(149, 21); this.cbAccountType.TabIndex = 1; // // label11 // this.label11.AutoSize = true; this.label11.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label11.Location = new System.Drawing.Point(3, 9); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(116, 19); this.label11.TabIndex = 0; this.label11.Text = "Loại tài khoản"; // // panel26 // this.panel26.Controls.Add(this.txbDisplayName); this.panel26.Controls.Add(this.label12); this.panel26.Location = new System.Drawing.Point(3, 53); this.panel26.Name = "panel26"; this.panel26.Size = new System.Drawing.Size(279, 44); this.panel26.TabIndex = 2; // // txbDisplayName // this.txbDisplayName.Location = new System.Drawing.Point(127, 8); this.txbDisplayName.Name = "txbDisplayName"; this.txbDisplayName.Size = new System.Drawing.Size(149, 20); this.txbDisplayName.TabIndex = 1; // // label12 // this.label12.AutoSize = true; this.label12.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label12.Location = new System.Drawing.Point(3, 9); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(104, 19); this.label12.TabIndex = 0; this.label12.Text = "Tên hiển thị:"; // // panel27 // this.panel27.Controls.Add(this.txbUserName); this.panel27.Controls.Add(this.label13); this.panel27.Location = new System.Drawing.Point(3, 3); this.panel27.Name = "panel27"; this.panel27.Size = new System.Drawing.Size(279, 44); this.panel27.TabIndex = 1; // // txbUserName // this.txbUserName.Location = new System.Drawing.Point(127, 8); this.txbUserName.Name = "txbUserName"; this.txbUserName.ReadOnly = true; this.txbUserName.Size = new System.Drawing.Size(149, 20); this.txbUserName.TabIndex = 1; // // label13 // this.label13.AutoSize = true; this.label13.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))); this.label13.Location = new System.Drawing.Point(3, 9); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(118, 19); this.label13.TabIndex = 0; this.label13.Text = "Tên tài khoản:"; // // panel28 // this.panel28.Controls.Add(this.btnShowAccount); this.panel28.Controls.Add(this.btnEditAccount); this.panel28.Controls.Add(this.btnDeleteAccount); this.panel28.Controls.Add(this.btnAddAccount); this.panel28.Location = new System.Drawing.Point(5, 4); this.panel28.Name = "panel28"; this.panel28.Size = new System.Drawing.Size(349, 52); this.panel28.TabIndex = 5; // // btnShowAccount // this.btnShowAccount.Location = new System.Drawing.Point(246, 3); this.btnShowAccount.Name = "btnShowAccount"; this.btnShowAccount.Size = new System.Drawing.Size(75, 46); this.btnShowAccount.TabIndex = 3; this.btnShowAccount.Text = "Xem"; this.btnShowAccount.UseVisualStyleBackColor = true; // // btnEditAccount // this.btnEditAccount.Location = new System.Drawing.Point(165, 3); this.btnEditAccount.Name = "btnEditAccount"; this.btnEditAccount.Size = new System.Drawing.Size(75, 46); this.btnEditAccount.TabIndex = 2; this.btnEditAccount.Text = "Sửa"; this.btnEditAccount.UseVisualStyleBackColor = true; // // btnDeleteAccount // this.btnDeleteAccount.Location = new System.Drawing.Point(84, 3); this.btnDeleteAccount.Name = "btnDeleteAccount"; this.btnDeleteAccount.Size = new System.Drawing.Size(75, 46); this.btnDeleteAccount.TabIndex = 1; this.btnDeleteAccount.Text = "Xóa"; this.btnDeleteAccount.UseVisualStyleBackColor = true; // // btnAddAccount // this.btnAddAccount.Location = new System.Drawing.Point(3, 3); this.btnAddAccount.Name = "btnAddAccount"; this.btnAddAccount.Size = new System.Drawing.Size(75, 46); this.btnAddAccount.TabIndex = 0; this.btnAddAccount.Text = "Thêm"; this.btnAddAccount.UseVisualStyleBackColor = true; // // panel29 // this.panel29.Controls.Add(this.dtgvAccount); this.panel29.Location = new System.Drawing.Point(5, 62); this.panel29.Name = "panel29"; this.panel29.Size = new System.Drawing.Size(349, 346); this.panel29.TabIndex = 4; // // dtgvAccount // this.dtgvAccount.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dtgvAccount.Location = new System.Drawing.Point(3, 3); this.dtgvAccount.Name = "dtgvAccount"; this.dtgvAccount.Size = new System.Drawing.Size(343, 340); this.dtgvAccount.TabIndex = 0; // // fAdmin // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(674, 463); this.Controls.Add(this.tcAdmin); this.Name = "fAdmin"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Admin"; this.tcAdmin.ResumeLayout(false); this.tpBill.ResumeLayout(false); this.panel2.ResumeLayout(false); this.panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dtgvBill)).EndInit(); this.tpFood.ResumeLayout(false); this.panel6.ResumeLayout(false); this.panel6.PerformLayout(); this.panel5.ResumeLayout(false); this.panel10.ResumeLayout(false); this.panel10.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.nmFoodPrice)).EndInit(); this.panel9.ResumeLayout(false); this.panel9.PerformLayout(); this.panel8.ResumeLayout(false); this.panel8.PerformLayout(); this.panel7.ResumeLayout(false); this.panel7.PerformLayout(); this.panel4.ResumeLayout(false); this.panel3.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dtgvFood)).EndInit(); this.tbFoodCategory.ResumeLayout(false); this.panel12.ResumeLayout(false); this.panel15.ResumeLayout(false); this.panel15.PerformLayout(); this.panel16.ResumeLayout(false); this.panel16.PerformLayout(); this.panel17.ResumeLayout(false); this.panel18.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dtgvCategory)).EndInit(); this.tpTable.ResumeLayout(false); this.panel11.ResumeLayout(false); this.panel21.ResumeLayout(false); this.panel21.PerformLayout(); this.panel13.ResumeLayout(false); this.panel13.PerformLayout(); this.panel14.ResumeLayout(false); this.panel14.PerformLayout(); this.panel19.ResumeLayout(false); this.panel20.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dtgvTable)).EndInit(); this.tpAccount.ResumeLayout(false); this.panel23.ResumeLayout(false); this.panel25.ResumeLayout(false); this.panel25.PerformLayout(); this.panel26.ResumeLayout(false); this.panel26.PerformLayout(); this.panel27.ResumeLayout(false); this.panel27.PerformLayout(); this.panel28.ResumeLayout(false); this.panel29.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dtgvAccount)).EndInit(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.TabControl tcAdmin; private System.Windows.Forms.TabPage tpBill; private System.Windows.Forms.Panel panel2; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.DataGridView dtgvBill; private System.Windows.Forms.TabPage tpFood; private System.Windows.Forms.TabPage tbFoodCategory; private System.Windows.Forms.TabPage tpTable; private System.Windows.Forms.TabPage tpAccount; private System.Windows.Forms.Button btnViewBill; private System.Windows.Forms.DateTimePicker dtpkToDate; private System.Windows.Forms.DateTimePicker dtpkFromDate; private System.Windows.Forms.Panel panel6; private System.Windows.Forms.TextBox txbSearchFoodName; private System.Windows.Forms.Button btnSearchFood; private System.Windows.Forms.Panel panel5; private System.Windows.Forms.Panel panel4; private System.Windows.Forms.Button btnShowFood; private System.Windows.Forms.Button btnEditFood; private System.Windows.Forms.Button btnDeleteFood; private System.Windows.Forms.Button btnAddFood; private System.Windows.Forms.Panel panel3; private System.Windows.Forms.DataGridView dtgvFood; private System.Windows.Forms.Panel panel8; private System.Windows.Forms.TextBox txbFoodName; private System.Windows.Forms.Label label2; private System.Windows.Forms.Panel panel7; private System.Windows.Forms.TextBox txbFoodID; private System.Windows.Forms.Label label1; private System.Windows.Forms.Panel panel10; private System.Windows.Forms.NumericUpDown nmFoodPrice; private System.Windows.Forms.Label label4; private System.Windows.Forms.Panel panel9; private System.Windows.Forms.ComboBox cbFoodCategory; private System.Windows.Forms.Label label3; private System.Windows.Forms.Panel panel12; private System.Windows.Forms.Panel panel15; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label7; private System.Windows.Forms.Panel panel16; private System.Windows.Forms.TextBox txbCategoryID; private System.Windows.Forms.Label label8; private System.Windows.Forms.Panel panel17; private System.Windows.Forms.Button btnShowCategory; private System.Windows.Forms.Button btnEditCategory; private System.Windows.Forms.Button btnDeleteCategory; private System.Windows.Forms.Button btnAddCategory; private System.Windows.Forms.Panel panel18; private System.Windows.Forms.DataGridView dtgvCategory; private System.Windows.Forms.Panel panel11; private System.Windows.Forms.Panel panel21; private System.Windows.Forms.ComboBox cbTableStatus; private System.Windows.Forms.Label label9; private System.Windows.Forms.Panel panel13; private System.Windows.Forms.TextBox txbTableName; private System.Windows.Forms.Label label5; private System.Windows.Forms.Panel panel14; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Label label6; private System.Windows.Forms.Panel panel19; private System.Windows.Forms.Button btnShowTable; private System.Windows.Forms.Button btnEditTable; private System.Windows.Forms.Button btnDeleteTable; private System.Windows.Forms.Button btnAddTable; private System.Windows.Forms.Panel panel20; private System.Windows.Forms.DataGridView dtgvTable; private System.Windows.Forms.Panel panel23; private System.Windows.Forms.Button btnResetPassword; private System.Windows.Forms.Panel panel25; private System.Windows.Forms.ComboBox cbAccountType; private System.Windows.Forms.Label label11; private System.Windows.Forms.Panel panel26; private System.Windows.Forms.TextBox txbDisplayName; private System.Windows.Forms.Label label12; private System.Windows.Forms.Panel panel27; private System.Windows.Forms.TextBox txbUserName; private System.Windows.Forms.Label label13; private System.Windows.Forms.Panel panel28; private System.Windows.Forms.Button btnShowAccount; private System.Windows.Forms.Button btnEditAccount; private System.Windows.Forms.Button btnDeleteAccount; private System.Windows.Forms.Button btnAddAccount; private System.Windows.Forms.Panel panel29; private System.Windows.Forms.DataGridView dtgvAccount; } }Code fAdmin.cs
using QuanLyQuanCafe.DAO; using QuanLyQuanCafe.DTO; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace QuanLyQuanCafe { public partial class fAdmin : Form { BindingSource foodList = new BindingSource(); public fAdmin() { InitializeComponent(); Load(); } #region methods void Load() { dtgvFood.DataSource = foodList; LoadDateTimePickerBill(); LoadListBillByDate(dtpkFromDate.Value, dtpkToDate.Value); LoadListFood(); LoadCategoryIntoCombobox(cbFoodCategory); AddFoodBinding(); } void LoadDateTimePickerBill() { DateTime today = DateTime.Now; dtpkFromDate.Value = new DateTime(today.Year, today.Month, 1); dtpkToDate.Value = dtpkFromDate.Value.AddMonths(1).AddDays(-1); } void LoadListBillByDate(DateTime checkIn, DateTime checkOut) { dtgvBill.DataSource = BillDAO.Instance.GetBillListByDate(checkIn, checkOut); } void AddFoodBinding() { txbFoodName.DataBindings.Add(new Binding("Text", dtgvFood.DataSource, "Name", true, DataSourceUpdateMode.Never)); txbFoodID.DataBindings.Add(new Binding("Text", dtgvFood.DataSource, "ID", true, DataSourceUpdateMode.Never)); nmFoodPrice.DataBindings.Add(new Binding("Value", dtgvFood.DataSource, "Price", true, DataSourceUpdateMode.Never)); } void LoadCategoryIntoCombobox(ComboBox cb) { cb.DataSource = CategoryDAO.Instance.GetListCategory(); cb.DisplayMember = "Name"; } void LoadListFood() { foodList.DataSource = FoodDAO.Instance.GetListFood(); } #endregion #region events private void txbFoodID_TextChanged(object sender, EventArgs e) { if (dtgvFood.SelectedCells.Count > 0) { int id = (int)dtgvFood.SelectedCells[0].OwningRow.Cells["CategoryID"].Value; Category cateogory = CategoryDAO.Instance.GetCategoryByID(id); cbFoodCategory.SelectedItem = cateogory; int index = -1; int i = 0; foreach (Category item in cbFoodCategory.Items) { if (item.ID == cateogory.ID) { index = i; break; } i++; } cbFoodCategory.SelectedIndex = index; } } private void btnAddFood_Click(object sender, EventArgs e) { string name = txbFoodName.Text; int categoryID = (cbFoodCategory.SelectedItem as Category).ID; float price = (float)nmFoodPrice.Value; if (FoodDAO.Instance.InsertFood(name, categoryID, price)) { MessageBox.Show("Thêm món thành công"); LoadListFood(); if (insertFood != null) insertFood(this, new EventArgs()); } else { MessageBox.Show("Có lỗi khi thêm thức ăn"); } } private void btnEditFood_Click(object sender, EventArgs e) { string name = txbFoodName.Text; int categoryID = (cbFoodCategory.SelectedItem as Category).ID; float price = (float)nmFoodPrice.Value; int id = Convert.ToInt32(txbFoodID.Text); if (FoodDAO.Instance.UpdateFood(id, name, categoryID, price)) { MessageBox.Show("Sửa món thành công"); LoadListFood(); if (updateFood != null) updateFood(this, new EventArgs()); } else { MessageBox.Show("Có lỗi khi sửa thức ăn"); } } private void btnDeleteFood_Click(object sender, EventArgs e) { int id = Convert.ToInt32(txbFoodID.Text); if (FoodDAO.Instance.DeleteFood(id)) { MessageBox.Show("Xóa món thành công"); LoadListFood(); if (deleteFood != null) deleteFood(this, new EventArgs()); } else { MessageBox.Show("Có lỗi khi xóa thức ăn"); } } private void btnShowFood_Click(object sender, EventArgs e) { LoadListFood(); } private void btnViewBill_Click(object sender, EventArgs e) { LoadListBillByDate(dtpkFromDate.Value, dtpkToDate.Value); } private event EventHandler insertFood; public event EventHandler InsertFood { add { insertFood += value; } remove { insertFood -= value; } } private event EventHandler deleteFood; public event EventHandler DeleteFood { add { deleteFood += value; } remove { deleteFood -= value; } } private event EventHandler updateFood; public event EventHandler UpdateFood { add { updateFood += value; } remove { updateFood -= value; } } #endregion } }Bài sau chúng ta sẽ cùng nhau tìm hiểu cách tìm kiếm gần đúng thức ăn.
Đừng quên: “Luyện tập – Thử thách – Không ngại khó”
Tải xuống
Tài liệu
Nhằm phục vụ mục đích học tập Offline của cộng đồng, Kteam hỗ trợ tính năng lưu trữ nội dung bài học Thêm, xóa, sửa thức ăn trong phần mềm Quản lý quán cafe với C# Winform dưới dạng file PDF trong link bên dưới.
Ngoài ra, bạn cũng có thể tìm thấy các tài liệu được đóng góp từ cộng đồng ở mục TÀI LIỆU trên thư viện Howkteam.com
Đừng quên like và share để ủng hộ Kteam và tác giả nhé!
Project
Nếu việc thực hành theo hướng dẫn không diễn ra suôn sẻ như mong muốn. Bạn cũng có thể tải xuống PROJECT THAM KHẢO ở link bên dưới!
Thảo luận
Nếu bạn có bất kỳ khó khăn hay thắc mắc gì về khóa học, đừng ngần ngại đặt câu hỏi trong phần BÌNH LUẬN bên dưới hoặc trong mục HỎI & ĐÁP trên thư viện Howkteam.com để nhận được sự hỗ trợ từ cộng đồng.
CỘNG ĐỒNG HỎI ĐÁP HOWKTEAM.COM GROUP THẢO LUẬN FACEBOOKTừ khóa » Thêm Xóa Sửa Trên C#
-
Thêm, Sửa, Xóa Học Sinh Trong C# Winforms - Freetuts
-
Thêm, Sửa, Xóa User Trong C# Winforms - Freetuts
-
[C#] Hướng Dẫn Thêm, Lưu, Xóa, Sửa, Tìm Kiếm ... - Lập Trình VB.NET
-
[C# Cơ Bản] - Thêm, Sửa, Xóa, Tìm Kiếm - YouTube
-
[Lập Trình Winform C#] - Thêm, Sửa, Xóa, Thoát Dữ Liệu ... - Tiện ích
-
Thêm Sửa-xóa-combobox - C# - SlideShare
-
[Lập Trình Winform C#] – Thêm, Sửa, Xóa, Thoát Dữ Liệu C# Sql ...
-
[C#] Hướng Dẫn Thêm, Lưu, Xóa, Sửa, Tìm Kiếm ...
-
Lập Trình Cơ Sở Dữ Liệu Với C# | Tìm ở đây
-
Tổng Hợp Hàm Thêm, Xóa, Sửa Trong Lập Trình C# Theo Mô Hình 3 Lớp
-
[Lập Trình Winform C#] – Thêm, Sửa, Xóa, Thoát Dữ Liệu C# Sql ...
-
Thêm Xóa Sửa Trên Lưới Dữ Liệu Với GridControl GridView ...
-
Thêm, đọc, Sửa, Xóa (CRUD) Cơ Sở Dữ Liệu SQL Server Trong C# ...
-
Thêm, Xóa, Sửa Trực Tiếp Trên Datagridview Bằng Ngôn Ngữ C# (Quản ...