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 sqshDal { public List GetAllTreeList() { using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query("select * from sqsh", new { @zt = 1 }).ToList(); } } public List GetAllList() { using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query("select * from sqsh where zt=1 ").ToList(); } } public List GetListByKey(string type,string sqid) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = "select * from sqsh where type=@type and sqid =@sqid"; return conn.Query(sql, new { type = type, sqid = sqid }).ToList(); } } public sqshModel GetmodelByName(string name) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { List model = conn.Query("select * from sqsh where title=@name", new { name = name }).ToList(); if (model.Any()) { return model[0]; } return null; } } public List GetAllList(string id) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string param = ""; if (id != "") { param = " and id=@id"; } return conn.Query("select * from sqsh where 1=1" + param, new { @id = id }).ToList(); } } public bool Add(sqshModel model) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = @"INSERT INTO [dbo].[sqsh] ([type] ,[sqid] ,[spr] ,[sptime] ,[spnr] ,[zt] ,[spzw]) VALUES (@type ,@sqid ,@spr ,@sptime ,@spnr ,@zt ,@spzw)"; return (conn.Execute(sql, model) != 0 ? true : false); } } public bool Update(sqshModel model) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = @"UPDATE [dbo].[sqsh] SET [type] = @type ,[sqid] = @sqid ,[spr] = @spr ,[sptime] = @sptime ,[spnr] = @spnr ,[zt] = @zt ,[spzw] = @spzw WHERE id=@id"; return (conn.Execute(sql, model) != 0 ? true : false); } } } }