public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output)
        {
            output.SuppressOutput();

            if (tagContext.Items.ContainsKey(typeof(NccGridContext)))
            {
                _context = (NccGridContext)tagContext.Items[typeof(NccGridContext)];
            }
            else
            {
                return;
            }

            if (_context.GridExportExcel == null)
            {
                _context.GridExportExcel = new GridExportExcel
                {
                    Title          = DocTitle,
                    Subject        = DocSubject,
                    Author         = DocAuthor,
                    Company        = DocCompany,
                    Keywords       = DocKeywords,
                    AutoFitColumns = AutoFitColumns,
                    ShowHeader     = ShowHeader,
                    ShowTotal      = ShowTotal,
                    Columns        = new List <GridExportExcelColumn>()
                };

                await output.GetChildContentAsync();
            }
        }
Exemplo n.º 2
0
        public IActionResult MultiGridWithFilter()
        {
            var context1 = new NccGridContext
            {
                Id = "MultiGridWithFilter1",
                DataAccessClass  = typeof(IDataAccess).AssemblyQualifiedName,
                SelectMethod     = "GetCustomerDetailByOrder",
                SelectParameters = new { orderId = (int?)null }.NccToExpando(),
                ViewPaths = new ViewsPathsModel {
                    ViewPath = "/Views/NccGrid/Partials/_MultiGridWithFilter1.cshtml"
                }
            };

            ViewData[context1.Id] = context1;

            var context2 = new NccGridContext
            {
                Id = "MultiGridWithFilter2",
                DataAccessClass  = typeof(IDataAccess).AssemblyQualifiedName,
                SelectMethod     = "GetOrderDetailByOrder",
                SelectParameters = new { orderId = (int?)null }.NccToExpando(),
                ViewPaths = new ViewsPathsModel {
                    ViewPath = "/Views/NccGrid/Partials/_MultiGridWithFilter2.cshtml"
                }
            };

            ViewData[context2.Id] = context2;

            ViewData["Orders"] = DataAccess.GetOrders().ToList();

            return(View());
        }
        public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output)
        {
            output.SuppressOutput();

            if (tagContext.Items.ContainsKey(typeof(NccGridContext)))
            {
                _context = (NccGridContext)tagContext.Items[typeof(NccGridContext)];
            }
            else
            {
                return;
            }

            if (_context.AdditionalData.ContainsKey("EditRowNumber") && _context.AdditionalData["EditRowNumber"].ToString() == _nccTagContext.RowNumber.ToString())
            {
                var data = _context.DataObjects as IList;
                if (data == null || data.Count == 0)
                {
                    return;
                }

                var childContent = await output.GetChildContentAsync();

                var cell = new GridCell
                {
                    Value     = childContent,
                    CssClass  = CssClass,
                    Aggregate = Aggregate
                };

                var row = _nccTagContext.GridRows.LastOrDefault();

                row?.Cells.Add(cell);
            }
        }
Exemplo n.º 4
0
        public IActionResult CustomEditableGrid()
        {
            var suppliers  = DataAccess.GetSuppliers().ToList();
            var categories = DataAccess.GetCategories().ToList();

            var context = new NccGridContext
            {
                Id = "EditableGrid",
                DataAccessClass   = typeof(IDataAccess).AssemblyQualifiedName,
                SelectMethod      = "GetProductList",
                EventHandlerClass = typeof(CustomEditableGridEvents).AssemblyQualifiedName,
                ViewPaths         = new ViewsPathsModel {
                    ViewPath = "/Views/NccGrid/Partials/_CustomEditableGrid.cshtml"
                },
                AdditionalData = new Dictionary <string, object>
                {
                    { "Suppliers", suppliers },
                    { "Categories", categories }
                }
            };

            ViewData[context.Id] = context;

            return(View());
        }
Exemplo n.º 5
0
        public IActionResult EditableGrid()
        {
            var suppliers  = DataAccess.GetSuppliers().ToList();
            var categories = DataAccess.GetCategories().ToList();

            var context = new NccGridContext
            {
                Id = "EditableGrid",
                DataAccessClass        = typeof(IDataAccess).AssemblyQualifiedName,
                SelectMethod           = "GetProductList",
                UpdateMethod           = "UpdateProduct",
                AutoGenerateEditButton = true,
                DatabaseModelType      = typeof(Products).AssemblyQualifiedName,
                ViewPaths = new ViewsPathsModel {
                    ViewPath = "/Views/NccGrid/Partials/_EditableGrid.cshtml"
                },
                AdditionalData = new Dictionary <string, object>
                {
                    { "Suppliers", suppliers },
                    { "Categories", categories }
                }
            };

            ViewData[context.Id] = context;

            return(View());
        }
