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 CarDataService
{
///
/// 查询所有
///
/// sql语句
/// 可变参数数组
/// 返回集合
List excuteSql(string sql, params SqlParameter[] param)
{
return ServiceBase.excuteSql(new CarData(), "CarData", sql, CommandType.Text, param);
}
///
/// 获取单个对象
///
/// sql语句
/// 可变参数数组
/// 返回空或者单个对象
CarData excuteType(string sql, params SqlParameter[] param)
{
//查询结果放入对象集合
List ctggdList = excuteSql(sql, param);
//判断集合是否为空
if (ctggdList == null || ctggdList.Count == 0)
//返回null
return null;
//返回单个对象
return ctggdList[0];
}
///
/// 根据编号查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public CarData GetCarDataByID(int id)
{
//调用获取单个对象的方法
return excuteType("select * from CarData where Id = @id and IsDel = 0", new SqlParameter("@id", id));
}
///
/// 获取全部
///
///
public List GetAll()
{
return excuteSql("select * from CarData where IsDel = 0 order by id");
}
///
/// 查询信息
///
/// 返回空或者单个对象信息
public List GetCarDataUnitArea(string unitArea)
{
//调用获取单个对象的方法
return excuteSql("select * from CarData where UnitArea like '%" + unitArea + "%'");
}
///
/// 查询对象信息
///
/// 所在城市
/// 酒店名称
/// 返回空或者单个对象信息
public CarData GetCarData(string unitArea, string unitName)
{
//调用获取单个对象的方法
return excuteType("select * from CarData where UnitArea = @UnitArea and UnitName = @UnitName and IsDel = 0", new SqlParameter("@UnitArea", unitArea), new SqlParameter("@UnitName", unitName));
}
///
/// 查询对象信息
///
/// 所在城市
/// 酒店名称
/// 返回空或者单个对象信息
public CarData GetCarDataByUnitNameAndTel(string unitName, string tel)
{
//调用获取单个对象的方法
return excuteType("select * from CarData where UnitName = @UnitName and Tel = @Tel and IsDel = 0", new SqlParameter("@UnitName", unitName), new SqlParameter("@Tel", tel));
}
///
/// 获取全部 - 分页
///
///
public List GetCarData(int pageIndex, out int sumPage, out int totalRecord, string unitArea, string unitName, string contact, string tel)
{
string sqlwhere = "IsDel = 0 and UnitArea like '%" + unitArea + "%' and UnitName like '%" + unitName + "%' and Contact like '%" + contact + "%' and Tel like '%" + tel + "%'";
return PageBase.excutePageSql(new CarData(), "CarData", "CarData", "*", "id desc", sqlwhere, 20, pageIndex, out sumPage, out totalRecord);
}
///
/// 增加
///
///
///
public bool AddCarData(CarData ctggd)
{
string sql = "insert into CarData values(@UnitArea,@UnitName,@Address,@Contact,@Tel,@Email,@Fax,@CarDes,@CarAge,"
+ "@CarPicName,@CarPicPath,@OtherInformation,@CompanyOrGuide,@Score,@QualificationScore,@CarAgeScore,@CleanImgScore,"
+ "@SmellScore,@WaterPaperScore,@HardwareScore,@TimeScore,@SafetyScore,@DrivingAgeScore,@Operator,@OperatorDate,@IsDel)";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@UnitArea",ctggd.UnitArea),
new SqlParameter("@UnitName",ctggd.UnitName),
new SqlParameter("@Address",ctggd.Address),
new SqlParameter("@Contact",ctggd.Contact),
new SqlParameter("@Tel",ctggd.Tel),
new SqlParameter("@Email",ctggd.Email),
new SqlParameter("@Fax",ctggd.Fax),
new SqlParameter("@CarDes",ctggd.CarDes),
new SqlParameter("@CarAge",ctggd.CarAge),
new SqlParameter("@CarPicName",ctggd.CarPicName),
new SqlParameter("@CarPicPath",ctggd.CarPicPath),
new SqlParameter("@OtherInformation",ctggd.OtherInformation),
new SqlParameter("@CompanyOrGuide",ctggd.CompanyOrGuide),
new SqlParameter("@Score",ctggd.Score),
new SqlParameter("@QualificationScore",ctggd.QualificationScore),
new SqlParameter("@CarAgeScore",ctggd.CarAgeScore),
new SqlParameter("@CleanImgScore",ctggd.CleanImgScore),
new SqlParameter("@SmellScore",ctggd.SmellScore),
new SqlParameter("@WaterPaperScore",ctggd.WaterPaperScore),
new SqlParameter("@HardwareScore",ctggd.HardwareScore),
new SqlParameter("@TimeScore",ctggd.TimeScore),
new SqlParameter("@SafetyScore",ctggd.SafetyScore),
new SqlParameter("@DrivingAgeScore",ctggd.DrivingAgeScore),
new SqlParameter("@Operator",ctggd.Score),
new SqlParameter("@OperatorDate",ctggd.OperatorsDate),
new SqlParameter("@IsDel",ctggd.IsDel)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
///
/// 增加 返回id
///
///
///
public bool AddCarDataReturnId(CarData ctggd, out int id)
{
string sql = "insert into CarData values(@UnitArea,@UnitName,@Address,@Contact,@Tel,@Email,@Fax,@CarDes,@CarAge,"
+ "@CarPicName,@CarPicPath,@OtherInformation,@CompanyOrGuide,@Score,@QualificationScore,@CarAgeScore,@CleanImgScore,"
+ "@SmellScore,@WaterPaperScore,@HardwareScore,@TimeScore,@SafetyScore,@DrivingAgeScore,@Operator,@OperatorDate,@IsDel);SELECT @@IDENTITY";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@UnitArea",ctggd.UnitArea),
new SqlParameter("@UnitName",ctggd.UnitName),
new SqlParameter("@Address",ctggd.Address),
new SqlParameter("@Contact",ctggd.Contact),
new SqlParameter("@Tel",ctggd.Tel),
new SqlParameter("@Email",ctggd.Email),
new SqlParameter("@Fax",ctggd.Fax),
new SqlParameter("@CarDes",ctggd.CarDes),
new SqlParameter("@CarAge",ctggd.CarAge),
new SqlParameter("@CarPicName",ctggd.CarPicName),
new SqlParameter("@CarPicPath",ctggd.CarPicPath),
new SqlParameter("@OtherInformation",ctggd.OtherInformation),
new SqlParameter("@CompanyOrGuide",ctggd.CompanyOrGuide),
new SqlParameter("@Score",ctggd.Score),
new SqlParameter("@QualificationScore",ctggd.QualificationScore),
new SqlParameter("@CarAgeScore",ctggd.CarAgeScore),
new SqlParameter("@CleanImgScore",ctggd.CleanImgScore),
new SqlParameter("@SmellScore",ctggd.SmellScore),
new SqlParameter("@WaterPaperScore",ctggd.WaterPaperScore),
new SqlParameter("@HardwareScore",ctggd.HardwareScore),
new SqlParameter("@TimeScore",ctggd.TimeScore),
new SqlParameter("@SafetyScore",ctggd.SafetyScore),
new SqlParameter("@DrivingAgeScore",ctggd.DrivingAgeScore),
new SqlParameter("@Operator",ctggd.Operators),
new SqlParameter("@OperatorDate",ctggd.OperatorsDate),
new SqlParameter("@IsDel",ctggd.IsDel)
};
int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter));
if (obj > 0)
{
id = obj;
return true;
}
else
{
id = 0;
return false;
}
//if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
// return true;
//return false;
}
///
/// 编辑
///
///
///
public bool EditCarData(CarData ctggd)
{
string sql = "update CarData set UnitArea = @UnitArea,UnitName = @UnitName,Address = @Address,Contact = @Contact,Tel = @Tel,Email = @Email,Fax = @Fax,CarDes=@CarDes,CarAge=@CarAge,"
+ "CarPicName=@CarPicName,CarPicPath=@CarPicPath,OtherInformation = @OtherInformation,CompanyOrGuide = @CompanyOrGuide,Score = @Score,QualificationScore=@QualificationScore,CarAgeScore=@CarAgeScore,"
+ "CleanImgScore=@CleanImgScore,SmellScore=@SmellScore,WaterPaperScore=@WaterPaperScore,HardwareScore=@HardwareScore,TimeScore=@TimeScore,SafetyScore=@SafetyScore,DrivingAgeScore=@DrivingAgeScore,Operator = @Operator,OperatorDate = @OperatorDate where Id = @Id";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@UnitArea",ctggd.UnitArea),
new SqlParameter("@UnitName",ctggd.UnitName),
new SqlParameter("@Address",ctggd.Address),
new SqlParameter("@Contact",ctggd.Contact),
new SqlParameter("@Tel",ctggd.Tel),
new SqlParameter("@Email",ctggd.Email),
new SqlParameter("@Fax",ctggd.Fax),
new SqlParameter("@CarDes",ctggd.CarDes),
new SqlParameter("@CarAge",ctggd.CarAge),
new SqlParameter("@CarPicName",ctggd.CarPicName),
new SqlParameter("@CarPicPath",ctggd.CarPicPath),
new SqlParameter("@OtherInformation",ctggd.OtherInformation),
new SqlParameter("@CompanyOrGuide",ctggd.CompanyOrGuide),
new SqlParameter("@Score",ctggd.Score),
new SqlParameter("@QualificationScore",ctggd.QualificationScore),
new SqlParameter("@CarAgeScore",ctggd.CarAgeScore),
new SqlParameter("@CleanImgScore",ctggd.CleanImgScore),
new SqlParameter("@SmellScore",ctggd.SmellScore),
new SqlParameter("@WaterPaperScore",ctggd.WaterPaperScore),
new SqlParameter("@HardwareScore",ctggd.HardwareScore),
new SqlParameter("@TimeScore",ctggd.TimeScore),
new SqlParameter("@SafetyScore",ctggd.SafetyScore),
new SqlParameter("@DrivingAgeScore",ctggd.DrivingAgeScore),
new SqlParameter("@Operator",ctggd.Operators),
new SqlParameter("@OperatorDate",ctggd.OperatorsDate),
new SqlParameter("@Id",ctggd.Id)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
///
/// 删除
///
///
///
public bool DelCarData(int id)
{
if (SqlHelper.ExecuteNonQuery("update CarData set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
return true;
return false;
}
}
}