/// <summary>
        /// 获取属性中定义的下拉列表选项集合
        /// </summary>
        /// <param name="prop">属性名称</param>
        /// <returns>{id,text}的集合</returns>
        public virtual JsonResult GetPropList(string prop)
        {
            ModelRule rule = ModelRule.Get <TModel>();

            var catAttr = rule.SingleRules.FirstOrDefault(attr => attr.Name.Equals(prop, StringComparison.OrdinalIgnoreCase));

            return(GetList(catAttr));
        }
        /// <summary>
        /// 获取子表中Grid的下拉列表选项
        /// </summary>
        /// <param name="detail">子表中模型中的集合属性名称</param>
        /// <param name="prop">集合属性中单个子项的属性名称</param>
        /// <returns>Json序列化后的{id, text}集合</returns>
        public virtual JsonResult GetDetailPropList(string detail, string prop)
        {
            ModelRule rule     = ModelRule.Get <TModel>();
            var       collRule = rule.CollectionRules.FirstOrDefault(r => r.Name.Equals(detail, StringComparison.OrdinalIgnoreCase));

            if (collRule == null)
            {
                return(null);
            }

            var catAttr = collRule.SingleRules.FirstOrDefault(attr => attr.Name.Equals(prop, StringComparison.OrdinalIgnoreCase));

            return(GetList(catAttr));
        }
