public void EndToEndTest() { var inputFiles = new[] { "data/header.xml", "data/report.xbrl" }; ReportPackage.Create("keys/public.xml", "output/reportpackage.zip", inputFiles.First(), inputFiles.Last()); var outputFiles = ReportPackage.Unpack("keys/private.xml", "output/reportpackage.zip", "output"); var expectedOutputFiles = inputFiles.Select(f => f.Replace("data/", "output/")).ToArray(); Assert.Equal(expectedOutputFiles, outputFiles); }
private void LoadReport(ReportPackage report, XElement reportDef, Dictionary <String, String> parameters) { var paramInfo = ReportViewer1.LocalReport.GetParameters(); ReportViewer1.Visible = !((paramInfo.Count > 1) && parameters == null); RenderReportData(report); if ((Page.IsPostBack && paramInfo.Count > 0) || (parameters != null && parameters.Count == 0)) //Don't load report data on page load unless there are 0 parameters { LoadReportData(report, parameters, reportDef, _sb); } ReportViewer1.LocalReport.Refresh(); }
public static async Task <HttpResponseMessage> PostAsync( this ReportPackage package) { return(await LiteClient.PostAsync(new Uri(Config.Global.ReportUrl + "/report?".GlueGetList(new Dictionary <string, object>() { { "deviceid", (object)Critical.GetDeviceId() }, { "uuid", (object)Critical.GetUuid() } }, false) + package.UrlParameters), (Stream) new MemoryStream(package.GetRawStream().ToArray()))); }
private static bool TryPostOrIgnore(ReportPackage package) { try { if (package.Length <= 0L) { throw new Exception("Empty package"); } HttpResponseMessage result = package.PostAsync().Result; return(result != null && (result.IsSuccessStatusCode || !LiteMetricaCore.IsValidRequestByStatusCode(result.StatusCode))); } catch (Exception) { return(true); } }
/// <summary> /// Render any report data above the parameters. eg. Report Name, Report Description, etc... /// </summary> /// <param name="report"></param> /// <param name="reportDef"></param> private void RenderReportData(ReportPackage report) { // Empty controls so they aren't added more than once PlaceHolderReportData.Controls.Clear(); var panel = new Panel(); var reportName = new Label(); reportName.ID = "reportName"; reportName.Text = report.Report.DisplayName; panel.Controls.Add(reportName); var reportDescription = new Label(); reportDescription.CssClass = "reportDescription"; PlaceHolderReportData.Controls.Add(panel); PlaceHolderParameters.Controls.Add(_parameterContainer); }
/// <summary> /// Filters the specified package. /// </summary> /// <param name="package">The package.</param> /// <returns> /// True, if the filter criterias matches, otherwise False. /// </returns> public override bool Filter(ReportPackage package) { DoInitializationCheck(); bool result = false; string value = ExtractObjectData.Create(this.MemberName).GetValue(package).ToString(); if (value != null) { switch (MatchMode) { case LikeMatchModeFilterEnum.Exact: result = value.ToLower().Equals(Value.ToLower()); break; case LikeMatchModeFilterEnum.Start: result = value.ToLower().StartsWith(Value.ToLower()); break; case LikeMatchModeFilterEnum.End: result = value.ToLower().EndsWith(Value.ToLower()); break; case LikeMatchModeFilterEnum.Anywhere: result = value.ToLower().Contains(Value.ToLower()); break; } } if (Negation) { result = !result; } return(result); }
/// <summary> /// Filters the specified package. /// </summary> /// <param name="package">The package.</param> /// <returns> /// True, if the filter criterias matches, otherwise False. /// </returns> public override bool Filter(ReportPackage package) { DoInitializationCheck(); bool result = false; if (this.FilterLogic == GroupFilterLoginEnum.And) { result = true; foreach (IErrorReportFilter filter in mFilters) { result = result && filter.Filter(package); if (!result) { break; } } } else { foreach (IErrorReportFilter filter in mFilters) { result = filter.Filter(package); if (result) { break; } } } if (Negation) { result = !result; } return(result); }
private void GenerateIlithaPDF(ReportPackage myReportPackage) { if (myReportPackage.TimeSheets.Count > 0) { #region Table Header Collection List <string> ColList = new List <string>(); ColList.Add("MOC"); ColList.Add("SAP#"); ColList.Add("Cost Code"); ColList.Add("Project"); for (DateTime dt = myReportPackage.DateFrom; dt < myReportPackage.DateTo.AddDays(1); dt = dt.AddDays(1)) { ColList.Add(dt.ToString("ddd\ndd\nMMM")); } ColList.Add("Mth\nTotal"); ColList.Add("Total"); ColList.Add("Prj\nHrs"); #endregion #region Detail Collection List <ReportRow> rows = new List <ReportRow>(); int colcount = 0; int rowcount = 1; foreach (var r in myReportPackage.TimeSheets) { colcount = 0; List <ReportCell> cells = new List <ReportCell>(); cells.Add(new ReportCell() { colnum = colcount, rownum = rowcount, colspan = 1, type = CellType.String, value = r.Project_Number.ToString() }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.String, value = r.SAP }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.String, value = r.WBS }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.String, value = r.Project_Name }); foreach (var d in r.Days) { cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.Number, value = (!d.HoursWorked.HasValue) ? string.Empty : d.HoursWorked.Value.ToString("#0.00") }); } cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.Number, value = r.MonthTotal.ToString("#0.00") }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.Number, value = (r.SAP != "Leave")? r.Total.ToString("#0.00"): string.Empty }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.Number, value = (r.ProjectHours == 0 || r.SAP == "Leave") ? string.Empty : r.ProjectHours.ToString("#0.00") }); rows.Add(new ReportRow() { row = cells }); rowcount++; } #endregion #region Footer Collection List <string> FooterList = new List <string>(); FooterList.Add(""); FooterList.Add(""); FooterList.Add(""); FooterList.Add(""); foreach (var d in myReportPackage.DayTotals) { FooterList.Add((String.IsNullOrEmpty(d.HoursWorked.ToString())) ? string.Empty : (d.HoursWorked.Value == 0) ? string.Empty : d.HoursWorked.Value.ToString("#0.00")); } FooterList.Add(myReportPackage.GrandTotal.ToString()); FooterList.Add(""); FooterList.Add(""); #endregion #region Saco Collection List <string> SacoList = new List <string>(); SacoList.Add(""); SacoList.Add(""); SacoList.Add(""); SacoList.Add(""); foreach (var d in myReportPackage.DaySacoTotals) { SacoList.Add((String.IsNullOrEmpty(d.HoursWorked.ToString())) ? string.Empty : (d.HoursWorked.Value == 0) ? string.Empty : d.HoursWorked.Value.ToString("#0.00")); } decimal sacototal = myReportPackage.DaySacoTotals.Sum(s => (decimal)s.HoursWorked); SacoList.Add(sacototal.ToString("#0.00")); SacoList.Add(""); SacoList.Add(""); #endregion #region Set the Column Widths float[] HeaderWidths = new float[colcount + 1]; HeaderWidths[0] = 26f; HeaderWidths[1] = 30f; HeaderWidths[2] = 30f; HeaderWidths[3] = 60f; for (int col = 4; col < colcount - 2; col++) { HeaderWidths[col] = 19f; } HeaderWidths[colcount - 2] = 24f; HeaderWidths[colcount - 1] = 24f; HeaderWidths[colcount] = 24f; //the last column #endregion //Create New PDF Timesheet Report IPDFReport myReport = new IlithaTimeSheetReport(true); //Assgin Column, Row and Footer collections to MyReport Object myReport.ColList = ColList; myReport.FooterList = FooterList; myReport.ReportRows = rows; myReport.SacoList = SacoList; //Set Report Properties myReport.Start = myReportPackage.DateFrom; myReport.End = myReportPackage.DateTo; myReport.User = myReportPackage.User; myReport.filename = "TSD_TimeSheets_" + myReportPackage.User_CAI + "_" + myReportPackage.DateFrom.ToString("dd-MMM-yyyy") + "_" + myReportPackage.DateTo.ToString("dd-MMM-yyyy"); myReport.PageHeight = 595; myReport.LogoImagePath = "~/images/img_hallmark.gif"; myReport.ReportDescription = "TimeSheet"; //Assign Column Widths to myReport myReport.Headerwidths = HeaderWidths; //Write myReport myReport.GenerateXMLReport(); //Open Report and browswer myReport.OpenPDF(); } }
/// <summary> /// Filters the specified package. /// </summary> /// <param name="package">The package.</param> /// <returns> /// True, if the filter criterias matches, otherwise False. /// </returns> public abstract bool Filter(ReportPackage package);
/// <summary> /// Processes the report package. /// </summary> /// <param name="package">The package.</param> public abstract void ProcessReportPackage(ReportPackage package);
/// <summary> /// Processes the report package. /// </summary> /// <param name="package">The package.</param> public override void ProcessReportPackage(ReportPackage package) { DoInitializationCheck(); LOGGER.Debug(string.Format("{0}, an error report package arrived. SinkId: '{0}'", this.GetType().Name, this.SinkId)); PatternLayout layout = new PatternLayout(this.ConversionPattern); StringBuilder sb = new StringBuilder(); sb.Append("Created (UTC): "); sb.AppendLine(package.ReportCreated.ToString()); sb.Append("ApplicationId: "); sb.AppendLine(package.ApplicationId); sb.AppendLine(); sb.AppendLine(layout.Format(package.LoggingEvent)); using (SmtpClient client = new SmtpClient()) { if (!string.IsNullOrEmpty(this.SmtpHost)) { client.Host = this.SmtpHost; } client.Port = this.Port; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = this.EnableSsl; if (this.Authentication == SmtpAppender.SmtpAuthentication.Basic) { client.Credentials = new NetworkCredential(this.Username, this.Password); } else if (this.Authentication == SmtpAppender.SmtpAuthentication.Ntlm) { client.Credentials = CredentialCache.DefaultNetworkCredentials; } using (MailMessage message = new MailMessage()) { message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; message.IsBodyHtml = false; message.Body = sb.ToString(); message.BodyEncoding = this.BodyEncoding; message.From = new MailAddress(this.From); message.To.Add(this.To); if (!string.IsNullOrEmpty(this.Cc)) { message.CC.Add(this.Cc); } if (!string.IsNullOrEmpty(this.Bcc)) { message.Bcc.Add(this.Bcc); } if (!string.IsNullOrEmpty(this.ReplyTo)) { message.ReplyToList.Add(new MailAddress(this.ReplyTo)); } message.Subject = this.Subject; message.SubjectEncoding = this.SubjectEncoding; message.Priority = this.Priority; client.Send(message); } } }
/// <summary> /// Sends the error report. /// </summary> /// <param name="package">The package.</param> public void SendErrorReport(ReportPackage package) { if (package != null) { if (LOGGER.IsDebugEnabled) { LOGGER.Debug("ERROR_REPORT_SERVICE, new error report package arrived."); } IErrorReportFilter filter = null; List <IErrorReportPackageSink> sinks = new List <IErrorReportPackageSink>(); lock (mReportPackageSinks) { filter = mErrorReportFilter; sinks.AddRange(mReportPackageSinks); } bool allowed = true; if (filter != null) { try { allowed = filter.Filter(package); } catch (Exception ex) { allowed = false; if (LOGGER.IsErrorEnabled) { LOGGER.Error(string.Format("ERROR_REPORT_SERVICE, filter threw an exception. Filter type: '{0}'", filter.GetType().AssemblyQualifiedName), ex); } } } if (allowed && sinks.Count > 0) { foreach (IErrorReportPackageSink sink in sinks) { allowed = true; if (sink.Filter != null) { try { allowed = sink.Filter.Filter(package); } catch (Exception ex) { allowed = false; if (LOGGER.IsErrorEnabled) { LOGGER.Error(string.Format("ERROR_REPORT_SERVICE, sink filter threw an exception. Sink type: '{0}', filter type: '{1}'", sink.GetType().AssemblyQualifiedName, filter.GetType().AssemblyQualifiedName), ex); } } } if (allowed) { try { sink.ProcessReportPackage(package); } catch (Exception ex) { if (LOGGER.IsErrorEnabled) { LOGGER.Error(string.Format("ERROR_REPORT_SERVICE, a sink threw an exception. SinkId: '{0}', sink type: '{1}'", sink.SinkId, sink.GetType().AssemblyQualifiedName), ex); } } } } sinks.Clear(); } } }
public void CreatePackageTest() => ReportPackage.Create("keys/fin-fsa-pub.xml", "output/reportpackage.zip", "data/header.xml", "data/report.xbrl");
private List <ReportParameterPackage> GetReportParameterPackages(ReportPackage report, XElement reportDef) { var dataSets = report.ReportDataSets; var xmlns = reportDef.GetDefaultNamespace().ToString(); var reportParams = reportDef.Descendants(XName.Get("ReportParameter", xmlns)); var localReportParams = ReportViewer1.LocalReport.GetParameters(); var reportParameterPkgs = new List <ReportParameterPackage>(); foreach (var reportParam in reportParams) { var reportParamName = reportParam.SafeAttributeValue("Name", ""); // Skip internal hidden parameter "EclipseURL" (Used to link documents) if (reportParamName == Constants.REPORTS_ECLIPSE_URL) { continue; } //TODO: Use the report parameter prompt instead of the name var multiValue = reportParam.Element(XName.Get("MultiValue", xmlns)); var hasMultiValues = false; if (multiValue != null) { Boolean.TryParse(multiValue.Value, out hasMultiValues); } var allowBlank = reportParam.Element(XName.Get("AllowBlank", xmlns)); var hasAllowBlank = false; if (allowBlank != null) { Boolean.TryParse(allowBlank.Value, out hasAllowBlank); } var validValues = reportParam.Descendants(XName.Get("ValidValues", xmlns)); var paramValidValues = new List <ParameterValidValue>(); var hasValidValues = false; String lrpLabel = String.Empty; String lrpValue = String.Empty; var rpPkg = new ReportParameterPackage { Name = reportParamName }; foreach (var validValue in validValues) { hasValidValues = true; var paramValue = validValue.Descendants(XName.Get("ParameterValue", xmlns)); foreach (var param in paramValue) { var vvLabel = param.Element(XName.Get("Label", xmlns)); var vvValue = param.Element(XName.Get("Value", xmlns)); var lblVal = vvLabel == null ? null : vvLabel.Value; GetReportParameters(localReportParams, reportParamName, lblVal, out lrpLabel, out lrpValue); paramValidValues.Add(new ParameterValidValue { Name = reportParamName, Label = lrpLabel, Value = lrpValue }); } } rpPkg.ValidValues = paramValidValues.ToArray(); var defaultValues = reportParam.Descendants(XName.Get("DefaultValue", xmlns)); var paramDefaultValues = new List <String>(); foreach (var defaultValue in defaultValues) { var defParamValues = defaultValue.Descendants(XName.Get("Values", xmlns)); foreach (var defParamValue in defParamValues) { var dvValue = defParamValue.Element(XName.Get("Value", xmlns)); var val = dvValue == null ? null : dvValue.Value; GetReportParameters(localReportParams, reportParamName, val, out lrpLabel, out lrpValue); paramDefaultValues.Add(lrpValue); } } rpPkg.DefaultValues = paramDefaultValues.ToArray(); if (hasValidValues) { var dataSetRefs = reportParam.Descendants(XName.Get("DataSetReference", xmlns)); foreach (var dataSetRef in dataSetRefs) { var fieldValue = dataSetRef.Element(XName.Get("ValueField", xmlns)).Value; var fieldLabel = dataSetRef.Element(XName.Get("LabelField", xmlns)).Value; var dataSetName = dataSetRef.Element(XName.Get("DataSetName", xmlns)).Value; // Obtain the dataset from the reports data sets, matched on name int idx; var dataSetsLen = dataSets.SafeLength(); for (idx = 0; idx < dataSetsLen; idx++) { var queryParams = new Dictionary <String, String>(); if (dataSets[idx].Name == dataSetName) { var sqlQuery = DLUtility.Deserialize <SQLQuery>(dataSets[idx].QueryDefinition); if (sqlQuery.Params.Count == 0) { var args = new GetReportDataArgs { QueryDefinition = dataSets[idx].QueryDefinition }; _sb.SendTimeout = TimeSpan.FromMinutes(30); var dlSvc = _sb.DataLinkV2(); var rdSR = dlSvc.GetReportData(args); ExceptionsML.Check(rdSR.Error); var colLen = rdSR.Result.Columns[fieldLabel].SafeLength(); for (int colIdx = 0; colIdx < colLen; colIdx++) { paramValidValues.Add(new ParameterValidValue { Name = reportParamName, Label = rdSR.Result.Columns[fieldLabel][colIdx], Value = rdSR.Result.Columns[fieldValue][colIdx] ?? String.Empty }); } rpPkg.ValidValues = paramValidValues.ToArray(); } else { rpPkg.Name = reportParamName; rpPkg.ValidValues = new ParameterValidValue[0]; rpPkg.IsTypeAhead = true; rpPkg.DataSetId = dataSets[idx].Id; } } } } rpPkg.IsMultiValued = hasMultiValues; rpPkg.AllowBlank = hasAllowBlank; } else { var type = reportParam.Descendants(XName.Get("DataType", xmlns)); var values = reportParam.Descendants(XName.Get("Value", xmlns)); var vals = GetStandardReportParameters(localReportParams, reportParamName); rpPkg.Values = vals; rpPkg.Type = reportParam.Element(XName.Get("DataType", xmlns)).Value; } rpPkg.ValidValues.Sort <ParameterValidValue>((a, b) => a.Label.CompareTo(b.Label)); reportParameterPkgs.Add(rpPkg); } return(reportParameterPkgs); }
private void LoadReportData(ReportPackage report, Dictionary <String, String> parameters, XElement reportDef, ServiceBuilder sb) { try { var reportParams = ReportViewer1.LocalReport.GetParameters(); sb.SendTimeout = TimeSpan.FromMinutes(30); var dlSvc = sb.DataLinkV2(); var newParams = new Dictionary <String, String>(); var xmlns = reportDef.GetDefaultNamespace().ToString(); var rd = reportDef.GetNamespaceOfPrefix("rd").ToString(); var dataSets = reportDef.Descendants(XName.Get("DataSet", xmlns)); if (dataSets == null) { throw new Exception("DataSet not found in report"); //We control writing this, so we should never see this occur. } foreach (var dataSet in dataSets) { var dsName = dataSet.SafeAttributeValue <String>("Name", Constants.ECLIPSE_DATASOURCE); var rds = report.ReportDataSets.FirstOrDefault(r => r.Name == dsName); var dlSR = dlSvc.GetReportData(new GetReportDataArgs { Parameters = parameters, QueryDefinition = rds.QueryDefinition }); ExceptionsML.Check(dlSR.Error); newParams.AddRange(dlSR.Result.Parameters); var dt = new DataTable(dsName); var fields = dataSet.Descendants(XName.Get("Field", xmlns)); if (fields != null) { foreach (var field in fields) { var fieldName = field.Element(XName.Get("DataField", xmlns)).Value; var fieldType = field.Element(XName.Get("TypeName", rd)).Value; dt.Columns.Add(new DataColumn(fieldName, Converter.GetType(fieldType))); } if (dlSR.Result != null) { dlSR.Result.FillDataTable(dt); } } var rptData = new ReportDataSource(dsName, dt); ReportViewer1.LocalReport.DataSources.Add(rptData); } // Set the parameters for the report var length = reportParams == null ? 0 : reportParams.Count; var setParams = new ReportParameter[length]; var eclipseURL = String.Format("{0}://{1}:{2}{3}", Request.IsSecureConnection ? "https" : "http", Request.ServerVariables["SERVER_NAME"], Request.ServerVariables["SERVER_PORT"], Request.ApplicationPath); var idx = 0; foreach (var param in reportParams) { // Add a hardcoded EclipseURL parameter so the report can use it to navigate documents var name = param.Name; var newParamsName = "@" + name; if (name == Constants.REPORTS_ECLIPSE_URL) { setParams[idx] = new ReportParameter(name, eclipseURL); } else if (newParams.ContainsKey(newParamsName)) // newParams names begin with "@", where as name does not { setParams[idx] = new ReportParameter(name, newParams[newParamsName]); } else { setParams[idx] = new ReportParameter(name); } idx++; } setParams = setParams.RemoveNulls(); // Prevents setting null parameters (ones' that have been deleted) ReportViewer1.LocalReport.SetParameters(setParams); } catch (LocalProcessingException lex) { ErrorHandler(lex.InnerMost()); } catch (Exception ex) { ErrorHandler(ex); } }
private FileContentResult SendToExcel2(FormCollection coll) { DateTime firstDay = DateTime.Parse(coll["txtDateFrom"]); DateTime lastDay = DateTime.Parse(coll["txtDateTo"]); string User_CAI = coll["ddlUsers"]; ReportPackage rp = timedb.GetReportByUser(User_CAI, firstDay, lastDay); // FileStream fs = new FileStream(Server.MapPath("~/Content/Template.xls"), FileMode.Open, FileAccess.Read); // Getting the complete workbook... HSSFWorkbook wb = new HSSFWorkbook(); // Getting the worksheet by its name... HSSFSheet sheet = wb.CreateSheet(User_CAI + "_" + coll["txtDateFrom"] + "_" + coll["txtDateTo"]); sheet.SetColumnWidth(2, 20 * 256); sheet.SetColumnWidth(3, 20 * 256); sheet.SetColumnWidth(4, 30 * 256); HSSFFont font1 = wb.CreateFont(); font1.Boldweight = HSSFFont.BOLDWEIGHT_BOLD; font1.Color = HSSFColor.BLACK.index; font1.FontHeightInPoints = 10; HSSFFont font2 = wb.CreateFont(); font2.Color = HSSFColor.BLACK.index; font2.FontHeightInPoints = 8; HSSFFont sacofont = wb.CreateFont(); sacofont.Color = HSSFColor.WHITE.index; sacofont.FontHeightInPoints = 8; HSSFFont font2Bold = wb.CreateFont(); font2Bold = font2; font2Bold.Boldweight = HSSFFont.BOLDWEIGHT_BOLD; HSSFFont font_Red_Bold = wb.CreateFont(); font_Red_Bold.Color = HSSFColor.RED.index; font_Red_Bold.Boldweight = HSSFFont.BOLDWEIGHT_BOLD; font_Red_Bold.FontHeightInPoints = 10; HSSFCellStyle globalstyle = wb.CreateCellStyle(); globalstyle.BorderBottom = HSSFCellStyle.BORDER_THIN; globalstyle.BottomBorderColor = HSSFColor.BLACK.index; globalstyle.BorderLeft = HSSFCellStyle.BORDER_THIN; globalstyle.LeftBorderColor = HSSFColor.BLACK.index; globalstyle.BorderRight = HSSFCellStyle.BORDER_THIN; globalstyle.RightBorderColor = HSSFColor.BLACK.index; globalstyle.BorderTop = HSSFCellStyle.BORDER_THIN; globalstyle.TopBorderColor = HSSFColor.BLACK.index; HSSFCellStyle headerstyle = wb.CreateCellStyle(); headerstyle.CloneStyleFrom(globalstyle); headerstyle.Alignment = HSSFCellStyle.ALIGN_CENTER; headerstyle.FillForegroundColor = HSSFColor.GREY_25_PERCENT.index; headerstyle.FillPattern = HSSFCellStyle.SOLID_FOREGROUND; headerstyle.SetFont(font1); HSSFCellStyle dayStyle = wb.CreateCellStyle(); dayStyle.CloneStyleFrom(headerstyle); dayStyle.SetFont(font1); HSSFCellStyle datastyle = wb.CreateCellStyle(); datastyle.CloneStyleFrom(globalstyle); datastyle.SetFont(font2); HSSFCellStyle footerStyle = wb.CreateCellStyle(); footerStyle.CloneStyleFrom(headerstyle); footerStyle.Alignment = HSSFCellStyle.ALIGN_RIGHT; footerStyle.SetFont(font2); HSSFCellStyle ErrorStyle = wb.CreateCellStyle(); ErrorStyle.CloneStyleFrom(headerstyle); ErrorStyle.Alignment = HSSFCellStyle.ALIGN_RIGHT; ErrorStyle.SetFont(font_Red_Bold); HSSFCellStyle SacofooterStyle = wb.CreateCellStyle(); SacofooterStyle.CloneStyleFrom(globalstyle); SacofooterStyle.Alignment = HSSFCellStyle.ALIGN_RIGHT; SacofooterStyle.FillForegroundColor = HSSFColor.LIGHT_BLUE.index; SacofooterStyle.FillPattern = HSSFCellStyle.SOLID_FOREGROUND; SacofooterStyle.SetFont(sacofont); //Header HSSFRow row = sheet.CreateRow(0); row.CreateCell(0).CellStyle = headerstyle; row.GetCell(0).SetCellValue("Status"); row.CreateCell(1).CellStyle = headerstyle; row.GetCell(1).SetCellValue("Prj No."); row.CreateCell(2).CellStyle = headerstyle; row.GetCell(2).SetCellValue("SAP"); row.CreateCell(3).CellStyle = headerstyle; row.GetCell(3).SetCellValue("Cost Code"); row.CreateCell(4).CellStyle = headerstyle; row.GetCell(4).SetCellValue("Project Name"); int colcount = 5; for (DateTime dt = rp.DateFrom; dt < rp.DateTo.AddDays(1); dt = dt.AddDays(1)) { row.CreateCell(colcount).CellStyle = dayStyle; row.GetCell(colcount).CellStyle.WrapText = true; row.GetCell(colcount).SetCellValue(new DateTime(dt.Year, dt.Month, dt.Day).ToString("ddd") + "\n" + new DateTime(dt.Year, dt.Month, dt.Day).ToString("dd") + "\n" + new DateTime(dt.Year, dt.Month, dt.Day).ToString("MMM")); colcount++; } row.CreateCell(colcount).CellStyle = headerstyle; row.GetCell(colcount).SetCellValue("Total"); //Details int rowcount = 1; foreach (var ts in rp.TimeSheets) { sheet.CreateRow(rowcount); sheet.GetRow(rowcount).CreateCell(0).CellStyle = datastyle; sheet.GetRow(rowcount).GetCell(0).SetCellValue(ts.Status); sheet.GetRow(rowcount).CreateCell(1).CellStyle = datastyle; sheet.GetRow(rowcount).GetCell(1).SetCellValue(ts.Project_Number.ToString()); sheet.GetRow(rowcount).CreateCell(2).CellStyle = datastyle; sheet.GetRow(rowcount).GetCell(2).SetCellValue(ts.SAP); sheet.GetRow(rowcount).CreateCell(3).CellStyle = datastyle; sheet.GetRow(rowcount).GetCell(3).SetCellValue(ts.WBS); sheet.GetRow(rowcount).CreateCell(4).CellStyle = datastyle; sheet.GetRow(rowcount).GetCell(4).CellStyle.WrapText = true; sheet.GetRow(rowcount).GetCell(4).SetCellValue(ts.Project_Name); colcount = 5; foreach (var d in ts.Days) { sheet.GetRow(rowcount).CreateCell(colcount).CellStyle = datastyle; if (d.HoursWorked.HasValue) { sheet.GetRow(rowcount).GetCell(colcount).SetCellValue((double)d.HoursWorked.Value); } else { sheet.GetRow(rowcount).GetCell(colcount).SetCellValue(string.Empty); } colcount++; } sheet.GetRow(rowcount).CreateCell(colcount).CellStyle = datastyle; sheet.GetRow(rowcount).GetCell(colcount).SetCellValue((double)ts.Total); rowcount++; } //Footer //Insert blank spaces sheet.CreateRow(rowcount); sheet.GetRow(rowcount).CreateCell(0).CellStyle = footerStyle; sheet.GetRow(rowcount).CreateCell(1).CellStyle = footerStyle; sheet.GetRow(rowcount).CreateCell(2).CellStyle = footerStyle; sheet.GetRow(rowcount).CreateCell(3).CellStyle = footerStyle; sheet.GetRow(rowcount).CreateCell(4).CellStyle = footerStyle; colcount = 5; //Start at column 5 inserting values int loopindex = 0; foreach (var d in rp.DayTotals) { sheet.GetRow(rowcount).CreateCell(colcount).CellStyle = footerStyle; if (d.HoursWorked.HasValue && (decimal)d.HoursWorked.Value > 0) { loopindex = d.Number - 1; if (rp.DayTotals[loopindex].HoursWorked.Value > rp.DaySacoTotals[loopindex].HoursWorked.Value) { sheet.GetRow(rowcount).GetCell(colcount).CellStyle = ErrorStyle; } sheet.GetRow(rowcount).GetCell(colcount).SetCellValue(((decimal)d.HoursWorked.Value).ToString("#0.00")); } else { sheet.GetRow(rowcount).GetCell(colcount).SetCellValue(string.Empty); } colcount++; } sheet.GetRow(rowcount).CreateCell(colcount).CellStyle = footerStyle; sheet.GetRow(rowcount).GetCell(colcount).SetCellValue(((decimal)rp.GrandTotal).ToString("#0.00")); rowcount++; //SACO Footer //Insert blank spaces sheet.CreateRow(rowcount); sheet.GetRow(rowcount).CreateCell(0).CellStyle = SacofooterStyle; sheet.GetRow(rowcount).GetCell(0).SetCellValue("Saco"); sheet.GetRow(rowcount).CreateCell(1).CellStyle = SacofooterStyle; sheet.GetRow(rowcount).CreateCell(2).CellStyle = SacofooterStyle; sheet.GetRow(rowcount).CreateCell(3).CellStyle = SacofooterStyle; sheet.GetRow(rowcount).CreateCell(4).CellStyle = SacofooterStyle; colcount = 5; //Start at column 5 inserting values foreach (var d in rp.DaySacoTotals) { sheet.GetRow(rowcount).CreateCell(colcount).CellStyle = SacofooterStyle; if (d.HoursWorked.HasValue && (decimal)d.HoursWorked.Value > 0) { sheet.GetRow(rowcount).GetCell(colcount).SetCellValue(((decimal)d.HoursWorked.Value).ToString("#0.00")); } else { sheet.GetRow(rowcount).GetCell(colcount).SetCellValue(string.Empty); } colcount++; } sheet.GetRow(rowcount).CreateCell(colcount).CellStyle = SacofooterStyle; sheet.GetRow(rowcount).GetCell(colcount).SetCellValue(((decimal)rp.DaySacoTotals.Sum(t => t.HoursWorked)).ToString("#0.00")); MemoryStream ms = new MemoryStream(); // Writing the workbook content to the FileStream... wb.Write(ms); // Sending the server processed data back to the user computer... return(File(ms.ToArray(), "application/vnd.ms-excel", coll["ddlUsers"] + "_" + coll["txtDateFrom"] + "_" + coll["txtDateTo"] + "_TimeSheetReport.xls")); }
/// <summary> /// Filters the specified package. /// </summary> /// <param name="package">The package.</param> /// <returns> /// True, if the filter criterias matches, otherwise False. /// </returns> public override bool Filter(ReportPackage package) { DoInitializationCheck(); bool result = false; IComparable value = (IComparable)ExtractObjectData.Create(this.MemberName).GetValue(package); switch (this.Operand) { case ArithmeticFilterOperandEnum.Equal: { if (value == null && this.Value == null) { result = true; } else if (value == null || this.Value == null) { } else { result = value.Equals((IComparable)Convert.ChangeType(this.Value, value.GetType())); } } break; case ArithmeticFilterOperandEnum.NotEqual: { if (value == null && this.Value == null) { } else if (value == null || this.Value == null) { result = true; } else { result = !value.Equals((IComparable)Convert.ChangeType(this.Value, value.GetType())); } } break; case ArithmeticFilterOperandEnum.Greater: { if (this.Value == null) { throw new NullReferenceException("Filter value is null"); } if (value == null) { throw new NullReferenceException(string.Format("Field or property value is null '{0}'", this.MemberName)); } result = value.CompareTo((IComparable)Convert.ChangeType(this.Value, value.GetType())) < 0; } break; case ArithmeticFilterOperandEnum.Lower: { if (this.Value == null) { throw new NullReferenceException("Filter value is null"); } if (value == null) { throw new NullReferenceException(string.Format("Field or property value is null '{0}'", this.MemberName)); } result = value.CompareTo((IComparable)Convert.ChangeType(this.Value, value.GetType())) > 0; } break; case ArithmeticFilterOperandEnum.GreaterOrEqual: { if (this.Value == null) { throw new NullReferenceException("Filter value is null"); } if (value == null) { throw new NullReferenceException(string.Format("Field or property value is null '{0}'", this.MemberName)); } result = value.CompareTo((IComparable)Convert.ChangeType(this.Value, value.GetType())) <= 0; } break; case ArithmeticFilterOperandEnum.LowerOrEqual: { if (this.Value == null) { throw new NullReferenceException("Filter value is null"); } if (value == null) { throw new NullReferenceException(string.Format("Field or property value is null '{0}'", this.MemberName)); } result = value.CompareTo((IComparable)Convert.ChangeType(this.Value, value.GetType())) >= 0; } break; } return(result); }
private static void SenderThreadMain() { while (!mShutdown) { mSendErrorReportFlushedSignalEvent.Reset(); mSendErrorReportSignalEvent.WaitOne(); try { if (mServiceLocator.ServiceState == Net.Services.ServiceStateEnum.Available && mProxy != null) { int counter = 0; lock (LOCK_FOR_LISTS) { counter = mReportPackages.Count; } while (counter > 0) { lock (LOCK_PROXY) { if (mProxy != null) { ReportPackage rp = null; lock (LOCK_FOR_LISTS) { // csomag kiválasztása küldésre if (mReportPackages.Count > 0) { rp = mReportPackages[0]; } else { counter = 0; } } // a küldést már a lock context-en kívül valósítom meg. if (rp != null) { // meg van mit kell küldeni mProxy.SendErrorReport(rp); // ha nem dobott hibát a küldés, akkor törlöm a tárolóból a packaget lock (LOCK_FOR_LISTS) { mReportPackages.RemoveAt(0); counter = mReportPackages.Count; } } } } } } } catch (Exception) { } mSendErrorReportFlushedSignalEvent.Set(); } mShutdownEvent.Set(); }