public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output) { if (!string.IsNullOrEmpty(EventHandler)) { Context.EventHandlerClass = EventHandler; } if (!string.IsNullOrEmpty(DataKeys) && DataKeys != Context.DataKeys) { Context.DataKeys = DataKeys; } object service = null; if (!string.IsNullOrEmpty(Context.EventHandlerClass)) { service = NccReflectionService.NccGetClassInstance(Context.EventHandlerClass, null); } service?.NccInvokeMethod(NccEventsEnum.Load.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext } }); //Get grid id and share it with siblings parents if (string.IsNullOrEmpty(Context.Id)) { Context.Id = Guid.NewGuid().ToString(); } output.TagName = "div"; output.Attributes.SetAttribute("id", Context.Id); output.Attributes.SetAttribute("style", "position:relative"); if (Context.Visible) { if (RenderForm) { var form = new TagBuilder("form"); form.TagRenderMode = TagRenderMode.StartTag; output.PreContent.AppendHtml(form); } //Get data from datasource NccControlsService.BindData(Context, ViewContext.HttpContext, null, null); service?.NccInvokeMethod(NccEventsEnum.DataBound.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext, DataObjects = Context.DataObjects } }); var data = Context.DataObjects.GetType().ToString().Contains("Microsoft.EntityFrameworkCore.Internal.InternalDbSet") || Context.DataObjects.GetType().ToString().Contains("Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable") ? ((IQueryable <object>)Context.DataObjects).FirstOrDefault() : Context.DataObjects as object; if (data != null) { if (!string.IsNullOrEmpty(Context.DataKeys)) { Context.DataKeysValues = new List <Dictionary <string, object> >(); var dataKeys = Context.DataKeys.Split(',')?.ToList(); var dataKeysRow = new Dictionary <string, object>(); foreach (var dataKey in dataKeys) { var keyValue = data.NccGetPropertyValue <object>(dataKey); if (keyValue != null) { dataKeysRow[dataKey] = keyValue; } } Context.DataKeysValues.Add(dataKeysRow); } ViewContext.ViewData.Model = data; var content = await output.GetChildContentAsync(); output.Content.SetHtmlContent(content.GetContent()); } if (RenderForm) { output.PostContent.AppendHtml(new TagBuilder("form") { TagRenderMode = TagRenderMode.EndTag }); } } else { output.SuppressOutput(); } service?.NccInvokeMethod(NccEventsEnum.PreRender.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext } }); output.PostContent.AppendHtml(NccControlsService.GetEncodedContext(_protector, Context.Id, Context)); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderOverlay()); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderImage()); }
public static byte[] GetExcelPackage(NccGridContext context, HttpContext httpContext) { NccActionsService.ExtraParameters <NccGridContext> setExtraParameters = GridService.GetExtraNullableParameters; NccActionsService.DataResult <NccGridContext> setDataResult = GridService.SetDataResult; NccControlsService.BindData(context, httpContext, setExtraParameters, setDataResult); using (ExcelPackage package = new ExcelPackage()) { Int32 row = 2; Int32 col = 1; if (string.IsNullOrEmpty(context.GridExportExcel.Title)) { context.GridExportExcel.Title = context.Id; } package.Workbook.Properties.Title = context.GridExportExcel.Title; package.Workbook.Properties.Subject = context.GridExportExcel.Subject; package.Workbook.Properties.Company = context.GridExportExcel.Company; package.Workbook.Properties.Author = context.GridExportExcel.Author; package.Workbook.Properties.Keywords = context.GridExportExcel.Keywords; package.Workbook.Worksheets.Add(context.GridExportExcel.Title); var list = context.DataObjects as IList; var propInfo = list.GetType().GetTypeInfo().GenericTypeArguments[0].GetProperties(); ExcelWorksheet sheet = package.Workbook.Worksheets[context.GridExportExcel.Title]; foreach (var column in context.GridExportExcel.Columns) { if (string.IsNullOrEmpty(column.ColumnTitle)) { column.ColumnTitle = $"Coluna {col}"; } sheet.Cells[1, col].Value = column.ColumnTitle; //if (!string.IsNullOrEmpty(column.HeaderHorizontalAlignment)) // sheet.Cells[1, col].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment. if (!context.GridExportExcel.AutoFitColumns.HasValue || !context.GridExportExcel.AutoFitColumns.Value) { sheet.Column(col).Width = column.Width.Value; } col++; } //foreach (var column in propInfo) //{ // if (column.PropertyType == typeof(string) || !typeof(IEnumerable).IsAssignableFrom(column.PropertyType)) // { // sheet.Cells[1, col].Value = "Coluna " + col; // sheet.Column(col++).Width = 18; // } //} foreach (var gridRow in list) { col = 1; foreach (var column in context.GridExportExcel.Columns) { sheet.Cells[row, col++].Value = propInfo.FirstOrDefault(x => x.Name == column.ColumnPropName).GetValue(gridRow, null); } //foreach (var column in propInfo) //{ // if (column.PropertyType == typeof(string) || !typeof(IEnumerable).IsAssignableFrom(column.PropertyType)) // sheet.Cells[row, col++].Value = column.GetValue(gridRow, null); //} row++; } // Add to table / Add summary row var tbl = sheet.Tables.Add(new ExcelAddressBase(fromRow: 1, fromCol: 1, toRow: row - 1, toColumn: col - 1), context.GridExportExcel.Title); if (context.GridExportExcel.ShowHeader.HasValue) { tbl.ShowHeader = context.GridExportExcel.ShowHeader.Value; } //tbl.TableStyle = TableStyles.Medium13; if (context.GridExportExcel.ShowTotal.HasValue) { tbl.ShowTotal = context.GridExportExcel.ShowTotal.Value; } //tbl.Columns[3].DataCellStyleName = dataCellStyleName; //tbl.Columns[3].TotalsRowFunction = RowFunctions.Sum; //sheet.Cells[5, 4].Style.Numberformat.Format = numberformat; if (context.GridExportExcel.AutoFitColumns.HasValue && context.GridExportExcel.AutoFitColumns.Value) { sheet.Cells[1, 1, row - 1, col - 1].AutoFitColumns(); } return(package.GetAsByteArray()); } }
public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output) { if (Context == null) { throw new Exception("The NccRepeaterContext is null... Please check the reference."); } object service = null; if (!string.IsNullOrEmpty(Context.EventHandlerClass)) { service = NccReflectionService.NccGetClassInstance(Context.EventHandlerClass, null); } service?.NccInvokeMethod(NccEventsEnum.Load.ToString(), new object[] { new NccEventArgs { NccTagContext = _nccTagContext, NccControlContext = Context, ViewContext = ViewContext } }); //Get grid id and share it with siblings parents if (string.IsNullOrEmpty(Context.Id)) { Context.Id = Guid.NewGuid().ToString(); } output.TagName = "div"; output.Attributes.SetAttribute("id", Context.Id); output.Attributes.SetAttribute("style", "position:relative"); if (Context.Visible) { tagContext.Items.Add(typeof(NccRepeaterContext), Context); //NccActionsService.ExtraParameters<NccRepeaterContext> setExtraParameters = RepeaterService.GetExtraParameters; //NccActionsService.DataResult<NccRepeaterContext> setDataResult = RepeaterService.SetDataResult; NccControlsService.BindData(Context, ViewContext.HttpContext, null, null); service?.NccInvokeMethod(NccEventsEnum.DataBound.ToString(), new object[] { new NccEventArgs { NccTagContext = _nccTagContext, NccControlContext = Context, ViewContext = ViewContext, DataObjects = Context.DataObjects } }); await output.GetChildContentAsync(); } var content = ""; foreach (var repeaterItem in _nccTagContext.RepeaterItems) { content += repeaterItem; } output.Content.AppendHtml(_nccTagContext.RepeaterHeader); output.Content.AppendHtml(content); output.Content.AppendHtml(_nccTagContext.RepeaterFooter); service?.NccInvokeMethod(NccEventsEnum.PreRender.ToString(), new object[] { new NccEventArgs { NccTagContext = _nccTagContext, NccControlContext = Context, ViewContext = ViewContext } }); _nccTagContext.ControlContext = Context; output.PostContent.AppendHtml(NccControlsService.GetEncodedContext(_protector, Context.Id, Context)); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderOverlay()); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderImage()); }
public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output) { if (Context == null) { throw new Exception("The NccGridContext is null... Please check the reference."); } _nccTagContext.CssClassGrid = CssClassTable; _nccTagContext.CssClassBody = CssClassBody; _nccTagContext.CssClassHeader = CssClassHeader; _nccTagContext.CssClassFooter = CssClassFooter; _nccTagContext.CssClassHeaderContainer = CssClassHeaderContainer; _nccTagContext.CssClassTableContainer = CssClassTableContainer; _nccTagContext.CssClassFooterContainer = CssClassFooterContainer; if (!string.IsNullOrEmpty(DataKeys) && DataKeys != Context.DataKeys) { Context.DataKeys = DataKeys; } if (RenderForm.HasValue) { Context.RenderForm = RenderForm.Value; } if (AutoGenerateEditButton.HasValue) { Context.AutoGenerateEditButton = AutoGenerateEditButton.Value; } if (AllowPaging.HasValue) { Context.AllowPaging = AllowPaging.Value; } if (Context.AllowPaging) { if (PagerNavigationSize.HasValue) { Context.PagerNavigationSize = PagerNavigationSize.Value; } if (Context.Filters.ContainsKey("pageSize")) { Context.PageSize = Convert.ToInt32(Context.Filters["pageSize"]); } else if (PageSize.HasValue) { Context.PageSize = PageSize.Value; } if (Context.PageSize == 0 || Context.PageSize == int.MaxValue) { Context.PageSize = 10; } } else { Context.PageSize = int.MaxValue; } if (Context.Filters.ContainsKey("pageNumber")) { Context.PageNumber = Convert.ToInt32(Context.Filters["pageNumber"]); } object service = null; if (!string.IsNullOrEmpty(Context.EventHandlerClass)) { service = NccReflectionService.NccGetClassInstance(Context.EventHandlerClass, null); } service?.NccInvokeMethod(NccEventsEnum.Load.ToString(), new object[] { new NccEventArgs { NccTagContext = _nccTagContext, NccControlContext = Context, ViewContext = ViewContext } }); //Get grid id and share it with siblings parents if (string.IsNullOrEmpty(Context.Id)) { Context.Id = Guid.NewGuid().ToString(); } output.TagName = "div"; output.Attributes.SetAttribute("id", Context.Id); output.Attributes.SetAttribute("style", "position:relative"); if (Context.Visible) { tagContext.Items.Add(typeof(NccGridContext), Context); if (Context.RenderForm) { var form = new TagBuilder("form") { TagRenderMode = TagRenderMode.StartTag }; output.PreContent.AppendHtml(form); } NccActionsService.ExtraParameters <NccGridContext> setExtraParameters = GridService.GetExtraParameters; NccActionsService.DataResult <NccGridContext> setDataResult = GridService.SetDataResult; NccControlsService.BindData(Context, ViewContext.HttpContext, setExtraParameters, setDataResult); service?.NccInvokeMethod(NccEventsEnum.DataBound.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext, DataObjects = Context.DataObjects } }); _nccTagContext.GridHeader = new GridRow { Cells = new List <GridCell>(), CssClass = CssClassHeader }; await output.GetChildContentAsync(); var tableContainerDiv = new TagBuilder("div"); if (!string.IsNullOrEmpty(_nccTagContext.CssClassTableContainer)) { tableContainerDiv.Attributes.Add("class", _nccTagContext.CssClassTableContainer); } tableContainerDiv.InnerHtml.AppendHtml(GridService.BuildTableHtml(_nccTagContext, Context)); output.Content.SetHtmlContent(tableContainerDiv); if (Context.AllowPaging) { output.Content.AppendHtml(GridService.BuildTablePager(_nccTagContext, Context)); } output.PreContent.AppendHtml(_nccTagContext.PreContent); output.PostContent.AppendHtml(_nccTagContext.PostContent); if (Context.RenderForm) { var antiforgeryTag = Generator.GenerateAntiforgery(ViewContext); if (antiforgeryTag != null) { output.PostContent.AppendHtml(antiforgeryTag); } output.PostContent.AppendHtml(new TagBuilder("form") { TagRenderMode = TagRenderMode.EndTag }); } } service?.NccInvokeMethod(NccEventsEnum.PreRender.ToString(), new object[] { new NccEventArgs { NccTagContext = _nccTagContext, NccControlContext = Context, ViewContext = ViewContext } }); _nccTagContext.ControlContext = Context; output.PostContent.AppendHtml(NccControlsService.GetEncodedContext(_protector, Context.Id, Context)); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderOverlay()); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderImage()); }
public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output) { if (Context == null) { throw new Exception("The NccSelectContext is null... Please check the reference."); } object service = null; if (!string.IsNullOrEmpty(Context.EventHandlerClass)) { service = NccReflectionService.NccGetClassInstance(Context.EventHandlerClass, null); } service?.NccInvokeMethod(NccEventsEnum.Load, new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext } }); if (string.IsNullOrEmpty(Context.Id)) { Context.Id = Guid.NewGuid().ToString(); } output.TagName = "select"; output.Attributes.SetAttribute("id", Context.Id); if (!string.IsNullOrEmpty(DataValue)) { Context.DataValue = DataValue; } if (string.IsNullOrEmpty(Context.DataValue)) { throw new Exception($"Please set the DataValue property on NccSelect with id {Context.Id}."); } if (!string.IsNullOrEmpty(TextValue)) { Context.TextValue = TextValue; } if (string.IsNullOrEmpty(Context.TextValue)) { throw new Exception($"Please set the TextValue property on NccSelect with id {Context.Id}."); } if (!string.IsNullOrEmpty(FirstItem)) { Context.FirstItem = FirstItem; } if (Context.Visible) { NccActionsService.ExtraParameters <NccSelectContext> setExtraParameters = SelectService.GetExtraParameters; NccActionsService.DataResult <NccSelectContext> setDataResult = SelectService.SetDataResult; NccControlsService.BindData(Context, ViewContext.HttpContext, setExtraParameters, setDataResult); output.Content.AppendHtml(await output.GetChildContentAsync()); if (!string.IsNullOrEmpty(Context.FirstItem)) { var select = new TagBuilder("option") { Attributes = { { "value", "" } } }; select.InnerHtml.SetContent(Context.FirstItem); service?.NccInvokeMethod(NccSelectEventsEnum.OptionBound.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext, DataObjects = Context.DataObjects } }); output.Content.AppendHtml(select); } //var data = Context.DataObjects.GetType().ToString().Contains("Microsoft.EntityFrameworkCore.Internal.InternalDbSet") || // Context.DataObjects.GetType().ToString().Contains("Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable") ? // ((IQueryable<object>)Context.DataObjects).ToList() : Context.DataObjects as IList; var data = Context.DataObjects as IList; if (data?.Count > 0) { foreach (var elem in data) { var val = elem.NccGetPropertyValue <string>(Context.DataValue); var txt = elem.NccGetPropertyValue <string>(Context.TextValue); var select = new TagBuilder("option") { Attributes = { { "value", val } } }; select.InnerHtml.Append(txt); if (val == SelectedValue) { select.Attributes.Add("selected", "selected"); } service?.NccInvokeMethod(NccSelectEventsEnum.OptionBound.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext, DataObjects = Context.DataObjects } }); output.Content.AppendHtml(select); } } else { output.Attributes.Add("disabled", "disabled"); } service?.NccInvokeMethod(NccEventsEnum.PreRender, new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext } }); output.PostContent.AppendHtml(NccControlsService.GetEncodedContext(_protector, Context.Id, Context)); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderOverlay()); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderImage()); var divContainer = new TagBuilder("div") { Attributes = { { "id", Context.Id }, { "style", "position:relative" } }, TagRenderMode = TagRenderMode.StartTag }; output.PreElement.AppendHtml(divContainer); var endDivContainer = new TagBuilder("div") { TagRenderMode = TagRenderMode.EndTag }; output.PostElement.AppendHtml(endDivContainer); } }