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 AirCompanyServcies { List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new AirCompany(), "AirCompany", sql, CommandType.Text, param); } AirCompany excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List hdList = excuteSql(sql, param); AirCompany air = new AirCompany(); //判断集合是否为空 if (hdList == null || hdList.Count == 0) { //返回null air.CnName = "该航司尚未收录"; return air; } //返回单个对象 return hdList[0]; } public AirCompany getByShortCode(string ShortCode) { return this.excuteType("select * from AirCompany where Isdel=0 and ShortCode=@ShortCode", new SqlParameter("@ShortCode", ShortCode.ToUpper())); } public AirCompany getById(string Id) { return this.excuteType("select * from AirCompany where Isdel=0 and Id=" + Id); } /// /// 查找所有数据 - 分页 /// /// public List GetAll(int pageIndex, out int sumPage, out int totalRecord, string ShortCode) { string sqlwhere = "IsDel = 0 and ShortCode like '%" + ShortCode + "%'"; return PageBase.excutePageSql(new AirCompany(), "AirCompany", "AirCompany", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord); } /// /// 增加 /// /// /// public bool Add(AirCompany hd) { string sql = "insert into AirCompany values(@ShortCode,@CnName,@EnName,@OPer,@OPDate,@Isdel)"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@ShortCode",hd.ShortCode), new SqlParameter("@CnName",hd.CnName), new SqlParameter("@EnName",hd.EnName), 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(AirCompany hd) { string sql = "update AirCompany set ShortCode=@ShortCode,CnName=@CnName,EnName=@EnName," + "OPer=@OPer,OPDate=@OPDate,Isdel=@Isdel where Id = @Id"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@ShortCode",hd.ShortCode), new SqlParameter("@CnName",hd.CnName), new SqlParameter("@EnName",hd.EnName), 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 AirCompany set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0) return true; return false; } } }