ASP.NET Aries Advanced Development Tutorial: Form detection field is saved (side story)

Preface:

Just yesterday someone asked this question, and therefore address this issue, it added something chapter.

text: 

Figure: the user to edit the list, the user name is whether it will automatically detect that already exists.  

Html specific content corresponding to the following:

                            <label><em>*</em>用户名:</label>
                            <input name="UserName" id="UserName" missingmessage="" class='easyui-validatebox' validtype="exists['UserName']"  required="required" />
                        </div>
                        <div class="short"> 

Verification parameter is a string type, for the field name.

Initiated request content:

The core principle:

JS achieve in concrete: Aries.EasyUIExtend.js file.

            validator: function (value, param) {
                if (!param[0]) {
                    this.message = $Core.Lang.ruleError;
                    return false;
                }
                var data = {};
                data.n = param[0].name || param[0];
                data.v = value;
                if (data.n.indexOf(',') > -1) {
                    var items = data.n.split(',');
                    if (items.length > 1) {
                        data.n = items[0];
                        var $input = $(":input[name='" + items[1] + "']");
                        if ($input) {
                            data.n2 = items[1];
                            data.v2 = $input.val();
                        }
                        if (items.length > 2) {
                            var $input = $(":input[name='" + items[2] + "']");
                            if ($input) {
                                data.n3 = items[2];
                                data.v3 = $input.val();
                            }

                        }
                    }
                }
                var id = param[1] || AR.Utility.queryString('id');
                if (id) data.id = id;
                //method, objName, data, async, url, callback, isShowProgress
                var result = AR.Ajax.get("Exists", AR.Form.tableName, data);
                if (result) {
                    if (result.success) {
                        this.message = $Core.Lang.dataExists;
                        return false;
                    }
                    return true;
                }
                else {
                    this.messgage = $Core.Lang.requestFail;
                    return false;
                }
            }
        },

 这段实现,可以带多两个参数,即可以满足三个联合主键组成的唯一。

即配置可以成Exsists['name1','name2','name3']。

对应的后台代码:

 [ActionKey("View,Get")]
        /// <summary>
        /// 是否存在某数据。
        /// </summary>
        public void Exists()
        {
            string name = Query<string>("n", "");
            string value = Query<string>("v", "");

            string name2 = Query<string>("n2", "");
            string value2 = Query<string>("v2", "");

            string name3 = Query<string>("n3", "");
            string value3 = Query<string>("v3", "");//支持到三个,可以了

            bool result = false;
            using (MAction action = new MAction(ObjCode))
            {
                string id = GetID;
                string where = string.Format("{0}='{1}'", name, value);
                if (name2 != "" && value2 != "")
                {
                    where += string.Format(" and {0}='{1}'", name2, value2);
                }
                if (name3 != "" && value3 != "")
                {
                    where += string.Format(" and {0}='{1}'", name3, value3);
                }
                if (!string.IsNullOrEmpty(id))
                {
                    where += string.Format(" and {0}<>'{1}'", action.Data.PrimaryCell.ColumnName, id);
                }
                result = action.Exists(where);
            }
            jsonResult = JsonHelper.OutResult(result, string.Empty);
        }

扩展:在行内编辑,如何实现该功能: 

这里只给出思路,dg.options.onEditing事件中,可以拿到编辑框,可以动态赋加验证属性,也可以拿到值,再调用Exsits手工检测。

Guess you like

Origin www.cnblogs.com/cyq1162/p/11243440.html