/// <summary>
/// 获取单条数据
/// </summary>
/// <param name="Id">Id</param>
/// <returns></returns>
public LinksEntity GetLinksEntity(Int64 Id)
{
LinksEntity LinksEntity = null;
SqlParameter[] Para = new SqlParameter[1];
Para[0] = new SqlParameter("@Id", Id);
DataSet Set = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, procedurePrefixes + "Links_GetInfoById", Para);
if (Set.Tables[0].Rows.Count > 0)
{
LinksEntity = new LinksEntity();
DataRow dr = Set.Tables[0].Rows[0];
foreach (DataColumn dc in dr.Table.Columns)
{
PropertyInfo pi = LinksEntity.GetType().GetProperty(dc.ColumnName);
if (pi != null)
{
if (dr[dc.ColumnName] != DBNull.Value)
{
if (pi.PropertyType.IsEnum)
{
pi.SetValue(LinksEntity, Enum.ToObject(pi.PropertyType, dr[dc.ColumnName]), null);
}
else
{
pi.SetValue(LinksEntity, dr[dc.ColumnName], null);
}
}
else
{
pi.SetValue(LinksEntity, null, null);
}
}
}
}
return LinksEntity;
}
/// <summary>
/// 按条件选择数据
/// </summary>
/// <param name="condition">Chaige.Pagination.Condition</param>
/// <returns></returns>
public IList<LinksEntity> GetLinksList(Chaige.Pagination.Condition condition)
{
IList<LinksEntity> list = new List<LinksEntity>();
if (condition.TableName == "")
condition.TableName = tablePrefixes + "Links";
SqlParameter[] Para = new SqlParameter[5];
Para[0] = new SqlParameter("@TableName", condition.TableName);
Para[1] = new SqlParameter("@TopNum", condition.TopNum);
Para[2] = new SqlParameter("@FieldList", condition.FieldList);
Para[3] = new SqlParameter("@Conditions", condition.Conditions);
Para[4] = new SqlParameter("@OrderBy", condition.OrderBy);
DataSet Set = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, procedurePrefixes + "Condition", Para);
foreach (DataRow dr in Set.Tables[0].Rows)
{
LinksEntity LinksEntity = new LinksEntity();
foreach (DataColumn dc in dr.Table.Columns)
{
PropertyInfo pi = LinksEntity.GetType().GetProperty(dc.ColumnName);
if (pi != null)
{
if (dr[dc.ColumnName] != DBNull.Value)
{
if (pi.PropertyType.IsEnum)
{
pi.SetValue(LinksEntity, Enum.ToObject(pi.PropertyType, dr[dc.ColumnName]), null);
}
else
{
pi.SetValue(LinksEntity, dr[dc.ColumnName], null);
}
}
else
{
pi.SetValue(LinksEntity, null, null);
}
}
}
list.Add(LinksEntity);
}
return list;
}
/// <summary>
/// 分页数据
/// </summary>
/// <param name="pagination">Chaige.Pagination.Pagination</param>
/// <returns></returns>
public IList<LinksEntity> GetLinksList(Chaige.Pagination.Pagination pagination)
{
IList<LinksEntity> list = new List<LinksEntity>();
if (pagination.TableName == "")
pagination.TableName = tablePrefixes + "Links";
SqlParameter[] Para = new SqlParameter[10];
Para[0] = new SqlParameter("@TableName", pagination.TableName);
Para[1] = new SqlParameter("@PKey", pagination.PKey);
Para[2] = new SqlParameter("@FieldList", pagination.FieldList);
Para[3] = new SqlParameter("@Condition", pagination.Condition);
Para[4] = new SqlParameter("@OrderBy", pagination.OrderBy);
Para[5] = new SqlParameter("@Sql", pagination.Sql);
Para[6] = new SqlParameter("@SqlGetRC", pagination.SqlGetRC);
Para[7] = new SqlParameter("@CurrPage", pagination.CurrPage);
Para[8] = new SqlParameter("@PageSize", pagination.PageSize);
Para[9] = new SqlParameter("@RecordCount", pagination.RecordCount);
DataSet Set = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, procedurePrefixes + "Pagination", Para);
recordcount = int.Parse(Set.Tables[1].Rows[0]["RecordCount"].ToString());
pagecount = int.Parse(Set.Tables[1].Rows[0]["PageCount"].ToString());
foreach (DataRow dr in Set.Tables[0].Rows)
{
LinksEntity LinksEntity = new LinksEntity();
foreach (DataColumn dc in dr.Table.Columns)
{
PropertyInfo pi = LinksEntity.GetType().GetProperty(dc.ColumnName);
if (pi != null)
{
if (dr[dc.ColumnName] != DBNull.Value)
{
if (pi.PropertyType.IsEnum)
{
pi.SetValue(LinksEntity, Enum.ToObject(pi.PropertyType, dr[dc.ColumnName]), null);
}
else
{
pi.SetValue(LinksEntity, dr[dc.ColumnName], null);
}
}
else
{
pi.SetValue(LinksEntity, null, null);
}
}
}
list.Add(LinksEntity);
}
return list;
}
}