123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using Models;
- namespace DAL
- {
- public class CarInfoService
- {
- List<CarInfo> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<CarInfo>.excuteSql(new CarInfo(), "CarInfo", sql, CommandType.Text, param);
- }
- CarInfo excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<CarInfo> hdList = excuteSql(sql, param);
- //判断集合是否为空
- if (hdList == null || hdList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return hdList[0];
- }
- /// <summary>
- /// 根据ID查询
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public CarInfo GetById(string id)
- {
- //调用获取单个对象的方法
- string sql = "select * from CarInfo where Id=@Id";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@Id", id)
- };
- return excuteType(sql, parameter);
- }
- /// <summary>
- /// 获取全部 - 分页
- /// </summary>
- /// <returns></returns>
- public List<CarInfo> 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<CarInfo>.excutePageSql(new CarInfo(), "CarInfo", "CarInfo", "*", "City asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
- }
- /// <summary>
- /// 获取全部 - 分页
- /// </summary>
- /// <returns></returns>
- public List<CarInfo> 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<CarInfo>.excutePageSql(new CarInfo(), "CarInfo", "CarInfo", "*", "City asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
- }
- }
- }
|