public static string ToXmlRowCell <T>(this List <T> list, GridSpec <T> spec, int rowLimit) { var rowID = 0; //we want to ensure that T implements are needed interface... using (var stream = new MemoryStream()) { using (var writer = new XmlTextWriter(stream, null)) { writer.WriteStartElement("rows"); if (rowLimit != UnlimitedRowLimit && list.Count > rowLimit) { list.RemoveRange(rowLimit, list.Count - rowLimit); } list.ForEach(m => m.ToXmlRowCell(writer, ++rowID, spec)); writer.WriteFullEndElement(); writer.Flush(); var array = stream.ToArray(); var s = Encoding.UTF8.GetString(array); return(s); } } }
public static string DataTableToXmlRowCol(this DataTable table, GridSpec <IStringIndexer> spec) { var rowID = 0; using (var stream = new MemoryStream()) using (var writer = new XmlTextWriter(stream, null)) { writer.WriteStartElement("rows"); var reader = table.CreateDataReader(); while (reader.Read()) { var indexer = AdaptReaderToIStringIndexer(reader); indexer.ToXmlRowCell(writer, rowID, spec); rowID++; } reader.Close(); writer.WriteFullEndElement(); writer.Flush(); var array = stream.ToArray(); var s = Encoding.UTF8.GetString(array); return(s); } }
/// <summary> /// DHTMLx Grid expects a json format like this: /// { /// rows:[ /// { id:1, data: ["A Time to Kill", "John Grisham", "100"]}, /// { id:2, data: ["Blood and Smoke", "Stephen King", "1000"]}, /// { id:3, data: ["The Rainmaker", "John Grisham", "-200"]} /// ] /// } /// </summary> /// <param name="modelList"></param> /// <param name="gridSpec"></param> /// <param name="rowLimit"></param> public GridJsonNetJObjectResult(List <T> modelList, GridSpec <T> gridSpec, int?rowLimit) { _gridSpec = gridSpec; _modelList = modelList; var list = rowLimit.HasValue ? modelList.Take(rowLimit.Value) : modelList; _data = JObject.FromObject(new { rows = list.Select((t, i) => t.ToDhtmlxGridJsonRow(i + 1, _gridSpec)).ToList() }); }
public static void AssertColumnExistsAndMatchesValue <T>(GridSpec <T> gridSpec, string expectColumnName, T sampleObject, string expectedValue) { var expectedColumn = gridSpec.SingleOrDefault(c => String.Equals(c.ColumnNameInnerText, expectColumnName, StringComparison.InvariantCultureIgnoreCase)); Assert.That(expectedColumn, Is.Not.Null, String.Format("Missing Column \"{0}\"", expectColumnName)); // ReSharper disable PossibleNullReferenceException Assert.That(expectedColumn.CalculateStringValue(sampleObject), Is.StringContaining(expectedValue), String.Format("Column \"{0}\" had an unexpected value.", expectColumnName)); // ReSharper restore PossibleNullReferenceException }
public DetailViewData(Person currentPerson, Models.GrantAllocation grantAllocation , GrantAllocationBasicsViewData grantAllocationBasicsViewData , EntityNotesViewData grantAllocationNotesViewData , EntityNotesViewData grantAllocationNoteInternalsViewData , ViewGoogleChartViewData viewGoogleChartViewData , GridSpec <Models.ProjectGrantAllocationRequest> projectGrantAllocationRequestsGridSpec , GrantAllocationExpendituresGridSpec grantAllocationExpendituresGridSpec) : base(currentPerson, grantAllocation) { PageTitle = grantAllocation.GrantAllocationName.ToEllipsifiedStringClean(110); BreadCrumbTitle = $"{Models.FieldDefinition.GrantAllocation.GetFieldDefinitionLabel()} Detail"; GrantAllocationBasicsViewData = grantAllocationBasicsViewData; GrantAllocationNotesViewData = grantAllocationNotesViewData; NewGrantAllocationNoteUrl = grantAllocation.GetNewNoteUrl(); GrantAllocationNoteInternalsViewData = grantAllocationNoteInternalsViewData; ViewGoogleChartViewData = viewGoogleChartViewData; var projectGrantAllocationExpenditures = GrantAllocation.ProjectGrantAllocationExpenditures.ToList(); CalendarYearsForProjectExpenditures = projectGrantAllocationExpenditures.CalculateCalendarYearRangeForExpenditures(grantAllocation); ProjectCalendarYearExpendituresGridSpec = new ProjectCalendarYearExpendituresGridSpec(CalendarYearsForProjectExpenditures) { ObjectNameSingular = $"{Models.FieldDefinition.Project.GetFieldDefinitionLabel()}", ObjectNamePlural = $"{Models.FieldDefinition.Project.GetFieldDefinitionLabelPluralized()}", SaveFiltersInCookie = true }; ProjectCalendarYearExpendituresGridName = "projectsCalendarYearExpendituresFromGrantAllocationGrid"; ProjectCalendarYearExpendituresGridDataUrl = SitkaRoute <GrantAllocationController> .BuildUrlFromExpression(tc => tc.ProjectCalendarYearExpendituresGridJsonData(grantAllocation)); ProjectGrantAllocationRequestsGridSpec = projectGrantAllocationRequestsGridSpec; ProjectGrantAllocationRequestsGridName = "projectsGrantAllocationRequestsFromGrantAllocationGrid"; ProjectGrantAllocationRequestsGridDataUrl = SitkaRoute <GrantAllocationController> .BuildUrlFromExpression(tc => tc.ProjectGrantAllocationRequestsGridJsonData(grantAllocation)); GrantAllocationExpendituresGridSpec = grantAllocationExpendituresGridSpec; GrantAllocationExpendituresGridName = "grantAllocationExpendituresGrid"; GrantAllocationExpendituresGridDataUrl = SitkaRoute <GrantAllocationController> .BuildUrlFromExpression(gac => gac.GrantAllocationExpendituresGridJsonData(grantAllocation)); GrantAllocationBudgetLineItemsViewData = new GrantAllocationBudgetLineItemsViewData(currentPerson, grantAllocation, grantAllocation.GrantAllocationBudgetLineItems.ToList()); GrantAllocationBudgetVsActualsViewData = new GrantAllocationBudgetVsActualsViewData(currentPerson, grantAllocation); var canEditDocuments = new GrantAllocationEditAsAdminFeature().HasPermission(currentPerson, grantAllocation).HasPermission; GrantAllocationDetailsFileDetailsViewData = new FileDetailsViewData( EntityDocument.CreateFromEntityDocument(new List <IEntityDocument>(grantAllocation.GrantAllocationFileResources)), SitkaRoute <GrantAllocationController> .BuildUrlFromExpression(x => x.NewGrantAllocationFiles(grantAllocation.PrimaryKey)), canEditDocuments, Models.FieldDefinition.GrantAllocation ); }
/// <summary> /// All grids use this /// </summary> /// <typeparam name="T"></typeparam> /// <param name="html"></param> /// <param name="gridSpec"></param> /// <param name="gridName"></param> /// <param name="optionalGridDataUrl"></param> /// <param name="styleString"></param> /// <param name="dhtmlxGridResizeType"></param> /// <returns></returns> public static HtmlString DhtmlxGrid <T>(this HtmlHelper html, GridSpec <T> gridSpec, string gridName, string optionalGridDataUrl, string styleString, DhtmlxGridResizeType dhtmlxGridResizeType) { var dhtmlxGridHeader = DhtmlxGridHtmlHelpers.BuildDhtmlxGridHeader(gridSpec, gridName, ExcelDownloadWithFooterUrl, ExcelDownloadWithoutFooterUrl); var dhtmlxGrid = DhtmlxGridHtmlHelpers.DhtmlxGridImpl(gridSpec, gridName, optionalGridDataUrl, $"background-color:white;{styleString}", null, dhtmlxGridHeader, dhtmlxGridResizeType); return(new HtmlString(dhtmlxGrid)); }
/// <summary> /// DHTMLx Grid expects a json format like this: /// { /// rows:[ /// { id:1, data: ["A Time to Kill", "John Grisham", "100"]}, /// { id:2, data: ["Blood and Smoke", "Stephen King", "1000"]}, /// { id:3, data: ["The Rainmaker", "John Grisham", "-200"]} /// ] /// } /// </summary> /// <param name="modelList"></param> /// <param name="gridSpec"></param> /// <param name="rowLimit"></param> /// <param name="uniqueIDFunc"></param> public GridJsonNetJObjectResult(List <T> modelList, GridSpec <T> gridSpec, int?rowLimit, Expression <Func <T, int> > uniqueIDFunc) { _gridSpec = gridSpec; _modelList = modelList; var list = rowLimit.HasValue ? modelList.Take(rowLimit.Value) : modelList; var anonymousObject = new { rows = list.Select((t, i) => t.ToDhtmlxGridJsonRow(uniqueIDFunc?.Compile()(t) ?? i + 1, _gridSpec)).ToList() }; _data = JObject.FromObject(anonymousObject); }
/// <summary> /// /// </summary> public static string ToCsv<T>(this IEnumerable<T> modelList, GridSpec<T> spec) { Check.RequireNotNull(modelList, ErrorMessageForEmptyModelList); var output = new StringBuilder(); output.AppendLine(EnumerableStringToCsvRow(spec.ColumnNames)); foreach (var viewModel in modelList) { viewModel.ToCsvRow(output, spec); } return output.ToString(); }
/// <summary> /// All grids use this /// </summary> /// <typeparam name="T"></typeparam> /// <param name="html"></param> /// <param name="gridSpec"></param> /// <param name="gridName"></param> /// <param name="optionalGridDataUrl"></param> /// <param name="styleString"></param> /// <param name="dhtmlxGridResizeType"></param> /// <returns></returns> public static HtmlString DhtmlxGrid <T>(this HtmlHelper html, GridSpec <T> gridSpec, string gridName, string optionalGridDataUrl, string styleString, DhtmlxGridResizeType dhtmlxGridResizeType) { var dhtmlxGridHeader = DhtmlxGridHtmlHelpers.BuildDhtmlxGridHeader(gridSpec, gridName, ExcelDownloadUrl); var saveGridSettingsUrl = SitkaRoute <GridSettingsController> .BuildUrlFromExpression(c => c.SaveGridSettings()); var dhtmlxGrid = DhtmlxGridHtmlHelpers.DhtmlxGridImpl(gridSpec, gridName, optionalGridDataUrl, $"background-color:white;{styleString}", null, dhtmlxGridHeader, dhtmlxGridResizeType, saveGridSettingsUrl); return(new HtmlString(dhtmlxGrid)); }
public static string DataTableToCsv(this DataTable table, GridSpec <IStringIndexer> spec) { var output = new StringBuilder(); output.AppendLine(ToCsvExtensionMethods.EnumerableStringToCsvRow(spec.ColumnNames)); var reader = table.CreateDataReader(); while (reader.Read()) { var line = String.Join(ToCsvExtensionMethods.CsvDelimiter, spec.Select(cs => ToCsvExtensionMethods.CsvEscape(cs.CalculateStringValue(AdaptReaderToIStringIndexer(reader))))); output.AppendLine(line); } reader.Close(); return(output.ToString()); }
//public ObligationItemBudgetGridSpec ObligationItemBudgetGridSpec { get; } //public string ObligationItemBudgetGridName { get; } //public string ObligationItemBudgetGridDataUrl { get; } public DetailViewData(FirmaSession currentFirmaSession, ProjectFirmaModels.Models.FundingSource fundingSource, ViewGoogleChartViewData viewGoogleChartViewData, GridSpec <ProjectFirmaModels.Models.ProjectFundingSourceBudget> projectFundingSourceBudgetGridSpec, DisplayFundingSourceCustomAttributesViewData displayFundingSourceCustomAttributeTypesViewData) : base(currentFirmaSession) { ViewGoogleChartViewData = viewGoogleChartViewData; FundingSource = fundingSource; PageTitle = fundingSource.GetDisplayName(); EntityName = $"{FieldDefinitionEnum.FundingSource.ToType().GetFieldDefinitionLabel()}"; UserHasFundingSourceManagePermissions = new FundingSourceEditFeature().HasPermission(currentFirmaSession, fundingSource).HasPermission; UserHasFundingSourceCustomAttributeManagePermissions = new FundingSourceCustomAttributeEditFeature().HasPermission(currentFirmaSession, fundingSource).HasPermission; UserHasProjectFundingSourceExpenditureManagePermissions = new FirmaAdminFeature().HasPermissionByFirmaSession(currentFirmaSession); EditFundingSourceUrl = fundingSource.GetEditUrl(); EditFundingSourceCustomAttributesUrl = SitkaRoute <FundingSourceCustomAttributesController> .BuildUrlFromExpression(c => c.EditFundingSourceCustomAttributesForFundingSource(fundingSource)); var projectFundingSourceExpenditures = FundingSource.ProjectFundingSourceExpenditures.ToList(); CalendarYearsForProjectExpenditures = projectFundingSourceExpenditures.CalculateCalendarYearRangeForExpenditures(fundingSource); ProjectCalendarYearExpendituresGridSpec = new ProjectCalendarYearExpendituresGridSpec(CalendarYearsForProjectExpenditures) { ObjectNameSingular = $"{FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()}", ObjectNamePlural = $"{FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabelPluralized()}", SaveFiltersInCookie = true }; ProjectCalendarYearExpendituresGridName = "projectsCalendarYearExpendituresFromFundingSourceGrid"; ProjectCalendarYearExpendituresGridDataUrl = SitkaRoute <FundingSourceController> .BuildUrlFromExpression(tc => tc.ProjectCalendarYearExpendituresGridJsonData(fundingSource)); ManageFundingSourcesUrl = SitkaRoute <FundingSourceController> .BuildUrlFromExpression(c => c.Index()); ProjectFundingSourceBudgetGridSpec = projectFundingSourceBudgetGridSpec; ProjectFundingSourceBudgetGridName = "projectsFundingSourceRequestsFromFundingSourceGrid"; ProjectFundingSourceBudgetGridDataUrl = SitkaRoute <FundingSourceController> .BuildUrlFromExpression(tc => tc.ProjectFundingSourceBudgetGridJsonData(fundingSource)); DisplayFundingSourceCustomAttributeTypesViewData = displayFundingSourceCustomAttributeTypesViewData; ContractualInvoiceGridName = "fundingSourceContractualInvoicesGrid"; ContractualInvoiceGridSpec = new ContractualInvoiceGridSpec(currentFirmaSession); ContractualInvoiceGridDataUrl = SitkaRoute <FundingSourceController> .BuildUrlFromExpression(fc => fc.ContractualInvoiceGridOnFundDetailJsonData(fundingSource)); //ObligationItemBudgetGridName = "fundingSourceContractualInvoicesGrid"; //ObligationItemBudgetGridSpec = new ObligationItemBudgetGridSpec(currentFirmaSession); //ObligationItemBudgetGridDataUrl = SitkaRoute<FundingSourceController>.BuildUrlFromExpression(fc => fc.ObligationItemBudgetGridOnFundDetailJsonData(fundingSource)); }
public GridXmlDataTableResult(DataTable dataTable, GridSpec <IStringIndexer> gridSpec) { DataTable = dataTable; GridSpec = gridSpec; }
public static MemoryStream ObjectListToExcelWorksheet <T>(List <T> modelList, GridSpec <T> spec, string sheetName) { var xmlStream = SpreadsheetReader.Create(); using (var spreadsheetDocument = SpreadsheetDocument.Open(xmlStream, true)) { SetSheetName(sheetName, spreadsheetDocument); var worksheetPart = GetWorksheetPartByName(spreadsheetDocument, sheetName); var modelObjects = modelList.Select(c => c); uint rowIndex = 1; var sharedStringDictionary = new SharedStringTableDictionary(); AddExcelRow(spec.ColumnNames, worksheetPart, sharedStringDictionary, rowIndex); foreach (var modelObject in modelObjects) { rowIndex++; ToExcelRow(modelObject, spec, worksheetPart, sharedStringDictionary, rowIndex); } // Update the real string table with values var sharedStringTablePart = spreadsheetDocument.WorkbookPart.GetPartsOfType <SharedStringTablePart>().First(); sharedStringDictionary.AppendToSharedStringTable(sharedStringTablePart); sharedStringTablePart.SharedStringTable.Save(); // Save to the memory stream Save(spreadsheetDocument); spreadsheetDocument.Close(); } return(xmlStream); }
public GridXmlResult(List <T> modelList, GridSpec <T> gridSpec, int rowLimit) { _gridSpec = gridSpec; _modelList = modelList; _xmlDataForallRows = ModelList.ToXmlRowCell(GridSpec, rowLimit); }
public GridXmlResult(List <T> modelList, GridSpec <T> gridSpec) : this(modelList, gridSpec, ModelListAbstract.UnlimitedRowLimit) { }
// Use this for initialization void Awake() { grid = transform.parent.gameObject; gridSpec = grid.GetComponent <GridSpec>(); }
public static void AssertColumnDoesNotExist <T>(GridSpec <T> gridSpec, string expectColumnName) { var expectedColumn = gridSpec.SingleOrDefault(c => String.Equals(c.ColumnNameInnerText, expectColumnName, StringComparison.InvariantCultureIgnoreCase)); Assert.That(expectedColumn, Is.Null, String.Format("Should not have Column \"{0}\"", expectColumnName)); }
public GridJsonNetJObjectResult(List <T> modelList, GridSpec <T> gridSpec, Expression <Func <T, int> > uniqueIDFunc) : this(modelList, gridSpec, null, uniqueIDFunc) { }
public static DhtmlxGridJsonRow ToDhtmlxGridJsonRow <T>(this T thingToRead, int rowID, GridSpec <T> gridSpec) { var columnValues = gridSpec.Select(columnSpec => thingToRead.ToDhtmlxGridJsonCellData(columnSpec)).ToList(); return(new DhtmlxGridJsonRow(rowID, columnValues)); }
private ActionResult GetResultsAsCsvDowloadOrJsonResult <T>(WebServiceReturnTypeEnum webServiceReturnTypeEnum, IEnumerable <T> results, GridSpec <T> gridSpec, string downloadFileDescriptorPrefix) { switch (webServiceReturnTypeEnum) { case WebServiceReturnTypeEnum.CSV: var csv = results.ToCsv(gridSpec); var descriptor = new DownloadFileDescriptor(downloadFileDescriptorPrefix); return(new CsvDownloadResult(descriptor, csv)); case WebServiceReturnTypeEnum.JSON: return(Json(results, JsonRequestBehavior.AllowGet)); default: throw new ArgumentOutOfRangeException($"Invalid return type {webServiceReturnTypeEnum}"); } }
public GridJsonNetJObjectResult(List <T> modelList, GridSpec <T> gridSpec) : this(modelList, gridSpec, null) { }
public static void ToXmlRowCell <T>(this T thingToRead, XmlTextWriter writer, int rowID, GridSpec <T> gridSpec) { writer.WriteStartElement("row"); writer.WriteAttributeString("id", rowID.ToString(CultureInfo.InvariantCulture)); foreach (var columnSpec in gridSpec) { writer.WriteStartElement("cell"); var cellCssClass = columnSpec.CalculateCellCssClass(thingToRead); var title = columnSpec.CalculateTitle(thingToRead); if (!String.IsNullOrEmpty(cellCssClass)) { writer.WriteAttributeString("class", cellCssClass); } if (!String.IsNullOrEmpty(title)) { writer.WriteAttributeString("title", title); } //if (columnSpec.IsHidden) //{ // writer.WriteAttributeString("hidden", "true"); //} var value = columnSpec.CalculateStringValue(thingToRead) ?? String.Empty; var stripped = XmlResult.StripInvalidCharacters(value); var xmlEncoded = SecurityElement.Escape(stripped); var translated = XmlResult.XmlEncodeCodePage1252Characters(xmlEncoded); writer.WriteRaw(translated); writer.WriteFullEndElement(); } writer.WriteFullEndElement(); }
public static string ToXmlRowCell <T>(this List <T> list, GridSpec <T> spec) { return(ToXmlRowCell(list, spec, UnlimitedRowLimit)); }