public ActionResult actsuamonan(Models.MonAn ma) { if (ModelState.IsValid) { string tenfiletam = (string)Session["tenfilehinh"]; //tên file tạm Models.MonAn x = dc.MonAns.Find(ma.monan_id); if (x != null) { if (tenfiletam == "") { ma.monan_hinh = ""; } else { System.IO.FileInfo fi = new System.IO.FileInfo(tenfiletam); ma.monan_hinh = @"/Areas/Admin/Image/" + ma.monan_id + fi.Extension; //lấy phần mở rộng của file ảnh. vdL .jpg //xác định đường dẫn lưu file string tenfile = Request.PhysicalApplicationPath + @"/" + ma.monan_hinh; //tên file real tenfiletam = Request.PhysicalApplicationPath + @"/Areas/Admin/ImageTemp/" + tenfiletam; System.IO.File.Copy(tenfiletam, tenfile); //copy từ file tạm qua file real // x.monan_id = ma.monan_id; x.monan_ten = ma.monan_ten; x.monan_trangthai = ma.monan_trangthai; x.monan_gia = ma.monan_gia; x.loaimonan_id = ma.loaimonan_id; dc.SaveChanges(); } return(RedirectToAction("LstMonAn")); } return(RedirectToAction("LstMonAn")); } return(View("suamonan")); }
//hiện form sửa món ăn//chuafix public ActionResult suamonan(int id) { Models.MonAn x = dc.MonAns.Find(id); if (x != null) { return(View(x)); } return(RedirectToAction("LstMonan")); }
//xóa món ăn public ActionResult actxoaMonAn(int id) { Models.MonAn x = dc.MonAns.Find(id); if (x != null) { dc.MonAns.Remove(x); dc.SaveChanges(); return(Redirect("/Admin/admin/LstMonan")); } return(View("LstMonAn")); }
public JsonResult GetListDish() { List <Models.MonAn> ListDish = new List <Models.MonAn>(); Database db = new Database(); DataTable dt = db.Query("select * from MonAn; "); for (int i = 0; i < dt.Rows.Count; i++) { Models.MonAn Dish = new Models.MonAn(); Dish.MaMonAn = dt.Rows[i]["MaKhauPhanAn"].ToString(); Dish.TenMonAn = dt.Rows[i]["TenKhauPhanAn"].ToString(); ListDish.Add(Dish); } return(Json(ListDish)); }
public ActionResult actanmonan(int id) { Models.MonAn x = dc.MonAns.Find(id); if (x != null) { if (x.monan_trangthai == true) { x.monan_trangthai = false; } else { x.monan_trangthai = true; } dc.SaveChanges(); return(Redirect("/Admin/admin/LstMonan")); } return(View("LstMonAn")); }
public JsonResult MenuList() { List <Models.MonAn> MenuList = new List <Models.MonAn>(); Database db = new Database(); DataTable dt = db.Query("select * from MonAn ;"); for (int i = 0; i < dt.Rows.Count; i++) { Models.MonAn Dish = new Models.MonAn(); Dish.MaMonAn = dt.Rows[i]["MaKhauPhanAn"].ToString(); Dish.TenMonAn = dt.Rows[i]["TenKhauPhanAn"].ToString(); Dish.GiaBan = dt.Rows[i]["Gia"].ToString(); Dish.SoLuong = dt.Rows[i]["SoLuong"].ToString(); Dish.Hinh = dt.Rows[i]["HinhAnh"].ToString(); Dish.GhiChu = dt.Rows[i]["GhiChu"].ToString(); MenuList.Add(Dish); } return(Json(MenuList)); }
//action thêm món ăn vào bàn public ActionResult actThemMonAnVaoBan(int id, int idBan) { var thongbao = ""; //var idBan = banan_current_id; //int idBanAn = Int32.Parse(idBan.ToString()); Models.BanAn ba = dc.BanAns.Find(idBan); Models.MonAn ma = dc.MonAns.Find(id); string session_id = "hoadon" + idBan; Models.HoaDon hd = Session[session_id] as Models.HoaDon; Models.ChiTietHoaDon cthd = null; foreach (var a in hd.ChiTietHoaDons.Where(x => x.monan_id == id)) { cthd = a; break; } if (cthd == null) { cthd = new Models.ChiTietHoaDon(); cthd.monan_id = ma.monan_id; cthd.dongia = ma.monan_gia; cthd.soluong = 1; cthd.hoadon_id = hd.hoadon_id; cthd.MonAn = ma; hd.ChiTietHoaDons.Add(cthd); //thongbao = "<script language='javascript' type='text/javascript'>alert('Thành công!');</script>"; //ViewBag.thongbao = thongbao; Session["Thongbao_Noidung"] = "Thành công!"; Session["Thongbao_Kieu"] = "alert-success"; return(RedirectToAction("formThemMonAnVaoBan/" + idBan)); } else { cthd.soluong += 1; //int.Parse(Request["soluong"].ToString()); //thongbao = "<script language='javascript' type='text/javascript'>alert('Thành công!');</script>"; //return Content(thongbao); } return(RedirectToAction("formThemMonAnVaoBan/" + idBan)); }
public ActionResult actthemMonAn(Models.MonAn ma) { string tenfiletam = (string)Session["tenfilehinh"]; //tên file tạm //Models.MonAn x = dc.MonAns.Find(ma.monan_id); if (tenfiletam == "") { ma.monan_hinh = ""; } else { var kt = new Models.db_totnghiepEntities(); var ktid = kt.MonAns.SqlQuery("Select * from MonAn ORDER BY monan_id DESC").ToList(); //var getid = kt.MonAns.SqlQuery("Select TOP(1) from MonAn").FirstOrDefault(); string tenImg = tenfiletam.Split('.')[0]; System.IO.FileInfo fi = new System.IO.FileInfo(tenfiletam); //if (dc.MonAns.ToList().Count() == 0) //{ ma.monan_hinh = @"/Areas/Admin/Image/" + tenImg + (ktid[0].monan_id + 1) + fi.Extension; //lấy phần mở rộng của file ảnh. vdL .jpg //xác định đường dẫn lưu file //} //else //{ //ma.monan_hinh = @"/Areas/Admin/Image/" + (dc.MonAns.Count() + 1) + fi.Extension; //lấy phần mở rộng của file ảnh. vdL .jpg //xác định đường dẫn lưu file //} string tenfile = Request.PhysicalApplicationPath + @"/" + ma.monan_hinh; //tên file real tenfiletam = Request.PhysicalApplicationPath + @"/Areas/Admin/ImageTemp/" + tenfiletam; System.IO.File.Copy(tenfiletam, tenfile); //copy từ file tạm qua file real dc.MonAns.Add(ma); dc.SaveChanges(); } return(RedirectToAction("LstMonAn")); }
public ActionResult actThanhToanNBan() { Models.HoaDon hd_tong = Session["hoadon_thanhtoanN"] as Models.HoaDon; bool flag = false; string[] arr_idBan = Request.Form.GetValues("arr_idBan"); for (int i = 0; i < arr_idBan.Count(); i++) { var idBan = Int32.Parse(arr_idBan[i].ToString()); int tongtienhd = 0; string session_id = "hoadon" + idBan; var _sessionDB_TT = "datban_thanhtoan" + idBan; var idDatBan = Session[_sessionDB_TT]; Models.DatBan datban = dc.DatBans.Find(Int32.Parse(idDatBan.ToString())); Models.HoaDon hd = Session[session_id] as Models.HoaDon; DateTime _dt = DateTime.Now; foreach (var a in hd.ChiTietHoaDons) { tongtienhd += a.dongia * a.soluong; } Models.HoaDon hoadon = new HoaDon(); hoadon.hoadon_monan_tonggia = tongtienhd; hoadon.hoadon_tongtien = tongtienhd; hoadon.hoadon_ngaylap = _dt; hoadon.thuckhach_sdt = hd.thuckhach_sdt; hoadon.phongan_id = hd.phongan_id; hoadon.banan_id = hd.banan_id; //đặt lại trạng thái của đơn đặt bàn datban.datban_trangthai = true; //thêm chi tiết vào hóa đơn foreach (var a in hd.ChiTietHoaDons) { Models.ChiTietHoaDon cthd = new ChiTietHoaDon(); Models.MonAn ma = dc.MonAns.Find(a.monan_id); cthd.hoadon_id = hoadon.hoadon_id; cthd.monan_id = a.monan_id; cthd.nuocuong_id = a.nuocuong_id; cthd.soluong = a.soluong; cthd.dongia = a.dongia; cthd.MonAn = ma; hoadon.ChiTietHoaDons.Add(cthd); } //add vào hóa đơn lớn if (flag == false) { hd_tong = hoadon; flag = true; } else { hd_tong.hoadon_tongtien += hoadon.hoadon_tongtien; hd_tong.hoadon_monan_tonggia += hoadon.hoadon_monan_tonggia; foreach (var a in hd.ChiTietHoaDons) { Models.ChiTietHoaDon cthd = new ChiTietHoaDon(); Models.MonAn ma = dc.MonAns.Find(a.monan_id); cthd.hoadon_id = hoadon.hoadon_id; cthd.monan_id = a.monan_id; cthd.nuocuong_id = a.nuocuong_id; cthd.soluong = a.soluong; cthd.dongia = a.dongia; cthd.MonAn = ma; hd_tong.ChiTietHoaDons.Add(cthd); } } //save dc.HoaDons.Add(hoadon); dc.SaveChanges(); //clear session Session[session_id] = new Models.HoaDon(); Session[_sessionDB_TT] = null; Session["hoadon_thanhtoanN"] = hd_tong; } return(View("XuatBill", hd_tong.ChiTietHoaDons.ToList())); }
public void AddMenu(Models.MonAn a) { Database db = new Database(); db.Insert("insert into MonAn values (N'" + a.TenMonAn + "'," + a.GiaBan + ", " + a.SoLuong + ", N'" + a.GhiChu + "', '" + a.Hinh + "');"); }