Ejemplo n.º 1
0
        private void lvDesign_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
        {
            lvDesign.ColumnWidthChanged -= lvDesign_ColumnWidthChanged;

            var layout = ((ListView)sender);

            var column     = layout.Columns[e.ColumnIndex];
            var definition = (XmlNode)column.Tag;

            if (Snapped)
            {
                column.Width = NormalizeWidth(column.Width);
            }

            var attribute = definition.Attributes["width"];
            var width     = column.Width.ToString();

            if (!attribute.Value.Equals(width))
            {
                attribute.Value = width;

                var pattern = string.Format("//cell[@name=\"{0}\"]", definition.Attributes["name"].Value);
                var cell    = LayoutXml.SelectNodes(pattern).Cast <XmlNode>().FirstOrDefault();
                cell = definition;

                IsLayoutXmlChanged = true;
            }

            lvDesign.ColumnWidthChanged += lvDesign_ColumnWidthChanged;
        }
Ejemplo n.º 2
0
        private void lvDesign_ColumnReordered(object sender, ColumnReorderedEventArgs e)
        {
            var layout = XDocument.Parse(LayoutXml.OuterXml);

            var cells = layout.Descendants().First().Descendants().First().Descendants();

            var source = cells.ElementAt(e.OldDisplayIndex);
            var target = cells.ElementAt(e.NewDisplayIndex);

            if (e.OldDisplayIndex > e.NewDisplayIndex)
            {
                target.AddBeforeSelf(source);
            }
            else
            {
                target.AddAfterSelf(source);
            }

            source.Remove();

            LayoutXml.LoadXml(layout.ToString());

            IsLayoutXmlChanged = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// SavedQueryView constructor
        /// </summary>
        /// <param name="serviceContext">OrganizationServiceContext</param>
        /// <param name="savedQuery">savedquery entity</param>
        /// <param name="fetchXmlString">Existing known FetchXML for this view</param>
        /// <param name="layoutXmlString">Existing known LayoutXML for this view</param>
        /// <param name="languageCode">Language code used to retrieve the localized attribute label</param>
        /// <param name="aliasColumnNameStringFormat">A format string used to compose an alias column label. Index 0 is the alias attribute display name, index 1 is the aliased entity's display name. Default is "{0} ({1})".</param>
        public SavedQueryView(OrganizationServiceContext serviceContext, Entity savedQuery, string fetchXmlString, string layoutXmlString, int?languageCode = 0, string aliasColumnNameStringFormat = DefaultAliasColumnNameStringFormat)
        {
            if (serviceContext == null)
            {
                throw new ArgumentNullException("serviceContext");
            }

            if (savedQuery == null)
            {
                throw new ArgumentNullException("savedQuery");
            }

            ServiceContext = serviceContext;
            SavedQuery     = savedQuery;
            LanguageCode   = languageCode ?? 0;
            AliasColumnNameStringFormat = aliasColumnNameStringFormat;

            if (string.IsNullOrEmpty(fetchXmlString))
            {
                fetchXmlString = savedQuery.GetAttributeValue <string>("fetchxml");
            }
            if (!string.IsNullOrEmpty(fetchXmlString))
            {
                FetchXml       = XElement.Parse(fetchXmlString);
                SortExpression = SetSortExpression(FetchXml);

                var entityElement = FetchXml.Element("entity");
                if (entityElement != null)
                {
                    var entityName = entityElement.Attribute("name").Value;
                    EntityLogicalName = entityName;
                }

                var response = (RetrieveEntityResponse)ServiceContext.Execute(new RetrieveEntityRequest
                {
                    LogicalName   = EntityLogicalName,
                    EntityFilters = EntityFilters.Attributes
                });

                if (response == null || response.EntityMetadata == null)
                {
                    ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("Failed to get EntityMetadata for entity of type '{0}'.", EntityNamePrivacy.GetEntityName(EntityLogicalName)));

                    return;
                }

                EntityMetadata = response.EntityMetadata;

                PrimaryKeyLogicalName = EntityMetadata.PrimaryIdAttribute;
            }

            if (string.IsNullOrEmpty(layoutXmlString))
            {
                layoutXmlString = savedQuery.GetAttributeValue <string>("layoutxml");
            }
            LayoutXml = XElement.Parse(layoutXmlString);

            var rowElement = LayoutXml.Element("row");

            if (rowElement != null)
            {
                var cellNames = rowElement.Elements("cell")
                                .Where(cell => cell.Attribute("ishidden") == null || cell.Attribute("ishidden").Value != "1")
                                .Select(cell => cell.Attribute("name")).Where(name => name != null);
                CellNames = cellNames;
                var disabledSortCellNames = rowElement.Elements("cell")
                                            .Where(cell => cell.Attribute("disableSorting") != null && cell.Attribute("disableSorting").Value == "1")
                                            .Where(cell => cell.Attribute("name") != null)
                                            .Select(cell => cell.Attribute("name").Value);
                DisabledSortCellNames = disabledSortCellNames;
                var cellWidths = rowElement.Elements("cell")
                                 .Where(cell => cell.Attribute("ishidden") == null || cell.Attribute("ishidden").Value != "1")
                                 .Where(cell => cell.Attribute("name") != null)
                                 .ToDictionary(cell => cell.Attribute("name").Value, cell => Convert.ToInt32(cell.Attribute("width").Value));
                CellWidths = cellWidths;
            }

            Name = ServiceContext.RetrieveLocalizedLabel(savedQuery.ToEntityReference(), "name", LanguageCode);
            Id   = savedQuery.GetAttributeValue <Guid>("savedqueryid");
        }