You are on page 1of 46

University of Technology and Education

HCMC UNIVERSITY OF TECHNOLOGY AND EDUCATION


FACULTY OF INFORMATION TECHNOLOGY

FINAL TERM PROJECT


Course name: PROJECT

<< Design and implementation coffee shops management >>

Lecturer name: Assoc. Prof. Hoang Van Dung


List of members
Student ID Student name Contribution (%)
20TM11003 Le Duc Tho 100%
20TM11012 Pham Phu Hao 100%
20TM11014 Nguyen Thi Thuy Diem 100%

Ho Chi Minh City, 01/06/2022

Sincerely thanks!
P a g e 1 | 46
University of Technology and Education

For the completion of this project, I would like to express my sincere thanks to:
The Board of Directors of Ho Chi Minh City University of Technology and
Education for creating favorable conditions in terms of facilities with a modern
library system with a variety of books and documents that are convenient for
searching and researching. information.
We would like to thank Assoc. Prof. Hoang Van Dung, who has been dedicated to
guiding and teaching during the project implementation. We have completed on
time and accumulated valuable knowledge base for ourselves. Despite trying to
complete the best project, due to the limited time and knowledge, we could not
avoid certain shortcomings. We are looking forward to receiving your sympathy
and dedicated contribution.

Group of students made


20TM11005 NGUYEN VU TUAN KHOI
20TM11012 PHAM PHU HAO
20TM11014 NGUYEN THI THUY DIEM

Index
FOREWORD ......................................................................................4
Part 1: Introduction (project description) .......................................4

P a g e 2 | 46
University of Technology and Education

1. Problem and the purpose of choosing the topic


2. Research objectives
3. Methodology
Part 2: Background knowledge..........................................................5
1. Introduction to project
2. Algorithms
Part 3: Designs.....................................................................................6
Part 4: Conclusion.............................................................................47

FOREWORD

P a g e 3 | 46
University of Technology and Education

Today, with the strong development of science and technology, especially the
rapid development of information technology, information technology is
increasingly coming into life and being exploited by people in a very effective
way, making it a useful labor tool and playing a very important role in social life,
labor tools and information system design analysis is an important part of the field
of information technology, it helps people to manage databases more simply, easily
and quickly, saving a lot of time and manpower. We implemented the topic "cafe
management" to improve our knowledge and understanding of this field. The field
of information technology in general and the subject of system design and
management in particular.

PART 1: INTRODUCTION
1. Problem and the purpose
Coffee shops have a special reputation with increasing number of visitors, to serve customers
better, more accurately and quickly, the owner is gradually computerizing the management
stages. Especially in accounting and management of goods and beverages. Because with the
previous work, the store has revealed many limitations as follows :

P a g e 4 | 46
University of Technology and Education

 Look up information about goods, customers take a long time and sometimes inaccurate
 Store information on goods import and export, revenue and expenditure needs many
types of documents so it is cumbersome and inefficient
 Daily updates take time and difficulty in reporting and statistics, especially when there
are unexpected tasks.
 In the face of that situation, the problem is to build a new information system that makes
it easier to manage the coffee shop.
2. Research objectives
 Reduce the volume of information recorded to store information
 Update data quickly, accurately and in a timely manner
 Statistics on the quantity of goods exported, income and expenditure
and the revenue situation of the store
 Automatically print necessary invoices such as …………..
 Capable of long-term information storage, ensuring fast queries when
needed
Applied Technique
ADO.NET Entity Framework
Entity Data Model
 Abstraction over a relational database
 Consists of conceptual & logical models
 Provides mapping layer between conceptual model and logical model
Entity Client
 Provides classes similar to ADO.NET providers
 Can return results as DbDataReaders
Object Services
 Enables you to work with object instances
 Provides persistence and change tracking

P a g e 5 | 46
University of Technology and Education
No. Table code

1 PROVINCES CREATE TABLE [dbo].[provinces] (


[province_id] nvarchar(max) NOT NULL,
[province_name] nvarchar(max) NOT NULL
PRIMARY KEY CLUSTERED ([province_id] ASC));

2 DISTRICTS CREATE TABLE [dbo].[districts] (


[district_id] nvarchar(max) NOT NULL,
[district_name] nvarchar(max) NOT NULL,
[province_id] nvarchar(max) NOT NULL
PRIMARY KEY CLUSTERED ([district_id] ASC));

3 STORES CREATE TABLE [dbo].[stores] (


[store_id] nvarchar(max) NOT NULL,
[store_name] nvarchar(max) NOT NULL,
[phone] nvarchar(max) NOT NULL,
[email] nvarchar(max) NOT NULL,
[street] nvarchar(max) NULL,
[district_id] nvarchar(max) NOT NULL
PRIMARY KEY CLUSTERED ([store_id] ASC));

4 CATERGORIES CREATE TABLE [dbo].[categories] (


[category_id] nvarchar(max) NOT NULL,
[category_name] nvarchar(max) NOT NULL
PRIMARY KEY CLUSTERED ([category_id] ASC));

5 STAFFS CREATE TABLE [dbo].[staffs] (


[staff_id] nvarchar(max) NOT NULL,
[first_name] nvarchar(max) NOT NULL,
[last_name] nvarchar(max) NOT NULL,
[phone] nvarchar(max) NOT NULL,
[email] nvarchar(max) NOT NULL,
[active] nvarchar(max) NOT NULL,
[store_id] nvarchar(max) NOT NULL,
[manager_id] nvarchar(max) NULL
PRIMARY KEY CLUSTERED ([staff_id] ASC));

