using System; using System.Collections.Generic; using System.Linq; using System.Text; using Models; using System.Data.SqlClient; using System.Data; namespace DAL { public class MediaSuppliersService { /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new MediaSuppliers(), "MediaSuppliers", sql, CommandType.Text, param); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 MediaSuppliers excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List cdList = excuteSql(sql, param); //判断集合是否为空 if (cdList == null || cdList.Count == 0) //返回null return null; //返回单个对象 return cdList[0]; } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public MediaSuppliers GetMediaSuppliersByID(int id) { //调用获取单个对象的方法 return excuteType("select * from MediaSuppliers where Id = @id and IsDel = 0", new SqlParameter("@id", id)); } /// /// 查询信息 /// /// 返回空或者单个对象信息 public List GetMediaSuppliersName(string name) { //调用获取单个对象的方法 return excuteSql("select * from MediaSuppliers where Name like '%" + name + "%'"); } /// /// 查询信息 /// /// 返回空或者单个对象信息 public List GetMediaSuppliersByUnitName(string unitName) { //调用获取单个对象的方法 return excuteSql("select * from MediaSuppliers where UnitName = '" + unitName + "'"); } /// /// 查询信息 /// /// 返回空或者单个对象信息 public MediaSuppliers GetMediaSuppliersNameByEntity(string name) { //调用获取单个对象的方法 return excuteType("select * from MediaSuppliers where Name = '" + name + "'"); } /// /// 根据条件查询对象信息 /// /// 客户名称 /// 单位名称 /// 返回空或者单个对象信息 public MediaSuppliers GetMediaSuppliers(string name, string unitName) { //调用获取单个对象的方法 return excuteType("select * from MediaSuppliers where Name = @Name and UnitName = @UnitName and IsDel = 0", new SqlParameter("@Name", name), new SqlParameter("@UnitName", unitName)); } /// /// 根据条件查询对象信息 /// /// 客户名称 /// 单位名称 /// 返回空或者单个对象信息 public MediaSuppliers GetMediaSuppliers(string unitName) { //调用获取单个对象的方法 return excuteType("select * from MediaSuppliers where UnitName = @UnitName", new SqlParameter("@UnitName", unitName)); } /// /// 获取全部 - 分页 /// /// public List GetMediaSuppliers(int pageIndex, out int sumPage, out int totalRecord, string departmentType, string name, string unitName, string tel) { //string sql = "join Users as u on m.Operator = u.Id"; string sqlwhere = "IsDel = 0 and Name like '%" + name + "%' and UnitName like '%" + unitName + "%' and Tel like '%" + tel + "%'"; if (departmentType != "全部") sqlwhere += " and Did = " + departmentType + ""; //string sqly = sql + sqlwhere; return PageBase.excutePageSql(new MediaSuppliers(), "MediaSuppliers", "MediaSuppliers", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord); } /// /// 增加 /// /// /// public bool AddMediaSuppliers(MediaSuppliers cd) { string sql = "insert into MediaSuppliers values(@DId,@Privince,@City,@Name,@Sex,@UnitName,@UnitAbbreviation,@Post,@Tel,@QQ,@Email,@Fax,@Address,@OtherInformation,@Operator,@OperatorDate,@IsDel)"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@DId",cd.Did), new SqlParameter("@Privince",cd.Privince), new SqlParameter("@City",cd.City), new SqlParameter("@Name",cd.Name), new SqlParameter("@Sex",cd.Sex), new SqlParameter("@UnitName",cd.UnitName), new SqlParameter("@UnitAbbreviation",cd.UnitAbbreviation), new SqlParameter("@Post",cd.Post), new SqlParameter("@Tel",cd.Tel), new SqlParameter("@QQ",cd.QQ), new SqlParameter("@Email",cd.Email), new SqlParameter("@Fax",cd.Fax), new SqlParameter("@Address",cd.Address), new SqlParameter("@OtherInformation",cd.OtherInformation), new SqlParameter("@Operator",cd.Operators), new SqlParameter("@OperatorDate",cd.OperatorsDate), new SqlParameter("@IsDel",cd.IsDel) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 编辑 /// /// /// public bool EditMediaSuppliers(MediaSuppliers cd) { string sql = "update MediaSuppliers set DId = @DId,Privince=@Privince,City=@City,Name = @Name,Sex = @Sex,UnitName = @UnitName,UnitAbbreviation = @UnitAbbreviation,Post = @Post,Tel = @Tel,QQ=@QQ,Email = @Email,Fax = @Fax,Address=@Address,OtherInformation = @OtherInformation,Operator = @Operator,OperatorDate = @OperatorDate where Id = @Id"; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@DId",cd.Did), new SqlParameter("@Privince",cd.Privince), new SqlParameter("@City",cd.City), new SqlParameter("@Name",cd.Name), new SqlParameter("@Sex",cd.Sex), new SqlParameter("@UnitName",cd.UnitName), new SqlParameter("@UnitAbbreviation",cd.UnitAbbreviation), new SqlParameter("@Post",cd.Post), new SqlParameter("@Tel",cd.Tel), new SqlParameter("@QQ",cd.QQ), new SqlParameter("@Email",cd.Email), new SqlParameter("@Fax",cd.Fax), new SqlParameter("@Address",cd.Address), new SqlParameter("@OtherInformation",cd.OtherInformation), new SqlParameter("@Operator",cd.Operators), new SqlParameter("@OperatorDate",cd.OperatorsDate), new SqlParameter("@IsDel",cd.IsDel), new SqlParameter("@Id",cd.Id) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 删除 /// /// /// public bool DelMediaSuppliers(int id) { if (SqlHelper.ExecuteNonQuery("update MediaSuppliers set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0) return true; return false; } } }