Form.cshtml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. @{
  2. ViewBag.Title = "数据表表单";
  3. Layout = "~/Views/Shared/_Form.cshtml";
  4. }
  5. <!--jqgrid表格组件start-->
  6. <link href="~/Content/scripts/plugins/jqgrid/jqgrid.css" rel="stylesheet" />
  7. <script src="~/Content/scripts/plugins/jqgrid/grid.locale-cn.js"></script>
  8. <script src="~/Content/scripts/plugins/jqgrid/jqgrid.min.js"></script>
  9. <!--表格组件end-->
  10. <script>
  11. var dataBaseLinkId = request('dataBaseLinkId');
  12. var tableName = request('tableName');
  13. var tableDescription = request('tableDescription');
  14. $(function () {
  15. if (tableName != "") {
  16. $("#tableName").val(tableName);
  17. $("#tableDescription").val(tableDescription);
  18. }
  19. GetGrid();
  20. })
  21. function GetGrid() {
  22. var $gridTable = $("#gridTable");
  23. var _url = "../../SystemManage/DataBaseTable/GetTableFiledListJson";
  24. if (tableName == "") {
  25. _url = "";
  26. }
  27. $gridTable.jqGrid({
  28. url: _url,
  29. postData: { dataBaseLinkId: dataBaseLinkId, tableName: tableName },
  30. datatype: "json",
  31. height: 306,
  32. autowidth: true,
  33. unwritten:false,
  34. colModel: [
  35. { label: 'datatype', name: 'datatype', hidden: true },
  36. { label: 'length', name: 'length', hidden: true },
  37. { label: 'isnullable', name: 'isnullable', hidden: true },
  38. { label: 'identity', name: 'identity', hidden: true },
  39. { label: 'key', name: 'key', hidden: true },
  40. { label: "字段名称", name: "column", width: 150, align: "left", sortable: false },
  41. {
  42. label: "数据类型", name: "_column", width: 100, align: "left", sortable: false,
  43. formatter: function (cellvalue, options, rowObject) {
  44. var length = "";
  45. if (rowObject.datatype == 'varchar') {
  46. length = "(" + rowObject.length + ")";
  47. }
  48. return rowObject.datatype + length;
  49. }
  50. },
  51. {
  52. label: "允许空", name: "_isnullable", width: 50, align: "center", sortable: false,
  53. formatter: function (cellvalue, options, rowObject) {
  54. return rowObject.isnullable == 1 ? "√" : "";
  55. }
  56. },
  57. {
  58. label: "标识", name: "_identity", width: 50, align: "center", sortable: false,
  59. formatter: function (cellvalue, options, rowObject) {
  60. return rowObject.identity == 1 ? "√" : "";
  61. }
  62. },
  63. {
  64. label: "主键", name: "_key", width: 50, align: "center", sortable: false,
  65. formatter: function (cellvalue, options, rowObject) {
  66. return rowObject.key == 1 ? "√" : "";
  67. }
  68. },
  69. { label: "默认值", name: "defaults", width: 100, align: "left", sortable: false },
  70. { label: "说明", name: "remark", width: 100, align: "left", sortable: false }
  71. ], caption: "表字段信息", rowNum: "1000",
  72. rownumbers: true,
  73. shrinkToFit: false,
  74. gridview: true,
  75. hidegrid: false
  76. });
  77. }
  78. //添加
  79. function btn_add_field() {
  80. dialogOpen({
  81. id: "FieldForm",
  82. title: '添加字段',
  83. url: '/SystemManage/DataBaseTable/FieldForm',
  84. width: "450px",
  85. height: "350px",
  86. callBack: function (iframeId) {
  87. top.frames[iframeId].AcceptClick();
  88. }
  89. });
  90. };
  91. //修改
  92. function btn_edit_field() {
  93. var keyValue = $("#gridTable").getGridParam('selrow');
  94. if (checkedRow(keyValue)) {
  95. dialogOpen({
  96. id: "FieldForm",
  97. title: '修改字段',
  98. url: '/SystemManage/DataBaseTable/FieldForm?keyValue=' + keyValue,
  99. width: "450px",
  100. height: "350px",
  101. callBack: function (iframeId) {
  102. top.frames[iframeId].AcceptClick();
  103. }
  104. });
  105. }
  106. }
  107. //移除
  108. function btn_delete_field() {
  109. var keyValue = $("#gridTable").getGridParam('selrow');
  110. if (keyValue) {
  111. dialogConfirm('注:您确定要移除吗?该操作将无法恢复?', function (r) {
  112. if (r) {
  113. $("#gridTable").delRowData(keyValue);
  114. dialogMsg("移除成功。", 1);
  115. }
  116. });
  117. } else {
  118. dialogMsg('请选择需要移除的字段!', 0);
  119. }
  120. }
  121. //保存表单
  122. function AcceptClick() {
  123. if (!$('#form1').Validform()) {
  124. return false;
  125. }
  126. var fieldListJson = [];
  127. var rows = $('#gridTable').find('[role=row]');
  128. for (var i = 1; i < rows.length; i++) {
  129. fieldListJson.push({
  130. datatype: rows[i].childNodes[1].innerHTML.replace("&nbsp;", ''),
  131. length: rows[i].childNodes[2].innerHTML.replace("&nbsp;",''),
  132. isnullable: rows[i].childNodes[3].innerHTML.replace("&nbsp;", ''),
  133. identity: rows[i].childNodes[4].innerHTML.replace("&nbsp;", ''),
  134. key: rows[i].childNodes[5].innerHTML.replace("&nbsp;", ''),
  135. column: rows[i].childNodes[6].innerHTML.replace("&nbsp;", ''),
  136. defaults: rows[i].childNodes[11].innerHTML.replace("&nbsp;", ''),
  137. remark: rows[i].childNodes[12].innerHTML.replace("&nbsp;", '')
  138. });
  139. }
  140. var postData = {
  141. dataBaseLinkId: dataBaseLinkId,
  142. tableName: $("#tableName").val(),
  143. tableDescription: $("#tableDescription").val(),
  144. fieldListJson: JSON.stringify(fieldListJson)
  145. }
  146. $.SaveForm({
  147. url: "../../SystemManage/DataBaseTable/SaveForm",
  148. param: postData,
  149. loading: "正在保存数据...",
  150. success: function () {
  151. $.currentIframe().$("#gridTable").trigger("reloadGrid");
  152. }
  153. })
  154. }
  155. </script>
  156. <div class="border-left border-right border-top" style="margin: 5px; margin-bottom: 0px; padding-bottom: 2px;">
  157. <table class="form">
  158. <tr>
  159. <th class="formTitle" style="text-align: left; padding-left: 7px; width: 55px;">表名称:</th>
  160. <td class="formValue">
  161. <input id="tableName" type="text" class="form-control" style="box-shadow:none ;border-top: 0px; border-left: 0px; border-right: 0px;" placeholder="请输入表名称" isvalid="yes" checkexpession="NotNull" />
  162. </td>
  163. <th class="formTitle" style="text-align: left; padding-left: 7px; width: 55px;">表说明:</th>
  164. <td class="formValue">
  165. <input id="tableDescription" type="text" class="form-control" style="box-shadow:none ;border-top: 0px; border-left: 0px; border-right: 0px;" placeholder="添加说明" isvalid="yes" checkexpession="NotNull" />
  166. </td>
  167. </tr>
  168. </table>
  169. </div>
  170. <div style="margin: 5px; margin-top: 0px; margin-bottom: 0px;">
  171. <table id="gridTable"></table>
  172. <style>
  173. .ui-jqgrid .ui-jqgrid-caption {
  174. text-align: right;
  175. padding-right: 5px;
  176. background-color: #F5F5F5;
  177. }
  178. </style>
  179. </div>
  180. <div style="position: absolute; top: 51.5px; left: 10px;">
  181. <a id="lr-add" class="btn btn-success btn-xs" onclick="btn_add_field()"><i class="fa fa-plus"></i>&nbsp;添加</a>
  182. <a id="lr-edit" class="btn btn-info btn-xs" onclick="btn_edit_field()"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</a>
  183. <a id="lr-delete" class="btn btn-danger btn-xs" onclick="btn_delete_field()"><i class="fa fa-trash-o"></i>&nbsp;移除</a>
  184. </div>