接上一篇《hibernate+spring+mvc+Easyui框架模式下使用grid++report的总结》对grid++report做进一步开发

先写一下实现流程:

1、默认为全部载入

使用grid++report打印选中行-LMLPHP

2、双击一行后将记录改行的数据,并显示在上方div中

使用grid++report打印选中行-LMLPHP

3、点击div中各单元的X可以进行单元删除(上图删除了超级管理员显示如下)

使用grid++report打印选中行-LMLPHP

4、点击载入选中项后,对数据进行过滤,筛选出选中项

使用grid++report打印选中行-LMLPHP

5、全部删除后,默认查询出所有项

使用grid++report打印选中行-LMLPHP

6、所有项

使用grid++report打印选中行-LMLPHP

7、重新载入后可以选择打印,就相当于打印当前页面了

下面贴代码。

html

 <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>报表</title>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%:Styles.Render("~/Content/easyui/css")%>
<%:Styles.Render("~/Content/Index/css")%>
<%:Scripts.Render("~/bundles/jquery")%>
<%:Scripts.Render("~/Scripts/jquery-1.8.0.min.js")%>
<%:Scripts.Render("~/Scripts/easyUI/jquery.min.js")%>
<%:Scripts.Render("~/Scripts/easyUI/jquery.easyui.min.js")%>
<%:Scripts.Render("~/Scripts/jquery.uploadify.js")%>
<%:Scripts.Render("~/bundles/easyui")%>
<%:Styles.Render("~/Content/uploadify/uploadify.css")%>
<%:Scripts.Render("~/Content/CreateControl.js")%>
<script type="text/javascript">
//在网页初始加载时启动报表的运行显示
function window_onload() {
btnRefresh_onclick();
} //打印预览报表
function btnPreview_onclick() {
ReportViewer.Report.PrintPreview(true);
} //根据数据过滤参数重新显示报表
function btnRefresh_onclick() {
ReportViewer.Stop();
ReportViewer.DataURL = "user/load";
// var BeginDate = document.getElementById("txtBeginDate").value;
// var EndDate = document.getElementById("txtEndDate").value;
// var DataURL = encodeURI("xmlSummary.aspx?BeginDate=" + BeginDate + "&EndDate=" + EndDate);
// ReportViewer.DataURL = DataURL; //更新查询参数更新报表付标题,设置对应静态框的“Text”属性
//ReportViewer.Report.ControlByName("SubTitle").AsStaticBox.Text = "日期范围:" + BeginDate + "至" + EndDate;
ReportViewer.Start();
}
var str_Check = ""; //用于存放由选中而生成的html
var str_CheckId = ""; //用于存放选中的id 格式为‘1’,‘2’
//双击的时候div中添加显示
function btnDrillDown_onclick() {
var ProductName = ReportViewer.Report.FieldByName("Name").AsString; //要在html中显示的字段
var ID = ReportViewer.Report.FieldByName("ID").AsString; //获取id
var IDs = "'" + ID + "'";
var str_CheckIdArry = str_CheckId.split(',');
//判断是否已经存在防止重复添加
var isExist = false;
for (var i = 0; i < str_CheckIdArry.length; i++) {
if (str_CheckIdArry[i] == IDs) {
isExist = true;
}
}
//不存在的时候添加进去
if (!isExist) {
//添加到html字符串中
str_Check += "<div style='float: left;cursor:hand; border-width:1px; border-color:lightblue;border-style:solid;width:100px' id='sl_" + ID + "'>" + ProductName + "<img src='../../../../Content/easyUi/themes/icons/cancel.png' onclick=\"deleteIt('" + ID + "')\" style='float:right;width:10px;height:10px'/></div>";
//添加到id中
str_CheckId += IDs + ",";
//将html加载到页面中去
$("#selectedRow").html(str_Check);
}
//存在的时候提示
else {
alert("该行已选择!");
} }
//点击删除的时候把添加进去的单元进行删除
function deleteIt(id) { var IDs = "'" + id + "'";
var str_CheckIdArry = str_CheckId.split(',');
var isExist = false;
var str_CheckIdTemp = "";
str_Check = "";
//根据id是否重复进行排除
for (var i = 0; i < str_CheckIdArry.length; i++) {
if (str_CheckIdArry[i] != IDs && str_CheckIdArry[i] != "") {
str_CheckIdTemp += str_CheckIdArry[i] + ",";
}
}
//排除掉删除的单元后的id组合
str_CheckId = str_CheckIdTemp;
//移除单元的html
$("#sl_" + id).remove();
//移除单元后剩余的html
str_Check = $("#selectedRow").html(); }
//点击载入选中项将信息载入到当前页面。
function btn_dyxzx_onclick() {
ReportViewer.Stop();
if (str_CheckId.length > 0) {
str_CheckId = str_CheckId.substr(0, str_CheckId.length - 1);
}
//传递参数从后台获取数据源
ReportViewer.DataURL = "user/dyxzx?id=" + str_CheckId; ReportViewer.Start();
}
function OnContentCellDblClick(Sender) //响应内容行双击事件,打开当前行对应的明细报表
{
btnDrillDown_onclick();
}
</script>
<style type="text/css">
html, body
{
margin: 0;
height: 100%;
}
</style>
</head>
<body style="margin: 0; background-color: #f0ffff;" onload="window_onload()">
<table border="0" width="100%" height="100%">
<tr>
<td colspan="5">
<div id="selectedRow" style="width: 100%; height: auto">
</div>
</td>
</tr>
<tr style="width: 100%;">
<%-- <td style="font-size: 10pt; height: 23px; width: 50%;">
开始日期:<input id="txtBeginDate" type="text" value="1997-1-1" name="txtBeginDate" maxlength="20"
style="width: 84px">
结束日期:<input id="txtEndDate" type="text" value="1997-12-31" name="txtEndDate" maxlength="20"
style="width: 80px" />
<input id="btnRefresh" onclick="return btnRefresh_onclick()" type="button" value="更新显示"
name="btnRefresh" />
</td>--%>
<td colspan="5" style="font-size: 10pt; height: 23px; width: 50%;">
<input id="btnPreview" onclick="return btnPreview_onclick()" type="button" value="打印预览"
name="btnPreview" />
<%-- <input id="btnDrillDown" onclick="return btnDrillDown_onclick()" type="button" value="明细报表"
name="btnDrillDown" />--%>
<input id="btn_dyxzx" onclick="return btn_dyxzx_onclick()" type="button" value="载入选中项"
name="btn_dyxzx" />
</td>
</tr>
<tr style="height: 100%;">
<td colspan="5" style="font-size: 10pt;">
<script type="text/javascript">
CreateDisplayViewerEx("100%", "100%", "../../../../grf/user.grf", "", false, "<param name=BorderStyle value=1>" +
"<param name='OnContentCellDblClick' value='OnContentCellDblClick'>");
</script>
</td>
</tr>
</table>
</body>
</html>

