123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 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
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<Ticket> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<Ticket>.excuteSql(new Ticket(), "Ticket", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- Ticket excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<Ticket> vList = excuteSql(sql, param);
- //判断集合是否为空
- if (vList == null || vList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return vList[0];
- }
- /// <summary>
- /// 增加
- /// </summary>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 获取全部 - 分页
- /// </summary>
- /// <returns></returns>
- public List<Ticket> 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<Ticket>.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;
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <returns></returns>
- 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));
- }
- }
- }
|