123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using Models;
- namespace DAL
- {
- /// <summary>
- /// 车兼导数据访问层
- /// </summary>
- public class CarGuidesServcies
- {
- List<CarGuides> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<CarGuides>.excuteSql(new CarGuides(), "CarGuides", sql, CommandType.Text, param);
- }
- CarGuides excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<CarGuides> hdList = excuteSql(sql, param);
- //判断集合是否为空
- if (hdList == null || hdList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return hdList[0];
- }
- /// <summary>
- /// 增Add
- /// </summary>
- /// <param name="Dov"></param>
- /// <returns></returns>
- public bool Add(CarGuides cg)
- {
- string sql = "insert into AirGoods values(@Country,@City,@ServiceType,@CarType,@Offer,@CGCost,@RuningTime,@OvertimeFee,@CGOvertimeFee,@Currency,@Remark,@Oper,@OpDate,@Isdel);SELECT @@IDENTITY";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@Country",cg.Country),
- new SqlParameter("@City",cg.City),
- new SqlParameter("@ServiceType",cg.ServiceType),
- new SqlParameter("@CarType",cg.CarType),
- new SqlParameter("@Offer",cg.Offer),
- new SqlParameter("@CGCost",cg.CGCost),
- new SqlParameter("@RuningTime",cg.RuningTime),
- new SqlParameter("@OvertimeFee",cg.OvertimeFee),
- new SqlParameter("@CGOvertimeFee",cg.CGOvertimeFee),
- new SqlParameter("@Currency",cg.Currency),
- new SqlParameter("@Remark",cg.Remark),
- new SqlParameter("@Oper",cg.Oper),
- new SqlParameter("@OpDate",cg.OpDate),
- new SqlParameter("@Isdel",cg.Isdel)
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="Dov"></param>
- /// <returns></returns>
- public bool Edit(CarGuides cg)
- {
- string sql = "update CarGuides set Country=@Country,City=@City,ServiceType=@ServiceType,Offer=@Offer,CGCost=@CGCost,RuningTime=@RuningTime,OvertimeFee=@OvertimeFee,"
- + "CGOvertimeFee=@CGOvertimeFee,Currency=@Currency,Remark=@Remark,Oper=@Oper,OpDate=@OpDate,Isdel=@Isdel where Id = @Id";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@Country",cg.Country),
- new SqlParameter("@City",cg.City),
- new SqlParameter("@ServiceType",cg.ServiceType),
- new SqlParameter("@Offer",cg.Offer),
- new SqlParameter("@CGCost",cg.CGCost),
- new SqlParameter("@RuningTime",cg.RuningTime),
- new SqlParameter("@OvertimeFee",cg.OvertimeFee),
- new SqlParameter("@CGOvertimeFee",cg.CGOvertimeFee),
- new SqlParameter("@Currency",cg.Currency),
- new SqlParameter("@Remark",cg.Remark),
- new SqlParameter("@Oper",cg.Oper),
- new SqlParameter("@OpDate",cg.OpDate),
- new SqlParameter("@Isdel",cg.Isdel),
- new SqlParameter("@Id",cg.Id),
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 删
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool delOA(int id)
- {
- if (SqlHelper.ExecuteNonQuery("update CarGuides set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 根据ID查询
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public CarGuides GetById(string id)
- {
- //调用获取单个对象的方法
- string sql = "select * from CarGuides where Id=@Id";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@Id", id)
- };
- return excuteType(sql, parameter);
- }
- /// <summary>
- /// 车兼导 查询
- /// </summary>
- /// <param name="City"> 城市</param>
- /// <param name="ServiceType"> 服务类型</param>
- /// <param name="CarType">车类型</param>
- /// <returns>sql</returns>
- public CarGuides GetByCarTypeAndCarCost(string City,string ServiceType, string CarType)
- {
- //调用获取单个对象的方法
- string sql = "select * from CarGuides where City=@City and ServiceType=@ServiceType and CarType like '%CarType=@carType%'";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@City", City),
- new SqlParameter("@ServiceType", ServiceType),
- new SqlParameter("@CarType", CarType)
- };
- return excuteType(sql, parameter);
- }
- /// <summary>
- /// 获取全部 - 分页
- /// </summary>
- /// <returns></returns>
- public List<CarGuides> GetALL(int pageIndex, out int sumPage, out int totalRecord, string City)
- {
- string sqlwhere = "IsDel = 0";
- if (!string.IsNullOrEmpty(City))
- sqlwhere += " and City like '%" + City + "%'";
- return PageBase<CarGuides>.excutePageSql(new CarGuides(), "CarGuides", "CarGuides", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
- }
- /// <summary>
- /// 获取全部 - 分页
- /// </summary>
- /// <returns></returns>
- public List<CarGuides> GetALL(int pageIndex, out int sumPage, out int totalRecord, string City, string Countrys)
- {
- string sqlwhere = "IsDel = 0";
- if (!string.IsNullOrEmpty(Countrys))
- {
- if (Countrys.Contains("中国"))
- {
- if (Countrys == "中国")
- {
- sqlwhere += " and Country like '%" + City + "%'";
- }
- else
- {
- sqlwhere += " and City like '%" + City + "%'";
- }
- }
- else
- {
- string country1 = "";
- string[] country = new string[] { };
- if (Countrys.Contains(","))
- country = Countrys.Split(',');
- else if (Countrys.Contains("、"))
- country = Countrys.Split('、');
- else if (Countrys.Contains(","))
- country = Countrys.Split(',');
- else if (Countrys.Contains(" "))
- country = Countrys.Split(' ');
- if (country.Length >= 1)
- {
- for (int i = 0; i < country.Length; i++)
- {
- if (i == country.Length - 1)
- country1 += " '" + country[i] + "'";
- else
- country1 += " '" + country[i] + "',";
- }
- sqlwhere += " and Country in (" + country1 + ")";
- }
- else
- sqlwhere += " and Country like '%" + Countrys + "%'";
- }
- }
- else
- {
- sqlwhere += " and City like '%" + City + "%'";
- }
- return PageBase<CarGuides>.excutePageSql(new CarGuides(), "CarGuides", "CarGuides", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
- }
- }
- }
|