0e08cb36c6f0be17013800a5f2a30b67372928c2.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. package test.createHtml.file;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import test.junitTest.JunitInit;
  5. import com.sysmodel.datamodel.xmlmodel.impl.MdpAttributeImpl;
  6. import com.sysmodel.datamodel.xmlmodel.impl.MdpClassImpl;
  7. import com.sysmodel.datamodel.xmlmodel.impl.SysModelImpl;
  8. /**
  9. * 根据DataModel.xml 生成列表Js
  10. */
  11. public class TableToHtmlList{
  12. private String path = System.getProperty("user.dir").replace("\\", "/")
  13. + "/javatest/Afile/";
  14. private JunitInit init = new JunitInit();
  15. private SysModelImpl sysmodel = init.getSysmodel();
  16. public void CreateListJS(String tableName, String classId) {
  17. StringBuffer sb = new StringBuffer();
  18. sb.append("/**** \n");
  19. sb.append("功能描述: \n");
  20. sb.append("***/ \n");
  21. sb.append("com.sinosoft.maintain." + tableName + "List = function(){ //根据业务自定义函数名称 \n");
  22. sb.append(" _this = this; \n");
  23. sb.append(" _this.listGrid = null; //数据列表 \n");
  24. sb.append(" $queryForm = null; //查询区域对象\n");
  25. sb.append(" var loadParams = {listId : '" + classId
  26. + "',condition :\" Is_Del='0' \"}; \n");
  27. sb.append(" _this.exportParams = loadParams;//导出excel的条件 \n");
  28. sb.append("\n");
  29. sb.append(this.getAddForm(tableName));
  30. sb.append(this.getEditForm(tableName, classId));
  31. sb.append(this.getDelMethd(classId));
  32. sb.append(this.getLookInfor(classId));
  33. sb.append(this.getExport(classId));
  34. sb.append(" return { \n");
  35. sb.append(" init : function() { \n");
  36. sb.append(" _this.listGrid = $(\"#dataGrid_" + classId
  37. + "\").quiGrid({ //dataGrid Div Id 根据业务进行修改 \n");
  38. sb.append(" columns : [ \n");
  39. sb.append(" {name : 'FD_OBJECTID" + classId + "',hide : true}, \n");
  40. ArrayList<MdpClassImpl> list = sysmodel.getMdpClasses();
  41. for (int i = 0; i < list.size(); i++) {
  42. MdpClassImpl mdpClass = list.get(i);
  43. if (mdpClass.getClassid() == Integer.parseInt(classId)) {
  44. List<MdpAttributeImpl> attrilist = mdpClass.getAllMdpAttributes();
  45. for (int j = 0; j < attrilist.size(); j++) {
  46. MdpAttributeImpl mdbAttri = attrilist.get(j);
  47. sb.append(" {display : '" + mdbAttri.getDescription() + "',name : '"
  48. + mdbAttri.getName().toUpperCase() + "_" + classId
  49. + "', align : 'center',width : '10%'},\n");
  50. }
  51. }
  52. }
  53. if (sb.lastIndexOf(",") > -1) {
  54. sb.deleteCharAt(sb.lastIndexOf(","));
  55. }
  56. sb.append(" ],\n");
  57. sb.append(" url :$.pathname() + '/ws/crud/CRUDService/queryQui', \n");
  58. sb.append(" params: loadParams, \n");
  59. /**
  60. * sb.append(" params:{ \n"); sb.append(" listId : '402', \n");
  61. * sb.append(" condition :\" Is_Del='0' \" \n"); sb.append(" }, \n");
  62. */
  63. sb.append(" sortName : '', //排序字段 \n");
  64. sb.append(" sortOrder : 'asc', //排序方式 \n");
  65. sb.append(" rownumbers : true, \n");
  66. sb.append(" checkbox : true, \n");
  67. sb.append(" height : '100%', \n");
  68. sb.append(" width : '100%', \n");
  69. sb.append(" pageSize : 10, \n");
  70. sb.append(" percentWidthMode : true, \n");
  71. sb.append(" toolbar : { \n");
  72. sb.append(" items : [ { \n");
  73. sb.append(" text : '新增', \n");
  74. sb.append(" click :_this.addForm, //新增调用方法 \n");
  75. sb.append(" iconClass : 'icon_add' \n");
  76. sb.append(" }, {\n");
  77. sb.append(" line : true\n");
  78. sb.append(" }, {\n");
  79. sb.append(" text : '修改', \n");
  80. sb.append(" click :_this.editForm, //修改调用方法 \n");
  81. sb.append(" iconClass : 'icon_edit' \n");
  82. sb.append(" }, {\n");
  83. sb.append(" line : true\n");
  84. sb.append(" }, {\n");
  85. sb.append(" text : '删除', \n");
  86. sb.append(" click :_this.del, //删除调用方法 \n");
  87. sb.append(" iconClass : 'icon_delete' \n");
  88. sb.append(" }, {\n");
  89. sb.append(" line : true\n");
  90. sb.append(" }, {\n");
  91. sb.append(" text : '查看', \n");
  92. sb.append(" click :_this.showInfo, //查看调用方法 \n");
  93. sb.append(" iconClass : 'icon_list' \n");
  94. sb.append(" }, {\n");
  95. sb.append(" line : true\n");
  96. sb.append(" }, {\n");
  97. sb.append(" text : '导出', \n");
  98. sb.append(" click :_this.exportTotalData, //导出调用方法 \n");
  99. sb.append(" iconClass : 'icon_export' \n");
  100. sb.append(" }] \n");
  101. sb.append(" } \n");
  102. sb.append(" }); \n");
  103. sb.append(" } \n");
  104. sb.append(" }; \n");
  105. sb.append("}();\n");
  106. sb.append("$(function() { \n");
  107. sb.append(" com.sinosoft.maintain." + tableName + "List.init(); \n");
  108. sb.append("});\n ");
  109. Utile.outputToFile(this.path, tableName + "_List.js", sb.toString());
  110. System.out.println("java 文件生成到" + path + "路径下面.....");
  111. }
  112. private String getAddForm(String tableName) {
  113. StringBuffer sb = new StringBuffer();
  114. sb.append(" /******新增Form信息***********/ \n");
  115. sb.append(" _this.addForm = function(){ \n");
  116. sb.append(" var diag = new top.Dialog(); \n");
  117. sb.append(" diag.Title = '新增'; \n");
  118. sb.append(" diag.URL = $.pathname() + '/page/AddEdit.html'; //修改对应的路径的编辑界面 \n");
  119. sb.append(" diag.OkButtonText = '提交'; \n");
  120. sb.append(" diag.OKEvent = function(){ \n");
  121. sb.append(" _this.add(diag); \n");
  122. sb.append(" }; \n");
  123. sb.append(" diag.Width = 600; //宽度 \n");
  124. sb.append(" diag.Height = 650; //高度 \n");
  125. sb.append(" diag.ButtonAlign = 'center'; \n");
  126. sb.append(" diag.show(); \n");
  127. sb.append(" }; \n");
  128. sb.append(" _this.add = function(diag){ \n");
  129. sb.append(" $form = diag.innerFrame.contentWindow.$('#" + tableName
  130. + "EditForm'); //修改对应Form Id \n");
  131. sb.append(" var valid = $form.validationEngine({returnIsValid: true}); \n");
  132. sb.append(" if(valid){ \n");
  133. sb.append(" var formValue = $form.serialize(); \n");
  134. sb.append(" $.ajax({ \n");
  135. sb.append(" url : $.pathname() + '/ws/crud/CRUDService/create/', \n");
  136. sb.append(" type : 'post', \n");
  137. sb.append(" timeout : 15000, \n");
  138. sb.append(" data : formValue, \n");
  139. sb.append(" dataType : 'json', \n");
  140. sb.append(" success : function(data){ \n");
  141. sb.append(" top.Dialog.close(); \n");
  142. sb.append(" top.Dialog.alert(data.Msg.info, null, null, null, 1); \n");
  143. sb.append(" _this.listGrid.loadData(); //刷新表格数据 \n");
  144. sb.append(" }, \n");
  145. sb.append(" error : function(e){ \n");
  146. sb.append(" $.messager.alert('系统提示信息', '访问服务失败!', 'error'); \n");
  147. sb.append(" } \n");
  148. sb.append(" }); \n");
  149. sb.append(" } \n");
  150. sb.append(" }; \n");
  151. sb.append("\n");
  152. return sb.toString();
  153. }
  154. private String getEditForm(String tableName, String classId) {
  155. StringBuffer sb = new StringBuffer();
  156. sb.append(" /******修改Form信息***********/ \n");
  157. sb.append(" _this.editForm = function(){ \n");
  158. sb.append(" var rows = _this.listGrid.getSelectedRows(); \n");
  159. sb.append(" var rowsLength = rows.length; \n");
  160. sb.append(" if (rowsLength == 0) { \n");
  161. sb.append(" top.Dialog.alert('请选中要修改的记录!'); \n");
  162. sb.append(" return; \n");
  163. sb.append(" } else if (rowsLength > 1) { \n");
  164. sb.append(" top.Dialog.alert('请选中一条要修改的记录!'); \n");
  165. sb.append(" return; \n");
  166. sb.append(" } else { \n");
  167. sb.append(" var fd_id = _this.listGrid.getSelectedRow().FD_OBJECTID" + classId
  168. + "; // \n");
  169. sb.append(" var diag = new top.Dialog(); \n");
  170. sb.append(" diag.Title = '修改'; \n");
  171. sb.append(" diag.URL = $.pathname() +'/page/business/" + tableName
  172. + "_Edit.html?'+fd_id; //修改对表单路径\n");
  173. sb.append(" diag.OkButtonText = '提交'; \n");
  174. sb.append(" diag.OKEvent = function(){ \n");
  175. sb.append(" _this.edit(diag); \n");
  176. sb.append(" }; \n");
  177. sb.append(" diag.Width = 600; //宽度 \n");
  178. sb.append(" diag.Height = 650; //高度 \n");
  179. sb.append(" diag.ButtonAlign = 'center'; \n");
  180. sb.append(" diag.show(); \n");
  181. sb.append(" } \n");
  182. sb.append(" }; \n");
  183. sb.append(" _this.edit = function(diag){ \n");
  184. sb.append(" $form = diag.innerFrame.contentWindow.$('#" + tableName
  185. + "EditForm'); //修改对应Form Id \n");
  186. sb.append(" var valid = $form.validationEngine({returnIsValid: true}); \n");
  187. sb.append(" if(valid){ \n");
  188. sb.append(" var formValue = $form.serialize(); \n");
  189. sb.append(" $.ajax({ \n");
  190. sb.append(" url : $.pathname() + '/ws/crud/CRUDService/update/', \n");
  191. sb.append(" type : 'post', \n");
  192. sb.append(" timeout : 15000, \n");
  193. sb.append(" data : formValue, \n");
  194. sb.append(" dataType : 'json', \n");
  195. sb.append(" success : function(data){ \n");
  196. sb.append(" top.Dialog.close(); \n");
  197. sb.append(" top.Dialog.alert(data.Msg.info, null, null, null, 1); \n");
  198. sb.append(" _this.listGrid.loadData(); //刷新表格数据 \n");
  199. sb.append(" }, \n");
  200. sb.append(" error : function(e){ \n");
  201. sb.append(" $.messager.alert('系统提示信息', '访问服务失败!', 'error'); \n");
  202. sb.append(" } \n");
  203. sb.append(" }); \n");
  204. sb.append(" } \n");
  205. sb.append(" }; \n");
  206. sb.append("\n");
  207. return sb.toString();
  208. }
  209. private String getDelMethd(String classId) {
  210. StringBuffer sb = new StringBuffer();
  211. sb.append(" /****删除****/ \n");
  212. sb.append(" _this.del = function(){ \n");
  213. sb.append(" var rows = _this.listGrid.getSelectedRows(); \n");
  214. sb.append(" var rowsLength = rows.length; \n");
  215. sb.append(" if (rowsLength == 0) { \n");
  216. sb.append(" top.Dialog.alert('请选中要删除的记录!'); \n");
  217. sb.append(" return; \n");
  218. sb.append(" } \n");
  219. sb.append(" var ids = ''; \n");
  220. sb.append(" for ( var i = 0; i < rowsLength; i++) { \n");
  221. sb.append(" ids += rows[i].FD_OBJECTID" + classId + " + ','; \n");
  222. sb.append(" } \n");
  223. sb.append(" top.Dialog.confirm('确定要删除吗?', function() { \n");
  224. sb.append(" $.post($.pathname() +'/ws/crud/CRUDService/delete/', { \n");
  225. sb.append(" objectIDs : ids, \n");
  226. sb.append(" classid : '" + classId + "' \n");
  227. sb.append(" }, \n");
  228. sb.append(" function(result) {\n");
  229. sb.append(" if (result.Msg.sucsess == true) {\n");
  230. sb.append(" top.Dialog.alert('删除成功!', null, null, null, 1); \n");
  231. sb.append(" _this.listGrid.loadData(); \n");
  232. sb.append(" }else{ \n");
  233. sb.append(" top.Dialog.alert('删除失败!'); \n");
  234. sb.append(" } \n");
  235. sb.append(" }, 'json'); \n");
  236. sb.append(" }); \n");
  237. sb.append(" };\n");
  238. sb.append("\n");
  239. return sb.toString();
  240. }
  241. private String getLookInfor(String classId) {
  242. StringBuffer sb = new StringBuffer();
  243. sb.append(" /****查看详细信息****/ \n");
  244. sb.append(" _this.showInfo = function(){ \n");
  245. sb.append(" var rows = _this.listGrid.getSelectedRows(); \n");
  246. sb.append(" var rowsLength = rows.length; \n");
  247. sb.append(" if (rowsLength == 0) { \n");
  248. sb.append(" top.Dialog.alert('请选中要查看的记录!'); \n");
  249. sb.append(" return; \n");
  250. sb.append(" } else if (rowsLength > 1) { \n");
  251. sb.append(" top.Dialog.alert('请选中一条要查看的记录!'); \n");
  252. sb.append(" return; \n");
  253. sb.append(" } else { \n");
  254. sb.append(" var fd_id = _this.listGrid.getSelectedRow().FD_OBJECTID" + classId + "; \n");
  255. sb.append(" var diag = new top.Dialog(); \n");
  256. sb.append(" diag.Title = '查看详细信息'; \n");
  257. sb.append(" diag.URL = $.pathname() +'/page/business/info.html?'+fd_id; //修改对应详细信息路径 \n");
  258. sb.append(" diag.show(); \n");
  259. sb.append(" } \n");
  260. sb.append(" }; \n");
  261. sb.append("\n");
  262. return sb.toString();
  263. }
  264. private String getExport(String classId) {
  265. StringBuffer sb = new StringBuffer();
  266. sb.append(" _this.exportTotalData = function(){ \n");
  267. sb.append(" excelExport(" + classId + ",_this.exportParams,'导出信息',['IS_DEL']); \n");
  268. sb.append(" }; \n");
  269. sb.append("\n");
  270. return sb.toString();
  271. }
  272. }