|
|
@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Index.cshtml"; } <style> .btn-primary { margin-right: 2px; }
.topPanel .toolbar { float: left; } /*.ui-jqgrid tr.jqgrow td { white-space: normal !important; height: auto; }*/ </style> <script src="~/Content/js/CommonReport/CommonReport.js"></script> <script> //var _MenuCaption = ""; var _MenuTag = "";
var _MenuID = "";//菜单ID var _SourceID = "";//数据源ID var _sqlTxt = "";//加上参数的sql var _sqlTxt_Condition = new Array();//加上过滤条件的sql var _sqlTxt_AddCondition = "";//加上过滤条件的sql var _IsExistsDataSource = ""; var _DBName = "";//s数据库 var _Cols = new Array();//列 var _ReportName = ""; var _Filter = ""; var _TempName = ""; var _footerrow = false;//是否有合计项 var _footercols = new Array();//合计项 var _formatcols = new Array();//个性化项 var _formatcols_Row = new Array();//个性化项的行 var _Mergercols = new Array();//合并项 var _XCol = ""; var dataRR = ""; var _HiddenCols = new Array(); $(function () { //1、获取当前页菜单名 GetMenuID(); //2、获取菜单设置 GetMenu(); //gridList(); $(window).resize(function () {
$("#gridList").setGridWidth($(window).width() * 0.99); $("#gridList").setGridWidth(document.body.clientWidth * 0.99); $("#gridList").setGridHeight($(window).height() - 132); $("#gridList").setGridHeight(document.body.clientHeight - 132); });
});
//1、获取当前页菜单名 function GetMenuID() {
var cc = self.frameElement.getAttribute('id'); _MenuID = cc.replace("iframe", ""); //_MenuTag = $.request("MenuTag"); //$.ajax({ // url: "/SystemManage/CommonReport/GetMenuID?MenuTag=" + _MenuTag + "&" + Math.random(), // dataType: "json", // async: false, // success: function (data) { // if (data != false && data != null && data.length > 0) { // _MenuID = data[0].MenuID; // } // else { // alert("获取菜单ID异常,请查看菜单配置并刷新:" + data); // } // }, // error: function (aa) { // alert("异常:" + aa.responseText);
// } //}); }
//2、获取菜单设置 URL 列 等 function GetMenu() {
$.ajax({ url: "/SystemManage/CommonReport/GetMenu?MenuID=" + _MenuID + "&" + Math.random(), dataType: "json", async: false, success: function (data) { if (data != false && data != null) { _sqlTxt = data.sqlTxt; _sqlTxt_AddCondition = data.sqlTxt; _DBName = data.DBName; _SourceID = data.SourceID; _IsExistsDataSource = data.IsExistsDataSource; _ReportName = data.ReportName; _XCol = data.XCol; _Mergercols = eval(data.Mergercols); _formatcols = data.formatcols; _TempName = data.TempName; _footerrow = data.footerrow; _footercols = eval(data.footercols); _Cols = SetCols(eval(data.Cols)); _HiddenCols = eval(data.HiddenCols); btn_Filter();
} else { alert("获取菜单栏位等信息异常。" + data); } }, error: function (aa) { alert("异常:" + aa.responseText);
} }); } //个性化栏位背景色 function addCellAttr(rowId, val, rawObject, cm, rdata) { var rr = ' id=\'' + cm.name + '' + rowId + "\' "; var formatList = Getformatcol(_formatcols, cm.name);//获取format所有条件 if (formatList != null && formatList.length > 0) { for (var i = 0; i < formatList.length; i++) { var formatcol = formatList[i];//条件 var IsRow = false; if (formatcol.AllRowFlag) { IsRow = true; var rr = { rowid: rowId - 1, backgroundcolor: formatcol.Color, } } var FormatDataType = formatcol.DataType; var LogStr = GetLogStringByNum(parseInt(formatcol.LogStr));
if (FormatDataType != "日期型") { switch (LogStr) { case "等于": if (val == formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "不等于": if (val != formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "小于": if (val < formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "大于": if (val > formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "小于等于": if (val <= formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "大于等于": if (val >= formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "范围内": if (val >= formatcol.SValue && val <= formatcol.DValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "范围外": if (val < formatcol.SValue || val > formatcol.DValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "包含": if (val.indexOf(formatcol.SValue) != -1) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "头部包含": if (val.indexOf(formatcol.SValue) == 0) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "尾部包含": if (val.indexOf(formatcol.SValue) == formatcol.length - val.length) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "不包含": if (val.indexOf(formatcol.SValue) == -1) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break;
} } else { //日期型 if (val.length >= 10) { var VV = val.substring(0, 10); switch (LogStr) { case "等于": if (VV== formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "不等于": if (VV != formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "小于": if (VV < formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "大于": if (VV > formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "小于等于": if (VV <= formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "大于等于": if (VV >= formatcol.SValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "范围内": if (VV >= formatcol.SValue && VV <= formatcol.DValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break; case "范围外": if (VV < formatcol.SValue || VV > formatcol.DValue) { if (IsRow) { _formatcols_Row.push(rr); } else { rr += "style='background-color:" + formatcol.Color + "'"; return rr; } } break;
} } }
} } return rr; }
//个性化栏位背景色 function addCellAttr_ID(rowId, val, rawObject, cm, rdata) { var rr = ' id=\'' + cm.name + '' + rowId + "\' ";
return rr; }
function Getformatcol(formatcols, colname) { var formatList = new Array(); if (formatcols != null && formatcols.length > 0) { for (var i = 0; i < formatcols.length; i++) { if (formatcols[i].ColFiledName == colname) { formatList.push(formatcols[i]); } } }
return formatList; }
//生成colModel function SetCols(datacols) { var cols = new Array(); if (datacols != null && datacols.length > 0) { for (var i = 0; i < datacols.length; i++) { var ColCaption = datacols[i].ColCaption; var ColFiledName = datacols[i].ColFiledName; var DataType = datacols[i].DataType; var DataTypeStr = GetDataTypeByNum(DataType); var ColWidth = datacols[i].ColWidth; var DeciamlNum = datacols[i].DeciamlNum; var sortable = datacols[i].sortable; var ColMerFlag = datacols[i].ColMerFlag; var IsFormat = datacols[i].IsFormat; var obj = new Array(); if (IsFormat == "1") { obj = { label: ColCaption, name: ColFiledName, width: ColWidth, align: "left", sortable: sortable, cellattr: addCellAttr, } } else { obj = { label: ColCaption, name: ColFiledName, width: ColWidth, align: "left", sortable: sortable, cellattr: addCellAttr_ID, } }
switch (DataTypeStr) {
case "数值型": var Formatoptions = new { decimalPlaces: DeciamlNum }; obj.push({ formatter: "number" }); obj.push({ formatoptions: Formatoptions });
break; case "字符型": case "日期型": case "布尔值":
break;
} //if (IsFormat) {
// obj.push({ cellattr: addCellAttr }); //}
cols.push(obj); }
var collast = { label: "", name: "", width: "20", align: "left", sortable: false }; cols.push(collast); } return cols; }
function gridList() { document.getElementById("gridPanel").innerHTML = ' <table id="gridList"></table> <div id="gridPager"></div>';//重置grid _formatcols_Row = new Array(); var $gridList = $("#gridList"); var condion = new Array(); if (_sqlTxt_Condition != undefined && _sqlTxt_Condition.length > 0) { condion = _sqlTxt_Condition; } $gridList.dataGrid({ //url: "/SystemManage/CommonReport/GetGridJson", url: "/SystemManage/CommonReport/GetGridJsonNew", height: $(window).height() - 132, // postData: { sqlTxt: _sqlTxt_AddCondition, DBName: _DBName, TempName: _TempName }, postData: { MenuID: _MenuID, sqlTxt_Condition: JSON.stringify(condion), DBName: _DBName, TempName: _TempName }, colModel: _Cols, pager: "#gridPager", //sortname: ' ', //sortorder: ' ', sortname: _XCol, sortorder: ' ', viewrecords: true, footerrow: _footerrow, gridComplete: function () { var strIds = $("#gridList").jqGrid("getDataIDs");
if (_formatcols_Row.length > 0) { for (var i = 0; i < _formatcols_Row.length; i++) { $("#" + strIds[_formatcols_Row[i].rowid] + " td").css("background-color", _formatcols_Row[i].backgroundcolor); } } //$("#"+ids[ii]+ " td").css("background-color","red");
//合并行 if (_Mergercols != undefined && _Mergercols.length > 0) { for (var i = 0; i < _Mergercols.length; i++) { Merger("gridList", _Mergercols[i]); } }
//合计 if (_footerrow == true) { var footerData = {}; for (var i = 0; i < _footercols.length; i++) { var total = 0;
for (var j = 0; j < strIds.length; j++) { var qty = $("#gridList").jqGrid("getCell", strIds[j], _footercols[i]); if (qty != "") { total += parseInt(qty); } }
footerData[_footercols[i]] = total;
} $("#gridList").footerData('set', footerData); $("#gridList").footerData('set', { "rn": "合计" }); }
//隐藏列(不可见/无权限) if (_HiddenCols != null && _HiddenCols.length > 0) { for (var j = 0; j < _HiddenCols.length; j++) { $("#gridList").setGridParam().hideCol(_HiddenCols[j].ColFiledName); } }
}, loadError: function (data) { alert("异常:"); }
}); $("#btn_search").click(function () { $gridList.jqGrid('setGridParam', { //sqlTxt: _sqlTxt_AddCondition, DBName: _DBName, TempName: _TempName MenuID: _MenuID, sqlTxt_Condition: JSON.stringify(condion), DBName: _DBName, TempName: _TempName }).trigger('reloadGrid'); }); }
//过滤 function btn_Filter() { $.modalOpen({ id: "Filer", title: "过滤条件", url: "/SystemManage/CommonReport/Filter?MenuID=" + _MenuID + "&SourceID=" + _SourceID + "&" + Math.random(), width: "800px", height: "570px", btn: ['确认', '关闭'], callBack: function (iframeId) { _sqlTxt_Condition = eval(top.frames[iframeId].submitForm()); //_sqlTxt_AddCondition = _sqlTxt; if (_sqlTxt_Condition != undefined) { // if (_sqlTxt_Condition.length > 0) {
// for (var i = 0; i < _sqlTxt_Condition.length; i++) { // _sqlTxt_AddCondition = ReplaceALL(_sqlTxt_AddCondition, _sqlTxt_Condition[i].CIndex, _sqlTxt_Condition[i].Content); // }
// } top.frames[iframeId].Close(); gridList(); } }
});
}
//数据源 function btn_DataSource() { $.modalOpen({ id: "DataSource", title: "数据源", url: "/SystemManage/CommonReport/DataSource?MenuID=" + _MenuID,//+ "&" + Math.random(), width: "1300px", height: "570px", btn: ['确认', '关闭'], callBack: function (iframeId) { dataRR = top.frames[iframeId].submitForm(); if (dataRR == "Error") { } else { GetMenu(); } } });
}
//列设置 function btn_Cols() { if (_IsExistsDataSource != "1") { alert("请先设置数据源"); } else { $.modalOpen({ id: "Cols", title: "列设置", url: "/SystemManage/CommonReport/Cols?SourceID=" + _SourceID + "&MenuID=" + _MenuID + "&" + Math.random(), width: "1300px", height: "570px", btn: ['确认', '关闭'], callBack: function (iframeId) { top.frames[iframeId].submitForm(); GetMenu(); } }); } }
//个性化设置 function btn_GridFormat() { if (_IsExistsDataSource != "1") { alert("请先设置数据源"); } else { $.modalOpen({ id: "GridFormat", title: "个性化设置", url: "/SystemManage/CommonReport/GridFormat?SourceID=" + _SourceID + "&" + Math.random(), width: "800px", height: "570px", btn: null, callBack: function (iframeId) {
GetMenu(); }
}); } }
//多表头设置 function btn_GridHeader() { if (_IsExistsDataSource != "1") { alert("请先设置数据源"); } else { $.modalOpen({ id: "GridHeader", title: "多表头设置", url: "/SystemManage/CommonReport/GridHeader?SourceID=" + _SourceID + "&" + Math.random(), width: "1300px", height: "570px", btn: ['确认', '关闭'], callBack: function (iframeId) { top.frames[iframeId].submitForm(); GetMenu(); } }); } }
//清空本菜单所有数据源相关设置 function btn_Clear() {
$.deleteForm({ url: "/SystemManage/CommonReport/ClearAll?" + Math.random(), param: { MenuID: _MenuID }, success: function () { _SourceID = "";//数据源ID _sqlTxt = "";//加上参数的sql _sqlTxt_AddCondition = "";//加上过滤条件的sql _TempName = ""; _IsExistsDataSource = ""; _DBName = "";//s数据库 _Cols = new Array();//列 _Filter = ""; _footerrow = false;//是否有合计项 _footercols = new Array();//合计项 _formatcols = new Array();//个性化项 _formatcols_Row = new Array();//个性化项的行 _Mergercols = new Array();//合并项 document.getElementById("gridPanel").innerHTML = ' <table id="gridList"></table> <div id="gridPager"></div>'; }, error: function (aa) { alert("异常", aa.responseText); } }); }
function btn_ExportAll() { var condion = new Array(); if (_sqlTxt_Condition != undefined && _sqlTxt_Condition.length > 0) { condion = _sqlTxt_Condition; } //var data = "&sqlTxt=" + encodeURIComponent(_sqlTxt_AddCondition) + "&DBName=" + _DBName + "&TempName=" + _TempName + "&MenuID=" + _MenuID; var data = "&sqlTxt=" + encodeURIComponent(JSON.stringify(condion)) + "&DBName=" + _DBName + "&TempName=" + _TempName + "&MenuID=" + _MenuID; $.download("/SystemManage/CommonReport/ExportAllNew?" + Math.random(), data, 'post'); }
function btn_WatchPanel() { var condion = new Array(); if (_sqlTxt_Condition != undefined && _sqlTxt_Condition.length > 0) { condion = _sqlTxt_Condition; } $.modalOpen({ id: "WatchPanel", title: _ReportName + "看板显示", url: "/SystemManage/CommonReport/WatchPanel?_MenuID=" + _MenuID + "&_sqlTxt_Condition=" + escape(JSON.stringify(condion)) + "&TempName=" + escape(_TempName) + "&" + Math.random(), width: "1300px", height: "570px", btn: null, callBack: function (iframeId) { top.frames[iframeId].submitForm(); GetMenu(); } }); }
//角色显示栏位 function btn_ColsVisible() { $.modalOpen({ id: "ColsVisible", title: _ReportName + " 角色显示栏位", url: "/SystemManage/CommonReport/ColsVisible?MenuID=" + _MenuID + "&IsCommon=Y&Cols=&" + Math.random(), width: "1000px", height: "570px", btn: null, callBack: function (iframeId) { alert("111"); GetMenu(); } }); }
</script>
<div class="topPanel">
<div class="toolbar"> <div class="btn-group"> <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a> <a class="btn btn-primary dropdown-text" onclick="btn_Filter()"><i class="fa fa-filter"></i>过滤</a> </div> <div class="btn-group">
<a id="NF-DataSource" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_DataSource()"><i class="fa fa-database"></i>设置数据源</a> <a id="NF-Cols" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_Cols()"><i class="fa fa-text-width"></i>列设置</a> <a id="NF-GridFormat" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_GridFormat()"><i class="fa fa-bars"></i>个性化设置</a> <a id="NF-Clear" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_Clear()"><i class="fa fa-times"></i>清空本菜单所有设置</a> <a id="NF-ExportAll" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_ExportAll()"><i class="fa fa-download"></i>全部导出</a> <a id="NF-WatchPanel" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_WatchPanel()"><i class="fa fa-download"></i>看板显示</a> <a id="NF-ColsVisible" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_ColsVisible()"><i class="fa fa-user"></i>角色显示栏位</a> @*<a id="NF-GridHeader" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_GridHeader()"><i class="fa fa-list-alt"></i>多表头设置</a>*@ </div>
<script>$('.toolbar').authorizeButton()</script> </div>
</div> <div class="gridPanel" id="gridPanel"> <table id="gridList"></table> <div id="gridPager"></div> </div>
|