/// <reference path="ReportBuilder.core.js" />
/// <reference path="../../../JS/jquery-ui.min.js" />
/// <reference path="../../../JS/jquery.min.js" />
var ReportMain = null;
var paperWidth = 20.9;
var paperHeight = 29.7;
var gridLength = 0.5; //cm
var ZIndex = 1;
var winPage = null;
var SelectedCellControl = null;
var InfoTree = null;
var dsTree = null;
var UserTable = null;
var LastDragControl = null;
var ControlPropPanel = null;
var PropPanel = null;
var TemplateID = 10089;
var ReportID = 0;
var Table = null;
var DataSourceObj = [];
function OnPageLoad(page, pars) {
if (pars) {
TemplateID = pars.TemplateID || 10089;
ReportID = pars.ReportID || 0;
Table = pars.Table || null;
}
page.ActionPanel = $("#action_div");
dsTree = page.ActionPanel.find("#ds_tree").Tree();
ControlPropPanel = $("#ReportAttrPanel").PropertyPanel();
ControlPropPanel.OnChange(ControlPropertyChanged);
PropPanel = $("#ReportAttrPanel").PropertyPanel();
PropPanel.OnChange(PropertyPanelChanged);
LoadToolBar();
loadControlTree();
LoadReport();
BindEvent();
InitMenu();
}
var InitMenu = function () {
$("#designer_menu").menu({
hideOnUnhover: false,
onClick: function (item) {
var ctrl = ReportMain.SelectedReportControl;
if (ctrl) {
ctrl.ExcuteMenuCommand(item.name, item.target);
}
}
});
$(".report-designer").bind('contextmenu', function (e) {
var container = $(e.target).closest(".ctrl-container");
if (container && container.length > 0) {
var ctrlID = container.attr("ControlID");
var ctrl = ReportMain.GetControlByID(ctrlID);
if (ctrl) {
var menu = $('#designer_menu');
menu.children().each(function () {
if (!$(this).hasClass("menu-line")) {
menu.menu("removeItem", this);
}
});
var menus = ctrl.MenuItems;
var panelCtrl = ctrl;
if (ctrl.ParentControl != null && ctrl.ParentControl.IsIReportPanel) {
menus = ctrl.ParentControl.MenuItems;
if (ctrl instanceof ReportTextBox) {
menus = ([]).concat(menus);
menus.Insert(0, {
separator: true
}).Insert(0, {
id: "m_ReportTextBoxSameRowStyle",
text: "同行应用样式",
name: "TextBoxSameRowStyle",
iconCls: "icon-edit"
}).Insert(1, {
id: "m_ReportTextBoxSameColStyle",
text: "同列应用样式",
name: "TextBoxSameColStyle",
iconCls: "icon-edit"
});
}
panelCtrl = ctrl.ParentControl;
}
var setIconItems = ["Star", "Auto", "Pixel"];
if (menus) {
for (var i = 0; i < menus.length; i++) {
var mitem = menus[i];
menu.menu("appendItem", mitem);
if (mitem.children && mitem.children.length > 0) {
var rowHeightType = "";
var rowIndex = panelCtrl.SelectedRowIndex;
if (panelCtrl instanceof ReportLayoutTable) {
var rowDefines = panelCtrl.ListRowDefines || [];
var rowDefine = rowDefines.First(function (d) { return d.Row == rowIndex; });
rowHeightType = rowDefine ? rowDefine.GridUnitType : "";
}
else if (panelCtrl instanceof ReportTable) {
var row = panelCtrl.DataRow;
if (rowIndex == 0) {
row = panelCtrl.Header;
}
else if (rowIndex == 1) {
row = panelCtrl.DataRow;
}
else if (rowIndex == 2) {
row = panelCtrl.Footer;
}
rowHeightType = row.RowHeightUnitType;
}
var colDefines = panelCtrl.ListColDefines || panelCtrl.ColDefineUnits || [];
var colIndex = panelCtrl.SelectedColIndex;
var colDefine = colDefines.First(function (d) { return d.Col == colIndex; });
var colWidthType = colDefine ? colDefine.GridUnitType : "";
for (var j = 0; j < mitem.children.length; j++) {
var smitem = mitem.children[j];
if (smitem.name && setIconItems.Exist(function (o) { return smitem.name.EndsWith(o); })) {
smitem.iconCls = "";
if (smitem.name == ("Row" + rowHeightType) || smitem.name == ("Col" + colWidthType)) {
smitem.iconCls = "icon-ok";
}
}
smitem.parent = $("#" + mitem.id)[0]; //menu.menu("findItem", mitem.text).target;
menu.menu("appendItem", smitem);
}
}
}
$('#designer_menu').menu('show', {
left: e.pageX,
top: e.pageY
});
}
}
}
StopEvent(e);
});
}
//加载工具栏
var LoadToolBar = function () {
$("#ReportToolBar").ToolBar({
display: "tool-vertical",
items: [
//{ icon: "content_add", text: "新增报表", OnClick: NewReport },
//{ icon: "action_delete_forever", text: "删除报表", OnClick: DelReport },
{ icon: "action_zoom_in", text: "查看报表", OnClick: ViewReport },
//{ icon: "editor_border_color", text: "修改模版", OnClick: ModifyReport },
{ icon: "content_save", text: "保存", OnClick: SaveReport },
//{ icon: "editor_border_color", text: "另存为", OnClick: SaveAsReport },
{
icon: "editor_border_color", text: "报表属性", OnClick: ShowReportPropertyPanel
},
{
icon: "content_add", text: "添加数据源", OnClick: AddDataSource
},
{
icon: "editor_border_color", text: "修改数据源", OnClick: ModifyDataSource
},
{
icon: "editor_border_color", text: "修改数据源名称", OnClick: MidifyDataSourceName
}
]
});
};
//查看报表
var ViewReport = function () {
//EMW.UI.Dialog({
// url: "/Pages/Table/ReportViewer.aspx?rptid=" + ReportID + "&tplid=" + TemplateID,
// title: "打印报表",
//width: 1200,
//height: 800
//});
if (ReportID > 0) {
var dia = EMW.UI.Window({
url: "/page/" + ReportID,
title: "报表预览",
height: 'auto',
width: 1024
});
}
};
//显示保存结果
var ShowSaveMsg = function () {
var reportID = this.ID;
var msg = "<h3>服务器错误!!!</h3>";
if (reportID > 0) {
msg = "<h3>保存成功</h3>";
}
var winPage = EMW.UI.Dialog({
content: msg,
title: "信息提示!!!",
width: 250,
height: 180
});
}
var SaveReport = function () {
ReportMain.ActionSaveOver = ShowSaveMsg;
ReportMain.SaveReport();
}
/***************数据源操作****************/
//创建数据源名称
var CreateDSName = function () {
var DsSortID = !ReportMain.DataSources ? 1 : ReportMain.DataSources.length + 1;
var DataSourceName = "DataSource" + DsSortID;
return DataSourceName;
};
//添加数据源
var AddDataSource = function () {
var win = EMW.UI.Dialog({
url: "/pages/table/datasource.html",
title: "设置数据源",
width: 1200,
height: 800,
OnOK: function (DataSource) {
//保存新增数据源
var DsSortID = !ReportMain.DataSources ? 1 : ReportMain.DataSources.length + 1;
var DataSourceName = "DataSource" + DsSortID;
ReportMain.DataSources.push({ Name: DataSourceName, DataSource: DataSource });
BindDataSourceTree();
}
});
win.DataSource = null;
win.Table = UserTable;
win.save = "0";
};
//修改数据源
var ModifyDataSource = function () {
if (!dsTree.GetSelected()) return null;
var CurrentDataSourceName = dsTree.GetSelected().name;
var CurrentDataSourceObj = GetDataSourceByName(CurrentDataSourceName);
if (CurrentDataSourceObj == null) return null;
var CurrentDataSource = CurrentDataSourceObj.DataSource;
var index = CurrentDataSourceObj.index;
var win = EMW.UI.Dialog({
url: "/pages/table/datasource.html",
title: "设置数据源",
width: 1200,
height: 800,
OnOK: function (DataSource) {
if (!DataSource) //删除数据源
ReportMain.DataSources.splice(index, 1);
else //修改数据源
ReportMain.DataSources[index].DataSource = DataSource;
BindDataSourceTree();
}
});
win.DataSource = CurrentDataSource;
win.Table = UserTable;
win.save = "0";
}
//根据name获取DataSource
var GetDataSourceByName = function (DataSourceName) {
var obj = null
var DataSources = ReportMain.DataSources;
for (var i = 0; i < DataSources.length; i++) {
if (DataSourceName == DataSources[i].Name) {
obj = { index: i, DataSource: DataSources[i].DataSource };
}
}
return obj;
}
//修改数据源名称
var MidifyDataSourceName = function () {
if (!dsTree.GetSelected() || dsTree.GetSelected().nodeType != "DS") return null;
var TopDom = top.window.document;
var CurrentDataSourceName = $(TopDom).find("#ds_tree .selected .tree-item-text").text();//dsTree.GetSelected().name;
var content = "<div> <div class=\"inpt\" ><input id=\"iptDataSourceName\" type=\"text\" class=\"text-box\"></div></div>"
var win = EMW.UI.Dialog({
content: content,
title: "设置数据源",
width: 300,
height: 200,
OnOK: function () {
ModifyNameCallBack(CurrentDataSourceName);
}
});
win.Table = UserTable;
return win.Table;
};
var ModifyNameCallBack = function (CurrentDataSourceName) {
var TopDom = top.window.document;
var ModifyName = $(TopDom).find("#iptDataSourceName").val();
if (ModifyName == "") return null;
if (GetDataSourceByName(ModifyName) == null) {//没有找到该数据源名称表示可以修改
var index = GetDataSourceByName(CurrentDataSourceName).index;
ReportMain.DataSources[index].Name = ModifyName;
$(TopDom).find("#ds_tree .selected .tree-item-text").text(ModifyName);
}
};
//绑定
var BindDataSourceTree = function () {
dsTree.LoadData(DataSourcesToTreeData(ReportMain.DataSources));
};
//生成DS节点
var DataSourcesToTreeData = function (DataSources) {
if (DataSources == null) return [];
var dsDom = []
for (var ds = 0; ds < DataSources.length; ds++) {
var dsName = DataSources[ds].Name
var DataSource = DataSources[ds].DataSource;
dsDom.push({ id: dsName, name: dsName, text: dsName, nodeType: "DS", children: GetTableTree(DataSource) });
}
return dsDom;
};
//生成table树节点
var GetTableTree = function (DataSource, selectItemName) {
var TableDom = [];
if (DataSource) {
var main = DataSource.MainTable;
var tables = DataSource.Tables;
var childrensDom = [];
if (main) {
//var fields = main.Fields;
//for (var i = 0; i < fields.length; i++) {
// if (fields[i].Name == selectItemName) {
// childrensDom.push({
// id: fields[i].ID,
// name: fields[i].AliasName,
// text: fields[i].Name,
// nodeType: "Filed",
// icon: "action_toc",
// isSelected: true
// });
// } else {
// childrensDom.push({
// id: fields[i].ID,
// name: fields[i].AliasName,
// text: fields[i].Name,
// nodeType: "Filed",
// icon: "action_toc"
// });
// }
//}
TableDom.push({
id: main.ID,
name: main.AliasName,
text: "MainTable-" + main.Name,
nodeType: "Table",
children: GetFildedTree(main, selectItemName)
});
}
if (tables) {
for (var i = 0; i < tables.length; i++) {
//childrensDom = [];
//for (var j = 0; j < tables[i].Fields.length; j++) {
// var tablesfileds = tables[i].Fields[j];
// childrensDom.push({
// id: tablesfileds.ID,
// name: tablesfileds.AliasName,
// text: tablesfileds.Name,
// nodeType: "Filed",
// icon: "action_toc"
// });
//}
TableDom.push({
id: tables[i].ID,
name: tables[i].AliasName,
text: tables[i].Name,
nodeType: "Table",
children: GetFildedTree(tables[i], selectItemName)
});
}
}
}
return TableDom;
}
//字段节点
var GetFildedTree = function (table, selectFiledName) {
if (!table.Fields) return [];
var filedDom = [];
for (var j = 0; j < table.Fields.length; j++) {
var Fields = table.Fields[j];
if (selectFiledName == Fields.AliasName) {
filedDom.push({
id: Fields.ID,
name: Fields.AliasName,
text: Fields.Name,
tfVal: table.TableName + "." + Fields.AliasName,
nodeType: "Filed",
icon: "action_toc",
isSelected: true
});
}
else {
filedDom.push({
id: Fields.ID,
name: Fields.AliasName,
text: Fields.Name,
tfVal: table.TableName + "." + Fields.AliasName,
nodeType: "Filed",
icon: "action_toc"
});
}
}
return filedDom;
}
/*====================设计页面相关,标尺、网格====================*/
var CreateXalias = function (width) {
$(".xalias").css("width", (width + 0.1) + "cm");
var list = $(".xalias ul");
list.empty();
var count = Math.round(width);
while (count > 0) {
list.prepend("<li><span class=\"scale scale-x\">" + (count--) + "</span></li>");
}
};
var CreateYalias = function (height) {
//width:cm
$(".yalias").css("height", (height + 0.3) + "cm");
var list = $(".yalias ul");
list.empty();
var count = Math.round(height);
while (count >= 0) {
list.prepend("<li><span class=\"scale scale-y\">" + (count--) + "</span></li>");
}
}
var CreateGrid = function (width, height) {
var table = $(".designer-grid");
$(".designer-grid").css("width", width + "cm");
$(".designer-grid").css("height", height + "cm");
$(".report-designer").css("width", width + "cm");
$(".report-designer").css("height", height + "cm");
//性能太差...
//table.empty();
//var rowCount = Math.round(height / gridLength);
//while ((rowCount--) >= 0) {
// var tr = $("<tr></tr>");
// var colCount = Math.round(width / gridLength);
// while ((colCount--) >= 0) {
// tr.append("<td></td>");
// }
// table.append(tr);
//}
var rowCount = Math.round(height / gridLength);
var colCount = Math.round(width / gridLength);
var size = 0;
var row = "";
for (var i = 0; i < rowCount; i++) {
row += "<hr style=\"top:" + size + "cm; \" />"
size = size + 0.5;
}
table.append(row);
var col = "";
size = 0;
for (var i = 0; i < colCount; i++) {
col += "<div style=\" left:" + size + "cm;\"></div>";
size = size + 0.5;
}
table.append(col);
}
var ResetReportSize = function () {
CreateXalias(ReportMain.Width);
$(".designer-container").css("width", (ReportMain.Width + 0.7) + "cm");
$(".report-designer").css("width", ReportMain.Width + "cm");
CreateYalias(ReportMain.Height);
$(".designer-container").css("height", (ReportMain.Height + 0.9) + "cm");
$(".report-designer").css("height", (ReportMain.Height + 0.3) + "cm");
$(".designer-grid").html("");
paperWidth = ReportMain.Width;
paperHeight = ReportMain.Height;
CreateGrid(ReportMain.Width, ReportMain.Height);
//if (paperWidth != ReportMain.Width) {
// CreateXalias(ReportMain.Width);
// $(".designer-container").css("width", (ReportMain.Width + 0.7) + "cm");
// $(".report-designer").css("width", ReportMain.Width + "cm");
//}
//if (paperHeight != ReportMain.Height) {
// CreateYalias(ReportMain.Height);
// $(".designer-container").css("height", (ReportMain.Height + 0.9) + "cm");
// $(".report-designer").css("height", (ReportMain.Height + 0.3) + "cm");
//}
//if (paperWidth != ReportMain.Width || paperHeight != ReportMain.Height) {
// paperWidth = ReportMain.Width;
// paperHeight = ReportMain.Height;
// CreateGrid(paperWidth, paperHeight);
//}
};
var ShowMouseAlias = function (point) {
$(".mousemoveline-x").css("left", point.X);
$(".mousemoveline-y").css("top", point.Y);
}
var FixedAlias = function (e) {
var $this = $(this);
var top = $this.scrollTop();
var left = $this.scrollLeft();
$(".xalias").css("top", top <= 0 ? "" : top);
$(".yalias").css("left", left <= 0 ? "" : left);
}
var GetPoint = function (e) {
var point = { X: 0, Y: 0 };
if (e.offsetX !== undefined) {
point.X = e.offsetX || 0;
point.Y = e.offsetY || 0;
}
else { //FF
var evt = e.originalEvent;
if (evt) {
point.X = evt.layerX || 0;
point.Y = evt.layerY || 0;
}
}
return point;
}
//OnDesigner
var GetMouseAlias = function (e) {
var point = { X: e.pageX, Y: e.pageY }; //鼠标相对document的位置
var pos = ReportMain.designerPanel.offset(); //设计器相对document的位置
point.X -= pos.left;
point.Y -= pos.top;
return point;
}
//获取表格大小
var GetTableDom = function (ctrl) {
var table = "<div ControlType=\"Table\" class=\"InputTableSize\"><table style=\"margin: 0 auto;\"><tr><td>行数:</td><td><div class=\"inpt\" ><input id=\"InputTableRows\" type=\"text\" value=\"3\" class=\"text-box\"></div></td>"
+ "</tr><tr><td>列数:</td><td><div class=\"inpt\" ><input id=\"InputTableCols\" type=\"text\" value=\"3\" class=\"text-box\"></div></td></tr></table></div>"
var win = EMW.UI.Dialog({
content: table,
title: "表格大小",
width: 250,
height: 180,
OnOK: function () {
AddTableCallback(ctrl);
}
});
win.Table = UserTable;
return win.Table;
}
//获取表格行列值
var AddTableCallback = function (ctrl, window) {
var alterDom = top.window.document;
var colCount = $(alterDom).find("#InputTableCols").val();
var rowCount = $(alterDom).find("#InputTableRows").val();
if (ctrl.Type == "LayoutTable" || ctrl.Type == "CrossTable") {
ctrl.InitRowCount = rowCount;
ctrl.InitColCount = colCount;
ctrl.Width = ctrl.InitColCount * 100 + 100;
ctrl.Height = ctrl.InitRowCount * 22 + 40;
}
else if (ctrl.Type == "Table") {
ctrl.InitColCount = colCount;
ctrl.Width = ctrl.InitColCount * 100 + 100;
}
ctrl.ReportMain = ReportMain;
ctrl.CreateElement();
ReportMain.AddChild(ctrl);
ShowControlAttr(ctrl);
}
//添加新报表控件
var AddControlTolDesigner = function (ControlName, Container) {
var ctrl = new Function("return new Report" + ControlName + "();").call();
ctrl.MarginTopWidth = $(".designer").scrollTop();
if (ControlName == "LayoutTable") {
GetTableDom(ctrl);
}
else {
ctrl.ReportMain = ReportMain;
ctrl.CreateElement();
ReportMain.AddChild(ctrl);
}
}
//加载报表控件
var loadControlTree = function () {
if (!InfoTree) {
InfoTree = $("#control_tree").Tree({
data: [
{ id: 1, name: "TextBox", text: "文本框", icon: "action_info" },
{ id: 2, name: "LayoutTable", text: "布局表格", icon: "image_blur_linear" },
{ id: 3, name: "Table", text: "数据表格", icon: "av_library_books" },
{ id: 4, name: "CrossTable", text: "交叉表", icon: "action_toc" },
{ id: 5, name: "Image", text: "图片", icon: "social_group" },
{ id: 6, name: "List", text: "列表", icon: "action_chrome_reader_mode" },
{ id: 7, name: "Chart", text: "图表", icon: "image_rotate_90_degrees_ccw" }
]
}).OnDblClick(function (data) {
if (data.children == undefined) {
AddControlTolDesigner(data.name, LastDragControl);
}
});
}
}
/****加载报表****/
var LoadReport = function () {
ReportMain = new ReportManager();
ReportMain.designerPanel = $(".report-designer");
ReportMain.GridPageHeader = $(".report-header");
ReportMain.GridPageFooter = $(".report-footer");
ReportMain.ID = ReportID;
ReportMain.TemplateID = TemplateID;
ReportMain.ActionReadOver = ReportReadOver;
if (ReportID > 0) {
ReportMain.LoadReport();
}
else {
ReportReadOver();
}
};
//初始化
var ReportReadOver = function () {
CreateDefaultDS(Table);
var treedata = DataSourcesToTreeData(ReportMain.DataSources);
dsTree.LoadData(treedata);
dsTree.OnDblClick(function (data) {
if (data.nodeType == "Filed") {
CreateFieldControl(data.tfVal, LastDragControl)
}
});
ResetReportSize();
ShowReportPropertyPanel();
};
//添加默认数据源
var CreateDefaultDS = function (pTable) {
if (!pTable) return;
EMW.API.Table.GetFieldsByTableID(pTable.ID, function (fields) {
pTable.Fields = fields;
var DataSource = { MainTable: pTable };
ReportMain.DataSources.push({ Name: CreateDSName(), DataSource: DataSource });
BindDataSourceTree();
})
};
var ProcessMouseMove = function (e) {
var point = GetMouseAlias(e);
// ShowMouseAlias(point);
if (LastDragControl) {
$(".cell-drag-over").removeClass("cell-drag-over");
var $td = FindDropCell(point);
if ($td && $td.children().length == 0) {
var targetCtrl = $td.closest(".element").data("Tag");
if (targetCtrl != LastDragControl && !IsInParent(targetCtrl, LastDragControl)) {
$td.addClass("cell-drag-over");
}
}
}
}
var ProccessMouseUp = function (e) {
var target = e.target;
var $this = $(this);
if (LastDragControl) {
var point = GetMouseAlias(e);
var $td = FindDropCell(point);
if ($td) {//其它td
var sourceTd = LastDragControl.Element.closest("td");
if (sourceTd == $td || $td.children().length > 0) {
return;
}
var targetCtrl = $td.closest(".element").data("Tag");
if (targetCtrl && targetCtrl != LastDragControl && !IsInParent(targetCtrl, LastDragControl)) {
if (targetCtrl.IsIReportPanel) {//拖至其它控件
var ctrl = LastDragControl;
if (ctrl.ParentControl) {
ctrl.ParentControl.UnSelectCell();
ctrl.ParentControl.RemoveChild(ctrl);
}
else {
ReportMain.Elements.Remove(ctrl);
}
// delete ctrl.LeaveOriginal;
if (ctrl.GridRowSpan != 0 || ctrl.GridColSpan != 0) {
ctrl.GridRowSpan = 0;
ctrl.GridColSpan = 0;
ctrl.MergeRowColSpan();
}
setTimeout(function () {//迟延让dragEnd
targetCtrl.MoveIn(e, null, $td, ctrl);
}, 50);
}
}
}
else {
var parentControl = LastDragControl.ParentControl;
if (parentControl && parentControl.IsIReportPanel) {
MoveToDesigner(LastDragControl, point);
}
}
}
}
var MoveToDesigner = function (ctrl, point) {
var container = ctrl.Container;
var parentControl = ctrl.ParentControl;
//不能移动交叉表分组字段
//if (parentControl != null && parentControl.IsIReportPanel) {
// if (parentControl.Type == "CrossTable") {
// var isBody = ctrl.GridRow == parentControl.RowDefines.length - 1 && ctrl.GridCol == parentControl.ColDefines.length - 1;
// var isTitle = ctrl.GridRow < parentControl.RowDefines.length - 1 && ctrl.GridCol < parentControl.ColDefines.length - 1;
// if (isBody || isTitle) { } else { return false; }
// }
//}
ctrl.Width = ctrl.Element.parent().width();
ctrl.Height = ctrl.Element.parent().height();
var left = point.X; //(point.X - (ctrl.Width / 2));
var top = point.Y; //(point.Y - (ctrl.Height / 2));
ctrl.MarginLeftWidth = left > 0 ? left : 0;
ctrl.MarginTopWidth = top > 0 ? top : 0;
ctrl.Halign = "Left";
ctrl.Valign = "Top";
if (ctrl.GridRowSpan != 0 || ctrl.GridColSpan != 0) {
ctrl.GridRowSpan = 0;
ctrl.GridColSpan = 0;
ctrl.MergeRowColSpan();
}
parentControl.UnSelectCell();
parentControl.RemoveChild(ctrl);
ctrl.GridRow = 0;
ctrl.GridCol = 0;
var proxy = $(container.Container).draggable('proxy');
if (proxy) {
proxy.hide();
}
ReportMain.AddChild(ctrl);
// delete ctrl.LeaveOriginal;
container.Container.css({ width: ctrl.Width, height: "auto", position: "absolute" });
ctrl.UpdateLayout();
setTimeout(function () {
container.MoveOutTable();
}, 100);
ctrl.MovedOriginal = true;
}
//x是否是y的子孙
var IsInParent = function (x, y) {
/// <summary>x是否是y的子孙</summary>
if (x && y) {
var p = x.ParentControl;
while (p) {
if (p == y) {
return true;
}
p = p.ParentControl;
}
}
return false;
}
var OnClickDesigner = function (e) {
if (ReportMain.SelectedReportControl) {
ReportMain.SelectedReportControl.UnFocus();
ReportMain.SelectedReportControl = null;
} else {
ShowReportPropertyPanel();
}
}
//设计面板事件
var BindEvent = function () {
$(".report-designer").on("click", OnClickDesigner)
.on("mousemove", ProcessMouseMove)
.on("mouseup", ProccessMouseUp);
//$(".designer").on("scroll", FixedAlias);
$(".report-footer,.report-header").resizable({
onStopResize: function (e) {
if ($(this).hasClass("report-footer")) {
$(this).css("top", "").css("left", "");
ReportMain.FooterPos = e.data.height;
}
else {
ReportMain.HeaderPos = e.data.height;
}
}
});
};
/************报表属性操作************************/
//报表基本属性
var ReportProperty = [
{
text: "基本", rows: [
{ name: "ID", text: "编号", readOnly: true },
{ name: "Name", text: "名称", editor: "text" },
{ name: "Memo", text: "说明", editor: "textarea" },
{ name: "IsShowGrid", text: "显示网格", editor: "checkbox", option: [{ "value": "1", "text": "显示" }, { "value": "0", "text": "不显示" }], defaultValue: 0 },
{
name: "DataSource", text: "数据源", editor: "select", optionCreator: function () {
return GetDataSourceNames();
}, textField: "text", valueField: "value", formatter: function (data, item) {
return data.DataSource ? data.DataSource : "";
}
},
{
name: "Parameters", text: "参数设置", editor: function (data, item) { return SetParameters(data, item); }
, formatter: function (data, item) {
return data.Parameters && data.Parameters.length > 0 ? "已设置" : "未设置";
}
}
]
}, {
text: "显示", rows: [
{ name: "Width", text: "宽度", editor: "text" },
{ name: "Height", text: "高度", editor: "text" },
{ name: "IsShowHeader", text: "页眉", editor: "checkbox", option: [{ "value": "1", "text": "显示" }, { "value": "0", "text": "不显示" }] },
{ name: "IsShowFooter", text: "页脚", editor: "checkbox", option: [{ "value": "1", "text": "显示" }, { "value": "0", "text": "不显示" }] },
{ name: "MarginTop", text: "上边距", editor: "text" },
{ name: "MarginBottom", text: "下边距", editor: "text" },
{ name: "MarginLeft", text: "左边距", editor: "text" },
{ name: "MarginRight", text: "右边距", editor: "text" },
{
name: "PaperType", text: "纸张", editor: "select", option: [
{ text: "A4(21 * 29.7厘米)", value: "0" }, { text: "A3(29.7 * 42厘米)", value: "1" }, { text: "A5(14.8 * 21厘米)", value: "2" },
{ text: "信纸(21.59 * 27.94厘米)", value: "3" }, { text: "法律专用纸(21.59 * 31.56厘米)", value: "4" },
{ text: "16开(18.4 * 26厘米)", value: "5" }, { text: "32开(13 * 18.4厘米)", value: "6" }, { text: "大32开(14 * 20.4厘米))", value: "7" }
], textField: "text", valueField: "value"
},
{ name: "PrintType", text: "横向打印", editor: "checkbox" }
]
}
];
//显示报表属性面板
var ShowReportPropertyPanel = function () {
if (ReportMain.DataSource == null || ReportMain.DataSource == "") {
if (ReportMain.DataSources && ReportMain.DataSources.length > 0) {
ReportMain.DataSource = ReportMain.DataSources[0].Name;
}
}
PropPanel.Bind(ReportProperty, ReportMain);
EMW.UI.RightPanel.Show({
Width: 300,
Content: $("#ReportAttrPanel")
});
};
//属性面板事件
var PropertyPanelChanged = function (item, elem, oldValue) {
switch (item.name) {
case "IsShowGrid":
oldValue == false ? $(".designer-grid").show() : $(".designer-grid").hide();
break;
case "IsShowHeader":
case "IsShowFooter":
ReportMain.ShowHeaderFooter();
break;
case "PaperType":
var PaperType = PropPanel.GetValue(item);
ChangePageType(PaperType);
break;
}
elem.UpdateLayout();
};
//纸张大小
var ChangePageType = function (PaperType) {
var width = 0;
var height = 0;
switch (PaperType) {
case "0":
width = 21;
height = 29.7;
break;
case "1":
width = 29.7;
height = 42;
break;
case "2":
width = 14.8;
height = 21;
break;
case "3":
width = 21.59;
height = 27.94;
break;
case "4":
width = 21.59;
height = 31.56;
break;
case "5":
width = 18.4;
height = 26;
break;
case "6":
width = 13;
height = 18.4;
break;
case "7":
width = 14;
height = 20.4;
break;
default:
width = 20.9;
height = 29.7;
break;
}
ReportMain.Width = width;
ReportMain.Height = height;
ResetReportSize();
}
//参数设置
var SetParameters = function (data, item) {
var dia = EMW.UI.Dialog({
title: "报表参数设置",
url: "/pages/table/ReportParameters.html",
height: 600,
OnOK: function (para) {
if (para != "") {
ReportMain.Parameters = para;
ControlPropPanel.Update(item.name, ReportMain.Parameters);
}
}
});
dia.ReportMain = ReportMain;
}