急问,下面的代码有没有逻辑方面的bug,或者有没有任何能提高效率的建议?100分
请问大家,下面的这段代码在逻辑上有bug吗?在哪些方面还能提高效率的?谢谢。悬赏100分另,改代码已经编译通过,所以只要找逻辑方面的bug就行了……
namespace Demo.WebParts
{
/// <summary>
/// Description for MyTasks.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>"),
XmlRoot(Namespace="Demo.Tasks")]
public class MyTasks : Microsoft.SharePoint.WebPartPages.WebPart
{
private const string defaultListName = "";
private string listName = defaultListName;
private ArrayList alTasks;
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(defaultListName),
WebPartStorage(Storage.None),
FriendlyName("List Name Filter"),
Description("The name of sps lists to gather tasks from")]
public string ListName
{
get
{
return listName;
}
set
{
listName = value;
}
}
protected override void CreateChildControls()
{
alTasks = new ArrayList();
try
{
SPWeb myWeb = SPControl.GetContextWeb(this.Context);
foreach(SPList list in myWeb.Lists)
{
if(list.BaseTemplate == SPListTemplateType.Tasks)
{
if(list.Title == listName)
{
getTasksFromList(list);
}
}
}
foreach(SPWeb subWeb in myWeb.Webs)
foreach(SPList list in subWeb.Lists)
if(list.BaseTemplate == SPListTemplateType.Tasks)
getTasksFromList(list);
}
catch
{}
}
private void getTasksFromList(SPList list)
{
for(int i=0;i<list.ItemCount;i++)
{
if(list.Items[i]["AssignedTo"].ToString() == this.Context.User.Identity.Name)
{
Demo.Tasks.Task tsk = Tasks.Task.CreateTask();
tsk.Title = list.Items[i]["Title"].ToString();
tsk.DueDate = (DateTime)list.Items[i]["DueDate"];
tsk.Description = list.Items[i]["Description"].ToString();
tsk.Priority = (int)list.Items[i]["Priority"];
alTasks.Add(tsk);
//now update the item
list.Items[i]["LastViewed"] = DateTime.Now;
}
}
}
/// <summary>
/// Render this Web Part to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void RenderWebPart(HtmlTextWriter output)
{
try
{
string strHTML = "";
for(int i=0;i<alTasks.Count;i++)
{
Demo.Tasks.Task tsk = (Demo.Tasks.Task)alTasks[i];
strHTML = strHTML + "The task " + tsk.Title + " is due on " + tsk.DueDate + "<BR>" + tsk.Description + "<BR><BR>";
}
output.Write(strHTML);
}
catch
{}
}
}
} --------------------编程问答-------------------- 没有一行注释,兄弟你是不是和人有仇啊 --------------------编程问答-------------------- 楼主绝顶高手啊 --------------------编程问答-------------------- 排版一下,
namespace Demo.WebParts
{
/// <summary>
/// Description for MyTasks.
/// </summary>
[DefaultProperty("Text"),
ToolboxData(" <{0}:WebPart1 runat=server> </{0}:WebPart1> "),
XmlRoot(Namespace="Demo.Tasks")]
public class MyTasks : Microsoft.SharePoint.WebPartPages.WebPart
{
private const string defaultListName = "";
private string listName = defaultListName;
private ArrayList alTasks;
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(defaultListName),
WebPartStorage(Storage.None),
FriendlyName("List Name Filter"),
Description("The name of sps lists to gather tasks from")]
public string ListName
{
get
{
return listName;
}
set
{
listName = value;
}
}
protected override void CreateChildControls()
{
alTasks = new ArrayList();
try
{
SPWeb myWeb = SPControl.GetContextWeb(this.Context);
foreach(SPList list in myWeb.Lists)
{
if(list.BaseTemplate == SPListTemplateType.Tasks)
{
if(list.Title == listName)
{
getTasksFromList(list);
}
}
}
foreach(SPWeb subWeb in myWeb.Webs)
foreach(SPList list in subWeb.Lists)
if(list.BaseTemplate == SPListTemplateType.Tasks)
getTasksFromList(list);
}
catch
{}
}
private void getTasksFromList(SPList list)
{
for(int i=0;i <list.ItemCount;i++)
{
if(list.Items[i]["AssignedTo"].ToString() == this.Context.User.Identity.Name)
{
Demo.Tasks.Task tsk = Tasks.Task.CreateTask();
tsk.Title = list.Items[i]["Title"].ToString();
tsk.DueDate = (DateTime)list.Items[i]["DueDate"];
tsk.Description = list.Items[i]["Description"].ToString();
tsk.Priority = (int)list.Items[i]["Priority"];
alTasks.Add(tsk);
//now update the item
list.Items[i]["LastViewed"] = DateTime.Now;
}
}
}
/// <summary>
/// Render this Web Part to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void RenderWebPart(HtmlTextWriter output)
{
try
{
string strHTML = "";
for(int i=0;i <alTasks.Count;i++)
{
Demo.Tasks.Task tsk = (Demo.Tasks.Task)alTasks[i];
strHTML = strHTML + "The task " + tsk.Title + " is due on " + tsk.DueDate + " <BR> " + tsk.Description + " <BR> <BR> ";
}
output.Write(strHTML);
}
catch
{}
}
}
} --------------------编程问答-------------------- 楼上几个有点耐心嘛,我拿到手的也就这个,要有注释我也不用来这里送分了…… --------------------编程问答-------------------- 这种代码谁有耐心看...大家都很忙... --------------------编程问答-------------------- 是啊,最好是楼主说个大概,大家参考给点意见. --------------------编程问答-------------------- 嗯,就我目前所知,这段代码是从指定的网页里获得指定的内容,然后用RenderWebPart写出来。其中SPWeb.GetContextWeb方法是获取当前网页的内容,SPWeb.Webs方法是获取当前网页的子网页的内容。现在主要看看效率能不能再提高点和有没有逻辑方面的bug,个人认为那几个foreach不太好,但暂时又没想到改进的办法
--------------------编程问答-------------------- 无语。
飘过!!!!!!
上班时间,谢绝闲聊,若要强聊,每字伍毛;标点符号,半价收费,千字以上,八折优惠;表情图片,十块包月,语音视频,暂未开通;先款后聊,款到即聊,在线支付,提供发票;免付月租,单项收费,节假双休,照常营业;诚征代理,各地独一,急聘聊手,专兼均可。 --------------------编程问答-------------------- 看得好累
补充:.NET技术 , C#