123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Models;
- using System.Data.SqlClient;
- using System.Data;
- namespace DAL
- {
- /// <summary>
- /// 行程内容数据访问类
- /// </summary>
- public class StrokeContentService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<StrokeContent> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<StrokeContent>.excuteSql(new StrokeContent(), "StrokeContent", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- StrokeContent excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<StrokeContent> scList = excuteSql(sql, param);
- //判断集合是否为空
- if (scList == null || scList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return scList[0];
- }
- /// <summary>
- /// 增加 - 批量
- /// </summary>
- /// <returns></returns>
- public bool AddStrokeContent(List<StrokeContent> scList)
- {
- SqlCommand cmd = SqlHelper.createCon().CreateCommand();
- cmd.Connection.Open();
- SqlTransaction trans = cmd.Connection.BeginTransaction();
- try
- {
- foreach (StrokeContent sc in scList)
- {
- cmd.CommandText = "insert into StrokeContent values('" + sc.SId + "','" + sc.Date + "','" + sc.CityRange + "','" + sc.Traffic + "','" + sc.Content + "','" + sc.Point + "')";
- cmd.ExecuteNonQuery();
- }
- trans.Commit();
- cmd.Connection.Close();
- return true;
- }
- catch
- {
- trans.Rollback();
- cmd.Connection.Close();
- return false;
- }
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public StrokeContent GetStrokeContentByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from StrokeContent where Id = @id", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public List<StrokeContent> GetStrokeContentList(int pageIndex, out int sumPage, out int totalRecord, string point, string cityRange)
- {
- string sqlwhere = "cityRange <> '' and Point = '" + point + "' and cityRange like '%" + cityRange + "%'";
- return PageBase<StrokeContent>.excutePageSql(new StrokeContent(), "StrokeContent", "StrokeContent", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public List<StrokeContent> GetStrokeContentBySID(int sid)
- {
- //调用获取单个对象的方法
- return excuteSql("select * from StrokeContent where SId = @SId", new SqlParameter("@SId", sid));
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public List<StrokeContent> GetStrokeContentBySIDAndPoint(int sid,int point)
- {
- //调用获取单个对象的方法
- return excuteSql("select * from StrokeContent where SId = @SId and Point = @Point", new SqlParameter("@SId", sid), new SqlParameter("@Point", point));
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelStrokeContent(int sid)
- {
- if (SqlHelper.ExecuteNonQuery("delete StrokeContent where SId = @SId", CommandType.Text, new SqlParameter("@SId", sid)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// LiuChengYi 2014/5/08
- /// 用作微信平台上根据团组编号查询详细行程
- /// </summary>
- /// <returns></returns>
- public DataTable QueryTrip_weixin(string TourCode)
- {
- SqlParameter[] pars =
- {
- new SqlParameter("@TourCode",TourCode)
- };
- return SqlHelper.TransferProcedure("QueryTrip_weixin", CommandType.StoredProcedure, pars);
- }
- }
- }
|