editExc.jsp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <%@ page contentType="text/html;charset=UTF-8"%>
  2. <%@ page language="java"
  3. import="com.sysmodel.datamodel.xmlmodel.ModelFactory,
  4. com.sysmodel.datamodel.xmlmodel.able.SysModel,
  5. com.sysmodel.datamodel.xmlmodel.able.MdpConstant,
  6. com.sysmodel.datamodel.xmlmodel.able.Property,
  7. com.sysmodel.datamodel.xmlmodel.PropertyValue,
  8. com.persistence.service.PersistenceFactory,
  9. com.persistence.service.SysPersistence,
  10. com.sysmodel.datamodel.xmlmodel.able.Template"%>
  11. <%@ page language="java"
  12. import="java.util.*"%>
  13. <%
  14. request.setCharacterEncoding("UTF-8");
  15. String codeName =request.getParameter("codeName");
  16. if(codeName.equals("")) return;
  17. String command = request.getParameter("cmd")==null?"":(String)request.getParameter("cmd");
  18. String nodeID =request.getParameter("nodeID")==null?"":(String)request.getParameter("nodeID");
  19. String parentID =request.getParameter("parentID")==null?"":(String)request.getParameter("parentID");
  20. SysModel sysModel = ModelFactory.getSysmodel();
  21. SysPersistence sysPersistenceObject = PersistenceFactory.getInstance(sysModel);
  22. ArrayList listPropertyValue = new ArrayList();
  23. MdpConstant constant = sysModel.getMdpConstantByName(codeName);
  24. List listProperty = constant.getTemplate().getListproperty();
  25. Template templ = ModelFactory.getSysmodel().getTemplateByName(constant.getTemplateName());
  26. String templateName = templ.getTableName();
  27. Iterator it = listProperty.iterator();
  28. String selfParentCode = "";
  29. String newNodeID = "";
  30. while(it.hasNext()){
  31. PropertyValue pv = new PropertyValue();
  32. Property field = (Property)it.next();
  33. pv.setPropertyName(field.getName());
  34. String fieldValue = request.getParameter(field.getName());
  35. if(fieldValue == null) fieldValue = "";
  36. if(!field.getReferenceParentName().equals(""))
  37. selfParentCode = fieldValue;
  38. if(field.isUnique()) newNodeID = fieldValue;
  39. pv.setPropertyValue(fieldValue);
  40. listPropertyValue.add(pv);
  41. }
  42. boolean success = false;
  43. String paramString = "?codeName=" + codeName;
  44. if(command.equalsIgnoreCase("modify")){
  45. System.out.println("paramString==="+paramString);
  46. try {
  47. success= sysPersistenceObject.updateConstant(templateName,listPropertyValue);
  48. ArrayList newValueList = sysPersistenceObject.searchConstant(templateName,nodeID);
  49. constant.updateDataContent(newValueList);
  50. } catch (Exception e) {
  51. throw e;
  52. }
  53. if(request.getParameter("myParentID")!=null)
  54. paramString = paramString + "&nodeID="+request.getParameter("myParentID")+"&refreshNode=true";
  55. else
  56. paramString = paramString +"&nodeID="+selfParentCode+"&refreshNode=true";
  57. }
  58. if(command.equalsIgnoreCase("add")||command.equalsIgnoreCase("addRoot")){
  59. try {
  60. if(constant.getDataContentByCode(request.getParameter(constant.getTemplate().getUniqueProperty().getName()))==null) { // 如果从对象中没有查到重复的keyID,则可以增加
  61. success = sysPersistenceObject.insertConstant(templateName,listPropertyValue);
  62. ArrayList newValueList = sysPersistenceObject.searchConstant(templateName,newNodeID);
  63. constant.addDataContent(newValueList);
  64. paramString = paramString +"&refreshNode=true" ;
  65. }else{
  66. paramString = paramString +"&alertInfo=constant_repeat_tip" ;
  67. }
  68. } catch (Exception e) {
  69. throw e;
  70. }
  71. if(command.equalsIgnoreCase("add")) paramString = paramString +"&nodeID="+parentID;
  72. if(command.equalsIgnoreCase("addRoot")) paramString = paramString +"&nodeID="; // 如果新增的是根节点,传回空串
  73. }
  74. if(command.equalsIgnoreCase("delete")){
  75. try {
  76. success = sysPersistenceObject.deleteConstant(templateName,nodeID);
  77. constant.deleteDataContent(nodeID);
  78. } catch (Exception e) {
  79. throw e;
  80. }
  81. if(request.getParameter("myParentID")!=null)
  82. paramString = paramString + "&nodeID="+request.getParameter("myParentID")+"&refreshNode=true";
  83. else
  84. paramString = paramString +"&nodeID="+selfParentCode+"&refreshNode=true";
  85. }
  86. System.out.println(success);
  87. if(!success){
  88. response.getWriter().write("{\"success\":"+new Boolean(false).toString()+"}");
  89. %>
  90. <SCRIPT LANGUAGE="JavaScript">
  91. <!--
  92. alert("新增数据错误,请检查编码值是否重复!");
  93. history.go(-1);
  94. //-->
  95. </SCRIPT>
  96. <%
  97. }else{
  98. response.getWriter().write("{\"success\":"+new Boolean(true).toString()+"}");
  99. %>
  100. <SCRIPT LANGUAGE="JavaScript">
  101. <!--
  102. alert("成功操作数据!");
  103. //-->
  104. </SCRIPT>
  105. <%
  106. //response.sendRedirect("list.jsp?codeName=" + codeName+paramString);
  107. }
  108. response.getWriter().flush();
  109. response.getWriter().close();
  110. %>