using System; using System.Collections.Generic; using System.Linq; using System.Text; using Models; using System.Data.SqlClient; using System.Data; namespace DAL { public class TicketService { /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new Ticket(), "Ticket", sql, CommandType.Text, param); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 Ticket excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List vList = excuteSql(sql, param); //判断集合是否为空 if (vList == null || vList.Count == 0) //返回null return null; //返回单个对象 return vList[0]; } /// /// 增加 /// /// public bool AddTicketInfo(Ticket r) { string sql = "insert into Ticket values(@Country,@Area,@ScenicSpot,@Address,@Contact,@Price,@Currency,@Star,@StartDate,@Remark,@IsDel)"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Country",r.Country), new SqlParameter("@Area",r.Area), new SqlParameter("@ScenicSpot",r.ScenicSpot), new SqlParameter("@Address",r.Address), new SqlParameter("@Contact",r.Contact), new SqlParameter("@Price",r.Price), new SqlParameter("@Currency",r.Currency), new SqlParameter("@Star",r.Star), new SqlParameter("@StartDate",r.StartDate), new SqlParameter("@Remark",r.Remark), new SqlParameter("@IsDel",r.IsDel) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 获取全部 - 分页 /// /// public List GetTicketInfo(int pageIndex, out int sumPage, out int totalRecord, string txtWhere) { string sqlwhere = null; if (txtWhere == null || txtWhere == "") { sqlwhere = " IsDel = 0"; } else { sqlwhere = " IsDel = 0 or Country like '%" + txtWhere + "%' or Area like '%" + txtWhere + "%' or ScenicSpot like '%" + txtWhere + "%'"; } return PageBase.excutePageSql(new Ticket(), "Ticket", "Ticket", "*", "Star desc", sqlwhere, 20, pageIndex, out sumPage, out totalRecord); } public bool Del(int id) { if (SqlHelper.ExecuteNonQuery("update Ticket set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) >0) return true; return false; } /// /// 编辑 /// /// public bool EditTicket(Ticket r) { string sql = "update Ticket set Country = @Country,Area = @Area,ScenicSpot = @ScenicSpot,Address = @Address,Contact = @Contact,Price = @Price,Currency = @Currency,Star = @Star,StartDate = @StartDate,Remark = @Remark where Id = @Id"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Country",r.Country), new SqlParameter("@Area",r.Area), new SqlParameter("@ScenicSpot",r.ScenicSpot), new SqlParameter("@Address",r.Address), new SqlParameter("@Contact",r.Contact), new SqlParameter("@Price",r.Price), new SqlParameter("@Currency",r.Currency), new SqlParameter("@Star",r.Star), new SqlParameter("@StartDate",r.StartDate), new SqlParameter("@Remark",r.Remark), new SqlParameter("@Id",r.Id) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } public Ticket GetTicketByID(int id) { //调用获取单个对象的方法 return excuteType("select * from Ticket where Id = @id and isdel=0", new SqlParameter("@id", id)); } } }