6 FOODS CREATE TABLE [dbo].[foods] (


[food_id] nvarchar(max) NOT NULL,
[food_name] nvarchar(max) NOT NULL,
[food_price] decimal(18,0) NOT NULL,
[category_id] nvarchar(max) NOT NULL
PRIMARY KEY CLUSTERED ([food_id] ASC));

7 TABLES CREATE TABLE [dbo].[tables] (


[table_id] nvarchar(max) NOT NULL,
[table_position] nvarchar(max) NOT NULL
PRIMARY KEY CLUSTERED ([table_id] ASC));

8 ORDER_FOODS CREATE TABLE [dbo].[order_foods] (


[order_id] nvarchar(max) NOT NULL,
[food_id] nvarchar(max) NOT NULL,
[food_quantity] int NOT NULL,
[total_price] decimal(18,0) NOT NULL
PRIMARY KEY CLUSTERED ([order_id], [food_id] ASC);

9 ORDERS CREATE TABLE [dbo].[orders] (


[order_id] nvarchar(max) NOT NULL,
[order_date] datetime NOT NULL,
[store_id] nvarchar(max) NOT NULL,
[staff_id] nvarchar(max) NOT NULL,
[table_id] nvarchar(max) NOT NULL,
[total_price] decimal(18,0) NOT NULL
PRIMARY KEY CLUSTERED ([order_id] ASC));

3. Research methodology
P a g e 6 | 46
University of Technology and Education

- Methods of document research


- Data collection methods

PART 2: THEORETICAL BASIS FOR


PROJECT IMPLEMENTATION
1. Introduction to project
The coffee management system is a popular research field, with methods
based on retrieval capacity, computerized information search and advanced
practical application problems of great value. The management of the coffee shop
needs a number of operations:
a) Sales : It is the main function of the software, assuming the role of sales,
receiving orders of customers, opening tables, transferring tables if the
customer needs, choosing items, paying, invoicing customers.

b) Manage employees: store employee's information including name, gender,


phone number, login code, password, address, etc. ( allow more information,
edit information, delete information, save information ), store information of
all shifts (shift start time, shift end time)

c) Manage goods: store information of all goods by type ( allow to manipulate


more information, edit information, delete information, save information).

d) Desk area management: store information of all desk areas, manage tables
by area

e) Revenue statistics: revenue statistics by day, month, year, depending on the


needs of the users. There are also statistics on which products are selling
best.

2. Architecture
- ADO.NET
- LINQ
- ENITY
P a g e 7 | 46
University of Technology and Education

- MICROSOFT REPORT

PART 3: DESIGNS
1. Diagram

2. Login form

P a g e 8 | 46
University of Technology and Education

int count = 0;
private void btLogin_Click(object sender, EventArgs e)
{
if (txtMName.Text == "ThuyDiem" && txtPass.Text == "20TM11014")
{
MessageBox.Show("Login successfully!");
this.Hide();
Manager manager = new Manager();
manager.Show();
}
else
{
count++;
txtMName.ResetText();
txtPass.ResetText();
MessageBox.Show("Failed login!");
this.txtMName.Focus();
if (count == 3)
{
this.Close();
}
}
}

3. Store form

P a g e 9 | 46
University of Technology and Education

a. Form

private void btIncome_Click(object sender, EventArgs e)


{
FormIncome ic = new FormIncome();
ic.Show();
this.Hide();
}
CoffeeManagementEntities db = null;
private void MySetProvince()
{
db = new CoffeeManagementEntities();
var ProvQ = from ProvList in db.provinces select
ProvList.province_name;
foreach (string ProvName in ProvQ)
{
cbPName.Items.Add(ProvName);
}
cbPName.SelectedIndex = 0;
}
private void MySetDistrict()
{
var DistQ = from DistList in db.districts
join ProvList in db.provinces on
DistList.province_id equals
ProvList.province_id
where (ProvList.province_name == cbPName.Text)
select DistList.district_name;
cbDName.Items.Clear();
P a g e 10 | 46
University of Technology and Education

foreach (string DistName in DistQ)


{
cbDName.Items.Add(DistName);
}
cbDName.SelectedIndex = 0;
}
private void MySetStore()
{
var Store = from StoreList in db.stores
join DistList in db.districts on
StoreList.district_id equals DistList.district_id
where (DistList.district_name == cbDName.Text)
select StoreList;
DataTable dt = new DataTable();
dt.Columns.Add("store_id");
dt.Columns.Add("store_name");
dt.Columns.Add("phone");
dt.Columns.Add("email");
dt.Columns.Add("street");
dt.Columns.Add("district_id");
foreach (var p in Store)
{
dt.Rows.Add(p.store_id, p.store_name, p.phone,
p.email, p.street, p.district_id);
}
dtGridView.DataSource = dt;
}
private void FindStoreByName()
{
var Find = from StoreList in db.stores
where
StoreList.store_name.Contains(txtFind.Text)
select StoreList;

DataTable dt = new DataTable();


dt.Columns.Add("store_id");
dt.Columns.Add("store_name");
dt.Columns.Add("phone");
dt.Columns.Add("email");
dt.Columns.Add("street");
dt.Columns.Add("district_id");
foreach (var p in Find)
{
dt.Rows.Add(p.store_id, p.store_name, p.phone,
p.email, p.street, p.district_id);
}
P a g e 11 | 46
University of Technology and Education

dtGridView.DataSource = dt;
}
private void ResetAllTextBox()
{
txtSID.ResetText();
txtSName.ResetText();
txtPhone.ResetText();
txtEmail.ResetText();
txtStreet.ResetText();
txtDID.ResetText();
txtFind.ResetText();
}
private void LoadData()
{
MySetProvince();
MySetDistrict();
ResetAllTextBox();
}

