Esempio n. 1
0
        private void BwDisplayViewDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (ListViewDelegates.GetSelectedItems(lvSourceViews).Count() > 1)
                {
                    ColumnHeader header = new ColumnHeader();
                    header.Width = 380;
                    header.Text  = "Layout preview cannot be displayed when multiple views are selected.";
                    ListViewDelegates.AddColumn(lvSourceViewLayoutPreview, header);
                }
                else
                {
                    // Gets current view data
                    Entity currentSelectedView = (Entity)ListViewDelegates.GetSelectedItems(lvSourceViews)[0].Tag;
                    string layoutXml           = currentSelectedView["layoutxml"].ToString();
                    string fetchXml            = currentSelectedView.Contains("fetchxml")
                                          ? currentSelectedView["fetchxml"].ToString()
                                          : string.Empty;
                    string currentEntityDisplayName = ListViewDelegates.GetSelectedItems(lvEntities)[0].Text;

                    EntityMetadata currentEmd =
                        entitiesCache.Find(
                            delegate(EntityMetadata emd)
                            { return(emd.DisplayName.UserLocalizedLabel.Label == currentEntityDisplayName); });

                    XmlDocument layoutDoc = new XmlDocument();
                    layoutDoc.LoadXml(layoutXml);

                    EntityMetadata emdWithItems = MetadataHelper.RetrieveEntity(currentEmd.LogicalName, service);

                    ListViewItem item = new ListViewItem();

                    foreach (XmlNode columnNode in layoutDoc.SelectNodes("grid/row/cell"))
                    {
                        ColumnHeader header = new ColumnHeader();

                        header.Text = MetadataHelper.RetrieveAttributeDisplayName(emdWithItems,
                                                                                  columnNode.Attributes["name"].Value,
                                                                                  fetchXml, service);

                        int columnWidth = columnNode.Attributes["width"] == null ? 0 : int.Parse(columnNode.Attributes["width"].Value);

                        header.Width = columnWidth;

                        ListViewDelegates.AddColumn(lvSourceViewLayoutPreview, header);

                        if (string.IsNullOrEmpty(item.Text))
                        {
                            item.Text = columnWidth == 0 ? "(undefined)": (columnWidth + "px");
                        }
                        else
                        {
                            item.SubItems.Add(columnWidth == 0 ? "(undefined)": (columnWidth + "px"));
                        }
                    }

                    ListViewDelegates.AddItem(lvSourceViewLayoutPreview, item);

                    GroupBoxDelegates.SetEnableState(gbSourceViewLayout, true);
                }
            }
            catch (Exception error)
            {
                CommonDelegates.DisplayMessageBox(ParentForm, "Error while displaying view: " + error.Message, "Error",
                                                  MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }