123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- 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
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<MediaSuppliers> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<MediaSuppliers>.excuteSql(new MediaSuppliers(), "MediaSuppliers", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- MediaSuppliers excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<MediaSuppliers> cdList = excuteSql(sql, param);
- //判断集合是否为空
- if (cdList == null || cdList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return cdList[0];
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public MediaSuppliers GetMediaSuppliersByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from MediaSuppliers where Id = @id and IsDel = 0", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 查询信息
- /// </summary>
- /// <returns>返回空或者单个对象信息</returns>
- public List<MediaSuppliers> GetMediaSuppliersName(string name)
- {
- //调用获取单个对象的方法
- return excuteSql("select * from MediaSuppliers where Name like '%" + name + "%'");
- }
- /// <summary>
- /// 查询信息
- /// </summary>
- /// <returns>返回空或者单个对象信息</returns>
- public List<MediaSuppliers> GetMediaSuppliersByUnitName(string unitName)
- {
- //调用获取单个对象的方法
- return excuteSql("select * from MediaSuppliers where UnitName = '" + unitName + "'");
- }
- /// <summary>
- /// 查询信息
- /// </summary>
- /// <returns>返回空或者单个对象信息</returns>
- public MediaSuppliers GetMediaSuppliersNameByEntity(string name)
- {
- //调用获取单个对象的方法
- return excuteType("select * from MediaSuppliers where Name = '" + name + "'");
- }
- /// <summary>
- /// 根据条件查询对象信息
- /// </summary>
- /// <param name="name">客户名称</param>
- /// <param name="unitName">单位名称</param>
- /// <returns>返回空或者单个对象信息</returns>
- 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));
- }
- /// <summary>
- /// 根据条件查询对象信息
- /// </summary>
- /// <param name="name">客户名称</param>
- /// <param name="unitName">单位名称</param>
- /// <returns>返回空或者单个对象信息</returns>
- public MediaSuppliers GetMediaSuppliers(string unitName)
- {
- //调用获取单个对象的方法
- return excuteType("select * from MediaSuppliers where UnitName = @UnitName", new SqlParameter("@UnitName", unitName));
- }
- /// <summary>
- /// 获取全部 - 分页
- /// </summary>
- /// <returns></returns>
- public List<MediaSuppliers> 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<MediaSuppliers>.excutePageSql(new MediaSuppliers(), "MediaSuppliers", "MediaSuppliers", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
- }
- /// <summary>
- /// 增加
- /// </summary>
- /// <param name="cd"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="sdt"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
|