Ejemplo n.º 1
0
        public JsonResult GetFormField()
        {
            string id        = Request.Form[NamingCenter.PARAM_PARENT_ID];
            string pageId    = Request.Form[NamingCenter.PARAM_PAGE_ID];
            var    component = PageBuilder.BuildPage(pageId).FindControl(id);

            if (component is Form)
            {
                var form = component as Form;
                if (form.FormService == null)
                {
                    throw new FoxOneException("Need_DataSource", form.Id);
                }
                if (form.FormService is EntityDataSource)
                {
                    var tempForm = ComponentHelper.GetFormComponent((form.FormService as EntityDataSource).EntityType);
                    foreach (var field in tempForm.Fields)
                    {
                        field.PageId   = pageId;
                        field.ParentId = id;
                        field.TargetId = "Fields";
                        ComponentHelper.RecSave(field);
                    }
                    return(Json(true));
                }
                if (form.FormService is DataTableDataSource)
                {
                    var tableName = (form.FormService as DataTableDataSource).TableName;
                    var table     = FoxOne.Data.Mapping.TableMapper.Tables[Dao.Get().ConnectionString].FirstOrDefault(o => o.Name.Equals(tableName, StringComparison.OrdinalIgnoreCase));
                    foreach (var f in table.Columns.Where(o => o.Editable).OrderBy(o => o.Rank))
                    {
                        var field = ControlDefaultSetting.GetFormControl(f);
                        field.PageId   = pageId;
                        field.ParentId = id;
                        field.TargetId = "Fields";
                        ComponentHelper.RecSave(field);
                    }
                    return(Json(true));
                }
            }
            throw new FoxOneException("Only_Suppost_Form_Ctrl");
        }
Ejemplo n.º 2
0
        private void AddForm()
        {
            Form form = null;

            if (Type != null)
            {
                form = ComponentHelper.GetFormComponent(Type);
            }
            else
            {
                if (Table == null)
                {
                    return;
                }
                form = new Form()
                {
                    Rank = 1, Id = "{0}Form".FormatTo(EditPageName)
                };
                form.PostUrl           = "/Entity/Edit";
                form.FormMode          = FormMode.Insert;
                form.AppendQueryString = true;
                form.FormService       = new CRUDDataSource()
                {
                    CRUDName = CRUDName, Id = form.Id + "Ds"
                };
                foreach (var field in Table.Columns.Where(o => o.Editable).OrderBy(o => o.Rank))
                {
                    var f = ControlDefaultSetting.GetFormControl(field);
                    form.Fields.Add(f);
                }
                foreach (var btn in ControlDefaultSetting.GetDefaultFormButton())
                {
                    form.Buttons.Add(btn);
                }
            }
            form.PageId   = EditPageName;
            form.ParentId = EditPageName;
            form.TargetId = "Right";
            ComponentHelper.RecSave(form);
        }
Ejemplo n.º 3
0
        public ActionResult ComponentEditor()
        {
            var    model    = new FormModel();
            string ctrlId   = Request.QueryString[NamingCenter.PARAM_CTRL_ID];
            string typeName = Request.QueryString[NamingCenter.PARAM_TYPE_NAME];
            string pageId   = Request.QueryString[NamingCenter.PARAM_PAGE_ID];
            string parentId = Request.QueryString[NamingCenter.PARAM_PARENT_ID];
            string targetId = Request.QueryString[NamingCenter.PARAM_TARGET_ID];

            Type            type      = null;
            IControl        instance  = null;
            ComponentEntity component = null;

            if (ctrlId.IsNullOrEmpty())
            {
                if (!pageId.IsNullOrEmpty() && !parentId.IsNullOrEmpty() && !targetId.IsNullOrEmpty() && Request.QueryString[NamingCenter.PARAM_FORM_VIEW_MODE] != "Insert")
                {
                    component = DBContext <ComponentEntity> .Instance.FirstOrDefault(o => o.PageId.Equals(pageId, StringComparison.OrdinalIgnoreCase) && o.TargetId.Equals(targetId, StringComparison.OrdinalIgnoreCase) && o.ParentId.Equals(parentId, StringComparison.OrdinalIgnoreCase));
                }
            }
            else
            {
                component = DBContext <ComponentEntity> .Instance.FirstOrDefault(o => o.PageId.Equals(pageId, StringComparison.OrdinalIgnoreCase) && o.Id.Equals(ctrlId, StringComparison.OrdinalIgnoreCase));
            }
            if (component != null)
            {
                ctrlId   = component.Id;
                pageId   = component.PageId;
                parentId = component.ParentId;
                if (typeName.IsNullOrEmpty() || typeName.Equals(component.Type))
                {
                    type = TypeHelper.GetType(component.Type);
                    if (!component.JsonContent.IsNullOrEmpty())
                    {
                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        serializer.RegisterConverters(new[] { new FoxOne.Business.ComponentConverter() });
                        instance = serializer.Deserialize(component.JsonContent, type) as IControl;
                        if (instance == null)
                        {
                            throw new FoxOneException("Ctrl_Not_Valid");
                        }
                        instance.Id = component.Id;
                    }
                    typeName  = type.FullName;
                    model.Tab = ComponentHelper.GetTabComponent(instance, ctrlId, pageId);
                }
            }
            if (typeName.IsNullOrEmpty())
            {
                throw new FoxOneException("Parameter_Not_Found", NamingCenter.PARAM_TYPE_NAME + " Or " + NamingCenter.PARAM_CTRL_ID);
            }
            if (type == null)
            {
                type = TypeHelper.GetType(typeName);
            }
            if (parentId.IsNullOrEmpty())
            {
                parentId = pageId;
            }
            model.EntityName      = type.FullName;
            model.Form            = ComponentHelper.GetFormComponent(type);
            model.Form.AutoHeight = false;
            model.Form.PostUrl    = HttpHelper.BuildUrl(ctrlEdit, Request);

            if (instance == null)
            {
                model.Form.FormMode = FormMode.Insert;
                instance            = Activator.CreateInstance(type) as IControl;
                if (ctrlId.IsNotNullOrEmpty())
                {
                    instance.Id = ctrlId;
                    var fbCtrl = instance as FormControlBase;
                    if (fbCtrl != null)
                    {
                        fbCtrl.Rank  = Request.QueryString["Rank"].ConvertTo <int>();
                        fbCtrl.Label = Request.QueryString["Label"];
                    }
                    model.Form.FormMode = FormMode.Edit;
                }
                else
                {
                    if (!parentId.IsNullOrEmpty())
                    {
                        instance.Id = parentId + type.Name;
                    }
                    else
                    {
                        if (!pageId.IsNullOrEmpty())
                        {
                            instance.Id = pageId + type.Name;
                        }
                    }
                }
            }
            else
            {
                model.Form.FormMode = FormMode.Edit;
            }

            //如果是编辑控件,则控件ID不允许更改。
            //model.Form.Fields.FirstOrDefault(o => o.Id.Equals("Id", StringComparison.OrdinalIgnoreCase)).Enable = !(model.Form.FormMode == FormMode.Edit);

            model.Form.Data = instance;
            if (model.Tab != null)
            {
                if (model.Tab.TabItems.Count == 1)
                {
                    model.Tab = null;
                }
                else
                {
                    model.Tab.TabItems[0].Content.Add(model.Form);
                }
            }
            return(View(model));
        }