123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- package samples.formcollect;
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import com.sysmodel.Util;
- import com.sysmodel.XFormFactory;
- import com.sysmodel.XFormModel;
- import com.sysmodel.collectmodel.xmlmodel.able.Action;
- import com.sysmodel.collectmodel.xmlmodel.able.FormCollection;
- import com.sysmodel.collectmodel.xmlmodel.able.PageBody;
- import com.sysmodel.collectmodel.xmlmodel.able.PageHead;
- import com.sysmodel.collectmodel.xmlmodel.able.PageRoot;
- import com.sysmodel.collectmodel.xmlmodel.able.ReportField;
- import com.sysmodel.collectmodel.xmlmodel.impl.PageBodyImpl;
- import com.sysmodel.collectmodel.xmlmodel.impl.ReportFieldImpl;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.MdpAttribute;
- import com.sysmodel.datamodel.xmlmodel.able.MdpClass;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- import com.sysmodel.xformmodel.importcontrol.DateControl;
- import com.sysmodel.xformmodel.importcontrol.SelectControl;
- import com.sysmodel.xformmodel.importcontrol.TreeControl;
- import com.persistence.service.PersistenceFactory;
- import com.persistence.service.assitant.DataObject;
- import com.persistence.service.exception.PersistenceException;
- public class PageBuilder {
- private static Log log = LogFactory.getLog(PageBodyImpl.class);
- private XFormModel XFormModel = XFormFactory.getXFormModel();
- private FormCollection FormCollection = null;
- private DataObject dataobject = null;
- public PageBuilder(String pageid,DataObject dataobject){
- this.FormCollection = XFormModel.getFormCollection(pageid);
- this.dataobject = dataobject;
- }
-
- /**
- * 获得采集列表的标题
- * @return
- */
- public String produceTitleHtml(){
- PageHead PageHead = FormCollection.getPageHead();
- StringBuffer sb = new StringBuffer();
- sb.append(" "+PageHead.getPageTitle());
- return sb.toString();
- }
-
-
- /**
- * 产生采集页面的按钮
- * @param isDelete
- * @return
- */
- public String produceRootHtml(boolean isDelete) {
- PageRoot PageRoot = FormCollection.getPageRoot();
- ArrayList alAction = PageRoot.getAllActions();
-
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < alAction.size(); i++) {
-
- Action action = (Action)alAction.get(i);
- String buttonValue = action.getValue();
- if(!action.getType().equals("delete") && !isDelete){
- sb.append("<button id=\"bt"+i+"\" dojoType=\"dijit.form.Button\" onClick=\""+action.getMethod()+"\" type=\"button\" iconClass=\"plusIcon\">");
- sb.append(buttonValue);
- sb.append("</button>");
- }
-
- action = null;
- }
- return sb.toString();
- }
-
-
- /**
- * 生成页面填报数据项
- * @param req
- * @return
- */
- public String produceBodyHtml(HttpServletRequest req) {
-
- PageBody PageBody = FormCollection.getPageBody();
- int columnCount = PageBody.getColumnCount();
-
- //表头
- StringBuffer sb = new StringBuffer();
- // /**
- // * 产生页面中隐藏插入的字段
- // * 只限于在页面信增时候产生字段
- // */
- // if(dataobject != null){
- // ArrayList<HiddenField> alHiddenFields = PageBody.getAlHiddenFields();
- // if(dataobject.getObjectID() == null || dataobject.getObjectID().length()==0){
- // for (int i = 0; i < alHiddenFields.size(); i++) {
- // HiddenField field = (HiddenField) alHiddenFields.get(i);
- // sb.append(field.getHiddenInput(req)).append("\n");
- // }
- // }
- // }
- sb.append("<table align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\""+PageBody.getWidth() + "\"");
- String css = XFormModel.getCSSValue("ReportTableCss");
- if (!css.equals(""))
- sb.append(" class=\"" + css + "\"");
- if (!PageBody.getHeight().equals(""))
- sb.append(" height=\"" + PageBody.getHeight() + "\"");
- sb.append(">");
-
-
- //数据区
- boolean nextLine = true;
- int currentCount = 0;
- String FontTextCss = XFormModel.getCSSValue("FontTextCss");
- FontTextCss = FontTextCss.equals("")? "":" class=\"" + FontTextCss + "\"";
- //td 宽度
- short[] widthFlag = new short[columnCount * 2];
-
- String htmlLabelWidth = PageBody.getLabelWidth().equals("") ? "" : " width=\"" + PageBody.getLabelWidth() + "\"";
- String htmControlWidth = PageBody.getControlWidth().equals("") ? "" : " width=\"" + PageBody.getControlWidth() + "\"";
- String htmlLabelAlign = PageBody.getLabelAlign().equals("") ? "" : " align=\"" + PageBody.getLabelAlign()+ "\"";
- String htmControlAlign = PageBody.getControlAlign().equals("") ? "" : " align=\"" + PageBody.getControlAlign() + "\"";
-
-
- //隔行换色
- String LineCssA = XFormModel.getCSSValue("LineCssA");
- String LineCssB = XFormModel.getCSSValue("LineCssB");
- LineCssA = LineCssA.equals("") ? "" : " class=\"" + LineCssA + "\"";
- LineCssB = LineCssB.equals("") ? "" : " class=\"" + LineCssB + "\"";
- boolean currentLineCss = true;
-
- ArrayList<ReportFieldImpl> alReportFields = PageBody.getAllReportFields();
-
- for (int i = 0; i < alReportFields.size(); i++) {
- ReportField field = (ReportField) alReportFields.get(i);
- int result = currentCount + Integer.parseInt(field.getColumnWidth());
- if (result > columnCount) {//补上空位,结束该行
- int tdCount = columnCount - currentCount;
- for (int j = 0; j < tdCount; j++) {
- int index = currentCount + j;
- if (widthFlag[index] == 0) {
- widthFlag[index] = 1;
- widthFlag[index + 1] = 1;
- sb.append("<td").append(htmlLabelWidth + "></td>");
- sb.append("<td").append(htmControlWidth+ "></td>");
- } else {
- sb.append("<td></td>").append("<td></td>");
- }
- }
- sb.append("</tr>");
- nextLine = true;
- currentCount = 0;
- }
- if (nextLine) {
- //进行隔行换色
- if (currentLineCss)
- sb.append("<tr").append(LineCssA + ">");
- else
- sb.append("<tr").append(LineCssB + ">");
- nextLine = false;
- currentLineCss = !currentLineCss;
- }
- //生成控件
- if (field.getName().equals("")) {
- int ColumnWidth = Integer.parseInt(field.getColumnWidth()) * 2;
- sb.append("<td ColumnWidth=\"").append(ColumnWidth + "\" >");
- String DivCss = XFormModel.getCSSValue("DivCss");
- DivCss = DivCss.equals("")? "":" class=\"" + DivCss + "\"";
- sb.append("<div").append(DivCss);
- sb.append(">" + field.getLabel()).append("</div></td>");
- } else {
- sb.append("<td"+htmlLabelAlign);
- if (widthFlag[currentCount] == 0) {
- widthFlag[currentCount] = 1;
- sb.append(htmlLabelWidth);
- }
- sb.append(">");
- sb.append("<font").append(FontTextCss);
- sb.append(">" + field.getLabel()).append("</font>");
- if(field.getValidate().isNeed()) sb.append(" <span class=\"redcolor\">*</span>");
- sb.append("</td>");
-
- //control
- sb.append("<td"+htmControlAlign);
- if (Integer.parseInt(field.getColumnWidth()) > 1) {
- int ColumnWidth = Integer.parseInt(field.getColumnWidth()) * 2 - 1;
- sb.append(" ColumnWidth=\"").append(ColumnWidth + "\"");
- } else {
- if (widthFlag[currentCount + 1] == 0) {
- widthFlag[currentCount + 1] = 1;
- sb.append(htmControlWidth);
- }
- }
- sb.append(" nowrap>");
- sb.append(produceControlHtml(field, dataobject));
- sb.append("</td>");
- }
- //结束行
- if (result == columnCount) {
- sb.append("</tr>");
- nextLine = true;
- currentCount = 0;
- } else
- currentCount += Integer.parseInt(field.getColumnWidth());
- }
- if (currentCount > 0) {//确认tr封口
- int tdCount = columnCount - currentCount;
- for (int j = 0; j < tdCount; j++) {
- int index = currentCount + j;
- if (widthFlag[index] == 0) {
- widthFlag[index] = 1;
- widthFlag[index + 1] = 1;
- sb.append("<td").append(htmlLabelWidth + "></td>");
- sb.append("<td").append(htmControlWidth+ "></td>");
- } else {
- sb.append("<td></td>").append("<td></td>");
- }
- }
- sb.append("</tr>");
- }
- //end
- sb.append("</table>");
- return sb.toString();
- }
-
- /**
- * 获得页面中元素的验证JS
- * @return
- */
- public String produceCientValidateJs(){
-
- PageBody PageBody = FormCollection.getPageBody();
- ArrayList<ReportFieldImpl> alReportFields = PageBody.getAllReportFields();
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < alReportFields.size(); i++) {
- ReportField field = (ReportField) alReportFields.get(i);
- // sb.append(field.outputScript());
- }
- return sb.toString();
- }
-
-
- private String produceControlHtml(ReportField field, DataObject dataobject) {
- String value = "";
- String displayString = "";
- if (dataobject != null) {
- Object obj = dataobject.getValue(field.getName());
- if (field.getControlType().equals("tree")) {
-
- TreeControl treeControl = (TreeControl) field.getControl();
- value = obj.toString();
- if (treeControl.getType().equals("2") || treeControl.getType().equals("3")) {//constant
- displayString = ModelFactory.getSysmodel().getMdpConstantDisplayString(treeControl.getReferenceTable(), value);
- } else {//table
- displayString = getReferenceDisplayString(treeControl, value);
- }
-
- } else if (field.getControlType().equals("date")) {
- DateControl dateControl = (DateControl) field.getControl();
- if (!obj.equals(""))
- value = Util.getDateTime(dateControl.getFormat(), (Timestamp)obj);
- } else
- value = obj.toString();
-
- if (field.getControlType().equals("select")) {
-
- SelectControl SelectControl = (SelectControl) field.getControl();
- if(SelectControl.getType().equals("1")){
- SysModel sysmodel = ModelFactory.getSysmodel();
- MdpAttribute attributeObj = sysmodel.getMdpAttributeByName(Integer.parseInt(SelectControl.getIclassid()),field.getName());
- //资源数据库选择系统
- if(attributeObj.getReference().getReferenceTable().equals("907")){
- String StationId = (String)dataobject.getValue("StationId");
- displayString = " where StationId='"+ StationId +"'";
-
- }
- }
- }
- }
- return field.getControl().produceHtml(field.getName(), value, displayString, field.getValidate());
- }
-
-
- private String getReferenceDisplayString(TreeControl treeControl,String value){
- String retString = "";
- try {
- int classid = Integer.parseInt(treeControl.getReferenceTable());
- MdpClass mdpClass = ModelFactory.getSysmodel().getMdpClassByClassID(classid);
- String sql = "select "+treeControl.getDisplayName()+ " from " + mdpClass.getName()+ " where "+treeControl.getStoreCode()+"='"+value+"'";
- ArrayList list = PersistenceFactory.getInstance().getSearchResult(classid,sql);
- if(list.size()==1){
- String[] display = (String[])list.get(0);
- retString = display[0];
- }
- } catch (NumberFormatException e) {
- log.error(e);
- } catch (PersistenceException e) {
- log.error(e);
- }
- return retString;
- }
-
- }
|