绑定数据的代码 如下 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class AdvanceSearch_BylawSearch : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.WebViewer1.ViewerType = GrapeCity.ActiveReports.Web.ViewerType.FlashViewer;
Report.Empty EmptyRpt = new Report.Empty();
this.WebViewer1.Report = EmptyRpt;
}
private System.Data.DataSet SearchFileInfo(List<string> StrDepartIdList, string StrStartTime, string StrEndTime, string StrProjTypeId)
{
//调用联合查询过程
//string TablesName = "T_ProjectInvestPlan"
// + " left join T_ProjectInfo on T_ProjectInvestPlan.ProjectId = T_ProjectInfo.ProjectId"; ;
string TablesName = " T_ProjectInvestPlan "
+ " left join ( T_ProjectInfo left join T_DepartInfo on T_ProjectInfo.DepartId = T_DepartInfo.DepartId ) "
+ " on T_ProjectInvestPlan.ProjectId = T_ProjectInfo.ProjectId ";
string Fileds = " T_DepartInfo.DepartId, T_ProjectInvestPlan.Year,T_ProjectInvestPlan.YearCountryInvest,T_ProjectInvestPlan.YearSelfInvest,T_DepartInfo.DepartName ";
string StrSort = " T_ProjectInfo.DepartId ";
string FiliterString = string.Empty;
string StrSQL = "select " + Fileds + " from " + TablesName;
for (int index = 0; index < StrDepartIdList.Count; index++)
{
if (index == 0)
{
FiliterString += string.IsNullOrEmpty(StrDepartIdList[index]) == true ? "" : " T_ProjectInfo.DepartId='" + StrDepartIdList[index] + "'";
}
else
{
FiliterString += string.IsNullOrEmpty(StrDepartIdList[index]) == true ? "" : " or T_ProjectInfo.DepartId='" + StrDepartIdList[index] + "'";
}
}
if (string.IsNullOrEmpty(StrProjTypeId) == false && StrProjTypeId != "-1" && StrProjTypeId != "2")
{
FiliterString = FiliterString + (FiliterString.Equals(string.Empty) ? string.Empty : " and ")
+ "T_ProjectInfo.ProjectTypeId='" + StrProjTypeId + "' ";
}
if (string.IsNullOrEmpty(StrStartTime) == false
&& string.IsNullOrEmpty(StrEndTime) == false)
{
FiliterString = FiliterString + (FiliterString.Equals(string.Empty) ? string.Empty : " and ")
+ "T_ProjectInvestPlan.Year >= '" + StrStartTime + "' and T_ProjectInvestPlan.Year <= '"
+ StrEndTime + "'";
}
//if (!FiliterString.Equals(string.Empty)) { StrSQL += " where "; }
StrSQL += FiliterString.Equals(string.Empty) ? string.Empty : " where " + FiliterString;
//StrSQL += FiliterString;
StrSQL += " order by " + StrSort;
//按projectId,departId查找FileInfo表,得到所查询项目的全部文件
System.Data.DataSet ResultDataSet = null;
ResultDataSet = new PMWeb.DBUtility.DatabaseHelper().ExecuteDataSet(StrSQL);
return ResultDataSet;
}
///<summary>
/// 得到CheckBoxList中选中了的值
/// </summary>
/// <param name="checkList">CheckBoxList</param>
/// <param name="separator">分割符号</param>
/// <returns>01,02,03</returns>
private List<string> GetCheckedValue(CheckBoxList checkList)
{
List<string> StrList = new List<string>();
for (int i = 0; i < checkList.Items.Count; i++)
{
if (checkList.Items.Selected)
{
StrList.Add(checkList.Items.Value);
}
}
return StrList;
}
protected void startFileStatistics_Click(object sender, EventArgs e)
{
this.WebViewer1.ViewerType = GrapeCity.ActiveReports.Web.ViewerType.FlashViewer;
GrapeCity.ActiveReports.PageReport report1 = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../Report/DepartInvestReport.rdlx")));
report1.Document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(Document_LocateDataSource);
WebViewer1.PdfExportOptions.FitWindow = false;
WebViewer1.PdfExportOptions.DisplayMode = GrapeCity.ActiveReports.Export.Pdf.Section.DisplayMode.Outlines;
WebViewer1.Report = report1;
}
void Document_LocateDataSource(object sender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args)
{
if (args.DataSourceName == "DataSource1")
{
if (args.DataSetName == "DataSet1")
{
args.Data = GetData();
}
}
}
private System.Data.DataTable GetData()
{
//锁定项目
List<string> StrDepartIdList = GetCheckedValue(this.selDepartName);
string StrProjStartTime = this.StartTime.Value;
string StrProjEndTime = this.EndTime.Value;
string StrProjTypeId = this.ProjectTypeId.Items[this.ProjectTypeId.SelectedIndex].Value;
if (StrDepartIdList.LongCount() == 0)
{
ClientScript.RegisterStartupScript(this.GetType(), " ", "<scriptlanguage='javascript' >alert('请选择建设单位!');</script>");
}
if (StrProjStartTime.Equals(string.Empty) || StrProjEndTime.Equals(string.Empty))
{
ClientScript.RegisterStartupScript(this.GetType(), " ", "<scriptlanguage='javascript' >alert('请填写起止年度!');</script>");
}
System.Data.DataSet ds = SearchFileInfo(StrDepartIdList, StrProjStartTime, StrProjEndTime, StrProjTypeId);
System.Data.DataTable dt = ds.Tables[0];
System.Data.DataTable ResultDt = new System.Data.DataTable();
ResultDt.Columns.Add("DepartName");
ResultDt.Columns.Add("Year");
ResultDt.Columns.Add("YearDepartCountryInvest");
ResultDt.Columns.Add("YearDepartSelfInvest");
ResultDt.Columns.Add("YearDepartTotalInvest");
//ResultDt.Rows.Add("国家海洋技术中心",2013,1000.0000,20.0000);
foreach (string d in StrDepartIdList)
{
string StrDepartName = string.Empty;
for (int y = int.Parse(StrProjStartTime); y <= int.Parse(StrProjEndTime); y++)
{
double YearDepartCountryInvest = 0;
double YearDepartSelfInvest = 0;
double YearDepartTotalInvest = 0;
foreach (System.Data.DataRow dr in dt.Rows)
{
if(int.Parse(dr[1].ToString()) == y && dr[0].ToString() == d)
{
YearDepartCountryInvest += double.Parse(dr[2].ToString());
YearDepartSelfInvest += double.Parse(dr[3].ToString());
YearDepartTotalInvest += YearDepartCountryInvest + YearDepartTotalInvest;
StrDepartName = dr[4].ToString();
}
}
if (YearDepartTotalInvest != 0)
{ ResultDt.Rows.Add(StrDepartName, y, YearDepartCountryInvest, YearDepartSelfInvest, YearDepartTotalInvest); }
}
}
return ResultDt;
}
} |