using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL;
using System.Data.SqlClient;
using System.Data;
using CY.Model;
using System.Transactions;
namespace CY.SQLDAL
{
//软件客户
public class Soft_ClientDAL : ISoft_ClientDAL
{
private Database _dataBase = null;
public Soft_ClientDAL()
{
_dataBase = new Database();
}
public Soft_ClientDAL(Database dataBase)
{
_dataBase = dataBase;
}
///
/// 新增
///
///
///
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.Soft_Client trueModel = model as Model.Soft_Client;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@ClientCountry", trueModel.ClientCountry) ,
new SqlParameter("@ClientAddress", trueModel.ClientAddress) ,
new SqlParameter("@ClientPostcode", trueModel.ClientPostcode) ,
new SqlParameter("@ClientProxyId", trueModel.ClientProxyId) ,
new SqlParameter("@ClientType", trueModel.ClientType) ,
new SqlParameter("@ClientIsMember", trueModel.ClientIsMember) ,
new SqlParameter("@ClientMemberId", trueModel.ClientMemberId) ,
new SqlParameter("@ClientCreatTime", trueModel.ClientCreatTime) ,
new SqlParameter("@ClientEndTime", trueModel.ClientEndTime) ,
new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) ,
new SqlParameter("@ClientName", trueModel.ClientName) ,
new SqlParameter("@Operator", trueModel.Operator) ,
new SqlParameter("@LoginId", trueModel.LoginId) ,
new SqlParameter("@Password", trueModel.Password) ,
new SqlParameter("@UseState", trueModel.UseState) ,
new SqlParameter("@RegisterDate", trueModel.RegisterDate) ,
new SqlParameter("@ClientStatus", trueModel.ClientStatus) ,
new SqlParameter("@ClientPhone", trueModel.ClientPhone) ,
new SqlParameter("@ClientQQ", trueModel.ClientQQ) ,
new SqlParameter("@ClientEmail", trueModel.ClientEmail) ,
new SqlParameter("@ClientMobile", trueModel.ClientMobile) ,
new SqlParameter("@ClientProvince", trueModel.ClientProvince) ,
new SqlParameter("@ClientCity", trueModel.ClientCity)
};
try
{
_dataBase.Query("sp_Soft_Client_Insert", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 修改
///
///
///
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.Soft_Client trueModel = model as Model.Soft_Client;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid", trueModel.Keyid) ,
new SqlParameter("@ClientCountry", trueModel.ClientCountry) ,
new SqlParameter("@ClientAddress", trueModel.ClientAddress) ,
new SqlParameter("@ClientPostcode", trueModel.ClientPostcode) ,
new SqlParameter("@ClientProxyId", trueModel.ClientProxyId) ,
new SqlParameter("@ClientType", trueModel.ClientType) ,
new SqlParameter("@ClientIsMember", trueModel.ClientIsMember) ,
new SqlParameter("@ClientMemberId", trueModel.ClientMemberId) ,
new SqlParameter("@ClientCreatTime", trueModel.ClientCreatTime) ,
new SqlParameter("@ClientEndTime", trueModel.ClientEndTime) ,
new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) ,
new SqlParameter("@ClientName", trueModel.ClientName) ,
new SqlParameter("@Operator", trueModel.Operator) ,
new SqlParameter("@LoginId", trueModel.LoginId) ,
new SqlParameter("@Password", trueModel.Password) ,
new SqlParameter("@UseState", trueModel.UseState) ,
new SqlParameter("@RegisterDate", trueModel.RegisterDate) ,
new SqlParameter("@ClientStatus", trueModel.ClientStatus) ,
new SqlParameter("@ClientPhone", trueModel.ClientPhone) ,
new SqlParameter("@ClientQQ", trueModel.ClientQQ) ,
new SqlParameter("@ClientEmail", trueModel.ClientEmail) ,
new SqlParameter("@ClientMobile", trueModel.ClientMobile) ,
new SqlParameter("@ClientProvince", trueModel.ClientProvince) ,
new SqlParameter("@ClientCity", trueModel.ClientCity)
};
try
{
_dataBase.Query("sp_Soft_Client_Update", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 删除
///
///
///
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.Soft_Client trueModel = model as Model.Soft_Client;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid)
};
try
{
_dataBase.Query("sp_Soft_Client_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 分页查询
///
///
///
///
public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
{
throw new NotImplementedException();
}
///
/// 单个查询
///
///
///
public IEnumerable SelectAllModel(Infrastructure.Query.Query query)
{
throw new NotImplementedException();
}
///
/// 根据编号获得信息
///
/// 编号
///
public Soft_Client GetModelByKeyid(int? Keyid)
{
try
{
if (Keyid == null || Keyid < 0)
return null;//错误数据返会空
IList result = _dataBase.SelectModel(" * ", " Soft_Client ", string.Format(" Keyid='{0}'", Keyid)) as IList;//执行查询
return (null == result || result.Count == 0) ? null : result[0];//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 分页查询
///
///
///
public IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, string _ClientName, int? _ClientStatus, string _ClientPhone, string _ClientQQ, string _ClientMobile, string _ClientProvince, string _ClientCity, string _ClientCountry, string _ClientAddress, string _ClientPostcode, int? _ClientProxyId, int? _ClientType, int? _ClientIsMember, Guid _ClientMemberId, DateTime? _BeginClientCreatTime, DateTime? _EndClientCreatTime, DateTime? _BeginClientEndTime, DateTime? _EndClientEndTime, DateTime? _BeginLastUpdateTime, DateTime? _EndLastUpdateTime, string _Operator)
{
try
{
string condition = " 1=1 ";
if (!string.IsNullOrEmpty(_ClientName))
condition += " and ClientName like '%" + _ClientName + "%' ";
if (_ClientStatus.HasValue)
condition += " and ClientStatus = '" + _ClientStatus + "' ";
if (!string.IsNullOrEmpty(_ClientPhone))
condition += " and ClientPhone = '" + _ClientPhone + "' ";
if (!string.IsNullOrEmpty(_ClientQQ))
condition += " and ClientQQ = '" + _ClientQQ + "' ";
if (!string.IsNullOrEmpty(_ClientMobile))
condition += " and ClientMobile = '" + _ClientMobile + "' ";
if (!string.IsNullOrEmpty(_ClientProvince))
condition += " and ClientProvince = '" + _ClientProvince + "' ";
if (!string.IsNullOrEmpty(_ClientCity))
condition += " and ClientCity = '" + _ClientCity + "' ";
if (!string.IsNullOrEmpty(_ClientCountry))
condition += " and ClientCountry = '" + _ClientCountry + "' ";
if (!string.IsNullOrEmpty(_ClientAddress))
condition += " and ClientAddress = '" + _ClientAddress + "' ";
if (!string.IsNullOrEmpty(_ClientPostcode))
condition += " and ClientPostcode = '" + _ClientPostcode + "' ";
if (_ClientProxyId.HasValue)
condition += " and ClientProxyId = '" + _ClientProxyId + "' ";
if (_ClientType.HasValue)
condition += " and ClientType = '" + _ClientType + "' ";
if (_ClientIsMember.HasValue)
condition += " and ClientIsMember = '" + _ClientIsMember + "' ";
if (_ClientMemberId != Guid.Empty)
condition += " and ClientMemberId = '" + _ClientMemberId + "' ";
if (_BeginClientCreatTime.HasValue)
condition += string.Format(" and CAST(ClientCreatTime AS DATE) >='{0}' ", _BeginClientCreatTime);
if (_EndClientCreatTime.HasValue)
condition += string.Format(" and CAST(ClientCreatTime AS DATE) <='{0}' ", _EndClientCreatTime);
if (_BeginClientEndTime.HasValue)
condition += string.Format(" and CAST(ClientEndTime AS DATE) >='{0}' ", _BeginClientEndTime);
if (_EndClientEndTime.HasValue)
condition += string.Format(" and CAST(ClientEndTime AS DATE) <='{0}' ", _EndClientEndTime);
if (_BeginLastUpdateTime.HasValue)
condition += string.Format(" and CAST(LastUpdateTime AS DATE) >='{0}' ", _BeginLastUpdateTime);
if (_EndLastUpdateTime.HasValue)
condition += string.Format(" and CAST(LastUpdateTime AS DATE) <='{0}' ", _EndLastUpdateTime);
if (!string.IsNullOrEmpty(_Operator))
condition += " and Operator = '" + _Operator + "' ";
return _dataBase.SelectModelPage(pagination, " * ", " Soft_Client ", " Keyid desc", " Keyid desc ", condition);
}
catch (Exception ex)
{
throw ex;
}
}
}
}