/// <summary> /// 各类车型车位数量 列表 /// </summary> public ActionResult pcctvList(tb_pcctv model) { int count = 0; ViewBag.pcctvList = dpcctv.GetList(model, ref count); ViewBag.page = Utils.ShowPage(count, model.PageSize, model.PageIndex, 5); return(View()); }
/// <summary> /// 得到一个对象实体 /// </summary> public tb_pcctv GetInfo(tb_pcctv model) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from tb_pcctv"); strSql.Append(" where id=@id "); using (IDbConnection conn = DapperHelper.OpenConnection()) { model = conn.Query <tb_pcctv>(strSql.ToString(), model)?.FirstOrDefault(); } return(model); }
/// <summary> /// 各类车型车位数量 保存 /// </summary> public JsonResult pcctvSave(tb_pcctv model) { if (model == null) { return(ResultTool.jsonResult(false, "参数错误!")); } if (!String.IsNullOrEmpty(model.id)) { bool boolResult = dpcctv.Update(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "更新失败!")); } else { model.id = Guid.NewGuid().ToString("N"); bool boolResult = dpcctv.Add(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "添加失败!")); } }
/// <summary> /// 是否存在该记录 /// </summary> public bool Exists(tb_pcctv model) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) from tb_pcctv"); strSql.Append(" where id=@id "); using (IDbConnection conn = DapperHelper.OpenConnection()) { int count = conn.Execute(strSql.ToString(), model); if (count > 0) { return(true); } else { return(false); } } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(tb_pcctv model) { StringBuilder strSql = new StringBuilder(); StringBuilder setSql = new StringBuilder(); strSql.Append("update tb_pcctv set "); if (!String.IsNullOrEmpty(model.pid)) { setSql.Append("pid=@pid,"); } if (model.pcctvlevel != null) { setSql.Append("pcctvlevel=@pcctvlevel,"); } if (!String.IsNullOrEmpty(model.pcctvname)) { setSql.Append("pcctvname=@pcctvname,"); } if (!String.IsNullOrEmpty(model.classification)) { setSql.Append("classification=@classification,"); } if (!String.IsNullOrEmpty(model.remark)) { setSql.Append("remark=@remark,"); } strSql.Append(setSql.ToString().TrimEnd(',')); strSql.Append(" where id=@id "); using (IDbConnection conn = DapperHelper.OpenConnection()) { int count = conn.Execute(strSql.ToString(), model); if (count > 0) { return(true); } else { return(false); } } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(tb_pcctv model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_pcctv("); strSql.Append("pid,id,pcctvlevel,pcctvname,classification,remark)"); strSql.Append(" values ("); strSql.Append("@pid,@id,@pcctvlevel,@pcctvname,@classification,@remark)"); using (IDbConnection conn = DapperHelper.OpenConnection()) { int count = conn.Execute(strSql.ToString(), model); if (count > 0) { return(true); } else { return(false); } } }
/// <summary> /// 获得数据列表 /// </summary> public List <tb_pcctv> GetList(tb_pcctv model, ref int total) { List <tb_pcctv> list; StringBuilder strSql = new StringBuilder(); StringBuilder whereSql = new StringBuilder(" where 1 = 1 "); strSql.Append(" select ROW_NUMBER() OVER(ORDER BY id desc) AS RID, * from tb_pcctv "); if (!String.IsNullOrEmpty(model.pid)) { whereSql.Append(" and pid=@pid"); } if (model.pcctvlevel != null) { whereSql.Append(" and pcctvlevel=@pcctvlevel"); } if (!String.IsNullOrEmpty(model.pcctvname)) { whereSql.Append(" and pcctvname=@pcctvname"); } if (!String.IsNullOrEmpty(model.classification)) { whereSql.Append(" and classification=@classification"); } if (!String.IsNullOrEmpty(model.remark)) { whereSql.Append(" and remark=@remark"); } strSql.Append(whereSql); string CountSql = "SELECT COUNT(1) as RowsCount FROM (" + strSql.ToString() + ") AS CountList"; string pageSqlStr = "select * from ( " + strSql.ToString() + " ) as Temp_PageData where Temp_PageData.RID BETWEEN {0} AND {1}"; pageSqlStr = string.Format(pageSqlStr, (model.PageSize * (model.PageIndex - 1) + 1).ToString(), (model.PageSize * model.PageIndex).ToString()); using (IDbConnection conn = DapperHelper.OpenConnection()) { list = conn.Query <tb_pcctv>(pageSqlStr, model)?.ToList(); total = conn.ExecuteScalar <int>(CountSql, model); } return(list); }
/// <summary> /// 各类车型车位数量 详情 /// </summary> public ActionResult pcctvInfo(tb_pcctv model) { model = dpcctv.GetInfo(model); return(View(model ?? new tb_pcctv())); }
/// <summary> /// 各类车型车位数量 删除 /// </summary> public JsonResult pcctvDelete(tb_pcctv model) { bool boolResult = dpcctv.Delete(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "删除失败!")); }