123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <%@ page contentType="text/html;charset=UTF-8"%>
- <%@ page language="java"
- import="com.sysmodel.datamodel.xmlmodel.ModelFactory,
- com.sysmodel.datamodel.xmlmodel.able.SysModel,
- com.sysmodel.datamodel.xmlmodel.able.MdpConstant,
- com.sysmodel.datamodel.xmlmodel.able.Property,
- com.sysmodel.datamodel.xmlmodel.PropertyValue,
- com.persistence.service.PersistenceFactory,
- com.persistence.service.SysPersistence,
- com.sysmodel.datamodel.xmlmodel.able.Template"%>
- <%@ page language="java"
- import="java.util.*"%>
- <%
- request.setCharacterEncoding("UTF-8");
- String codeName =request.getParameter("codeName");
- if(codeName.equals("")) return;
- String command = request.getParameter("cmd")==null?"":(String)request.getParameter("cmd");
- String nodeID =request.getParameter("nodeID")==null?"":(String)request.getParameter("nodeID");
- String parentID =request.getParameter("parentID")==null?"":(String)request.getParameter("parentID");
-
- SysModel sysModel = ModelFactory.getSysmodel();
- SysPersistence sysPersistenceObject = PersistenceFactory.getInstance(sysModel);
- ArrayList listPropertyValue = new ArrayList();
- MdpConstant constant = sysModel.getMdpConstantByName(codeName);
- List listProperty = constant.getTemplate().getListproperty();
- Template templ = ModelFactory.getSysmodel().getTemplateByName(constant.getTemplateName());
- String templateName = templ.getTableName();
- Iterator it = listProperty.iterator();
- String selfParentCode = "";
- String newNodeID = "";
- while(it.hasNext()){
- PropertyValue pv = new PropertyValue();
- Property field = (Property)it.next();
- pv.setPropertyName(field.getName());
-
- String fieldValue = request.getParameter(field.getName());
- if(fieldValue == null) fieldValue = "";
-
- if(!field.getReferenceParentName().equals(""))
- selfParentCode = fieldValue;
-
- if(field.isUnique()) newNodeID = fieldValue;
- pv.setPropertyValue(fieldValue);
- listPropertyValue.add(pv);
- }
- boolean success = false;
- String paramString = "?codeName=" + codeName;
- if(command.equalsIgnoreCase("modify")){
- System.out.println("paramString==="+paramString);
- try {
- success= sysPersistenceObject.updateConstant(templateName,listPropertyValue);
- ArrayList newValueList = sysPersistenceObject.searchConstant(templateName,nodeID);
- constant.updateDataContent(newValueList);
- } catch (Exception e) {
- throw e;
- }
-
- if(request.getParameter("myParentID")!=null)
- paramString = paramString + "&nodeID="+request.getParameter("myParentID")+"&refreshNode=true";
- else
- paramString = paramString +"&nodeID="+selfParentCode+"&refreshNode=true";
- }
-
-
-
- if(command.equalsIgnoreCase("add")||command.equalsIgnoreCase("addRoot")){
- try {
- if(constant.getDataContentByCode(request.getParameter(constant.getTemplate().getUniqueProperty().getName()))==null) { // 如果从对象中没有查到重复的keyID,则可以增加
- success = sysPersistenceObject.insertConstant(templateName,listPropertyValue);
- ArrayList newValueList = sysPersistenceObject.searchConstant(templateName,newNodeID);
- constant.addDataContent(newValueList);
- paramString = paramString +"&refreshNode=true" ;
- }else{
- paramString = paramString +"&alertInfo=constant_repeat_tip" ;
- }
- } catch (Exception e) {
- throw e;
- }
- if(command.equalsIgnoreCase("add")) paramString = paramString +"&nodeID="+parentID;
- if(command.equalsIgnoreCase("addRoot")) paramString = paramString +"&nodeID="; // 如果新增的是根节点,传回空串
- }
- if(command.equalsIgnoreCase("delete")){
- try {
- success = sysPersistenceObject.deleteConstant(templateName,nodeID);
- constant.deleteDataContent(nodeID);
- } catch (Exception e) {
- throw e;
- }
- if(request.getParameter("myParentID")!=null)
- paramString = paramString + "&nodeID="+request.getParameter("myParentID")+"&refreshNode=true";
- else
- paramString = paramString +"&nodeID="+selfParentCode+"&refreshNode=true";
- }
- System.out.println(success);
- if(!success){
- response.getWriter().write("{\"success\":"+new Boolean(false).toString()+"}");
- %>
- <SCRIPT LANGUAGE="JavaScript">
- <!--
- alert("新增数据错误,请检查编码值是否重复!");
- history.go(-1);
- //-->
- </SCRIPT>
- <%
- }else{
- response.getWriter().write("{\"success\":"+new Boolean(true).toString()+"}");
- %>
- <SCRIPT LANGUAGE="JavaScript">
- <!--
- alert("成功操作数据!");
- //-->
- </SCRIPT>
- <%
- //response.sendRedirect("list.jsp?codeName=" + codeName+paramString);
- }
- response.getWriter().flush();
- response.getWriter().close();
- %>
|