子表数据重复检验(后端)可以改成主表
//获取到子表对象 H3.DataModel.BizObject[] child = (H3.DataModel.BizObject[]) this.Request.BizObject["D002033Fe0b8d95ac4e64112afabdf8069e098d5"]; //遍历子表对象 foreach(H3.DataModel.BizObject item in child) { string repStr = string.Format("select * from I_D002033Fe0b8d95ac4e64112afabdf8069e098d5 where F0000003='{0}'", item["F0000003"] + string.Empty); DataTable repDt = this.Engine.Query.QueryTable(repStr, null); if(repDt != null && repDt.Rows.Count > 0) { response.Infos.Add("子表数据提交重复"); } }
/* 控件接口说明: * 1. 读取控件: this.***,*号输入控件编码; * 2. 读取控件的值: this.***.GetValue(); * 3. 设置控件的值: this.***.SetValue(???); * 4. 绑定控件值变化事件: this.***.BindChange(key,function(){}),key是定义唯一的方法名; * 5. 解除控件值变化事件: this.***.UnbindChange(key); * 6. CheckboxList、DropDownList、RadioButtonList: $.***.AddItem(value,text),$.***.ClearItems(); */ /* 公共接口: * 1. ajax:$.SmartForm.PostForm(actionName,data,callBack,errorBack,async), * actionName:提交的ActionName;data:提交后台的数据;callback:回调函数;errorBack:错误回调函数;async:是否异步; * 2. 打开表单:$.IShowForm(schemaCode, objectId, checkIsChange), * schemaCode:表单编码;objectId;表单数据Id;checkIsChange:关闭时,是否感知变化; * 3. 定位接口:$.ILocation(); */ var that = this; // 表单插件代码 $.extend( $.JForm, { // 加载事件 OnLoad: function() { isAlreadyCreated(); that.F0000031.BindChange( "F0000031key", function() { isAlreadyCreated(); }); }, // 按钮事件 OnLoadActions: function( actions ) { }, // 提交校验 OnValidate: function( actionControl ) { //判断当前点击的按钮编码是否是"Submit"、"Save" if( actionControl.Action == "Submit" ) { var isAlreadyCreated = that.isAlreadyCreated.GetValue(); if(isAlreadyCreated) { $.IShowError( "错误", "本月已经提交!" );//弹出错误消息 return false; } } return true; }, // 提交前事件 BeforeSubmit: function( action, postValue ) { }, // 提交后事件 AfterSubmit: function( action, responseValue ) { } }); function isAlreadyCreated() { $.SmartForm.PostForm( "isAlreadyCreated", { creator: $.SmartForm.ResponseContext.Originator, reportTime: that.F0000031.GetValue() }, function( data ) { if( data.Errors && data.Errors.length ) { } else { if( data.ReturnData == undefined ) { } else { //接收后端传参 var result = data.ReturnData[ "result" ]; if( result ) { $.IShowError( "错误", "本月已经提交!" );//弹出错误消息 }; that.isAlreadyCreated.SetValue(result); } } }); } using System; using System.Collections.Generic; using System.Text; using H3; public class D000772d33d98a1a3a44959ae71a1c6ab6dc555: H3.SmartForm.SmartFormController { public D000772d33d98a1a3a44959ae71a1c6ab6dc555(H3.SmartForm.SmartFormRequest request): base(request) { } protected override void OnLoad(H3.SmartForm.LoadSmartFormResponse response) { base.OnLoad(response); } protected override void OnSubmit(string actionName, H3.SmartForm.SmartFormPostValue postValue, H3.SmartForm.SubmitSmartFormResponse response) { if(actionName == "isAlreadyCreated") { //获取前端传递的数据 string creator = this.Request["creator"]; string reportTime = this.Request["reportTime"]; //定义sql string sql = "select F0000031 from I_D000772d33d98a1a3a44959ae71a1c6ab6dc555 where createdby = '" + creator + "' and objectid != '" + this.Request.BizObjectId + "' order by F0000031 desc limit 0,1"; //调用sql,接收结果 System.Data.DataTable dt = this.Engine.Query.QueryTable(sql, null); //判断返回结果是否为空 if(dt != null && dt.Rows.Count > 0) { // foreach(System.Data.DataRow row in dt.Rows) // { // } response.ReturnData = new Dictionary<string, object>(); //最新创建时间 DateTime time = Convert.ToDateTime(dt.Rows[0]["F0000031"] + string.Empty); //当前时间 DateTime now = Convert.ToDateTime(reportTime); //当时间和月份匹配相等时,返回true if(time.Year == now.Year && time.Month == now.Month) { response.ReturnData.Add("result", true); } else { response.ReturnData.Add("result", false); } } } if(actionName == "Save" || actionName == "Submit") { this.Request.BizObject["F0000031"] = postValue.Data["F0000031"]; } base.OnSubmit(actionName, postValue, response); } }
一个月只能填写一次数据检验(按月份)(改)
后端代码
if(actionName == "isAlreadyCreated") { //获取前端传递的数据 string creator = this.Request["creator"]; string reportTime = this.Request["reportTime"]+string.Empty; //当前日期 DateTime now = Convert.ToDateTime(reportTime); //定义sql string sql = "select F0000031 from I_D000772d33d98a1a3a44959ae71a1c6ab6dc555 where year(F0000031)='" + now.Year + " ' and month(F0000031)='" + now.Month + " ' and createdby = '" + creator + "' and objectid != '" + this.Request.BizObjectId + "' order by F0000031 desc"; //调用sql,接收结果 System.Data.DataTable dt = this.Engine.Query.QueryTable(sql, null); //判断返回结果是否为空 if(dt != null && dt.Rows.Count > 0) { // foreach(System.Data.DataRow row in dt.Rows) // response.ReturnData = new Dictionary<string, object>(); //获取数据库的日期 // DateTime time = Convert.ToDateTime(dt.Rows[0]["F0000031"] + string.Empty); response.ReturnData = new Dictionary<string, object>(); response.ReturnData.Add("result", true); } else { //当时间和月份匹配相等时,返回true // if(time.Year == now.Year && time.Month == now.Month) // { // response.ReturnData.Add("result", true); // } // else // { // response.ReturnData.Add("result", false); // } response.ReturnData = new Dictionary<string, object>(); response.ReturnData.Add("result", false); } } if(actionName == "Save" || actionName == "Submit") { this.Request.BizObject["F0000031"] = postValue.Data["F0000031"]; }
前端代码
var that = this; // 表单插件代码 $.extend( $.JForm, { // 加载事件 OnLoad: function() { isAlreadyCreated(); that.F0000031.BindChange( "F0000031key", function() { isAlreadyCreated(); }); // that.F0000004.BindChange( "F0000004key", function() { // var fs=that.F0000004.GetText(); // }); }, // 按钮事件 OnLoadActions: function( actions ) { }, // 提交校验 OnValidate: function( actionControl ) { //判断当前点击的按钮编码是否是"Submit"、"Save" if( actionControl.Action == "Submit" ) { var isAlreadyCreated = that.isAlreadyCreated.GetValue(); if(isAlreadyCreated) { $.IShowError( "错误", "当月已经提交!" );//弹出错误消息 return false; } } return true; }, // 提交前事件 BeforeSubmit: function( action, postValue ) { }, // 提交后事件 AfterSubmit: function( action, responseValue ) { } }); function isAlreadyCreated() { debugger var F0000031 = that.F0000031.GetValue(); $.SmartForm.PostForm( "isAlreadyCreated", { creator: $.SmartForm.ResponseContext.Originator, reportTime: F0000031 }, function( data ) { if( data.Errors && data.Errors.length ) { } else { if( data.ReturnData == undefined) { } else { //接收后端传参 var result = data.ReturnData[ "result" ]; if( result ) { $.IShowError( "错误", "当月已经提交!" );//弹出错误消息 }; that.isAlreadyCreated.SetValue(result); } } }); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· 地球OL攻略 —— 某应届生求职总结