Esempio n. 1
0
        private void LoadForm(IDictionary <string, object>[] allMetaFields)
        {
            Debug.Assert(!string.IsNullOrEmpty(this.modelName));
            Debug.Assert(this.viewRecord != null);
            Debug.Assert(this.fields != null);

            //this.modelName = (string)this.actionRecord["model"];
            //var layout = (string)this.viewRecord["layout"];

            var app    = (App)Application.Current;
            var layout = (String)this.viewRecord["layout"];

            var xs = new XmlSerializer(typeof(Sandwych.Layout.Models.Form));

            Sandwych.Layout.Models.Form form;
            using (var sr = new System.IO.StringReader(layout))
            {
                form = (Sandwych.Layout.Models.Form)xs.Deserialize(sr);
            }

            var factory    = new FieldControlFactory(this.modelName, allMetaFields);
            var le         = new Sandwych.Layout.LayoutEngine(factory);
            var layoutGrid = (UIElement)le.BuildLayout(form);

            this.fieldWidgets = factory.CreatedFieldWidgets;
            this.Content      = layoutGrid;

            //注册按钮的事件
            foreach (var button in factory.CreatedButtons)
            {
                button.Click += new RoutedEventHandler(this.OnCommandButtonClicked);
            }
        }
Esempio n. 2
0
        private object CreateQueryForm(Dictionary <string, object>[] fields, IEnumerable <XElement> viewFields, string where)
        {
            //生成基本查询条件表单
            var columnsPerRow = 6;// (int)Math.Round(this.Width / 150.00) * 2;

            if (columnsPerRow % 2 != 0)
            {
                columnsPerRow--;
            }
            var basicQueryForm = new Sandwych.Layout.Models.Form()
            {
                ColumnCount = columnsPerRow,
            };

            var basicFields = viewFields.Where(ele =>
            {
                var attr = ele.Attribute("where");
                return(attr != null && attr.Value == where);
            });

            var basicQueryFormChildren = new List <Sandwych.Layout.Models.Placable>();
            var factory = new QueryFieldControlFactory(fields);
            var createdFieldControls = new Dictionary <string, IQueryField>();

            foreach (var fieldLayout in basicFields)
            {
                var fieldName = fieldLayout.Attribute("name").Value;
                var metaField = fields.Single(i => (string)i["name"] == fieldName);
                var label     = new Sandwych.Layout.Models.Label()
                {
                    Text = (string)metaField["label"],
                };
                basicQueryFormChildren.Add(label);

                var field = new Sandwych.Layout.Models.Input()
                {
                    Field = (string)metaField["name"],
                };
                basicQueryFormChildren.Add(field);
            }
            basicQueryForm.ChildElements = basicQueryFormChildren.ToArray();

            var layoutEngine   = new Sandwych.Layout.LayoutEngine(factory);
            var basicQueryGrid = layoutEngine.BuildLayout(basicQueryForm);

            foreach (var p in factory.CreatedQueryFields)
            {
                this.createdQueryFields.Add(p.Key, p.Value);
            }

            return(basicQueryGrid);
        }