private void FormStores_Load(object sender, EventArgs e)


{
LoadData();
}

private void cbPName_SelectedValueChanged(object sender,


EventArgs e)
{
MySetDistrict();
}

private void cbDName_SelectedValueChanged(object sender,


EventArgs e)
{
MySetStore();
}

private void dtGridView_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{
int r = dtGridView.CurrentCell.RowIndex;
txtSID.Text =
dtGridView.Rows[r].Cells[0].Value.ToString();
txtSName.Text =
dtGridView.Rows[r].Cells[1].Value.ToString();
txtPhone.Text =
dtGridView.Rows[r].Cells[2].Value.ToString();
P a g e 12 | 46
University of Technology and Education

txtEmail.Text =
dtGridView.Rows[r].Cells[3].Value.ToString();
txtStreet.Text =
dtGridView.Rows[r].Cells[4].Value.ToString();
txtDID.Text =
dtGridView.Rows[r].Cells[5].Value.ToString();
}

private void btAdd_Click(object sender, EventArgs e)


{
var StoreQ = (from S in db.stores
where S.store_id == txtSID.Text
select S).SingleOrDefault();
if (StoreQ != null)
{
MessageBox.Show("Store ID has already existed",
"Error!");
}
else
{
try
{
store S = new store();
S.store_id = txtSID.Text;
S.store_name = txtSName.Text;
S.phone = txtPhone.Text;
S.email = txtEmail.Text;
S.street = txtStreet.Text;
S.district_id = txtDID.Text;
db.stores.Add(S);
db.SaveChanges();
}
catch
{
MessageBox.Show("District id " +
"doest not exist in District table!" + "
Please update district id first",
"Error!");
}
MySetStore();
}
}

private void btEdit_Click(object sender, EventArgs e)


