天津刘金鹏做网站,宁波网站推广方式怎么样,生鲜网站建设费用,扒wordpress站目录
效果图
实现过程
1创建数据库 2创建项目文件 3创建控制器#xff0c;右键添加#xff0c;控制器
编辑 注意这里要写Home编辑 创建成功
数据模型创建过程之前作品有具体过程编辑
4创建DAL
5创建BLL
6创建视图#xff0c;右键添加视图
编辑 7HomeCont…目录
效果图
实现过程
1创建数据库 2创建项目文件 3创建控制器右键添加控制器
编辑 注意这里要写Home编辑 创建成功
数据模型创建过程之前作品有具体过程编辑
4创建DAL
5创建BLL
6创建视图右键添加视图
编辑 7HomeController.cs代码
8Index.cshtml代码 效果图 实现过程
1创建数据库 create database GoodsDB
CREATE TABLE Goods([GoodsID] [int] IDENTITY(1,1) NOT NULL,[GoodsName] [nvarchar](50) NOT NULL,[GoodsPrice] [decimal](10, 2) NOT NULL,[GoodsStock] [int] NOT NULL)INSERT Goods( [GoodsName], [GoodsPrice], [GoodsStock]) VALUES ( N魔幻陀螺, CAST(19.00 AS Decimal(10, 2)), 20)
INSERT Goods( [GoodsName], [GoodsPrice], [GoodsStock]) VALUES ( N开花精灵惊喜盲盒, CAST(89.00 AS Decimal(10, 2)), 10)
INSERT Goods ( [GoodsName], [GoodsPrice], [GoodsStock]) VALUES ( N跳跃战士玩具2变形汽车, CAST(18.00 AS Decimal(10, 2)), 50)
INSERT Goods( [GoodsName], [GoodsPrice], [GoodsStock]) VALUES ( N正版灵动奥特曼软胶囊玩具, CAST(25.00 AS Decimal(10, 2)), 20)
INSERT Goods ( [GoodsName], [GoodsPrice], [GoodsStock]) VALUES ( N帮帮龙变形车套装, CAST(109.00 AS Decimal(10, 2)), 5)2创建项目文件 3创建控制器右键添加控制器 注意这里要写Home 创建成功
数据模型创建过程之前作品有具体过程
4创建DAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Models;
namespace MvcApplication1.DAL
{public class GoodsService{ //展示public static ListGoods Show() {GoodsDBEntities db new GoodsDBEntities();return db.Goods.ToList();}//计算小计public static string Sun() {GoodsDBEntities db new GoodsDBEntities();return db.Goods.Sum(m m.GoodsPrice * m.GoodsStock).ToString();}//找到需要删除的一条数据后面被调用public static Goods GetID(string goodid) {GoodsDBEntities db new GoodsDBEntities();int temp Convert.ToInt32(goodid);return db.Goods.SingleOrDefault(m m.GoodsID temp);}//调用查找数据的方法进行删除public static bool Delect(string goodid) {Goods good GetID(goodid);if (goodnull){return false;}else{GoodsDBEntities db new GoodsDBEntities();db.Entry(good).State System.Data.EntityState.Deleted;db.Goods.Remove(good);return db.SaveChanges() 0;}}//排序方法public static ListGoods getGoodlist(bool priceOrder) {GoodsDBEntities db new GoodsDBEntities();if (priceOrdertrue){return db.Goods.OrderByDescending(m m.GoodsPrice).ToList();}else{return db.Goods.OrderBy(m m.GoodsPrice).ToList();}}}
}
5创建BLL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Models;
namespace MvcApplication1.BLL
{public class GoodsManger{public static ListGoods Show(){GoodsDBEntities db new GoodsDBEntities();return db.Goods.ToList();}public static string Sun(){return DAL.GoodsService.Sun();}public static bool Delect(string goodid) {return DAL.GoodsService.Delect(goodid);}public static ListGoods getGoodlist(bool priceOrder) {return DAL.GoodsService.getGoodlist(priceOrder);}}
}
6创建视图右键添加视图 7HomeController.cs代码 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{public class HomeController : Controller{//// GET: /Home/public ActionResult Index(bool PriceOrderDesefalse){ViewData[goods] BLL.GoodsManger.Show();ViewData[sum] BLL.GoodsManger.Sun();ViewData[goods] BLL.GoodsManger.getGoodlist(PriceOrderDese);ViewBag.PriceOrderDese !PriceOrderDese;return View();}public ActionResult DeleteGood(string goodId) {BLL.GoodsManger.Delect(goodId);return RedirectToAction(Index);}}
}8Index.cshtml代码 {Layout null;
}!DOCTYPE htmlhtml
headmeta nameviewport contentwidthdevice-width /titleIndex/title
/head
bodydivtable border1trthID/thth商品名/ththHtml.ActionLink(价格排序, Index, new {PriceOrderDeseViewBag.PriceOrderDese})/thth库存/thth小计/thth操作/th/tr{foreach (var good in ViewData[goods] as ListMvcApplication1.Models.Goods){trtdgood.GoodsID/tdtdgood.GoodsName/tdtdgood.GoodsPrice/tdtdgood.GoodsStock/tdtd(good.GoodsPrice*good.GoodsStock)/tdtdHtml.ActionLink(删除,DeleteGood, new{goodIdgood.GoodsID})/td/tr}}trtd colspan6总计:ViewData[sum]/td/tr/table/div
/body
/html