📄 newmessagelist.ascx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class WebUserControl_NewMessageList : System.Web.UI.UserControl
{
#region "公共参数"
//******************************************************************************
//* 组件名称:NewsColumn
//* 功能介绍:显示新闻栏.需要传递的参数有
//* sql(需要查询的sql语句)例如: sql = "select * from newscontent"
//*
//* arrayParam(连接地址后面的参数数组,此参数主要为了给每一条信息动态附值。) 例如:arrayParam2.Add("id") arrayParam2.Add("group_id")
//* 如果静态附值所有信息都跳转到一个页面可以不给此参数附值直接把参数写到strURl中赋给链接.
//* 例如:strUrl= "webform2.aspx?id=5&group_id=2"
//*
//* strURL(想要跳转到的页面) 例如: NewsColumn1.strURL = "webform2.aspx"
//* strLen(标题显示长度) 例如:NewsColumn1.strLen = 8
//* MyPageSize(每页显示多少行记录) 例如:NewsColumn1.MyPageSize = 3 但是当AllowPaging=false时,此属性无效.
//* ChildSQL(查看内容表的sql,用来传递给readNews组件查看具体内容用的sql语句) 例如: childsql2 = "sql=select Content from bannerContent "
//* VritualPath;网站的虚拟目录
//* 开发人员:徐宏杰
//* 开发日期:2006-5-26
//* 修改人员:
//* 修改日期:
//*******************************************************************************
/// <summary>
/// 需要查询的sql语句.
/// </summary>
/// public string sql;
/// <summary>
/// 参数数组。如果参数为空,就把strURl直接赋给链接.
/// </summary>
public bool boolAddDate;
/// <summary>
/// 参数数组。如果参数为空,就把strURl直接赋给链接.
/// </summary>
public ArrayList arrayParam = new ArrayList();
/// <summary>
/// "webform2.aspx" '跳转地址(总的跳转页)
/// </summary>
public string strURL="Content.aspx";
/// <summary>
/// 标题显示长度
/// </summary>
public int strLen = 20;
/// <summary>
/// 每页显示多少行记录!
/// </summary>
public int MyPageSize;
/// <summary>
/// 查看内容表的sql,用来传递给readNews组件查看具体内容用的sql语句
/// </summary>
public string ChildSQL;
/// <summary>
/// 查看更多跳转路径
/// </summary>
public string morePath = "#";
/// <summary>
/// 网站虚拟目录
/// </summary>
private string Vritual_Path;
public string VritualPath
{
set
{
Vritual_Path = value;
}
get
{
return Vritual_Path;
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
GetNewMessage();
}
}
catch (System.Exception ex)
{
throw ex;
}
}
/// <summary>
/// 最新留言列
/// </summary>
private void GetNewMessage()
{
DataSet ds = new DataSet();
DAL.boBusiness bo = new DAL.boBusiness();
DAL.MakeConnection Conn = new DAL.MakeConnection();
DAL.clsDBConnkey ConnKey = new DAL.clsDBConnkey();
ConnKey = bo.loadkey();//得到config数据库连接
try
{
//string sql = "select Top 10 * from MessageBoard where IsNominate=1 order by leavewordTime desc";
string sql = "select Top 10 * from MessageBoard order by leavewordTime desc";
ds = (DataSet)Conn.MakeConnectionMethod(sql, ConnKey, DAL.executeMethod.execute_DataSet, DAL.
EnumDBType.Sql, VritualPath);
if (ds.Tables[0].Rows.Count > 0)
{
DataTable dt = ds.Tables[0];
string html = makeHtml1(dt, arrayParam, strLen, strURL);
this.lab.InnerHtml = html;
}
}
catch (System.Exception ex)
{
throw ex;
}
}
#region "最新留言"
/// <summary>
///
/// </summary>
/// <param name="row"></param>
/// <param name="arrayParam"></param>
/// <param name="strlen"></param>
/// <param name="strUrl">总的跳转</param>
/// <returns></returns>
private string makeHtml1(DataTable dt, ArrayList arrayParam, int strlen, string strUrl)
{
string HTML = "";
HTML += "<TABLE id='Table1' width='100%' style='FONT-SIZE: 10pt' cellSpacing='2' cellPadding='2' border='0' >\r\n";
//HTML+="<TR border='0'>\r\n";
//HTML+="<TD width='7px' height='10'></TD>\r\n";
//HTML+="<TD ></TD>\r\n";
HTML += "</TR>\r\n";
string Title = "", AllTitle = "";
for (int i = 0; i < dt.Rows.Count; i++)
{
Title = ""; AllTitle = "";
AllTitle = dt.Rows[i]["Title"].ToString();
Title += (i + 1) + ".";
if (AllTitle.Length > strlen)
{
if (strlen != 0)
{
Title += AllTitle.Substring(0, strlen - 2);
Title += "..";
}
else
{
Title += AllTitle;
}
}
else
{
Title += AllTitle;
}
string ahref1 = "", ahref2 = "";
ChildSQL = "ID="+dt.Rows[i]["ArticleID"].ToString();
ahref1 = "a href= ";
if (arrayParam.Count > 0)//如果每一条信息有动态参数
{
ahref1 += strUrl + "?";
for (int j = 0; j < arrayParam.Count; j++)
{
ahref2 += arrayParam[j] + "=" + dt.Rows[i][arrayParam[j].ToString()] + " & ";
}
ahref1 += ahref2;
if (ChildSQL != "")
{
ahref1 += ChildSQL;
}
}
else //如果每一条信息没有参数
{
if (ChildSQL != "")
{
ahref1 += strUrl + "?";
ahref1 += ChildSQL;
}
else
{
ahref1 = "a href=";
ahref1 += strURL + "";
}
}
HTML += "<TR border='1'>\r\n";
HTML += "<TD width=2px height=24></TD>\r\n";
HTML += "<TD width='100px' Title='" + AllTitle + "'><" + ahref1 + ">" + Title + "</a></TD>\r\n";
HTML += "</TR>\r\n";
}
HTML += "<TR border='0'>\r\n";
HTML += "<TD width=2px height=24></TD>\r\n";
HTML += "<TD width='100px' Title='更多留言...' align='right'></TD>\r\n";
HTML += "</TR>\r\n";
HTML += "</TABLE>";
return HTML;
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -