string username = SPContext.Current.Web.CurrentUser.Name;
if (username != null)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(SPContext.Current.Site.ID))
{
using (web = site.OpenWeb())
{
string where = @"<Where><And><Contains><FieldRef Name='AssignedTo' /><Value Type='User'>" + username + "</Value></Contains><And><Leq><FieldRef Name='DueDate' /><Value Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now) + "</Value></Leq><Or><Eq><FieldRef Name='Status' /><Value Type='Choice'>Not Started</Value></Eq><Eq><FieldRef Name='Status' /><Value Type='Choice'>In Progress</Value></Eq></Or></And></And></Where>";
SPSiteDataQuery query = new SPSiteDataQuery();
query.Webs = "<Webs Scope='SiteCollection'>";
query.Lists = "<Lists ServerTemplate='171'/>";
query.ViewFields = "<FieldRef Name='Title' Type='Text'/>";
query.ViewFields += "<FieldRef Name='StartDate' />";
query.ViewFields += "<FieldRef Name='DueDate' />";
query.ViewFields += "<FieldRef Name='Status' />";
query.ViewFields += "<FieldRef Name='Assigned_To' Type='UserMulti' Nullable='TRUE' />";
query.ViewFields += "<FieldRef Name='TestUser' Type='User' Nullable='True'/>";
query.ViewFields += "<FieldRef Name='PercentComplete' Type='Number' Nullable='TRUE' />";
query.ViewFields += "<FieldRef Name='Remarks' />";
query.Query = where;
DataTable dt = web.GetSiteData(query);
//foreach (DataRow row in dt.Rows)
//{
// string name = row["Assigned_To"].ToString();
//}
if (dt.Rows.Count > 0)
{
gvlist.DataSource = dt;
gvlist.DataBind();
}
else
{
lblEmpty.Text = "No Records Found";
}
}
}
});
}
if (username != null)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (site = new SPSite(SPContext.Current.Site.ID))
{
using (web = site.OpenWeb())
{
string where = @"<Where><And><Contains><FieldRef Name='AssignedTo' /><Value Type='User'>" + username + "</Value></Contains><And><Leq><FieldRef Name='DueDate' /><Value Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now) + "</Value></Leq><Or><Eq><FieldRef Name='Status' /><Value Type='Choice'>Not Started</Value></Eq><Eq><FieldRef Name='Status' /><Value Type='Choice'>In Progress</Value></Eq></Or></And></And></Where>";
SPSiteDataQuery query = new SPSiteDataQuery();
query.Webs = "<Webs Scope='SiteCollection'>";
query.Lists = "<Lists ServerTemplate='171'/>";
query.ViewFields = "<FieldRef Name='Title' Type='Text'/>";
query.ViewFields += "<FieldRef Name='StartDate' />";
query.ViewFields += "<FieldRef Name='DueDate' />";
query.ViewFields += "<FieldRef Name='Status' />";
query.ViewFields += "<FieldRef Name='Assigned_To' Type='UserMulti' Nullable='TRUE' />";
query.ViewFields += "<FieldRef Name='TestUser' Type='User' Nullable='True'/>";
query.ViewFields += "<FieldRef Name='PercentComplete' Type='Number' Nullable='TRUE' />";
query.ViewFields += "<FieldRef Name='Remarks' />";
query.Query = where;
DataTable dt = web.GetSiteData(query);
//foreach (DataRow row in dt.Rows)
//{
// string name = row["Assigned_To"].ToString();
//}
if (dt.Rows.Count > 0)
{
gvlist.DataSource = dt;
gvlist.DataBind();
}
else
{
lblEmpty.Text = "No Records Found";
}
}
}
});
}
No comments:
Post a Comment