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 sqyssyDal { public List GetAllTreeList() { using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query("select * from sqyssy", new { @zt = 1 }).ToList(); } } public List GetAllList() { using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query("select * from sqyssy where zt=1 ").ToList(); } } public List GetListByKey(string type, string sqid) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = "select * from sqyssy where type=@type and sqid =@sqid"; return conn.Query(sql, new { type = type, sqid = sqid }).ToList(); } } public sqyssyModel GetmodelByName(string name) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { List model = conn.Query("select * from sqyssy 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 sqyssy where 1=1" + param, new { @id = id }).ToList(); } } public bool Add(sqyssyModel model) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = @"INSERT INTO [dbo].[sqyssy] ([type] ,[ysmxid] ,[je] ,[bxdid] ,[czsj] ,[czyid] ,[czyname]) VALUES (@type ,@ysmxid ,@je ,@bxdid ,@czsj ,@czyid ,@czyname)"; return (conn.Execute(sql, model) != 0 ? true : false); } } public object AddList(List models) { string sql = @"INSERT INTO [dbo].[sqyssy] ([type] ,[ysmxid] ,[je] ,[bxdid] ,[czsj] ,[czyid] ,[czyname]) VALUES (@type ,@ysmxid ,@je ,@bxdid ,@czsj ,@czyid ,@czyname)"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { conn.Execute(sql, models); return new { State = 1, Message = "操作成功" }; } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } public bool Update(sqyssyModel model) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = @"UPDATE [dbo].[sqyssy] SET [type] = @type ,[ysmxid] = @ysmxid ,[je] = @je ,[bxdid] = @bxdid ,[czsj] = @czsj ,[czyid] = @czyid ,[czyname] = @czyname WHERE id=@id"; return (conn.Execute(sql, model) != 0 ? true : false); } } } }