using Models; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; namespace DAL { public class AskDataService { List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new AskData(), "AskData", sql, CommandType.Text, param); } AskData excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List hdList = excuteSql(sql, param); //判断集合是否为空 if (hdList == null || hdList.Count == 0) //返回null return null; //返回单个对象 return hdList[0]; } //增Add public bool Add(AskData Dov) { string sql = "insert into AskData values(@Diid,@DeleName,@Country,@Area,@UnitName,@Field,@TalkCase,@Oper,@OpDate,@Isdel);SELECT @@IDENTITY"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Diid",Dov.Diid), new SqlParameter("@DeleName",Dov.DeleName), new SqlParameter("@Country",Dov.Country), new SqlParameter("@Area",Dov.Area), new SqlParameter("@UnitName",Dov.UnitName), new SqlParameter("@Field",Dov.Field), new SqlParameter("@TalkCase",Dov.TalkCase), new SqlParameter("@Oper",Dov.Oper), new SqlParameter("@OpDate",Dov.OpDate), new SqlParameter("@Isdel",Dov.Isdel) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } //改Update public bool Edit(AskData Dov) { string sql = "update AskData set Diid=@Diid,DeleName=@DeleName,Country=@Country,Area=@Area,UnitName=@UnitName,Field=@Field,TalkCase=@TalkCase,Oper=@Oper,OpDate=@OpDate,Isdel=@Isdel where Id = @Id"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Diid",Dov.Diid), new SqlParameter("@DeleName",Dov.DeleName), new SqlParameter("@Country",Dov.Country), new SqlParameter("@Area",Dov.Area), new SqlParameter("@UnitName",Dov.UnitName), new SqlParameter("@Field",Dov.Field), new SqlParameter("@TalkCase",Dov.TalkCase), new SqlParameter("@Oper",Dov.Oper), new SqlParameter("@OpDate",Dov.OpDate), new SqlParameter("@Isdel",Dov.Isdel), new SqlParameter("@Id",Dov.Id) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } //删 public bool delOA(int id) { if (SqlHelper.ExecuteNonQuery("update AskData set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0) return true; return false; } /// /// 查找所有数据 - 分页 /// /// public List GetAllAskData(int pageIndex, out int sumPage, out int totalRecord, string Country, string Area, string Field) { string sqlwhere = "IsDel = 0 and Country like '%" + Country + "%' and Area like '%" + Area + "%' and Field like '%" + Field + "%'"; return PageBase.excutePageSql(new AskData(), "AskData", "AskData", "*", "id asc", sqlwhere, 15, pageIndex, out sumPage, out totalRecord); } public AskData getById(int id) { return excuteType("select * from AskData where Isdel=0 and Id=@id", new SqlParameter("@id", id)); } /// /// 根据ID集合查询数据 /// 20210831 贾文滔 /// /// /// public List getByIdlist(string id) { return excuteSql("select * from AskData where Isdel=0 and Id in (" + id + ") order by Country", new SqlParameter("@id", id)); } } }