Exemplo n.º 6
0
        public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output)
        {
            output.SuppressOutput();

            if (tagContext.Items.ContainsKey(typeof(NccGridContext)))
            {
                _context = (NccGridContext)tagContext.Items[typeof(NccGridContext)];
            }
            else
            {
                return;
            }

            var childContent = await output.GetChildContentAsync();

            _nccTagContext.EmptyRow = new GridRow
            {
                CssClass = RowCssClass,
                Cells    = new List <GridCell>
                {
                    new GridCell
                    {
                        Value     = childContent,
                        CssClass  = CellCssClass,
                        Aggregate = false
                    }
                }
            };
        }
Exemplo n.º 7
0
        public static void SetDataResult(NccGridContext context, object result)
        {
            if (result.GetType().ToString().Contains(typeof(Tuple).ToString()))
            {
                context.TotalItems = Convert.ToInt32(result.GetType().GetProperty("Item2").GetValue(result));
            }
            else if (result.GetType().ToString().Contains("Microsoft.EntityFrameworkCore.Internal.InternalDbSet") ||
                     result.GetType().ToString().Contains("Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable") ||
                     result.GetType().ToString().Contains("System.Linq.IQueryable"))
            {
                context.TotalItems = ((IQueryable <object>)result).Count();
                if (context.TotalItems > context.PageSize)
                {
                    context.DataObjects = ((IQueryable <object>)result).Skip(context.PageSize * (context.PageNumber - 1)).Take(context.PageSize).ToList();
                }
            }
            else
            {
                var list = result as IList;
                context.TotalItems = list != null ? new List <object>(list.Cast <object>()).Count : 1;
            }


            //return context;
        }
Exemplo n.º 8
0
        public static TagBuilder BuildTableHtml(NccGridTagContext context, NccGridContext gridContext)
        {
            var table = new TagBuilder("table");

            table.Attributes.Add("class", !string.IsNullOrEmpty(context.CssClassGrid) ? context.CssClassGrid : "table");

            table.InnerHtml.AppendHtml(BuildTableHeader(context));

            table.InnerHtml.AppendHtml(BuildTableBody(context));

            //if (gridContext.AllowPaging)
            //    table.InnerHtml.AppendHtml(BuildTablePager(context, gridContext));

            return(table);
        }
Exemplo n.º 9
0
        public IActionResult SimpleGridWithServerPaging()
        {
            var context = new NccGridContext
            {
                Id = "SimpleGridWithServerPaging",
                DataAccessClass = typeof(IDataAccess).AssemblyQualifiedName,
                SelectMethod    = "GetProductListPaginated",
                ViewPaths       = new ViewsPathsModel {
                    ViewPath = "/Views/NccGrid/Partials/_SimpleGridWithServerPaging.cshtml"
                }
            };

            ViewData[context.Id] = context;

            return(View());
        }
Exemplo n.º 10
0
        public IActionResult SimpleGridWithServerPagingNoBind()
        {
            var context = new NccGridContext
            {
                Id         = "SimpleGridWithServerPagingNoBind",
                AutoBind   = false,
                DataSource = DataAccess.GetProductList(),
                ViewPaths  = new ViewsPathsModel {
                    ViewPath = "/Views/NccGrid/Partials/_SimpleGridWithServerPagingNoBind.cshtml"
                }
            };

            ViewData[context.Id] = context;

            return(View());
        }
