Пример #1
0
        private bool NeedSaveSpecial(MetaViewColumnModel item, List<MetaViewColumnModel> columnModel)
        {
            if (item.NeedSave)
                return true;

            if (item.AttributePurpose > 0)
            {
                var siblings = columnModel.Where(c => item.ParentId == c.ParentId && item.Id != c.Id).ToList();

                if (siblings.Any(sibling => sibling.NeedSave))
                    return true;

            }

            return false;
        }
Пример #2
0
        private static void AddEntities(Guid metaViewId, List<MetaViewColumnModel> items, List<MetadataEntityAttribute> metadataEntityAttribute, Guid entityId, Guid? parentId)
        {
            var atts = metadataEntityAttribute.Where(c => c.EntityId == entityId);

            foreach (var att in atts)
            {
                var item = items.FirstOrDefault(c => c.ParentId == parentId && c.AttributeId == att.Id);
                if(item == null)
                {
                    //var parentItem = items.FirstOrDefault(c => c.Id == parentId);
                    item = new MetaViewColumnModel()
                               {
                                   Id = Guid.NewGuid(),
                                   ParentId = parentId,
                                   AttributeId = att.Id,
                                   AttributeCaption = att.Caption,
                                   AttributeEntityId = att.EntityId,
                                   AttributeTypeId = att.TypeId,
                                   MetaViewId = metaViewId,
                                   AttributePurpose = att.Purpose,
                                   CustomEditor = string.Empty,
                                   CustomFormat = string.Empty
                               };
                    items.Add(item);

                   if(item.IsGroup && item.ParentId == null && att.ReferencedEntityId.HasValue)
                    {
                        AddEntities(metaViewId, items, metadataEntityAttribute, att.ReferencedEntityId.Value, item.Id);
                    }
                }
                else if(item.IsGroup && att.ReferencedEntityId.HasValue)
                {
                    AddEntities(metaViewId, items, metadataEntityAttribute, att.ReferencedEntityId.Value, item.Id);
                }
            }
        }
Пример #3
0
        private bool NeedSave(MetaViewColumnModel item, List<MetaViewColumnModel> columnModel, bool recursive = false )
        {
            if (item.ParentId == null)
            {
                if (
                    columnModel.Any(
                        c =>
                        c.AttributeId == item.AttributeId && !c.Id.ToString("N").Equals(item.Id.ToString("N"), StringComparison.InvariantCultureIgnoreCase)  &&
                        c.ParentId == null))
                {
                    var childrensecond = columnModel.Where(c => item.Id == c.ParentId).ToList();
                    if (childrensecond.Any())
                    {
                        if (childrensecond.Any(s => NeedSave(s, columnModel)))
                            return true;
                    }
                    else
                    {
                        return item.AllowEdit || item.AllowShow || item.AlowImportExport;
                    }
                    return false;
                }
                return true;
            }

            if (item.AllowEdit || item.AllowShow || item.AlowImportExport)
                return true;

            var children = columnModel.Where(c => item.Id == c.ParentId).ToList();

            if (!children.Any())
                return false;

            if (children.Any(c => c.AllowEdit || c.AllowShow || item.AlowImportExport))
                return true;

            if (children.Select(metaViewColumnModel => NeedSave(metaViewColumnModel, columnModel)).Any(needSave => needSave))
            {
                return true;
            }

            return false;
        }
