sharepoint 查询统计list数据,使用CAML联合datatable方法
2013-06-04 11:02
387 查看
需求;根据审批结果,统计上月个人,部门。财务已批准和未批准的综合。各种复杂技术不赘述。
新浪微博 jasondct
/// <summary>
/// 计算时间范围内各类审批统计
/// </summary>
/// <param name="monthfirst">月处</param>
/// <param name="monthend">月末</param>
protected void GetCostBudge(DateTime monthfirst, DateTime monthend)
{
//转换时间
string monthfirst1 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(monthfirst);
string monthend1 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(monthend);
//获得当前列表
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb("expense"))
{
SPList list = web.Lists["EBRL"];
SPQuery Query = new SPQuery();
Query.Query = string.Format(@"<Where><And><Geq><FieldRef Name='SubmitTime' /><Value IncludeTimeValue='TRUE' Type='DateTime'>{0}</Value>
</Geq><Leq><FieldRef Name='SubmitTime' /><Value IncludeTimeValue='TRUE' Type='DateTime'>{1}</Value></Leq></And></Where>",monthfirst1, monthend1 );
Query.ViewFields = @"<FieldRef Name='FreeType' />
<FieldRef Name='Total'/>
<FieldRef Name='State'/>
<FieldRef Name='Dep'/>
<FieldRef Name='DepID'/>
<FieldRef Name='ApplyName'/> ";
DataTable mydt = list.GetItems(Query).GetDataTable();
if (mydt != null)
{
//先得到个人总数 txtUntreatedGross
txtUsedGross.Text = mydt.Compute("Sum(Total)", "State = 1 and ApplyName ='"+labUserName.Text+"'").ToString();
txtUntreatedGross.Text = mydt.Compute("Sum(Total)", "State = 0 and ApplyName='" + labUserName.Text + "'").ToString();
//再获取个人费用类型内的总数
txtMonth.Text = mydt.Compute("Sum(Total)", "State = 1 and ApplyName ='" + labUserName.Text + "' and FreeType='" + labListName.Text + "'").ToString();
txtUntreated.Text = mydt.Compute("Sum(Total)", "State = 0 and ApplyName ='" + labUserName.Text + "' and FreeType='" + labListName.Text + "'").ToString();
//如果是xx部门只有二级部门
string[] getFunctionDep = labDep.Text.Split('-');
if (getFunctionDep[0].Contains("xx") && getFunctionDep.Length>1)
{
string FunctionDep = GetDepID(getFunctionDep[0]) + "-" + GetDepID(labDep.Text.Trim());
//二级部门已处理 Dep
txtUsedTwo.Text = mydt.Compute("Sum(Total)", "State = 1 and DepID ='" + FunctionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//二级部门待处理
txtUntreatedTwo.Text = mydt.Compute("Sum(Total)", "State = 0 and DepID ='" + FunctionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//txtUsedTwo.Text = mydt.Compute("Sum(Total)", "State = 1 and DepID ='" + FunctionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//txtUntreatedOne.Text = mydt.Compute("Sum(Total)", "State = 0 and DepID ='" + FunctionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//得到总数
txtUsedGross.Text = mydt.Compute("Sum(Total)", "State = 1 and DepID ='" + FunctionDep + "'").ToString();
txtUntreatedGross.Text = mydt.Compute("Sum(Total)", "State = 0 and DepID ='" + FunctionDep + "'").ToString();
}
else
{
//根据登录者部门获得三级部门
//逐级获得部门ID并赋值给
//给一级部门赋值 txtUsedUnit
if (!labDep.Text.Contains("-"))
{
//获得DepID
string ItemDepID = "";
string DepID = GetDepID(labDep.Text);
//一级部门已处理
txtUsedUnit.Text = mydt.Compute("Sum(Total)", "State = 1 and substring(DepID,1,6) ='" + DepID + "' and FreeType='" + labListName.Text + "'").ToString();
//一级部门待处理
txtUntreatedOne.Text = mydt.Compute("Sum(Total)", "State = 0 and substring(DepID,1,6) ='" + DepID + "' and FreeType='" + labListName.Text + "'").ToString();
//得到总数
txtUsedGross.Text = mydt.Compute("Sum(Total)", "State = 1 and substring(DepID,1,6) ='" + DepID + "'").ToString();
txtUntreatedGross.Text = mydt.Compute("Sum(Total)", "State = 0 and substring(DepID,1,6) ='" + DepID + "'").ToString();
}
else
{
string[] myarr = labDep.Text.Split('-');
//定义一个公共值,首先获取此人是一级部门
string recursionDep = string.Empty;
string recursionDep1 =GetDepID( myarr[0]);
recursionDep = recursionDep1;
//一级部门已处理
txtUsedUnit.Text = mydt.Compute("Sum(Total)", "State = 1 and substring(DepID,1,6) ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//一级部门待处理
txtUntreatedOne.Text = mydt.Compute("Sum(Total)", "State = 0 and substring(DepID,1,6) ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//得到总数
txtUsedGross.Text = mydt.Compute("Sum(Total)", "State = 1 and substring(DepID,1,6) ='" + recursionDep + "'").ToString();
txtUntreatedGross.Text = mydt.Compute("Sum(Total)", "State = 0 and substring(DepID,1,6) ='" + recursionDep + "'").ToString();
///////////////////////////////////////////////////////TWO////////////////////////////////////////////////
string recursionDep2 =GetDepID( myarr[0]+"-"+ myarr[1]);
recursionDep += "-" + recursionDep2;
//二级部门已处理 Dep
txtUsedTwo.Text = mydt.Compute("Sum(Total)", "State = 1 and substring(DepID,1,13) ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//二级部门待处理
txtUntreatedTwo.Text = mydt.Compute("Sum(Total)", "State = 0 and substring(DepID,1,13) ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
////////////////////////////////////////////////////three/////////////////////////////////////////////////
try
{
string recursionDep3 = GetDepID(myarr[0]+"-"+ myarr[1]+"-"+myarr[2]);
recursionDep += "-" + recursionDep3;
txtUsedthree.Text = mydt.Compute("Sum(Total)", "State = 1 and DepID ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
txtUntreatedthree.Text = mydt.Compute("Sum(Total)", "State = 0 and DepID ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
}
catch
{
}
}
}
}
}
}
}
新浪微博 jasondct
/// <summary>
/// 计算时间范围内各类审批统计
/// </summary>
/// <param name="monthfirst">月处</param>
/// <param name="monthend">月末</param>
protected void GetCostBudge(DateTime monthfirst, DateTime monthend)
{
//转换时间
string monthfirst1 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(monthfirst);
string monthend1 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(monthend);
//获得当前列表
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb("expense"))
{
SPList list = web.Lists["EBRL"];
SPQuery Query = new SPQuery();
Query.Query = string.Format(@"<Where><And><Geq><FieldRef Name='SubmitTime' /><Value IncludeTimeValue='TRUE' Type='DateTime'>{0}</Value>
</Geq><Leq><FieldRef Name='SubmitTime' /><Value IncludeTimeValue='TRUE' Type='DateTime'>{1}</Value></Leq></And></Where>",monthfirst1, monthend1 );
Query.ViewFields = @"<FieldRef Name='FreeType' />
<FieldRef Name='Total'/>
<FieldRef Name='State'/>
<FieldRef Name='Dep'/>
<FieldRef Name='DepID'/>
<FieldRef Name='ApplyName'/> ";
DataTable mydt = list.GetItems(Query).GetDataTable();
if (mydt != null)
{
//先得到个人总数 txtUntreatedGross
txtUsedGross.Text = mydt.Compute("Sum(Total)", "State = 1 and ApplyName ='"+labUserName.Text+"'").ToString();
txtUntreatedGross.Text = mydt.Compute("Sum(Total)", "State = 0 and ApplyName='" + labUserName.Text + "'").ToString();
//再获取个人费用类型内的总数
txtMonth.Text = mydt.Compute("Sum(Total)", "State = 1 and ApplyName ='" + labUserName.Text + "' and FreeType='" + labListName.Text + "'").ToString();
txtUntreated.Text = mydt.Compute("Sum(Total)", "State = 0 and ApplyName ='" + labUserName.Text + "' and FreeType='" + labListName.Text + "'").ToString();
//如果是xx部门只有二级部门
string[] getFunctionDep = labDep.Text.Split('-');
if (getFunctionDep[0].Contains("xx") && getFunctionDep.Length>1)
{
string FunctionDep = GetDepID(getFunctionDep[0]) + "-" + GetDepID(labDep.Text.Trim());
//二级部门已处理 Dep
txtUsedTwo.Text = mydt.Compute("Sum(Total)", "State = 1 and DepID ='" + FunctionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//二级部门待处理
txtUntreatedTwo.Text = mydt.Compute("Sum(Total)", "State = 0 and DepID ='" + FunctionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//txtUsedTwo.Text = mydt.Compute("Sum(Total)", "State = 1 and DepID ='" + FunctionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//txtUntreatedOne.Text = mydt.Compute("Sum(Total)", "State = 0 and DepID ='" + FunctionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//得到总数
txtUsedGross.Text = mydt.Compute("Sum(Total)", "State = 1 and DepID ='" + FunctionDep + "'").ToString();
txtUntreatedGross.Text = mydt.Compute("Sum(Total)", "State = 0 and DepID ='" + FunctionDep + "'").ToString();
}
else
{
//根据登录者部门获得三级部门
//逐级获得部门ID并赋值给
//给一级部门赋值 txtUsedUnit
if (!labDep.Text.Contains("-"))
{
//获得DepID
string ItemDepID = "";
string DepID = GetDepID(labDep.Text);
//一级部门已处理
txtUsedUnit.Text = mydt.Compute("Sum(Total)", "State = 1 and substring(DepID,1,6) ='" + DepID + "' and FreeType='" + labListName.Text + "'").ToString();
//一级部门待处理
txtUntreatedOne.Text = mydt.Compute("Sum(Total)", "State = 0 and substring(DepID,1,6) ='" + DepID + "' and FreeType='" + labListName.Text + "'").ToString();
//得到总数
txtUsedGross.Text = mydt.Compute("Sum(Total)", "State = 1 and substring(DepID,1,6) ='" + DepID + "'").ToString();
txtUntreatedGross.Text = mydt.Compute("Sum(Total)", "State = 0 and substring(DepID,1,6) ='" + DepID + "'").ToString();
}
else
{
string[] myarr = labDep.Text.Split('-');
//定义一个公共值,首先获取此人是一级部门
string recursionDep = string.Empty;
string recursionDep1 =GetDepID( myarr[0]);
recursionDep = recursionDep1;
//一级部门已处理
txtUsedUnit.Text = mydt.Compute("Sum(Total)", "State = 1 and substring(DepID,1,6) ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//一级部门待处理
txtUntreatedOne.Text = mydt.Compute("Sum(Total)", "State = 0 and substring(DepID,1,6) ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//得到总数
txtUsedGross.Text = mydt.Compute("Sum(Total)", "State = 1 and substring(DepID,1,6) ='" + recursionDep + "'").ToString();
txtUntreatedGross.Text = mydt.Compute("Sum(Total)", "State = 0 and substring(DepID,1,6) ='" + recursionDep + "'").ToString();
///////////////////////////////////////////////////////TWO////////////////////////////////////////////////
string recursionDep2 =GetDepID( myarr[0]+"-"+ myarr[1]);
recursionDep += "-" + recursionDep2;
//二级部门已处理 Dep
txtUsedTwo.Text = mydt.Compute("Sum(Total)", "State = 1 and substring(DepID,1,13) ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
//二级部门待处理
txtUntreatedTwo.Text = mydt.Compute("Sum(Total)", "State = 0 and substring(DepID,1,13) ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
////////////////////////////////////////////////////three/////////////////////////////////////////////////
try
{
string recursionDep3 = GetDepID(myarr[0]+"-"+ myarr[1]+"-"+myarr[2]);
recursionDep += "-" + recursionDep3;
txtUsedthree.Text = mydt.Compute("Sum(Total)", "State = 1 and DepID ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
txtUntreatedthree.Text = mydt.Compute("Sum(Total)", "State = 0 and DepID ='" + recursionDep + "' and FreeType='" + labListName.Text + "'").ToString();
}
catch
{
}
}
}
}
}
}
}
相关文章推荐
- 使用list方法插入datatable中的数据到数据库
- sharepoint 2010 列表的数据表视图无法使用 the list cannot be displayed in datasheet view 解决方法
- DataTable数据表的使用(联合GridView)
- Char绑定list数据,DataTable.Compute方法
- sharepoint通过excel导入list时报错:导入数据时(方法'Post'作用于对象'IOWSPostData'时失败)
- SharePoint内容定制之XSLT高级用法——使用Muenchian方法分组XML数据
- 写student类中的select,delete,update,insert方法并在objectDataSource中应用(分别写两个,一个返回datatable,一个使用list)
- Android中的使用ListView控件显示List集合中的数据,并对Item响应选择事件(方法二)
- 写student类中的select,delete,update,insert方法并在objectDataSource中应用(分别写两个,一个返回datatable,一个使用list)
- 1.写student类中的select,delete,update,insert方法并在objectDataSource中应用(分别写两个,一个返回datatable,一个使用list)
- SharePoint 2010 使用url参数过滤列表视图数据(使用get方法过滤列表数据)
- SharePoint内容定制之XSLT高级用法——使用Muenchian方法分组XML数据
- 使用Collections.sort()方法扩展list集合中的数据并对其进行排序
- 写student类中的select,delete,update,insert方法并在objectDataSource中应用(分别写两个,一个返回datatable,一个使用list)
- 写student类中的select,delete,update,insert方法并在objectDataSource中应用(分别写两个,一个返回datatable,一个使用list)
- 使用wxsqlite3后多表联合查询无数据的问题解决方法
- 使用扩展方法将datatable化成list,list转成datatable
- List使用add方法添加数据时的覆盖问题
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(9):服务器端和客户端数据类型的自动转换:DataTable和DataSet
- 使用扩展方法将DataTable转换为List<T>