123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- using Models;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- namespace DAL
- {
- public class TravelListService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<TravelList> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<TravelList>.excuteSql(new TravelList(), "TravelList", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- TravelList excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<TravelList> hdList = excuteSql(sql, param);
- //判断集合是否为空
- if (hdList == null || hdList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return hdList[0];
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public TravelList GetById(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from TravelList where Id = @id", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 根据团组编号查询信息
- /// </summary>
- /// <returns>返回空或者对象信息</returns>
- public List<TravelList> GetByDiid(int Diid)
- {
- //调用获取单个对象的方法
- return excuteSql("select * from TravelList where Diid =" + Diid + " and Isdel=0 order by Id");
- }
- public List<TravelList> GetByDiidandGroup(int Diid,int diffgroup)
- {
- return excuteSql($" select * from TravelList where Diid ={Diid} and diffgroup = {diffgroup} and Isdel=0 order by Id");
- }
- /// <summary>
- /// 获取全部
- /// </summary>
- /// <returns></returns>
- public List<TravelList> GetAll()
- {
- return excuteSql("select * from TravelList where Isdel=0");
- }
- /// <summary>
- /// 增加
- /// </summary>
- /// <param name="cd"></param>
- /// <returns></returns>
- public bool AddTravelList(TravelList hd)
- {
- string sql = "insert into TravelList values(@Diid,@Days,@Date,@WeekDay,@Traffic_First,@Traffic_Second,@Trip,@OPer,@issel,@diffgroup,@OPdate,@Isdel)";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@Diid",hd.Diid),
- new SqlParameter("@Days",hd.Days),
- new SqlParameter("@Date",hd.Date),
- new SqlParameter("@WeekDay",hd.WeekDay),
- new SqlParameter("@Traffic_First",hd.Traffic_First),
- new SqlParameter("@Traffic_Second",hd.Traffic_Second),
- new SqlParameter("@Trip",hd.Trip),
- new SqlParameter("@OPer",hd.OPer),
- new SqlParameter("@OPdate",hd.OPdate),
- new SqlParameter("@issel",hd.issel),
- new SqlParameter("@diffgroup",hd.diffgroup),
- new SqlParameter("@Isdel",hd.Isdel),
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="sdt"></param>
- /// <returns></returns>
- public bool EditTravelList(TravelList hd)
- {
- string sql = "update TravelList set Diid=@Diid,Days = @Days,Date = @Date,WeekDay = @WeekDay,Traffic_First = @Traffic_First,"
- + "Traffic_Second = @Traffic_Second,Trip = @Trip,OPer = @OPer,OPdate = @OPdate,Isdel = @Isdel where Id = @Id";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@Diid",hd.Diid),
- new SqlParameter("@Days",hd.Days),
- new SqlParameter("@Date",hd.Date),
- new SqlParameter("@WeekDay",hd.WeekDay),
- new SqlParameter("@Traffic_First",hd.Traffic_First),
- new SqlParameter("@Traffic_Second",hd.Traffic_Second),
- new SqlParameter("@Trip",hd.Trip),
- new SqlParameter("@OPer",hd.OPer),
- new SqlParameter("@OPdate",hd.OPdate),
- new SqlParameter("@Isdel",hd.Isdel),
- new SqlParameter("@Id",hd.Id)
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 20210818 贾文滔
- /// 根据ID执行delete操作
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelTravelList(int id)
- {
- if (SqlHelper.ExecuteNonQuery("delete TravelList where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 20210818 贾文滔
- /// 根据id执行清空"trip" 字段操作
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool Clean(int id)
- {
- if (SqlHelper.ExecuteNonQuery("update TravelList set Trip='' where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 20210818 贾文滔
- /// 根据团号和ID范围执行delete操作
- /// </summary>
- /// <param name="Diid"></param>
- /// <param name="start"></param>
- /// <param name="end"></param>
- /// <returns></returns>
- public bool DelOld(int Diid, int start, int end)
- {
- if (SqlHelper.ExecuteNonQuery("delete from TravelList where Diid=" + Diid + " and ( Id>=" + start + " and Id<=" + end + ")", CommandType.Text) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 20210818
- /// 根据团号diid 执行更新ISDEL=1的删除操作
- /// </summary>
- /// <param name="diid"></param>
- /// <returns></returns>
- public bool DelByDiid(int diid)
- {
- if (SqlHelper.ExecuteNonQuery("update TravelList set Isdel=1 where Diid=" + diid, CommandType.Text) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 设置一个行程为最终行程
- /// </summary>
- /// <param name="diid"></param>
- /// <param name="diffgroup"></param>
- /// <returns></returns>
- public bool UpdateSelbydiffGroupandDiid(int diid,int diffgroup)
- {
- bool istrue = SqlHelper.ExecuteNonQuery($"update TravelList set issel = 0 where Diid ={diid} and Isdel=0 ", CommandType.Text, null) > 0;
- if (istrue)
- {
- istrue = SqlHelper.ExecuteNonQuery($"update TravelList set issel = 1 where Diid ={diid} and Isdel=0 and diffgroup = {diffgroup}", CommandType.Text, null) > 0;
- }
- return istrue;
- }
- }
- public class tempTData
- {
- /// <summary>
- /// TravelList 表数据的再分组
- /// </summary>
- public int diffgroup { get; set; }
- /// <summary>
- /// 团组id
- /// </summary>
- public int diid { get; set; }
- /// <summary>
- /// 团组名称
- /// </summary>
- public string TeamName { get; set; }
- }
- }
|