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 AirTicketReservationsService
{
///
/// 查询所有
///
/// sql语句
/// 可变参数数组
/// 返回集合
List excuteSql(string sql, params SqlParameter[] param)
{
return ServiceBase.excuteSql(new AirTicketReservations(), "AirTicketReservations", sql, CommandType.Text, param);
}
///
/// 获取单个对象
///
/// sql语句
/// 可变参数数组
/// 返回空或者单个对象
AirTicketReservations excuteType(string sql, params SqlParameter[] param)
{
//查询结果放入对象集合
List ctggdList = excuteSql(sql, param);
//判断集合是否为空
if (ctggdList == null || ctggdList.Count == 0)
//返回null
return null;
//返回单个对象
return ctggdList[0];
}
///
/// 根据Id查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public AirTicketReservations GetAirTicketReservationsByID(int id)
{
//调用获取单个对象的方法
return excuteType("select * from AirTicketReservations where id = @id and IsDel = 0", new SqlParameter("@id", id));
}
///
/// 根据Diid查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public List GetAirTicketReservationsByDIID(int DIID)
{
//调用获取单个对象的方法
return excuteSql("select * from AirTicketReservations where Diid = @id and IsDel = 0 order by FlightsDate", new SqlParameter("@id", DIID));
}
///
/// 根据Diid查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public List GetAirTicketReservationsByDIIDAndUId(int DIID,int UId)
{
//调用获取单个对象的方法
return excuteSql("select * from AirTicketReservations where Diid = @id and IsDel = 0 and Operator=" + UId + " order by FlightsDate", new SqlParameter("@id", DIID));
}
///
/// 根据Diid,Ctype查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public List GetAirTicketReservationsByDIID(int DIID, int CType)
{
//调用获取单个对象的方法
return excuteSql("select * from AirTicketReservations where Diid =" + DIID + " and IsDel = 0 and CType=" + CType + " order by FlightsDate");
}
///
/// 获取全部
///
///
public List GetAll()
{
return excuteSql("select * from AirTicketReservations where IsDel = 0");
}
///
/// 获取全部 - 分页
///
///
public List GetAirTicketReservations(int pageIndex, out int sumPage, out int totalRecord, string tourCode, string arrayUsersId)
{
string sqlwhere = "IsDel = 0 and DIId = '" + tourCode + "' and Operator in (" + arrayUsersId + ")";
return PageBase.excutePageSql(new AirTicketReservations(), "AirTicketReservations", "AirTicketReservations", "*", "FlightsDate asc ,flightsTime asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
}
///
/// 增加
///
///
public bool AddAirTicketReservations(AirTicketReservations atr, out int id)
{
string sql = "insert into AirTicketReservations values(@DIId,@FlightsCode,@FlightsDate,@FlightsTime,@ArrivedTime,@IsCheckIn,@IsSetSeat,@IsPackage,@IsBagHandle,@IsTrain,@CType,"
+ "@FlightsCity,@LeaveDescription,@FlightsDescription,@ReturnDescription,@ClientNum,@ClientName,@PrePrice,@PreCurrency,@Price,@Currency,@PriceDescription,@TicketNumber,@TicketCode,@Remark,"
+ "@Operator,@OperatorDate,@IsDel,@PassengerType);SELECT @@IDENTITY";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@DIId",atr.DIId),
new SqlParameter("@FlightsCode",atr.FlightsCode),
new SqlParameter("@FlightsDate",atr.FlightsDate),
new SqlParameter("@FlightsTime",atr.FlightsTime),
new SqlParameter("@ArrivedTime",atr.ArrivedTime),
new SqlParameter("@IsCheckIn",atr.IsCheckIn),
new SqlParameter("@IsSetSeat",atr.IsSetSeat),
new SqlParameter("@IsPackage",atr.IsPackage),
new SqlParameter("@IsBagHandle",atr.IsBagHandle),
new SqlParameter("@IsTrain",atr.IsTrain),
new SqlParameter("@CType",atr.CType),
new SqlParameter("@FlightsCity",atr.FlightsCity),
new SqlParameter("@LeaveDescription",atr.LeaveDescription),
new SqlParameter("@FlightsDescription",atr.FlightsDescription),
new SqlParameter("@ReturnDescription",atr.ReturnDescription),
new SqlParameter("@ClientNum",atr.ClientNum),
new SqlParameter("@ClientName",atr.ClientName),
new SqlParameter("@PrePrice",atr.PrePrice),
new SqlParameter("@PreCurrency",atr.PreCurrency),
new SqlParameter("@Price",atr.Price),
new SqlParameter("@Currency",atr.Currency),
new SqlParameter("@PriceDescription",atr.PriceDescription),
new SqlParameter("@TicketNumber",atr.TicketNumber),
new SqlParameter("@TicketCode",atr.TicketCode),
new SqlParameter("@Remark",atr.Remark),
new SqlParameter("@Operator",atr.Operators),
new SqlParameter("@OperatorDate",atr.OperatorsDate),
new SqlParameter("@IsDel",atr.IsDel),
new SqlParameter("@PassengerType",atr.PassengerType)
};
int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter));
if (obj > 0)
{
id = obj;
return true;
}
id = 0;
return false;
}
///
/// 编辑
///
///
public bool EditAirTicketReservations(AirTicketReservations atr)
{
string sql = "update AirTicketReservations set DIId = @DIId,FlightsCode = @FlightsCode,FlightsDate = @FlightsDate,FlightsTime = @FlightsTime,"
+ "ArrivedTime=@ArrivedTime,IsCheckIn=@IsCheckIn,IsSetSeat=@IsSetSeat,IsPackage=@IsPackage,IsBagHandle=@IsBagHandle,IsTrain=@IsTrain,CType=@CType,FlightsCity = @FlightsCity,LeaveDescription = @LeaveDescription,"
+ "FlightsDescription = @FlightsDescription,ReturnDescription = @ReturnDescription,ClientNum=@ClientNum,ClientName = @ClientName,"
+ "PrePrice = @PrePrice,PreCurrency = @PreCurrency,Price = @Price,Currency = @Currency,PriceDescription = @PriceDescription,TicketNumber=@TicketNumber,"
+ "TicketCode=@TicketCode,Remark = @Remark,Operator = @Operator,OperatorDate = @OperatorDate,PassengerType=@PassengerType where Id = @Id";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@DIId",atr.DIId),
new SqlParameter("@FlightsCode",atr.FlightsCode),
new SqlParameter("@FlightsDate",atr.FlightsDate),
new SqlParameter("@FlightsTime",atr.FlightsTime),
new SqlParameter("@ArrivedTime",atr.ArrivedTime),
new SqlParameter("@IsCheckIn",atr.IsCheckIn),
new SqlParameter("@IsSetSeat",atr.IsSetSeat),
new SqlParameter("@IsPackage",atr.IsPackage),
new SqlParameter("@IsBagHandle",atr.IsBagHandle),
new SqlParameter("@IsTrain",atr.IsTrain),
new SqlParameter("@CType",atr.CType),
new SqlParameter("@FlightsCity",atr.FlightsCity),
new SqlParameter("@LeaveDescription",atr.LeaveDescription),
new SqlParameter("@FlightsDescription",atr.FlightsDescription),
new SqlParameter("@ReturnDescription",atr.ReturnDescription),
new SqlParameter("@ClientNum",atr.ClientNum),
new SqlParameter("@ClientName",atr.ClientName),
new SqlParameter("@PrePrice",atr.PrePrice),
new SqlParameter("@PreCurrency",atr.PreCurrency),
new SqlParameter("@Price",atr.Price),
new SqlParameter("@Currency",atr.Currency),
new SqlParameter("@PriceDescription",atr.PriceDescription),
new SqlParameter("@TicketNumber",atr.TicketNumber),
new SqlParameter("@TicketCode",atr.TicketCode),
new SqlParameter("@Remark",atr.Remark),
new SqlParameter("@Operator",atr.Operators),
new SqlParameter("@OperatorDate",atr.OperatorsDate),
new SqlParameter("@Id",atr.Id),
new SqlParameter("@PassengerType",atr.PassengerType)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
///
/// 删除
///
///
///
public bool DelAirTicketReservations(int id)
{
if (SqlHelper.ExecuteNonQuery("update AirTicketReservations set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
return true;
return false;
}
public List GetByIds(List ids)
{
var idsStr = string.Join(",",ids).TrimEnd(',') ;
string sql = "select * from AirTicketReservations where IsDel = 0 And id in(" + idsStr + ")";
return excuteSql(sql);
}
public List GetByDiiDs(List diids)
{
var diidsStr = string.Join(",", diids).TrimEnd(',');
string sql = "select * from AirTicketReservations where IsDel = 0 And diid in(" + diidsStr + ")";
return excuteSql(sql);
}
}
}