using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; namespace DAL { /// /// 报价基础信息数据访问类 /// public class OfferDataService { /// /// 查询所有—分页 /// /// /// /// /// public DataTable GetAll(int pageIndex, out int sumPage, out int totalRecord,int Cid,int pageSize) { SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@pageIndex", pageIndex), new SqlParameter("@pageSize", pageSize), new SqlParameter("@Cid",Cid) }; //查询总条数 totalRecord = Convert.ToInt32(SqlHelper.ExecuteScalar("select count(1) from dbo.OfferData T left join setData S on T.Pid=S.id where T.IsDel <> 1 and S.IsDel <> 1 and Cid="+Cid, CommandType.Text, null)); //计算出总页数 sumPage = totalRecord%10==0?totalRecord/10:totalRecord/10+1; return SqlHelper.TransferProcedure("[exec_OfferData_Query]", CommandType.StoredProcedure, parameter); } public bool AddOfferData(OfferData od) { string sql = "insert into OfferData values(@PId,@Cid,@PublishedPrice,@BasePrice,@AddedTax,@IsDel)"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@PId",od.PId), new SqlParameter("@Cid",od.Cid), new SqlParameter("@PublishedPrice",od.PublishedPrice), new SqlParameter("@BasePrice",od.BasePrice), new SqlParameter("@AddedTax",od.AddedTax), new SqlParameter("@IsDel",od.IsDel) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter)>0) return true; return false; } /// /// 删除 /// /// /// public bool DelOfferData(int id) { if (SqlHelper.ExecuteNonQuery("update OfferData set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0) return true; return false; } /// /// 根据编号查询信息 /// /// /// public List GetOfferDataByID(int id) { //调用获取单个对象的方法 return excuteSql("select T.*,S.Name from OfferData T left join setData S on T.Pid=S.id where T.Id = @id and T.IsDel = 0", new SqlParameter("@id", id)); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 OfferData excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List setDataList = excuteSql(sql, param); //判断集合是否为空 if (setDataList == null || setDataList.Count == 0) //返回null return null; //返回单个对象 return setDataList[0]; } /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new OfferData(), "OfferData", sql, CommandType.Text, param); } /// /// 修改 /// /// /// public bool EditSetData(OfferData od) { string sql = "update OfferData set PublishedPrice = @PublishedPrice ,BasePrice = @BasePrice,AddedTax=@AddedTax where id=@id"; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@PublishedPrice",od.PublishedPrice), new SqlParameter("@BasePrice",od.BasePrice), new SqlParameter("@AddedTax",od.AddedTax), new SqlParameter("@id",od.Id) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter)>0) return true; return false; } } }