Exemplo n.º 11
0
        public IActionResult DifferentControls()
        {
            var context = new NccSelectContext
            {
                Id = "DifferentControls1",
                DataAccessClass = typeof(IDataAccess).AssemblyQualifiedName,
                SelectMethod    = "GetCustomers",
                TextValue       = "CompanyName",
                DataValue       = "CustomerID",
                FirstItem       = "--- Please select ---",
                ViewPaths       = new ViewsPathsModel {
                    ViewPath = "/Views/NccSelect/Partials/_DifferentControls1.cshtml"
                }
            };

            ViewData[context.Id] = context;

            var context2 = new NccSelectContext
            {
                Id = "DifferentControls2",
                DataAccessClass  = typeof(IDataAccess).AssemblyQualifiedName,
                SelectMethod     = "GetOrderByCustomer",
                SelectParameters = new { customerId = (int?)null }.NccToExpando(),
                TextValue = "OrderDate",
                DataValue = "OrderID",
                FirstItem = "--- Please select ---",
                ViewPaths = new ViewsPathsModel {
                    ViewPath = "/Views/NccSelect/Partials/_DifferentControls2.cshtml"
                }
            };

            ViewData[context2.Id] = context2;

            var context3 = new NccGridContext
            {
                Id = "DifferentControls3",
                DataAccessClass  = typeof(IDataAccess).AssemblyQualifiedName,
                SelectMethod     = "GetOrderDetailByOrder",
                SelectParameters = new { customerId = (int?)null, orderId = (int?)null }.NccToExpando(),
                ViewPaths = new ViewsPathsModel {
                    ViewPath = "/Views/NccSelect/Partials/_DifferentControls3.cshtml"
                }
            };

            ViewData[context3.Id] = context3;
            return(View());
        }
Exemplo n.º 12
0
        public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output)
        {
            output.SuppressOutput();

            if (tagContext.Items.ContainsKey(typeof(NccGridContext)))
            {
                _context = (NccGridContext)tagContext.Items[typeof(NccGridContext)];
            }
            else
            {
                return;
            }

            _context.AllowPaging = true;
            if (_context.PageSize == int.MaxValue)
            {
                _context.PageSize = 10;
            }

            if (ShowRecordsCount.HasValue)
            {
                _context.ShowRecordsCount = ShowRecordsCount.Value;
            }
            if (!string.IsNullOrEmpty(GridRecordsTemplate))
            {
                _context.GridRecordsTemplate = GridRecordsTemplate;
            }
            if (GridPagerPosition.HasValue)
            {
                _context.GridPagerPosition = GridPagerPosition.Value;
            }
            if (GridRecordCountPosition.HasValue)
            {
                _context.GridRecordCountPosition = GridRecordCountPosition.Value;
            }

            _nccTagContext.CssClassRecordCountDiv = CssClassRecordCountDiv;
            _nccTagContext.CssClassPagerDiv       = CssClassPagerDiv;
            _nccTagContext.CssClassPagerUl        = CssClassPagerUl;
            _nccTagContext.CssClassPagerLi        = CssClassPagerLi;
            _nccTagContext.CssClassPagerA         = CssClassPagerA;

            await output.GetChildContentAsync();
        }
        public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output)
        {
            output.SuppressOutput();

            if (tagContext.Items.ContainsKey(typeof(NccGridContext)))
            {
                _context = (NccGridContext)tagContext.Items[typeof(NccGridContext)];
            }
            else
            {
                return;
            }

            var data = _context.DataObjects as IList;

            if (_nccTagContext.RowNumber > 0 || data == null || data.Count == 0)
            {
                return;
            }

            object showHeader = null;

            if (tagContext.Items.ContainsKey("ShowHeader"))
            {
                showHeader = tagContext.Items["ShowHeader"];
            }
            if (showHeader == null || (bool)showHeader)
            {
                var childContent = await output.GetChildContentAsync();

                _nccTagContext.GridHeader.Cells.Add(new GridCell {
                    Value = childContent, CssClass = CssClass
                });

                tagContext.Items.Remove("ShowHeader");
            }
            else
            {
                var cell = new GridCell();
                cell.Value.AppendHtml("");
                cell.CssClass = CssClass;
                _nccTagContext.GridHeader.Cells.Add(cell);
            }
        }
        public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output)
        {
            output.SuppressOutput();

            if (tagContext.Items.ContainsKey(typeof(NccGridContext)))
            {
                _context = (NccGridContext)tagContext.Items[typeof(NccGridContext)];
            }
            else
            {
                return;
            }

            ViewContext.ViewData.Model = new { NccPageSize = _context.PageSize, NccTotalRows = _context.TotalItems }.NccToExpando();

            var childContent = await output.GetChildContentAsync(false);

            _nccTagContext.PagerRecordsCountContent = childContent.GetContent();
        }
Exemplo n.º 15
0
        public async Task <IActionResult> CustomerPartyList()
        {
            var customerList = await JasminClient.Sales.CustomerParty.GetCustomerPartiesWithParty();

            var context = new NccGridContext
            {
                Id         = "CustomerPartyList",
                AutoBind   = false,
                DataSource = customerList.Response,
                PageSize   = 10,
                ViewPaths  = new ViewsPathsModel {
                    ViewPath = "/Views/Home/_CustomerPartyGrid.cshtml"
                }
            };

            ViewData[context.Id] = context;

            return(View());
        }
