private void SmartCopyForm_Load(object sender, EventArgs e)
{
string sourceName = "";
if (_source is ReportModel)
{
sourceName = "[Model Properties] ";
addRadioButton.Text = "Add the model to the destination reports selected";
updateRadioButton.Text = "Update selected properties, elements or restrictions to the destination models selected";
}
else if (_source is ReportRestriction)
{
sourceName = "[Restriction Properties] ";
addRadioButton.Text = "Add the restriction to the destination models selected";
updateRadioButton.Text = "Update selected properties to the destination restrictions selected";
}
else if (_source is ReportElement)
{
sourceName = "[Element Properties] ";
addRadioButton.Text = "Add the element to the destination models selected";
updateRadioButton.Text = "Update selected properties to the destination elements selected";
}
else if (_source is ReportView)
{
sourceName = "[View Properties] ";
addRadioButton.Text = "Add the view to the destination views selected";
updateRadioButton.Text = "Update selected properties, parameters or CSS values to the destination views selected";
}
else if (_source is ReportTask)
{
sourceName = "[Task Properties] ";
addRadioButton.Text = "Add the task to the destination reports selected";
updateRadioButton.Text = "Update selected properties to the destination tasks selected";
}
else if (_source is ReportOutput)
{
sourceName = "[Output Properties] ";
addRadioButton.Text = "Add the output to the destination reports selected";
updateRadioButton.Text = "Update selected properties to the destination outputs selected";
}
else if (_source is TasksFolder)
{
sourceName = "[Tasks Script] ";
addRadioButton.Visible = false;
updateRadioButton.Text = "Update selected properties to the reports selected";
}
List<PropertyItem> properties = new List<PropertyItem>();
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(_source))
{
if (_source is ReportView && property.Name == "ChartConfigurationXml")
{
properties.Add(new PropertyItem() { Name = "[View parameters] MS Chart Configuration", Object = property });
continue;
}
if (!property.IsBrowsable || property.IsReadOnly) continue;
DisplayNameAttribute displayAtt = property.Attributes.OfType<DisplayNameAttribute>().FirstOrDefault();
CategoryAttribute catAtt = property.Attributes.OfType<CategoryAttribute>().FirstOrDefault();
if (displayAtt != null && catAtt != null)
{
if (_source is ReportModel)
{
if (displayAtt.DisplayName.ToLower() == "source") continue;
}
else if (_source is ReportOutput)
{
if (displayAtt.DisplayName.ToLower() == "view name") continue;
}
properties.Add(new PropertyItem() { Name = string.Format("[{0}] {1}", catAtt.Category, displayAtt.DisplayName), Object = property });
}
}
//Manual sort by category...
List<PropertyItem> sortedProperties = new List<PropertyItem>();
sortedProperties.Add(new PropertyItem() { Name = sourceName + "Select/Unselect All", Object = null });
if (_source is ReportModel)
{
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Model Definition]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[SQL]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Join Preferences]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Options]")));
}
else if (_source is ReportRestriction)
{
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Definition]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Restriction Values]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Advanced]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Data Options]")));
}
else if (_source is ReportElement)
{
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Definition]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Chart]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Options]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Data Options]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Advanced]")));
}
else if (_source is ReportView)
{
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Definition]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Custom template configuration]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Custom template text]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[View parameters]")));
}
else if (_source is ReportTask)
{
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Definition]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Options]")));
}
else if (_source is ReportOutput)
{
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Definition]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Email Addresses]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Email Subject]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Email Body]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Email Attachments]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Folder]")));
sortedProperties.AddRange(properties.Where(i => i.Name.StartsWith("[Restrictions]")));
}
propertiesCheckedListBox.DataSource = sortedProperties;
propertiesCheckedListBox.DisplayMember = "Name";
propertiesCheckedListBox.ClearSelected();
source2CheckedListBox.Visible = false;
source3CheckedListBox.Visible = false;
if (_source is ReportModel)
{
ReportModel model = _source as ReportModel;
source2CheckedListBox.Visible = true;
source3CheckedListBox.Visible = true;
properties = new List<PropertyItem>();
properties.Add(new PropertyItem() { Name = "[Elements] Select/Unselect All", Object = null });
foreach (ReportElement element in model.Elements)
{
properties.Add(new PropertyItem() { Name = element.DisplayNameEl, Object = element });
}
source2CheckedListBox.DataSource = properties;
source2CheckedListBox.DisplayMember = "Name";
source2CheckedListBox.ClearSelected();
properties = new List<PropertyItem>();
properties.Add(new PropertyItem() { Name = "[Restriction] Select/Unselect All", Object = null });
properties.Add(new PropertyItem() { Name = "Restriction text", Object = null });
properties.Add(new PropertyItem() { Name = "[Aggregate] Restriction text", Object = null });
foreach (ReportElement restriction in model.Restrictions)
{
properties.Add(new PropertyItem() { Name = restriction.DisplayNameEl, Object = restriction });
}
foreach (ReportElement restriction in model.AggregateRestrictions)
{
properties.Add(new PropertyItem() { Name = string.Format("[Aggregate] {0}", restriction.DisplayNameEl), Object = restriction });
}
source3CheckedListBox.DataSource = properties;
source3CheckedListBox.DisplayMember = "Name";
source3CheckedListBox.ClearSelected();
}
else if (_source is ReportView)
{
ReportView view = _source as ReportView;
source2CheckedListBox.Visible = true;
source3CheckedListBox.Visible = true;
properties = new List<PropertyItem>();
properties.Add(new PropertyItem() { Name = "[Parameters] Select/Unselect All", Object = null });
foreach (var item in view.Parameters)
{
properties.Add(new PropertyItem() { Name = item.DisplayName, Object = item });
}
source2CheckedListBox.DataSource = properties;
source2CheckedListBox.DisplayMember = "Name";
source2CheckedListBox.ClearSelected();
properties = new List<PropertyItem>();
properties.Add(new PropertyItem() { Name = "[CSS Values] Select/Unselect All", Object = null });
foreach (var item in view.CSS)
{
properties.Add(new PropertyItem() { Name = item.DisplayName, Object = item });
}
source3CheckedListBox.DataSource = properties;
source3CheckedListBox.DisplayMember = "Name";
source3CheckedListBox.ClearSelected();
}
reportsListBox.DisplayMember = "Name";
_lastReports.RemoveAll(i => ((Report)i.Object).FilePath == _report.FilePath);
foreach (var item in _lastReports) reportsListBox.Items.Add(item);
destinationCheckedListBox.DisplayMember = "Name";
buildDestinationList();
if (LastSize != null) Size = LastSize.Value;
if (LastLocation != null) Location = LastLocation.Value;
}