public static void Generate(Telerik.ReportViewer.Html5.WebForms.ReportViewer rv, IEnumerable<object> data, string extension, SortDescriptorCollection sortDescriptors, GroupDescriptorCollection grpDescriptors) { Telerik.Reporting.Report report1 = new Telerik.Reporting.Report(); report1.DataSource = data; string sortCol = ""; string sortDir = ""; //multi sort can be done by iterating through collection like for group if (sortDescriptors.Count > 0) { ColumnSortDescriptor sd = sortDescriptors[0] as ColumnSortDescriptor; sortCol = sd.Column.UniqueName; sortDir = sd.SortDirection.ToString(); } //Page Header Section Telerik.Reporting.PageHeaderSection pageHeaderSection1 = new Telerik.Reporting.PageHeaderSection(); pageHeaderSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch); pageHeaderSection1.Style.BackgroundColor = Color.Gray; Telerik.Reporting.TextBox txtHead = new Telerik.Reporting.TextBox(); txtHead.Value = "Title"; txtHead.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(3.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch)); txtHead.Name = "reportTitle"; txtHead.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch)); pageHeaderSection1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { txtHead }); IEnumerator dataColl = data.GetEnumerator(); int count = 0; int first = 0; object obj = null; while (dataColl.MoveNext()) { if (first == 0) { obj = dataColl.Current; foreach (PropertyInfo info in obj.GetType().GetProperties()) { count++; } first++; } } Telerik.Reporting.Drawing.Unit x = Telerik.Reporting.Drawing.Unit.Inch(0); Telerik.Reporting.Drawing.Unit y = Telerik.Reporting.Drawing.Unit.Inch(0); Telerik.Reporting.ReportItemBase[] headColumnList = new Telerik.Reporting.ReportItem[count]; Telerik.Reporting.ReportItemBase[] detailColumnList = new Telerik.Reporting.ReportItem[count]; Telerik.Reporting.Group group = new Telerik.Reporting.Group(); SizeU size = new SizeU(Telerik.Reporting.Drawing.Unit.Inch((double)(22) / count), Telerik.Reporting.Drawing.Unit.Inch(0.6)); int column = 0; foreach (PropertyInfo info in obj.GetType().GetProperties()) { string columnName = info.Name; Telerik.Reporting.HtmlTextBox headerCol = CreateTxtHeader(columnName, column); headerCol.Style.BackgroundColor = Color.LemonChiffon; headerCol.Style.BorderStyle.Default = BorderType.Solid; headerCol.Style.BorderWidth.Default = Unit.Pixel(1); headerCol.CanGrow = true; headerCol.Location = new Telerik.Reporting.Drawing.PointU(x, y); headerCol.Size = size; headColumnList[column] = headerCol; Telerik.Reporting.TextBox textBox = CreateTxtDetail(columnName, column); textBox.Style.BorderStyle.Default = BorderType.Solid; textBox.Style.BorderWidth.Default = Unit.Pixel(1); textBox.CanGrow = true; textBox.Location = new Telerik.Reporting.Drawing.PointU(x, y); textBox.Size = size; detailColumnList[column] = textBox; textBox.ItemDataBinding += new EventHandler(textBox_ItemDataBound); x += Telerik.Reporting.Drawing.Unit.Inch(headerCol.Size.Width.Value); column++; } Telerik.Reporting.ReportItemBase[] groupColumnList = new Telerik.Reporting.ReportItem[grpDescriptors.Count]; int i = grpDescriptors.Count; if (grpDescriptors.Count > 0) { Telerik.Reporting.GroupHeaderSection groupHeaderSection1 = new Telerik.Reporting.GroupHeaderSection(); foreach (ColumnGroupDescriptor grpDescriptor in grpDescriptors) { string grpCol = grpDescriptor.Column.UniqueName; group.Groupings.Add(new Grouping("=Fields." + grpCol)); if (grpDescriptor.SortDirection.ToString().ToLower() == "descending") { group.Sortings.Add(new Sorting("=Fields." + grpCol, SortDirection.Desc)); } else { group.Sortings.Add(new Sorting("=Fields." + grpCol, SortDirection.Asc)); } i--; Telerik.Reporting.TextBox hdCol = new Telerik.Reporting.TextBox(); hdCol.Style.BackgroundColor = Color.Orange; hdCol.Style.BorderStyle.Default = BorderType.Solid; hdCol.Style.BorderWidth.Default = Unit.Pixel(1); hdCol.KeepTogether = true; hdCol.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch)); hdCol.Value = "=[" + grpCol + "]"; groupColumnList[i] = hdCol; group.GroupHeader = groupHeaderSection1; //to avoid extra row after group col group.GroupHeader.Height = Telerik.Reporting.Drawing.Unit.Inch(0); } groupHeaderSection1.Items.AddRange(groupColumnList); } if (sortCol.Length > 0) { group.Groupings.Add(new Grouping("=Fields." + sortCol)); if (sortDir.ToLower() == "descending") { group.Sortings.Add(new Sorting("=Fields." + sortCol, SortDirection.Desc)); } else { group.Sortings.Add(new Sorting("=Fields." + sortCol, SortDirection.Asc)); } } ReportHeaderSection reportHeaderSection1 = new Telerik.Reporting.ReportHeaderSection(); reportHeaderSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch); reportHeaderSection1.Items.AddRange(headColumnList); report1.Groups.Add(group); //Detail Section Telerik.Reporting.DetailSection detailSection1 = new Telerik.Reporting.DetailSection(); detailSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch); detailSection1.Items.AddRange(detailColumnList); //Page Footer Section Telerik.Reporting.PageFooterSection pageFooterSection1 = new Telerik.Reporting.PageFooterSection(); pageFooterSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch); pageFooterSection1.Style.BackgroundColor = Color.LightGray; pageFooterSection1.PrintOnFirstPage = true; pageFooterSection1.PrintOnLastPage = true; Telerik.Reporting.TextBox txtFooter = new Telerik.Reporting.TextBox(); txtFooter.Value = "='Page ' + PageNumber + ' of ' + PageCount"; txtFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(4.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch)); txtFooter.Name = "pageInfoTextBox"; txtFooter.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch)); Telerik.Reporting.PictureBox picBoxFooter = new Telerik.Reporting.PictureBox(); picBoxFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(5.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch)); picBoxFooter.Value = @"C:\CCMSGoldStandard_Local\CCMSGoldStandard\CCMSAppShell\Images\no.png"; picBoxFooter.Style.TextAlign = Telerik.Reporting.Drawing. HorizontalAlign.Center; picBoxFooter.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(1, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))), new Telerik.Reporting.Drawing.Unit(.5D, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch)))); picBoxFooter.Sizing = ImageSizeMode.AutoSize; pageFooterSection1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { txtFooter, picBoxFooter }); //add all section to report report1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { pageHeaderSection1, reportHeaderSection1, detailSection1, pageFooterSection1 }); report1.PageSettings.Landscape = false; report1.PageSettings.Margins.Bottom = new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Inch); report1.PageSettings.Margins.Left = new Telerik.Reporting.Drawing.Unit(.25, Telerik.Reporting.Drawing.UnitType.Inch); report1.PageSettings.Margins.Right = new Telerik.Reporting.Drawing.Unit(.25, Telerik.Reporting.Drawing.UnitType.Inch); report1.PageSettings.Margins.Top = new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Inch); Telerik.Reporting.Drawing.SizeU paperSize = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(22, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(22, Telerik.Reporting.Drawing.UnitType.Inch)); report1.PageSettings.PaperSize = paperSize; report1.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Custom; Hashtable deviceInfo = new Hashtable(); deviceInfo["FontEmbedding"] = "Subset"; if (extension.ToLower() == "csv") { deviceInfo["NoHeader"] = true; deviceInfo["NoStaticText"] = true; } Telerik.Reporting.Processing.ReportProcessor RP = new Telerik.Reporting.Processing.ReportProcessor(); byte[] buffer = RP.RenderReport(extension.ToUpper(), report1, deviceInfo).DocumentBytes; string myPath = "C:"; string file = myPath + @"\" + DateTime.Now.ToString("HHmmss") + "." + extension; FileStream fs = new FileStream(file, FileMode.Create); fs.Write(buffer, 0, buffer.Length); fs.Flush(); fs.Close(); Process.Start(file); }
/// <summary> /// /// </summary> /// <param name="descriptors"></param> /// <param name="name"></param> public static int Add(this GroupDescriptorCollection descriptors, string name) { int count = descriptors.Count; descriptors.Add(name, ListSortDirection.Ascending); return(count); }
/// <summary> /// Initializes a new instance of the <see cref="GroupCollectionManager"/> class. /// </summary> /// <param name="sourceCollection">The collection of <see cref="GroupDescriptor"/>s to manage</param> /// <param name="descriptionCollection">The collection of <see cref="GroupDescription"/>s to synchronize with the <paramref name="sourceCollection"/></param> /// <param name="expressionCache">The cache with entries for the <see cref="GroupDescriptor"/>s</param> /// <param name="validationAction">The callback for validating items that are added or changed</param> public GroupCollectionManager(GroupDescriptorCollection sourceCollection, ObservableCollection<GroupDescription> descriptionCollection, ExpressionCache expressionCache, Action<GroupDescriptor> validationAction) { if (sourceCollection == null) { throw new ArgumentNullException("sourceCollection"); } if (descriptionCollection == null) { throw new ArgumentNullException("descriptionCollection"); } if (expressionCache == null) { throw new ArgumentNullException("expressionCache"); } if (validationAction == null) { throw new ArgumentNullException("validationAction"); } this._sourceCollection = sourceCollection; this._descriptionCollection = descriptionCollection; this.ExpressionCache = expressionCache; this._groupValidationAction = validationAction; this.ValidationAction = this.Validate; this.AsINotifyPropertyChangedFunc = this.AsINotifyPropertyChanged; this.AddCollection(sourceCollection); this.AddCollection(descriptionCollection); }
public void InitializeDescriptors() { this.sortDescriptors = new SortDescriptorCollection((IDataDescriptorsHost)this); this.sortDescriptors.CollectionChanged += this.OnSortDescriptorsCollectionChanged; this.groupDescriptors = new GroupDescriptorCollection((IDataDescriptorsHost)this); this.groupDescriptors.CollectionChanged += this.OnGroupDescriptorsCollectionChanged; this.filterDescriptors = new FilterDescriptorCollection((IDataDescriptorsHost)this); this.filterDescriptors.CollectionChanged += this.OnFilterDescriptorsCollectionChanged; this.aggregateDescriptors = new AggregateDescriptorCollection((IDataDescriptorsHost)this); this.aggregateDescriptors.CollectionChanged += this.OnAggregateDescriptorsCollectionChanged; }
public void CollectionManagerCollatesGroupDescriptorEvents() { GroupDescriptorCollection collection = new GroupDescriptorCollection(); ObservableCollection <GroupDescription> descriptionCollection = new ObservableCollection <GroupDescription>(); ExpressionCache cache = new ExpressionCache(); GroupDescriptor descriptor = null; this.CollectionManagerCollatesTemplate( (validationAction) => { return(new GroupCollectionManager(collection, descriptionCollection, cache, gd => validationAction())); }, () => { collection.Add(new GroupDescriptor()); }, () => { collection[0].PropertyPath = "First"; }, () => { collection.Add(new GroupDescriptor()); }, () => { collection[1].PropertyPath = "Second"; }, () => { collection[1] = new GroupDescriptor(); }, () => { descriptor = collection[0]; collection.Remove(descriptor); }, () => { descriptor.PropertyPath = "Removed"; }); }
/// <summary> /// Composes an <see cref="EntityQuery" /> for sorting and grouping purposes. /// </summary> /// <param name="source">The queryable source.</param> /// <param name="groupDescriptors">The group descriptors.</param> /// <param name="sortDescriptors">The sort descriptors.</param> /// <param name="expressionCache">Cache for storing built expressions</param> /// <returns>The composed <see cref="EntityQuery" />.</returns> public static EntityQuery OrderBy( EntityQuery source, GroupDescriptorCollection groupDescriptors, SortDescriptorCollection sortDescriptors, ExpressionCache expressionCache) { Debug.Assert(source != null, "Unexpected null source"); Debug.Assert(sortDescriptors != null, "Unexpected null sortDescriptors"); Debug.Assert(groupDescriptors != null, "Unexpected null groupDescriptors"); bool hasOrderBy = false; // check the GroupDescriptors first foreach (GroupDescriptor groupDescriptor in groupDescriptors) { if (groupDescriptor != null && groupDescriptor.PropertyPath != null) { Debug.Assert(expressionCache.ContainsKey(groupDescriptor), "There should be a cached group expression"); // check to see if we sort by the same parameter in desc order bool sortAsc = true; foreach (SortDescriptor sortDescriptor in sortDescriptors) { if (sortDescriptor != null) { string sortDescriptorPropertyPath = sortDescriptor.PropertyPath; string groupDescriptorPropertyPath = groupDescriptor.PropertyPath; if (sortDescriptorPropertyPath != null && sortDescriptorPropertyPath.Equals(groupDescriptorPropertyPath)) { if (sortDescriptor.Direction == ListSortDirection.Descending) { sortAsc = false; } break; } } } string orderMethodName = (!hasOrderBy ? "OrderBy" : "ThenBy"); if (!sortAsc) { orderMethodName += "Descending"; } source = OrderBy(source, orderMethodName, expressionCache[groupDescriptor]); hasOrderBy = true; } } // then check the SortDescriptors foreach (SortDescriptor sortDescriptor in sortDescriptors) { if (sortDescriptor != null) { Debug.Assert(expressionCache.ContainsKey(sortDescriptor), "There should be a cached sort expression"); string orderMethodName = (!hasOrderBy ? "OrderBy" : "ThenBy"); if (sortDescriptor.Direction == ListSortDirection.Descending) { orderMethodName += "Descending"; } source = OrderBy(source, orderMethodName, expressionCache[sortDescriptor]); hasOrderBy = true; } } return source; }
public void CollectionManagerCollatesGroupDescriptorEvents() { GroupDescriptorCollection collection = new GroupDescriptorCollection(); ObservableCollection<GroupDescription> descriptionCollection = new ObservableCollection<GroupDescription>(); ExpressionCache cache = new ExpressionCache(); GroupDescriptor descriptor = null; this.CollectionManagerCollatesTemplate( (validationAction) => { return new GroupCollectionManager(collection, descriptionCollection, cache, gd => validationAction()); }, () => { collection.Add(new GroupDescriptor()); }, () => { collection[0].PropertyPath = "First"; }, () => { collection.Add(new GroupDescriptor()); }, () => { collection[1].PropertyPath = "Second"; }, () => { collection[1] = new GroupDescriptor(); }, () => { descriptor = collection[0]; collection.Remove(descriptor); }, () => { descriptor.PropertyPath = "Removed"; }); }
/// <summary> /// Determines whether the <paramref name="groupDescriptions"/> are equivalent to the <paramref name="groupDescriptors"/>. /// </summary> /// <param name="groupDescriptions">The descriptions to compare</param> /// <param name="groupDescriptors">The descriptors to compare</param> /// <returns><c>true</c> if the collections are equivalent</returns> private static bool AreEquivalent(ObservableCollection<GroupDescription> groupDescriptions, GroupDescriptorCollection groupDescriptors) { Debug.Assert((groupDescriptions != null) && (groupDescriptors != null), "Both should be non-null."); if (groupDescriptions.Count != groupDescriptors.Count) { return false; } for (int i = 0, count = groupDescriptions.Count; i < count; i++) { if (!GroupCollectionManager.AreEquivalent(groupDescriptions[i], groupDescriptors[i])) { return false; } } return true; }
/// <summary> /// Resets the <paramref name="groupDescriptions"/> collection to match the <paramref name="groupDescriptors"/> collection. /// </summary> /// <param name="groupDescriptions">The collection to reset</param> /// <param name="groupDescriptors">The collection to match</param> private static void ResetToGroupDescriptors(ObservableCollection<GroupDescription> groupDescriptions, GroupDescriptorCollection groupDescriptors) { groupDescriptions.Clear(); foreach (GroupDescriptor descriptor in groupDescriptors) { GroupDescription description = GroupCollectionManager.GetDescriptionFromDescriptor(descriptor); if (description != null) { groupDescriptions.Add(description); } } }
/// <summary> /// Resets the <paramref name="groupDescriptors"/> collection to match the <paramref name="groupDescriptions"/> collection. /// </summary> /// <param name="groupDescriptions">The collection to match</param> /// <param name="groupDescriptors">The collection to reset</param> private static void ResetToGroupDescriptions(ObservableCollection<GroupDescription> groupDescriptions, GroupDescriptorCollection groupDescriptors) { groupDescriptors.Clear(); foreach (GroupDescription description in groupDescriptions) { groupDescriptors.Add(GroupCollectionManager.GetDescriptorFromDescription(description)); } }