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 Info_AdDAL : IInfo_AdDAL
{
private Database _dataBase = null;
public Info_AdDAL()
{
_dataBase = new Database();
}
public Info_AdDAL(Database database)
{
_dataBase = database;
}
///
/// 新增
///
///
///
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.Info_Ad trueModel = model as Model.Info_Ad;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter(){Direction=ParameterDirection.ReturnValue,SqlDbType = SqlDbType.Int},
new SqlParameter("@AdLocationId",trueModel.AdLocationId),
new SqlParameter("@A_Title",trueModel.A_Title),
new SqlParameter("@A_Pic",trueModel.A_Pic),
new SqlParameter("@A_Url",trueModel.A_Url),
new SqlParameter("@A_Remarks",trueModel.A_Remarks),
new SqlParameter("@A_IsTarget",trueModel.A_IsTarget),
new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
new SqlParameter("@Operator",trueModel.Operator),
new SqlParameter("@Remark",trueModel.Remark),
new SqlParameter("@A_MemberId",trueModel.A_MemberId),
new SqlParameter("@A_StartTime",trueModel.A_StartTime),
new SqlParameter("@A_EndTime",trueModel.A_EndTime)
};
try
{
_dataBase.Query("sp_Info_Ad_Insert", CommandType.StoredProcedure, sqlParms.ToArray());
trueModel.Keyid = CY.Infrastructure.Common.MyConvert.ConvertToInt32(sqlParms[0].Value);
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 修改
///
///
///
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.Info_Ad trueModel = model as Model.Info_Ad;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid),
new SqlParameter("@AdLocationId",trueModel.AdLocationId),
new SqlParameter("@A_Title",trueModel.A_Title),
new SqlParameter("@A_Pic",trueModel.A_Pic),
new SqlParameter("@A_Url",trueModel.A_Url),
new SqlParameter("@A_Remarks",trueModel.A_Remarks),
new SqlParameter("@A_IsTarget",trueModel.A_IsTarget),
new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
new SqlParameter("@Operator",trueModel.Operator),
new SqlParameter("@Remark",trueModel.Remark),
new SqlParameter("@A_MemberId",trueModel.A_MemberId),
new SqlParameter("@A_StartTime",trueModel.A_StartTime),
new SqlParameter("@A_EndTime",trueModel.A_EndTime)
};
try
{
_dataBase.Query("sp_Info_Ad_Update", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 删除
///
///
///
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.Info_Ad trueModel = model as Model.Info_Ad;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid)
};
try
{
_dataBase.Query("sp_Info_Ad_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 IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, int? Remark , int? locationid, string UserName,bool isNow)
{
try
{
string condtion = " 1=1 ";
if (locationid != null && locationid >0 )
condtion += " and b.Keyid = '" + locationid + "' ";
else
{
if (Remark != null && Remark > 0)
condtion += " and b.Remark = '" + Remark + "' ";
}
if (!string.IsNullOrEmpty(UserName))
condtion += " and c.Name like '%" + UserName + "%'";
if(isNow)
condtion += " and a.A_StartTime <= GETDATE() and a.A_EndTime >= GETDATE()";
else
condtion += " and a.A_StartTime >= GETDATE() ";
//TypeName
IList result = _dataBase.SelectModelPage(pagination, " a.*,d.Name as LocationRemark,b.AP_Title as LocationName,b.AP_WidePixels as AP_WidePixels,b.AP_HighPixels as AP_HighPixels,c.Name as UserName ", " Info_Ad as a left join Info_AdLoction as b on a.AdLocationId = b.Keyid left join EC_MemberBasic as c on a.A_MemberId = c.MemberId left join Sys_Dictionary as d on b.Remark = d.MeanValue and d.DicType ='网站广告位置版块' ", " b.Remark ASC,A_StartTime ASC ", "", condtion) as IList;//执行查询
return null == result ? null : result;//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 查询全部分类
///
///
public DataTable SelectList()
{
return _dataBase.SelectModel("*", "Info_Ad", string.Format("1= 1 ORDER BY AdLocationId ASC"));
}
///
/// 根据编号查询单个信息
///
/// 编号
///
public Info_Ad SelectModelByKeyId(int? KeyId)
{
if (KeyId == null)
return null;//错误数据返会空
Info_Ad m_Info_Ad = new Info_Ad();
try
{
IList result = _dataBase.SelectModel("*", "Info_Ad", string.Format(" Keyid='{0}' ", KeyId)) as IList;//执行查询
if (null == result || result.Count == 0)
{
m_Info_Ad = null;
}
else
{
m_Info_Ad = result[0];
}
}
catch (Exception ex)
{
throw ex;
}
return m_Info_Ad;
}
///
/// 根据位置编号查询所有广告信息
///
///
///
public Info_Ad SelectListByAdLocationId(int? AdLocationId)
{
if (AdLocationId == null)
return null;//错误数据返会空
Info_Ad m_Info_Ad = new Info_Ad();
try
{
IList result = _dataBase.SelectModel("*", "Info_Ad", string.Format(" AdLocationId='{0}' order by A_EndTime DESC ", AdLocationId)) as IList;//执行查询
if (null == result || result.Count == 0)
{
m_Info_Ad = null;
}
else
{
m_Info_Ad = result[0];
}
}
catch (Exception ex)
{
throw ex;
}
return m_Info_Ad;
}
///
/// 根据版块名称和位置名称返回广告代码
///
///
///
///
public string SelectAdByLocationName(string ForumName, string LocationName)
{
if (string.IsNullOrEmpty(LocationName))
return "";//错误数据返会空
Info_AdLoctionDAL dal_Info_AdLoctionDAL = new Info_AdLoctionDAL();
string AdsHtml = "";
try
{
Info_AdLoction m_Info_AdLoction = dal_Info_AdLoctionDAL.SelectModelByLocationName(ForumName, LocationName);
if (m_Info_AdLoction != null)
{
string DefaultImg = string.IsNullOrEmpty(m_Info_AdLoction.AP_DefaultImg) ? "../../images/admin/_LoadDefault.gif" : m_Info_AdLoction.AP_DefaultImg;
AdsHtml = "
";
IList m_Info_AdList = _dataBase.SelectModel("*", "Info_Ad", string.Format(" AdLocationId='{0}' and A_StartTime <= GETDATE() and A_EndTime >= GETDATE()", m_Info_AdLoction.Keyid)) as IList;//执行查询
if (m_Info_AdList != null && m_Info_AdList.Count > 0)
{
AdsHtml = "";
foreach (var m_Info_Ad in m_Info_AdList)
{
AdsHtml += "
";
}
}
}
}
catch (Exception ex)
{
throw ex;
}
return AdsHtml;
}
}
}