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 StrokeContentService { /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new StrokeContent(), "StrokeContent", sql, CommandType.Text, param); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 StrokeContent excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List scList = excuteSql(sql, param); //判断集合是否为空 if (scList == null || scList.Count == 0) //返回null return null; //返回单个对象 return scList[0]; } /// /// 增加 - 批量 /// /// public bool AddStrokeContent(List 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; } } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public StrokeContent GetStrokeContentByID(int id) { //调用获取单个对象的方法 return excuteType("select * from StrokeContent where Id = @id", new SqlParameter("@id", id)); } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public List 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.excutePageSql(new StrokeContent(), "StrokeContent", "StrokeContent", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord); } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public List GetStrokeContentBySID(int sid) { //调用获取单个对象的方法 return excuteSql("select * from StrokeContent where SId = @SId", new SqlParameter("@SId", sid)); } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public List GetStrokeContentBySIDAndPoint(int sid,int point) { //调用获取单个对象的方法 return excuteSql("select * from StrokeContent where SId = @SId and Point = @Point", new SqlParameter("@SId", sid), new SqlParameter("@Point", point)); } /// /// 删除 /// /// /// public bool DelStrokeContent(int sid) { if (SqlHelper.ExecuteNonQuery("delete StrokeContent where SId = @SId", CommandType.Text, new SqlParameter("@SId", sid)) > 0) return true; return false; } /// /// LiuChengYi 2014/5/08 /// 用作微信平台上根据团组编号查询详细行程 /// /// public DataTable QueryTrip_weixin(string TourCode) { SqlParameter[] pars = { new SqlParameter("@TourCode",TourCode) }; return SqlHelper.TransferProcedure("QueryTrip_weixin", CommandType.StoredProcedure, pars); } } }