Exemplo n.º 16
0
        public IActionResult GridWithFilter()
        {
            var context = new NccGridContext
            {
                Id = "GridWithFilter",
                DataAccessClass  = typeof(IDataAccess).AssemblyQualifiedName,
                SelectMethod     = "GetProductListFiltered",
                SelectParameters = new { discontinued = (bool?)null, supplierId = (int?)null, categoryId = (int?)null }.NccToExpando(),
                ViewPaths = new ViewsPathsModel {
                    ViewPath = "/Views/NccGrid/Partials/_GridWithFilter.cshtml"
                }
            };

            ViewData[context.Id] = context;

            ViewData["Suppliers"]  = DataAccess.GetSuppliers().ToList();
            ViewData["Categories"] = DataAccess.GetCategories().ToList();

            return(View());
        }
Exemplo n.º 17
0
        public async Task <IActionResult> ProductList()
        {
            var productList = await JasminClient.MasterDataBusinessEntities.Item.GetItems();

            var context = new NccGridContext
            {
                Id         = "ProductList",
                AutoBind   = false,
                DataSource = productList.Response,
                PageSize   = 10,
                ViewPaths  = new ViewsPathsModel {
                    ViewPath = "/Views/Home/_ProductGrid.cshtml"
                }
            };

            ViewData[context.Id] = context;


            return(View());
        }
        public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output)
        {
            output.SuppressOutput();

            if (tagContext.Items.ContainsKey(typeof(NccGridContext)))
            {
                _context = (NccGridContext)tagContext.Items[typeof(NccGridContext)];
            }
            else
            {
                return;
            }

            _context.GridExportExcel.Columns.Add(new GridExportExcelColumn
            {
                ColumnTitle               = ColumnTitle,
                ColumnPropName            = ColumnPropName,
                HeaderHorizontalAlignment = HeaderHorizontalAlignment,
                HeaderVerticalAlignment   = HeaderVerticalAlignment,
                RowHorizontalAlignment    = RowHorizontalAlignment,
                RowVerticalAlignment      = RowVerticalAlignment,
                Width = Width
            });
        }
Exemplo n.º 19
0
 public static void GetExtraParameters(IDictionary <string, object> methodParams, NccGridContext context)
 {
     methodParams["pageNumber"] = context.PageNumber;
     methodParams["pageSize"]   = context.PageSize;
 }
