//用户信息删除 public ActionResult MembersDelete(string id) { int membersId; if (!int.TryParse(id, out membersId)) { return(Content("<script>alert('参数不合法!');window.location.href = '/Manage/MembersManage'</script>")); } using (FlowersSIMEntities fs = new FlowersSIMEntities()) { Members entity = fs.Members.FirstOrDefault(m => m.MembersId == membersId); if (entity != null) { fs.Members.Remove(entity); } if (fs.SaveChanges() > 0) { return(Content("<script>alert('删除成功!');window.location.href = '/Manage/MembersManage'</script>")); } else { return(Content("<script>alert('删除失败!');window.location.href = '/Manage/MembersManage'</script>")); } } }
public ActionResult MembersAdd(Members entity) { ModelState.Remove("MembersId"); if (ModelState.IsValid) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { bool result = fs.Members.Count(m => m.MembersName == entity.MembersName) == 0; if (result) { entity.LoginStatus = 0; fs.Members.Add(entity); if (fs.SaveChanges() > 0) { return(Content("<script language='javascript' type='text/javascript'>alert('增加成功!');window.location.href = '/Manage/MembersManage'</script>")); } else { return(Content("<script>alert('增加失败!');window.location.href = '/Manage/MembersManage'</script>")); } } else { return(Content("<script>alert('该用户名已存在,请重新输入!');window.location.href = '/Manage/MembersAdd'</script>")); } } } return(View(entity)); }
public ActionResult MenberEdit(Members enty) { using (FlowersSIMEntities dc = new FlowersSIMEntities()) { //2.1 先查询 Members ape = dc.Members.FirstOrDefault(u => u.MembersId == enty.MembersId); //2.2 在数据上下文中修改状态值 if (ape != null) { ape.MembersName = enty.MembersName; ape.MembersPwd = enty.MembersPwd; ape.Phone = enty.Phone; ape.ConfirmPwd = enty.ConfirmPwd; ape.LoginStatus = enty.LoginStatus; } //2.3 保存回数据库中 if (dc.SaveChanges() > 0) { return(Content("<script>alert('修改成功!');window.location.href = '/Personal/Index'</script>")); } else { if (ape != null) { return(Content("<script>alert('没有进行修改!');window.location.href = '/Personal/Index'</script>")); } else { return(Content("<script>alert('修改失败!');window.location.href = '/Personal/Index'</script>")); } } } }
public ActionResult MenberEdit(string id) { int memberId; if (!int.TryParse(id, out memberId)) { return(Content("<script>alert('参数不合法!');window.location.href = '/Personal/Index'</script>")); } //2、退款 using (FlowersSIMEntities dc = new FlowersSIMEntities()) { //2.1 先查询 Members entity = dc.Members.FirstOrDefault(u => u.MembersId == memberId); //2.2 在数据上下文中修改状态值 if (entity != null) { return(View(entity)); } //2.3 保存回数据库中 if (dc.SaveChanges() > 0) { return(Content("<script>alert('修改成功!');window.location.href = '/Personal/Index'</script>")); } else { return(Content("<script>alert('修改失败!');window.location.href = '/Personal/Index'</script>")); } } }
//商品信息删除 public ActionResult ProductDelete(string id) { int productId; if (!int.TryParse(id, out productId)) { return(Content("<script>alert('参数不合法!');window.location.href = '/Manage/ProductManage'</script>")); } using (FlowersSIMEntities fs = new FlowersSIMEntities()) { Product entity = fs.Product.FirstOrDefault(p => p.ProductId == productId); if (entity != null) { fs.Product.Remove(entity); } if (fs.SaveChanges() > 0) { return(Content("<script>alert('删除成功!');window.location.href = '/Manage/ProductManage'</script>")); } else { return(Content("<script>alert('删除失败!');window.location.href = '/Manage/ProductManage'</script>")); } } }
public ActionResult AddCar(int id, int Num) { int membersId = Convert.ToInt32(Session["LoginId"]); using (FlowersSIMEntities fs = new FlowersSIMEntities()) { ShoppingCar shop = fs.ShoppingCar.FirstOrDefault(s => s.MembersId == membersId && s.ProductId == id); if (shop != null) { //return Content("<script>alert('您已加入购物车');window.location.href='/Home/Detailed?id=" + id + "'</script>"); return(Json(-1, JsonRequestBehavior.AllowGet)); } else { Product pro = fs.Product.FirstOrDefault(p => p.ProductId == id); ShoppingCar shopcar = new ShoppingCar(); shopcar.MembersId = membersId; shopcar.NowPrice = pro.NowPrice; shopcar.Num = Num; shopcar.Price = pro.NowPrice * Num; shopcar.ProductId = id; fs.ShoppingCar.Add(shopcar); fs.SaveChanges(); return(Json("添加成功", JsonRequestBehavior.AllowGet)); } } }
public ActionResult DeleteShopCar(int id) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { ShoppingCar car = fs.ShoppingCar.FirstOrDefault(c => c.CarId == id); fs.ShoppingCar.Remove(car); fs.SaveChanges(); return(Json("删除成功", JsonRequestBehavior.AllowGet)); } }
public ActionResult ProductEdit(Product entity) { Bind(); //获取上传图片路径 HttpPostedFileBase file = Request.Files["imgFile"]; var ext = Path.GetExtension(file.FileName); if (ext != "") { string path = "/Image/" + Guid.NewGuid().ToString() + file.FileName; file.SaveAs(Request.MapPath(path)); entity.Picture1 = path; } using (FlowersSIMEntities fs = new FlowersSIMEntities()) { Product model = fs.Product.FirstOrDefault(p => p.ProductId == entity.ProductId); if (model != null) { model.ProductName = entity.ProductName; model.Material = entity.Material; model.Package = entity.Package; model.FlowerLanguage = entity.FlowerLanguage; if (entity.Picture1 != null) { model.Picture1 = entity.Picture1; } model.OriginalPrice = entity.OriginalPrice; model.NowPrice = entity.NowPrice; model.Inventory = entity.Inventory; model.FestivalId = entity.FestivalId; model.ColorId = entity.ColorId; model.FlowerKindId = entity.FlowerKindId; } if (fs.SaveChanges() > 0) { return(Content("<script>alert('修改成功');window.location.href = '/Manage/ProductManage'</script>")); } else { if (model != null) { return(Content("<script>alert('未做任何修改,修改成功');window.location.href = '/Manage/ProductManage'</script>")); } else { return(Content("<script>alert('修改失败');window.location.href = '/Manage/ProductManage'</script>")); } } } }
public ActionResult EditShopCar(int afternum, int id) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { ShoppingCar car = fs.ShoppingCar.FirstOrDefault(c => c.CarId == id); Product pro = fs.Product.FirstOrDefault(p => p.ProductId == car.ProductId); car.Num = afternum; car.Price = afternum * pro.NowPrice; decimal price = afternum * pro.NowPrice; fs.SaveChanges(); return(Json(price, JsonRequestBehavior.AllowGet)); } }
public ActionResult SendContent(string SendContent, int SendMemId) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { int Id = Convert.ToInt32(Session["LoginId"]); Chat chat = new Chat(); chat.MembersId = Id; chat.ChatContent = SendContent; chat.ChatCreatTime = DateTime.Now; chat.SendMemId = SendMemId; chat.ChatStatus = 0; fs.Chat.Add(chat); fs.SaveChanges(); } return(Json(SendMemId, JsonRequestBehavior.AllowGet)); }
public ActionResult Delete(string id) { //1、验证参数的合法性 字符串参数 => 整型值 int ordersId; if (!int.TryParse(id, out ordersId)) { return(Content("<script>alert('参数不合法!');window.location.href = '/MemberOrders/OrderIndex'</script>")); } //2、订单操作 using (FlowersSIMEntities dc = new FlowersSIMEntities()) { //2.1 先查询 Orders entity = dc.Orders.FirstOrDefault(u => u.OrdersId == ordersId); //2.2 在数据上下文中修改状态值 if (entity != null) { if (entity.Status == 4) { entity.Status += 1; } if (entity.Status == 1) { entity.Status = 4; } if (entity.Status == 0) { entity.Status += 1; } if (entity.Status == 2) { entity.Status += 1; } } //2.3 保存回数据库中 if (dc.SaveChanges() > 0) { return(Content("<script>alert('操作成功!');window.location.href = '/MemberOrders/Index'</script>")); } else { return(Content("<script>alert('操作失败!');window.location.href = '/MemberOrders/Index'</script>")); } } }
[HttpPost] //限定此Action仅能通过Post请求访问 //模型映射规则:实体模型属性 和 目标元素名称 一致 //MVC会将视图页面中各元素的值,赋值给模型对象entity的同名属性 public ActionResult Register(Members members) { members.LoginStatus = 0; members.Phone = "123456789"; using (FlowersSIMEntities dc = new FlowersSIMEntities()) { //增加用户功能 dc.Members.Add(members); if (dc.SaveChanges() > 0) { return(Content("<script>alert('用户注册成功!');window.location.href='/Main/Index'</script>")); } else { return(Content("<script>alert('用户注册失败!');window.location.href='/Home/Index'</script>")); } } }
//获取该订单内的商品信息 public void GetOrdersList(int ordersId) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { //清除存放订单内商品信息的临时数据表OrderGoods内的数据 List <OrderGoods> list = fs.OrderGoods.ToList(); for (int i = 0; i < list.Count; i++) { int ogId = list[i].OGId; SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ogId", ogId), }; fs.Database.ExecuteSqlCommand("delete from OrderGoods where OGId=@ogId", paras); } Orders entity1 = fs.Orders.FirstOrDefault(o => o.OrdersId == ordersId); string[] productIdString = entity1.ProductIdList.Split(','); int[] productIdArray = Array.ConvertAll(productIdString, int.Parse); string[] productNumString = entity1.OrderNumbers.Split(','); int[] productNumArray = Array.ConvertAll(productNumString, int.Parse); decimal Price = 0; OrderGoods entity = new OrderGoods(); for (int i = 0; i < productIdArray.Length; i++) { int productId = productIdArray[i]; Product IdToName = fs.Product.FirstOrDefault(p => p.ProductId == productId); entity.Picture1 = IdToName.Picture1; entity.ProductName = IdToName.ProductName; entity.Num = productNumArray[i]; entity.NowPrice = IdToName.NowPrice; string num1 = Convert.ToString(entity.Num); decimal num = decimal.Parse(num1); decimal nowPrice = Convert.ToDecimal(entity.NowPrice); entity.Price = num * nowPrice; Price += num * nowPrice; fs.OrderGoods.Add(entity); fs.SaveChanges(); } ViewBag.Price = Price; } }
public ActionResult ProductAdd(Product entity) { Bind(); ModelState.Remove("ProductId"); //获取上传图片路径 HttpPostedFileBase file = Request.Files["imgFile"]; var ext = Path.GetExtension(file.FileName); string path = "/Image/" + Guid.NewGuid().ToString() + file.FileName; file.SaveAs(Request.MapPath(path)); entity.Picture1 = path; if (ModelState.IsValid) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { bool result = fs.Product.Count(m => m.ProductName == entity.ProductName) == 0; if (result) { fs.Product.Add(entity); if (fs.SaveChanges() > 0) { return(Content("<script>alert('增加成功!');window.location.href = '/Manage/ProductManage'</script>")); } else { return(Content("<script>alert('增加失败!');window.location.href = '/Manage/ProductManage'</script>")); } } else { return(Content("<script>alert('该商品名称存在,请重新输入!');window.location.href = '/Manage/ProductAdd'</script>")); } } } return(View(entity)); }
public ActionResult OrdersList(string ordersId, int pageIndex = 1) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { int id = Convert.ToInt32(ordersId); //获取当前查看的订单信息并用ViewBag.Orders存放信息 Orders entity = fs.Orders.FirstOrDefault(o => o.OrdersId == id); ViewBag.Orders = entity; string[] productIdString = entity.ProductIdList.Split(','); int[] productIdArray = Array.ConvertAll(productIdString, int.Parse); //每次加载订单商品信息的第一页时重新进行商品信息的添加 if (pageIndex < productIdArray.Length || productIdArray.Length == 1) { GetOrdersList(id); } entity.Price = GetOrdersPrice(); fs.SaveChanges(); ViewBag.Price = entity.Price; List <OrderGoods> list = fs.OrderGoods.ToList().ToPagedList(pageIndex, 2); return(View(list)); } }
public ActionResult MembersEdit(Members entity) { if (ModelState.IsValid) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { Members model = fs.Members.FirstOrDefault(m => m.MembersId == entity.MembersId); if (model != null) { model.MembersName = entity.MembersName; model.MembersPwd = entity.MembersPwd; model.Phone = entity.Phone; model.Gender = entity.Gender; model.LoginStatus = 0; } fs.Configuration.ValidateOnSaveEnabled = false; if (fs.SaveChanges() > 0) { fs.Configuration.ValidateOnSaveEnabled = true; return(Content("<script>alert('修改成功');window.location.href = '/Manage/MembersManage'</script>")); } else { if (model != null) { return(Content("<script>alert('未做任何修改,修改成功');window.location.href = '/Manage/MembersManage'</script>")); } else { return(Content("<script>alert('修改失败');window.location.href = '/Manage/MembersManage'</script>")); } } } } return(View(entity)); }
public ActionResult Add(Orders entity) { string name = Session["LoginUser"] as string; string productidlist = Request.Form["ProductIdList"]; string[] sproductid = productidlist.Split(','); int carorproduct = Convert.ToInt32(Request.Form["carOrproduct"]); //获取来源 int price = 0; string num = ""; #region 将carid转为productid string array = ""; #endregion #region 计算数量加入购物车 using (FlowersSIMEntities dc = new FlowersSIMEntities()) { Orders order = new Orders(); if (carorproduct == 0) { if (productidlist.Length == 1) { int id = Convert.ToInt32(productidlist); ShoppingCar shop = dc.ShoppingCar.FirstOrDefault(s => s.CarId == id); array = Convert.ToString(shop.ProductId); } else { string[] idlist = productidlist.Split(','); for (int i = 0; i < idlist.Length; i++) { int id = Convert.ToInt32(idlist[i]); ShoppingCar shop = dc.ShoppingCar.FirstOrDefault(s => s.CarId == id); if (i == (idlist.Count() - 1)) { array = "" + array + "," + shop.ProductId + ""; } if (idlist.Count() == 1) { array = "" + shop.ProductId + ""; } if (i == 0) { array = "" + shop.ProductId + ""; } if (i != (idlist.Count() - 1) && i != 0) { array = "" + array + "," + shop.ProductId + ""; } } } for (int i = 0; i < sproductid.Count(); i++) { int id = Convert.ToInt32(sproductid[i]); ShoppingCar shop = dc.ShoppingCar.FirstOrDefault(s => s.CarId == id); price += Convert.ToInt32(shop.NowPrice * shop.Num); if (i == (sproductid.Count() - 1)) { //num += "" + shop.Num + ""; num = "" + num + "," + shop.Num + ""; } if (sproductid.Count() == 1) { //num = "" + shop.Num + ""; num = "" + shop.Num + ""; } if (i == 0) { num = "" + shop.Num + ""; } if (i != (sproductid.Count() - 1) && i != 0) { //num += "" + shop + ","; num = "" + num + "," + shop.Num + ""; } } order.OrderNumbers = num; order.Price = price; order.ProductIdList = array; } else { int productid = (Convert.ToInt32(productidlist)); Product pro = dc.Product.FirstOrDefault(p => p.ProductId == productid); string Number = Request.Form["Number"]; order.OrderNumbers = Number; order.Price = pro.NowPrice * Convert.ToInt32(Number); order.ProductIdList = productidlist; } Members ber = dc.Members.FirstOrDefault(b => b.MembersName == name); order.MembersId = ber.MembersId; order.OrdersName = entity.OrdersName; order.OrdersPhone = entity.OrdersPhone; order.ConsigneeAddress = entity.ConsigneeAddress; order.ConsigneeName = entity.ConsigneeName; order.ConsigneePhone = entity.ConsigneePhone; order.Status = 0; order.DeliveryTime = DateTime.Now.Date; order.CreateTime = DateTime.Now.Date; //添加实体 dc.Orders.Add(order); //保存更新 dc.SaveChanges(); } #endregion return(Content("<script>alert('添加订单成功!');window.location.href='/MemberOrders/OrderIndex'</script>")); }
public ActionResult BatchDelete(string idArray, string tableName) { //判断是否有选中数据 if (idArray == "" || tableName == "") { return(Content("<script>alert('您还没选中,请先选中至少一项数据再进行操作!');window.location.href = '/Manage/" + tableName + "Manage'</script>")); } //将传进来的所选数据的编号数组进行分割 string[] deleteValue = idArray.Split(','); int[] deleteId = Array.ConvertAll(deleteValue, int.Parse); for (int i = 0; i < deleteId.Length; i++) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { int id = deleteId[i]; //删除该表名内的数据及其与其他表相关联的数据 if (tableName == "Members") { ShoppingCar entity = fs.ShoppingCar.FirstOrDefault(p => p.MembersId == id); if (entity != null) { fs.ShoppingCar.Remove(entity); fs.SaveChanges(); } Orders entity1 = fs.Orders.FirstOrDefault(p => p.MembersId == id); if (entity1 != null) { fs.Orders.Remove(entity1); fs.SaveChanges(); } Members entity2 = fs.Members.FirstOrDefault(p => p.MembersId == id); if (entity2 != null) { fs.Members.Remove(entity2); fs.SaveChanges(); } } if (tableName == "Product") { Product entity = fs.Product.FirstOrDefault(p => p.ProductId == id); if (entity != null) { fs.Product.Remove(entity); fs.SaveChanges(); } } if (tableName == "Orders") { Orders entity = fs.Orders.FirstOrDefault(p => p.OrdersId == id); if (entity != null) { fs.Orders.Remove(entity); fs.SaveChanges(); } } if (i == deleteId.Length - 1) { return(Content("<script>alert('删除成功!,已删除" + deleteId.Length + "项数据');window.location.href = '/Manage/" + tableName + "Manage'</script>")); } } } return(View()); }
public ActionResult OrderOperation(string id) { int ordersId; if (!int.TryParse(id, out ordersId)) { return(Content("<script>alert('参数不合法!');window.location.href = '/Manage/OrdersManage'</script>")); } using (FlowersSIMEntities fs = new FlowersSIMEntities()) { Orders entity = fs.Orders.FirstOrDefault(u => u.OrdersId == ordersId); if (entity != null) { if (entity.Status == 1) { entity.Status = 2; Orders entity1 = fs.Orders.FirstOrDefault(o => o.OrdersId == ordersId); string[] productIdString = entity1.ProductIdList.Split(','); int[] productIdArray = Array.ConvertAll(productIdString, int.Parse); string[] productNumString = entity1.OrderNumbers.Split(','); int[] productNumArray = Array.ConvertAll(productIdString, int.Parse); for (int i = 0; i < productIdArray.Length; i++) { int productId = productIdArray[i]; Product model = fs.Product.FirstOrDefault(p => p.ProductId == productId); model.Inventory -= productNumArray[i]; if (model.Inventory < 0) { return(Content("<script>alert('库存不足无法发货,请及时增加库存!');window.location.href = '/Manage/OrdersList/?ordersId=" + id + "'</script>")); } } } if (entity.Status == 4) { entity.Status = 5; Orders entity1 = fs.Orders.FirstOrDefault(o => o.OrdersId == ordersId); string[] productIdString = entity1.ProductIdList.Split(','); int[] productIdArray = Array.ConvertAll(productIdString, int.Parse); string[] productNumString = entity1.OrderNumbers.Split(','); int[] productNumArray = Array.ConvertAll(productIdString, int.Parse); for (int i = 0; i < productIdArray.Length; i++) { int productId = productIdArray[i]; Product model = fs.Product.FirstOrDefault(p => p.ProductId == productId); model.Inventory += productNumArray[i]; } } } if (fs.SaveChanges() > 0) { return(Content("<script>alert('订单操作成功!');window.location.href = '/Manage/OrdersList/?ordersId=" + id + "'</script>")); } else { return(Content("<script>alert('订单操作失败!');window.location.href = '/Manage/OrdersManage/?ordersId=" + id + "'</script>")); } } }