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;
|
}
|
|
/// <summary>
|
/// 新增
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.Info_Ad trueModel = model as Model.Info_Ad;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
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<SqlParameter>());
|
trueModel.Keyid = CY.Infrastructure.Common.MyConvert.ConvertToInt32(sqlParms[0].Value);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 修改
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.Info_Ad trueModel = model as Model.Info_Ad;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
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<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.Info_Ad trueModel = model as Model.Info_Ad;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@Keyid",trueModel.Keyid)
|
};
|
try
|
{
|
_dataBase.Query("sp_Info_Ad_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 分页查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.Info_Ad> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 单个查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.Info_Ad> SelectAllModel(Infrastructure.Query.Query query)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 列表查询
|
/// </summary>
|
/// <param name="pagination"></param>
|
/// <param name="Remark"></param>
|
/// <param name="locationid"></param>
|
/// <param name="UserName"></param>
|
/// <param name="isNow"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.Info_Ad> 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<Info_Ad> result = _dataBase.SelectModelPage<Model.Info_Ad>(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<Info_Ad>;//执行查询
|
return null == result ? null : result;//返回结果
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 查询全部分类
|
/// </summary>
|
/// <returns></returns>
|
public DataTable SelectList()
|
{
|
return _dataBase.SelectModel("*", "Info_Ad", string.Format("1= 1 ORDER BY AdLocationId ASC"));
|
}
|
|
/// <summary>
|
/// 根据编号查询单个信息
|
/// </summary>
|
/// <param name="Keyid">编号</param>
|
/// <returns></returns>
|
public Info_Ad SelectModelByKeyId(int? KeyId)
|
{
|
if (KeyId == null)
|
return null;//错误数据返会空
|
|
Info_Ad m_Info_Ad = new Info_Ad();
|
try
|
{
|
IList<Info_Ad> result = _dataBase.SelectModel<Info_Ad>("*", "Info_Ad", string.Format(" Keyid='{0}' ", KeyId)) as IList<Info_Ad>;//执行查询
|
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;
|
}
|
|
/// <summary>
|
/// 根据位置编号查询所有广告信息
|
/// </summary>
|
/// <param name="AdLocationId"></param>
|
/// <returns></returns>
|
public Info_Ad SelectListByAdLocationId(int? AdLocationId)
|
{
|
if (AdLocationId == null)
|
return null;//错误数据返会空
|
|
Info_Ad m_Info_Ad = new Info_Ad();
|
try
|
{
|
IList<Info_Ad> result = _dataBase.SelectModel<Info_Ad>("*", "Info_Ad", string.Format(" AdLocationId='{0}' order by A_EndTime DESC ", AdLocationId)) as IList<Info_Ad>;//执行查询
|
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;
|
}
|
|
/// <summary>
|
/// 根据版块名称和位置名称返回广告代码
|
/// </summary>
|
/// <param name="ForumName"></param>
|
/// <param name="LocationName"></param>
|
/// <returns></returns>
|
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 = "<a href='#'><img width='" + m_Info_AdLoction.AP_WidePixels + "' height='" + m_Info_AdLoction.AP_HighPixels + "' src='" + DefaultImg + "' onerror=\"this.src='../../images/admin/_LoadDefault.gif'\" /></a>";
|
|
IList<Info_Ad> m_Info_AdList = _dataBase.SelectModel<Info_Ad>("*", "Info_Ad", string.Format(" AdLocationId='{0}' and A_StartTime <= GETDATE() and A_EndTime >= GETDATE()", m_Info_AdLoction.Keyid)) as IList<Info_Ad>;//执行查询
|
if (m_Info_AdList != null && m_Info_AdList.Count > 0)
|
{
|
AdsHtml = "";
|
foreach (var m_Info_Ad in m_Info_AdList)
|
{
|
AdsHtml += "<a href='http://" + m_Info_Ad.A_Url.ToString().Replace("http://", "") + "' " + (m_Info_Ad.A_IsTarget ? " target='_blank'" : "") + " title='" + m_Info_Ad.A_Title + "'><img width='" + m_Info_AdLoction.AP_WidePixels + "' height='" + m_Info_AdLoction.AP_HighPixels + "' alt='" + m_Info_Ad.A_Title + "' src='" + m_Info_Ad.A_Pic + "' onerror=\"this.src='../../images/admin/_LoadDefault.gif'\" /></a>";
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return AdsHtml;
|
}
|
}
|
}
|