Пример #1
0
        void LoadCategoryIntoCombobox(ComboBox cb)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            cb.DataSource    = dbcontext.FoodCategories.ToList();
            cb.DisplayMember = "Name";
        }
Пример #2
0
        private void btnDeleteAccount_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            string userName = txtAccountUserName.Text;

            if (loginAccount.UserName.Equals(userName))
            {
                MessageBox.Show("Bậy nào đừng xóa bản thân mình bạn êi");
                return;
            }

            Account acc = dbcontext.Accounts.Where(x => userName.Equals(x.UserName)).SingleOrDefault();

            dbcontext.Remove(acc);

            int numberRows = dbcontext.SaveChanges();

            if (numberRows > 0)
            {
                MessageBox.Show("Cập nhập tài khoản thành công");
            }
            else
            {
                MessageBox.Show("Cập nhập tài khoản thất bại");
            }

            LoadAccount();
        }
Пример #3
0
        private void btnAddAccount_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            string userName    = txtAccountUserName.Text;
            string displayName = txtAccountDisplayName.Text;
            int    type        = (int)txtAccountType.Value;

            Account newAcc = new Account();

            newAcc.UserName    = userName;
            newAcc.DisplayName = displayName;
            newAcc.Type        = type;

            dbcontext.Add(newAcc);

            int numberRows = dbcontext.SaveChanges();

            if (numberRows > 0)
            {
                MessageBox.Show("Thêm tài khoản thành công");
                LoadAccount();
            }
            else
            {
                MessageBox.Show("Có lỗi khi thêm tài khoản");
            }
        }
Пример #4
0
        private void btnEditAccount_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            string userName    = txtAccountUserName.Text;
            string displayName = txtAccountDisplayName.Text;
            int    type        = (int)txtAccountType.Value;

            Account acc = dbcontext.Accounts.Where(x => userName.Equals(x.UserName)).SingleOrDefault();

            acc.DisplayName = displayName;
            acc.Type        = type;

            int numberRows = dbcontext.SaveChanges();

            if (numberRows > 0)
            {
                MessageBox.Show("Cập nhập tài khoản thành công");
            }
            else
            {
                MessageBox.Show("Cập nhập tài khoản thất bại");
            }

            LoadAccount();
        }
Пример #5
0
        private void btnEditFood_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            string name       = txtFoodName.Text;
            int    categoryID = (cbFoodCategory.SelectedItem as FoodCategory).Id;
            float  price      = (float)nudFoodPrice.Value;
            int    id         = Convert.ToInt32(txtFoodId.Text);

            Food food = dbcontext.Foods.Where(x => id.Equals(x.Id)).SingleOrDefault();

            food.Name       = name;
            food.IdCategory = categoryID;
            food.Price      = price;

            int numberRows = dbcontext.SaveChanges();

            if (numberRows > 0)
            {
                MessageBox.Show("Sửa món thành công");
                LoadListFood();
            }
            else
            {
                MessageBox.Show("Có lỗi khi sửa thức ăn");
            }
        }
Пример #6
0
        private void btnAddFood_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            string name       = txtFoodName.Text;
            int    categoryID = (cbFoodCategory.SelectedItem as FoodCategory).Id;
            float  price      = (float)nudFoodPrice.Value;

            Food newfood = new Food();

            newfood.Name       = name;
            newfood.IdCategory = categoryID;
            newfood.Price      = price;

            dbcontext.Add(newfood);

            int numberRows = dbcontext.SaveChanges();

            if (numberRows > 0)
            {
                MessageBox.Show("Thêm món thành công");
                LoadListFood();
            }
            else
            {
                MessageBox.Show("Có lỗi khi thêm thức ăn");
            }
        }
Пример #7
0
        private void txtFoodId_TextChanged(object sender, EventArgs e)
        {
            if (dgvFood.SelectedCells.Count > 0)
            {
                using var dbcontext = new QuanLyQuanCafeContext();

                int?id = (int?)dgvFood.SelectedCells[0].OwningRow.Cells["IdCategory"].Value;

                if (id == null)
                {
                    return;
                }

                FoodCategory category = dbcontext.FoodCategories.Where(x => id.Equals(x.Id)).SingleOrDefault();

                cbFoodCategory.SelectedItem = category;

                int index = -1;
                int i     = 0;

                foreach (FoodCategory item in cbFoodCategory.Items)
                {
                    if (item.Id == category.Id)
                    {
                        index = i;
                        break;
                    }
                    i++;
                }

                cbFoodCategory.SelectedIndex = index;
            }
        }
