Esempio n. 1
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <tb_module> GetList(tb_module model, ref int total)
        {
            List <tb_module> 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_module ");
            if (!String.IsNullOrEmpty(model.name))
            {
                whereSql.Append(" and name=@name");
            }
            if (!String.IsNullOrEmpty(model.url))
            {
                whereSql.Append(" and url=@url");
            }
            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_module>(pageSqlStr, model)?.ToList();
                total = conn.ExecuteScalar <int>(CountSql, model);
            }
            return(list);
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(tb_module model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder setSql = new StringBuilder();

            strSql.Append("update tb_module set ");
            if (!String.IsNullOrEmpty(model.name))
            {
                setSql.Append("name=@name,");
            }
            if (!String.IsNullOrEmpty(model.url))
            {
                setSql.Append("url=@url,");
            }
            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);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 权限模块 列表
        /// </summary>
        public ActionResult moduleList(tb_module model)
        {
            int count = 0;

            ViewBag.moduleList = dmodule.GetList(model, ref count);
            ViewBag.page       = Utils.ShowPage(count, model.PageSize, model.PageIndex, 5);
            return(View());
        }
Esempio n. 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public tb_module GetInfo(tb_module model)
        {
            StringBuilder strSql = new StringBuilder();

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

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

            strSql.Append("insert into tb_module(");
            strSql.Append("id,name,url)");
            strSql.Append(" values (");
            strSql.Append("@id,@name,@url)");
            using (IDbConnection conn = DapperHelper.OpenConnection())
            {
                int count = conn.Execute(strSql.ToString(), model);
                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 /// 权限模块 详情
 /// </summary>
 public ActionResult moduleInfo(tb_module model)
 {
     model = dmodule.GetInfo(model);
     return(View(model ?? new tb_module()));
 }
Esempio n. 9
0
        /// <summary>
        /// 权限模块 删除
        /// </summary>
        public JsonResult moduleDelete(tb_module model)
        {
            bool boolResult = dmodule.Delete(model);

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