Exemplo n.º 20
0
 public static void GetExtraNullableParameters(IDictionary <string, object> methodParams, NccGridContext context)
 {
     methodParams["pageNumber"] = 1;
     methodParams["pageSize"]   = int.MaxValue;
 }
        public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output)
        {
            output.SuppressOutput();

            if (tagContext.Items.ContainsKey(typeof(NccGridContext)))
            {
                _context = (NccGridContext)tagContext.Items[typeof(NccGridContext)];
            }
            else
            {
                return;
            }

            var gridViewContext = (NccGridContext)tagContext.Items[typeof(NccGridContext)];

            var global = ViewContext.ViewData.Model;

            output.TagName = null;

            var data = gridViewContext.DataObjects as IList;

            _nccTagContext.RowNumber      = 0;
            ViewContext.ViewBag.EmptyData = false;

            if (data != null && data.Count > 0)
            {
                object service = null;
                if (!string.IsNullOrEmpty(_context.EventHandlerClass))
                {
                    service = NccReflectionService.NccGetClassInstance(_context.EventHandlerClass, null);
                }

                _nccTagContext.GridRows = new List <GridRow>();

                if (data.Count > _context.PageSize)
                {
                    if (_context.Filters.ContainsKey("pageSize"))
                    {
                        var pageSize = Convert.ToInt32(_context.Filters["pageSize"]);
                        data = new List <object>(data.Cast <object>()).Skip(pageSize * (_context.PageNumber - 1)).Take(pageSize).ToList();
                    }
                    else
                    {
                        data = new List <object>(data.Cast <object>()).Skip(_context.PageSize * (_context.PageNumber - 1)).Take(_context.PageSize).ToList();
                    }
                }

                _context.DataObjects = data;

                var dataKeys = _context.DataKeys?.Split(',')?.ToList();
                if (dataKeys != null)
                {
                    _context.DataKeysValues = new List <Dictionary <string, object> >();
                }

                foreach (var row in data)
                {
                    if (dataKeys != null)
                    {
                        var dataKeysRow = new Dictionary <string, object>();
                        foreach (var dataKey in dataKeys)
                        {
                            var keyValue = row.NccGetPropertyValue <object>(dataKey);
                            if (keyValue != null)
                            {
                                dataKeysRow[dataKey] = keyValue;
                            }
                        }
                        _context.DataKeysValues.Add(dataKeysRow);
                    }

                    service?.NccInvokeMethod(NccGridEventsEnum.RowDataBound.ToString(), new object[] { new NccEventArgs {
                                                                                                           NccTagContext = _nccTagContext, NccControlContext = _context, DataObjects = data
                                                                                                       }, row });

                    _nccTagContext.GridRows.Add(new GridRow {
                        Cells = new List <GridCell>(), RowNumber = _nccTagContext.RowNumber
                    });

                    var rowData = row.NccToExpando() as IDictionary <string, object>;
                    rowData["NccRowNumber"] = _nccTagContext.RowNumber;

                    ViewContext.ViewData.Model = rowData.NccToExpando();

                    await output.GetChildContentAsync(false);

                    if (_context.AutoGenerateEditButton)
                    {
                        var rowModel = _nccTagContext.GridRows.LastOrDefault();

                        if (_context.AdditionalData.ContainsKey("EditRowNumber") && _context.AdditionalData["EditRowNumber"].ToString() == _nccTagContext.RowNumber.ToString())
                        {
                            var model = new NccActionModel
                            {
                                TargetIds = new[] { _context.Id }
                            };
                            model.Parameters.Add($"{DefaultParameters.ActionType.ToString().NccAddPrefix()}", "GridAction");
                            model.Parameters.Add($"{DefaultParameters.EventName.ToString().NccAddPrefix()}", "CancelEditRow");
                            model.Parameters.Add($"{NccGridParametersEnum.RowNumber.ToString().NccAddPrefix()}", _nccTagContext.RowNumber.ToString());
                            var link = new TagBuilder("a")
                            {
                                Attributes =
                                {
                                    { "style",   "cursor:pointer;"                                                                                      },
                                    { "onclick", $"nccAction(null, $(this), '{JsonConvert.SerializeObject(model)}', '{NccConstants.AttributePrefix}');" }
                                }
                            };
                            link.InnerHtml.AppendHtml("Cancel");

                            model.Parameters[$"{DefaultParameters.EventName.ToString().NccAddPrefix()}"] = "UpdateRow";
                            var link2 = new TagBuilder("a")
                            {
                                Attributes =
                                {
                                    { "style",   "cursor:pointer;"                                                                                      },
                                    { "onclick", $"nccAction(null, $(this), '{JsonConvert.SerializeObject(model)}', '{NccConstants.AttributePrefix}');" }
                                }
                            };
                            link2.InnerHtml.AppendHtml("Save");

                            var cell = new GridCell();
                            cell.Value.AppendHtml(link);
                            rowModel?.Cells.Add(cell);
                            var cell2 = new GridCell();
                            cell2.Value.SetHtmlContent(link2);
                            rowModel?.Cells.Add(cell2);
                        }
                        else
                        {
                            var model = new NccActionModel
                            {
                                TargetIds = new[] { _context.Id }
                            };
                            model.Parameters.Add($"{DefaultParameters.ActionType.ToString().NccAddPrefix()}", "GridAction");
                            model.Parameters.Add($"{DefaultParameters.EventName.ToString().NccAddPrefix()}", "EditRow");
                            model.Parameters.Add($"{NccGridParametersEnum.RowNumber.ToString().NccAddPrefix()}", _nccTagContext.RowNumber.ToString());

                            var link = new TagBuilder("a")
                            {
                                Attributes =
                                {
                                    { "style",   "cursor:pointer;"                                                                                      },
                                    { "onclick", $"nccAction(null, $(this), '{JsonConvert.SerializeObject(model)}', '{NccConstants.AttributePrefix}');" }
                                }
                            };
                            link.InnerHtml.AppendHtml("Edit");

                            var cell = new GridCell();
                            cell.Value.AppendHtml(link);
                            rowModel?.Cells.Add(cell);
                        }
                    }
                    //ViewContext.ViewBag.RowCount
                    _nccTagContext.RowNumber++;
                    _nccTagContext.ColCountComplete = true;

                    service?.NccInvokeMethod(NccGridEventsEnum.RowCreated.ToString(), new object[] { new NccEventArgs {
                                                                                                         NccTagContext = _nccTagContext, NccControlContext = _context, DataObjects = data
                                                                                                     }, _nccTagContext.GridRows.LastOrDefault() });
                }
            }
        }