{
int r = dtGridView.CurrentCell.RowIndex;
P a g e 13 | 46
University of Technology and Education

string tempSID =
dtGridView.Rows[r].Cells[0].Value.ToString();
store SQuery = db.stores.Single(x => x.store_id ==
tempSID);
if (SQuery != null)
{
district DTQuery = db.districts.Single(x =>
x.district_id == txtDID.Text);

var SQuery2 = (from Store in db.stores


where Store.store_id == txtSID.Text
select Store).SingleOrDefault();
if (DTQuery == null)
{
MessageBox.Show("Distric id does not exist. Please
update district id!",
"Error!");
return;
}
if (SQuery.store_id == txtSID.Text)
{
SQuery.store_name = txtSName.Text;
SQuery.phone = txtPhone.Text;
SQuery.email = txtEmail.Text;
SQuery.street = txtStreet.Text;
SQuery.district_id = txtDID.Text;
db.SaveChanges();
}
else
{
if (SQuery2 != null)
{
MessageBox.Show("District id " +
"doest not exist in District table!" + "
Please update province id or district id first",
"Error!");
return;
}
try
{
db.stores.Remove(SQuery);

db.SaveChanges();
store S = new store();
S.store_id = txtSID.Text;
S.store_name = txtSName.Text;
P a g e 14 | 46
University of Technology and Education

S.phone = txtPhone.Text;
S.email = txtEmail.Text;
S.street = txtStreet.Text;
S.district_id = txtDID.Text;
db.stores.Add(S);
db.SaveChanges();
}
catch
{
MessageBox.Show("Store ID has already
existed!", "Error!");
}
}
}
MySetStore();
}

private void btDelete_Click(object sender, EventArgs e)


{
int r = dtGridView.CurrentCell.RowIndex;
string tempSID =
dtGridView.Rows[r].Cells[0].Value.ToString();
store Store = db.stores.Single(x => x.store_id ==
tempSID);
db.stores.Remove(Store);
db.SaveChanges();
MySetStore();
}

private void btCancel_Click(object sender, EventArgs e)


{
LoadData();
}

private void btFind_Click(object sender, EventArgs e)


{
FindStoreByName();
}
b. Report

P a g e 15 | 46
University of Technology and Education

4. Staff form
a. Form

private void TimeKeeping_Click(object sender, EventArgs e)


{

private void TimeKeeping_Click_1(object sender, EventArgs e)


{
FormTimeKeeping fkp = new FormTimeKeeping();
fkp.Show();
this.Hide();
P a g e 16 | 46
University of Technology and Education

}
CoffeeManagementEntities db = null;
private void MySetStore()
{
db = new CoffeeManagementEntities();
var StoreQ = from StoreL in db.stores select
StoreL.store_name;
foreach (string SName in StoreQ)
{
cbSName.Items.Add(SName);
}
cbSName.SelectedIndex = 0;
}
private void MySetStaff()
{
var Staff = from StaffList in db.staffs
join StoreL in db.stores on StaffList.store_id
equals StoreL.store_id
where (StoreL.store_name == cbSName.Text)
select StaffList;
DataTable dt = new DataTable();
dt.Columns.Add("staff_id");
dt.Columns.Add("first_name");
dt.Columns.Add("last_name");
dt.Columns.Add("phone");
dt.Columns.Add("email");
dt.Columns.Add("active");
dt.Columns.Add("store_id");
dt.Columns.Add("manager_id");
foreach (var p in Staff)
{
dt.Rows.Add(p.staff_id, p.first_name, p.last_name,
p.phone, p.email, p.active, p.store_id, p.manager_id);
}
dtGridView.DataSource = dt;
}
private void FindStaffByName()
{
var Find = from StaffList in db.staffs
where
StaffList.first_name.Contains(txtFind.Text)
|| StaffList.last_name.Contains(txtFind.Text)
select StaffList;

DataTable dt = new DataTable();


dt.Columns.Add("staff_id");
P a g e 17 | 46
University of Technology and Education

dt.Columns.Add("first_name");
dt.Columns.Add("last_name");
dt.Columns.Add("phone");
dt.Columns.Add("email");
dt.Columns.Add("active");
dt.Columns.Add("store_id");
dt.Columns.Add("manager_id");
foreach (var p in Find)
{
dt.Rows.Add(p.staff_id, p.first_name, p.last_name,
p.phone, p.email, p.active, p.store_id, p.manager_id);
}
dtGridView.DataSource = dt;
}
private void ResetAllTextBox()
{
txtSfID.ResetText();
txtFName.ResetText();
txtLName.ResetText();
txtPhone.ResetText();
txtEmail.ResetText();
txtActive.ResetText();
txtSID.ResetText();
txtMID.ResetText();
txtFind.ResetText();
}
private void LoadData()
{
MySetStore();
ResetAllTextBox();
}

private void FormStaff_Load(object sender, EventArgs e)


{
LoadData();
}

private void cbSName_SelectionChangeCommitted(object sender,


EventArgs e)
{
MySetStaff();
}

private void dtGridView_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{
P a g e 18 | 46
University of Technology and Education

int r = dtGridView.CurrentCell.RowIndex;
txtSfID.Text =
dtGridView.Rows[r].Cells[0].Value.ToString();
txtFName.Text =
dtGridView.Rows[r].Cells[1].Value.ToString();
txtLName.Text =
dtGridView.Rows[r].Cells[2].Value.ToString();
txtPhone.Text =
dtGridView.Rows[r].Cells[3].Value.ToString();
txtEmail.Text =
dtGridView.Rows[r].Cells[4].Value.ToString();
txtActive.Text =
dtGridView.Rows[r].Cells[5].Value.ToString();
txtSID.Text =
dtGridView.Rows[r].Cells[6].Value.ToString();
txtMID.Text =
dtGridView.Rows[r].Cells[7].Value.ToString();
}

private void btAdd_Click(object sender, EventArgs e)


{
var StaffQ = (from S in db.staffs
where S.staff_id == txtSfID.Text
select S).SingleOrDefault();
if (StaffQ != null)
{
MessageBox.Show("Staff ID has already existed",
"Error!");
}
else
{
try
{
staff S = new staff();
S.staff_id = txtSfID.Text;
S.first_name = txtFName.Text;
S.last_name = txtLName.Text;
S.phone = txtPhone.Text;
S.email = txtEmail.Text;
S.active = txtActive.Text;
S.store_id = txtSID.Text;
S.manager_id = txtMID.Text;
db.staffs.Add(S);
db.SaveChanges();
}
catch
P a g e 19 | 46
University of Technology and Education

{
MessageBox.Show("Store id " +
"doest not exist in Store table!" + " Please
update store id first",
"Error!");
}
MySetStaff();
}
}

private void btEdit_Click(object sender, EventArgs e)


{
int r = dtGridView.CurrentCell.RowIndex;
string tempSID =
dtGridView.Rows[r].Cells[0].Value.ToString();
staff SQuery = db.staffs.Single(x => x.staff_id ==
tempSID);
if (SQuery != null)
{
store StoreQuery = db.stores.Single(x => x.store_id ==
txtSID.Text);

var SQuery2 = (from Staff in db.staffs


where Staff.staff_id == txtSfID.Text
select Staff).SingleOrDefault();
if (StoreQuery == null)
{
MessageBox.Show("Store id does not exist. Please
update store id!",
"Error!");
return;
}
if (SQuery.staff_id == txtSfID.Text)
{
SQuery.first_name = txtFName.Text;
SQuery.last_name = txtLName.Text;
SQuery.phone = txtPhone.Text;
SQuery.email = txtEmail.Text;
SQuery.active = txtActive.Text;
SQuery.store_id = txtSID.Text;
SQuery.manager_id = txtMID.Text;
db.SaveChanges();
}
else
{
if (SQuery2 != null)
P a g e 20 | 46
University of Technology and Education

{
MessageBox.Show("Store id " +
"doest not exist in Store table!",
"Error!");
return;
}
try
{
db.staffs.Remove(SQuery);

db.SaveChanges();
staff S = new staff();
S.staff_id = txtSfID.Text;
S.first_name = txtFName.Text;
S.last_name = txtLName.Text;
S.phone = txtPhone.Text;
S.email = txtEmail.Text;
S.active = txtActive.Text;
S.store_id = txtSID.Text;
S.manager_id = txtMID.Text;
db.staffs.Add(S);
db.SaveChanges();
}
catch
{
MessageBox.Show("Staff ID has already
existed!", "Error!");
}
}
}
MySetStaff();
}

private void btDelete_Click(object sender, EventArgs e)


{
int r = dtGridView.CurrentCell.RowIndex;
string tempSID =
dtGridView.Rows[r].Cells[0].Value.ToString();
staff Staff = db.staffs.Single(x => x.staff_id ==
tempSID);
db.staffs.Remove(Staff);
db.SaveChanges();
MySetStaff();
}

private void btCancel_Click(object sender, EventArgs e)


P a g e 21 | 46
University of Technology and Education

{
LoadData();
}

private void btFind_Click(object sender, EventArgs e)


{
FindStaffByName();
}
b. Report

5. Category form

P a g e 22 | 46
University of Technology and Education

string connstr = "Data Source=(localdb)\\mssqllocaldb;Initial


Catalog=CoffeeManagement;Integrated Security=True";

SqlConnection conn = null;


SqlDataAdapter adCategory = null;
DataTable dtCategory = null;
bool Add = false;
void ResetAllTextBox()
{
txtCID.ResetText();
txtCName.ResetText();
txtFind.ResetText();
}
void LoadData()
{
ResetAllTextBox();

try
{
conn = new SqlConnection(connstr);
adCategory = new SqlDataAdapter("SELECT * FROM
categories", conn);
dtCategory = new DataTable();
adCategory.Fill(dtCategory);
dtGridView.DataSource = dtCategory;
}
catch (SqlException)
{

P a g e 23 | 46
University of Technology and Education

MessageBox.Show("Cannot connect to Categories table",


"Error!");

}
}
void FindByNameCategory()
{

try
{
conn = new SqlConnection(connstr);
adCategory = new SqlDataAdapter("SELECT * FROM
categories WHERE category_name LIKE '%" + txtFind.Text + "%'", conn);
dtCategory = new DataTable();
adCategory.Fill(dtCategory);
dtGridView.DataSource = dtCategory;
}
catch (SqlException)
{
MessageBox.Show("Cannot connect to Categories table",
"Error!");

}
}
void CheckCategoryIDExit()
{
// Mở kết nối
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Open();
SqlCommand cmd = new SqlCommand();
try
{
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;

cmd.CommandText = "SELECT Count(*) FROM categories


WHERE category_id = '" +

txtCID.Text.Trim() + "'";

int nCount;
nCount = Int32.Parse(cmd.ExecuteScalar().ToString());
if (nCount > 0)
{
P a g e 24 | 46
University of Technology and Education

MessageBox.Show("CategoryID (" +
txtCID.Text.Trim() + ") have already existed. " +
"Please enter again!");

txtCID.ResetText();
txtCID.Focus();

}
else
{
txtCName.Focus();
}
}
catch (SqlException)
{
MessageBox.Show("Error!");
}
finally
{
conn.Close();
}
}

private void FormCategory_Load(object sender, EventArgs e)


{
LoadData();
}

private void btAdd_Click(object sender, EventArgs e)


{
Add = true;
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Open();
SqlCommand cmd = new SqlCommand();
try
{
cmd.Connection = conn;

cmd.CommandType = CommandType.Text;

cmd.CommandText = "INSERT INTO categories VALUES('" +


txtCID.Text
+ "','" + txtCName.Text + "')";

P a g e 25 | 46
University of Technology and Education

cmd.ExecuteNonQuery();

LoadData();
MessageBox.Show("Add successully!");

}
catch (SqlException)

MessageBox.Show(cmd.CommandText);
}
conn.Close();
}

private void btEdit_Click(object sender, EventArgs e)


{
Add = false;
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Open();
SqlCommand cmd = new SqlCommand();
try
{
cmd.Connection = conn;

cmd.CommandType = CommandType.Text;

int r = dtGridView.CurrentCell.RowIndex;
string strCID =
dtGridView.Rows[r].Cells[0].Value.ToString();

cmd.CommandText = "UPDATE categories SET " +


"category_id='" +
txtCID.Text + "', category_name='" + txtCName.Text +
"'WHERE category_id = '" + strCID + "'";

cmd.ExecuteNonQuery();

LoadData();
// Thông báo
MessageBox.Show("Edit successfully!");
}

catch (SqlException)
P a g e 26 | 46
University of Technology and Education

MessageBox.Show("Cannot edit.", "Error!");


}
conn.Close();
}

private void btDelete_Click(object sender, EventArgs e)


{
DialogResult CheckYN;
CheckYN = MessageBox.Show("Do you really want to delete?",
"Answer", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (CheckYN == DialogResult.Yes)
{

if (conn.State == ConnectionState.Open)
conn.Close();
conn.Open();
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
int r = dtGridView.CurrentCell.RowIndex;
string CID =
dtGridView.Rows[r].Cells[0].Value.ToString();

cmd.CommandText = "DELETE FROM categories WHERE


category_id='" + CID + "'";

cmd.CommandType = CommandType.Text;

cmd.ExecuteNonQuery();
LoadData();

MessageBox.Show("Delete successfully Category ID


=" + CID + ".");

}
catch (SqlException)
{
MessageBox.Show("Cannot delete Category ID.",
"Error!");
}
P a g e 27 | 46
University of Technology and Education

finally
{
conn.Close();
}
}
}

private void btCancel_Click(object sender, EventArgs e)


{
LoadData();
}

private void dtGridView_CellClick(object sender,


DataGridViewCellEventArgs e)
{
int r = dtGridView.CurrentCell.RowIndex;

txtCID.Text =
dtGridView.Rows[r].Cells[0].Value.ToString();
txtCName.Text =
dtGridView.Rows[r].Cells[1].Value.ToString();
}

private void btFind_Click(object sender, EventArgs e)


{
FindByNameCategory();
}

private void txtCID_Leave(object sender, EventArgs e)


{
if (Add)
{
CheckCategoryIDExit();
}
}

P a g e 28 | 46
University of Technology and Education

6. Food form
a. Form

CoffeeManagementEntities db = null;
private void MySetCategory()
{
db = new CoffeeManagementEntities();
var CQ = from CL in db.categories select CL.category_name;
foreach (string CName in CQ)
{
cbCName.Items.Add(CName);
}
cbCName.SelectedIndex = 0;
}
private void MySetFood()
{
var Food = from FoodList in db.foods
join CL in db.categories on
FoodList.category_id equals CL.category_id
where (CL.category_name == cbCName.Text)
select FoodList;
DataTable dt = new DataTable();
dt.Columns.Add("food_id");
dt.Columns.Add("food_name");

P a g e 29 | 46
University of Technology and Education

dt.Columns.Add("food_price");
dt.Columns.Add("category_id");
foreach (var p in Food)
{
dt.Rows.Add(p.food_id, p.food_name, p.food_price,
p.category_id);
}
dtGridView.DataSource = dt;
}
private void FindFoodByName()
{
var Find = from FoodList in db.foods
where FoodList.food_name.Contains(txtFind.Text)
select FoodList;

DataTable dt = new DataTable();


dt.Columns.Add("food_id");
dt.Columns.Add("food_name");
dt.Columns.Add("food_price");
dt.Columns.Add("category_id");
foreach (var p in Find)
{
dt.Rows.Add(p.food_id, p.food_name, p.food_price,
p.category_id);
}
dtGridView.DataSource = dt;
}
private void ResetAllTextBox()
{
txtFID.ResetText();
txtFName.ResetText();
txtPrice.ResetText();
txtCID.ResetText();
}
private void LoadData()
{
MySetCategory();
ResetAllTextBox();
}
private void btCancel_Click(object sender, EventArgs e)
{
LoadData();
}

private void btDelete_Click(object sender, EventArgs e)


{
P a g e 30 | 46
University of Technology and Education

int r = dtGridView.CurrentCell.RowIndex;
string tempFID =
dtGridView.Rows[r].Cells[0].Value.ToString();
food Food = db.foods.Single(x => x.food_id == tempFID);
db.foods.Remove(Food);
db.SaveChanges();
MySetFood();
}

private void btEdit_Click(object sender, EventArgs e)


{
int r = dtGridView.CurrentCell.RowIndex;
string tempFID =
dtGridView.Rows[r].Cells[0].Value.ToString();
food FQuery = db.foods.Single(x => x.food_id == tempFID);
if (FQuery != null)
{
category CQuery = db.categories.Single(x =>
x.category_id == txtCID.Text);

var FQuery2 = (from Food in db.foods


where Food.food_id == txtFID.Text
select Food).SingleOrDefault();
if (FQuery == null)
{
MessageBox.Show("Category id does not exist.
Please update category id!",
"Error!");
return;
}
if (FQuery.food_id == txtFID.Text)
{
FQuery.food_name = txtFName.Text;
FQuery.food_price = decimal.Parse(txtPrice.Text);
FQuery.category_id = txtCID.Text;
db.SaveChanges();
}
else
{
if (FQuery2 != null)
{
MessageBox.Show("Store id " +
"doest not exist in Store table!",
"Error!");
return;
}
P a g e 31 | 46
University of Technology and Education

try
{
db.foods.Remove(FQuery);

db.SaveChanges();
food F = new food();
F.food_id = txtFID.Text;
F.food_name = txtFName.Text;
F.food_price = decimal.Parse(txtPrice.Text);
F.category_id = txtCID.Text;
db.foods.Add(F);
db.SaveChanges();
}
catch
{
MessageBox.Show("Food ID has already
existed!", "Error!");
}
}
}
MySetFood();
}

private void btAdd_Click(object sender, EventArgs e)


{
var FoodQ = (from F in db.foods
where F.food_id == txtFID.Text
select F).SingleOrDefault();
if (FoodQ != null)
{
MessageBox.Show("Food ID has already existed",
"Error!");
}
else
{
try
{
food F = new food();
F.food_id = txtFID.Text;
F.food_name = txtFName.Text;
F.food_price = decimal.Parse(txtPrice.Text);
F.category_id = txtCID.Text;
db.foods.Add(F);
db.SaveChanges();
}
catch
P a g e 32 | 46
University of Technology and Education

{
MessageBox.Show("Category id " +
"doest not exist in Category table!" + "
Please update category id first",
"Error!");
}
MySetFood();
}
}

private void label7_Click(object sender, EventArgs e)


{

private void btFind_Click(object sender, EventArgs e)


{
FindFoodByName();
}

private void dtGridView_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{
int r = dtGridView.CurrentCell.RowIndex;
txtFID.Text =
dtGridView.Rows[r].Cells[0].Value.ToString();
txtFName.Text =
dtGridView.Rows[r].Cells[1].Value.ToString();
txtPrice.Text =
dtGridView.Rows[r].Cells[2].Value.ToString();
txtCID.Text =
dtGridView.Rows[r].Cells[3].Value.ToString();
}

private void btExit_Click(object sender, EventArgs e)


{
FormStatisticcs fta = new FormStatisticcs();
fta.Show();
this.Hide();
}

private void FormFood_Load(object sender, EventArgs e)


{
LoadData();
}

P a g e 33 | 46
University of Technology and Education

private void cbCName_SelectedValueChanged(object sender,


EventArgs e)
{
MySetFood();
}

b. Report

7. Manager form
P a g e 34 | 46
University of Technology and Education

private void AddForm(Form f)


{
this.panel3.Controls.Clear();
f.TopLevel = false;
f.AutoScroll = true;
f.Dock = DockStyle.Fill;
this.panel3.Controls.Add(f);
f.Show();
}
private void panel3_Paint(object sender, PaintEventArgs e)
{

private void button1_Click(object sender, EventArgs e)


{
FormStores st = new FormStores();
AddForm(st);
}

private void button2_Click(object sender, EventArgs e)


{
FormStaff stt = new FormStaff();
AddForm(stt);
}

private void button3_Click(object sender, EventArgs e)


{
FormFood food = new FormFood();

P a g e 35 | 46
University of Technology and Education

AddForm(food);
}

private void button4_Click(object sender, EventArgs e)


{
FormCategory cte = new FormCategory();
AddForm(cte);
}

private void button5_Click(object sender, EventArgs e)


{
FormLogin lg = new FormLogin();
lg.Show();
this.Hide();
}

private void button6_Click(object sender, EventArgs e)


{
FormIncome IC = new FormIncome();
AddForm(IC);
}

private void button7_Click(object sender, EventArgs e)


{
FormStatisticcs stc = new FormStatisticcs();
AddForm(stc);
}

private void button8_Click(object sender, EventArgs e)


{
FormTimeKeeping tkp = new FormTimeKeeping();
AddForm(tkp);
}

8. Order form

P a g e 36 | 46
University of Technology and Education

CoffeeManagementEntities db = null;
private void MySetCategory()
{
db = new CoffeeManagementEntities();
var CQ = from CL in db.categories select CL.category_name;
foreach (string CName in CQ)
{
cbCName.Items.Add(CName);
}
cbCName.SelectedIndex = 0;
}
private void MySetFood()
{

var FQ = from FL in db.foods


join CL in db.categories on
FL.category_id equals CL.category_id
where (CL.category_name == cbCName.Text)
select FL.food_name;
cbFName.Items.Clear();
foreach (string FName in FQ)
{
cbFName.Items.Add(FName);
}
cbFName.SelectedIndex = 0;
}
private void MySetOrderFood()

P a g e 37 | 46
University of Technology and Education

{
var OrderFood = from OFList in db.order_foods
join OL in db.orders on OFList.order_id equals
OL.order_id
where (OL.order_id == txtOID.Text)
select OFList;
DataTable dt = new DataTable();
dt.Columns.Add("order_id");
dt.Columns.Add("food_id");
dt.Columns.Add("food_quantity");
dt.Columns.Add("total_price");
foreach (var p in OrderFood)
{
dt.Rows.Add(p.order_id, p.food_id, p.food_quantity,
p.total_price);
}
dtGridView.DataSource = dt;
}
private void MySetStore()
{
db = new CoffeeManagementEntities();
var StoreQ = from StoreL in db.stores select StoreL.store_name;
foreach (string StoreName in StoreQ)
{
cbStoreName.Items.Add(StoreName);
}
cbStoreName.SelectedIndex = 0;
}
private void MySetStaff()
{

var StaffQ = from StaffL in db.staffs


join StoreL in db.stores
on StaffL.store_id equals StoreL.store_id
where (StoreL.store_name == cbStoreName.Text)
select StaffL.last_name;
cbStaffName.Items.Clear();
foreach (string StaffName in StaffQ)
{
cbStaffName.Items.Add(StaffName);
P a g e 38 | 46
University of Technology and Education

}
cbStaffName.SelectedIndex = 0;
}
private void Reset()
{
numQuan.ResetText();
txtTotal.Text = "0";
txtOID.ResetText();
txtTableID.ResetText();
}
private void SetButtonOff()
{
groupBox1.Enabled = false;
btDelete.Enabled = false;
btSave.Enabled = false;
}
private void SetButtonOn()
{
groupBox1.Enabled = true;
btDelete.Enabled = true;
btSave.Enabled = true;
}
private void linkLabel1_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
{
FormLogin lg = new FormLogin();
lg.Show();
this.Hide();
}

private void FormOrder_Load(object sender, EventArgs e)


{
MySetCategory();
MySetFood();
MySetStore();
MySetStaff();
SetButtonOff();
}

P a g e 39 | 46
University of Technology and Education

private void cbCName_SelectedValueChanged(object sender,


EventArgs e)
{
MySetFood();
}

private void btAdd_Click(object sender, EventArgs e)


{
if (txtOID.Text != "")
{
decimal total = decimal.Parse(txtTotal.Text);
decimal price = decimal.Parse(txtPrice.Text) *
(int)numQuan.Value;
try
{
order_food OFood = new order_food();
OFood.order_id = txtOID.Text;
OFood.food_id = txtFID.Text;
OFood.food_quantity = (int)numQuan.Value;
OFood.total_price = price;
db.order_foods.Add(OFood);
db.SaveChanges();
}
catch
{
MessageBox.Show("Order id " +
"doest not exist in order table!" + " Please update order id
first",
"Error!");
}
txtTotal.Text = (total + price).ToString();
SetButtonOn();
btPay.Enabled = false;
MySetOrderFood();
}
else
{
MessageBox.Show("Please enter Order ID first!", "Error");
txtOID.Focus();
}
P a g e 40 | 46
University of Technology and Education

private void dtGridView_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{
int r = dtGridView.CurrentCell.RowIndex;
txtOID.Text = dtGridView.Rows[r].Cells[0].Value.ToString();
txtFID.Text = dtGridView.Rows[r].Cells[1].Value.ToString();
numQuan.Value =
dtGridView.Rows[r].Cells[2].Value.ToString().Length;
//txtTotal.Text = dtGridView.Rows[r].Cells[3].Value.ToString();
txtPrice.ResetText();
}

private void btDelete_Click(object sender, EventArgs e)


{
int r = dtGridView.CurrentCell.RowIndex;
string tempFID = dtGridView.Rows[r].Cells[1].Value.ToString();
order_food OF = db.order_foods.Single(x => x.food_id ==
tempFID);
db.order_foods.Remove(OF);
db.SaveChanges();
MySetOrderFood();
}

private void btSave_Click(object sender, EventArgs e)


{
var OrderQ = (from O in db.orders
where O.order_id == txtOID.Text
select O).SingleOrDefault();
if (OrderQ != null)
{
MessageBox.Show("Order ID has already existed", "Error!");
}
else
{
if (txtTableID.Text != "")
{
try
{
P a g e 41 | 46
University of Technology and Education

order O = new order();


O.order_id = txtOID.Text;
O.order_date = DateTime.Now;
O.store_id = txtSID.Text;
O.staff_id = txtSfID.Text;
O.table_id = txtTableID.Text;
O.total_price = decimal.Parse(txtTotal.Text);
db.orders.Add(O);
db.SaveChanges();
}
catch
{
MessageBox.Show("Store id " +
"doest not exist in store table!" + " Please update store id
first",
"Error!");
}

foreach (Button bt in groupBox1.Controls)


{
if (bt.Text == txtTableID.Text)
bt.BackColor = Color.Red;
}
Reset();
MySetOrderFood();
SetButtonOff();
btPay.Enabled = true;
cbStoreName.Enabled = false;
}
else
{
MessageBox.Show("Table hasn't been chosen yet! " +
"Please choose a table!", "Table");
}
}
}

private void cbStoreName_SelectedValueChanged(object sender,


EventArgs e)
{
P a g e 42 | 46
University of Technology and Education

MySetStaff();
}

private void cbStaffName_SelectedIndexChanged(object sender,


EventArgs e)
{
var staff = from SL in db.staffs
where SL.last_name == cbStaffName.Text
select SL;
if (staff != null)
{
foreach (var item in staff)
{
txtSfID.Text = item.staff_id.ToString();
}
}
}

private void cbFName_SelectedIndexChanged(object sender,


EventArgs e)
{
var FQ = from FL in db.foods
where FL.food_name == cbFName.Text
select FL;
if (FQ != null)
{
foreach (var id in FQ)
{
txtFID.Text = id.food_id.ToString();
txtPrice.Text = id.food_price.ToString();
}
}
}
int pay = 0;

private void btPay_Click(object sender, EventArgs e)


{
DialogResult p = MessageBox.Show("Pay?", "Payment",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (p == DialogResult.Yes)
P a g e 43 | 46
University of Technology and Education

{
SetButtonOn();
pay = 1;
}
}

private void button1_Click(object sender, EventArgs e)


{
Button bt = (Button)sender;
txtTableID.Text = bt.Text;
var Order = from OL in db.orders
where OL.table_id == bt.Text
select OL;

if (pay == 1)
{

if (bt.BackColor == Color.Red)
{
foreach (var id in Order)
{
txtOID.Text = id.order_id.ToString();
txtSID.Text = id.store_id.ToString();
txtSfID.Text = id.staff_id.ToString();
txtTotal.Text = id.total_price.ToString();
}
MySetOrderFood();

DialogResult p = MessageBox.Show("Table " + bt.Text + "


wants to pay?",
"Payment", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (p == DialogResult.Yes)
{
bt.BackColor = Color.White;
MessageBox.Show("Pay successfully!", "Payment");
pay = 0;
order O = db.orders.Single(x => x.order_id == txtOID.Text);
db.SaveChanges();
Reset();
P a g e 44 | 46
University of Technology and Education

MySetOrderFood();
SetButtonOff();
}
else
{
Reset();
MySetOrderFood();
SetButtonOff();
}
}
else
{
MessageBox.Show("This table has no customer!", "Payment");
pay = 0;
txtTableID.ResetText();
MySetOrderFood();
SetButtonOff();
}
}
if (bt.BackColor == Color.Red)
{
MessageBox.Show("This table has already had customer!",
"Table");

}
}

private void cbStoreName_SelectedIndexChanged(object sender,


EventArgs e)
{
var Store = from SL in db.stores
where SL.store_name == cbStoreName.Text
select SL;
if (Store != null)
{
foreach (var SL in Store)
{
txtSID.Text = SL.store_id.ToString();
}
}
P a g e 45 | 46
University of Technology and Education

private void btExit_Click(object sender, EventArgs e)


{
DialogResult exit = MessageBox.Show("Do you really want to
exit?", "Exit comfirm",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (exit == DialogResult.Yes)
Application.Exit();
}

PART 4: CONCLUDES
This is a relatively complex and broad topic, although our group has tried to build
a program system capable of managing a coffee shop. During the implementation
of the project, it has brought us a lot of useful knowledge, fixed the lost holes, as
well as found many good resources. Knowing how to design and run an interface
that we have never tried and thought we can do before is quite an interesting
experience and a stepping stone for us to continue to develop deeper and broader
research if we have the opportunity.

P a g e 46 | 46

You might also like