예제 #1
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <tb_roomfurniture> GetList(tb_roomfurniture model, ref int total)
        {
            List <tb_roomfurniture> 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_roomfurniture ");
            if (!String.IsNullOrEmpty(model.roomid))
            {
                whereSql.Append(" and roomid=@roomid");
            }
            if (!String.IsNullOrEmpty(model.name))
            {
                whereSql.Append(" and name=@name");
            }
            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_roomfurniture>(pageSqlStr, model)?.ToList();
                total = conn.ExecuteScalar <int>(CountSql, model);
            }
            return(list);
        }
예제 #2
0
        /// <summary>
        /// 家具 列表
        /// </summary>
        public ActionResult roomfurnitureList(tb_roomfurniture model)
        {
            int count = 0;

            ViewBag.roomfurnitureList = droomfurniture.GetList(model, ref count);
            ViewBag.page = Utils.ShowPage(count, model.PageSize, model.PageIndex, 5);
            return(View());
        }
예제 #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public tb_roomfurniture GetInfo(tb_roomfurniture model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from tb_roomfurniture");
            strSql.Append("  where id=@id ");
            using (IDbConnection conn = DapperHelper.OpenConnection())
            {
                model = conn.Query <tb_roomfurniture>(strSql.ToString(), model)?.FirstOrDefault();
            }
            return(model);
        }
예제 #4
0
 /// <summary>
 /// 家具 保存
 /// </summary>
 public JsonResult roomfurnitureSave(tb_roomfurniture model)
 {
     if (model == null)
     {
         return(ResultTool.jsonResult(false, "参数错误!"));
     }
     if (!String.IsNullOrEmpty(model.id))
     {
         bool boolResult = droomfurniture.Update(model);
         return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "更新失败!"));
     }
     else
     {
         model.id = Guid.NewGuid().ToString("N");
         bool boolResult = droomfurniture.Add(model);
         return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "添加失败!"));
     }
 }
예제 #5
0
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(tb_roomfurniture model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select count(1) from tb_roomfurniture");
            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);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(tb_roomfurniture model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tb_roomfurniture(");
            strSql.Append("id,roomid,name,intro,addtime)");
            strSql.Append(" values (");
            strSql.Append("@id,@roomid,@name,@intro,@addtime)");
            using (IDbConnection conn = DapperHelper.OpenConnection())
            {
                int count = conn.Execute(strSql.ToString(), model);
                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(tb_roomfurniture model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder setSql = new StringBuilder();

            strSql.Append("update tb_roomfurniture set ");
            if (!String.IsNullOrEmpty(model.roomid))
            {
                setSql.Append("roomid=@roomid,");
            }
            if (!String.IsNullOrEmpty(model.name))
            {
                setSql.Append("name=@name,");
            }
            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);
                }
            }
        }
예제 #8
0
 /// <summary>
 /// 家具 详情
 /// </summary>
 public ActionResult roomfurnitureInfo(tb_roomfurniture model)
 {
     model = droomfurniture.GetInfo(model);
     return(View(model ?? new tb_roomfurniture()));
 }
예제 #9
0
        /// <summary>
        /// 家具 删除
        /// </summary>
        public JsonResult roomfurnitureDelete(tb_roomfurniture model)
        {
            bool boolResult = droomfurniture.Delete(model);

            return(ResultTool.jsonResult(boolResult, boolResult ? "成功!" : "删除失败!"));
        }