using Dapper; using dccdc.Models; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace dccdc.DAL { public class xmjfsysqmxDal { public List GetAllList(string id) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = "select * from xmjfsysqmx where 1=1"; if (!string.IsNullOrEmpty(id)) { sql += " and id=@id"; } return conn.Query(sql, new { @id = id }).ToList(); } } public List GetAllList(string id, string zt) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = "select * from xmjfsysqmx where 1=1"; if (!string.IsNullOrEmpty(id)) { sql += " and id=@id"; } if (!string.IsNullOrEmpty(zt)) { sql += " and zt=@zt"; } return conn.Query(sql, new { @id = id, @zt = zt }).ToList(); } } public List GetListByParent(string parentid) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = "select * from xmjfsysqmx where 1=1 and sqdid=@parentid"; return conn.Query(sql, new { parentid = parentid }).ToList(); } } public object save(xmjfsysqmxModel model) { string sql = ""; if (model.id == 0) { sql = @"INSERT INTO [dbo].[xmjfsysqmx] ([sqdid] ,[jfid] ,[jfmc] ,[sl] ,[dj] ,[czsj]) VALUES (@sqdid ,@jfid ,@jfmc ,@sl ,@dj ,@czsj)"; } else { sql = @"UPDATE [dbo].[xmjfsysqmx] SET [sqdid] = @sqdid ,[jfid] = @jfid ,[jfmc] = @jfmc ,[sl] = @sl ,[dj] = @dj ,[czsj] = @czsj WHERE id=@id"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int result = conn.Execute(sql, model); if (result > 0) return new { State = 1, Message = "保存成功!" }; else return new { State = 0, Message = "保存失败!" }; } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } public object delete(string id) { string sql = "delete from xmjfsysqmx where id=@id"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int result = conn.Execute(sql, new { id = id }); if (result > 0) return new { State = 1, Message = "操作成功!" }; else return new { State = 0, Message = "操作失败!" }; } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } public int getCount(string key) { string sql = "select count(1) from dbo.xmjfsysqmx where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and jfmc like @key"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { key = "%" + key + "%" }); } } public List getPage(int page, int pagesize, string key) { string sql = "select *,row_number() over(order by id) as rownum from xmjfsysqmx where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and jfmc like @key"; } sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { key = "%" + key + "%" }).ToList(); } } } }