/// <summary> /// 文印设计 列表 /// </summary> public ActionResult copyroomList(tb_copyroom model) { int count = 0; ViewBag.copyroomList = dcopyroom.GetList(model, ref count); ViewBag.page = Utils.ShowPage(count, model.PageSize, model.PageIndex, 5); return(View()); }
/// <summary> /// 得到一个对象实体 /// </summary> public tb_copyroom GetInfo(tb_copyroom model) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from tb_copyroom"); strSql.Append(" where id=@id "); using (IDbConnection conn = DapperHelper.OpenConnection()) { model = conn.Query <tb_copyroom>(strSql.ToString(), model)?.FirstOrDefault(); } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(tb_copyroom model) { StringBuilder strSql = new StringBuilder(); StringBuilder setSql = new StringBuilder(); strSql.Append("update tb_copyroom set "); if (!String.IsNullOrEmpty(model.buildingid)) { setSql.Append("buildingid=@buildingid,"); } if (!String.IsNullOrEmpty(model.name)) { setSql.Append("name=@name,"); } if (!String.IsNullOrEmpty(model.address)) { setSql.Append("address=@address,"); } if (!String.IsNullOrEmpty(model.phone)) { setSql.Append("phone=@phone,"); } if (model.isopen != null) { setSql.Append("isopen=@isopen,"); } if (!String.IsNullOrEmpty(model.intro)) { setSql.Append("intro=@intro,"); } if (model.addtime != null) { setSql.Append("addtime=@addtime,"); } 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 List <tb_copyroom> GetList(tb_copyroom model, ref int total) { List <tb_copyroom> 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_copyroom "); if (!String.IsNullOrEmpty(model.buildingid)) { whereSql.Append(" and buildingid=@buildingid"); } if (!String.IsNullOrEmpty(model.name)) { whereSql.Append(" and name=@name"); } if (!String.IsNullOrEmpty(model.address)) { whereSql.Append(" and address=@address"); } if (!String.IsNullOrEmpty(model.phone)) { whereSql.Append(" and phone=@phone"); } if (model.isopen != null) { whereSql.Append(" and isopen=@isopen"); } if (!String.IsNullOrEmpty(model.intro)) { whereSql.Append(" and intro=@intro"); } if (model.addtime != null) { whereSql.Append(" and addtime=@addtime"); } 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_copyroom>(pageSqlStr, model)?.ToList(); total = conn.ExecuteScalar <int>(CountSql, model); } return(list); }
/// <summary> /// 文印设计 保存 /// </summary> public JsonResult copyroomSave(tb_copyroom model) { if (model == null) { return(ResultTool.jsonResult(false, "参数错误!")); } if (!String.IsNullOrEmpty(model.id)) { bool boolResult = dcopyroom.Update(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "更新失败!")); } else { model.id = Guid.NewGuid().ToString("N"); bool boolResult = dcopyroom.Add(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "添加失败!")); } }
/// <summary> /// 是否存在该记录 /// </summary> public bool Exists(tb_copyroom model) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(1) from tb_copyroom"); 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_copyroom model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_copyroom("); strSql.Append("buildingid,name,address,phone,isopen,intro,id,addtime)"); strSql.Append(" values ("); strSql.Append("@buildingid,@name,@address,@phone,@isopen,@intro,@id,@addtime)"); using (IDbConnection conn = DapperHelper.OpenConnection()) { int count = conn.Execute(strSql.ToString(), model); if (count > 0) { return(true); } else { return(false); } } }
/// <summary> /// 文印设计 详情 /// </summary> public ActionResult copyroomInfo(tb_copyroom model) { model = dcopyroom.GetInfo(model); return(View(model ?? new tb_copyroom())); }
/// <summary> /// 文印设计 删除 /// </summary> public JsonResult copyroomDelete(tb_copyroom model) { bool boolResult = dcopyroom.Delete(model); return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "删除失败!")); }