C# 使用c显示想法列表#
我希望显示一个想法列表,而不是只显示每天变化的一个想法。有没有办法编辑我的代码,以秒数而不是新的一天来显示更改 如何编辑下面的代码C# 使用c显示想法列表#,c#,sharepoint-2010,C#,Sharepoint 2010,我希望显示一个想法列表,而不是只显示每天变化的一个想法。有没有办法编辑我的代码,以秒数而不是新的一天来显示更改 如何编辑下面的代码 using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Microsoft.SharePoint; using Microsoft.SharePoint.Utilities; namespa
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
namespace TOTD.TOTD
{
public partial class TOTDUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["QOTD"];
SPListItemCollection collItem = oList.GetItems("Thought", "AuthorImage", "AuthorName","Head");
Random random = new Random();
int RndItem = random.Next(1, collItem.Count + 1);
int LastDay = 0;
int TOTD = 0;
int CurrentDay = DateTime.Now.DayOfYear;
try
{
LastDay = int.Parse(Application["LastDay"].ToString());
TOTD = int.Parse(Application["TOTD"].ToString());
if (LastDay != CurrentDay)
{
Application["LastDay"] = CurrentDay;
Application["TOTD"] = RndItem;
SPListItem oItem = collItem[RndItem - 1];
this.ImgAuthor.ImageUrl = SPEncode.HtmlEncode
(oItem["AuthorImage"].ToString().TrimEnd('?', '.', ',', ' '));
this.lblTOTD.Text = oItem["Thought"].ToString();
this.lblAuthor.Text = SPEncode.HtmlEncode(oItem["AuthorName"].ToString());
this.lblNext.Text = SPEncode.HtmlEncode(oItem["Head"].ToString());
}
else
{
SPListItem oItem = collItem[TOTD - 1];
this.ImgAuthor.ImageUrl = SPEncode.HtmlEncode
(oItem["AuthorImage"].ToString().TrimEnd('?', '.', ',', ' '));
this.lblTOTD.Text = oItem["Thought"].ToString();
this.lblAuthor.Text = SPEncode.HtmlEncode(oItem["AuthorName"].ToString());
this.lblNext.Text = SPEncode.HtmlEncode(oItem["Head"].ToString());
}
}
catch
{
Application["LastDay"] = CurrentDay;
Application["TOTD"] = RndItem;
SPListItem oItem = collItem[RndItem - 1];
this.ImgAuthor.ImageUrl = SPEncode.HtmlEncode
(oItem["AuthorImage"].ToString().TrimEnd('?', '.', ',', ' '));
this.lblTOTD.Text = oItem["Thought"].ToString();
this.lblAuthor.Text = SPEncode.HtmlEncode(oItem["AuthorName"].ToString());
this.lblNext.Text = SPEncode.HtmlEncode(oItem["Head"].ToString());
}
}
}
}
只需保存相关的DateTime并使用方法:
可能是代替了最后一天=整数。。。。只要有LastTime=int。。。。如果当前时间大于一定的秒数,则显示所需的时间
if (DateTime.Now.Subtract(givenDate).TotalSeconds >= 1)
{
Application["LastDay"] = DateTime.Now;
// do stuff.
}...