Dẫn nhập
Bạn đã học qua LẬP TRÌNH C# CƠ BẢN ? Xong nốt cả LẬP TRÌNH WINFORM lẫn SQL ?
Bạn đã chán các bài tập căn bản, muốn thực hành các kiến thức đã học vào một dự án thực tế?
Hay đơn giản bạn là chủ quán café, mong muốn tự tạo nên phần mềm dành cho chính mình sử dụng?
Sẽ 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 CAFÉ VỚI C# WINFORM
Ở bài trước, Kteam đã hướng dẫn bạn cách
HẠN CHẾ LỖI SQL INJECTION CHO PHẦN MỀM QUẢN LÝ QUÁN CAFE . Trong bài này, chúng ta sẽ tìm hiểu cách
Hiển thị số bàn theo CSDL cho phần mềm Quản lý quán cafe với C# Winform
Nội dung
Nội dung bao gồm Source code & các lưu ý chính về quá trình thực hiện phần mềm. Kteam khuyến khích bạn cập nhập thêm nhiều kinh nghiệm cũng như hiểu chi tiết hơn về các kỹ thuật được đề cập trong bài học thông qua các video đính kèm.
Đừng quên Like Facebook hoặc +1 Google để ủng hộ Kteam và tác giả.
Để theo dõi tốt khóa học này, hãy đảm bảo bạn đã xem qua kiến thức về:
Project tham khảo
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
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
Code fLogin.Designer.cs
namespace QuanLyQuanCafe
{
partial class fLogin
{
private System.ComponentModel.IContainer components = null ;
protected override void Dispose (bool disposing)
{
if (disposing && (components != null ))
{
components.Dispose();
}
base .Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent ()
{
this .panel1 = new System.Windows.Forms.Panel();
this .btnExit = new System.Windows.Forms.Button();
this .btnLogin = new System.Windows.Forms.Button();
this .panel3 = new System.Windows.Forms.Panel();
this .txbPassWord = new System.Windows.Forms.TextBox();
this .label2 = new System.Windows.Forms.Label();
this .panel2 = new System.Windows.Forms.Panel();
this .txbUserName = new System.Windows.Forms.TextBox();
this .label1 = new System.Windows.Forms.Label();
this .panel1.SuspendLayout();
this .panel3.SuspendLayout();
this .panel2.SuspendLayout();
this .SuspendLayout();
this .panel1.Controls.Add(this .btnExit);
this .panel1.Controls.Add(this .btnLogin);
this .panel1.Controls.Add(this .panel3);
this .panel1.Controls.Add(this .panel2);
this .panel1.Location = new System.Drawing.Point(12 , 12 );
this .panel1.Name = "panel1" ;
this .panel1.Size = new System.Drawing.Size(400 , 136 );
this .panel1.TabIndex = 0 ;
this .btnExit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this .btnExit.Location = new System.Drawing.Point(319 , 103 );
this .btnExit.Name = "btnExit" ;
this .btnExit.Size = new System.Drawing.Size(75 , 23 );
this .btnExit.TabIndex = 3 ;
this .btnExit.Text = "Thoát" ;
this .btnExit.UseVisualStyleBackColor = true ;
this .btnExit.Click += new System.EventHandler(this .btnExit_Click);
this .btnLogin.Location = new System.Drawing.Point(238 , 103 );
this .btnLogin.Name = "btnLogin" ;
this .btnLogin.Size = new System.Drawing.Size(75 , 23 );
this .btnLogin.TabIndex = 2 ;
this .btnLogin.Text = "Đăng nhập" ;
this .btnLogin.UseVisualStyleBackColor = true ;
this .btnLogin.Click += new System.EventHandler(this .btnLogin_Click);
this .panel3.Controls.Add(this .txbPassWord);
this .panel3.Controls.Add(this .label2);
this .panel3.Location = new System.Drawing.Point(3 , 53 );
this .panel3.Name = "panel3" ;
this .panel3.Size = new System.Drawing.Size(394 , 44 );
this .panel3.TabIndex = 1 ;
this .txbPassWord.Location = new System.Drawing.Point(139 , 10 );
this .txbPassWord.Name = "txbPassWord" ;
this .txbPassWord.Size = new System.Drawing.Size(252 , 20 );
this .txbPassWord.TabIndex = 1 ;
this .txbPassWord.Text = "1" ;
this .txbPassWord.UseSystemPasswordChar = true ;
this .label2.AutoSize = true ;
this .label2.Font = new System.Drawing.Font("Arial" , 12 F, 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(84 , 19 );
this .label2.TabIndex = 0 ;
this .label2.Text = "Mật khẩu:" ;
this .panel2.Controls.Add(this .txbUserName);
this .panel2.Controls.Add(this .label1);
this .panel2.Location = new System.Drawing.Point(3 , 3 );
this .panel2.Name = "panel2" ;
this .panel2.Size = new System.Drawing.Size(394 , 44 );
this .panel2.TabIndex = 0 ;
this .txbUserName.Location = new System.Drawing.Point(139 , 10 );
this .txbUserName.Name = "txbUserName" ;
this .txbUserName.Size = new System.Drawing.Size(252 , 20 );
this .txbUserName.TabIndex = 1 ;
this .txbUserName.Text = "k9" ;
this .label1.AutoSize = true ;
this .label1.Font = new System.Drawing.Font("Arial" , 12 F, 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(130 , 19 );
this .label1.TabIndex = 0 ;
this .label1.Text = "Tên đăng nhập:" ;
this .AcceptButton = this .btnLogin;
this .AutoScaleDimensions = new System.Drawing.SizeF(6 F, 13 F);
this .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this .CancelButton = this .btnExit;
this .ClientSize = new System.Drawing.Size(424 , 157 );
this .Controls.Add(this .panel1);
this .Name = "fLogin" ;
this .StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this .Text = "Đăng nhập" ;
this .FormClosing += new System.Windows.Forms.FormClosingEventHandler(this .fLogin_FormClosing);
this .panel1.ResumeLayout(false );
this .panel3.ResumeLayout(false );
this .panel3.PerformLayout();
this .panel2.ResumeLayout(false );
this .panel2.PerformLayout();
this .ResumeLayout(false );
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.TextBox txbPassWord;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.TextBox txbUserName;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnLogin;
}
}
Code 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.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace QuanLyQuanCafe
{
public partial class fTableManager : Form
{
public fTableManager ()
{
InitializeComponent();
LoadTable();
}
#region Method
void LoadTable()
{
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;
switch (item.Status)
{
case "Trống" :
btn.BackColor = Color.Aqua;
break ;
default :
btn.BackColor = Color.LightPink;
break ;
}
flpTable.Controls.Add(btn);
}
}
#endregion
#region Events
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();
f.ShowDialog();
}
private void adminToolStripMenuItem_Click (object sender, EventArgs e)
{
fAdmin f = new fAdmin();
f.ShowDialog();
}
#endregion
}
}
Code fTableManager.Designer.cs
namespace QuanLyQuanCafe
{
partial class fTableManager
{
private System.ComponentModel.IContainer components = null ;
protected override void Dispose (bool disposing)
{
if (disposing && (components != null ))
{
components.Dispose();
}
base .Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent ()
{
this .menuStrip1 = new System.Windows.Forms.MenuStrip();
this .adminToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this .thôngTinTàiKhoảnToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this .thôngTinCáNhânToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this .đăngXuấtToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this .panel2 = new System.Windows.Forms.Panel();
this .lsvBill = new System.Windows.Forms.ListView();
this .panel3 = new System.Windows.Forms.Panel();
this .cbSwitchTable = new System.Windows.Forms.ComboBox();
this .btnSwitchTable = new System.Windows.Forms.Button();
this .nmDisCount = new System.Windows.Forms.NumericUpDown();
this .btnDiscount = new System.Windows.Forms.Button();
this .btnCheckOut = new System.Windows.Forms.Button();
this .panel4 = new System.Windows.Forms.Panel();
this .nmFoodCount = new System.Windows.Forms.NumericUpDown();
this .btnAddFood = new System.Windows.Forms.Button();
this .cbFood = new System.Windows.Forms.ComboBox();
this .cbCategory = new System.Windows.Forms.ComboBox();
this .flpTable = new System.Windows.Forms.FlowLayoutPanel();
this .menuStrip1.SuspendLayout();
this .panel2.SuspendLayout();
this .panel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this .nmDisCount)).BeginInit();
this .panel4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this .nmFoodCount)).BeginInit();
this .SuspendLayout();
this .menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this .adminToolStripMenuItem,
this .thôngTinTàiKhoảnToolStripMenuItem});
this .menuStrip1.Location = new System.Drawing.Point(0 , 0 );
this .menuStrip1.Name = "menuStrip1" ;
this .menuStrip1.Size = new System.Drawing.Size(797 , 24 );
this .menuStrip1.TabIndex = 1 ;
this .menuStrip1.Text = "menuStrip1" ;
this .adminToolStripMenuItem.Name = "adminToolStripMenuItem" ;
this .adminToolStripMenuItem.Size = new System.Drawing.Size(55 , 20 );
this .adminToolStripMenuItem.Text = "Admin" ;
this .adminToolStripMenuItem.Click += new System.EventHandler(this .adminToolStripMenuItem_Click);
this .thôngTinTàiKhoảnToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this .thôngTinCáNhânToolStripMenuItem,
this .đăngXuấtToolStripMenuItem});
this .thôngTinTàiKhoảnToolStripMenuItem.Name = "thôngTinTàiKhoảnToolStripMenuItem" ;
this .thôngTinTàiKhoảnToolStripMenuItem.Size = new System.Drawing.Size(123 , 20 );
this .thôngTinTàiKhoảnToolStripMenuItem.Text = "Thông tin tài khoản" ;
this .thôngTinCáNhânToolStripMenuItem.Name = "thôngTinCáNhânToolStripMenuItem" ;
this .thôngTinCáNhânToolStripMenuItem.Size = new System.Drawing.Size(171 , 22 );
this .thôngTinCáNhânToolStripMenuItem.Text = "Thông tin cá nhân" ;
this .thôngTinCáNhânToolStripMenuItem.Click += new System.EventHandler(this .thôngTinCáNhânToolStripMenuItem_Click);
this .đăngXuấtToolStripMenuItem.Name = "đăngXuấtToolStripMenuItem" ;
this .đăngXuấtToolStripMenuItem.Size = new System.Drawing.Size(171 , 22 );
this .đăngXuấtToolStripMenuItem.Text = "Đăng xuất" ;
this .đăngXuấtToolStripMenuItem.Click += new System.EventHandler(this .đăngXuấtToolStripMenuItem_Click);
this .panel2.Controls.Add(this .lsvBill);
this .panel2.Location = new System.Drawing.Point(447 , 85 );
this .panel2.Name = "panel2" ;
this .panel2.Size = new System.Drawing.Size(338 , 315 );
this .panel2.TabIndex = 2 ;
this .lsvBill.Location = new System.Drawing.Point(3 , 3 );
this .lsvBill.Name = "lsvBill" ;
this .lsvBill.Size = new System.Drawing.Size(332 , 309 );
this .lsvBill.TabIndex = 0 ;
this .lsvBill.UseCompatibleStateImageBehavior = false ;
this .panel3.Controls.Add(this .cbSwitchTable);
this .panel3.Controls.Add(this .btnSwitchTable);
this .panel3.Controls.Add(this .nmDisCount);
this .panel3.Controls.Add(this .btnDiscount);
this .panel3.Controls.Add(this .btnCheckOut);
this .panel3.Location = new System.Drawing.Point(447 , 406 );
this .panel3.Name = "panel3" ;
this .panel3.Size = new System.Drawing.Size(338 , 52 );
this .panel3.TabIndex = 3 ;
this .cbSwitchTable.FormattingEnabled = true ;
this .cbSwitchTable.Location = new System.Drawing.Point(3 , 28 );
this .cbSwitchTable.Name = "cbSwitchTable" ;
this .cbSwitchTable.Size = new System.Drawing.Size(75 , 21 );
this .cbSwitchTable.TabIndex = 6 ;
this .btnSwitchTable.Location = new System.Drawing.Point(3 , 3 );
this .btnSwitchTable.Name = "btnSwitchTable" ;
this .btnSwitchTable.Size = new System.Drawing.Size(75 , 26 );
this .btnSwitchTable.TabIndex = 5 ;
this .btnSwitchTable.Text = "Chuyển bàn" ;
this .btnSwitchTable.UseVisualStyleBackColor = true ;
this .nmDisCount.Location = new System.Drawing.Point(133 , 29 );
this .nmDisCount.Name = "nmDisCount" ;
this .nmDisCount.Size = new System.Drawing.Size(74 , 20 );
this .nmDisCount.TabIndex = 4 ;
this .nmDisCount.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this .btnDiscount.Location = new System.Drawing.Point(133 , 3 );
this .btnDiscount.Name = "btnDiscount" ;
this .btnDiscount.Size = new System.Drawing.Size(75 , 26 );
this .btnDiscount.TabIndex = 4 ;
this .btnDiscount.Text = "Giảm giá" ;
this .btnDiscount.UseVisualStyleBackColor = true ;
this .btnCheckOut.Location = new System.Drawing.Point(260 , 3 );
this .btnCheckOut.Name = "btnCheckOut" ;
this .btnCheckOut.Size = new System.Drawing.Size(75 , 46 );
this .btnCheckOut.TabIndex = 3 ;
this .btnCheckOut.Text = "Thanh toán" ;
this .btnCheckOut.UseVisualStyleBackColor = true ;
this .panel4.Controls.Add(this .nmFoodCount);
this .panel4.Controls.Add(this .btnAddFood);
this .panel4.Controls.Add(this .cbFood);
this .panel4.Controls.Add(this .cbCategory);
this .panel4.Location = new System.Drawing.Point(447 , 27 );
this .panel4.Name = "panel4" ;
this .panel4.Size = new System.Drawing.Size(338 , 52 );
this .panel4.TabIndex = 4 ;
this .nmFoodCount.Location = new System.Drawing.Point(296 , 19 );
this .nmFoodCount.Minimum = new decimal (new int [] {
100 ,
0 ,
0 ,
-2147483648 });
this .nmFoodCount.Name = "nmFoodCount" ;
this .nmFoodCount.Size = new System.Drawing.Size(39 , 20 );
this .nmFoodCount.TabIndex = 3 ;
this .nmFoodCount.Value = new decimal (new int [] {
1 ,
0 ,
0 ,
0 });
this .btnAddFood.Location = new System.Drawing.Point(214 , 3 );
this .btnAddFood.Name = "btnAddFood" ;
this .btnAddFood.Size = new System.Drawing.Size(75 , 46 );
this .btnAddFood.TabIndex = 2 ;
this .btnAddFood.Text = "Thêm món" ;
this .btnAddFood.UseVisualStyleBackColor = true ;
this .cbFood.FormattingEnabled = true ;
this .cbFood.Location = new System.Drawing.Point(3 , 28 );
this .cbFood.Name = "cbFood" ;
this .cbFood.Size = new System.Drawing.Size(205 , 21 );
this .cbFood.TabIndex = 1 ;
this .cbCategory.FormattingEnabled = true ;
this .cbCategory.Location = new System.Drawing.Point(3 , 3 );
this .cbCategory.Name = "cbCategory" ;
this .cbCategory.Size = new System.Drawing.Size(205 , 21 );
this .cbCategory.TabIndex = 0 ;
this .flpTable.AutoScroll = true ;
this .flpTable.Location = new System.Drawing.Point(12 , 30 );
this .flpTable.Name = "flpTable" ;
this .flpTable.Size = new System.Drawing.Size(429 , 428 );
this .flpTable.TabIndex = 5 ;
this .AutoScaleDimensions = new System.Drawing.SizeF(6 F, 13 F);
this .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this .ClientSize = new System.Drawing.Size(797 , 470 );
this .Controls.Add(this .flpTable);
this .Controls.Add(this .panel4);
this .Controls.Add(this .panel3);
this .Controls.Add(this .panel2);
this .Controls.Add(this .menuStrip1);
this .MainMenuStrip = this .menuStrip1;
this .Name = "fTableManager" ;
this .StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this .Text = "Phần mềm quản lý quán cafe" ;
this .menuStrip1.ResumeLayout(false );
this .menuStrip1.PerformLayout();
this .panel2.ResumeLayout(false );
this .panel3.ResumeLayout(false );
((System.ComponentModel.ISupportInitialize)(this .nmDisCount)).EndInit();
this .panel4.ResumeLayout(false );
((System.ComponentModel.ISupportInitialize)(this .nmFoodCount)).EndInit();
this .ResumeLayout(false );
this .PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem adminToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem thôngTinTàiKhoảnToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem thôngTinCáNhânToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem đăngXuấtToolStripMenuItem;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.ListView lsvBill;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.NumericUpDown nmFoodCount;
private System.Windows.Forms.Button btnAddFood;
private System.Windows.Forms.ComboBox cbFood;
private System.Windows.Forms.ComboBox cbCategory;
private System.Windows.Forms.ComboBox cbSwitchTable;
private System.Windows.Forms.Button btnSwitchTable;
private System.Windows.Forms.NumericUpDown nmDisCount;
private System.Windows.Forms.Button btnDiscount;
private System.Windows.Forms.Button btnCheckOut;
private System.Windows.Forms.FlowLayoutPanel flpTable;
}
}
Code Table.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QuanLyQuanCafe.DTO
{
public class Table
{
public Table (int id, string name, string status)
{
this .ID = id;
this .Name = name;
this .Status = status;
}
public Table (DataRow row)
{
this .ID = (int )row["id" ];
this .Name = row["name" ].ToString();
this .Status = row["status" ].ToString();
}
private string status;
public string Status
{
get { return status; }
set { status = value ; }
}
private string name;
public string Name
{
get { return name; }
set { name = value ; }
}
private int iD;
public int ID
{
get { return iD; }
set { iD = value ; }
}
}
}
Code TableDAO.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 TableDAO
{
private static TableDAO instance;
public static TableDAO Instance
{
get { if (instance == null ) instance = new TableDAO(); return TableDAO.instance; }
private set { TableDAO.instance = value ; }
}
public static int TableWidth = 90 ;
public static int TableHeight = 90 ;
private TableDAO () { }
public List<Table> LoadTableList ()
{
List<Table> tableList = new List<Table>();
DataTable data = DataProvider.Instance.ExecuteQuery("USP_GetTableList" );
foreach (DataRow item in data.Rows)
{
Table table = new Table(item);
tableList.Add(table);
}
return tableList;
}
}
}
Kết
Trong bài này, chúng ta đã tìm hiểu cách Hiển thị số bàn theo CSDL cho phần mềm Quản lý quán cafe với C# Winform
Ở bài sau, Kteam sẽ giới thiệu đến bạn về HIỂN THỊ HÓA ĐƠN THEO BÀN CHO PHẦN MỀM
QUẢN LÝ QUÁN CAFE VỚI C# WINFORM
Cảm ơn các bạn đã theo dõi bài viết. Hãy để lại bình luận hoặc góp ý của mình để phát triển bài viết tốt hơn. Và đừ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 Hiển thị số bàn theo CSDL cho 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.
Copy nguyên tất cả code phần này vào nhưng nó ko ra cái btn bên flpTable ạ
ai giúp e với
System.Data.SqlClient.SqlException: 'Could not find stored procedure 'USP_GetTableList'.'
em bị lỗi này :(
k biết khắc phục sao cả .
nếu em chỉ chạy bài trước thì nó vẫn ok . nhưng đến bài này thì nó có lỗi :( anh chỉ em sảa dc k . cảm ơn anh rất nhiều
mình code có xuất hiện lỗi trên mong mọi ng trợ giúp
an unhandled exception of type 'system.stackoverflowexception' occurred in .... trong đoạn code
public static donthuocDAO Instance
{
get
{
if (Instance == null) instance = new donthuocDAO(); return donthuocDAO.instance;
}
private set
{
instance = value;
}
}
Mến chào Kteam!
Cảm ơn Kteam đã có những bài học thiết thực.
Kteam cho tôi hỏi ở đoạn code trong file
Table.CS
Trên hàm khởi tạo mỗi biến tương ứng với 1 giá trị của cột dữ liệu trong bảng
Nếu như bảng có nhiều cột thì các biến truyền vào trong hàm khởi tạo Table có cách nào ngắn gọn hơn không hay ta phải thực hiện khai báo đầy đủ tất cả các biến tương ứng với các cột dữ liệu của bảng?
Ví dụ: bảng nhân viênc có 15 cột vậy khi viết hàm khởi tạo cho Employee theo như cách trên thì cũng phải truyền vào 15 biến tương ứng hay có cách nào khác.
mình run thì tại class Table.cs báo lỗi: System.InvalidCastException: 'Specified cast is not valid.'
Debug thì thấy kết quả khi chạy nó lấy luôn cả bảng Account. Sai ở chỗ nào vậy ad