Пример #4
0
        public static string GenerateColumnHtml(string name, MetaViewColumnModel m, List<MetaViewColumnModel> Model, ref int index, string refId)
        {
            string valuePrefix = string.Format("{0}[{1}]", name, index);

            var sb = new StringBuilder();
            string trName = string.Format("tr_{0}{1}", name, index);

            sb.AppendFormat("<tr Id='{0}' {1}>", trName,
                            string.IsNullOrEmpty(refId) ? string.Empty : string.Format("class='child-of-{0}'", refId));
            sb.AppendFormat("<input type='hidden' name='{0}.Id' value='{1}'></input>", valuePrefix, m.Id);
            sb.AppendFormat("<input type='hidden' name='{0}.AttributeId' value='{1}'></input>", valuePrefix, m.AttributeId);
            sb.AppendFormat("<input type='hidden' name='{0}.AttributePurpose' value='{1}'></input>", valuePrefix, m.AttributePurpose);
            sb.AppendFormat("<input type='hidden' name='{0}.ParentId' value='{1}'></input>", valuePrefix, m.ParentId);
            //sb.AppendFormat("<input type='hidden' name='{0}.MetaViewId' value='{1}'></input>", valuePrefix, m.MetaViewId);
            sb.AppendFormat("<td class='columnTree'>");
            sb.AppendFormat("{0}", m.AttributeCaption);
            sb.AppendFormat("</td>");
            sb.AppendFormat("<td><input name=\"{0}.SortOrder\" value='{1}' ></input></td>", valuePrefix, m.SortOrder);
            sb.AppendFormat("<td><input name=\"{0}.Width\" value='{1}' ></input></td>", valuePrefix, m.Width);
            //sb.AppendFormat("<td><input name=\"{0}.Width\" value='{1}' ></input></td>", valuePrefix, m.Width);
            sb.AppendFormat("<td class=\"ColumnChecked\"><input name=\"{0}.AllowShow\" type=\"checkbox\" {1} class=\"AllowShow\" value='true' ></input></td>", valuePrefix, m.AllowShow ? "checked=\"checked\"" : string.Empty);
            sb.AppendFormat("<td class=\"ColumnChecked\"><input name=\"{0}.AllowEdit\" type=\"checkbox\" {1} class=\"AllowEdit\" value='true' ></input></td>", valuePrefix, m.AllowEdit ? "checked=\"checked\"" : string.Empty);
            sb.AppendFormat("<td class=\"ColumnChecked\"><input name=\"{0}.AlowImportExport\" type=\"checkbox\" {1} class=\"AlowImportExport\" value='true' ></input></td>", valuePrefix, m.AlowImportExport ? "checked=\"checked\"" : string.Empty);
            sb.AppendFormat("<td class=\"ColumnChecked\"><input name=\"{0}.AllowCompare\" type=\"checkbox\" {1} class=\"AllowCompare\" value='true' ></input></td>", valuePrefix, m.AllowCompare ? "checked=\"checked\"" : string.Empty);
            if (m.IsGroup)
            {
                var availiableViews = MetadataAttributeHelper.GetAvailableViewsForEdit(m.AttributeId);
                if (availiableViews.Count() > 0)
                {
                    sb.AppendFormat("<td><select name='{0}.MetaViewForSelectId'>", valuePrefix);
                    foreach (var availiableView in availiableViews)
                    {
                        if (m.MetaViewForSelectId.HasValue && availiableView.Id == m.MetaViewForSelectId.Value)
                            sb.AppendFormat("<option selected value='{0}'>{1}</option>", availiableView.Id, availiableView.Name);
                        else
                            sb.AppendFormat("<option value='{0}'>{1}</option>", availiableView.Id, availiableView.Name);

                    }
                    sb.Append("</select></td>");
                }
                else
                {
                    sb.Append("<td></td>");
                }
            }
            else
            {
                sb.Append("<td></td>");
            }
            sb.AppendFormat("<td><input name=\"{0}.CustomCaption\" value=\"{1}\"></input></td>", valuePrefix, m.CustomCaption);
            sb.AppendFormat("<td><input name=\"{0}.CustomFormat\" value='{1}' ></input></td>", valuePrefix, m.CustomFormat);
            sb.AppendFormat("<td><input name=\"{0}.CustomEditor\" value='{1}' ></input></td>", valuePrefix, m.CustomEditor);
            sb.Append("</tr>");

            if(m.IsGroup)
            {
                foreach(var item in Model.Where(c=> c.ParentId == m.Id))
                {
                    index++;
                    sb.Append(GenerateColumnHtml(name, item, Model, ref index, trName));
                }
            }

            return sb.ToString();
        }