Example #3
0
        private Expression <Func <T, bool> > BuildDefaultKeyFilter(string key)
        {
            Expression <Func <T, bool> > expr = null;

            ModelRule rule = ModelRule.Get <T>();

            foreach (var attr in rule.SingleRules)
            {
                if (!attr.Browsable)
                {
                    continue;
                }
                if (attr.Property.PropertyType == typeof(string))
                {
                    string exprStr = String.Format("{0}.Contains(@0)", attr.Name);
                    expr = expr.Or(Jurassic.Com.Tools.DynamicExpression.ParseLambda <T, bool>(exprStr, key));
                }
                else if (attr.Property.PropertyType.IsEnum && !attr.Property.PropertyType.IsNullableType())
                {
                    var enumValue = GetEnumValue(attr.Property.PropertyType, key);
                    if (enumValue == null)
                    {
                        continue;
                    }
                    string exprStr = String.Format("{0} = @0", attr.Name);
                    expr = expr.Or(Jurassic.Com.Tools.DynamicExpression.ParseLambda <T, bool>(exprStr, enumValue));
                }
                else if (attr.Property.PropertyType.IsNullableType())
                {
                    string exprStr = String.Format("{0} !=null &&{0}.Value.ToString().Contains(@0)", attr.Name);
                    expr = expr.Or(Jurassic.Com.Tools.DynamicExpression.ParseLambda <T, bool>(exprStr, key));
                }
                //else if (attr.Property.PropertyType == typeof(DateTime))
                //{
                //    DateTime dt = CommOp.ToDateTime(key);
                //    if (dt == default(DateTime)) continue;
                //    string exprStr = String.Format("{0} == @0", attr.Name);
                //    expr = expr.Or(Jurassic.Com.Tools.DynamicExpression.ParseLambda<T, bool>(exprStr, dt));
                //}
                else
                {
                    string exprStr = String.Format("{0}.ToString().Contains(@0)", attr.Name);
                    expr = expr.Or(Jurassic.Com.Tools.DynamicExpression.ParseLambda <T, bool>(exprStr, key));
                }
            }

            return(expr);
        }
        public virtual ActionResult Edit(TModel t)
        {
            if (Strict && !ModelState.IsValid)
            {
                return(JsonTips());
            }
            var modelRule = ModelRule.Get <TModel>();

            if (!t.Id.IsDefault()) //在修改操作时,复制原有对象集合到新对象的集合
            {
                var oldt = GetCurrentModel(t.Id);
                foreach (var collrule in modelRule.CollectionRules)
                {
                    collrule.Attr.Property.SetValue(t, modelRule.GetCollectionValue(oldt, collrule.Name), null);
                }
            }
            MethodInfo mi = this.GetType().GetMethod("SaveDetails", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod);

            foreach (ModelRule rule in modelRule.CollectionRules)
            {
                var gmi = mi.MakeGenericMethod(rule.ModelType);
                gmi.Invoke(this, new object[] { t, rule.Name });
            }
            if (!BeforeSaving(t))
            {
                return(JsonTips());
            }

            if (t.Id.IsDefault())
            {
                DataService.Add(t);
                AfterSaved(t);
                t = DataService.GetByKey(t.Id);
                BeforeShowing(t);
                Session[_modelSessionKey] = t;
                return(JsonTips("success", ResHelper.GetStr("Create_Success"), (object)JsonHelper.ToJson(t, true)));
            }
            else
            {
                var id = DataService.Change(t);
                AfterSaved(t);
                t = DataService.GetByKey(t.Id);
                BeforeShowing(t);
                Session[_modelSessionKey] = t;
                return(JsonTips("success", ResHelper.GetStr("Update_Success"), (object)JsonHelper.ToJson(t, true)));
            }
        }
        private void CreateDefaultChildren()
        {
            List <AppFunction> children       = new List <AppFunction>();
            string             controllerName = this.GetType().FullName;

            children.Add(new AppFunction
            {
                AuthType  = JAuthType.AllUsers,
                IconClass = "icon-new-edit",
                ParentId  = Function.Id,
                Id        = "DefaultAdd-" + Function.Id,
                LogType   = AppCenter.Logs.JLogType.Info,
                Visible   = VisibleType.Button | VisibleType.Menu,
                Ord       = 1,
                Name      = "新增",
            });

            children.Add(new AppFunction
            {
                AuthType  = JAuthType.AllUsers,
                IconClass = "icon-new-edit",
                ParentId  = Function.Id,
                Id        = "DefaultEdit-" + Function.Id,
                LogType   = AppCenter.Logs.JLogType.Info,
                Visible   = VisibleType.Button | VisibleType.Menu,
                Ord       = 2,
                Name      = "编辑",
            });
            children.Add(new AppFunction
            {
                AuthType       = JAuthType.AllUsers,
                IconClass      = "icon-new-delete",
                ParentId       = Function.Id,
                Id             = "DefaultDelete-" + Function.Id,
                Method         = WebMethod.POST,
                LogType        = AppCenter.Logs.JLogType.Info,
                ActionName     = "Delete",
                ControllerName = controllerName,
                Location       = Url.Action("Delete"),
                Visible        = VisibleType.Button | VisibleType.Menu,
                Ord            = 3,
                Name           = "删除",
            });

            var editPage = new AppFunction
            {
                AuthType       = JAuthType.AllUsers,
                ParentId       = Function.Id,
                Id             = "editpage-" + Function.Id,
                Method         = WebMethod.GET,
                LogType        = AppCenter.Logs.JLogType.Info,
                ActionName     = "Edit",
                ControllerName = controllerName,
                Location       = Url.Action("Edit"),
                Visible        = VisibleType.Role,
                Ord            = 3,
                Name           = "编辑页",
            };

            children.Add(editPage);

            children.Add(new AppFunction
            {
                AuthType       = JAuthType.AllUsers,
                IconClass      = "icon-new-save",
                ParentId       = editPage.Id,
                Id             = "DefaultSave-" + editPage.Id,
                Method         = WebMethod.POST,
                LogType        = AppCenter.Logs.JLogType.Info,
                ActionName     = "Edit",
                ControllerName = controllerName,
                Location       = Url.Action("Edit"),
                Visible        = VisibleType.Button | VisibleType.Menu,
                Ord            = 1,
                Name           = "保存",
            });
            children.Add(new AppFunction
            {
                AuthType       = JAuthType.AllUsers,
                IconClass      = "icon-new-copy",
                ParentId       = editPage.Id,
                Id             = "DefaultCopy-" + editPage.Id,
                Method         = WebMethod.POST,
                LogType        = AppCenter.Logs.JLogType.Info,
                ActionName     = "Copy",
                ControllerName = controllerName,
                Location       = Url.Action("Copy"),
                Visible        = VisibleType.Button | VisibleType.Menu,
                Ord            = 2,
                Name           = "复制",
            });
            children.Add(new AppFunction
            {
                AuthType  = JAuthType.AllUsers,
                IconClass = "icon-new-return",
                ParentId  = editPage.Id,
                Id        = "DefaultReturn-" + Function.Id,
                Visible   = VisibleType.Button | VisibleType.Menu,
                Ord       = 3,
                Name      = "返回",
            });

            var rule = ModelRule.Get <TModel>();

            //添加子表Grid上方工具栏按钮
            foreach (var r in rule.CollectionRules)
            {
                var detailMenu = new AppFunction
                {
                    AuthType  = JAuthType.AllUsers,
                    IconClass = "icon-new-add",
                    ParentId  = editPage.Id,
                    Id        = r.Name + "-" + editPage.Id,
                    Visible   = VisibleType.QuckAccessBar,
                    Ord       = 1,
                    Name      = r.Name,
                };
                children.Add(detailMenu);
                children.Add(new AppFunction
                {
                    AuthType  = JAuthType.AllUsers,
                    IconClass = "icon-new-add",
                    ParentId  = detailMenu.Id,
                    Id        = "DefaultAdd-" + detailMenu.Id,
                    Visible   = VisibleType.Button | VisibleType.Menu,
                    Ord       = 1,
                    Name      = "新增",
                });
                children.Add(new AppFunction
                {
                    AuthType  = JAuthType.AllUsers,
                    IconClass = "icon-new-delete",
                    ParentId  = detailMenu.Id,
                    Id        = "DefaultDelete-" + r.Name + "-" + editPage.Id,
                    Visible   = VisibleType.Button | VisibleType.Menu,
                    Ord       = 2,
                    Name      = "删除",
                });
            }

            foreach (var func in children)
            {
                AppManager.Instance.FunctionManager.Add(func);
            }
        }