public List <ThucUong> ListThucUong()
        {
            List <ThucUong> list  = new List <ThucUong>();
            string          query = "select * from thucuong";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    SqlCommand cmd = new SqlCommand(query, connection);
                    connection.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        //db to model
                        ThucUong thucUong = new ThucUong();
                        thucUong.MaHH       = reader[0].ToString();
                        thucUong.TenHangHoa = reader[1].ToString();
                        thucUong.Gia        = Convert.ToInt32(reader[2]);
                        thucUong.TinhTrang  = Convert.ToInt32(reader[3]);
                        list.Add(thucUong);
                    }
                    connection.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            return(list);
        }
        //public List<FoodViewModel> Search(string keyword)
        //{

        //    var model = (from a in cf.ThucUong
        //                 join b in cf.FoodCategory
        //                 on a.IDCategory equals b.ID
        //                 where a.Name.Contains(keyword)
        //                 select new
        //                 {
        //                     ID = a.ID,
        //                     CateName = b.Name,
        //                     UrlTitle = a.UrlTitle,
        //                     Price = a.Price,
        //                     Detail = a.Detail,
        //                     Description = a.Description,
        //                     Name = a.Name,
        //                     Image = a.Image,

        //                 }).AsEnumerable().Select(x => new FoodViewModel()
        //                 {
        //                     ID = x.ID,
        //                     CateName = x.Name,
        //                     UrlTitle = x.UrlTitle,
        //                     Price = x.Price,
        //                     Detail = x.Detail,
        //                     Description = x.Description,
        //                     Name = x.Name,
        //                     Image = x.Image,
        //                 });
        //    //model.OrderByDescending(x => x.ID).Skip((pageIndex - 1) * pageSize).Take(pageSize);
        //    return model.ToList();
        //}
        public bool Insert(ThucUong thucuong)
        {
            try
            {
                cf.ThucUongs.Add(thucuong);
                cf.SaveChanges();
                return(true);
            }
            catch { return(false); }
        }
 public void AddItem(ThucUong thucUong, int soLuong, int TiLeGiam)
 {
     ListViewItem item = new ListViewItem(thucUong.TenHangHoa);
     item.SubItems.Add(soLuong.ToString());
     item.SubItems.Add(thucUong.Gia.ToString());
     item.SubItems.Add(TiLeGiam.ToString());
     item.SubItems.Add(GetThucUongToTal(thucUong.Gia, soLuong, TiLeGiam).ToString());
     item.SubItems.Add(thucUong.MaHH);
     listViewDSThucUong.Items.Add(item);
     listViewDSThucUong.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.HeaderSize);
     listViewDSThucUong.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.HeaderSize);
     listViewDSThucUong.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.HeaderSize);
     listViewDSThucUong.AutoResizeColumn(3, ColumnHeaderAutoResizeStyle.HeaderSize);
     listViewDSThucUong.AutoResizeColumn(4, ColumnHeaderAutoResizeStyle.HeaderSize);
 }
 public ActionResult Edit(ThucUong model)
 {
     if (ModelState.IsValid)
     {
         SetViewBag(model.IDCaterogy);
         var kq = new FoodDao().Update(model);
         if (kq)
         {
             SetAlert("Sửa món thành công", "success");
             return(Redirect("/Admin/Food/DSFood"));
         }
     }
     SetViewBag();
     return(View(model));
 }
        public bool Update(ThucUong model)
        {
            try
            {
                var food = cf.ThucUongs.Find(model.ID);
                food.IDCaterogy = model.IDCaterogy;
                food.Name       = model.Name;
                food.Price      = model.Price;

                food.Image       = model.Image;
                food.Description = model.Description;
                food.Detail      = model.Detail;
                cf.SaveChanges();
                return(true);
            }
            catch { return(false); }
        }
Beispiel #6
0
        private void CrystalReportViewer1_Load(object sender, EventArgs e)
        {
            List <HoaDon>         hds             = new HoaDon().getListHoaDon();
            List <MonAn>          mas             = new MonAn().GetMonAns();
            List <ThucUong>       tus             = new ThucUong().GetThucUongs();
            List <NhanVien>       nvs             = new NhanVien().getListNhanVien();
            List <BestSellerFood> bestSellerFoods = new BestSellerFood().GetBestSellerFoods(tungay, denngay);
            List <BestSellerItem> bestSellerItems = new BestSellerItem().GetBestSellerDrinks(tungay, denngay);

            hDreport1.Database.Tables[0].SetDataSource(hds);// này là cái list món ăn thức uống trong hóa đơn
            hDreport1.Database.Tables[1].SetDataSource(tus);
            hDreport1.Database.Tables[2].SetDataSource(nvs);
            hDreport1.Database.Tables[3].SetDataSource(mas);
            hDreport1.Database.Tables[4].SetDataSource(bestSellerFoods);
            hDreport1.Database.Tables[5].SetDataSource(bestSellerItems);
            hDreport1.SetParameterValue("ptungay", from);
            hDreport1.SetParameterValue("pdenngay", to);
            hDreport1.SetParameterValue("pnguoitao", nguoitao);
            hDreport1.SetParameterValue("pngaytaobaocao", ngaytao);
            hDreport1.SetParameterValue("pthucthu", thucthu);
            hDreport1.SetParameterValue("psohoadon", sohd);
            crystalReportViewer1.ReportSource = hDreport1;
        }