123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- 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 StrokeService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<Stroke> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<Stroke>.excuteSql(new Stroke(), "Stroke", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- Stroke excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<Stroke> sList = excuteSql(sql, param);
- //判断集合是否为空
- if (sList == null || sList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return sList[0];
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public Stroke GetStrokeByDIId(int DIId)
- {
- //调用获取单个对象的方法
- return excuteType("select * from Stroke where DIId = @DIId", new SqlParameter("@DIId", DIId));
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public Stroke GetStrokeByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from Stroke where Id = @id and IsDel = 0", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 获取全部 - 分页
- /// </summary>
- /// <returns></returns>
- public List<Stroke> GetStroke(int pageIndex, out int sumPage, out int totalRecord, string tourCode, string arrayUsersId)
- {
- string sqlwhere = "IsDel = 0 and DIId = '" + tourCode + "' and Operator in (" + arrayUsersId + ")";
- return PageBase<Stroke>.excutePageSql(new Stroke(), "Stroke", "Stroke", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
- }
- /// <summary>
- /// 增加
- /// </summary>
- /// <param name="cd"></param>
- /// <returns></returns>
- public bool AddStroke(Stroke s)
- {
- string sql = "insert into Stroke values(@DIId,@StrokeName,@WayCity,@Days,@PNumber,@Remark,@Operator,@OperatorDate,@IsDel)";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@DIId",s.DIId),
- new SqlParameter("@StrokeName",s.StrokeName),
- new SqlParameter("@WayCity",s.WayCity),
- new SqlParameter("@Days",s.Days),
- new SqlParameter("@PNumber",s.PNumber),
- new SqlParameter("@Remark",s.Remark),
- new SqlParameter("@Operator",s.Operators),
- new SqlParameter("@OperatorDate",s.OperatorsDate),
- new SqlParameter("@IsDel",s.IsDel)
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="cd"></param>
- /// <returns></returns>
- public bool EditStroke(Stroke s)
- {
- string sql = "update Stroke set StrokeName=@StrokeName,WayCity = @WayCity,Days = @Days,PNumber = @PNumber,Remark = @Remark,Operator = @Operator,OperatorDate = @OperatorDate where Id = @Id";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@StrokeName",s.StrokeName),
- new SqlParameter("@WayCity",s.WayCity),
- new SqlParameter("@Days",s.Days),
- new SqlParameter("@PNumber",s.PNumber),
- new SqlParameter("@Remark",s.Remark),
- new SqlParameter("@Operator",s.Operators),
- new SqlParameter("@OperatorDate",s.OperatorsDate),
- new SqlParameter("@Id",s.Id)
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelStroke(int id)
- {
- if (SqlHelper.ExecuteNonQuery("update Stroke set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
- return true;
- return false;
- }
- }
- }
|