private void TestDataSources(object expected, ReportDataSourceCollection actual) { foreach (ReportDataSource actualReportDataSource in actual) { if (expected.GetType().IsArray) { bool isDataSourceFound = false; foreach (var expectedReportDataSource in (IEnumerable)expected) { if (expectedReportDataSource.GetType().GetProperty("Name").GetValue(expectedReportDataSource).ToString() == actualReportDataSource.Name) { isDataSourceFound = true; TestObjects(expectedReportDataSource, actualReportDataSource); break; } } if (!isDataSourceFound) { Assert.Fail(); } } else { TestObjects(expected, actualReportDataSource); } } }
public void FillDataSources(ReportDataSourceCollection dataSources) { dataSources.Add(new ReportDataSource("DataSet1")); dataSources["DataSet1"].Value = _tunesRecords; dataSources.Add(new ReportDataSource("DataSet2")); dataSources["DataSet2"].Value = _testsRecords; }
/// <summary> /// 根据后台数据来生成数据源。 /// </summary> /// <param name="dataSources"></param> private void AddDataSource(ReportDataSourceCollection dataSources) { var em = this.Meta.EntityMeta; //如果数据是一个单一聚合实体,则把它及它的第一层聚合子对象作为数据源加入。 var data = this.Data; var entity = data as Entity; if (entity != null) { dataSources.Add(new ReportDataSource(em.EntityType.Name, new BindingSource(entity, null))); foreach (var childProperty in em.ChildrenProperties) { dataSources.Add(new ReportDataSource( childProperty.ChildType.EntityType.Name, new BindingSource(entity, childProperty.Name) )); } return; } //如果数据是一个实体列表,则直接把这个列表作为报表的数据源。 var entityList = data as EntityList; if (entityList != null) { dataSources.Add(new ReportDataSource(em.EntityType.Name, entityList)); } }
protected override void FillReportData(ReportDataSourceCollection sources, List <ReportParameter> pars) { // Получение даты начала выборки ХП в UTC. DateTime?startDate = UserTimeZoneHelper.ToUniversalTime(BeginInterval, UserTimeZone); // Формирование списка параметров RDL. pars.Add(new ReportParameter("dDateBegin", String.Format("{0:dd MMMM yyyy} г.", BeginInterval))); pars.Add(new ReportParameter("cLogin", UserLogin)); pars.Add(new ReportParameter("cUserName", UserName)); // Вызов ХП с сохранением полученного рекордсета в переменную "dt". var dt = spc.FillTable("rptAnodeReportDay", "dDateIn", startDate, SqlDbType.DateTime); var rds = new ReportDataSource { Name = "DataSet", Value = dt }; sources.Add(rds); // Отчёт редактируется, для его редактирования заполним данные. EditedInfoList.First().Source = dt; }
public ReportGenerator(LocalReport localReport) { if (localReport == null) { throw new ArgumentNullException("localReport"); } this.localReport = localReport; this.DataSources = localReport.DataSources; }
public void FillDataSources(ReportDataSourceCollection dataSources) { dataSources.Add(new ReportDataSource("TO1DataSet")); dataSources.Add(new ReportDataSource("TO2DataSet")); dataSources.Add(new ReportDataSource("UOGTDataSet")); dataSources["TO1DataSet"].Value = _summaryTO1.GetReportLines(); dataSources["TO2DataSet"].Value = _summaryTO2.GetReportLines(); dataSources["UOGTDataSet"].Value = _summaryUOGT.GetReportLines(); }
public ReportGenerator(LocalReport localReport) { if (localReport == null) { throw new ArgumentNullException(nameof(localReport)); } _localReport = localReport; DataSources = localReport.DataSources; }
private void SetDataSources(ReportDataSourceCollection reportDataSources) { reportDataSources.Clear(); foreach (var dataSource in dataSources) { if (dataSource.Value is IEnumerable) { reportDataSources.Add(new ReportDataSource(dataSource.Key, (IEnumerable)dataSource.Value)); } else { reportDataSources.Add(new ReportDataSource(dataSource.Key, dataSource.Value)); } } }
void GenerateReport(string ReportDataSet, string ReportName, NameValueCollection ReportParameters) { SqlConnection connection = new SqlConnection(Session["CustomerConnectSQLString"].ToString()); Type adapterType = Type.GetType("TMS_Recycling." + ReportDataSet); DataSet newSet = Activator.CreateInstance(adapterType) as DataSet; ReportViewerShow.LocalReport.ReportPath = "Reports\\" + ReportName + ".rdlc"; ReportViewerShow.LocalReport.DataSources.Clear(); ReportDataSourceCollection RepDSColl = ReportViewerShow.LocalReport.DataSources; ClassDataSetHelper.Load(newSet, RepDSColl, connection, ReportParameters); ReportViewerShow.LocalReport.Refresh(); }
/// <summary> /// Adds the elements of the specified collection to the end of the ReportDataSourceCollection. /// </summary> /// <param name="reportDataSourceCollection">The ReportDataSourceCollection that this method extends.</param> /// <param name="collection">The collection whose elements should be added to the end of the ReportDataSourceCollection.</param> public static void Add(this ReportDataSourceCollection reportDataSourceCollection, IEnumerable <ReportDataSource> collection) { if (reportDataSourceCollection == null) { throw new ArgumentNullException("reportDataSourceCollection", "Value cannot be null."); } if (collection == null) { throw new ArgumentNullException("collection", "Value cannot be null."); } foreach (ReportDataSource reportDataSource in collection) { reportDataSourceCollection.Add(reportDataSource); } }
protected void Page_Load(object sender, EventArgs e) { if ((!IsPostBack) && (Request.Params["d"] != null)) { // set the connection to execute the dataset for the report builder SqlConnection connection = new SqlConnection(Session["CustomerConnectSQLString"].ToString()); Type adapterType = Type.GetType("TMS_Recycling." + Request.Params["d"].ToString()); DataSet newSet = Activator.CreateInstance(adapterType) as DataSet; // set the reportviewers report path. This report will be shown ReportViewerShow.LocalReport.ReportPath = "Reports\\" + Request.Params["r"].ToString() + ".rdlc"; // link up the reports dataset and datasources and fill them with data ReportViewerShow.LocalReport.DataSources.Clear(); ReportDataSourceCollection RepDSColl = ReportViewerShow.LocalReport.DataSources; ClassDataSetHelper.Load(newSet, RepDSColl, connection, Request.Params); // get the URL parameters & set them in the report List <ReportParameter> paramList = new List <ReportParameter>(); ReportParameterInfoCollection rpic = ReportViewerShow.LocalReport.GetParameters(); for (int i = 0; i < Request.Params.Count; i++) { if (rpic[Request.Params.GetKey(i)] != null) { if ((Request.Params.GetKey(i).IndexOf("Id") == Request.Params.GetKey(i).Length - 2) && (Request.Params.GetValues(i)[0] == "")) // if this parametername ends with Id and has an empty value then make it an empty guid { paramList.Add(new ReportParameter(Request.Params.GetKey(i), Guid.Empty.ToString())); } else { paramList.Add(new ReportParameter(Request.Params.GetKey(i), Request.Params.GetValues(i))); } } } ReportViewerShow.LocalReport.SetParameters(paramList); // refresh the report ReportViewerShow.LocalReport.Refresh(); } }
/// <summary> /// 加入自定义数据源 /// </summary> /// <param name="dataSources"></param> private void AddCustomDataSource(ReportDataSourceCollection dataSources) { foreach (var item in this._customDataSources) { var entityOrList = item.Value; var itemEntity = entityOrList as Entity; if (itemEntity != null) { dataSources.Add(new ReportDataSource(itemEntity.GetType().Name, new BindingSource(itemEntity, null))); } //如果数据是一个实体列表,则直接把这个列表作为报表的数据源。 var itemEntityList = entityOrList as EntityList; if (itemEntityList != null) { dataSources.Add(new ReportDataSource(itemEntityList.EntityType.Name, itemEntityList)); } dataSources.Add(new ReportDataSource(item.Key, item.Value)); } }
public void FillDataSources(ReportDataSourceCollection dataSources) { throw new NotImplementedException(); }
public ReportPriner(string reportPath, ReportDataSourceCollection dataSources, object p) { ReportPath = reportPath; this.DataSources = dataSources; this.p = p; }
public static void Load(DataSet data, ReportDataSourceCollection ReportData, SqlConnection connection, NameValueCollection Pars) { foreach (DataTable table in data.Tables) { /// Find the table adapter using Reflection. Type adapterType = GetTableAdapterType(table); object adapterObj = SetupTableAdapterObject(adapterType, connection); SqlCommand[] sqColl = (SqlCommand[])GetPropertyValue(adapterType, adapterObj, "CommandCollection"); SqlCommand sqc = sqColl[0]; if ((sqc != null) && (Pars != null)) { // scan for parameters to fill foreach (SqlParameter sp in sqc.Parameters) { string ParName = sp.ParameterName.Remove(0, 1); if (Pars[ParName] != null) { if (sqc.Parameters[sp.ParameterName].DbType == DbType.Guid) { if (Pars[ParName] != "") { sqc.Parameters[sp.ParameterName].Value = new Guid(Pars[ParName]); } else { sqc.Parameters[sp.ParameterName].Value = Guid.Empty; } } else { sqc.Parameters[sp.ParameterName].Value = Pars[ParName]; } } } } // rip off the constraints on the fields in this datatable foreach (DataColumn dc in table.Columns) { if (dc.MaxLength > 0) { dc.MaxLength = -1; } dc.AllowDBNull = true; } try { connection.Open(); SqlDataReader sdr = sqc.ExecuteReader(); table.Load(sdr); ReportDataSource rds = new ReportDataSource(); rds.Name = table.TableName; rds.Value = table; ///ReportData.Add(new ReportDataSource(table.TableName, table)); ReportData.Add(rds); } finally { connection.Close(); } } }
public JsonResult GeneratePreBill(BillRequest billRequest) { bool isEnglishBilling; var preBill = _billRepo.GeneratePreBill(billRequest, out isEnglishBilling); //Report setup var details = preBill.BillDetails.Select(d => new { BillDetailType = Convert.ToInt32(d.BillDetailType), FixedAmount = d.FixedAmount, UnitRate = d.UnitRate, Quantity = d.Quantity, Subtotal = d.Subtotal, Description = d.Description, TaxesAmount = d.TaxesAmount }).ToList(); string basePath = _hostingEnvironment.ContentRootPath; string fullPath = basePath + @"/Reports/Bill.rdlc"; FileStream inputStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read); ReportDataSourceCollection dataSources = new ReportDataSourceCollection(); dataSources.Add(new ReportDataSource { Name = "BillDataSet", Value = details }); Syncfusion.ReportWriter.ReportWriter writer = new Syncfusion.ReportWriter.ReportWriter(inputStream, dataSources); //Setting up the parameters List <ReportParameter> parameters = new List <ReportParameter>(); //IsEnglish ReportParameter isEnglishParam = new ReportParameter(); isEnglishParam.Name = "IsEnglish"; isEnglishParam.Values = new List <string>() { isEnglishBilling ? "1" : "0" }; //IsBilled ReportParameter isBilledParam = new ReportParameter(); isBilledParam.Name = "IsBilled"; isBilledParam.Values = new List <string>() { "0" }; //ClientName ReportParameter clientNameParam = new ReportParameter(); clientNameParam.Name = "ClientName"; clientNameParam.Values = new List <string>() { preBill.BillName }; //BillingPeriod string culture = isEnglishBilling ? "en" : "es"; string billingPeriod = $"{CultureInfo.GetCultureInfoByIetfLanguageTag(culture).DateTimeFormat.GetMonthName(DateTime.UtcNow.AddHours(-6).Month)} - {preBill.BillYear}"; ReportParameter billingPeriodParam = new ReportParameter(); billingPeriodParam.Name = "BillingPeriod"; billingPeriodParam.Values = new List <string>() { billingPeriod }; //Subtotal ReportParameter subTotalExpenseParam = new ReportParameter(); subTotalExpenseParam.Name = "Subtotal"; subTotalExpenseParam.Values = new List <string>() { preBill.BillSubtotal.ToString() }; //Discount ReportParameter discountParam = new ReportParameter(); discountParam.Name = "Discount"; discountParam.Values = new List <string>() { preBill.BillDiscount.ToString() }; //Taxes ReportParameter taxesParam = new ReportParameter(); taxesParam.Name = "Taxes"; taxesParam.Values = new List <string>() { preBill.Taxes.ToString() }; //TotalExpense ReportParameter totalParam = new ReportParameter(); totalParam.Name = "Total"; totalParam.Values = new List <string>() { preBill.Total.ToString() }; //TotalExpense ReportParameter billDateParam = new ReportParameter(); billDateParam.Name = "BillDate"; billDateParam.Values = new List <string>() { preBill.BillDate.ToString("dd/MM/yyyy") }; parameters.Add(isEnglishParam); parameters.Add(isBilledParam); parameters.Add(clientNameParam); parameters.Add(billingPeriodParam); parameters.Add(subTotalExpenseParam); parameters.Add(discountParam); parameters.Add(taxesParam); parameters.Add(totalParam); parameters.Add(billDateParam); writer.SetParameters(parameters); writer.ReportProcessingMode = ProcessingMode.Local; MemoryStream memoryStream = new MemoryStream(); writer.Save(memoryStream, WriterFormat.PDF); memoryStream.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(memoryStream, "application/pdf"); fileStreamResult.FileDownloadName = $"FacturaCliente{preBill.BillName}deMes{preBill.BillMonth}YAño{preBill.BillYear}.pdf"; return(Json(new { result = memoryStream.ConvertToBase64() })); }
public void FillDataSources(ReportDataSourceCollection dataSources) { dataSources.Add(new ReportDataSource("ShiftReportDataSet")); dataSources["ShiftReportDataSet"].Value = ReportRecords; }
public ServerReportDataSourceCollection(ReportDataSourceCollection reportDataSourceCollection) { ReportDataSourceCollection = reportDataSourceCollection; }
async void Button_Click(object sender, RoutedEventArgs e) { FileSavePicker fileSavePicker = new FileSavePicker(); WriterFormat format = WriterFormat.PDF; if (pdf.IsChecked == true) { fileSavePicker.FileTypeChoices.Add("PDF", new List <string> { ".pdf" }); fileSavePicker.DefaultFileExtension = ".pdf"; format = WriterFormat.PDF; } else if (excel.IsChecked == true) { fileSavePicker.FileTypeChoices.Add("Excel", new List <string> { ".xls" }); fileSavePicker.DefaultFileExtension = ".xls"; format = WriterFormat.Excel; } else if (word.IsChecked == true) { fileSavePicker.FileTypeChoices.Add("Word", new List <string> { ".doc" }); fileSavePicker.DefaultFileExtension = ".doc"; format = WriterFormat.Word; } else if (html.IsChecked == true) { fileSavePicker.FileTypeChoices.Add("Html", new List <string> { ".html" }); fileSavePicker.DefaultFileExtension = ".html"; format = WriterFormat.HTML; } fileSavePicker.SuggestedFileName = "ExportReport"; var savedItem = await fileSavePicker.PickSaveFileAsync(); if (savedItem != null) { MemoryStream exportFileStream = new MemoryStream(); Assembly assembly = typeof(Syncfusion.SampleBrowser.UWP.ReportViewer.MainPage).GetTypeInfo().Assembly; Stream reportStream = assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.ReportViewer.ReportViewer.ReportElement.Table Summaries.rdlc"); ReportDataSourceCollection datas = new ReportDataSourceCollection(); datas.Add(new ReportDataSource { Name = "Sales", Value = Syncfusion.SampleBrowser.UWP.ReportViewer.TableSummaries.SalesDetails.GetData() }); ReportWriter writer = new ReportWriter(reportStream, datas); writer.ExportMode = Syncfusion.ReportWriter.ExportMode.Local; writer.ExportCompleted += Writer_ExportCompleted; await writer.SaveASync(exportFileStream, format); try { using (IRandomAccessStream stream = await savedItem.OpenAsync(FileAccessMode.ReadWrite)) { // Write compressed data from memory to file using (Stream outstream = stream.AsStreamForWrite()) { byte[] buffer = exportFileStream.ToArray(); outstream.Write(buffer, 0, buffer.Length); outstream.Flush(); } } exportFileStream.Dispose(); } catch { } } }
public IActionResult Report(NewExpenseReport newExpenseReport) { var list = new List <ActivityExpense>(); list = _activityRepo.Expenses.Include(a => a.Expense).Include(a => a.Activity).ThenInclude(b => b.Package) .Include(a => a.Activity).ThenInclude(b => b.Service) .Include(a => a.Activity).ThenInclude(b => b.BillableRetainer) .Include(a => a.Activity).ThenInclude(b => b.Client) .Where(a => a.Activity.RealizationDate >= newExpenseReport.InitialDate && a.RealizationDate <= newExpenseReport.FinalDate && (newExpenseReport.UserId == null || a.Activity.CreatorId == newExpenseReport.UserId) && (newExpenseReport.ActivityType == null || a.Activity.ActivityType == newExpenseReport.ActivityType) ).ToList(); var expenses = list.Select(g => new { expenseName = g.Expense.Name, expenseDate = g.RealizationDate, expenseQuantity = g.Quantity, expensePrice = g.UnitAmount, expenseSubtotal = g.TotalAmount, expenseClient = g.Activity?.Client?.Name ?? "", expenseAssociatedTo = g.Activity.ActivityType == ActivityTypeEnum.Hourly ? "Horario" : g.Activity.ActivityType == ActivityTypeEnum.Item ? $"Ítem - {g.Activity?.Service?.Name}" : g.Activity.ActivityType == ActivityTypeEnum.Package ? $"Paquete - {g.Activity?.Package?.Name}" : g.Activity.ActivityType == ActivityTypeEnum.Retainer ? $"Retainer - {g.Activity?.BillableRetainer?.Name}" : "" }).ToList(); string basePath = _hostingEnvironment.ContentRootPath; string fullPath = basePath + @"/Reports/Expenses.rdlc"; FileStream inputStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read); ReportDataSourceCollection dataSources = new ReportDataSourceCollection(); dataSources.Add(new ReportDataSource { Name = "ExpensesDataSet", Value = expenses }); ReportWriter writer = new ReportWriter(inputStream, dataSources); //writer.DataSources = dataSources; writer.ReportProcessingMode = ProcessingMode.Local; //Setting up the parameters List <ReportParameter> parameters = new List <ReportParameter>(); //StartDate ReportParameter startDateParam = new ReportParameter(); startDateParam.Name = "StartDate"; startDateParam.Values = new List <string>() { newExpenseReport.InitialDate.ToString("dd/MM/yyyy") }; //EndDate ReportParameter endDateParam = new ReportParameter(); endDateParam.Name = "EndDate"; endDateParam.Values = new List <string>() { newExpenseReport.FinalDate.ToString("dd/MM/yyyy") }; //AttorneyName ReportParameter attorneyParam = new ReportParameter(); attorneyParam.Name = "AttorneyName"; attorneyParam.Values = new List <string>() { newExpenseReport.UserId == null? "Todos" : _attorneyRepo.Attorneys.Where(a => a.UserId == ((int)newExpenseReport.UserId)).Select(a => a.Name).First() }; //ActivityType ReportParameter activityTypeParam = new ReportParameter(); activityTypeParam.Name = "ActivityType"; activityTypeParam.Values = new List <string>() { newExpenseReport.ActivityType == null? "0" : ((int)newExpenseReport.ActivityType).ToString() }; //TotalExpense ReportParameter totalExpenseParam = new ReportParameter(); totalExpenseParam.Name = "TotalExpense"; totalExpenseParam.Values = new List <string>() { expenses.Sum(e => e.expenseSubtotal).ToString() }; parameters.Add(startDateParam); parameters.Add(endDateParam); parameters.Add(attorneyParam); parameters.Add(activityTypeParam); parameters.Add(totalExpenseParam); writer.SetParameters(parameters); //Generating the processed report MemoryStream memoryStream = new MemoryStream(); writer.Save(memoryStream, WriterFormat.PDF); memoryStream.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(memoryStream, "application/pdf"); fileStreamResult.FileDownloadName = $"ReporteDeGastosDel{newExpenseReport.InitialDate.ToString("ddMMyyyy")}Al{newExpenseReport.FinalDate.ToString("ddMMyyyy")}.pdf"; return(fileStreamResult); }
public void FillDataSources(ReportDataSourceCollection dataSources) { dataSources.Add(new ReportDataSource("DataSet1")); dataSources["DataSet1"].Value = GroupHeaders; }
public IActionResult Report(NewActivityReport newActivityReport) { Func <Activity, decimal, decimal> GetFeeByActivity = (activity, ratePerHour) => { switch (activity.ActivityType) { case ActivityTypeEnum.Hourly: return(activity.Subtotal); case ActivityTypeEnum.Item: return(activity.Subtotal); case ActivityTypeEnum.NoBillable: return((decimal)(0.00)); case ActivityTypeEnum.Package: if (activity.Package.IsFinished) { return(ratePerHour * activity.HoursWorked); } else { return((decimal)(0.00)); } case ActivityTypeEnum.Retainer: //Under working the hours if (activity.BillableQuantity == 0) { return(ratePerHour * activity.HoursWorked); } //Is normal billed as excedent of the agreed hours else if (activity.BillableQuantity == activity.HoursWorked) { return(activity.Subtotal); } else { return(activity.Subtotal + ((activity.HoursWorked - activity.BillableQuantity) * activity.BillableRate)); } default: return((decimal)(0.00)); } }; var list = new List <Activity>(); list = _activityRepo.Activities.Include(a => a.Service).ThenInclude(s => s.Category) .Include(a => a.Client) .Include(a => a.Package) .Include(a => a.BillableRetainer) .Where(a => a.RealizationDate >= newActivityReport.InitialDate && a.RealizationDate <= newActivityReport.FinalDate && (newActivityReport.UserId == null || a.CreatorId == newActivityReport.UserId) && (newActivityReport.ActivityType == null || a.ActivityType == newActivityReport.ActivityType) ).ToList(); //To get all the packages amount involved var involvedPackagesRates = list.Where(a => a.ActivityType == ActivityTypeEnum.Package && a.Package.IsFinished).Select(a => a.Package) .Distinct() .Select(package => new { package.Id, rate = (package.Amount / (_activityRepo.Activities.Where(act => act.PackageId == package.Id).Sum(act => act.HoursWorked))) }) .ToList(); var activities = list.Select(a => new { activityClient = a.Client.Name, activityService = a.Service.Name, activityCategory = a.Service.Category.Name, activityHoursWorked = Math.Round(a.HoursWorked, 2), activityAssociatedTo = a.ActivityType == ActivityTypeEnum.Hourly ? "Horario" : a.ActivityType == ActivityTypeEnum.Item ? $"Ítem" : a.ActivityType == ActivityTypeEnum.Package ? $"Paquete - {a.Package?.Name}" : a.ActivityType == ActivityTypeEnum.Retainer ? $"Retainer - {a?.BillableRetainer?.Name}" : a.ActivityType == ActivityTypeEnum.NoBillable ?"No cobrable" :"", activityDate = a.RealizationDate, activityTotalFee = GetFeeByActivity(a, a.ActivityType == ActivityTypeEnum.Package ? (involvedPackagesRates.Where(ip => ip.Id == a.PackageId).FirstOrDefault()?.rate ?? (decimal)0.00) : a.ActivityType == ActivityTypeEnum.Retainer ? a.BillableRetainer.AgreedFee / a.BillableRetainer.AgreedHours : (decimal)0.00) }).ToList(); string basePath = _hostingEnvironment.ContentRootPath; string fullPath = basePath + @"/Reports/Activities.rdlc"; FileStream inputStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read); ReportDataSourceCollection dataSources = new ReportDataSourceCollection(); dataSources.Add(new ReportDataSource { Name = "ActivitiesDataSet", Value = activities }); Syncfusion.ReportWriter.ReportWriter writer = new Syncfusion.ReportWriter.ReportWriter(inputStream, dataSources); //writer.DataSources = dataSources; writer.ReportProcessingMode = ProcessingMode.Local; //Setting up the parameters List <ReportParameter> parameters = new List <ReportParameter>(); //StartDate ReportParameter startDateParam = new ReportParameter(); startDateParam.Name = "StartDate"; startDateParam.Values = new List <string>() { newActivityReport.InitialDate.ToString("dd/MM/yyyy") }; //EndDate ReportParameter endDateParam = new ReportParameter(); endDateParam.Name = "EndDate"; endDateParam.Values = new List <string>() { newActivityReport.FinalDate.ToString("dd/MM/yyyy") }; //AttorneyName ReportParameter attorneyParam = new ReportParameter(); attorneyParam.Name = "AttorneyName"; attorneyParam.Values = new List <string>() { newActivityReport.UserId == null? "Todos" : _attorneyRepo.Attorneys.Where(a => a.UserId == ((int)newActivityReport.UserId)).Select(a => a.Name).First() }; //ActivityType ReportParameter activityTypeParam = new ReportParameter(); activityTypeParam.Name = "ActivityType"; activityTypeParam.Values = new List <string>() { newActivityReport.ActivityType == null ? "0" : ((int)newActivityReport.ActivityType).ToString() }; //TotalHours ReportParameter totalHoursParam = new ReportParameter(); totalHoursParam.Name = "TotalHours"; totalHoursParam.Values = new List <string>() { activities.Sum(a => a.activityHoursWorked).ToString() }; //Total Amount ReportParameter totalAmountParam = new ReportParameter(); totalAmountParam.Name = "TotalAmount"; totalAmountParam.Values = new List <string>() { activities.Sum(a => a.activityTotalFee).ToString() }; parameters.Add(startDateParam); parameters.Add(endDateParam); parameters.Add(attorneyParam); parameters.Add(activityTypeParam); parameters.Add(totalHoursParam); parameters.Add(totalAmountParam); writer.SetParameters(parameters); MemoryStream memoryStream = new MemoryStream(); writer.Save(memoryStream, WriterFormat.PDF); memoryStream.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(memoryStream, "application/pdf"); fileStreamResult.FileDownloadName = $"ReporteDeActividadesDel{newActivityReport.InitialDate.ToString("ddMMyyyy")}Al{newActivityReport.FinalDate.ToString("ddMMyyyy")}.pdf"; return(fileStreamResult); }
public IActionResult RenderBill(int id) { var bill = _billRepo.BillHeaders.Where(b => b.Id == id).Include(b => b.BillDetails).FirstOrDefault(); var details = bill.BillDetails.Select(d => new { BillDetailType = Convert.ToInt32(d.BillDetailType), d.FixedAmount, d.UnitRate, d.Quantity, d.Subtotal, d.Description, d.TaxesAmount }).ToList(); string basePath = _hostingEnvironment.ContentRootPath; string fullPath = basePath + @"/Reports/Bill.rdlc"; FileStream inputStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read); ReportDataSourceCollection dataSources = new ReportDataSourceCollection(); dataSources.Add(new ReportDataSource { Name = "BillDataSet", Value = details }); Syncfusion.ReportWriter.ReportWriter writer = new Syncfusion.ReportWriter.ReportWriter(inputStream, dataSources); //writer.DataSources = dataSources; //Setting up the parameters List <ReportParameter> parameters = new List <ReportParameter>(); //IsEnglish bool isBillingInEnglish = _clientRepo.Clients.Where(c => c.Id == bill.ClientId).Select(c => c.BillingInEnglish).First(); ReportParameter isEnglishParam = new ReportParameter(); isEnglishParam.Name = "IsEnglish"; isEnglishParam.Values = new List <string>() { isBillingInEnglish ? "1" : "0" }; //IsBilled ReportParameter isBilledParam = new ReportParameter(); isBilledParam.Name = "IsBilled"; isBilledParam.Values = new List <string>() { "1" }; //ClientName ReportParameter clientNameParam = new ReportParameter(); clientNameParam.Name = "ClientName"; clientNameParam.Values = new List <string>() { bill.BillName }; //BillingPeriod string culture = isBillingInEnglish ? "en" : "es"; string billingPeriod = $"{CultureInfo.GetCultureInfoByIetfLanguageTag(culture).DateTimeFormat.GetMonthName(DateTime.UtcNow.AddHours(-6).Month)} - {bill.BillYear}"; ReportParameter billingPeriodParam = new ReportParameter(); billingPeriodParam.Name = "BillingPeriod"; billingPeriodParam.Values = new List <string>() { billingPeriod }; //Subtotal ReportParameter subTotalExpenseParam = new ReportParameter(); subTotalExpenseParam.Name = "Subtotal"; subTotalExpenseParam.Values = new List <string>() { bill.BillSubtotal.ToString() }; //Discount ReportParameter discountParam = new ReportParameter(); discountParam.Name = "Discount"; discountParam.Values = new List <string>() { bill.BillDiscount.ToString() }; //Taxes ReportParameter taxesParam = new ReportParameter(); taxesParam.Name = "Taxes"; taxesParam.Values = new List <string>() { bill.Taxes.ToString() }; //TotalExpense ReportParameter totalParam = new ReportParameter(); totalParam.Name = "Total"; totalParam.Values = new List <string>() { bill.Total.ToString() }; //TotalExpense ReportParameter billDateParam = new ReportParameter(); billDateParam.Name = "BillDate"; billDateParam.Values = new List <string>() { bill.BillDate.ToString() }; parameters.Add(isEnglishParam); parameters.Add(isBilledParam); parameters.Add(clientNameParam); parameters.Add(billingPeriodParam); parameters.Add(subTotalExpenseParam); parameters.Add(discountParam); parameters.Add(taxesParam); parameters.Add(totalParam); parameters.Add(billDateParam); writer.SetParameters(parameters); writer.ReportProcessingMode = ProcessingMode.Local; MemoryStream memoryStream = new MemoryStream(); writer.Save(memoryStream, WriterFormat.PDF); memoryStream.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(memoryStream, "application/pdf"); fileStreamResult.FileDownloadName = $"FacturaCliente{bill.BillName}deMes{bill.BillMonth}YAño{bill.BillYear}.pdf"; return(fileStreamResult); }