/// <summary> /// Adds the field to the form. /// </summary> /// <param name="node">Document node</param> /// <param name="compareNode">Document compare node</param> /// <param name="columnName">Column name</param> private void AddField(TreeNode node, TreeNode compareNode, string columnName) { FormFieldInfo ffi = null; if (fi != null) { ffi = fi.GetFormField(columnName); } TableCell valueCell = new TableCell(); valueCell.EnableViewState = false; TableCell valueCompare = new TableCell(); valueCompare.EnableViewState = false; TableCell labelCell = new TableCell(); labelCell.EnableViewState = false; TextComparison comparefirst; TextComparison comparesecond; bool loadValue = true; bool empty = true; bool allowLabel = true; // Get the caption if ((columnName == UNSORTED) || (ffi != null)) { AttachmentInfo aiCompare = null; // Compare attachments if ((columnName == UNSORTED) || ((ffi != null) && (ffi.DataType == FieldDataType.DocAttachments))) { allowLabel = false; string title = String.Empty; if (columnName == UNSORTED) { title = GetString("attach.unsorted") + ":"; } else if (ffi != null) { string caption = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver); title = (String.IsNullOrEmpty(caption) ? ffi.Name : caption) + ":"; } // Prepare DataSource for original node loadValue = false; dsAttachments = new AttachmentsDataSource(); dsAttachments.DocumentVersionHistoryID = versionHistoryId; if ((ffi != null) && (columnName != UNSORTED)) { dsAttachments.AttachmentGroupGUID = ffi.Guid; } dsAttachments.Path = node.NodeAliasPath; dsAttachments.CultureCode = LocalizationContext.PreferredCultureCode; SiteInfo si = SiteInfoProvider.GetSiteInfo(node.NodeSiteID); dsAttachments.SiteName = si.SiteName; dsAttachments.OrderBy = "AttachmentOrder, AttachmentName, AttachmentHistoryID"; dsAttachments.SelectedColumns = "AttachmentHistoryID, AttachmentGUID, AttachmentImageWidth, AttachmentImageHeight, AttachmentExtension, AttachmentName, AttachmentSize, AttachmentOrder, AttachmentTitle, AttachmentDescription"; dsAttachments.IsLiveSite = false; dsAttachments.DataSource = null; dsAttachments.DataBind(); // Get the attachments table attachments = GetAttachmentsTable((DataSet)dsAttachments.DataSource, versionHistoryId, node.DocumentID); // Prepare data source for compared node if (compareNode != null) { dsAttachmentsCompare = new AttachmentsDataSource(); dsAttachmentsCompare.DocumentVersionHistoryID = versionCompare; if ((ffi != null) && (columnName != UNSORTED)) { dsAttachmentsCompare.AttachmentGroupGUID = ffi.Guid; } dsAttachmentsCompare.Path = compareNode.NodeAliasPath; dsAttachmentsCompare.CultureCode = LocalizationContext.PreferredCultureCode; dsAttachmentsCompare.SiteName = si.SiteName; dsAttachmentsCompare.OrderBy = "AttachmentOrder, AttachmentName, AttachmentHistoryID"; dsAttachmentsCompare.SelectedColumns = "AttachmentHistoryID, AttachmentGUID, AttachmentImageWidth, AttachmentImageHeight, AttachmentExtension, AttachmentName, AttachmentSize, AttachmentOrder, AttachmentTitle, AttachmentDescription"; dsAttachmentsCompare.IsLiveSite = false; dsAttachmentsCompare.DataSource = null; dsAttachmentsCompare.DataBind(); // Get the table to compare attachmentsCompare = GetAttachmentsTable((DataSet)dsAttachmentsCompare.DataSource, versionCompare, node.DocumentID); // Switch the sides if older version is on the right if (versionHistoryId > versionCompare) { Hashtable dummy = attachmentsCompare; attachmentsCompare = attachments; attachments = dummy; } // Add comparison AddTableComparison(attachments, attachmentsCompare, "<strong>" + title + "</strong>", true, true); } else { // Normal display if (attachments.Count != 0) { bool first = true; foreach (DictionaryEntry item in attachments) { string itemValue = ValidationHelper.GetString(item.Value, null); if (!String.IsNullOrEmpty(itemValue)) { valueCell = new TableCell(); labelCell = new TableCell(); if (first) { labelCell.Text = "<strong>" + String.Format(title, item.Key) + "</strong>"; first = false; } valueCell.Text = itemValue; AddRow(labelCell, valueCell); } } } } } // Compare single file attachment else if ((ffi != null) && (ffi.DataType == FieldDataType.File)) { // Get the attachment AttachmentInfo ai = DocumentHelper.GetAttachment(ValidationHelper.GetGuid(node.GetValue(columnName), Guid.Empty), versionHistoryId, TreeProvider, false); if (compareNode != null) { aiCompare = DocumentHelper.GetAttachment(ValidationHelper.GetGuid(compareNode.GetValue(columnName), Guid.Empty), versionCompare, TreeProvider, false); } loadValue = false; // Prepare text comparison controls if ((ai != null) || (aiCompare != null)) { string textorig = null; if (ai != null) { textorig = CreateAttachment(ai.Generalized.DataClass, versionHistoryId); } string textcompare = null; if (aiCompare != null) { textcompare = CreateAttachment(aiCompare.Generalized.DataClass, versionCompare); } comparefirst = new TextComparison(); comparefirst.SynchronizedScrolling = false; comparefirst.IgnoreHTMLTags = true; comparefirst.ConsiderHTMLTagsEqual = true; comparefirst.BalanceContent = false; comparesecond = new TextComparison(); comparesecond.SynchronizedScrolling = false; comparesecond.IgnoreHTMLTags = true; // Source text must be older version if (versionHistoryId < versionCompare) { comparefirst.SourceText = textorig; comparefirst.DestinationText = textcompare; } else { comparefirst.SourceText = textcompare; comparefirst.DestinationText = textorig; } comparefirst.PairedControl = comparesecond; comparesecond.RenderingMode = TextComparisonTypeEnum.DestinationText; valueCell.Controls.Add(comparefirst); valueCompare.Controls.Add(comparesecond); // Add both cells if (compareNode != null) { AddRow(labelCell, valueCell, valueCompare); } // Add one cell only else { valueCell.Controls.Clear(); Literal ltl = new Literal(); ltl.Text = textorig; valueCell.Controls.Add(ltl); AddRow(labelCell, valueCell); } } } } if (allowLabel && String.IsNullOrEmpty(labelCell.Text)) { labelCell.Text = "<strong>" + columnName + ":</strong>"; } if (loadValue) { string textcompare = null; switch (columnName.ToLowerCSafe()) { // Document content - display content of editable regions and editable web parts case "documentcontent": EditableItems ei = new EditableItems(); ei.LoadContentXml(ValidationHelper.GetString(node.GetValue(columnName), String.Empty)); // Add text comparison control if (compareNode != null) { EditableItems eiCompare = new EditableItems(); eiCompare.LoadContentXml(ValidationHelper.GetString(compareNode.GetValue(columnName), String.Empty)); // Create editable regions comparison Hashtable hashtable; Hashtable hashtableCompare; // Source text must be older version if (versionHistoryId < versionCompare) { hashtable = ei.EditableRegions; hashtableCompare = eiCompare.EditableRegions; } else { hashtable = eiCompare.EditableRegions; hashtableCompare = ei.EditableRegions; } // Add comparison AddTableComparison(hashtable, hashtableCompare, "<strong>" + columnName + " ({0}):</strong>", false, false); // Create editable webparts comparison // Source text must be older version if (versionHistoryId < versionCompare) { hashtable = ei.EditableWebParts; hashtableCompare = eiCompare.EditableWebParts; } else { hashtable = eiCompare.EditableWebParts; hashtableCompare = ei.EditableWebParts; } // Add comparison AddTableComparison(hashtable, hashtableCompare, "<strong>" + columnName + " ({0}):</strong>", false, false); } // No compare node else { // Editable regions Hashtable hashtable = ei.EditableRegions; if (hashtable.Count != 0) { foreach (DictionaryEntry region in hashtable) { string regionValue = ValidationHelper.GetString(region.Value, null); if (!String.IsNullOrEmpty(regionValue)) { string regionKey = ValidationHelper.GetString(region.Key, null); valueCell = new TableCell(); labelCell = new TableCell(); labelCell.Text = "<strong>" + columnName + " (" + DictionaryHelper.GetFirstKey(regionKey) + "):</strong>"; valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(regionValue, false)); AddRow(labelCell, valueCell); } } } // Editable web parts hashtable = ei.EditableWebParts; if (hashtable.Count != 0) { foreach (DictionaryEntry part in hashtable) { string partValue = ValidationHelper.GetString(part.Value, null); if (!String.IsNullOrEmpty(partValue)) { string partKey = ValidationHelper.GetString(part.Key, null); valueCell = new TableCell(); labelCell = new TableCell(); labelCell.Text = "<strong>" + columnName + " (" + DictionaryHelper.GetFirstKey(partKey) + "):</strong>"; valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(partValue, false)); AddRow(labelCell, valueCell); } } } } break; case "documentwebparts": StringBuilder sbOriginal = new StringBuilder(); StringBuilder sbCompared = new StringBuilder(); // Set original web parts string originalWebParts = Convert.ToString(node.GetValue(columnName)); GenerateWebPartsMarkup(ref sbOriginal, originalWebParts, true); // Add text comparison control if (compareNode != null) { string compareWebParts = Convert.ToString(compareNode.GetValue(columnName)); GenerateWebPartsMarkup(ref sbCompared, compareWebParts, false); } // Set empty flag empty = ((sbOriginal.Length == 0) && (sbCompared.Length == 0)); if (!empty) { valueCell.Text += sbOriginal.ToString(); valueCompare.Text = sbCompared.ToString(); } break; // Others, display the string value default: // Shift date time values to user time zone object origobject = node.GetValue(columnName); string textorig; if (origobject is DateTime) { textorig = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(origobject, DateTimeHelper.ZERO_TIME), true, CurrentUser, SiteContext.CurrentSite); } else { textorig = ValidationHelper.GetString(origobject, String.Empty); } // Add text comparison control if (compareNode != null) { // Shift date time values to user time zone object compareobject = compareNode.GetValue(columnName); if (compareobject is DateTime) { textcompare = TimeZoneHelper.ConvertToUserTimeZone(ValidationHelper.GetDateTime(compareobject, DateTimeHelper.ZERO_TIME), true, CurrentUser, SiteContext.CurrentSite); } else { textcompare = ValidationHelper.GetString(compareobject, String.Empty); } comparefirst = new TextComparison(); comparefirst.SynchronizedScrolling = false; comparesecond = new TextComparison(); comparesecond.SynchronizedScrolling = false; comparesecond.RenderingMode = TextComparisonTypeEnum.DestinationText; // Source text must be older version if (versionHistoryId < versionCompare) { comparefirst.SourceText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false)); comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textcompare, false)); } else { comparefirst.SourceText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textcompare, false)); comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false)); } comparefirst.PairedControl = comparesecond; if (Math.Max(comparefirst.SourceText.Length, comparefirst.DestinationText.Length) < 100) { comparefirst.BalanceContent = false; } valueCell.Controls.Add(comparefirst); valueCompare.Controls.Add(comparesecond); } else { valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false)); } empty = (String.IsNullOrEmpty(textorig)) && (String.IsNullOrEmpty(textcompare)); break; } } if (!empty) { if (compareNode != null) { AddRow(labelCell, valueCell, valueCompare); } else { AddRow(labelCell, valueCell); } } }
/// <summary> /// Adds the field to the form. /// </summary> /// <param name="node">Document node</param> /// <param name="compareNode">Document compare node</param> /// <param name="columnName">Column name</param> private void AddField(TreeNode node, TreeNode compareNode, string columnName) { FormFieldInfo ffi = null; if (fi != null) { ffi = fi.GetFormField(columnName); } TableCell valueCell = new TableCell(); valueCell.EnableViewState = false; TableCell valueCompare = new TableCell(); valueCompare.EnableViewState = false; TableCell labelCell = new TableCell(); labelCell.EnableViewState = false; TextComparison comparefirst = null; TextComparison comparesecond = null; bool switchSides = true; bool loadValue = true; bool empty = true; bool allowLabel = true; // Get the caption if ((columnName == UNSORTED) || (ffi != null)) { AttachmentInfo aiCompare = null; // Compare attachments if ((columnName == UNSORTED) || (ffi.DataType == FormFieldDataTypeEnum.DocumentAttachments)) { allowLabel = false; string title = null; if (columnName == UNSORTED) { title = GetString("attach.unsorted") + ":"; } else { title = (String.IsNullOrEmpty(ffi.Caption) ? ffi.Name : ffi.Caption) + ":"; } // Prepare DataSource for original node loadValue = false; dsAttachments = new AttachmentsDataSource(); dsAttachments.DocumentVersionHistoryID = versionHistoryId; if (columnName != UNSORTED) { dsAttachments.AttachmentGroupGUID = ffi.Guid; } dsAttachments.Path = node.NodeAliasPath; dsAttachments.CultureCode = CMSContext.PreferredCultureCode; SiteInfo si = SiteInfoProvider.GetSiteInfo(node.NodeSiteID); dsAttachments.SiteName = si.SiteName; dsAttachments.OrderBy = "AttachmentOrder, AttachmentName, AttachmentHistoryID"; dsAttachments.SelectedColumns = "AttachmentHistoryID, AttachmentGUID, AttachmentImageWidth, AttachmentImageHeight, AttachmentExtension, AttachmentName, AttachmentSize, AttachmentOrder, AttachmentTitle, AttachmentDescription"; dsAttachments.IsLiveSite = false; dsAttachments.DataSource = null; dsAttachments.DataBind(); // Get the attachments table attachments = GetAttachmentsTable((DataSet)dsAttachments.DataSource, versionHistoryId, node.DocumentID); // Prepare datasource for compared node if (compareNode != null) { dsAttachmentsCompare = new AttachmentsDataSource(); dsAttachmentsCompare.DocumentVersionHistoryID = versionCompare; if (columnName != UNSORTED) { dsAttachmentsCompare.AttachmentGroupGUID = ffi.Guid; } dsAttachmentsCompare.Path = compareNode.NodeAliasPath; dsAttachmentsCompare.CultureCode = CMSContext.PreferredCultureCode; dsAttachmentsCompare.SiteName = si.SiteName; dsAttachmentsCompare.OrderBy = "AttachmentOrder, AttachmentName, AttachmentHistoryID"; dsAttachmentsCompare.SelectedColumns = "AttachmentHistoryID, AttachmentGUID, AttachmentImageWidth, AttachmentImageHeight, AttachmentExtension, AttachmentName, AttachmentSize, AttachmentOrder, AttachmentTitle, AttachmentDescription"; dsAttachmentsCompare.IsLiveSite = false; dsAttachmentsCompare.DataSource = null; dsAttachmentsCompare.DataBind(); // Get the table to compare attachmentsCompare = GetAttachmentsTable((DataSet)dsAttachmentsCompare.DataSource, versionCompare, node.DocumentID); // Switch the sides if older version is on the right if (versionHistoryId > versionCompare) { Hashtable dummy = attachmentsCompare; attachmentsCompare = attachments; attachments = dummy; } // Add comparison AddTableComparison(attachments, attachmentsCompare, "<strong>" + title + "</strong>", true, true); } else { // Normal display if (attachments.Count != 0) { bool first = true; string itemValue = null; foreach (DictionaryEntry item in attachments) { itemValue = ValidationHelper.GetString(item.Value, null); if (!String.IsNullOrEmpty(itemValue)) { valueCell = new TableCell(); labelCell = new TableCell(); if (first) { labelCell.Text = "<strong>" + String.Format(title, item.Key) + "</strong>"; first = false; } valueCell.Text = itemValue; AddRow(labelCell, valueCell, null, even); even = !even; } } } } } // Compare single file attachment else if (ffi.DataType == FormFieldDataTypeEnum.File) { // Get the attachment AttachmentInfo ai = DocumentHelper.GetAttachment(ValidationHelper.GetGuid(node.GetValue(columnName), Guid.Empty), versionHistoryId, TreeProvider, false); if (compareNode != null) { aiCompare = DocumentHelper.GetAttachment(ValidationHelper.GetGuid(compareNode.GetValue(columnName), Guid.Empty), versionCompare, TreeProvider, false); } loadValue = false; empty = true; // Prepare text comparison controls if ((ai != null) || (aiCompare != null)) { string textorig = null; if (ai != null) { textorig = CreateAttachment(ai.Generalized.DataClass, versionHistoryId); } string textcompare = null; if (aiCompare != null) { textcompare = CreateAttachment(aiCompare.Generalized.DataClass, versionCompare); } comparefirst = new TextComparison(); comparefirst.SynchronizedScrolling = false; comparefirst.IgnoreHTMLTags = true; comparefirst.ConsiderHTMLTagsEqual = true; comparefirst.BalanceContent = false; comparesecond = new TextComparison(); comparesecond.SynchronizedScrolling = false; comparesecond.IgnoreHTMLTags = true; // Source text must be older version if (versionHistoryId < versionCompare) { comparefirst.SourceText = textorig; comparefirst.DestinationText = textcompare; } else { comparefirst.SourceText = textcompare; comparefirst.DestinationText = textorig; } comparefirst.PairedControl = comparesecond; comparesecond.RenderingMode = TextComparisonTypeEnum.DestinationText; valueCell.Controls.Add(comparefirst); valueCompare.Controls.Add(comparesecond); switchSides = false; // Add both cells if (compareNode != null) { AddRow(labelCell, valueCell, valueCompare, switchSides, null, even); } // Add one cell only else { valueCell.Controls.Clear(); Literal ltl = new Literal(); ltl.Text = textorig; valueCell.Controls.Add(ltl); AddRow(labelCell, valueCell, null, even); } even = !even; } } } if (allowLabel && (labelCell.Text == "")) { labelCell.Text = "<strong>" + columnName + ":</strong>"; } if (loadValue) { string textcompare = null; switch (columnName.ToLower()) { // Document content - display content of editable regions and editable web parts case "documentcontent": EditableItems ei = new EditableItems(); ei.LoadContentXml(ValidationHelper.GetString(node.GetValue(columnName), "")); // Add text comparison control if (compareNode != null) { EditableItems eiCompare = new EditableItems(); eiCompare.LoadContentXml(ValidationHelper.GetString(compareNode.GetValue(columnName), "")); // Create editable regions comparison Hashtable hashtable; Hashtable hashtableCompare; // Source text must be older version if (versionHistoryId < versionCompare) { hashtable = ei.EditableRegions; hashtableCompare = eiCompare.EditableRegions; } else { hashtable = eiCompare.EditableRegions; hashtableCompare = ei.EditableRegions; } // Add comparison AddTableComparison(hashtable, hashtableCompare, "<strong>" + columnName + " ({0}):</strong>", false, false); // Create editable webparts comparison // Source text must be older version if (versionHistoryId < versionCompare) { hashtable = ei.EditableWebParts; hashtableCompare = eiCompare.EditableWebParts; } else { hashtable = eiCompare.EditableWebParts; hashtableCompare = ei.EditableWebParts; } // Add comparison AddTableComparison(hashtable, hashtableCompare, "<strong>" + columnName + " ({0}):</strong>", false, false); } // No compare node else { // Editable regions Hashtable hashtable = ei.EditableRegions; if (hashtable.Count != 0) { string regionValue = null; string regionKey = null; foreach (DictionaryEntry region in hashtable) { regionValue = ValidationHelper.GetString(region.Value, null); if (!String.IsNullOrEmpty(regionValue)) { regionKey = ValidationHelper.GetString(region.Key, null); valueCell = new TableCell(); labelCell = new TableCell(); labelCell.Text = "<strong>" + columnName + " (" + MultiKeyHashtable.GetFirstKey(regionKey) + "):</strong>"; valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(regionValue, false)); AddRow(labelCell, valueCell, null, even); even = !even; } } } // Editable web parts hashtable = ei.EditableWebParts; if (hashtable.Count != 0) { string partValue = null; string partKey = null; foreach (DictionaryEntry part in hashtable) { partValue = ValidationHelper.GetString(part.Value, null); if (!String.IsNullOrEmpty(partValue)) { partKey = ValidationHelper.GetString(part.Key, null); valueCell = new TableCell(); labelCell = new TableCell(); labelCell.Text = "<strong>" + columnName + " (" + MultiKeyHashtable.GetFirstKey(partKey) + "):</strong>"; valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(partValue, false)); AddRow(labelCell, valueCell, null, even); even = !even; } } } } break; // Others, display the string value default: // Shift date time values to user time zone object origobject = node.GetValue(columnName); string textorig = null; if (origobject is DateTime) { TimeZoneInfo usedTimeZone = null; textorig = TimeZoneHelper.GetCurrentTimeZoneDateTimeString(ValidationHelper.GetDateTime(origobject, DateTimeHelper.ZERO_TIME), CurrentUser, CMSContext.CurrentSite, out usedTimeZone); } else { textorig = ValidationHelper.GetString(origobject, ""); } // Add text comparison control if (compareNode != null) { // Shift date time values to user time zone object compareobject = compareNode.GetValue(columnName); if (compareobject is DateTime) { TimeZoneInfo usedTimeZone = null; textcompare = TimeZoneHelper.GetCurrentTimeZoneDateTimeString(ValidationHelper.GetDateTime(compareobject, DateTimeHelper.ZERO_TIME), CurrentUser, CMSContext.CurrentSite, out usedTimeZone); } else { textcompare = ValidationHelper.GetString(compareobject, ""); } comparefirst = new TextComparison(); comparefirst.SynchronizedScrolling = false; comparesecond = new TextComparison(); comparesecond.SynchronizedScrolling = false; comparesecond.RenderingMode = TextComparisonTypeEnum.DestinationText; // Source text must be older version if (versionHistoryId < versionCompare) { comparefirst.SourceText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false)); comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textcompare, false)); } else { comparefirst.SourceText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textcompare, false)); comparefirst.DestinationText = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false)); } comparefirst.PairedControl = comparesecond; if (Math.Max(comparefirst.SourceText.Length, comparefirst.DestinationText.Length) < 100) { comparefirst.BalanceContent = false; } valueCell.Controls.Add(comparefirst); valueCompare.Controls.Add(comparesecond); switchSides = false; } else { valueCell.Text = HttpUtility.HtmlDecode(HTMLHelper.StripTags(textorig, false)); } empty = (String.IsNullOrEmpty(textorig)) && (String.IsNullOrEmpty(textcompare)); break; } } if (!empty) { if (compareNode != null) { AddRow(labelCell, valueCell, valueCompare, switchSides, null, even); even = !even; } else { AddRow(labelCell, valueCell, null, even); even = !even; } } }