public static XtraReport CreateQueryReport(QueryEduSummaryModel model) { var edus = model.EduList; var queries = model.QueryList; var year = model.Year; var form = model.Form; var reportDataList = new QueryReportDataCollection(); using (var workbook = new Workbook()) { foreach (var edu in edus) { var formData = edu.edu_form_data.FirstOrDefault(t => t.form == form && t.send_date.Year == year); if (formData != null) { var excelData = formData.file.contents; var format = formData.document_format.IsOpenXml() ? DocumentFormat.OpenXml : DocumentFormat.Xls; workbook.LoadDocument(excelData, format); } foreach (var query in queries) { var stringValue = ""; try { var content = query.content; if (content.StartsWith("@")) { var propName = content.Substring(1); var propInfo = typeof (edu).GetProperty(propName); var value = propInfo.GetValue(edu); var valueType = value.GetType(); if (valueType.GetInterface("System.Collections.IEnumerable") != null && valueType != typeof (string)) { var collection = (IEnumerable<object>) value; stringValue = collection.Join(", "); } else if (valueType == typeof (bool)) { stringValue = (bool) value ? "Да" : "Нет"; } else if (valueType == typeof (DateTime)) { stringValue = ((DateTime) value).ToString("yyyy-MM-dd"); } else { stringValue = value.ToString(); } } else { var range = workbook.Range[query.content]; var value = range.Value; stringValue = GetStringValueFromCell(value); } } catch (NullReferenceException nre) { stringValue = ""; } catch (Exception e) { stringValue = "Не удалось"; } reportDataList.Add(new QueryReportEduData(edu, query, stringValue)); } } } var groupedList = reportDataList.Group().ToList(); var report = new QueryReport { ReportData = groupedList }; Reports.Add(report); return report; }
public static XtraReport CreateQueryReport(QueryRegionSummaryModel model) { var regions = model.RegionList; var queries = model.QueryList; var year = model.Year; var form = model.Form; var reportDataList = new QueryReportDataCollection(); using (var spreadsheetControl = new SpreadsheetControl() { AllowDrop = false }) { foreach (var region in regions) { var formData = region.region_form_data.FirstOrDefault(t => t.form == form && t.send_date.Year == year); if (formData != null) { var excelData = formData.file.contents; var format = formData.document_format.IsOpenXml() ? DocumentFormat.OpenXml : DocumentFormat.Xls; spreadsheetControl.LoadDocument(excelData, format); } foreach (var query in queries) { var stringValue = ""; try { var content = query.content; if (content.StartsWith("@")) { var propName = content.Substring(1); var propInfo = typeof(region).GetProperty(propName); var value = propInfo.GetValue(region); var valueType = value.GetType(); if (valueType.GetInterface("System.Collections.IEnumerable") != null && valueType != typeof(String)) { var collection = (IEnumerable<object>)value; stringValue = collection.Join(", "); } else if (valueType == typeof(bool)) { stringValue = (bool)value ? "Да" : "Нет"; } else { stringValue = value.ToString(); } } else { var value = spreadsheetControl.Document.Range[content].Value; stringValue = GetStringValueFromCell(value); } } catch (Exception ex) { stringValue = "Не удалось"; } reportDataList.Add(new QueryReportRegionData(region, query, stringValue)); } } } var groupedList = reportDataList.Group().ToList(); var report = new QueryReport { ReportData = groupedList }; Reports.Add(report); return report; }