Exemplo n.º 22
0
        public static TagBuilder BuildTablePager(NccGridTagContext context, NccGridContext gridContext)
        {
            var pageSize = gridContext.PageSize;

            if (gridContext.Filters.ContainsKey("pageSize"))
            {
                pageSize = Convert.ToInt32(gridContext.Filters["pageSize"]);
            }

            var totalPages = gridContext.TotalItems % pageSize > 0
                ? gridContext.TotalItems / pageSize + 1
                : gridContext.TotalItems / pageSize;

            if (totalPages <= 1)
            {
                return(null);
            }

            var model = new NccActionModel {
                TargetIds = new [] { gridContext.Id }
            };

            model.Parameters.Add($"{DefaultParameters.ActionType.ToString().NccAddPrefix()}", "Filter");

            var footerContainerDiv = new TagBuilder("div")
            {
                Attributes = { { "class", context.CssClassFooterContainer ?? "row" } }
            };

            var divColLeft = new TagBuilder("div")
            {
                Attributes = { { "class", "col-sm-12 col-md-6" } }
            };
            var divColRight = new TagBuilder("div")
            {
                Attributes = { { "class", "col-sm-12 col-md-6" } }
            };
            var divRecordCount = new TagBuilder("div");

            if (!string.IsNullOrEmpty(context.CssClassRecordCountDiv))
            {
                divRecordCount.Attributes.Add("class", context.CssClassRecordCountDiv);
            }
            //TODO: Add RecordCount html

            var div = new TagBuilder("div")
            {
                Attributes = { { "class", context.CssClassPagerDiv ?? "nccGridPagerContainer" } }
            };
            var ul = new TagBuilder("ul")
            {
                Attributes = { { "class", context.CssClassPagerUl ?? "nccGridPagerPagination" } }
            };

            var firstLink = BuilPagerLink(1, model, context, "<<", false, gridContext.PageNumber == 1);
            var prevLink  = BuilPagerLink(gridContext.PageNumber - 1, model, context, "<", false, gridContext.PageNumber == 1);

            ul.InnerHtml.AppendHtml(firstLink);
            ul.InnerHtml.AppendHtml(prevLink);

            var nextLink = BuilPagerLink(gridContext.PageNumber + 1, model, context, ">", false, gridContext.PageNumber == totalPages);
            var lastLink = BuilPagerLink(totalPages, model, context, ">>", false, gridContext.PageNumber == totalPages);

            var navSize     = gridContext.PagerNavigationSize >= totalPages ? totalPages : gridContext.PagerNavigationSize;
            var linksBefore = navSize / 2 < gridContext.PageNumber
                ? navSize / 2
                : gridContext.PageNumber - 1;
            var linksAfter = navSize / 2 <= totalPages - gridContext.PageNumber
                ? navSize - linksBefore
                : totalPages - gridContext.PageNumber;

            if (navSize / 2 > linksAfter)
            {
                linksBefore = linksBefore + (navSize / 2 - linksAfter);
            }
            if (navSize % 2 == 0)
            {
                if (linksBefore > 0 && linksBefore >= navSize / 2)
                {
                    linksBefore--;
                }
                else
                {
                    linksAfter--;
                }
            }
            else if (navSize < linksBefore + linksAfter + 1)
            {
                linksAfter--;
            }

            for (var i = 0; i < linksBefore; i++)
            {
                var link = BuilPagerLink(gridContext.PageNumber - linksBefore + i, model, context);
                ul.InnerHtml.AppendHtml(link);
            }
            ul.InnerHtml.AppendHtml(BuilPagerLink(gridContext.PageNumber, model, context, null, true));
            for (var i = 0; i < linksAfter; i++)
            {
                var link = BuilPagerLink(gridContext.PageNumber + i + 1, model, context);
                ul.InnerHtml.AppendHtml(link);
            }

            ul.InnerHtml.AppendHtml(nextLink);
            ul.InnerHtml.AppendHtml(lastLink);

            div.InnerHtml.AppendHtml(ul);
            if (gridContext.GridPagerPosition == NccGridPagerPositionEnum.Left)
            {
                divColLeft.InnerHtml.AppendHtml(div);
                if (gridContext.ShowRecordsCount && gridContext.GridRecordCountPosition == NccGridPagerPositionEnum.Left)
                {
                    divColLeft.InnerHtml.AppendHtml(divRecordCount);
                }
                else if (gridContext.ShowRecordsCount && gridContext.GridRecordCountPosition == NccGridPagerPositionEnum.Right)
                {
                    divColRight.InnerHtml.AppendHtml(divRecordCount);
                }
            }
            else
            {
                if (gridContext.ShowRecordsCount && gridContext.GridRecordCountPosition == NccGridPagerPositionEnum.Left)
                {
                    divColLeft.InnerHtml.AppendHtml(divRecordCount);
                }
                else if (gridContext.ShowRecordsCount && gridContext.GridRecordCountPosition == NccGridPagerPositionEnum.Right)
                {
                    divColRight.InnerHtml.AppendHtml(divRecordCount);
                }
                divColRight.InnerHtml.AppendHtml(div);
            }

            if (gridContext.ShowRecordsCount && string.IsNullOrEmpty(context.PagerRecordsCountContent))
            {
                var firstRecord = pageSize * (gridContext.PageNumber - 1) + 1;
                var lastRecord  = pageSize * (gridContext.PageNumber - 1) + pageSize;
                if (lastRecord > gridContext.TotalItems)
                {
                    lastRecord = gridContext.TotalItems;
                }

                divRecordCount.InnerHtml.AppendHtml(string.Format($"<span>{gridContext.GridRecordsTemplate}</span>", firstRecord, lastRecord, gridContext.TotalItems));
            }

            footerContainerDiv.InnerHtml.AppendHtml(divColLeft);
            footerContainerDiv.InnerHtml.AppendHtml(divColRight);

            return(footerContainerDiv);
        }