c#

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using CLGL.Web.Controllers;
using System.Text;
using Wat.Common;
using Domain;
using System.IO.Compression;
using Newtonsoft.Json;
using System.Globalization;
using Common.ToolsHelper; namespace CLGL.Web.Areas.GrfDemo.Controllers
{
public class UserController : Controller
{
//
// GET: /GrfDemo/User/
Service.IUserManager userManage { get; set; }
//User user = new User();
public ActionResult Index()
{
return View();
}
/// <summary>
/// 默认载入所有项
/// 创建标识:guohao
/// </summary>
/// <returns></returns>
public ActionResult Load()
{
IList<User> list = userManage.LoadAll();
string str = XMLHelperToList<User>.EntityToXml(list);
Response.Write(str);
Response.End();
return View();
}
/// <summary>
/// 载入选中项
/// 创建标识:guohao
/// </summary>
/// <param name="id">id组合格式‘1',‘2’</param>
/// <returns></returns>
public ActionResult dyxzx(string id)
{
if (id == "")//如果id为空的话全部载入
{
IList<User> list = userManage.LoadAll();
string str = XMLHelperToList<User>.EntityToXml(list);
Response.Write(str);
Response.End();
}
else//如果不为空的话,载入选中项
{
IList<User> list = userManage.LoadAll();
var listSlect = (from r in list
where id.Contains(r.Id)
select new
{
r.Id,
r.Name,
r.Account,
r.Password,
r.IsCanLogin,
r.ShowOrder1,
r.ShowOrder2,
r.CreatePer,
r.CreateDpt,
r.CreateDate,
r.Dpt,
r.Phone,
r.OfficePhone,
r.SexCode,
r.EmailAddress
});
IList<User> listselect = new List<User>();
//循环到List中
foreach (var a in listSlect)
{
User user = new User();
user.Id = a.Id;
user.Name = a.Name;
user.Account = a.Account;
user.Password = a.Password;
user.IsCanLogin = a.IsCanLogin;
user.ShowOrder1 = a.ShowOrder1;
user.ShowOrder2 = a.ShowOrder2;
user.CreatePer = a.CreatePer;
user.CreateDpt = a.CreateDpt;
user.CreateDate = a.CreateDate;
user.Dpt = a.Dpt;
user.Phone = a.Phone;
user.OfficePhone = a.OfficePhone;
user.SexCode = a.SexCode;
user.EmailAddress = a.EmailAddress;
listselect.Add(user);
}
//转为xml字符串
string str = XMLHelperToList<User>.EntityToXml(listselect);
//push
Response.Write(str);
Response.End();
}
return View();
}
}
}

还有其他好用的方式请留言讨论,报表画的烂,请担待

05-06 04:13