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 DayAndCostService { List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new DayAndCost(), "DayAndCost", sql, CommandType.Text, param); } DayAndCost excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List hdList = excuteSql(sql, param); //判断集合是否为空 if (hdList == null || hdList.Count == 0) //返回null return null; //返回单个对象 return hdList[0]; } //增Add public bool Add(DayAndCost Dov) { string sql = "insert into DayAndCost values(@Diid,@Type,@Days,@Place,@Cost,@Currency,@SubTotal,@OPer,@OPDate,@Isdel);SELECT @@IDENTITY"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Diid",Dov.Diid), new SqlParameter("@Type",Dov.Type), new SqlParameter("@Days",Dov.Days), new SqlParameter("@Place",Dov.Place), new SqlParameter("@Cost",Dov.Cost), new SqlParameter("@Currency",Dov.Currency), new SqlParameter("@SubTotal",Dov.SubTotal), new SqlParameter("@OPer",Dov.OPer), new SqlParameter("@OPDate",Dov.OPDate), new SqlParameter("@Isdel",Dov.Isdel) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } //改Update public bool Edit(DayAndCost Dov) { string sql = "update DayAndCost set Diid=@Diid,Type=@Type,Days=@Days,Place=@Place,Cost=@Cost,Currency=@Currency,SubTotal=@SubTotal,OPer=@OPer,OPDate=@OPDate,Isdel=@Isdel where Id = @Id"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Diid",Dov.Diid), new SqlParameter("@Type",Dov.Type), new SqlParameter("@Days",Dov.Days), new SqlParameter("@Place",Dov.Place), new SqlParameter("@Cost",Dov.Cost), new SqlParameter("@Currency",Dov.Currency), new SqlParameter("@SubTotal",Dov.SubTotal), new SqlParameter("@OPer",Dov.OPer), new SqlParameter("@OPDate",Dov.OPDate), new SqlParameter("@Isdel",Dov.Isdel), new SqlParameter("@Id",Dov.Id) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } //删 public bool delOA(int id) { if (SqlHelper.ExecuteNonQuery("update DayAndCost set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0) return true; return false; } /// /// 清空 /// /// /// public bool Clean(int id) { string sql = "update DayAndCost set Place ='"+ "',Cost ='0.00',Currency='" + "',SubTotal='0.00' where Id = @Id"; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, new SqlParameter("@Id", id)) > 0) return true; return false; } public DayAndCost GetById(string id) { return excuteType("select * from DayAndCost where Isdel=0 and Id =" + id); } public List Get(string Diid, int type) { return excuteSql("select * from DayAndCost where Isdel=0 and Diid =" + Diid + " and Type=" + type + " order by Days"); } public bool DelAllDataByDiid(string diid) { string sql = "update DayAndCost set isdel = 1 where isdel = 0 and diid = '" + diid + "' "; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text) > 0) return true; return false; } } }