您好:参考这个模块整个代码和具体的操作都可以看到啊,可以看我们这里的投票是一个主子表单,当用户进行投票后,就把该用户选择的记录自动插入到对应的子表中,并且在投票之前先去对应的子表中查询,该用户是否已经进行过投票,类似代码:
- var where = "aa";
- var document = getCurrentDocument();
- var voting = getItemValue("voting");
- var radio = getItemValue("radio");
- var check = getItemValue("check");
- var anonymous = document.getItemValueAsString("anonymous");
- if ("单选".equals(voting)) {
- if (radio == null || radio.trim().length() <= 0) {
- where = "选项不能为空!";
- }
- }
- if ("多选".equals(voting)) {
- if (check == null || check.trim().length() <= 0) {
- where = "选项不能为空!";
- }
- }
- if (anonymous == null || anonymous.trim().length() <= 0) {
- where = "是否匿名不能为空!";
- }
- $PRINTER.print("-----------------------"+radio +"-----"+check +"-------------"+anonymous+document.getId());
- if ("aa".equals(where)) {
- var user = getWebUser();
- var doc = getCurrentDocument();
- var domain = getDomainid();
- var id = new Packages.cn.myapps.util.sequence.Sequence();
- var application = getApplication();
- var process = new Packages.cn.myapps.core.dynaform.document.ejb.DocumentProcessBean(application);
- var dql = "$formname='voting_record' and $parent = '" + doc.getId() + "' and $author = '" + user.getId() + "'"; //去投票的子表中查询该用户是否已经投票
- var budget = findByDQL(dql);
- if (budget != null && budget.getId() != null) {
- where="已投票,不能重复投票!"; //如果投票了就不允许进行投票
- } else {
- //如果没有投票,就把该用户选择的投票信息插入到对应的子表中
- budget.setId(id.getSequence());
- budget.setFormname("OA/投票/voting_record");
- budget.setFormid("11e0-197e-d3044197-b991-cf1024c68a7b");
- budget.setIstmp(false);
- budget.setParent(doc.getId());
- budget.setApplicationid(application);
- budget.setAuthor(user.getId());
- budget.setCreated(getToday());
- budget.setDomainid(domain);
- budget.addStringItem("topics", doc.getItemValueAsString("topic"));
- if ("单选".equals(doc.getItemValueAsString("voting"))) {
- budget.addStringItem("options", doc.getItemValueAsString("radio"));
- } else {
- budget.addStringItem("options", doc.getItemValueAsString("check"));
- }
- budget.addStringItem("voterid", user.getId());
- budget.addStringItem("pollid", doc.getId());
- if ("否".equals(doc.getItemValueAsString("anonymous"))) {
- budget.addStringItem("voters", user.getName());
- } else {
- budget.addStringItem("voters", "匿名");
- }
- budget.addDateItem("votetime", getToday());
- budget.addStringItem("comment",doc.getItemValueAsString("comment"));
- process.doCreate(budget);
- where = "";
- }
- }
- where;
复制代码 |