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 ThreeCodeServices { List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new ThreeCode(), "ThreeCode", sql, CommandType.Text, param); } ThreeCode excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List hdList = excuteSql(sql, param); //判断集合是否为空 if (hdList == null || hdList.Count == 0) //返回null return null; //返回单个对象 return hdList[0]; } public ThreeCode getByThree(string three) { return this.excuteType("select * from ThreeCode where Isdel=0 and Three=@Three", new SqlParameter("@Three", three.ToUpper())); } //public ThreeCode getByCountry(string country) //{ // return this.excuteType("select * from ThreeCode where Isdel=0 and country='"+country+"'"); //} public List getByCountry(string country) { return this.excuteSql("select * from ThreeCode where Isdel=0 and country='" + country + "'"); } public List getByCity(string city) { return this.excuteSql("select * from ThreeCode where Isdel=0 and City='" + city + "'"); } public ThreeCode getById(string Id) { return this.excuteType("select * from ThreeCode where Isdel=0 and Id=" + Id); } /// /// 查找所有数据 - 分页 /// /// public List GetAll(int pageIndex, out int sumPage, out int totalRecord, string Three,string City) { string sqlwhere = "IsDel = 0 and Three like '%" + Three + "%'"+ "and City like '%" + City + "%'"; return PageBase.excutePageSql(new ThreeCode(), "ThreeCode", "ThreeCode", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord); } /// /// 查找所有数据 - 国家 /// /// public List GetAllCountry() { return excuteSql("select * from ThreeCode where IsDel = 0"); } /// /// 增加 /// /// /// public bool Add(ThreeCode hd) { string sql = "insert into ThreeCode values(@Three,@Four,@Country,@City,@AirPort,@AirPort_En,@OPer,@OPDate,@Isdel)"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Three",hd.Three), new SqlParameter("@Four",hd.Four), new SqlParameter("@Country",hd.Country), new SqlParameter("@City",hd.City), new SqlParameter("@AirPort",hd.AirPort), new SqlParameter("@AirPort_En",hd.AirPort_En), new SqlParameter("@OPer",hd.OPer), new SqlParameter("@OPDate",hd.OPDate), new SqlParameter("@Isdel",hd.Isdel) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 编辑 /// /// /// public bool Edit(ThreeCode hd) { string sql = "update ThreeCode set Three=@Three,Four=@Four,Country=@Country,City=@City,AirPort=@AirPort," + "AirPort_En=@AirPort_En,OPer=@OPer,OPDate=@OPDate,Isdel=@Isdel where Id = @Id"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Three",hd.Three), new SqlParameter("@Four",hd.Four), new SqlParameter("@Country",hd.Country), new SqlParameter("@City",hd.City), new SqlParameter("@AirPort",hd.AirPort), new SqlParameter("@AirPort_En",hd.AirPort_En), new SqlParameter("@OPer",hd.OPer), new SqlParameter("@OPDate",hd.OPDate), new SqlParameter("@Isdel",hd.Isdel), new SqlParameter("@Id",hd.Id) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 删除 /// /// /// public bool Del(int id) { if (SqlHelper.ExecuteNonQuery("update ThreeCode set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0) return true; return false; } } }