示例#1
0
        public String CreateControl(ActiveRecordModel model, BelongsToModel belongsToModel, object instance)
        {
            stringBuilder.Length = 0;

            PropertyInfo prop = belongsToModel.Property;

            ActiveRecordModel otherModel = ActiveRecordModel.GetModel(belongsToModel.BelongsToAtt.Type);

            PrimaryKeyModel keyModel = ObtainPKProperty(otherModel);

            if (otherModel == null || keyModel == null)
            {
                return("Model not found or PK not found");
            }

            object[] items = CommonOperationUtils.FindAll(otherModel.Type);

            String propName = String.Format("{0}.{1}", prop.Name, keyModel.Property.Name);

            object value = null;

            if (instance != null)
            {
                if (model.IsNestedType)
                {
                    instance = model2nestedInstance[model];
                }

                if (instance != null)
                {
                    value = prop.GetValue(instance, null);
                }
            }

            stringBuilder.Append(LabelFor(propName, prop.Name + ":  "));

            stringBuilder.Append(Select(propName));

            if (!belongsToModel.BelongsToAtt.NotNull)
            {
                stringBuilder.Append(CreateOption("Empty", 0));
            }

            stringBuilder.Append(CreateOptionsFromArray(items, null, keyModel.Property.Name, value));

            stringBuilder.Append(EndSelect());

            return(stringBuilder.ToString());
        }
示例#2
0
        public String CreateControl(ActiveRecordModel model, String prefix,
                                    HasAndBelongsToManyModel hasAndBelongsModel, object instance)
        {
            stringBuilder.Length = 0;

            var prop = hasAndBelongsModel.Property;

            prefix += "." + prop.Name;

            var otherModel = ActiveRecordModel.GetModel(hasAndBelongsModel.HasManyAtt.MapType);

            var keyModel = ObtainPKProperty(otherModel);

            if (otherModel == null || keyModel == null)
            {
                return("Model not found or PK not found");
            }

            var source = CommonOperationUtils.FindAll(otherModel.Type);

            stringBuilder.Append(prop.Name + ":  ");
            stringBuilder.Append("<br/>\r\n");

            IDictionary attrs = new HybridDictionary(true);

            attrs["value"] = keyModel.Property.Name;

            var list = CreateCheckboxList(prefix, source, attrs);

            foreach (var item in list)
            {
                stringBuilder.Append(list.Item());

                stringBuilder.Append(item.ToString());

                stringBuilder.Append("<br/>\r\n");
            }

            return(stringBuilder.ToString());
        }
示例#3
0
        public String CreateControl(ActiveRecordModel model, String prefix,
                                    BelongsToModel belongsToModel, object instance)
        {
            stringBuilder.Length = 0;

            var prop = belongsToModel.Property;

            prefix += "." + prop.Name;

            var otherModel = ActiveRecordModel.GetModel(belongsToModel.BelongsToAtt.Type);

            var keyModel = ObtainPKProperty(otherModel);

            if (otherModel == null || keyModel == null)
            {
                return("Model not found or PK not found");
            }

            var items = CommonOperationUtils.FindAll(otherModel.Type);

            var propName = CreatePropName(model, prefix, keyModel.Property.Name);

            stringBuilder.Append(LabelFor(propName, TextHelper.PascalCaseToWord(prop.Name) + ": &nbsp;"));

            IDictionary attrs = new HybridDictionary(true);

            attrs["value"] = keyModel.Property.Name;

            if (!belongsToModel.BelongsToAtt.NotNull)
            {
                attrs.Add("firstOption", "Empty");
                attrs.Add("firstOptionValue", "");
            }

            stringBuilder.Append(Select(propName, items, attrs));

            return(stringBuilder.ToString());
        }
示例#4
0
        public String CreateControl(ActiveRecordModel model, HasAndBelongsToManyModel hasAndBelongsModel, object instance)
        {
            stringBuilder.Length = 0;

            PropertyInfo prop = hasAndBelongsModel.Property;

            ActiveRecordModel otherModel = ActiveRecordModel.GetModel(hasAndBelongsModel.HasManyAtt.MapType);

            PrimaryKeyModel keyModel = ObtainPKProperty(otherModel);

            if (otherModel == null || keyModel == null)
            {
                return("Model not found or PK not found");
            }

            object container = InitializeRelationPropertyIfNull(instance, prop);

            object value = null;

            if (container != null)
            {
                value = CreateArrayFromExistingIds(keyModel, container as ICollection);
            }

            object[] items = CommonOperationUtils.FindAll(otherModel.Type, hasAndBelongsModel.HasManyAtt.Where);

            String propName = String.Format("{0}.{1}", prop.Name, keyModel.Property.Name);

            stringBuilder.Append(LabelFor(propName, prop.Name + ": &nbsp;"));
            stringBuilder.Append("<br/>");
            stringBuilder.Append(Select(propName, new DictHelper().CreateDict("size=6", "multiple")));
            stringBuilder.Append(CreateOptionsFromArray(items, null, keyModel.Property.Name, value));
            stringBuilder.Append(EndSelect());

            return(stringBuilder.ToString());
        }