Пример #8
0
        List <Food> SearchFoodByName(string name)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            List <Food> listFood = dbcontext.Foods.Where(x => x.Name.Contains(name)).ToList();

            return(listFood);
        }
Пример #9
0
 public bool Login(string userName, string password)
 {
     using var dbcontext = new QuanLyQuanCafeContext();
     if (dbcontext.Accounts.Where(x => $"{userName}".Equals(x.UserName) && $"{password}".Equals(x.PassWord)).Select(x => x).SingleOrDefault() != null)
     {
         return(true);
     }
     return(false);
 }
Пример #10
0
        void LoadAccount()
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            accountList.DataSource = dbcontext.Accounts.Select(x => new
            {
                x.UserName,
                x.DisplayName,
                x.Type
            }).ToList();
        }
Пример #11
0
        void LoadListViewByDate(DateTime fromDate, DateTime toDate, string strSkip, int take)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            int skip = Convert.ToInt32(strSkip) * billByPage - billByPage;

            dgvBill.DataSource = dbcontext.Bills.Join(dbcontext.TableFoods, b => b.IdTable, tb => tb.Id, (b, tb) => new
            {
                TableName  = tb.Name,
                TotalPrice = b.TotalPrice,
                CheckIn    = b.DateCheckIn,
                CheckOut   = b.DateCheckOut,
                Discount   = b.Discount
            }).Where(x => fromDate <= x.CheckIn && toDate >= x.CheckOut).Skip(skip).Take(take).ToList();
        }
Пример #12
0
        private void btnLastVewPage_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            int count = dbcontext.Bills.Where(x => dtpFromDate.Value <= x.DateCheckIn && dtpToDate.Value >= x.DateCheckOut).Count();

            int lastPage = count / billByPage;

            if (count % billByPage > 0)
            {
                lastPage++;
            }

            txtPage.Text = lastPage.ToString();
        }
Пример #13
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();
            string userName = txtUserName.Text;
            string password = txtPassword.Text;

            if (Login(userName, password))
            {
                Account         loginAccount = dbcontext.Accounts.Where(x => $"{userName}".Equals(x.UserName)).Select(x => x).FirstOrDefault();
                frmTableManager f            = new frmTableManager(loginAccount);
                this.Hide();
                f.ShowDialog();
                this.Show();
            }
            else
            {
                MessageBox.Show("Sai tên tài khoản hoặc mật khẩu!");
            }
        }
Пример #14
0
        private void btnResetPassword_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            string userName = txtAccountUserName.Text;

            Account acc = dbcontext.Accounts.Where(x => userName.Equals(x.UserName)).SingleOrDefault();

            acc.PassWord = "******";

            int numberRows = dbcontext.SaveChanges();

            if (numberRows > 0)
            {
                MessageBox.Show("Đặt lại tài khoản thành công");
            }
            else
            {
                MessageBox.Show("Đặt lại tài khoản thất bại");
            }

            LoadAccount();
        }
Пример #15
0
        private void btnDeleteFood_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            int id = Convert.ToInt32(txtFoodId.Text);

            Food food = dbcontext.Foods.Where(x => id.Equals(x.Id)).SingleOrDefault();

            dbcontext.BillInfos.Where(x => id.Equals(x.IdFood)).ToList().ForEach(x => { dbcontext.Remove(x); dbcontext.SaveChanges(); });

            dbcontext.Remove(food);

            int numberRows = dbcontext.SaveChanges();

            if (numberRows > 0)
            {
                MessageBox.Show("Xóa món thành công");
                LoadListFood();
            }
            else
            {
                MessageBox.Show("Có lỗi khi xóa thức ăn");
            }
        }
Пример #16
0
        void LoadListFood()
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            foodList.DataSource = dbcontext.Foods.ToList();
        }