Code
Code
Dao
.
1
Bo
.
3
Login
.
6
Admin
.
7
QLBan
.
8
QLMonAn
.
10
QLTaiKhoan
.
12
ThuNgan
.
14
Dao
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Data;
using
System.Data.SqlClient;
using
System.IO;
namespace
DAO
{
public
class
DataAccessObject
{
public
SqlConnection
Getconnect()
{
return
new
SqlConnection
(
"Data Source=TEji;Initial Catalog=Assignment_duongvtph00550;Integrated Security=True"
);
}
public
void
ExcuteNonQuery(
string
sql)
{
SqlConnection
con = Getconnect();
SqlCommand
cmd =
new
SqlCommand
(sql, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
cmd.Dispose();
}
public
DataTable
GetTable(
string
s)
{
SqlConnection
con = Getconnect();
SqlDataAdapter
da =
new
SqlDataAdapter
(s, con);
DataTable
dt =
new
DataTable
();
da.Fill(dt);
return
dt;
}
public
SqlDataReader
ExecuteReader(
string
sql)
{
SqlConnection
con = Getconnect();
con.Open();
SqlCommand
cmd =
new
SqlCommand
(sql, con);
SqlDataReader
reader = cmd.ExecuteReader();
return
reader;
}
}
}
Bo
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
DAO;
using
System.Data;
using
System.Data.SqlClient;
namespace
BO
{
public
class
BusinessObject
{
DataAccessObject
da =
new
DataAccessObject
();
public
int
checkLogin(
string
UserName,
string
Pass)
{
SqlDataReader
reader = da.ExecuteReader(
"select TEN_DANG_NHAP, MAT_KHAU, QUYEN_HAN from DANG_NHAP"
);
while
(reader.Read())
{
if
(reader[0].ToString() == UserName && reader[1].ToString() == Pass && reader[2].ToString() ==
"admin"
)
{
return
1;
}
if
(reader[0].ToString() == UserName && reader[1].ToString() == Pass && reader[2].ToString() ==
"thungan"
)
{
return
2;
}
}
return
0;
}
public
DataTable
SelectMon()
{
string
sql =
"select * from MON_AN"
;
return
da.GetTable(sql);
}
public
void
InsertMon(
string
MA_MON,
string
TEN_MON,
double
GIA_TIEN,
string
MA_THE_LOAI)
{
string
sql =
"insert into MON_AN values('"
+ MA_MON +
"','"
+ TEN_MON +
"','"
+ GIA_TIEN +
"','"
+ MA_THE_LOAI +
"')"
;
da.ExcuteNonQuery(sql);
}
public
void
UpdateMon(
string
MA_MON,
string
TEN_MON,
double
GIA_TIEN,
string
MA_THE_LOAI)
{
string
sql =
"update MON_AN set TEN_MON='"
+ TEN_MON +
"', GIA_TIEN='"
+ GIA_TIEN +
"',MA_THE_LOAI ='"
+ MA_THE_LOAI +
"' where MA_MON='"
+ MA_MON +
"'"
;
da.ExcuteNonQuery(sql);
}
public
void
DeleteMon(
string
MA_MON)
{
string
sql =
"delete from MON_AN where MA_MON='"
+ MA_MON +
"'"
;
da.ExcuteNonQuery(sql);
}
public
DataTable
SelectMaTL()
{
string
sql =
"select * from THE_LOAI"
;
return
da.GetTable(sql);
}
public
void
InsertTHE_LOAI(
string
MA_THE_LOAI,
string
TEN_THE_LOAI)
{
string
sql =
"insert into THE_LOAI values('"
+ MA_THE_LOAI +
"','"
+ TEN_THE_LOAI +
"')"
;
da.ExcuteNonQuery(sql);
}
public
void
UpdateTHE_LOAI(
string
MA_THE_LOAI,
string
TEN_THE_LOAI)
{
string
sql =
"update THE_LOAI set TEN_THE_LOAI='"
+ TEN_THE_LOAI +
"' where MA_THE_LOAI= '"
+ MA_THE_LOAI +
"'"
;
da.ExcuteNonQuery(sql);
}
public
void
DeleteTHE_LOAI(
string
MA_THE_LOAI)
{
string
sql =
"delete from THE_LOAI where MA_THE_LOAI='"
+ MA_THE_LOAI +
"'"
;
da.ExcuteNonQuery(sql);
}
public
DataTable
SelectTK()
{
string
sql =
"select * from DANG_NHAP"
;
return
da.GetTable(sql);
}
public
void
InsertTK(
string
TEN_DANG_NHAP,
string
MAT_KHAU,
string
QUYEN_HAN)
{
string
sql =
"insert into DANG_NHAP values('"
+ TEN_DANG_NHAP +
"','"
+ MAT_KHAU +
"','"
+ QUYEN_HAN +
"')"
;
da.ExcuteNonQuery(sql);
}
public
void
UpdateTK(
string
TEN_DANG_NHAP,
string
MAT_KHAU,
string
QUYEN_HAN)
{
string
sql =
"update DANG_NHAP set MAT_KHAU='"
+ MAT_KHAU +
"',QUYEN_HAN = '"
+ QUYEN_HAN +
"' where TEN_DANG_NHAP = '"
+ TEN_DANG_NHAP +
"'"
;
da.ExcuteNonQuery(sql);
}
public
void
DeleteTK(
string
TEN_DANG_NHAP)
{
string
sql =
"delete from DANG_NHAP where TEN_DANG_NHAP = '"
+ TEN_DANG_NHAP +
"'"
;
da.ExcuteNonQuery(sql);
}
public
DataTable
SelectPhong()
{
string
sql =
"select * from PHONG"
;
return
da.GetTable(sql);
}
public
void
InsertPhong(
string
MA_PHONG,
string
TEN_PHONG)
{
string
sql =
"insert into PHONG values('"
+ MA_PHONG +
"','"
+ TEN_PHONG +
"')"
;
da.ExcuteNonQuery(sql);
}
public
void
UpdatePhong(
string
MA_PHONG,
string
TEN_PHONG)
{
string
sql =
"update PHONG set TEN_PHONG = '"
+ TEN_PHONG +
"' where MA_PHONG = '"
+ MA_PHONG +
"'"
;
da.ExcuteNonQuery(sql);
}
public
void
DeletePhong(
string
MA_PHONG)
{
string
sql =
"delete Phong where MA_PHONG = '"
+ MA_PHONG +
"'"
;
da.ExcuteNonQuery(sql);
}
public
DataTable
SelectBAN()
{
string
sql =
"select * from BAN"
;
return
da.GetTable(sql);
}
public
void
Insertban(
string
MA_BAN,
string
TEN_BAN,
string
MA_QUYEN_HAN)
{
string
sql =
"insert into BAN values('"
+ MA_BAN +
"','"
+ TEN_BAN +
"','"
+ MA_QUYEN_HAN +
"')"
;
da.ExcuteNonQuery(sql);
}
public
void
UpdateBAN(
string
MA_BAN,
string
TEN_BAN,
string
MA_QUYEN_HAN)
{
string
sql =
"update BAN set TEN_BAN = '"
+ TEN_BAN +
"', MA_QUYEN_HAN = '"
+ MA_QUYEN_HAN +
"' where MA_BAN = '"
+ MA_BAN +
"'"
;
da.ExcuteNonQuery(sql);
}
public
void
DeleteBAN(
string
MA_BAN)
{
string
sql =
"delete BAN where MA_BAN = '"
+ MA_BAN +
"'"
;
da.ExcuteNonQuery(sql);
}
public
DataTable
ShowBAN()
{
string
sql =
"select TEN_BAN from BAN"
;
return
da.GetTable(sql);
}
}
}
Login
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
BO;
namespace
Assignment_Sof201_duongvtph00550
{
public
partial
class
Login
:
Form
{
public
Login()
{
InitializeComponent();
}
BusinessObject
pok =
new
BusinessObject
();
private
void
btnlogin_Click(
object
sender,
EventArgs
e)
{
int
t = pok.checkLogin(txtuser.Text, txtpass.Text);
if
(t == 1)
{
Admin
ad =
new
Admin
();
ad.Show();
this
.Hide();
}
else
if
(t == 2)
{
ThuNgan
th =
new
ThuNgan
();
th.Show();
this
.Hide();
}
else
{
MessageBox
.Show(
"Tên đăng nhập hoặc mật khẩu không chính xác"
+
"
"
+
"Xin vui lòng nhập lại"
);
txtuser.Text =
""
;
txtpass.Text =
""
;
txtuser.Focus();
}
}
private
void
btnhelp_Click(
object
sender,
EventArgs
e)
{
MessageBox
.Show(
"Để có được ID và Passwords đăng nhập"
+
"
"
+
"Xin mời liên hệ với người quản lý để được cấp ID dành cho nhân viên bán hàng"
,
"Trợ giúp"
,
MessageBoxButtons
.OK);
}
private
void
btnexit_Click(
object
sender,
EventArgs
e)
{
Application
.Exit();
}
}
}
Admin
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace
Assignment_Sof201_duongvtph00550
{
public
partial
class
Admin
:
Form
{
public
Admin()
{
InitializeComponent();
}
private
void
btnfood_Click(
object
sender,
EventArgs
e)
{
this
.Hide();
QLMonAn
food =
new
QLMonAn
();
food.Show();
}
private
void
btnrab_Click(
object
sender,
EventArgs
e)
{
this
.Hide();
QLBan
room =
new
QLBan
();
room.Show();
}
private
void
btnexit_Click(
object
sender,
EventArgs
e)
{
this
.Close();
Login
log =
new
Login
();
log.Show();
}
private
void
btnacc_Click(
object
sender,
EventArgs
e)
{
this
.Hide();
QLTaiKhoan
acc =
new
QLTaiKhoan
();
acc.Show();
}
}
}
QLBan
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
BO;
namespace
Assignment_Sof201_duongvtph00550
{
public
partial
class
QLBan
:
Form
{
public
QLBan()
{
InitializeComponent();
}
BusinessObject
pok =
new
BusinessObject
();
private
void
QuanlyPhongban_Load(
object
sender,
EventArgs
e)
{
dataGridView1.DataSource = pok.SelectPhong();
dataGridView2.DataSource = pok.SelectBAN();
ccbroomID.DataSource = pok.SelectPhong();
ccbroomID.DisplayMember =
"MA_PHONG"
;
txtroomID.Text =
""
;
txtroomName.Text =
""
;
txttableID.Text =
""
;
txttableName.Text =
""
;
txtroomID.Focus();
}
private
void
dataGridView1_Click(
object
sender,
EventArgs
e)
{
int
r = dataGridView1.CurrentCell.RowIndex;
string
maP = dataGridView1.Rows[r].Cells[0].Value.ToString();
string
tenP = dataGridView1.Rows[r].Cells[1].Value.ToString();
txtroomID.Text = maP;
txtroomName.Text = tenP;
}
private
void
dataGridView2_Click(
object
sender,
EventArgs
e)
{
int
r = dataGridView2.CurrentCell.RowIndex;
string
maB = dataGridView2.Rows[r].Cells[0].Value.ToString();
string
tenB = dataGridView2.Rows[r].Cells[1].Value.ToString();
string
maP = dataGridView2.Rows[r].Cells[2].Value.ToString();
txttableID.Text = maB;
txttableName.Text = tenB;
ccbroomID.Text = maP;
}
private
void
btnaddroom_Click(
object
sender,
EventArgs
e)
{
pok.InsertPhong(txtroomID.Text, txtroomName.Text);
QuanlyPhongban_Load(sender, e);
}
private
void
btnfixroom_Click(
object
sender,
EventArgs
e)
{
pok.UpdatePhong(txtroomID.Text, txtroomName.Text);
QuanlyPhongban_Load(sender, e);
}
private
void
btndelroom_Click(
object
sender,
EventArgs
e)
{
pok.DeletePhong(txtroomID.Text);
QuanlyPhongban_Load(sender, e);
}
private
void
btnaddtable_Click(
object
sender,
EventArgs
e)
{
pok.Insertban(txttableID.Text, txttableName.Text, ccbroomID.Text);
QuanlyPhongban_Load(sender, e);
}
private
void
btnfixtable_Click(
object
sender,
EventArgs
e)
{
pok.UpdateBAN(txttableID.Text, txttableName.Text, ccbroomID.Text);
QuanlyPhongban_Load(sender, e);
}
private
void
btndeltable_Click(
object
sender,
EventArgs
e)
{
pok.DeleteBAN(txttableID.Text);
QuanlyPhongban_Load(sender, e);
}
private
void
btnexit_Click(
object
sender,
EventArgs
e)
{
this
.Close();
Admin
ad =
new
Admin
();
ad.Show();
}
}
}
QLMonAn
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
BO;
namespace
Assignment_Sof201_duongvtph00550
{
public
partial
class
QLMonAn
:
Form
{
public
QLMonAn()
{
InitializeComponent();
}
BusinessObject
pok =
new
BusinessObject
();
private
void
QLMonAn_Load(
object
sender,
EventArgs
e)
{
dataGridView1.DataSource = pok.SelectMon();
cbbftype.DataSource = pok.SelectMaTL();
cbbftype.DisplayMember =
"maTheLoai"
;
}
private
void
dataGridView1_Click(
object
sender,
EventArgs
e)
{
int
r = dataGridView1.CurrentCell.RowIndex;
string
maM = dataGridView1.Rows[r].Cells[0].Value.ToString();
string
tenM = dataGridView1.Rows[r].Cells[1].Value.ToString();
string
giaban = dataGridView1.Rows[r].Cells[2].Value.ToString();
string
matheloai = dataGridView1.Rows[r].Cells[3].Value.ToString();
txtfoodID.Text = maM;
txtfoodName.Text = tenM;
txtfprice.Text = giaban;
cbbftype.Text = matheloai;
}
private
void
btnaddfood_Click(
object
sender,
EventArgs
e)
{
pok.InsertMon(txtfoodID.Text, txtfoodName.Text,
Convert
.ToDouble(txtfprice.Text), cbbftype.Text);
QLMonAn_Load(sender, e);
txtfoodID.Text =
""
;
txtfoodName.Text =
""
;
txtfprice.Text =
""
;
txtfoodID.Focus();
}
private
void
btnfixfood_Click(
object
sender,
EventArgs
e)
{
pok.UpdateMon(txtfoodID.Text, txtfoodName.Text,
Convert
.ToDouble(txtfprice.Text), cbbftype.Text);
QLMonAn_Load(sender, e);
txtfoodID.Text =
""
;
txtfoodName.Text =
""
;
txtfprice.Text =
""
;
txtfoodID.Focus();
}
private
void
btndelfood_Click(
object
sender,
EventArgs
e)
{
pok.DeleteMon(txtfoodID.Text);
QLMonAn_Load(sender, e);
txtfoodID.Text =
""
;
txtfoodName.Text =
""
;
txtfprice.Text =
""
;
txtfoodID.Focus();
}
private
void
btnexit_Click(
object
sender,
EventArgs
e)
{
this
.Close();
Admin
ad =
new
Admin
();
ad.Show();
}
}
}
QLTaiKhoan
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
BO;
namespace
Assignment_Sof201_duongvtph00550
{
public
partial
class
QLTaiKhoan
:
Form
{
public
QLTaiKhoan()
{
InitializeComponent();
}
BusinessObject
pok =
new
BusinessObject
();
private
void
QLTaiKhoan_Load(
object
sender,
EventArgs
e)
{
dataGridView1.DataSource = pok.SelectTK();
txtuser.Text =
""
;
txtpass.Text =
""
;
txtuser.Focus();
}
private
void
dataGridView1_Click(
object
sender,
EventArgs
e)
{
int
r = dataGridView1.CurrentCell.RowIndex;
string
tendangnhap = dataGridView1.Rows[r].Cells[0].Value.ToString();
string
matkhau = dataGridView1.Rows[r].Cells[1].Value.ToString();
string
quyenhan = dataGridView1.Rows[r].Cells[2].Value.ToString();
txtuser.Text = tendangnhap;
txtpass.Text = matkhau;
cbbPermit.Text = quyenhan;
}
private
void
btnadd_Click(
object
sender,
EventArgs
e)
{
pok.InsertTK(txtuser.Text, txtpass.Text, cbbPermit.Text);
QLTaiKhoan_Load(sender, e);
}
private
void
btnfix_Click(
object
sender,
EventArgs
e)
{
pok.UpdateTK(txtuser.Text, txtpass.Text, cbbPermit.Text);
QLTaiKhoan_Load(sender, e);
}
private
void
btndel_Click(
object
sender,
EventArgs
e)
{
pok.DeleteTK(txtuser.Text);
QLTaiKhoan_Load(sender, e);
}
private
void
btnexit_Click(
object
sender,
EventArgs
e)
{
this
.Close();
Admin
ad =
new
Admin
();
ad.Show();
}
}
}
ThuNgan
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
BO;
namespace
Assignment_Sof201_duongvtph00550
{
public
partial
class
ThuNgan
:
Form
{
public
ThuNgan()
{
InitializeComponent();
}
BusinessObject
pok =
new
BusinessObject
();
private
void
ThuNgan_Load(
object
sender,
EventArgs
e)
{
dataGridView1.DataSource = pok.SelectMon();
dataGridView2.DataSource = pok.ShowBAN();
}
private
void
dataGridView2_DoubleClick(
object
sender,
EventArgs
e)
{
int
r = dataGridView2.CurrentCell.RowIndex;
string
tenphong = dataGridView2.Rows[r].Cells[0].Value.ToString();
dataGridView3.Rows.Clear();
lbltablename.Text = tenphong;
DateTime
tmp =
DateTime
.Now;
String
gkt = tmp.ToString(
"dd/MM/yyyy hh:mm:ss "
);
lbldate2.Text = gkt;
}
private
void
dataGridView1_DoubleClick(
object
sender,
EventArgs
e)
{
if
(lbltablename.Text ==
""
)
{
MessageBox
.Show(
"Phải có dữ liệu bàn"
,
"Lỗi"
,
MessageBoxButtons
.OK,
MessageBoxIcon
.Error);
}
else
{
int
r = dataGridView1.CurrentCell.RowIndex;
string
tenmon = dataGridView1.Rows[r].Cells[1].Value.ToString();
string
gia = dataGridView1.Rows[r].Cells[2].Value.ToString();
string
index = lbltablename.Text;
dataGridView3.Rows.Add(tenmon, gia);
}
}
private
void
btnexit_Click(
object
sender,
EventArgs
e)
{
this
.Close();
Login
log =
new
Login
();
log.Show();
}
private
void
btncheckout_Click(
object
sender,
EventArgs
e)
{
decimal
total = 0;
if
(lbltablename.Text ==
""
)
{
MessageBox
.Show(
"Mời bạn chọn bàn thanh toán"
,
"Lỗi"
,
MessageBoxButtons
.OK,
MessageBoxIcon
.Error);
}
else
{
for
(
int
i = 0; i < dataGridView3.Rows.Count; i++)
{
string
gia = dataGridView1.Rows[i].Cells[2].Value.ToString();
total +=
Convert
.ToDecimal(gia);
}
MessageBox
.Show(
"Hóa đơn thanh toán"
+
"
"
+
"Bàn : "
+ lbltablename.Text +
"
"
+
"Ngày : "
+ lbldate2.Text +
"
"
+
"Tổng số tiền phải thanh toán là : "
+ total +
"VNĐ"
,
"Hóa đơn"
,
MessageBoxButtons
.OK);
}
}
}
}
Bạn đang đọc truyện trên: AzTruyen.Top