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 ApprovalTravelService { /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new ApprovalTravel(), "ApprovalTravel", sql, CommandType.Text, param); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 ApprovalTravel excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List hdList = excuteSql(sql, param); //判断集合是否为空 if (hdList == null || hdList.Count == 0) //返回null return null; //返回单个对象 return hdList[0]; } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public ApprovalTravel GetById(int id) { //调用获取单个对象的方法 return excuteType("select * from ApprovalTravel where Id = @id", new SqlParameter("@id", id)); } /// /// 根据团组编号查询信息 /// /// 返回空或者对象信息 public List GetByDiid(int Diid) { //调用获取单个对象的方法 return excuteSql("select * from ApprovalTravel where Diid =" + Diid + " and Isdel=0 order by Id"); } /// /// 获取全部 /// /// public List GetAll() { return excuteSql("select * from ApprovalTravel where Isdel=0"); } /// /// 增加 /// /// /// public bool AddApprovalTravel(ApprovalTravel hd) { string sql = "insert into ApprovalTravel values(@Diid,@Date,@Time,@Detail,@OPer,@OPdate,@Isdel)"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Diid",hd.Diid), new SqlParameter("@Date",hd.Date), new SqlParameter("@Time",hd.Time), new SqlParameter("@Detail",hd.Detail), new SqlParameter("@OPer",hd.OPer), new SqlParameter("@OPdate",hd.OPdate), new SqlParameter("@Isdel",hd.Isdel) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } public bool AddApprovalTravelReturnID(ApprovalTravel hd, out int id) { string sql = "insert into ApprovalTravel values(@Diid,@Date,@Time,@Detail,@OPer,@OPdate,@Isdel);SELECT @@IDENTITY "; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Diid",hd.Diid), new SqlParameter("@Date",hd.Date), new SqlParameter("@Time",hd.Time), new SqlParameter("@Detail",hd.Detail), new SqlParameter("@OPer",hd.OPer), new SqlParameter("@OPdate",hd.OPdate), new SqlParameter("@Isdel",hd.Isdel) }; int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter)); if (obj > 0) { id = obj; return true; } else { id = 0; return false; } } /// /// 编辑 /// /// /// public bool EditApprovalTravel(ApprovalTravel hd) { string sql = "update ApprovalTravel set Diid=@Diid,Date = @Date,Time = @Time,Detail=@Detail,OPer = @OPer,OPdate = @OPdate,Isdel = @Isdel where Id = @Id"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Diid",hd.Diid), new SqlParameter("@Date",hd.Date), new SqlParameter("@Time",hd.Time), new SqlParameter("@Detail",hd.Detail), 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; } /// /// 删除 /// s /// public bool DelApprovalTravel(int id) { if (SqlHelper.ExecuteNonQuery("delete ApprovalTravel where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0) return true; return false; } /// /// 删除范围 /// /// /// /// /// public bool DelOld(int Diid, int start, int end) { if (SqlHelper.ExecuteNonQuery("delete from ApprovalTravel where Diid=" + Diid + " and ( Id>=" + start + " and Id<=" + end + ")", CommandType.Text) > 0) return true; return false; } /// /// 20210901 /// 根据团号diid 执行更新ISDEL=1的删除操作 /// /// /// public bool DelByDiid(int diid) { if (SqlHelper.ExecuteNonQuery("update ApprovalTravel set Isdel=1 where Diid=" + diid, CommandType.Text) > 0) return true; return false; } } }