关于MVC工厂模式的增删改查sql存储过程
1 namespace DAL
2 {
3 public class DalHouse : IHouse
4 {
5 public int Add(HouseInfo m)
6 {
7 string sql = "pro_add";
8 SqlParameter eid = new SqlParameter("@eid", m.Eid);
9 SqlParameter bid = new SqlParameter("@bid", m.Bid);
10 SqlParameter floornum = new SqlParameter("@floornum", m.FloorNum);
11 SqlParameter roomnum = new SqlParameter("@roomnum", m.RoomNum);
12 SqlParameter spaces = new SqlParameter("@spaces", m.Spaces);
13 SqlParameter ads = new SqlParameter("@ads", m.Addresses);
14 SqlParameter tid = new SqlParameter("@tid", m.Tid);
15 SqlParameter sids = new SqlParameter("@sids", m.Sids);
16 SqlParameter uid = new SqlParameter("@uid", m.Uid);
17 SqlParameter[] paras = new SqlParameter[] { eid, bid, floornum, roomnum, spaces, ads, tid, sids, uid };
18 int i = DbHelperSQL.ExecuteNonQuery(DbHelperSQL.ConnB2c, CommandType.StoredProcedure, sql, paras);
19 return i;
20 }
21
22 public int Delete(string id)
23 {
24 string sql = "pro_delete";
25 SqlParameter pid = new SqlParameter("@id", id);
26 SqlParameter[] paras = new SqlParameter[] { pid };
27 int i = DbHelperSQL.ExecuteNonQuery(DbHelperSQL.ConnB2c, CommandType.StoredProcedure, sql, paras);
28 return i;
29 }
30
31 public HouseInfo SelectById(int id)
32 {
33 string sql = "pro_selectbyid";
34 SqlParameter pid = new SqlParameter("@id",id);
35 SqlParameter[] paras = new SqlParameter[] { pid};
36 DataTable dt= DbHelperSQL.ExecuteDataTable(DbHelperSQL.ConnB2c,CommandType.StoredProcedure,sql,paras);
37 List<HouseInfo> info = JsonConvert.DeserializeObject<List<HouseInfo>>(JsonConvert.SerializeObject(dt));
38 return info[0];
39 }
40
41 public PageList ShowAll(DataModel d)
42 {
43 string sql = "pro_ShowAll";
44 SqlParameter paraEid = new SqlParameter("@Estateid", d.Eid);
45 SqlParameter paraBid = new SqlParameter("@BuildingId", d.Bid);
46 SqlParameter paraTid = new SqlParameter("@Type", d.Tid);
47 SqlParameter paraSid = new SqlParameter("@State", d.Sids);
48 SqlParameter paraAddress = new SqlParameter("@Address", d.Addresses);
49 SqlParameter paraSize = new SqlParameter("@size", d.Size);
50 SqlParameter paraIndex = new SqlParameter("@index", d.Index);
51 SqlParameter count = new SqlParameter("@totalCount", SqlDbType.Int);
52 count.Direction = ParameterDirection.Output;
53 SqlParameter page = new SqlParameter("@totalPage", SqlDbType.Int);
54 page.Direction = ParameterDirection.Output;
55 SqlParameter[] paras = new SqlParameter[] { paraEid, paraBid, paraTid, paraSid, paraAddress, paraSize, count, paraIndex, page };
56 DataTable dt= DbHelperSQL.ExecuteDataTable(DbHelperSQL.ConnB2c,CommandType.StoredProcedure,sql,paras);
57 PageList p = new PageList();
58 p.TotalCount = Convert.ToInt32(count.Value);
59 p.TotalPage = Convert.ToInt32(page.Value);
60 p.House = JsonConvert.DeserializeObject<List<HouseInfo>>(JsonConvert.SerializeObject(dt));
61 return p;
62 }
63
64 public List<Building> ShowBuilding()
65 {
66 string sql = "select * from Building";
67 DataTable dt= DbHelperSQL.ExecuteDataTable(DbHelperSQL.ConnB2c,CommandType.Text,sql);
68 return JsonConvert.DeserializeObject<List<Building>>(JsonConvert.SerializeObject(dt));
69
70 }
71
72 public List<BuildStruct> ShowBuildStruct()
73 {
74 string sql = "select * from BuildStruct";
75 DataTable dt = DbHelperSQL.ExecuteDataTable(DbHelperSQL.ConnB2c, CommandType.Text, sql);
76 return JsonConvert.DeserializeObject<List<BuildStruct>>(JsonConvert.SerializeObject(dt));
77 }
78
79 public List<HouseEatate> ShowEstate()
80 {
81 string sql = "select * from HouseEstate";
82 DataTable dt = DbHelperSQL.ExecuteDataTable(DbHelperSQL.ConnB2c, CommandType.Text, sql);
83 return JsonConvert.DeserializeObject<List<HouseEatate>>(JsonConvert.SerializeObject(dt));
84 }
85
86 public List<States> ShowStates()
87 {
88 string sql = "select * from States";
89 DataTable dt = DbHelperSQL.ExecuteDataTable(DbHelperSQL.ConnB2c, CommandType.Text, sql);
90 return JsonConvert.DeserializeObject<List<States>>(JsonConvert.SerializeObject(dt));
91 }
92
93 public List<HouseType> ShowType()
94 {
95 string sql = "select * from HouseType";
96 DataTable dt = DbHelperSQL.ExecuteDataTable(DbHelperSQL.ConnB2c, CommandType.Text, sql);
97 return JsonConvert.DeserializeObject<List<HouseType>>(JsonConvert.SerializeObject(dt));
98 }
99
100 public int Update(HouseInfo m)
101 {
102 string sql = "pro_update";
103 SqlParameter id = new SqlParameter("@id", m.Id);
104 SqlParameter eid = new SqlParameter("@eid",m.Eid);
105 SqlParameter bid = new SqlParameter("@bid", m.Bid);
106 SqlParameter floornum = new SqlParameter("@floornum", m.FloorNum);
107 SqlParameter roomnum = new SqlParameter("@roomnum", m.RoomNum);
108 SqlParameter spaces = new SqlParameter("@spaces", m.Spaces);
109 SqlParameter ads = new SqlParameter("@ads", m.Addresses);
110 SqlParameter tid = new SqlParameter("@tid", m.Tid);
111 SqlParameter sids = new SqlParameter("@sids", m.Sids);
112 SqlParameter uid = new SqlParameter("@uid", m.Uid);
113 SqlParameter[] paras = new SqlParameter[] {id,eid,bid,floornum,roomnum,spaces,ads,tid,sids,uid };
114 int i= DbHelperSQL.ExecuteNonQuery(DbHelperSQL.ConnB2c,CommandType.StoredProcedure,sql,paras);
115 return i;
116
117 }
118 }
119 }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAL;
using IDAL;
using Model;
using Factory;
using BLL;
namespace EF_House.Controllers
{
public class HouseController : Controller
{ // GET: House
public ActionResult Index(int index=1,int size=3)
{
DataModel d = new DataModel();
d.Bid = 0;
d.Eid = 0;
d.Sids = 0;
d.Tid = 0;
d.Addresses = "";
d.Index = index;
d.Size = size;
BllHouse bll = new BllHouse();
PageList info = bll.ShowAll(d);
ViewBag.totalpage = info.TotalPage;
ViewBag.totalcount = info.TotalCount;
ViewBag.index = d.Index;
//下拉绑定
ViewBag.Estate = new SelectList(bll.ShowEatate(), "Id", "Ename");
ViewBag.HouseType = new SelectList(bll.ShowType(), "Id", "TypeName");
ViewBag.States = new SelectList(bll.ShowStates(), "Id", "Sname");
ViewBag.Building = new SelectList(bll.ShowBuilding(), "Bid", "Bname");
return View(info.House);
}
public ActionResult Search(string Addresses="",int Bid=0,int Eid=0,int Sids=0,int Tid=0,int index=1,int size=3)
{
if (Addresses == null)
{
Addresses = "";
}
ViewBag.bid = Bid;
ViewBag.eid = Eid;
ViewBag.sids = Sids;
ViewBag.tid = Tid;
ViewBag.ads = Addresses;
DataModel d = new DataModel();
d.Bid = Bid;
d.Eid = Eid;
d.Sids = Sids;
d.Tid = Tid;
d.Addresses = Addresses;
d.Index = index;
d.Size = size; BllHouse bll = new BllHouse();
PageList p = bll.ShowAll(d);
ViewBag.totalcount = p.TotalCount;
ViewBag.totalpage = p.TotalPage;
ViewBag.index = d.Index;
//下拉绑定
ViewBag.Estate = new SelectList(bll.ShowEatate(), "Id", "Ename");
ViewBag.HouseType = new SelectList(bll.ShowType(), "Id", "TypeName");
ViewBag.States = new SelectList(bll.ShowStates(), "Id", "Sname");
ViewBag.Building = new SelectList(bll.ShowBuilding(), "Bid", "Bname"); return PartialView("Search",p.House);
}
public int DeleteAll(string id)
{
BllHouse bll = new BllHouse();
int i = bll.Delete(id);
return i;
}
public void Delete(string id)
{
BllHouse bll = new BllHouse();
int i = bll.Delete(id);
if (i > 0)
{
Response.Write("<script>alert('删除成功');location.href='/house/index/1'</script>");
}
else
{
Response.Write("<script>alert('删除失败')</script>");
}
}
public ActionResult Update(int id)
{
BllHouse bll = new BllHouse();
ViewBag.Estate = new SelectList(bll.ShowEatate(), "Id", "Ename");
ViewBag.HouseType = new SelectList(bll.ShowType(), "Id", "TypeName");
ViewBag.States = new SelectList(bll.ShowStates(), "Id", "Sname");
ViewBag.Building = new SelectList(bll.ShowBuilding(), "Bid", "Bname");
ViewBag.Struct = new SelectList(bll.ShowBuildStruct(), "Id", "Uname"); HouseInfo h = bll.SelectById(id); return View(h);
}
[HttpPost]
public void Update(HouseInfo h)
{
BllHouse bll = new BllHouse();
int i = bll.Update(h);
if (i > 0)
{
Response.Write("<script>alert('修改成功');location.href='/house/index/1'</script>");
}
else
{
Response.Write("<script>alert('修改失败')</script>");
}
}
public ActionResult Add()
{
BllHouse bll = new BllHouse();
ViewBag.Estate = new SelectList(bll.ShowEatate(), "Id", "Ename");
ViewBag.HouseType = new SelectList(bll.ShowType(), "Id", "TypeName");
ViewBag.States = new SelectList(bll.ShowStates(), "Id", "Sname");
ViewBag.Building = new SelectList(bll.ShowBuilding(), "Bid", "Bname");
ViewBag.Struct = new SelectList(bll.ShowBuildStruct(), "Id", "Uname");
return View();
}
[HttpPost]
public ActionResult Add(HouseInfo h)
{
BllHouse bll = new BllHouse();
int i = bll.Add(h);
if (i > 0)
{
return Content("<script>alert('添加成功');location.href='/house/index/1'</script>");
}
else
{
return Content("<script>alert('添加失败')</script>");
} }
}
}
<script>
//全选
$(function () {
$("#CheckAll").click(function () {
if (this.checked) {
$("input[name='check']").each(function () {
this.checked = true;
})
} else {
$("input[name='check']:checked").each(function () {
this.checked = false;
})
} })
})
function DelAll() {
var check = [];
$("input[name='check']:checked").each(function () {
check.push($(this).val());
})
if (check == 0) {
alert("请先进行选择");
}
else {
$.ajax({
type: "post",
url: "/house/deleteall",
data: { id: check.toString() },
success: function (a) {
if (a > 0) {
alert("批量删除成功!");
location.reload();
}
}
})
} }
</script>
基本的页面布局,这里就不展示了,
还需要说的就是使用强类型视图,在修改的时候,
需要使用@html.Hidden("Id")
关于MVC工厂模式的增删改查sql存储过程的更多相关文章
- MVC与EasyUI结合增删改查
构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(9)-MVC与EasyUI结合增删改查 在第八讲中,我们已经做到了怎么样分页.这一讲主要讲增删改查.第六讲的 ...
- MVC无限级分类02,增删改查
继上一篇"MVC无限级分类01,分层架构,引入缓存,完成领域模型与视图模型的映射",本篇开始MVC无限级分类的增删改查部分,源码在github. 显示和查询 使用datagrid显 ...
- sqlHelper做增删改查,SQL注入处理,存储值,cookie,session
一.存储值 eg:登录一个页面,在进入这个页面之前你怎么知道它登没登录呢?[在登录成功之后我们把状态保存起来] 存储值得方式有两种,一种是cookie,一种是session 1.1区别: 代码: if ...
- 使用jdbc实现简单的mvc模式的增删改查
Mvc模式设计: 视图:添加界面(addUser.jsp),修改界面(updateUser.jsp),显示页面(allUser.jsp) 控制器:添加信息控制器(AddUserServlet),修改信 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(9)-MVC与EasyUI结合增删改查
系列目录 文章于2016-12-17日重写 在第八讲中,我们已经做到了怎么样分页.这一讲主要讲增删改查.第六讲的代码已经给出,里面包含了增删改,大家可以下载下来看下. 这讲主要是,制作漂亮的工具栏,虽 ...
- MVC 入门 自动生成 增删改查所有功能
MVC现在版本已经是5了 EF现在最新的应该是6.0.2了 开发工具是 Visual Studio2013 数据库是 SQL Server 2012 这些需要.NET Framework4.5 的 ...
- MVC 中aspx的增删改查
先看总体结构 LInQ #pragma warning disable 1591 //--------------------------------------------------------- ...
- MVC中使用EF增删改查,简单的例子
//这个是分页数据和总页数类 public class SummaryBase<TModel> { public SummaryBase(); public IList<TModel ...
- ASP.NET+MVC+EntityFramework快速实现增删改查
本教程已经录制视频,欢迎大家观看我在CSDN学院录制的课程:http://edu.csdn.net/lecturer/944
随机推荐
- [转][Oracle]清理归档日志
来自:https://www.cnblogs.com/Roobbin/p/9617962.html 在Oracle 服务器,打开cmd命令行,执行以下命令: rman target / crossch ...
- Windows平台安装配置mysql数据库
Windows平台安装配置mysql数据库 作者:Eric 微信:loveoracle11g 去下载mysql软件 https://www.mysql.com/downloads/ https://d ...
- logging模块全总结
Python之日志处理(logging模块) 本节内容 日志相关概念 logging模块简介 使用logging提供的模块级别的函数记录日志 logging模块日志流处理流程 使用logging四 ...
- Redis深入学习笔记(五)Redis阻塞原因
在实际使用Redis中,有时会碰到客户端timeout异常,或者没有可用连接异常等等异常,总结大概有如下原因: 内部阻塞原因: 1)大对象存取. 2)Fork阻塞. 3)Aof刷盘阻塞(距离上次刷盘大 ...
- Highcharts绘制曲线图小结
Higcharts绘制曲线图很好用! 虽然说Highcharts官网有API 刚接触这个领域,学有心得,理解不到位之处希望大家多多指教! 项目绘制的曲线是:平均水位随时间的变化而改变的水情走势图. 主 ...
- kafka connect rest api
1. 获取 Connect Worker 信息curl -s http://127.0.0.1:8083/ | jq lenmom@M1701:~/workspace/software/kafka_2 ...
- PhysicalBasedRendering(一)物理篇
很多人对PBR的理解是存在偏差的,跳不出传统渲染模型的思维圈子,把它理解成一种模拟效果更为精确的算法公式,虽然在某种程度上是对的,但没有看到PBR的本质. PBR是对光在真实世界中与环境交互的一种近似 ...
- centos7安装Jenkins
一.准备工作 机器要求: 256MB内存,建议大于512MB 10GB的硬盘空间(用于存放Jenkins镜像) 需要安装以下软件: Java (JRE或者JDK都可以) 需要可以访问公网 关闭防火墙连 ...
- 记一次bond引起的网络故障
本案中3个关键服务器 物理服务器:192.168.6.63,简称P,(Physical server) KVM-VM:192.168.6.150,是物理服务器P上的一个KVM虚机,简称VM NAS:外 ...
- C# 密码盐码加密
每次新建账号密码的时候都需要获取一下新的盐码,之后用使用MD5为用户密码加密 /// <summary> /// 获取新的密码盐码 /// </summary> /// < ...