Exemplo n.º 23
0
        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 void Process(TagHelperContext tagContext, TagHelperOutput output)
        {
            output.SuppressOutput();

            if (tagContext.Items.ContainsKey(typeof(NccGridContext)))
            {
                _context = (NccGridContext)tagContext.Items[typeof(NccGridContext)];
            }
            else
            {
                return;
            }

            var data = _context.DataObjects as IList;

            if (data == null || data.Count == 0)
            {
                return;
            }

            if (Visible)
            {
                if (!_nccTagContext.ColCountComplete)
                {
                    _nccTagContext.ColCount++;
                }

                if (ShowHeader)
                {
                    if (_nccTagContext.RowNumber == 0)
                    {
                        var cell = new GridCell();
                        cell.Value.AppendHtml(string.IsNullOrEmpty(HeaderText) ? DataValue : HeaderText);
                        _nccTagContext.GridHeader.Cells.Add(cell);
                    }
                }
                else
                {
                    var cell = new GridCell();
                    cell.Value.AppendHtml("");
                    _nccTagContext.GridHeader.Cells.Add(cell);
                }

                if (!ViewContext.ViewBag.EmptyData)
                {
                    if (!string.IsNullOrEmpty(DataField) && _context.AdditionalData.ContainsKey("EditRowNumber") && _context.AdditionalData["EditRowNumber"].ToString() == _nccTagContext.RowNumber.ToString())
                    {
                        var cell = new GridCell
                        {
                            CssClass = CssClass
                        };
                        var val   = ViewContext.ViewData.Model.NccGetPropertyValue <string>(DataField);
                        var input = new TagBuilder("input")
                        {
                            Attributes =
                            {
                                { "class", "form-control" },
                                { "name",  DataField      },
                                { "value", val            }
                            }
                        };
                        cell.Value.AppendHtml(input);

                        var row = _nccTagContext.GridRows.LastOrDefault();

                        row?.Cells.Add(cell);
                    }
                    else
                    {
                        var cell = new GridCell
                        {
                            CssClass  = CssClass,
                            Aggregate = Aggregate
                        };
                        cell.Value.AppendHtml(DataValue);

                        var row = _nccTagContext.GridRows.LastOrDefault();

                        if (row != null)
                        {
                            row.Cells.Add(cell);
                            row.CssClass = CssClass;
                        }
                    }
                }
            }

            output.TagName = null;
            output.SuppressOutput();
        }