Index.cshtml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. @{
  2. ViewBag.Title = "数据库管理";
  3. Layout = "~/Views/Shared/_LayoutIndex.cshtml";
  4. }
  5. <script>
  6. $(function () {
  7. InitialPage();
  8. GetTree();
  9. GetGrid();
  10. });
  11. //初始化页面
  12. function InitialPage() {
  13. //layout布局
  14. $('#layout').layout({
  15. applyDemoStyles: true,
  16. onresize: function () {
  17. $(window).resize();
  18. }
  19. });
  20. //resize重设(表格、树形)宽高
  21. $(window).resize(function (e) {
  22. window.setTimeout(function () {
  23. $('#gridTable').setGridWidth(($('.gridPanel').width()));
  24. $("#gridTable").setGridHeight($(window).height() - 141);
  25. $("#itemTree").setTreeHeight($(window).height() - 52);
  26. }, 200);
  27. e.stopPropagation();
  28. });
  29. }
  30. //加载树
  31. var _DataBaseLinkId = "";
  32. function GetTree() {
  33. var item = {
  34. height: $(window).height() - 52,
  35. url: "../../SystemManage/DataBaseLink/GetTreeJson",
  36. onnodeclick: function (item) {
  37. if (item.parentnodes) {
  38. _DataBaseLinkId = item.id;
  39. $("#titleinfo").html("[" + item.text + "]&nbsp;[" + item.parentnodes + "]&nbsp;[" + item.title + "]");
  40. $("#txt_Keyword").val("");
  41. $('#btn_Search').trigger("click");
  42. }
  43. }
  44. };
  45. //初始化
  46. $("#itemTree").treeview(item);
  47. }
  48. //加载表格
  49. function GetGrid() {
  50. var selectedRowIndex = 0;
  51. var $gridTable = $("#gridTable");
  52. $gridTable.jqGrid({
  53. datatype: "json",
  54. height: $(window).height() - 141,
  55. autowidth: true,
  56. colModel: [
  57. { label: '主键', name: 'pk', hidden: true },
  58. { label: "表名", name: "name", width: 300, align: "left", sortable: false },
  59. {
  60. label: "记录数", name: "sumrows", width: 100, align: "center", sortable: false,
  61. formatter: function (cellvalue, options, rowObject) {
  62. return cellvalue + "条";
  63. }
  64. },
  65. { label: "使用大小", name: "reserved", width: 100, align: "center", sortable: false },
  66. { label: "表类型", name: "reserved", width: 100, align: "center", sortable: false },
  67. { label: "更新时间", name: "updatetime", width: 120, align: "center", sortable: false },
  68. { label: "索引使用大小", name: "index_size", width: 120, align: "center", sortable: false },
  69. { label: "说明", name: "tdescription", width: 120, align: "left", sortable: false }
  70. ],
  71. onSelectRow: function () {
  72. selectedRowIndex = $("#" + this.id).getGridParam('selrow');
  73. },
  74. gridComplete: function () {
  75. $("#" + this.id).setSelection(selectedRowIndex, false);
  76. },
  77. rowNum: "1000",
  78. rownumbers: true,
  79. shrinkToFit: false,
  80. gridview: true,
  81. subGrid: true,
  82. subGridRowExpanded: function (subgrid_id, row_id) {
  83. var tableName = $gridTable.jqGrid('getRowData', row_id)['name'];
  84. var subgrid_table_id = subgrid_id + "_t";
  85. $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "'></table>");
  86. $("#" + subgrid_table_id).jqGrid({
  87. url: "../../SystemManage/DataBaseTable/GetTableFiledListJson",
  88. postData: { dataBaseLinkId: _DataBaseLinkId, tableName: tableName },
  89. datatype: "json",
  90. height: 260,
  91. colModel: [
  92. { label: "列名", name: "column", index: "column", width: 300, sortable: false },
  93. { label: "数据类型", name: "datatype", index: "datatype", width: 120, align: "center", sortable: false },
  94. { label: "长度", name: "length", index: "length", width: 57, align: "center", sortable: false },
  95. { label: "允许空", name: "isnullable", index: "isnullable", width: 58, align: "center", sortable: false },
  96. { label: "标识", name: "identity", index: "identity", width: 58, align: "center", sortable: false },
  97. { label: "主键", name: "key", index: "key", width: 57, align: "center", sortable: false },
  98. { label: "默认值", name: "default", index: "default", width: 120, align: "center", sortable: false },
  99. { label: "说明", name: "remark", index: "remark", width: 200, sortable: false }
  100. ],
  101. caption: "表字段信息",
  102. rowNum: "1000",
  103. rownumbers: true,
  104. shrinkToFit: false,
  105. gridview: true,
  106. hidegrid: false
  107. });
  108. }
  109. });
  110. $gridTable.authorizeColModel();
  111. //查询事件
  112. $("#btn_Search").click(function () {
  113. $gridTable.resetSelection();
  114. selectedRowIndex = 0;
  115. $gridTable.jqGrid('setGridParam', {
  116. url: "../../SystemManage/DataBaseTable/GetTableListJson",
  117. postData: { dataBaseLinkId: _DataBaseLinkId, keyword: $("#txt_Keyword").val() },
  118. }).trigger('reloadGrid');
  119. });
  120. }
  121. //新增表
  122. function btn_add() {
  123. if (_DataBaseLinkId) {
  124. dialogOpen({
  125. id: "Form",
  126. title: '创建表',
  127. url: '/SystemManage/DataBaseTable/Form?dataBaseLinkId=' + _DataBaseLinkId,
  128. width: "800px",
  129. height: "500px",
  130. callBack: function (iframeId) {
  131. top.frames[iframeId].AcceptClick();
  132. }
  133. });
  134. } else {
  135. dialogMsg('请选择左边数据库!', 0);
  136. }
  137. };
  138. //编辑表
  139. function btn_edit() {
  140. var tableName = $("#gridTable").jqGridRowValue("name");
  141. var tdescription = $("#gridTable").jqGridRowValue("tdescription");
  142. if (checkedRow(tableName)) {
  143. dialogOpen({
  144. id: "Form",
  145. title: '编辑表',
  146. url: '/SystemManage/DataBaseTable/Form?tableName=' + tableName + '&dataBaseLinkId=' + _DataBaseLinkId + "&tableDescription=" + escape(tdescription),
  147. width: "800px",
  148. height: "500px",
  149. callBack: function (iframeId) {
  150. top.frames[iframeId].AcceptClick();
  151. }
  152. });
  153. }
  154. }
  155. //删除表
  156. function btn_delete() {
  157. var tableName = $("#gridTable").jqGridRowValue("name");
  158. if (tableName) {
  159. $.RemoveForm({
  160. url: "../../SystemManage/DataBaseTable/RemoveForm",
  161. param: { tableName: tableName, dataBaseLinkId: _DataBaseLinkId },
  162. success: function (data) {
  163. $("#gridTable").trigger("reloadGrid");
  164. }
  165. })
  166. } else {
  167. dialogMsg('请选择需要删除的表!', 0);
  168. }
  169. }
  170. //打开表数据
  171. function btn_open_tabledata() {
  172. var tableName = $("#gridTable").jqGridRowValue("name");
  173. if (checkedRow(tableName)) {
  174. dialogOpen({
  175. id: "TableData",
  176. title: '打开表数据 - ' + tableName,
  177. url: '/SystemManage/DataBaseTable/TableData?tableName=' + tableName + "&dataBaseLinkId=" + _DataBaseLinkId,
  178. width: $(window).width() + "px",
  179. height: $(window).height() + "px",
  180. btn: null
  181. });
  182. }
  183. }
  184. </script>
  185. <div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
  186. <div class="ui-layout-west">
  187. <div class="west-Panel">
  188. <div class="panel-Title">数据库目录</div>
  189. <div id="itemTree"></div>
  190. </div>
  191. </div>
  192. <div class="ui-layout-center">
  193. <div class="center-Panel">
  194. <div class="panel-Title">
  195. 数据表信息 - <span id="titleinfo">未选择数据库</span>
  196. </div>
  197. <div class="titlePanel">
  198. <div class="title-search">
  199. <table>
  200. <tr>
  201. <td>
  202. <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
  203. </td>
  204. <td style="padding-left: 5px;">
  205. <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
  206. </td>
  207. </tr>
  208. </table>
  209. </div>
  210. <div class="toolbar">
  211. <div class="btn-group">
  212. <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
  213. <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
  214. <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
  215. @*<a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>*@
  216. </div>
  217. <div class="btn-group">
  218. <a id="lr-tabledata" class="btn btn-default" onclick="btn_open_tabledata()"><i class="fa fa-table"></i>&nbsp;打开表数据</a>
  219. @*<a id="lr-datacategory" class="btn btn-default" onclick="btn_datacategory()"><i class="fa fa-bug"></i>&nbsp;SQL命令</a>*@
  220. </div>
  221. <script>$('.toolbar').authorizeButton()</script>
  222. </div>
  223. </div>
  224. <div class="gridPanel">
  225. <table id="gridTable"></table>
  226. </div>
  227. </div>
  228. </div>
  229. </div>