123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Models;
- using System.Data.SqlClient;
- using System.Data;
- namespace DAL
- {
- /// <summary>
- /// 客户资料数据访问类
- /// </summary>
- public class ClientDataService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<ClientData> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<ClientData>.excuteSql(new ClientData(), "ClientData", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- ClientData excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<ClientData> 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 ClientData GetClientDataByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from ClientData where Id = @id and IsDel = 0", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 查询信息
- /// </summary>
- /// <returns>返回空或者单个对象信息</returns>
- public List<ClientData> GetClientDataName(string name)
- {
- //调用获取单个对象的方法
- return excuteSql("select * from ClientData where Name like '%" + name + "%'");
- }
- /// <summary>
- /// 查询信息
- /// </summary>
- /// <returns>返回空或者单个对象信息</returns>
- public List<ClientData> GetClientDataByUnitName(string unitName)
- {
- //调用获取单个对象的方法
- return excuteSql("select * from ClientData where UnitName like '" + unitName + "'");
- }
- /// <summary>
- /// 查询信息
- /// </summary>
- /// <returns>返回空或者单个对象信息</returns>
- public ClientData GetClientDataNameByEntity(string name)
- {
- //调用获取单个对象的方法
- return excuteType("select * from ClientData where Name = '" + name + "'");
- }
- /// <summary>
- /// 根据条件查询对象信息
- /// </summary>
- /// <param name="name">客户名称</param>
- /// <param name="unitName">单位名称</param>
- /// <returns>返回空或者单个对象信息</returns>
- public ClientData GetClientData(string name, string unitName)
- {
- //调用获取单个对象的方法
- return excuteType("select * from ClientData 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 ClientData GetClientData(string unitName)
- {
- //调用获取单个对象的方法
- return excuteType("select * from ClientData where UnitName = @UnitName", new SqlParameter("@UnitName", unitName));
- }
- /// <summary>
- /// 获取全部 - 分页
- /// </summary>
- /// <returns></returns>
- public List<ClientData> GetClientData(int pageIndex, out int sumPage, out int totalRecord, string clientLvl,string departmentType, string name, string unitName, string tel)
- {
- string sqlwhere = "IsDel = 0 and Name like '%" + name + "%' and UnitName like '%" + unitName + "%' and Tel like '%" + tel + "%'";
- if (departmentType != "全部")
- sqlwhere += " and Did = " + departmentType + "";
- if (clientLvl != "")
- sqlwhere += " and ClientLvl = '" + clientLvl + "'";
- return PageBase<ClientData>.excutePageSql(new ClientData(), "ClientData", "ClientData", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
- }
- /// <summary>
- /// 增加
- /// </summary>
- /// <param name="cd"></param>
- /// <returns></returns>
- public bool AddClientData(ClientData cd)
- {
- string sql = "insert into ClientData values(@DId,@Name,@Sex,@UnitName,@UnitAbbreviation,@Post,@Tel,@Email,@Fax,@OtherInformation,@Operator,@OperatorDate,@IsDel,@Lid,@ClientLvl)";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@DId",cd.Did),
- 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("@Email",cd.Email),
- new SqlParameter("@Fax",cd.Fax),
- new SqlParameter("@OtherInformation",cd.OtherInformation),
- new SqlParameter("@Operator",cd.Operators),
- new SqlParameter("@OperatorDate",cd.OperatorsDate),
- new SqlParameter("@IsDel",cd.IsDel),
- new SqlParameter("@Lid",cd.Lid),
- new SqlParameter("@ClientLvl",cd.ClientLvl)
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="sdt"></param>
- /// <returns></returns>
- public bool EditClientData(ClientData cd)
- {
- string sql = "update ClientData set DId = @DId,Name = @Name,Sex = @Sex,UnitName = @UnitName,UnitAbbreviation = @UnitAbbreviation,Post = @Post,Tel = @Tel,Email = @Email,Fax = @Fax,OtherInformation = @OtherInformation,Operator = @Operator,OperatorDate = @OperatorDate,Lid=@Lid,ClientLvl=@ClientLvl where Id = @Id";
- SqlParameter[] parameter = new SqlParameter[] {
- new SqlParameter("@DId",cd.Did),
- 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("@Email",cd.Email),
- new SqlParameter("@Fax",cd.Fax),
- new SqlParameter("@OtherInformation",cd.OtherInformation),
- new SqlParameter("@Operator",cd.Operators),
- new SqlParameter("@OperatorDate",cd.OperatorsDate),
- new SqlParameter("@Id",cd.Id),
- new SqlParameter("@Lid",cd.Lid),
- new SqlParameter("@ClientLvl",cd.ClientLvl)
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelClientData(int id)
- {
- if (SqlHelper.ExecuteNonQuery("update ClientData set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
- return true;
- return false;
- }
- }
- }
|